Blob


1 #include "std.h"
2 #include "dat.h"
4 Logbuf confbuf;
6 void
7 confirmread(Req *r)
8 {
9 lbread(&confbuf, r);
10 }
12 void
13 confirmflush(Req *r)
14 {
15 lbflush(&confbuf, r);
16 }
18 int
19 confirmwrite(char *s)
20 {
21 char *t, *ans;
22 int allow;
23 ulong tag;
24 Attr *a;
25 Conv *c;
27 a = _parseattr(s);
28 if(a == nil){
29 werrstr("bad attr");
30 return -1;
31 }
32 if((t = _strfindattr(a, "tag")) == nil){
33 flog("bad confirm write: no tag");
34 werrstr("no tag");
35 return -1;
36 }
37 tag = strtoul(t, 0, 0);
38 if((ans = _strfindattr(a, "answer")) == nil){
39 flog("bad confirm write: no answer");
40 werrstr("no answer");
41 return -1;
42 }
43 if(strcmp(ans, "yes") == 0)
44 allow = 1;
45 else if(strcmp(ans, "no") == 0)
46 allow = 0;
47 else{
48 flog("bad confirm write: bad answer");
49 werrstr("bad answer");
50 return -1;
51 }
52 for(c=conv; c; c=c->next){
53 if(tag == c->tag){
54 nbsendul(c->keywait, allow);
55 break;
56 }
57 }
58 if(c == nil){
59 werrstr("tag not found");
60 return -1;
61 }
62 return 0;
63 }
65 int
66 confirmkey(Conv *c, Key *k)
67 {
68 int ret;
70 if(*confirminuse == 0)
71 return -1;
73 lbappend(&confbuf, "confirm tag=%lud %A %N", c->tag, k->attr, k->privattr);
74 flog("confirm %A %N", k->attr, k->privattr);
75 c->state = "keyconfirm";
76 ret = recvul(c->keywait);
77 flog("confirm=%d %A %N", ret, k->attr, k->privattr);
78 return ret;
79 }
81 Logbuf needkeybuf;
83 void
84 needkeyread(Req *r)
85 {
86 lbread(&needkeybuf, r);
87 }
89 void
90 needkeyflush(Req *r)
91 {
92 lbflush(&needkeybuf, r);
93 }
95 int
96 needkeywrite(char *s)
97 {
98 char *t;
99 ulong tag;
100 Attr *a;
101 Conv *c;
103 a = _parseattr(s);
104 if(a == nil){
105 werrstr("empty write");
106 return -1;
108 if((t = _strfindattr(a, "tag")) == nil){
109 werrstr("no tag");
110 freeattr(a);
111 return -1;
113 tag = strtoul(t, 0, 0);
114 for(c=conv; c; c=c->next)
115 if(c->tag == tag){
116 nbsendul(c->keywait, 0);
117 break;
119 if(c == nil){
120 werrstr("tag not found");
121 freeattr(a);
122 return -1;
124 freeattr(a);
125 return 0;
128 int
129 needkey(Conv *c, Attr *a)
131 if(c == nil || *needkeyinuse == 0)
132 return -1;
134 lbappend(&needkeybuf, "needkey tag=%lud %A", c->tag, a);
135 flog("needkey %A", a);
136 return nbrecvul(c->keywait);
139 int
140 badkey(Conv *c, Key *k, char *msg, Attr *a)
142 if(c == nil || *needkeyinuse == 0)
143 return -1;
145 lbappend(&needkeybuf, "badkey tag=%lud %A %N\n%s\n%A",
146 c->tag, k->attr, k->privattr, msg, a);
147 flog("badkey %A / %N / %s / %A",
148 k->attr, k->privattr, msg, a);
149 return nbrecvul(c->keywait);