fgui.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. #include "dat.h"
  2. #include <draw.h>
  3. #include <mouse.h>
  4. #include <keyboard.h>
  5. #include <control.h>
  6. int ctldeletequits = 1;
  7. typedef struct RequestType RequestType;
  8. typedef struct Request Request;
  9. typedef struct Memory Memory;
  10. struct RequestType
  11. {
  12. char *file; /* file to read requests from */
  13. void (*f)(Request*); /* request handler */
  14. void (*r)(Controlset*); /* resize handler */
  15. int fd; /* fd = open(file, ORDWR) */
  16. Channel *rc; /* channel requests are multiplexed to */
  17. Controlset *cs;
  18. };
  19. struct Request
  20. {
  21. RequestType *rt;
  22. Attr *a;
  23. Attr *tag;
  24. };
  25. struct Memory
  26. {
  27. Memory *next;
  28. Attr *a;
  29. Attr *val;
  30. };
  31. Memory *mem;
  32. static void readreq(void*);
  33. static void hide(void);
  34. static void unhide(void);
  35. static void openkmr(void);
  36. static void closekmr(void);
  37. static Memory* searchmem(Attr*);
  38. static void addmem(Attr*, Attr*);
  39. static void confirm(Request*);
  40. static void resizeconfirm(Controlset*);
  41. static void needkey(Request*);
  42. static void resizeneedkey(Controlset*);
  43. Control *b_remember;
  44. Control *b_accept;
  45. Control *b_refuse;
  46. RequestType rt[] =
  47. {
  48. { "/mnt/factotum/confirm", confirm, resizeconfirm, },
  49. { "/mnt/factotum/needkey", needkey, resizeneedkey, },
  50. { 0 },
  51. };
  52. enum
  53. {
  54. ButtonDim= 15,
  55. };
  56. void
  57. threadmain(int argc, char *argv[])
  58. {
  59. Request r;
  60. Channel *rc;
  61. RequestType *p;
  62. Font *invis;
  63. ARGBEGIN{
  64. }ARGEND;
  65. if(newwindow("-hide") < 0)
  66. sysfatal("newwindow: %r");
  67. fmtinstall('A', _attrfmt);
  68. /* create the proc's that read */
  69. rc = chancreate(sizeof(Request), 0);
  70. for(p = rt; p->file != 0; p++){
  71. p->fd = -1;
  72. p->rc = rc;
  73. proccreate(readreq, p, 16*1024);
  74. }
  75. /* gui initialization */
  76. initdraw(0, 0, "auth/fgui");
  77. initcontrols();
  78. hide();
  79. /* get an invisible font for passwords */
  80. invis = openfont(display, "/lib/font/bit/lucm/passwd.9.font");
  81. if (invis == nil)
  82. sysfatal("fgui: %s: %r", "/lib/font/bit/lucm/passwd.9.font");
  83. namectlfont(invis, "invisible");
  84. /* serialize all requests */
  85. for(;;){
  86. if(recv(rc, &r) < 0)
  87. break;
  88. (*r.rt->f)(&r);
  89. _freeattr(r.a);
  90. _freeattr(r.tag);
  91. }
  92. threadexitsall(nil);
  93. }
  94. /*
  95. * read requests and pass them to the main loop
  96. */
  97. enum
  98. {
  99. Requestlen=4096,
  100. };
  101. static void
  102. readreq(void *a)
  103. {
  104. RequestType *rt = a;
  105. char *buf, *p;
  106. int n;
  107. Request r;
  108. Attr **l;
  109. rt->fd = open(rt->file, ORDWR);
  110. if(rt->fd < 0)
  111. sysfatal("opening %s: %r", rt->file);
  112. rt->cs = nil;
  113. buf = malloc(Requestlen);
  114. if(buf == nil)
  115. sysfatal("allocating read buffer: %r");
  116. r.rt = rt;
  117. for(;;){
  118. n = read(rt->fd, buf, Requestlen-1);
  119. if(n < 0)
  120. break;
  121. buf[n] = 0;
  122. /* skip verb, parse attributes, and remove tag */
  123. p = strchr(buf, ' ');
  124. if(p != nil)
  125. p++;
  126. else
  127. p = buf;
  128. r.a = _parseattr(p);
  129. /* separate out the tag */
  130. r.tag = nil;
  131. for(l = &r.a; *l != nil; l = &(*l)->next)
  132. if(strcmp((*l)->name, "tag") == 0){
  133. r.tag = *l;
  134. *l = r.tag->next;
  135. r.tag->next = nil;
  136. break;
  137. }
  138. /* if no tag, forget it */
  139. if(r.tag == nil){
  140. _freeattr(r.a);
  141. continue;
  142. }
  143. send(rt->rc, &r);
  144. }
  145. }
  146. #ifdef asdf
  147. static void
  148. readreq(void *a)
  149. {
  150. RequestType *rt = a;
  151. char *buf, *p;
  152. int n;
  153. Request r;
  154. rt->fd = -1;
  155. rt->cs = nil;
  156. buf = malloc(Requestlen);
  157. if(buf == nil)
  158. sysfatal("allocating read buffer: %r");
  159. r.rt = rt;
  160. for(;;){
  161. strcpy(buf, "adfasdf=afdasdf asdfasdf=asdfasdf");
  162. r.a = _parseattr(buf);
  163. send(rt->rc, &r);
  164. sleep(5000);
  165. }
  166. }
  167. #endif asdf
  168. /*
  169. * open/close the keyboard, mouse and resize channels
  170. */
  171. static Channel *kbdc;
  172. static Channel *mousec;
  173. static Channel *resizec;
  174. static Keyboardctl *kctl;
  175. static Mousectl *mctl;
  176. static void
  177. openkmr(void)
  178. {
  179. /* get channels for subsequent newcontrolset calls */
  180. kctl = initkeyboard(nil);
  181. if(kctl == nil)
  182. sysfatal("can't initialize keyboard: %r");
  183. kbdc = kctl->c;
  184. mctl = initmouse(nil, screen);
  185. if(mctl == nil)
  186. sysfatal("can't initialize mouse: %r");
  187. mousec = mctl->c;
  188. resizec = mctl->resizec;
  189. }
  190. static void
  191. closekmr(void)
  192. {
  193. Mouse m;
  194. while(nbrecv(kbdc, &m) > 0)
  195. ;
  196. closekeyboard(kctl);
  197. while(nbrecv(mousec, &m) > 0)
  198. ;
  199. closemouse(mctl);
  200. }
  201. /*
  202. * called when the window is resized
  203. */
  204. void
  205. resizecontrolset(Controlset *cs)
  206. {
  207. RequestType *p;
  208. for(p = rt; p->file != 0; p++){
  209. if(p->cs == cs){
  210. (*p->r)(cs);
  211. break;
  212. }
  213. }
  214. }
  215. /*
  216. * hide window when not in use
  217. */
  218. static void
  219. unhide(void)
  220. {
  221. int wctl;
  222. wctl = open("/dev/wctl", OWRITE);
  223. if(wctl < 0)
  224. return;
  225. fprint(wctl, "unhide");
  226. close(wctl);
  227. }
  228. static void
  229. hide(void)
  230. {
  231. int wctl;
  232. int tries;
  233. wctl = open("/dev/wctl", OWRITE);
  234. if(wctl < 0)
  235. return;
  236. for(tries = 0; tries < 10; tries++){
  237. if(fprint(wctl, "hide") >= 0)
  238. break;
  239. sleep(100);
  240. }
  241. close(wctl);
  242. }
  243. /*
  244. * set up the controls for the confirmation window
  245. */
  246. static Channel*
  247. setupconfirm(Request *r)
  248. {
  249. Controlset *cs;
  250. Channel *c;
  251. Attr *a;
  252. /* create a new control set for the confirmation */
  253. openkmr();
  254. cs = newcontrolset(screen, kbdc, mousec, resizec);
  255. createtext(cs, "msg");
  256. chanprint(cs->ctl, "msg image paleyellow");
  257. chanprint(cs->ctl, "msg border 1");
  258. chanprint(cs->ctl, "msg add 'The following key is being used:'");
  259. for(a = r->a; a != nil; a = a->next)
  260. chanprint(cs->ctl, "msg add ' %s = %s'", a->name,
  261. a->val);
  262. namectlimage(display->white, "i_white");
  263. namectlimage(display->black, "i_black");
  264. b_remember = createbutton(cs, "b_remember");
  265. chanprint(cs->ctl, "b_remember border 1");
  266. chanprint(cs->ctl, "b_remember mask i_white");
  267. chanprint(cs->ctl, "b_remember image i_white");
  268. chanprint(cs->ctl, "b_remember light i_black");
  269. createtext(cs, "t_remember");
  270. chanprint(cs->ctl, "t_remember image white");
  271. chanprint(cs->ctl, "t_remember bordercolor white");
  272. chanprint(cs->ctl, "t_remember add 'Remember this answer for future confirmations'");
  273. b_accept = createtextbutton(cs, "b_accept");
  274. chanprint(cs->ctl, "b_accept border 1");
  275. chanprint(cs->ctl, "b_accept align center");
  276. chanprint(cs->ctl, "b_accept text Accept");
  277. chanprint(cs->ctl, "b_accept image i_white");
  278. chanprint(cs->ctl, "b_accept light i_black");
  279. b_refuse = createtextbutton(cs, "b_refuse");
  280. chanprint(cs->ctl, "b_refuse border 1");
  281. chanprint(cs->ctl, "b_refuse align center");
  282. chanprint(cs->ctl, "b_refuse text Refuse");
  283. chanprint(cs->ctl, "b_refuse image i_white");
  284. chanprint(cs->ctl, "b_refuse light i_black");
  285. c = chancreate(sizeof(char*), 0);
  286. controlwire(b_remember, "event", c);
  287. controlwire(b_accept, "event", c);
  288. controlwire(b_refuse, "event", c);
  289. /* make the controls interactive */
  290. activate(b_remember);
  291. activate(b_accept);
  292. activate(b_refuse);
  293. r->rt->cs = cs;
  294. unhide();
  295. resizecontrolset(cs);
  296. return c;
  297. }
  298. /*
  299. * resize the controls for the confirmation window
  300. */
  301. static void
  302. resizeconfirm(Controlset *cs)
  303. {
  304. Rectangle r, mr, nr, ntr, ar, rr;
  305. int fontwidth;
  306. fontwidth = font->height;
  307. /* get usable window rectangle */
  308. if(getwindow(display, Refnone) < 0)
  309. ctlerror("resize failed: %r");
  310. r = insetrect(screen->r, 10);
  311. /* message box fills everything not needed for buttons */
  312. mr = r;
  313. mr.max.y = mr.min.y + font->height*((Dy(mr)-3*ButtonDim-font->height-4)/font->height);
  314. /* remember button */
  315. nr.min = Pt(mr.min.x, mr.max.y+ButtonDim);
  316. nr.max = Pt(mr.max.x, r.max.y);
  317. if(Dx(nr) > ButtonDim)
  318. nr.max.x = nr.min.x+ButtonDim;
  319. if(Dy(nr) > ButtonDim)
  320. nr.max.y = nr.min.y+ButtonDim;
  321. ntr.min = Pt(nr.max.x+ButtonDim, nr.min.y);
  322. ntr.max = Pt(r.max.x, nr.min.y+font->height);
  323. /* accept/refuse buttons */
  324. ar.min = Pt(r.min.x+Dx(r)/2-ButtonDim-6*fontwidth, nr.max.y+ButtonDim);
  325. ar.max = Pt(ar.min.x+6*fontwidth, ar.min.y+font->height+4);
  326. rr.min = Pt(r.min.x+Dx(r)/2+ButtonDim, nr.max.y+ButtonDim);
  327. rr.max = Pt(rr.min.x+6*fontwidth, rr.min.y+font->height+4);
  328. /* make the controls visible */
  329. chanprint(cs->ctl, "msg rect %R\nmsg show", mr);
  330. chanprint(cs->ctl, "b_remember rect %R\nb_remember show", nr);
  331. chanprint(cs->ctl, "t_remember rect %R\nt_remember show", ntr);
  332. chanprint(cs->ctl, "b_accept rect %R\nb_accept show", ar);
  333. chanprint(cs->ctl, "b_refuse rect %R\nb_refuse show", rr);
  334. }
  335. /*
  336. * free the controls for the confirmation window
  337. */
  338. static void
  339. teardownconfirm(Request *r)
  340. {
  341. Controlset *cs;
  342. cs = r->rt->cs;
  343. r->rt->cs = nil;
  344. hide();
  345. closecontrolset(cs);
  346. closekmr();
  347. }
  348. /*
  349. * get user confirmation of a key
  350. */
  351. static void
  352. confirm(Request *r)
  353. {
  354. Channel *c;
  355. char *s;
  356. int n;
  357. char *args[3];
  358. int remember;
  359. Attr *val;
  360. Memory *m;
  361. /* if it's something that the user wanted us not to ask again about */
  362. m = searchmem(r->a);
  363. if(m != nil){
  364. fprint(r->rt->fd, "%A %A", r->tag, m->val);
  365. return;
  366. }
  367. /* set up the controls */
  368. c = setupconfirm(r);
  369. /* wait for user to reply */
  370. remember = 0;
  371. for(;;){
  372. s = recvp(c);
  373. n = tokenize(s, args, nelem(args));
  374. if(n==3 && strcmp(args[1], "value")==0){
  375. if(strcmp(args[0], "b_remember:") == 0){
  376. remember = atoi(args[2]);
  377. }
  378. if(strcmp(args[0], "b_accept:") == 0){
  379. val = _mkattr(AttrNameval, "answer", "yes", nil);
  380. free(s);
  381. break;
  382. }
  383. if(strcmp(args[0], "b_refuse:") == 0){
  384. val = _mkattr(AttrNameval, "answer", "no", nil);
  385. free(s);
  386. break;
  387. }
  388. }
  389. free(s);
  390. }
  391. teardownconfirm(r);
  392. fprint(r->rt->fd, "%A %A", r->tag, val);
  393. if(remember)
  394. addmem(_copyattr(r->a), val);
  395. else
  396. _freeattr(val);
  397. }
  398. /*
  399. * confirmations that are remembered
  400. */
  401. static int
  402. match(Attr *a, Attr *b)
  403. {
  404. Attr *x;
  405. for(; a != nil; a = a->next){
  406. x = _findattr(b, a->name);
  407. if(x == nil || strcmp(a->val, x->val) != 0)
  408. return 0;
  409. }
  410. return 1;
  411. }
  412. static Memory*
  413. searchmem(Attr *a)
  414. {
  415. Memory *m;
  416. for(m = mem; m != nil; m = m->next){
  417. if(match(a, m->a))
  418. break;
  419. }
  420. return m;
  421. }
  422. static void
  423. addmem(Attr *a, Attr *val)
  424. {
  425. Memory *m;
  426. m = malloc(sizeof *m);
  427. if(m == nil)
  428. return;
  429. m->a = a;
  430. m->val = val;
  431. m->next = mem;
  432. mem = m;
  433. }
  434. /* controls for needkey */
  435. Control *msg;
  436. Control *b_done;
  437. enum {
  438. Pprivate= 1<<0,
  439. Pneed= 1<<1,
  440. };
  441. typedef struct Entry Entry;
  442. struct Entry {
  443. Control *name;
  444. Control *val;
  445. Control *eq;
  446. Attr *a;
  447. };
  448. static Entry *entry;
  449. static int entries;
  450. /*
  451. * set up the controls for the confirmation window
  452. */
  453. static Channel*
  454. setupneedkey(Request *r)
  455. {
  456. Controlset *cs;
  457. Channel *c;
  458. Attr *a;
  459. Attr **l;
  460. char cn[10];
  461. int i;
  462. /* create a new control set for the confirmation */
  463. openkmr();
  464. cs = newcontrolset(screen, kbdc, mousec, resizec);
  465. /* count attributes and allocate entry controls */
  466. entries = 0;
  467. for(l = &r->a; *l; l = &(*l)->next)
  468. entries++;
  469. if(entries == 0){
  470. closecontrolset(cs);
  471. closekmr();
  472. return nil;
  473. }
  474. *l = a = mallocz(sizeof *a, 1);
  475. a->type = AttrQuery;
  476. entries++;
  477. l = &(*l)->next;
  478. *l = a = mallocz(sizeof *a, 1);
  479. a->type = AttrQuery;
  480. entries++;
  481. entry = malloc(entries*sizeof(Entry));
  482. if(entry == nil){
  483. closecontrolset(cs);
  484. closekmr();
  485. return nil;
  486. }
  487. namectlimage(display->white, "i_white");
  488. namectlimage(display->black, "i_black");
  489. /* create controls */
  490. msg = createtext(cs, "msg");
  491. chanprint(cs->ctl, "msg image white");
  492. chanprint(cs->ctl, "msg bordercolor white");
  493. chanprint(cs->ctl, "msg add 'You need the following key. Fill in the blanks'");
  494. chanprint(cs->ctl, "msg add 'and click on the DONE button.'");
  495. for(i = 0, a = r->a; a != nil; i++, a = a->next){
  496. entry[i].a = a;
  497. snprint(cn, sizeof cn, "name_%d", i);
  498. if(entry[i].a->name == nil){
  499. entry[i].name = createentry(cs, cn);
  500. chanprint(cs->ctl, "%s image yellow", cn);
  501. chanprint(cs->ctl, "%s border 1", cn);
  502. } else {
  503. entry[i].name = createtext(cs, cn);
  504. chanprint(cs->ctl, "%s image white", cn);
  505. chanprint(cs->ctl, "%s bordercolor white", cn);
  506. chanprint(cs->ctl, "%s add '%s'", cn, a->name);
  507. }
  508. snprint(cn, sizeof cn, "val_%d", i);
  509. if(a->type == AttrQuery){
  510. entry[i].val = createentry(cs, cn);
  511. chanprint(cs->ctl, "%s image yellow", cn);
  512. chanprint(cs->ctl, "%s border 1", cn);
  513. if(a->name != nil){
  514. if(strcmp(a->name, "user") == 0)
  515. chanprint(cs->ctl, "%s value %q", cn, getuser());
  516. if(*a->name == '!')
  517. chanprint(cs->ctl, "%s font invisible", cn);
  518. }
  519. } else {
  520. entry[i].val = createtext(cs, cn);
  521. chanprint(cs->ctl, "%s image white", cn);
  522. chanprint(cs->ctl, "%s add %q", cn, a->val);
  523. }
  524. snprint(cn, sizeof cn, "eq_%d", i);
  525. entry[i].eq = createtext(cs, cn);
  526. chanprint(cs->ctl, "%s image white", cn);
  527. chanprint(cs->ctl, "%s add ' = '", cn);
  528. }
  529. b_done = createtextbutton(cs, "b_done");
  530. chanprint(cs->ctl, "b_done border 1");
  531. chanprint(cs->ctl, "b_done align center");
  532. chanprint(cs->ctl, "b_done text DONE");
  533. chanprint(cs->ctl, "b_done image green");
  534. chanprint(cs->ctl, "b_done light green");
  535. /* wire controls for input */
  536. c = chancreate(sizeof(char*), 0);
  537. controlwire(b_done, "event", c);
  538. for(i = 0; i < entries; i++)
  539. if(entry[i].a->type == AttrQuery)
  540. controlwire(entry[i].val, "event", c);
  541. /* make the controls interactive */
  542. activate(msg);
  543. activate(b_done);
  544. for(i = 0; i < entries; i++){
  545. if(entry[i].a->type != AttrQuery)
  546. continue;
  547. if(entry[i].a->name == nil)
  548. activate(entry[i].name);
  549. activate(entry[i].val);
  550. }
  551. /* change the display */
  552. r->rt->cs = cs;
  553. unhide();
  554. resizecontrolset(cs);
  555. return c;
  556. }
  557. /*
  558. * resize the controls for the confirmation window
  559. */
  560. static void
  561. resizeneedkey(Controlset *cs)
  562. {
  563. Rectangle r, mr;
  564. int mid, i, n, lasty;
  565. /* get usable window rectangle */
  566. if(getwindow(display, Refnone) < 0)
  567. ctlerror("resize failed: %r");
  568. r = insetrect(screen->r, 10);
  569. /* find largest name */
  570. mid = 0;
  571. for(i = 0; i < entries; i++){
  572. if(entry[i].a->name == nil)
  573. continue;
  574. n = strlen(entry[i].a->name);
  575. if(n > mid)
  576. mid = n;
  577. }
  578. mid = (mid+2) * font->height;
  579. /* top line is the message */
  580. mr = r;
  581. mr.max.y = mr.min.y + 2*font->height + 2;
  582. chanprint(cs->ctl, "msg rect %R\nmsg show", mr);
  583. /* one line per attribute */
  584. mr.min.x += 2*font->height;
  585. lasty = mr.max.y;
  586. for(i = 0; i < entries; i++){
  587. r.min.x = mr.min.x;
  588. r.min.y = lasty+2;
  589. r.max.x = r.min.x + mid - 3*stringwidth(font, "=");
  590. r.max.y = r.min.y + font->height;
  591. chanprint(cs->ctl, "name_%d rect %R\nname_%d show", i, r, i);
  592. r.min.x = r.max.x;
  593. r.max.x = r.min.x + 3*stringwidth(font, "=");
  594. chanprint(cs->ctl, "eq_%d rect %R\neq_%d show", i, r, i);
  595. r.min.x = r.max.x;
  596. r.max.x = mr.max.x;
  597. if(Dx(r) > 32*font->height)
  598. r.max.x = r.min.x + 32*font->height;
  599. chanprint(cs->ctl, "val_%d rect %R\nval_%d show", i, r, i);
  600. lasty = r.max.y;
  601. }
  602. /* done button */
  603. mr.min.x -= 2*font->height;
  604. r.min.x = mr.min.x + mid - 3*font->height;
  605. r.min.y = lasty+10;
  606. r.max.x = r.min.x + 6*font->height;
  607. r.max.y = r.min.y + font->height + 2;
  608. chanprint(cs->ctl, "b_done rect %R\nb_done show", r);
  609. }
  610. /*
  611. * free the controls for the confirmation window
  612. */
  613. static void
  614. teardownneedkey(Request *r)
  615. {
  616. Controlset *cs;
  617. cs = r->rt->cs;
  618. r->rt->cs = nil;
  619. hide();
  620. closecontrolset(cs);
  621. closekmr();
  622. if(entry != nil)
  623. free(entry);
  624. entry = nil;
  625. }
  626. static void
  627. needkey(Request *r)
  628. {
  629. Channel *c;
  630. char *nam, *val;
  631. int i, n;
  632. int fd;
  633. char *args[3];
  634. /* set up the controls */
  635. c = setupneedkey(r);
  636. if(c == nil)
  637. goto out;
  638. /* wait for user to reply */
  639. for(;;){
  640. val = recvp(c);
  641. n = tokenize(val, args, nelem(args));
  642. if(n==3 && strcmp(args[1], "value")==0){ /* user hit 'enter' */
  643. free(val);
  644. break;
  645. }
  646. free(val);
  647. }
  648. /* get entry values */
  649. for(i = 0; i < entries; i++){
  650. if(entry[i].a->type != AttrQuery)
  651. continue;
  652. chanprint(r->rt->cs->ctl, "val_%d data", i);
  653. val = recvp(entry[i].val->data);
  654. if(entry[i].a->name == nil){
  655. chanprint(r->rt->cs->ctl, "name_%d data", i);
  656. nam = recvp(entry[i].name->data);
  657. if(nam == nil || *nam == 0){
  658. free(val);
  659. continue;
  660. }
  661. entry[i].a->val = estrdup(val);
  662. free(val);
  663. entry[i].a->name = estrdup(nam);
  664. free(nam);
  665. } else {
  666. if(val != nil){
  667. entry[i].a->val = estrdup(val);
  668. free(val);
  669. }
  670. }
  671. entry[i].a->type = AttrNameval;
  672. }
  673. /* enter the new key !!!!need to do something in case of error!!!! */
  674. fd = open("/mnt/factotum/ctl", OWRITE);
  675. fprint(fd, "key %A", r->a);
  676. close(fd);
  677. teardownneedkey(r);
  678. out:
  679. fprint(r->rt->fd, "%A", r->tag);
  680. }