/[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 23 by twoaday, Fri Sep 30 10:10:16 2005 UTC revision 24 by twoaday, Sat Oct 8 10:43:08 2005 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 Timo Schulz
3     *      Copyright (C) 2005 g10 Code GmbH
4   *   *
5   * This file is part of WinPT.   * This file is part of WinPT.
6   *   *
# Line 28  Line 29 
29  #include "wptCommonCtl.h"  #include "wptCommonCtl.h"
30  #include "wptContext.h"  #include "wptContext.h"
31  #include "wptKeyEdit.h"  #include "wptKeyEdit.h"
32    #include "wptErrors.h"
33    
34    
35  /* edit key callback for command 'keyserver' */  /* edit key callback for command 'keyserver' */
# Line 45  cmd_keyserv_handler (GpgKeyEdit *ctx, gp Line 47  cmd_keyserv_handler (GpgKeyEdit *ctx, gp
47      if (!strcmp (key, "passphrase.enter"))      if (!strcmp (key, "passphrase.enter"))
48          return ctx->pass;          return ctx->pass;
49      if (!strcmp (key, "keyedit.prompt")) {      if (!strcmp (key, "keyedit.prompt")) {
50          ctx->cmd_sent = 0;          ctx->reset ();
51          return "save";          return "save";
52      }      }
53    
# Line 58  cmd_sign_handler (GpgKeyEdit *ctx, gpgme Line 60  cmd_sign_handler (GpgKeyEdit *ctx, gpgme
60  {  {
61      static char buf[32];      static char buf[32];
62    
63        if (code == GPGME_STATUS_ALREADY_SIGNED)
64            ctx->setResultValue (GPG_EDITRES_ALREADY_SIGNED);
65    
66      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
67          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
68          switch (ctx->type) {          switch (ctx->type) {
# Line 93  cmd_sign_handler (GpgKeyEdit *ctx, gpgme Line 98  cmd_sign_handler (GpgKeyEdit *ctx, gpgme
98      if( !strcmp ( key, "passphrase.enter" ) )      if( !strcmp ( key, "passphrase.enter" ) )
99          return ctx->pass;          return ctx->pass;
100      if( !strcmp (key, "keyedit.prompt" ) ) {      if( !strcmp (key, "keyedit.prompt" ) ) {
101          ctx->cmd_sent = 0;          ctx->reset ();
102          return "save";          return "save";
103      }      }
104            
# Line 117  cmd_trust_handler (GpgKeyEdit *ctx, gpgm Line 122  cmd_trust_handler (GpgKeyEdit *ctx, gpgm
122          return buf;          return buf;
123      }      }
124      if (!strcmp (key, "keyedit.prompt")) {      if (!strcmp (key, "keyedit.prompt")) {
125          ctx->cmd_sent = 0;          ctx->reset ();
126          return "save";          return "save";
127      }      }
128    
# Line 144  cmd_adduid_handler (GpgKeyEdit *ctx, gpg Line 149  cmd_adduid_handler (GpgKeyEdit *ctx, gpg
149      if( !strcmp (key, "passphrase.enter" ) )      if( !strcmp (key, "passphrase.enter" ) )
150          return ctx->pass;          return ctx->pass;
151      if( !strcmp (key, "keyedit.prompt" ) ) {      if( !strcmp (key, "keyedit.prompt" ) ) {
152          ctx->cmd_sent = 0;          ctx->reset ();
153          return "save";          return "save";
154      }      }
155    
# Line 174  cmd_deluid_handler (GpgKeyEdit *ctx, gpg Line 179  cmd_deluid_handler (GpgKeyEdit *ctx, gpg
179      }      }
180      if( step == 3 && !strcmp ( key, "keyedit.prompt" ) ) {      if( step == 3 && !strcmp ( key, "keyedit.prompt" ) ) {
181          *r_step = step = 0;          *r_step = step = 0;
182            ctx->reset ();
183          return "save";          return "save";
184      }      }
185            
# Line 209  cmd_delsig_handler (GpgKeyEdit *ctx, gpg Line 215  cmd_delsig_handler (GpgKeyEdit *ctx, gpg
215          return "Y";          return "Y";
216      if (step == 2 && !strcmp (key, "keyedit.prompt")) {      if (step == 2 && !strcmp (key, "keyedit.prompt")) {
217          *r_step = step = 0;          *r_step = step = 0;
218            ctx->reset ();
219          return "save";          return "save";
220      }      }
221      return NULL;      return NULL;
# Line 237  cmd_delkey_handler (GpgKeyEdit *ctx, gpg Line 244  cmd_delkey_handler (GpgKeyEdit *ctx, gpg
244      }      }
245      if( step == 3 && !strcmp (key, "keyedit.prompt" ) ) {      if( step == 3 && !strcmp (key, "keyedit.prompt" ) ) {
246          *r_step = step = 0;          *r_step = step = 0;
247            ctx->reset ();
248          return "save";          return "save";
249      }      }
250            
# Line 269  cmd_addkey_handler (GpgKeyEdit *ctx, gpg Line 277  cmd_addkey_handler (GpgKeyEdit *ctx, gpg
277          return buf;                  return buf;        
278      }      }
279      if( !strcmp (key, "keyedit.prompt" ) ) {      if( !strcmp (key, "keyedit.prompt" ) ) {
280          ctx->cmd_sent = 0;          ctx->reset ();
281          return "save";          return "save";
282      }      }
283      return NULL;      return NULL;
# Line 292  cmd_passwd_handler (GpgKeyEdit *ctx, gpg Line 300  cmd_passwd_handler (GpgKeyEdit *ctx, gpg
300      if( !strcmp (key, "change_passwd.empty.okay" ))      if( !strcmp (key, "change_passwd.empty.okay" ))
301          return ctx->flags?  "Y" : "N";          return ctx->flags?  "Y" : "N";
302      if( !strcmp ( key, "keyedit.prompt" ) ) {      if( !strcmp ( key, "keyedit.prompt" ) ) {
303          ctx->cmd_sent = 0;          ctx->reset ();
304          return "save";          return "save";
305      }      }
306      return NULL;      return NULL;
# Line 325  cmd_setpref_handler (GpgKeyEdit *ctx, gp Line 333  cmd_setpref_handler (GpgKeyEdit *ctx, gp
333          return ctx->u.pref.passwd;          return ctx->u.pref.passwd;
334      if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 2) {      if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 2) {
335          ctx->u.pref.id = 0;          ctx->u.pref.id = 0;
336            ctx->reset ();
337          return "save";          return "save";
338      }      }
339  #endif  #endif
# Line 354  cmd_primary_handler (GpgKeyEdit *ctx, gp Line 363  cmd_primary_handler (GpgKeyEdit *ctx, gp
363      }      }
364      if( step == 3 && !strcmp (key, "keyedit.prompt" ) ) {      if( step == 3 && !strcmp (key, "keyedit.prompt" ) ) {
365          *r_step = step = 0;          *r_step = step = 0;
366            ctx->reset ();
367          return "save";          return "save";
368      }      }
369      return NULL;      return NULL;
# Line 391  cmd_expire_handler (GpgKeyEdit *ctx, gpg Line 401  cmd_expire_handler (GpgKeyEdit *ctx, gpg
401      }      }
402      if( step == 4 && !strcmp ( key, "keyedit.prompt" ) ) {      if( step == 4 && !strcmp ( key, "keyedit.prompt" ) ) {
403          *r_step = step = 0;          *r_step = step = 0;
404            ctx->reset ();
405          return "save";          return "save";
406      }      }
407            
# Line 440  cmd_revsig_handler (GpgKeyEdit *ctx, gpg Line 451  cmd_revsig_handler (GpgKeyEdit *ctx, gpg
451      }      }
452      if( step == 8 && !strcmp ( key, "keyedit.prompt" ) ) {      if( step == 8 && !strcmp ( key, "keyedit.prompt" ) ) {
453          *r_step = step = 0;          *r_step = step = 0;
454            ctx->reset ();
455          return "save";          return "save";
456      }      }
457            
# Line 486  cmd_revkey_handler (GpgKeyEdit *ctx, gpg Line 498  cmd_revkey_handler (GpgKeyEdit *ctx, gpg
498      }      }
499      if( step == 7 && !strcmp ( key, "keyedit.prompt" ) ) {      if( step == 7 && !strcmp ( key, "keyedit.prompt" ) ) {
500          *r_step = step = 0;          *r_step = step = 0;
501            ctx->reset ();
502          return "save";          return "save";
503      }      }
504      return NULL;      return NULL;
# Line 514  cmd_addrev_handler (GpgKeyEdit *ctx, gpg Line 527  cmd_addrev_handler (GpgKeyEdit *ctx, gpg
527      }      }
528      if (step == 3 && !strcmp (key, "keyedit.prompt")) {      if (step == 3 && !strcmp (key, "keyedit.prompt")) {
529          *r_step = step = 0;          *r_step = step = 0;
530            ctx->reset ();
531          return "save";          return "save";
532      }      }
533      return NULL;      return NULL;
# Line 534  cmd_addphoto_handler (GpgKeyEdit *ctx, g Line 548  cmd_addphoto_handler (GpgKeyEdit *ctx, g
548          return ctx->pass;          return ctx->pass;
549      if (!strcmp (key, "keyedit.prompt")) {      if (!strcmp (key, "keyedit.prompt")) {
550          *r_step = step = 0;          *r_step = step = 0;
551            ctx->reset ();
552          return "save";          return "save";
553      }      }
554      return NULL;      return NULL;
# Line 551  cmd_enable_disable_handler (GpgKeyEdit * Line 566  cmd_enable_disable_handler (GpgKeyEdit *
566          return "enable";          return "enable";
567      }      }
568      if (!strcmp (key, "keyedit.prompt")) {      if (!strcmp (key, "keyedit.prompt")) {
569          ctx->cmd_sent = 0;          ctx->reset ();
570          return "save";          return "save";
571      }      }
572      return NULL;      return NULL;
# Line 566  editkey_command_handler (void *opaque, g Line 581  editkey_command_handler (void *opaque, g
581      static int step = 0;      static int step = 0;
582      const char *out = NULL;      const char *out = NULL;
583      GpgKeyEdit *ke = (GpgKeyEdit *)opaque;      GpgKeyEdit *ke = (GpgKeyEdit *)opaque;
584        HANDLE hd = (HANDLE)fd;
585        DWORD n;
586            
587      if (!code || !ke)      if (!ke)
588          return gpg_error (GPG_ERR_INV_ARG);          return gpg_error (GPG_ERR_INV_ARG);
589            
590      switch (ke->type) {      switch (ke->type) {
# Line 581  editkey_command_handler (void *opaque, g Line 598  editkey_command_handler (void *opaque, g
598                    
599      case GPG_EDITKEY_TRUST:      case GPG_EDITKEY_TRUST:
600          out =  cmd_trust_handler (ke, code, key);          out =  cmd_trust_handler (ke, code, key);
601            log_debug ("key=%s out=%s\n", key, out);
602          break;          break;
603                    
604      case GPG_EDITKEY_ADDUID:      case GPG_EDITKEY_ADDUID:
# Line 646  editkey_command_handler (void *opaque, g Line 664  editkey_command_handler (void *opaque, g
664          break;          break;
665      }      }
666      if (out != NULL) {      if (out != NULL) {
667          write (fd, out, strlen (out));            WriteFile (hd, out, strlen (out), &n, NULL);    
668          write (fd, "\n", 1);          WriteFile (hd, "\n", 1, &n, NULL);
669            /* XXX: check return codes. */
670      }      }
671      return 0;      return 0;
672  }  }
# Line 658  gpgme_error_t Line 677  gpgme_error_t
677  gpg_editkey (gpgme_ctx_t ctx, gpgme_key_t key, GpgKeyEdit *ek)  gpg_editkey (gpgme_ctx_t ctx, gpgme_key_t key, GpgKeyEdit *ek)
678  {  {
679      gpgme_error_t err;      gpgme_error_t err;
680        gpgme_data_t out;
681        
682      err = gpgme_op_edit (ctx, key, editkey_command_handler, ek, NULL);      err = gpgme_data_new (&out);
683        if (err)
684            return err;
685        err = gpgme_op_edit (ctx, key, editkey_command_handler, ek, out);    
686    
687        gpgme_data_release (out);
688      return err;      return err;
689  }  }
690    

Legend:
Removed from v.23  
changed lines
  Added in v.24

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26