5 static char *okvers[] = {
11 static char EBigString[] = "string too long";
12 static char EBigPacket[] = "packet too long";
13 static char ENullString[] = "missing string";
15 static char EBadVersion[] = "bad format in version string";
18 vtreadversion(VtConn *z, char *q, char *v, int nv)
24 werrstr("version too long");
27 n = read(z->infd, v, 1);
30 werrstr("unexpected eof");
37 if((uchar)*v < ' ' || (uchar)*v > 0x7f || (*q && *v != *q)){
52 char buf[VtMaxStringSize], *p, *ep, *prefix, *pp;
56 if(z->state != VtStateAlloc){
57 werrstr("bad session state");
66 ep = buf + sizeof buf;
68 p = seprint(p, ep, "%s", prefix);
70 for(i=0; okvers[i]; i++)
71 p = seprint(p, ep, "%s%s", i ? ":" : "", okvers[i]);
72 p = seprint(p, ep, "-libventi\n");
73 assert(p-buf < sizeof buf);
75 if(write(z->outfd, buf, p-buf) != p-buf)
77 vtdebug(z, "version string out: %s", buf);
79 if(vtreadversion(z, prefix, buf, sizeof buf) < 0)
81 vtdebug(z, "version string in: %s", buf);
83 p = buf+strlen(prefix);
85 if(*p == ':' || *p == '-')
87 pp = strpbrk(p, ":-");
90 for(i=0; okvers[i]; i++)
91 if(strlen(okvers[i]) == pp-p && memcmp(okvers[i], p, pp-p) == 0){
93 z->version = vtstrdup(p);
97 werrstr("unable to negotiate version");
101 z->state = VtStateConnected;
108 werrstr("vtversion: %r");
111 if(z->outfd >= 0 && z->outfd != z->infd)
115 z->state = VtStateClosed;