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 werrstr("no tag");
34 return -1;
35 }
36 tag = strtoul(t, 0, 0);
37 if((ans = _strfindattr(a, "answer")) == nil){
38 werrstr("no answer");
39 return -1;
40 }
41 if(strcmp(ans, "yes") == 0)
42 allow = 1;
43 else if(strcmp(ans, "no") == 0)
44 allow = 0;
45 else{
46 werrstr("bad answer");
47 return -1;
48 }
49 for(c=conv; c; c=c->next){
50 if(tag == c->tag){
51 nbsendul(c->keywait, allow);
52 break;
53 }
54 }
55 if(c == nil){
56 werrstr("tag not found");
57 return -1;
58 }
59 return 0;
60 }
62 int
63 confirmkey(Conv *c, Key *k)
64 {
65 if(*confirminuse == 0)
66 return -1;
68 lbappend(&confbuf, "confirm tag=%lud %A %N", c->tag, k->attr, k->privattr);
69 c->state = "keyconfirm";
70 return recvul(c->keywait);
71 }
73 Logbuf needkeybuf;
75 void
76 needkeyread(Req *r)
77 {
78 lbread(&needkeybuf, r);
79 }
81 void
82 needkeyflush(Req *r)
83 {
84 lbflush(&needkeybuf, r);
85 }
87 int
88 needkeywrite(char *s)
89 {
90 char *t;
91 ulong tag;
92 Attr *a;
93 Conv *c;
95 a = _parseattr(s);
96 if(a == nil){
97 werrstr("empty write");
98 return -1;
99 }
100 if((t = _strfindattr(a, "tag")) == nil){
101 werrstr("no tag");
102 freeattr(a);
103 return -1;
105 tag = strtoul(t, 0, 0);
106 for(c=conv; c; c=c->next)
107 if(c->tag == tag){
108 nbsendul(c->keywait, 0);
109 break;
111 if(c == nil){
112 werrstr("tag not found");
113 freeattr(a);
114 return -1;
116 freeattr(a);
117 return 0;
120 int
121 needkey(Conv *c, Attr *a)
123 if(c == nil || *needkeyinuse == 0)
124 return -1;
126 lbappend(&needkeybuf, "needkey tag=%lud %A", c->tag, a);
127 return nbrecvul(c->keywait);
130 int
131 badkey(Conv *c, Key *k, char *msg, Attr *a)
133 if(c == nil || *needkeyinuse == 0)
134 return -1;
136 lbappend(&needkeybuf, "badkey tag=%lud %A %N\n%s\n%A",
137 c->tag, k->attr, k->privattr, msg, a);
138 return nbrecvul(c->keywait);