1 6e527fbc 2005-02-13 devnull #include "std.h"
2 6e527fbc 2005-02-13 devnull #include "dat.h"
4 6e527fbc 2005-02-13 devnull Logbuf confbuf;
7 6e527fbc 2005-02-13 devnull confirmread(Req *r)
9 6e527fbc 2005-02-13 devnull lbread(&confbuf, r);
13 6e527fbc 2005-02-13 devnull confirmflush(Req *r)
15 6e527fbc 2005-02-13 devnull lbflush(&confbuf, r);
19 6e527fbc 2005-02-13 devnull confirmwrite(char *s)
21 6e527fbc 2005-02-13 devnull char *t, *ans;
22 6e527fbc 2005-02-13 devnull int allow;
23 6e527fbc 2005-02-13 devnull ulong tag;
27 6e527fbc 2005-02-13 devnull a = _parseattr(s);
28 6e527fbc 2005-02-13 devnull if(a == nil){
29 6e527fbc 2005-02-13 devnull werrstr("bad attr");
30 6e527fbc 2005-02-13 devnull return -1;
32 6e527fbc 2005-02-13 devnull if((t = _strfindattr(a, "tag")) == nil){
33 5f6612ba 2008-05-31 rsc flog("bad confirm write: no tag");
34 6e527fbc 2005-02-13 devnull werrstr("no tag");
35 6e527fbc 2005-02-13 devnull return -1;
37 6e527fbc 2005-02-13 devnull tag = strtoul(t, 0, 0);
38 6e527fbc 2005-02-13 devnull if((ans = _strfindattr(a, "answer")) == nil){
39 5f6612ba 2008-05-31 rsc flog("bad confirm write: no answer");
40 6e527fbc 2005-02-13 devnull werrstr("no answer");
41 6e527fbc 2005-02-13 devnull return -1;
43 6e527fbc 2005-02-13 devnull if(strcmp(ans, "yes") == 0)
44 6e527fbc 2005-02-13 devnull allow = 1;
45 6e527fbc 2005-02-13 devnull else if(strcmp(ans, "no") == 0)
46 6e527fbc 2005-02-13 devnull allow = 0;
48 5f6612ba 2008-05-31 rsc flog("bad confirm write: bad answer");
49 6e527fbc 2005-02-13 devnull werrstr("bad answer");
50 6e527fbc 2005-02-13 devnull return -1;
52 6e527fbc 2005-02-13 devnull for(c=conv; c; c=c->next){
53 6e527fbc 2005-02-13 devnull if(tag == c->tag){
54 6e527fbc 2005-02-13 devnull nbsendul(c->keywait, allow);
58 6e527fbc 2005-02-13 devnull if(c == nil){
59 6e527fbc 2005-02-13 devnull werrstr("tag not found");
60 6e527fbc 2005-02-13 devnull return -1;
62 6e527fbc 2005-02-13 devnull return 0;
66 6e527fbc 2005-02-13 devnull confirmkey(Conv *c, Key *k)
70 6e527fbc 2005-02-13 devnull if(*confirminuse == 0)
71 6e527fbc 2005-02-13 devnull return -1;
73 6e527fbc 2005-02-13 devnull lbappend(&confbuf, "confirm tag=%lud %A %N", c->tag, k->attr, k->privattr);
74 5f6612ba 2008-05-31 rsc flog("confirm %A %N", k->attr, k->privattr);
75 6e527fbc 2005-02-13 devnull c->state = "keyconfirm";
76 5f6612ba 2008-05-31 rsc ret = recvul(c->keywait);
77 5f6612ba 2008-05-31 rsc flog("confirm=%d %A %N", ret, k->attr, k->privattr);
81 6e527fbc 2005-02-13 devnull Logbuf needkeybuf;
84 6e527fbc 2005-02-13 devnull needkeyread(Req *r)
86 6e527fbc 2005-02-13 devnull lbread(&needkeybuf, r);
90 6e527fbc 2005-02-13 devnull needkeyflush(Req *r)
92 6e527fbc 2005-02-13 devnull lbflush(&needkeybuf, r);
96 6e527fbc 2005-02-13 devnull needkeywrite(char *s)
99 6e527fbc 2005-02-13 devnull ulong tag;
100 6e527fbc 2005-02-13 devnull Attr *a;
101 6e527fbc 2005-02-13 devnull Conv *c;
103 6e527fbc 2005-02-13 devnull a = _parseattr(s);
104 6e527fbc 2005-02-13 devnull if(a == nil){
105 6e527fbc 2005-02-13 devnull werrstr("empty write");
106 6e527fbc 2005-02-13 devnull return -1;
108 6e527fbc 2005-02-13 devnull if((t = _strfindattr(a, "tag")) == nil){
109 6e527fbc 2005-02-13 devnull werrstr("no tag");
110 6e527fbc 2005-02-13 devnull freeattr(a);
111 6e527fbc 2005-02-13 devnull return -1;
113 6e527fbc 2005-02-13 devnull tag = strtoul(t, 0, 0);
114 6e527fbc 2005-02-13 devnull for(c=conv; c; c=c->next)
115 6e527fbc 2005-02-13 devnull if(c->tag == tag){
116 6e527fbc 2005-02-13 devnull nbsendul(c->keywait, 0);
119 6e527fbc 2005-02-13 devnull if(c == nil){
120 6e527fbc 2005-02-13 devnull werrstr("tag not found");
121 6e527fbc 2005-02-13 devnull freeattr(a);
122 6e527fbc 2005-02-13 devnull return -1;
124 6e527fbc 2005-02-13 devnull freeattr(a);
125 6e527fbc 2005-02-13 devnull return 0;
129 6e527fbc 2005-02-13 devnull needkey(Conv *c, Attr *a)
133 6e527fbc 2005-02-13 devnull if(c == nil || *needkeyinuse == 0)
134 6e527fbc 2005-02-13 devnull return -1;
136 6e527fbc 2005-02-13 devnull lbappend(&needkeybuf, "needkey tag=%lud %A", c->tag, a);
137 5f6612ba 2008-05-31 rsc flog("needkey %A", a);
139 e75dbb6a 2020-01-15 rsc // Note: This code used to "return nbrecvul(c->keywait)."
140 e75dbb6a 2020-01-15 rsc // In Jan 2020 we changed nbrecvul to match Plan 9 and
141 e75dbb6a 2020-01-15 rsc // the man page and return 0 on "no data available" instead
142 e75dbb6a 2020-01-15 rsc // of -1. This new code with an explicit nbrecv preserves the
143 e75dbb6a 2020-01-15 rsc // code's old semantics, distinguishing a sent 0 from "no data".
144 e75dbb6a 2020-01-15 rsc // That said, this code seems to return -1 unconditionally:
145 e75dbb6a 2020-01-15 rsc // the c->keywait channel is unbuffered, and the only sending
146 e75dbb6a 2020-01-15 rsc // to it is done with an nbsendul, which won't block waiting for
147 e75dbb6a 2020-01-15 rsc // a receiver. So there is no sender for nbrecv to find here.
148 e75dbb6a 2020-01-15 rsc if(nbrecv(c->keywait, &u) < 0)
154 6e527fbc 2005-02-13 devnull badkey(Conv *c, Key *k, char *msg, Attr *a)
158 6e527fbc 2005-02-13 devnull if(c == nil || *needkeyinuse == 0)
159 6e527fbc 2005-02-13 devnull return -1;
161 6e527fbc 2005-02-13 devnull lbappend(&needkeybuf, "badkey tag=%lud %A %N\n%s\n%A",
162 6e527fbc 2005-02-13 devnull c->tag, k->attr, k->privattr, msg, a);
163 5f6612ba 2008-05-31 rsc flog("badkey %A / %N / %s / %A",
164 5f6612ba 2008-05-31 rsc k->attr, k->privattr, msg, a);
166 e75dbb6a 2020-01-15 rsc // Note: This code used to "return nbrecvul(c->keywait)."
167 e75dbb6a 2020-01-15 rsc // In Jan 2020 we changed nbrecvul to match Plan 9 and
168 e75dbb6a 2020-01-15 rsc // the man page and return 0 on "no data available" instead
169 e75dbb6a 2020-01-15 rsc // of -1. This new code with an explicit nbrecv preserves the
170 e75dbb6a 2020-01-15 rsc // code's old semantics, distinguishing a sent 0 from "no data".
171 e75dbb6a 2020-01-15 rsc // That said, this code seems to return -1 unconditionally:
172 e75dbb6a 2020-01-15 rsc // the c->keywait channel is unbuffered, and the only sending
173 e75dbb6a 2020-01-15 rsc // to it is done with an nbsendul, which won't block waiting for
174 e75dbb6a 2020-01-15 rsc // a receiver. So there is no sender for nbrecv to find here.
175 e75dbb6a 2020-01-15 rsc if(nbrecv(c->keywait, &u) < 0)