ref: 411ba896b894f0595c81a7f1eb708b8e8733bf53
parent: 388e7781c24cbdb2299607d47472f7741cc5f80f
author: cinap_lenrek <cinap_lenrek@centraldogma>
date: Wed Sep 28 07:45:33 EDT 2011
factotum: allow fgui to cancel needkey transaction
--- a/sys/src/cmd/auth/factotum/confirm.c
+++ b/sys/src/cmd/auth/factotum/confirm.c
@@ -186,7 +186,11 @@
werrstr("tag not found");
return -1;
}
- rpcread(r);
+ if(s = _strfindattr(a, "error")){
+ werrstr("%s", s);
+ retrpc(r, RpcErrstr, (Fsstate*)r->fid->aux);
+ }else
+ rpcread(r);
return 0;
}
--- a/sys/src/cmd/auth/factotum/dat.h
+++ b/sys/src/cmd/auth/factotum/dat.h
@@ -177,6 +177,7 @@
void rpcstartlog(Attr*, Fsstate*, int);
void rpcread(Req*);
void rpcwrite(Req*);
+void retrpc(Req*, int, Fsstate*);
/* secstore.c */
int havesecstore(void);
--- a/sys/src/cmd/auth/factotum/fgui.c
+++ b/sys/src/cmd/auth/factotum/fgui.c
@@ -503,6 +503,7 @@
/* controls for needkey */
Control *msg;
Control *b_done;
+Control *b_cancel;
enum {
Pprivate= 1<<0,
Pneed= 1<<1,
@@ -607,13 +608,21 @@
b_done = createtextbutton(cs, "b_done");
chanprint(cs->ctl, "b_done border 1");
chanprint(cs->ctl, "b_done align center");
- chanprint(cs->ctl, "b_done text DONE");
+ chanprint(cs->ctl, "b_done text Done");
chanprint(cs->ctl, "b_done image green");
chanprint(cs->ctl, "b_done light green");
+ b_cancel = createtextbutton(cs, "b_cancel");
+ chanprint(cs->ctl, "b_cancel border 1");
+ chanprint(cs->ctl, "b_cancel align center");
+ chanprint(cs->ctl, "b_cancel text Cancel");
+ chanprint(cs->ctl, "b_cancel image i_white");
+ chanprint(cs->ctl, "b_cancel light i_black");
+
/* wire controls for input */
c = chancreate(sizeof(char*), 0);
controlwire(b_done, "event", c);
+ controlwire(b_cancel, "event", c);
for(i = 0; i < entries; i++)
if(entry[i].a->type == AttrQuery)
controlwire(entry[i].val, "event", c);
@@ -621,6 +630,7 @@
/* make the controls interactive */
activate(msg);
activate(b_done);
+ activate(b_cancel);
for(i = 0; i < entries; i++){
if(entry[i].a->type != AttrQuery)
continue;
@@ -689,13 +699,21 @@
lasty = r.max.y;
}
- /* done button */
mr.min.x -= 2*font->height;
- r.min.x = mr.min.x + mid - 3*font->height;
+
+ /* done button */
+ r.min.x = mr.min.x + mid - 9*font->height;
r.min.y = lasty+10;
r.max.x = r.min.x + 6*font->height;
r.max.y = r.min.y + font->height + 2;
chanprint(cs->ctl, "b_done rect %R\nb_done show", r);
+
+ /* cancel button */
+ r.min.x = mr.min.x + mid + 3*font->height;
+ r.min.y = lasty+10;
+ r.max.x = r.min.x + 6*font->height;
+ r.max.y = r.min.y + font->height + 2;
+ chanprint(cs->ctl, "b_cancel rect %R\nb_cancel show", r);
}
/*
@@ -735,12 +753,17 @@
for(;;){
val = recvp(c);
n = tokenize(val, args, nelem(args));
- if(n==3 && strcmp(args[1], "value")==0){ /* user hit 'enter' */
- free(val);
+ if(n==3 && strcmp(args[1], "value")==0) /* user hit 'enter' */
break;
- }
free(val);
}
+ if(strcmp(args[0], "b_cancel:") == 0){
+ free(val);
+ teardownneedkey(r);
+ fprint(r->rt->fd, "%A error='canceled by user'", r->tag);
+ return;
+ }
+ free(val);
/* get entry values */
for(i = 0; i < entries; i++){
--- a/sys/src/cmd/auth/factotum/rpc.c
+++ b/sys/src/cmd/auth/factotum/rpc.c
@@ -112,7 +112,7 @@
return;
}
-static void
+void
retrpc(Req *r, int ret, Fsstate *fss)
{
switch(ret){