/[winpt]/trunk/Src/wptKeyEditCB.cpp
ViewVC logotype

Diff of /trunk/Src/wptKeyEditCB.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 181 by twoaday, Tue Mar 14 11:01:22 2006 UTC revision 200 by twoaday, Mon Apr 17 09:12:50 2006 UTC
# Line 1  Line 1 
1  /* wptKeyEditCB.cpp - Key edit callback handling  /* wptKeyEditCB.cpp - Key edit callback handling
2   *      Copyright (C) 2005 Timo Schulz   *      Copyright (C) 2005, 2006 Timo Schulz
3   *      Copyright (C) 2005 g10 Code GmbH   *      Copyright (C) 2005 g10 Code GmbH
4   *   *
5   * This file is part of WinPT.   * This file is part of WinPT.
# Line 41  enum editkey_error_t { Line 41  enum editkey_error_t {
41      EDITKEY_ERR_BAD_PASSPHRASE = 2      EDITKEY_ERR_BAD_PASSPHRASE = 2
42  };  };
43    
44    typedef gpgme_status_code_t status_code_t;
45    
46    /* 'notation' command handler. */
47    static const char*
48    cmd_notation_handler (GpgKeyEdit *ctx, status_code_t code, const char *key)
49    {
50        static char buf[32];
51    
52        if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
53            int uid = ctx->getUseridIndex ();
54            ctx->cmd_sent = 1;
55            if (uid != -1) {
56                sprintf (buf, "uid %d", ctx->getUseridIndex ());
57                return buf;
58            }
59        }
60        if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 0) {
61            ctx->cnt = 1;
62            return "notation";
63        }
64        if (!strcmp (key, "keyedit.add_notation"))
65            return ctx->notation;
66        if (!strcmp (key, "passphrase.enter"))
67            return ctx->pass;
68    
69        return NULL;
70    }
71    
72    
73  /* 'keyserver' command handler. */  /* 'keyserver' command handler. */
74  static const char*  static const char*
75  cmd_keyserv_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)  cmd_keyserv_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)
# Line 55  cmd_keyserv_handler (GpgKeyEdit *ctx, gp Line 84  cmd_keyserv_handler (GpgKeyEdit *ctx, gp
84              return buf;              return buf;
85          }          }
86      }      }
87      if (!strcmp (key, "keyedit.prompt") && !ctx->cnt) {      if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 0) {
88          ctx->cnt = 1;          ctx->cnt = 1;
89          return "keyserver";          return "keyserver";
90      }      }
# Line 90  cmd_sign_handler (GpgKeyEdit *ctx, gpgme Line 119  cmd_sign_handler (GpgKeyEdit *ctx, gpgme
119      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
120          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
121          switch (ctx->getType ()) {          switch (ctx->getType ()) {
122          case GPG_EDITKEY_SIGN: return "sign";          case GPG_EDITKEY_SIGN:      return "sign";
123          case GPG_EDITKEY_TSIGN: return "tsign";          case GPG_EDITKEY_TSIGN:     return "tsign";
124          case GPG_EDITKEY_LSIGN: return "lsign";          case GPG_EDITKEY_LSIGN:     return "lsign";
125          case GPG_EDITKEY_NRSIGN: return"nrsign";          case GPG_EDITKEY_NRSIGN:    return"nrsign";
126          case GPG_EDITKEY_NRLSIGN: return "nrlsign";          case GPG_EDITKEY_NRLSIGN:   return "nrlsign";
127          }          }
128      }      }
129      if (!strcmp (key, "sign_uid.class")) {      if (!strcmp (key, "sign_uid.class")) {
# Line 180  cmd_adduid_handler (GpgKeyEdit *ctx, gpg Line 209  cmd_adduid_handler (GpgKeyEdit *ctx, gpg
209    
210    
211  static const char*  static const char*
212  cmd_deluid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key,  cmd_deluid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
213                      int *r_step)                      const char *key)
214  {  {
215      static char buf[64];      static char buf[64];
     int step = *r_step;  
216    
217      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
218          sprintf (buf, "uid %d", ctx->getUseridIndex ());          sprintf (buf, "uid %d", ctx->getUseridIndex ());
219          *r_step = step = 1;          ctx->cnt = 1;
220          return buf;          return buf;
221      }      }
222      if (step == 1 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {
223          *r_step = step = 2;          ctx->cnt = 2;
224          return "deluid";          return "deluid";
225      }      }
226      if (step == 2 && !strcmp (key, "keyedit.remove.uid.okay")) {      if (ctx->cnt == 2 && !strcmp (key, "keyedit.remove.uid.okay")) {
227          *r_step = step = 3;          ctx->cnt = 3;
228          return "Y";          return "Y";
229      }      }
230      if (step == 3 && !strcmp (key, "keyedit.prompt" )) {      if (ctx->cnt == 3 && !strcmp (key, "keyedit.prompt" )) {
         *r_step = step = 0;  
231          ctx->reset ();          ctx->reset ();
232          return "save";          return "save";
233      }      }
# Line 210  cmd_deluid_handler (GpgKeyEdit *ctx, gpg Line 237  cmd_deluid_handler (GpgKeyEdit *ctx, gpg
237    
238    
239  static const char*  static const char*
240  cmd_delsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key,  cmd_delsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)
                     int *r_step)  
