5 static char *okvers[] = {
12 static char EBigString[] = "string too long";
13 static char EBigPacket[] = "packet too long";
14 static char ENullString[] = "missing string";
16 static char EBadVersion[] = "bad format in version string";
19 vtreadversion(VtConn *z, char *q, char *v, int nv)
25 werrstr("version too long");
28 n = read(z->infd, v, 1);
31 werrstr("unexpected eof");
38 if((uchar)*v < ' ' || (uchar)*v > 0x7f || (*q && *v != *q)){
53 char buf[VtMaxStringSize], *p, *ep, *prefix, *pp;
57 if(z->state != VtStateAlloc){
58 werrstr("bad session state");
67 ep = buf + sizeof buf;
69 p = seprint(p, ep, "%s", prefix);
71 for(i=0; okvers[i]; i++)
72 p = seprint(p, ep, "%s%s", i ? ":" : "", okvers[i]);
73 p = seprint(p, ep, "-libventi\n");
74 assert(p-buf < sizeof buf);
76 if(write(z->outfd, buf, p-buf) != p-buf)
78 vtdebug(z, "version string out: %s", buf);
80 if(vtreadversion(z, prefix, buf, sizeof buf) < 0)
82 vtdebug(z, "version string in: %s", buf);
84 p = buf+strlen(prefix);
86 if(*p == ':' || *p == '-')
88 pp = strpbrk(p, ":-");
91 for(i=0; okvers[i]; i++)
92 if(strlen(okvers[i]) == pp-p && memcmp(okvers[i], p, pp-p) == 0){
94 z->version = vtstrdup(p);
98 werrstr("unable to negotiate version");
102 z->state = VtStateConnected;
109 werrstr("vtversion: %r");
112 if(z->outfd >= 0 && z->outfd != z->infd)
116 z->state = VtStateClosed;