1 2277c5d7 2004-03-21 devnull #include "std.h"
2 2277c5d7 2004-03-21 devnull #include "dat.h"
4 2277c5d7 2004-03-21 devnull Logbuf confbuf;
7 2277c5d7 2004-03-21 devnull confirmread(Req *r)
9 2277c5d7 2004-03-21 devnull lbread(&confbuf, r);
13 2277c5d7 2004-03-21 devnull confirmflush(Req *r)
15 2277c5d7 2004-03-21 devnull lbflush(&confbuf, r);
19 2277c5d7 2004-03-21 devnull confirmwrite(char *s)
21 2277c5d7 2004-03-21 devnull char *t, *ans;
22 2277c5d7 2004-03-21 devnull int allow;
23 2277c5d7 2004-03-21 devnull ulong tag;
27 2277c5d7 2004-03-21 devnull a = _parseattr(s);
28 2277c5d7 2004-03-21 devnull if(a == nil){
29 2277c5d7 2004-03-21 devnull werrstr("bad attr");
30 2277c5d7 2004-03-21 devnull return -1;
32 2277c5d7 2004-03-21 devnull if((t = _strfindattr(a, "tag")) == nil){
33 2277c5d7 2004-03-21 devnull werrstr("no tag");
34 2277c5d7 2004-03-21 devnull return -1;
36 2277c5d7 2004-03-21 devnull tag = strtoul(t, 0, 0);
37 2277c5d7 2004-03-21 devnull if((ans = _strfindattr(a, "answer")) == nil){
38 2277c5d7 2004-03-21 devnull werrstr("no answer");
39 2277c5d7 2004-03-21 devnull return -1;
41 2277c5d7 2004-03-21 devnull if(strcmp(ans, "yes") == 0)
42 2277c5d7 2004-03-21 devnull allow = 1;
43 2277c5d7 2004-03-21 devnull else if(strcmp(ans, "no") == 0)
44 2277c5d7 2004-03-21 devnull allow = 0;
46 2277c5d7 2004-03-21 devnull werrstr("bad answer");
47 2277c5d7 2004-03-21 devnull return -1;
49 2277c5d7 2004-03-21 devnull for(c=conv; c; c=c->next){
50 2277c5d7 2004-03-21 devnull if(tag == c->tag){
51 2277c5d7 2004-03-21 devnull nbsendul(c->keywait, allow);
55 2277c5d7 2004-03-21 devnull if(c == nil){
56 2277c5d7 2004-03-21 devnull werrstr("tag not found");
57 2277c5d7 2004-03-21 devnull return -1;
59 2277c5d7 2004-03-21 devnull return 0;
63 2277c5d7 2004-03-21 devnull confirmkey(Conv *c, Key *k)
65 2277c5d7 2004-03-21 devnull if(*confirminuse == 0)
66 2277c5d7 2004-03-21 devnull return -1;
68 2277c5d7 2004-03-21 devnull lbappend(&confbuf, "confirm tag=%lud %A %N", c->tag, k->attr, k->privattr);
69 2277c5d7 2004-03-21 devnull c->state = "keyconfirm";
70 2277c5d7 2004-03-21 devnull return recvul(c->keywait);
73 2277c5d7 2004-03-21 devnull Logbuf needkeybuf;
76 2277c5d7 2004-03-21 devnull needkeyread(Req *r)
78 2277c5d7 2004-03-21 devnull lbread(&needkeybuf, r);
82 2277c5d7 2004-03-21 devnull needkeyflush(Req *r)
84 2277c5d7 2004-03-21 devnull lbflush(&needkeybuf, r);
88 2277c5d7 2004-03-21 devnull needkeywrite(char *s)
91 2277c5d7 2004-03-21 devnull ulong tag;
95 2277c5d7 2004-03-21 devnull a = _parseattr(s);
96 2277c5d7 2004-03-21 devnull if(a == nil){
97 2277c5d7 2004-03-21 devnull werrstr("empty write");
98 2277c5d7 2004-03-21 devnull return -1;
100 2277c5d7 2004-03-21 devnull if((t = _strfindattr(a, "tag")) == nil){
101 2277c5d7 2004-03-21 devnull werrstr("no tag");
102 2277c5d7 2004-03-21 devnull freeattr(a);
103 2277c5d7 2004-03-21 devnull return -1;
105 2277c5d7 2004-03-21 devnull tag = strtoul(t, 0, 0);
106 2277c5d7 2004-03-21 devnull for(c=conv; c; c=c->next)
107 2277c5d7 2004-03-21 devnull if(c->tag == tag){
108 2277c5d7 2004-03-21 devnull nbsendul(c->keywait, 0);
111 2277c5d7 2004-03-21 devnull if(c == nil){
112 2277c5d7 2004-03-21 devnull werrstr("tag not found");
113 2277c5d7 2004-03-21 devnull freeattr(a);
114 2277c5d7 2004-03-21 devnull return -1;
116 2277c5d7 2004-03-21 devnull freeattr(a);
117 2277c5d7 2004-03-21 devnull return 0;
121 2277c5d7 2004-03-21 devnull needkey(Conv *c, Attr *a)
123 2277c5d7 2004-03-21 devnull if(c == nil || *needkeyinuse == 0)
124 2277c5d7 2004-03-21 devnull return -1;
126 2277c5d7 2004-03-21 devnull lbappend(&needkeybuf, "needkey tag=%lud %A", c->tag, a);
127 2277c5d7 2004-03-21 devnull return nbrecvul(c->keywait);
131 2277c5d7 2004-03-21 devnull badkey(Conv *c, Key *k, char *msg, Attr *a)
133 2277c5d7 2004-03-21 devnull if(c == nil || *needkeyinuse == 0)
134 2277c5d7 2004-03-21 devnull return -1;
136 2277c5d7 2004-03-21 devnull lbappend(&needkeybuf, "badkey tag=%lud %A %N\n%s\n%A",
137 2277c5d7 2004-03-21 devnull c->tag, k->attr, k->privattr, msg, a);
138 2277c5d7 2004-03-21 devnull return nbrecvul(c->keywait);