241  {  {
242      static char buf[64];      static char buf[64];
243      int step = *r_step;      static int sig_cnt = 0;
244    
245      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
246          sprintf (buf, "uid %d", ctx->getUseridIndex ());          sprintf (buf, "uid %d", ctx->getUseridIndex ());
247          *r_step = step = 1;          ctx->cnt = 1;
248          return buf;          return buf;
249      }      }
250      if (step == 1 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {
251          *r_step = step = 2;          ctx->cnt = 2;
252          return "delsig";          return "delsig";
253      }      }
254      if (!strcmp (key, "keyedit.delsig.unknown") ||      if (!strcmp (key, "keyedit.delsig.unknown") ||
255          !strcmp (key, "keyedit.delsig.valid")) {          !strcmp (key, "keyedit.delsig.valid")) {
256          if (++ctx->cnt == ctx->getSigIndex ())          if (++sig_cnt == ctx->getSigIndex ())
257              return "Y";              return "Y";
258          else          else
259              return "N";              return "N";
260      }      }
261      if (!strcmp (key, "keyedit.delsig.selfsig"))      if (!strcmp (key, "keyedit.delsig.selfsig"))
262          return "Y";          return "Y";
263      if (step == 2 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 2 && !strcmp (key, "keyedit.prompt")) {
264          *r_step = step = 0;          sig_cnt = 0;
265          ctx->reset ();          ctx->reset ();
266          return "save";          return "save";
267      }      }
# Line 246  cmd_delsig_handler (GpgKeyEdit *ctx, gpg Line 272  cmd_delsig_handler (GpgKeyEdit *ctx, gpg
272  /* 'delkey' command handler. */  /* 'delkey' command handler. */
273  static const char*  static const char*
274  cmd_delkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_delkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
275                      const char *key, int *r_step )                      const char *key)
276  {  {
277      static char buf[64];      static char buf[64];
     int step = *r_step;  
278    
279      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
280          sprintf (buf, "key %d", ctx->getKeyIndex ());          sprintf (buf, "key %d", ctx->getKeyIndex ());
281          *r_step = step = 1;          ctx->cnt = 1;
282          return buf;          return buf;
283      }      }
284      if (step == 1 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {
285          *r_step = step = 2;          ctx->cnt = 2;
286          return "delkey";          return "delkey";
287      }      }
288      if (step == 2 && !strcmp (key, "keyedit.remove.subkey.okay")) {      if (ctx->cnt == 2 && !strcmp (key, "keyedit.remove.subkey.okay")) {
289          *r_step = step = 3;          ctx->cnt = 3;
290          return "Y";          return "Y";
291      }      }
292      if (step == 3 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 3 && !strcmp (key, "keyedit.prompt")) {
         *r_step = step = 0;  
293          ctx->reset ();          ctx->reset ();
294          return "save";          return "save";
295      }      }
# Line 306  cmd_addkey_handler (GpgKeyEdit *ctx, gpg Line 330  cmd_addkey_handler (GpgKeyEdit *ctx, gpg
330      return NULL;      return NULL;
331  }  }
332    
333    
334  /* 'passwd' command handler. */  /* 'passwd' command handler. */
335  static const char*  static const char*
336  cmd_passwd_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)  cmd_passwd_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)
# Line 314  cmd_passwd_handler (GpgKeyEdit *ctx, gpg Line 339  cmd_passwd_handler (GpgKeyEdit *ctx, gpg
339          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
340          return "passwd";          return "passwd";
341      }      }
342      if (!ctx->cnt && !strcmp (key, "passphrase.enter")) {      if (ctx->cnt == 0 && !strcmp (key, "passphrase.enter")) {
343          ctx->cnt = 1;          ctx->cnt = 1;
344          return ctx->pass;          return ctx->pass;
345      }      }
# Line 342  cmd_setpref_handler (GpgKeyEdit *ctx, gp Line 367  cmd_setpref_handler (GpgKeyEdit *ctx, gp
367          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
368          return "";          return "";
369      }      }
370      if (!strcmp ( key, "keyedit.prompt") && ctx->u.pref.id == 0) {      if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 0) {
371          ctx->u.pref.id++;          ctx->u.pref.id++;
372          _snprintf (buf, sizeof buf-1, "setpref %s", ctx->u.pref.new_prefs);          _snprintf (buf, sizeof buf-1, "setpref %s", ctx->u.pref.new_prefs);
373          return buf;          return buf;
374      }      }
375      if (!strcmp ( key, "keyedit.prompt") && ctx->u.pref.id == 1) {      if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 1) {
376          ctx->u.pref.id++;          ctx->u.pref.id++;
377          return "updpref";          return "updpref";
378      }      }
379      if (!strcmp ( key, "keyedit.updpref.okay"))      if (!strcmp (key, "keyedit.updpref.okay"))
380          return "Y";          return "Y";
381      if (!strcmp (key, "passphrase.enter"))      if (!strcmp (key, "passphrase.enter"))
382          return ctx->u.pref.passwd;          return ctx->u.pref.passwd;
# Line 367  cmd_setpref_handler (GpgKeyEdit *ctx, gp Line 392  cmd_setpref_handler (GpgKeyEdit *ctx, gp
392    
393  /* 'primary' command handler. */  /* 'primary' command handler. */
394  static const char*  static const char*
395  cmd_primary_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_primary_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
396                       const char *key, int *r_step )                       const char *key)
397  {  {
398      static char buf[64];      static char buf[64];
     int step = *r_step;  
399    
400      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
401          sprintf (buf, "uid %d", ctx->getUseridIndex ());          sprintf (buf, "uid %d", ctx->getUseridIndex ());
402          *r_step = step = 1;          ctx->cnt = 1;
403          return buf;          return buf;
404      }      }
405      if (step == 1 && !strcmp (key, "keyedit.prompt" )) {      if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt" )) {
406          *r_step = step = 2;          ctx->cnt = 2;
407          return "primary";          return "primary";
408      }      }
409      if (step == 2 && !strcmp (key, "passphrase.enter")) {      if (ctx->cnt == 2 && !strcmp (key, "passphrase.enter")) {
410          *r_step = step = 3;          ctx->cnt = 3;
411          return ctx->pass;          return ctx->pass;
412      }      }
413      if (step == 3 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 3 && !strcmp (key, "keyedit.prompt")) {
         *r_step = step = 0;  
414          ctx->reset ();          ctx->reset ();
415          return "save";          return "save";
416      }      }
417      return NULL;      return NULL;
418  }  }
419    
420    
421  /* 'expire' command handler. */  /* 'expire' command handler. */
422  static const char*  static const char*
423  cmd_expire_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_expire_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
424                      const char *key, int *r_step )                      const char *key)
425  {  {
426      static char buf[64];      static char buf[64];
     int step = *r_step;  
427    
428      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
429          sprintf (buf, "key %d", ctx->getKeyIndex ());          sprintf (buf, "key %d", ctx->getKeyIndex ());
430          *r_step = step = 1;          ctx->cnt = 1;
431          return buf;          return buf;
432      }      }
433      if (step == 1 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {
434          *r_step = step = 2;          ctx->cnt = 2;
435          return "expire";          return "expire";
436      }      }
437      if( step == 2 && !strcmp ( key, "keygen.valid" ) ) {      if (ctx->cnt == 2 && !strcmp (key, "keygen.valid" )) {
438          *r_step = step = 3;          ctx->cnt = 3;
439          sprintf (buf, "%d", ctx->getValidDays ());          sprintf (buf, "%d", ctx->getValidDays ());
440          return buf;          return buf;
441      }      }
442      if (step == 3 && !strcmp (key, "passphrase.enter")) {      if (ctx->cnt == 3 && !strcmp (key, "passphrase.enter")) {
443          *r_step = step = 4;          ctx->cnt = 4;
444          return ctx->pass;          return ctx->pass;
445      }      }
446      if (step == 4 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 4 && !strcmp (key, "keyedit.prompt")) {
         *r_step = step = 0;  
447          ctx->reset ();          ctx->reset ();
448          return "save";          return "save";
449      }      }
# Line 433  cmd_expire_handler (GpgKeyEdit *ctx, gpg Line 455  cmd_expire_handler (GpgKeyEdit *ctx, gpg
455  /* 'revuid' command handler. */  /* 'revuid' command handler. */
456  const char*  const char*
457  cmd_revuid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_revuid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
458                      const char *key, int *r_step)                      const char *key)
459  {  {
460      static char buf[32];      static char buf[32];
     int step = *r_step;  
461            
462      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
463          *r_step = step = 1;          ctx->cnt = 1;
464          sprintf (buf, "uid %d", ctx->getUseridIndex ());          sprintf (buf, "uid %d", ctx->getUseridIndex ());
465          return buf;          return buf;
466      }      }
467      else if (step == 1 && !strcmp (key, "keyedit.prompt")) {      else if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {
468          *r_step = step = 2;          ctx->cnt = 2;
469          return "revuid";          return "revuid";
470      }      }
471      else if (step == 2 && !strcmp (key, "keyedit.revoke.uid.okay")) {      else if (ctx->cnt == 2 && !strcmp (key, "keyedit.revoke.uid.okay")) {
472          *r_step = step = 3;          ctx->cnt = 3;
473          return "Y";          return "Y";
474      }      }
475      else if (step == 3 && !strcmp (key, "ask_revocation_reason.code")) {      else if (ctx->cnt == 3 && !strcmp (key, "ask_revocation_reason.code")) {
476          *r_step = step = 4;          ctx->cnt = 4;
477          return "4";          return "4";
478      }      }
479      else if (step == 4 && !strcmp (key, "ask_revocation_reason.text")) {      else if (ctx->cnt == 4 && !strcmp (key, "ask_revocation_reason.text")) {
480          *r_step = step = 5;          ctx->cnt = 5;
481          return "";          return "";
482      }      }
483      else if (step == 5 && !strcmp (key, "ask_revocation_reason.okay")) {      else if (ctx->cnt == 5 && !strcmp (key, "ask_revocation_reason.okay")) {
484          *r_step = step = 6;          ctx->cnt = 6;
485          return "Y";          return "Y";
486      }      }
487      else if (step == 6 && !strcmp (key, "passphrase.enter")) {      else if (ctx->cnt == 6 && !strcmp (key, "passphrase.enter")) {
488          *r_step = step = 7;          ctx->cnt = 7;
489          return ctx->pass;          return ctx->pass;
490      }      }
491      else if (step == 7 && !strcmp (key, "keyedit.prompt")) {      else if (ctx->cnt == 7 && !strcmp (key, "keyedit.prompt")) {
         *r_step = step = 0;  
492          ctx->reset ();          ctx->reset ();
493          return "save";          return "save";
494      }      }
# Line 478  cmd_revuid_handler (GpgKeyEdit *ctx, gpg Line 498  cmd_revuid_handler (GpgKeyEdit *ctx, gpg
498    
499  const char*  const char*
500  cmd_revsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_revsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
501                      const char *key, int *r_step)                      const char *key)
502  {  {
503      static char buf[64];      static char buf[64];
     int step = *r_step;  
504            
505      if( step == 0 && !strcmp ( key, "keyedit.prompt" ) ) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt" )) {
506          sprintf( buf, "uid %d", ctx->getUseridIndex ());          sprintf( buf, "uid %d", ctx->getUseridIndex ());
507          *r_step = step = 1;          ctx->cnt = 1;
508          return buf;          return buf;
509      }      }
510      if( step == 1 && !strcmp ( key, "keyedit.prompt" ) ) {      if (ctx->cnt == 1 && !strcmp ( key, "keyedit.prompt" ) ) {
511          *r_step = step = 2;          ctx->cnt = 2;
512          return "revsig";          return "revsig";
513      }      }
514      if( step == 2 && !strcmp (key, "ask_revoke_sig.one" ) ) {      if (ctx->cnt == 2 && !strcmp (key, "ask_revoke_sig.one" ) ) {
515          *r_step = step = 3;          ctx->cnt = 3;
516          return "Y";          return "Y";
517      }      }
518      if( step == 3 && !strcmp (key, "ask_revoke_sig.okay" ) ) {      if (ctx->cnt == 3 && !strcmp (key, "ask_revoke_sig.okay" ) ) {
519          *r_step = step = 4;          ctx->cnt = 4;
520          return "Y";          return "Y";
521      }      }
522      if( step == 4 && !strcmp ( key, "ask_revocation_reason.code" ) ) {      if (ctx->cnt == 4 && !strcmp ( key, "ask_revocation_reason.code" ) ) {
523          *r_step = step = 5;          ctx->cnt = 5;
524          return "0";          return "0";
525      }      }
526      if( step == 5 && !strcmp ( key, "ask_revocation_reason.text" ) ) {      if (ctx->cnt == 5 && !strcmp ( key, "ask_revocation_reason.text" ) ) {
527          *r_step = step = 6;          ctx->cnt = 6;
528          return "";          return "";
529      }      }
530      if( step == 6 && !strcmp (key, "ask_revocation_reason.okay" ) ) {      if (ctx->cnt == 6 && !strcmp (key, "ask_revocation_reason.okay" ) ) {
531          *r_step = step = 7;          ctx->cnt = 7;
532          return "Y";          return "Y";
533      }      }
534      if( step == 7 && !strcmp (key, "passphrase.enter" ) ) {      if (ctx->cnt == 7 && !strcmp (key, "passphrase.enter" ) ) {
535          *r_step = step = 8;          ctx->cnt = 8;
536          return ctx->pass;          return ctx->pass;
537      }      }
538      if( step == 8 && !strcmp ( key, "keyedit.prompt" ) ) {      if (ctx->cnt == 8 && !strcmp ( key, "keyedit.prompt" ) ) {
         *r_step = step = 0;  
539          ctx->reset ();          ctx->reset ();
540          return "save";          return "save";
541      }      }
# Line 529  cmd_revsig_handler (GpgKeyEdit *ctx, gpg Line 547  cmd_revsig_handler (GpgKeyEdit *ctx, gpg
547  /* 'revoke' command handler. */  /* 'revoke' command handler. */
548  static const char *  static const char *
549  cmd_revkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_revkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
550                      const char * key, int *r_step)                      const char *key)
551  {  {
     int step = *r_step;  
552      static char buf[64];      static char buf[64];
553    
554      if( step == 0 && !strcmp ( key, "keyedit.prompt" ) ) {      if (ctx->cnt == 0 && !strcmp ( key, "keyedit.prompt" ) ) {
555          sprintf( buf, "key %d", ctx->getKeyIndex ());          sprintf( buf, "key %d", ctx->getKeyIndex ());
556          *r_step = step = 1;          ctx->cnt = 1;
557          return buf;          return buf;
558      }      }
559      if( step == 1 && !strcmp ( key, "keyedit.prompt" ) ) {      if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {
560          *r_step = step = 2;          ctx->cnt = 2;
561          return "revkey";          return "revkey";
562      }      }
563      if( step == 2 && !strcmp (key, "keyedit.revoke.subkey.okay" ) ) {      if (ctx->cnt == 2 && !strcmp (key, "keyedit.revoke.subkey.okay")) {
564          *r_step = step = 3;          ctx->cnt = 3;
565          return "Y";          return "Y";
566      }      }
567      if( step == 3 &&  !strcmp ( key, "ask_revocation_reason.code" ) ) {      if (ctx->cnt == 3 &&  !strcmp ( key, "ask_revocation_reason.code")) {
568          sprintf( buf, "%d", ctx->reason);          sprintf( buf, "%d", ctx->reason);
569          *r_step = step = 4;          ctx->cnt = 4;
570          return buf;          return buf;
571      }      }
572      if( step == 4 && !strcmp ( key, "ask_revocation_reason.text" ) ) {      if (ctx->cnt == 4 && !strcmp (key, "ask_revocation_reason.text")) {
573          *r_step = step = 5;          ctx->cnt = 5;
574          return "";          return "";
575      }      }
576      if( step == 5 && !strcmp (key, "ask_revocation_reason.okay" ) ) {      if (ctx->cnt == 5 && !strcmp (key, "ask_revocation_reason.okay")) {
577          *r_step = step = 6;          ctx->cnt = 6;
578          return "Y";          return "Y";
579      }      }
580      if( step == 6 && !strcmp (key, "passphrase.enter" ) ) {      if (ctx->cnt == 6 && !strcmp (key, "passphrase.enter")) {
581          *r_step = step = 7;          ctx->cnt = 7;
582          return ctx->pass;          return ctx->pass;
583      }      }
584      if( step == 7 && !strcmp ( key, "keyedit.prompt" ) ) {      if (ctx->cnt == 7 && !strcmp ( key, "keyedit.prompt")) {
         *r_step = step = 0;  
585          ctx->reset ();          ctx->reset ();
586          return "save";          return "save";
587      }      }
# Line 576  cmd_revkey_handler (GpgKeyEdit *ctx, gpg Line 592  cmd_revkey_handler (GpgKeyEdit *ctx, gpg
592  /* 'addrevoker' command handler. */  /* 'addrevoker' command handler. */
593  static const char *  static const char *
594  cmd_addrev_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_addrev_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
595                      const char *key, int *r_step)                      const char *key)
596  {  {
     int step = *r_step;  
597    
598      /* If the isuser already signed the key, send an empty      /* If the isuser already signed the key, send an empty
599             string and jump to quit. */             string and jump to quit. */
600      if (ctx->getResult () & EDITKEY_ERR_ALREADY_SIGNED      if (ctx->getResult () & EDITKEY_ERR_ALREADY_SIGNED
601          && *r_step != -1 && *r_step != 4) {          && ctx->cnt != -1 && ctx->cnt != 4) {
602          *r_step = step = -1;          ctx->cnt = -1;
603          return "";          return "";
604      }      }
605      if (*r_step == -1) {      if (ctx->cnt == -1) {
606          *r_step = step = 4;          ctx->cnt = 4;
607          return ""; /* empty value to abort. */          return ""; /* empty value to abort. */
608      }      }
609      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
610          *r_step = step = 1;          ctx->cnt = 1;
611          return "addrevoker";          return "addrevoker";
612      }      }
613      if (step == 1 && !strcmp (key, "keyedit.add_revoker")) {      if (ctx->cnt == 1 && !strcmp (key, "keyedit.add_revoker")) {
614          *r_step = step = 2;          ctx->cnt = 2;
615          return ctx->name;          return ctx->name;
616      }      }
617      if (step == 2 && !strcmp (key, "keyedit.add_revoker.okay")) {      if (ctx->cnt == 2 && !strcmp (key, "keyedit.add_revoker.okay")) {
618          *r_step = step = 3;          ctx->cnt = 3;
619          return "Y";          return "Y";
620      }      }
621      if (step == 3 && !strcmp (key, "passphrase.enter")) {      if (ctx->cnt == 3 && !strcmp (key, "passphrase.enter")) {
622          *r_step = step = 4;          ctx->cnt = 4;
623          return ctx->pass;          return ctx->pass;
624      }      }
625      if (step == 4 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 4 && !strcmp (key, "keyedit.prompt")) {
         *r_step = step = 0;  
626          ctx->reset ();          ctx->reset ();
627          return "save";          return "save";
628      }      }
# Line 662  cmd_enable_disable_handler (GpgKeyEdit * Line 676  cmd_enable_disable_handler (GpgKeyEdit *
676  {  {
677      if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) {      if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) {
678          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
679          if (mode)          return mode? "disable": "enable";
             return "disable";  
         return "enable";  
680      }      }
681      if (!strcmp (key, "keyedit.prompt")) {      if (!strcmp (key, "keyedit.prompt")) {
682          ctx->reset ();          ctx->reset ();
# Line 679  static gpgme_error_t Line 691  static gpgme_error_t
691  editkey_command_handler (void *opaque, gpgme_status_code_t code,  editkey_command_handler (void *opaque, gpgme_status_code_t code,
692                           const char *key, int fd)                           const char *key, int fd)
693  {  {
     static int step = 0; /* XXX use ke->cnt */  
694      const char *out = NULL;      const char *out = NULL;
695      GpgKeyEdit *ke = (GpgKeyEdit *)opaque;      GpgKeyEdit *ke = (GpgKeyEdit *)opaque;
696      HANDLE hd = (HANDLE)fd;      HANDLE hd = (HANDLE)fd;
# Line 710  editkey_command_handler (void *opaque, g Line 721  editkey_command_handler (void *opaque, g
721          if (!strcmp (key, "keyedit.prompt"))          if (!strcmp (key, "keyedit.prompt"))
722              WriteFile (hd, "quit\n", 5, &n, NULL);              WriteFile (hd, "quit\n", 5, &n, NULL);
723          ke->reset ();          ke->reset ();
         step = 0;  
724          return 0;          return 0;
725      }      }
726            
# Line 732  editkey_command_handler (void *opaque, g Line 742  editkey_command_handler (void *opaque, g
742          break;          break;
743                    
744      case GPG_EDITKEY_DELUID:      case GPG_EDITKEY_DELUID:
745          out =  cmd_deluid_handler (ke, code, key, &step);          out =  cmd_deluid_handler (ke, code, key);
746          break;          break;
747                    
748      case GPG_EDITKEY_DELSIG:      case GPG_EDITKEY_DELSIG:
749          out =  cmd_delsig_handler (ke, code, key, &step);          out =  cmd_delsig_handler (ke, code, key);
750          break;          break;
751    
752      case GPG_EDITKEY_DELKEY:      case GPG_EDITKEY_DELKEY:
753          out =  cmd_delkey_handler(ke, code, key, &step );          out =  cmd_delkey_handler(ke, code, key);
754          break;          break;
755                    
756      case GPG_EDITKEY_ADDKEY:      case GPG_EDITKEY_ADDKEY:
# Line 752  editkey_command_handler (void *opaque, g Line 762  editkey_command_handler (void *opaque, g
762          break;          break;
763                    
764      case GPG_EDITKEY_PRIMARY:      case GPG_EDITKEY_PRIMARY:
765          out =  cmd_primary_handler (ke, code, key, &step);          out =  cmd_primary_handler (ke, code, key);
766          break;          break;
767                    
768      case GPG_EDITKEY_EXPIRE:      case GPG_EDITKEY_EXPIRE:
769          out =  cmd_expire_handler (ke, code, key, &step);          out =  cmd_expire_handler (ke, code, key);
770          break;          break;
771    
772      case GPG_EDITKEY_REVSIG:      case GPG_EDITKEY_REVSIG:
773          out =  cmd_revsig_handler (ke, code, key, &step);          out =  cmd_revsig_handler (ke, code, key);
774          break;          break;
775    
776      case GPG_EDITKEY_REVKEY:      case GPG_EDITKEY_REVKEY:
777          out =  cmd_revkey_handler (ke, code, key, &step);          out =  cmd_revkey_handler (ke, code, key);
778          break;          break;
779                            
780      case GPG_EDITKEY_REVUID:      case GPG_EDITKEY_REVUID:
781          out = cmd_revuid_handler (ke, code, key, &step);          out = cmd_revuid_handler (ke, code, key);
782          break;          break;
783    
784      case GPG_EDITKEY_ADDREV:      case GPG_EDITKEY_ADDREV:
785          out =  cmd_addrev_handler (ke, code, key, &step);          out =  cmd_addrev_handler (ke, code, key);
786          break;          break;
787    
788      case GPG_EDITKEY_ADDPHOTO:      case GPG_EDITKEY_ADDPHOTO:
789          out =  cmd_addphoto_handler (ke, code, key);          out =  cmd_addphoto_handler (ke, code, key);
790          break;          break;
791    
792        case GPG_EDITKEY_NOTATION:
793            out = cmd_notation_handler (ke, code, key);
794            break;
795    
796      case GPG_EDITKEY_CLEAN:      case GPG_EDITKEY_CLEAN:
797          out = cmd_clean_handler (ke, code, key);          out = cmd_clean_handler (ke, code, key);
798          break;          break;
799    
800      case GPG_EDITKEY_ENABLE:      case GPG_EDITKEY_ENABLE:
801      case GPG_EDITKEY_DISABLE:      case GPG_EDITKEY_DISABLE:
802          out = cmd_enable_disable_handler (ke, code, key,          n = ke->getType () == GPG_EDITKEY_DISABLE? 1: 0;
803                                            ke->getType () == GPG_EDITKEY_DISABLE? 1: 0);          out = cmd_enable_disable_handler (ke, code, key, n);
804          break;          break;
805    
806      case GPG_EDITKEY_SETPREF:      case GPG_EDITKEY_SETPREF:
# Line 799  editkey_command_handler (void *opaque, g Line 813  editkey_command_handler (void *opaque, g
813      }      }
814    
815      if (out != NULL) {      if (out != NULL) {
         /* XXX: check return codes. */  
816          WriteFile (hd, out, strlen (out), &n, NULL);          WriteFile (hd, out, strlen (out), &n, NULL);
817          WriteFile (hd, "\n", 1, &n, NULL);          WriteFile (hd, "\n", 1, &n, NULL);
818      }      }

Legend:
Removed from v.181  
changed lines
  Added in v.200

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26