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

Diff of /trunk/Src/wptKeylist.cpp

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

revision 161 by twoaday, Thu Jan 19 16:10:37 2006 UTC revision 273 by twoaday, Fri Dec 8 10:22:17 2006 UTC
# Line 83  key_array_search (key_array_s *ka, int i Line 83  key_array_search (key_array_s *ka, int i
83      int j;      int j;
84            
85      for (j = 0; j < items; j++) {      for (j = 0; j < items; j++) {
86          if (!strcmp (keyid, ka[j].keyid ))          if (!strcmp (keyid, ka[j].keyid))
87              return 1;                return 1;  
88      }      }
89      return 0;      return 0;
# Line 155  count_subkeys (gpgme_key_t key) Line 155  count_subkeys (gpgme_key_t key)
155  /* Return the self signature of the key @keyid.  /* Return the self signature of the key @keyid.
156     If first is set, the first self sig will be returned. */     If first is set, the first self sig will be returned. */
157  gpgme_key_sig_t  gpgme_key_sig_t
158  get_selfsig (gpgme_user_id_t uid, const char *keyid, int first)  get_selfsig (gpgme_key_sig_t sigs, const char *keyid, int first)
159  {  {
160      gpgme_key_sig_t s, self_sig=NULL;      gpgme_key_sig_t s, self_sig=NULL;
161      long timestamp=0;      long timestamp=0;
# Line 164  get_selfsig (gpgme_user_id_t uid, const Line 164  get_selfsig (gpgme_user_id_t uid, const
164      if (strlen (keyid) == 8)      if (strlen (keyid) == 8)
165          off = 8;          off = 8;
166    
167      for (s = uid->signatures; s; s = s->next) {      for (s = sigs; s; s = s->next) {
168          if (!strcmp (s->keyid+off, keyid) && s->timestamp > timestamp) {          if (!strcmp (s->keyid+off, keyid) && s->timestamp > timestamp) {
169              self_sig = s;              self_sig = s;
170              timestamp = s->timestamp;              timestamp = s->timestamp;
# Line 176  get_selfsig (gpgme_user_id_t uid, const Line 176  get_selfsig (gpgme_user_id_t uid, const
176  }  }
177    
178    
   
179  const char*  const char*
180  get_key_algo (gpgme_key_t key, int keyidx)  get_key_algo (gpgme_key_t key, int keyidx)
181  {  {
# Line 195  get_key_algo (gpgme_key_t key, int keyid Line 194  get_key_algo (gpgme_key_t key, int keyid
194      strcpy (alg, get_key_pubalgo (key->subkeys->pubkey_algo));      strcpy (alg, get_key_pubalgo (key->subkeys->pubkey_algo));
195      n = count_subkeys (key);      n = count_subkeys (key);
196      if (n > 1) {      if (n > 1) {
197          k = get_nth_key (key, n-1);          do {
198                k = get_nth_key (key, --n);
199                if (k->revoked || k->expired)
200                    continue;
201                else
202                    break;
203            } while (n > 0);
204          subalg = get_key_pubalgo (k->pubkey_algo);          subalg = get_key_pubalgo (k->pubkey_algo);
205          _snprintf (algo_id, DIM (algo_id)-1, "%s/%s", alg, subalg);          if (k == key->subkeys)
206                _snprintf (algo_id, DIM (algo_id)-1, "%s", subalg);
207            else
208                _snprintf (algo_id, DIM (algo_id)-1, "%s/%s", alg, subalg);
209          return algo_id;          return algo_id;
210      }      }
211      return get_key_pubalgo (key->subkeys->pubkey_algo);      return get_key_pubalgo (key->subkeys->pubkey_algo);
# Line 213  get_key_created (long timestamp) Line 221  get_key_created (long timestamp)
221    
222      if (timestamp < 1)      if (timestamp < 1)
223          return "????" "-??" "-??";          return "????" "-??" "-??";
224      dat = get_locale_date (timestamp, timebuf, sizeof (timebuf)-1);      dat = get_locale_date (timestamp, timebuf, DIM (timebuf)-1);
225      if (dat)      if (dat)
226          return dat;          return dat;
227        /* Fallback if locate date conversion failed. */
228      warp = localtime (&timestamp);      warp = localtime (&timestamp);
229      _snprintf (timebuf, sizeof timebuf - 1, "%04d-%02d-%02d",      _snprintf (timebuf, DIM (timebuf) - 1, "%04d-%02d-%02d",
230                 warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday);                 warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday);
231      return timebuf;      return timebuf;
232  }  }
# Line 233  get_key_expire_date (long timestamp) Line 242  get_key_expire_date (long timestamp)
242    
243      if (timestamp == 0)      if (timestamp == 0)
244          return _("Never");          return _("Never");
245      dat = get_locale_date (timestamp, timebuf, sizeof (timebuf)-1);      dat = get_locale_date (timestamp, timebuf, DIM (timebuf)-1);
246      if (dat)      if (dat)
247          return dat;          return dat;
248      warp = localtime (&timestamp);      warp = localtime (&timestamp);
249      _snprintf (timebuf, sizeof timebuf -1, "%04d-%02d-%02d",      _snprintf (timebuf, DIM (timebuf) -1, "%04d-%02d-%02d",
250                 warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday);                 warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday);
251      return timebuf;      return timebuf;
252  }  }
# Line 274  get_key_size (gpgme_key_t key, int keyid Line 283  get_key_size (gpgme_key_t key, int keyid
283      if (n > 1) {      if (n > 1) {
284          k = get_nth_key (key, n-1);          k = get_nth_key (key, n-1);
285          size_sub = k->length;          size_sub = k->length;
286          _snprintf (size_id, sizeof (size_id) - 1, "%d/%d",          _snprintf (size_id, DIM (size_id) - 1, "%d/%d",
287                      size_main, size_sub);                      size_main, size_sub);
288          return size_id;          return size_id;
289      }      }
290      _snprintf( size_id, sizeof (size_id) - 1, "%d", size_main );      _snprintf (size_id, DIM (size_id) - 1, "%d", size_main);
291      return size_id;      return size_id;
292  }  }
293    
# Line 303  get_key_pubalgo (gpgme_pubkey_algo_t alg Line 312  get_key_pubalgo (gpgme_pubkey_algo_t alg
312      case GPGME_PK_DSA: return "DSA";      case GPGME_PK_DSA: return "DSA";
313      case GPGME_PK_ELG:      case GPGME_PK_ELG:
314      case GPGME_PK_ELG_E: return "ELG";      case GPGME_PK_ELG_E: return "ELG";
315      case GPGME_PK_RSA: return "RSA";      case 0: /* XXX: do we still need this?? */
316        case GPGME_PK_RSA:
317        case GPGME_PK_RSA_S:
318        case GPGME_PK_RSA_E: return "RSA";
319      default: return "???";      default: return "???";
320      }      }
321      return "???";      return "???";
322  }  }
323    
324    
325  const char*  const char*
326  get_key_fpr (gpgme_key_t key)  get_key_fpr (gpgme_key_t key)
327  {  {
# Line 341  get_key_fpr (gpgme_key_t key) Line 354  get_key_fpr (gpgme_key_t key)
354  }  }
355    
356    
357    /* Extract the key ID from the fingerprint.
358       A long ID will be converted into a short ID. */
359    const char*
360    get_keyid_from_fpr (const char *fpr)
361    {
362        if (!fpr)
363            return "????????";
364        if (strlen (fpr) == 40)
365            fpr += 32;
366        else if (strlen (fpr) == 32)
367            fpr += 24;
368        else if (strlen (fpr) == 16)
369            fpr += 8;
370        else
371            return "????????";
372        return fpr;
373    }
374    
375    
376  const char*  const char*
377  get_key_trust2 (gpgme_key_t key, int val, int uididx, int listmode)  get_key_trust2 (gpgme_key_t key, int val, int uididx, int listmode)
378  {  {
# Line 355  get_key_trust2 (gpgme_key_t key, int val Line 387  get_key_trust2 (gpgme_key_t key, int val
387      case GPGME_VALIDITY_MARGINAL:      case GPGME_VALIDITY_MARGINAL:
388          return _("Marginal");          return _("Marginal");
389      case GPGME_VALIDITY_FULL:      case GPGME_VALIDITY_FULL:
     case GPGME_VALIDITY_ULTIMATE:  
390          return _("Full");          return _("Full");
391        case GPGME_VALIDITY_ULTIMATE:
392            return _("Ultimate");
393      }      }
394      return "";      return "";
395  }  }
396    
397    
398  const char *  const char*
399  get_key_trust (gpgme_key_t key, int uididx, int listmode)  get_key_trust (gpgme_key_t key, int uididx, int listmode)
400  {  {
401      return get_key_trust2 (key, 0, uididx, listmode);      return get_key_trust2 (key, 0, uididx, listmode);
402  }  }
403    
404    
405  const char *  const char*
406  get_key_trust_str (int val)  get_key_trust_str (int val)
407  {  {
408      return get_key_trust2 (NULL, val, 0, 0);      return get_key_trust2 (NULL, val, 0, 0);
# Line 408  get_key_status (gpgme_key_t key, int uid Line 441  get_key_status (gpgme_key_t key, int uid
441  }  }
442    
443    
444    /* Return human readable description of the key @key. */
445    char*
446    get_key_desc (gpgme_key_t key)
447    {
448        gpgme_key_t sk;
449        const char *state, *alg, *type;
450        char *p;
451    
452        /* XXX: problems with the German translation. */
453        state = "";
454        if (key->disabled)
455            state = _("Disabled");
456        if (key->expired)
457            state = _("Expired");
458        if (key->revoked)
459            state = _("Revoked");
460        alg = "OpenPGP";
461        if (strlen (key->subkeys->fpr) == 32)
462            alg = "RSA Legacy";
463        type = _("public key");
464        if (!get_seckey (key->subkeys->keyid+8, &sk))
465            type = _("key pair");
466        p = new char[strlen (state) + strlen (alg) + strlen (type) + 4 + 1];
467        if (!p)
468            BUG (0);
469        sprintf (p, "%s %s %s", state, alg, type);
470        return p;
471    }
472    
473    
474  /* Integer comparsion of @a and @b.  /* Integer comparsion of @a and @b.
475     Return values: same as in strcmp. */     Return values: same as in strcmp. */
476  static inline int  static inline int
# Line 439  get_ext_validity (gpgme_key_t k) Line 502  get_ext_validity (gpgme_key_t k)
502  static int CALLBACK  static int CALLBACK
503  keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby)  keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby)
504  {  {
505        struct keycache_s *aa, *bb;
506      gpgme_key_t a, b;      gpgme_key_t a, b;
507      int cmpresult = 0;      int cmpresult = 0;
508            
509      a = (gpgme_key_t)first;      aa = (struct keycache_s *)first;
510      b = (gpgme_key_t)second;      bb = (struct keycache_s *)second;
511      if (!a || !b)      if (!aa || !bb)
512          BUG (NULL);          BUG (NULL);
513        a = aa->key;
514        b = bb->key;
515            
516      switch (sortby & ~KEYLIST_SORT_DESC) {      switch (sortby & ~KEYLIST_SORT_DESC) {
517      case KEY_SORT_USERID:      case KEY_SORT_USERID:
# Line 498  keylist_cmp_cb (LPARAM first, LPARAM sec Line 564  keylist_cmp_cb (LPARAM first, LPARAM sec
564  }  }
565    
566    
 #if 0  
 /* Return the validity of the group @grp. */  
 static const char*  
 calc_validity (gpg_group_t grp)  
 {  
     int valid = 0;  
     gpg_member_t mbr;  
     gpgme_key_t key;  
   
     for (mbr = grp->list; mbr; mbr = mbr->next) {  
         if (get_pubkey (mbr->name, &key))  
             continue;  
         valid = key->uids->validity;  
         switch (valid) {  
         case GPGME_VALIDITY_MARGINAL:  
         case GPGME_VALIDITY_NEVER:  
         case GPGME_VALIDITY_UNDEFINED:  
             return get_key_trust2 (NULL, valid, 0, 0);  
         }  
     }  
     return _("Full");  
 }  
 #endif  
   
   
567  int  int
568  keylist_add_groups (listview_ctrl_t lv)  keylist_add_groups (listview_ctrl_t lv)
569  {  {
# Line 532  keylist_add_groups (listview_ctrl_t lv) Line 573  keylist_add_groups (listview_ctrl_t lv)
573    
574  /* Create a listview for listing keys. Use the mode given in @mode  /* Create a listview for listing keys. Use the mode given in @mode
575     and the control is given in @ctrl. */     and the control is given in @ctrl. */
576  static int  static void
577  keylist_build (listview_ctrl_t *r_lv, HWND ctrl, int mode)  keylist_build (listview_ctrl_t *r_lv, HWND ctrl, int mode)
578  {  {
579      struct listview_column_s klist_enc[] = {      struct listview_column_s klist_enc[] = {
# Line 554  keylist_build (listview_ctrl_t *r_lv, HW Line 595  keylist_build (listview_ctrl_t *r_lv, HW
595      {7, 72, (char *)_("Creation")},      {7, 72, (char *)_("Creation")},
596      {0, 0, NULL}      {0, 0, NULL}
597      };      };
598      HICON ico[2];      HICON ico[6];
599      listview_ctrl_t lv;      listview_ctrl_t lv;
600      listview_column_t col;      listview_column_t col;
601      int j, n = 0;      int j, n = 0, ext_chk = 0;
     int rc = 0;  
       
     rc = listview_new (&lv);  
     if (rc)  
         return rc;  
602            
603      lv->ctrl = ctrl;      listview_new (&lv, ctrl);
604      if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN)) {      if (mode & KEYLIST_ENCRYPT_MIN) {
605          col = klist_enc;          col = klist_enc;
606          n = (DIM(klist_enc) -1);          n = (DIM (klist_enc) -1);
607            ext_chk = 1;
608      }        }  
609      else if ((mode & KEYLIST_SIGN)) {      else if ((mode & KEYLIST_SIGN)) {
610          col = klist_enc;          col = klist_enc;
611          n = (DIM(klist_enc) - 1) - 1;          n = (DIM (klist_enc) - 1) - 1;
612            ext_chk = 1;
613      }      }
614      else {      else {
615          col = klist;          col = klist;
616          n = (DIM(klist) - 1);          n = (DIM (klist) - 1);
617      }      }
618            
619      for (j = 0; j < n; j++)      for (j = 0; j < n; j++)
620          listview_add_column (lv, &col[j]);          listview_add_column (lv, &col[j]);
621      listview_set_ext_style (lv);      listview_set_ext_style (lv);
622        if (ext_chk)
623            listview_set_chkbox_style (lv);
624      ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_PUBKEY);      ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_PUBKEY);
625      ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEYPAIR);      ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEYPAIR);
626      listview_set_image_list (lv, ico, 2);      ico[2] = LoadIcon (glob_hinst, (LPCTSTR)IDI_REV_KEYPAIR);
627        ico[3] = LoadIcon (glob_hinst, (LPCTSTR)IDI_REV_PUBKEY);
628        ico[4] = LoadIcon (glob_hinst, (LPCTSTR)IDI_SORT_DOWNARROW);
629        ico[5] = LoadIcon (glob_hinst, (LPCTSTR)IDI_SORT_UPARROW);
630        listview_set_image_list (lv, 22, 14, ico, DIM (ico));
631      listview_del_all_items (lv);      listview_del_all_items (lv);
632    
633      *r_lv = lv;      *r_lv = lv;
     return 0;  
634  }  }
635    
636    
# Line 597  keylist_load_keycache (listview_ctrl_t l Line 640  keylist_load_keycache (listview_ctrl_t l
640  {  {
641      gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);      gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);
642      gpgme_key_t key, skey;      gpgme_key_t key, skey;
643      const char * keyid;      struct keycache_s *c;
644        const char *keyid;
645    
646      if (pubkc && seckc) {      if (pubkc && seckc) {
647          gpg_keycache_rewind (pubkc);          gpg_keycache_rewind (pubkc);
648          while (!gpg_keycache_next_key (pubkc, 0, &key)) {          while (!gpg_keycache_next_key2 (pubkc, 0, &c, &key)) {
649              keyid = key->subkeys->keyid;              keyid = key->subkeys->keyid;
650              if (keyid && !gpg_keycache_find_key (seckc, keyid, 0, &skey))              if (keyid && !gpg_keycache_find_key (seckc, keyid, 0, &skey))
651                  keylist_add_key (lv, mode, key);                  keylist_add_key (lv, mode, c, key);
652          }                }      
653      }      }
654      else if (pubkc) {      else if (pubkc) {
655          gpg_keycache_rewind (pubkc);          gpg_keycache_rewind (pubkc);
656          while (!err) {              while (!err) {    
657              err = gpg_keycache_next_key (pubkc, 0, &key);              err = gpg_keycache_next_key2 (pubkc, 0, &c, &key);
658              if (!err)              if (!err)
659                  keylist_add_key (lv, mode, key);                  keylist_add_key (lv, mode, c, key);
660          }          }
661      }      }
662  }  }
# Line 625  keylist_load (HWND ctrl, gpg_keycache_t Line 669  keylist_load (HWND ctrl, gpg_keycache_t
669                int mode, int sortby)                int mode, int sortby)
670  {      {    
671      listview_ctrl_t lv;      listview_ctrl_t lv;
     int rc = 0;      
672    
673      rc = keylist_build (&lv, ctrl, mode);      keylist_build (&lv, ctrl, mode);  
     if (rc)  
         return NULL;              
674      keylist_load_keycache (lv, mode, pubkc, seckc);      keylist_load_keycache (lv, mode, pubkc, seckc);
675      keylist_sort (lv, sortby);      keylist_sort (lv, sortby);
676      if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN))      if (mode & KEYLIST_ENCRYPT_MIN)
677          keylist_add_groups (lv);          keylist_add_groups (lv);
678      return lv;      return lv;
679  }  }
# Line 663  keylist_delete (listview_ctrl_t lv) Line 704  keylist_delete (listview_ctrl_t lv)
704  static int  static int
705  find_secret_key (gpgme_key_t key)  find_secret_key (gpgme_key_t key)
706  {  {
     const char *keyid;  
707      winpt_key_s skey;      winpt_key_s skey;
708            
709      memset (&skey, 0, sizeof (skey));      if (!key->subkeys->keyid)
     keyid = key->subkeys->keyid;  
     if (!keyid)  
710          return 0;          return 0;
711      winpt_get_seckey (keyid, &skey);      memset (&skey, 0, sizeof (skey));
712        winpt_get_seckey (key->subkeys->keyid, &skey);
713      if (skey.ext && skey.ext->gloflags.divert_to_card)      if (skey.ext && skey.ext->gloflags.divert_to_card)
714          return 2;          return 2;
715      return skey.ctx? 1 : 0;      return skey.ctx? 1 : 0;
716  }  }
717    
718    
719    /* Enumeration for possible key icons. */
720    enum key_icontype_t {
721        IMG_KEY_PUB = 0,
722        IMG_KEY_PAIR = 1,
723        IMG_KEY_PAIR_REV = 2,
724        IMG_KEY_PUB_REV = 3
725    };
726    
727    
728  static int  static int
729  do_addkey (listview_ctrl_t lv, gpgme_key_t key, int uididx, int keyidx, int list)  key_get_image_id (gpgme_key_t key)
730    {
731        if (find_secret_key (key))    
732            return key->revoked ? IMG_KEY_PAIR_REV :IMG_KEY_PAIR;
733        if (key->revoked)
734            return IMG_KEY_PUB_REV;
735        return IMG_KEY_PUB;
736    }
737    
738    
739    static int
740    do_addkey (listview_ctrl_t lv, struct keycache_s *ctx, gpgme_key_t key,
741               int uididx, int keyidx, int list)
742  {      {    
743      LV_ITEM lvi;      LV_ITEM lvi;
744      gpgme_user_id_t u;      gpgme_user_id_t u;
745      gpgme_subkey_t k;      gpgme_subkey_t k;
746      char fmt[128], *p;      char *p;
747      const char *attr;      const char *attr;
748      u32 key_attr;      int idx = 0;
     int idx = 0;      
749    
750      /* we check the pubkey algorithm here to make sure that no ElGamal      /* we check the pubkey algorithm here to make sure that no ElGamal
751         sign+encrypt key is used in _any_ mode */         sign+encrypt key is used in _any_ mode */
# Line 695  do_addkey (listview_ctrl_t lv, gpgme_key Line 754  do_addkey (listview_ctrl_t lv, gpgme_key
754                     key->uids->name, key->subkeys->keyid);                     key->uids->name, key->subkeys->keyid);
755          return 0;          return 0;
756      }      }
757            
758      if (listview_add_item2 (lv, " ", (void *)key))      if (listview_add_item2 (lv, " ", (void *)ctx))
759          return WPTERR_GENERAL;          return WPTERR_GENERAL;
760    
761      attr = key->uids->uid;      attr = ctx->uids->uid;
762      memset (&lvi, 0, sizeof lvi);      memset (&lvi, 0, sizeof lvi);
763      lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;      lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
764      lvi.pszText = (char *)attr;      lvi.pszText = (char *)attr;
765      lvi.iImage = find_secret_key (key)? 1 : 0;      lvi.iImage = key_get_image_id (key);
766      lvi.lParam = (LPARAM )key;      lvi.lParam = (LPARAM )ctx;
767      if (ListView_SetItem (lv->ctrl, &lvi) == FALSE)      if (ListView_SetItem (lv->ctrl, &lvi) == FALSE)
768          return WPTERR_GENERAL;          return WPTERR_GENERAL;
769                    
770      if (uididx == -1) { /* request the primary user-id of the key. */      if (uididx == -1) { /* request the primary user-id of the key. */
771          attr = key->uids->uid;          attr = ctx->uids->uid;
772          uididx = 0;          uididx = 0;
773      }      }
774      else {      else {
# Line 723  do_addkey (listview_ctrl_t lv, gpgme_key Line 782  do_addkey (listview_ctrl_t lv, gpgme_key
782          attr = _("Invalid User ID");          attr = _("Invalid User ID");
783          listview_add_sub_item (lv, 0, idx++, attr);          listview_add_sub_item (lv, 0, idx++, attr);
784      }        }  
785      else {      else        
786          char *uid = utf8_to_wincp (attr, strlen (attr));          listview_add_sub_item (lv, 0, idx++, attr);
         if (uid) {  
             listview_add_sub_item (lv, 0, idx++, uid);  
             free (uid);  
         }  
     }  
787      k = get_nth_key (key, keyidx);      k = get_nth_key (key, keyidx);
788      if (k && k->keyid) {      if (k && k->keyid != NULL) {
789          _snprintf (fmt, sizeof fmt -1, "0x%s", k->keyid + 8);          char keyid[16+1];
790          listview_add_sub_item( lv, 0, idx++, fmt );  
791            _snprintf (keyid, DIM (keyid) -1, "0x%s", k->keyid + 8);
792            listview_add_sub_item (lv, 0, idx++, keyid);
793      }      }
794      if (list > 0) {      if (list > 0) {
795          key_attr = find_secret_key (key);          DWORD key_attr = find_secret_key (key);
796          if (!key_attr)          if (!key_attr)
797              attr = "pub";              attr = "pub";
798          else          else
# Line 745  do_addkey (listview_ctrl_t lv, gpgme_key Line 801  do_addkey (listview_ctrl_t lv, gpgme_key
801      }      }
802      if (lv->cols >= 2) {      if (lv->cols >= 2) {
803          attr = get_key_size (key, list == -1? keyidx+1 : 0);          attr = get_key_size (key, list == -1? keyidx+1 : 0);
804          if (attr)          if (attr != NULL)
805              listview_add_sub_item (lv, 0, idx++, attr);              listview_add_sub_item (lv, 0, idx++, attr);
806      }      }
807      if (lv->cols >= 3) {      if (lv->cols >= 3) {
808          attr = get_key_algo (key, list == -1? keyidx+1 : 0);          attr = get_key_algo (key, list == -1? keyidx+1 : 0);
809          if (attr)          if (attr != NULL)
810              listview_add_sub_item( lv, 0, idx++, attr);              listview_add_sub_item( lv, 0, idx++, attr);
811      }      }
812      if( lv->cols >= 4 ) {      if (lv->cols >= 4) {
813          p = get_key_status( key, uididx, list > 0? 1 : 0 );          p = get_key_status (key, uididx, list > 0? 1 : 0);
814          if (!p)          if (p != NULL)
815              return WPTERR_GENERAL;              listview_add_sub_item (lv, 0, idx++, p);
         listview_add_sub_item (lv, 0, idx++, p);  
816          free_if_alloc (p);          free_if_alloc (p);
817      }      }
818      if (lv->cols >= 5) {      if (lv->cols >= 5) {
819          attr = get_key_trust (key, uididx, list > 0? 1 : 0);          attr = get_key_trust (key, uididx, list > 0? 1 : 0);
820          listview_add_sub_item (lv, 0, idx++, attr);          listview_add_sub_item (lv, 0, idx++, attr);
821      }      }
822      if( lv->cols >= 6 ) {      if (lv->cols >= 6) {
823          k = get_nth_key (key, keyidx);          k = get_nth_key (key, keyidx);
824          key_attr = k->timestamp;          if (k->timestamp > 0) {
825          if( key_attr ) {              attr = get_key_created (k->timestamp);
826              attr = get_key_created (key_attr);              listview_add_sub_item (lv, 0, idx++, attr);
827              listview_add_sub_item( lv, 0, idx++, attr );          }
         }        
828      }      }
829    
830      return 0;      return 0;
# Line 784  keylist_upd_col (listview_ctrl_t lv, int Line 838  keylist_upd_col (listview_ctrl_t lv, int
838  {  {
839      gpgme_key_t key;      gpgme_key_t key;
840      const char *s;      const char *s;
841      char buf[32];      char buf[32], *p;
842      int i;      int i;
843    
844      for (i=0; i < listview_count_items (lv, 0); i++) {      for (i=0; i < listview_count_items (lv, 0); i++) {
845          key = (gpgme_key_t)listview_get_item2 (lv, i);          key = km_get_key_ptr (lv, i, NULL);
846          if (!key)          if (!key)
847              continue;              continue;
848          switch (col) {          switch (col) {
849          case KM_COL_KEYID:          case KM_COL_KEYID:
850              _snprintf (buf, sizeof (buf)-1, "0x%s", key->subkeys->keyid+8);              _snprintf (buf, DIM (buf)-1, "0x%s", key->subkeys->keyid+8);
851              listview_add_sub_item (lv, i, col, buf);              listview_add_sub_item (lv, i, col, buf);
852              break;              break;
853    
# Line 811  keylist_upd_col (listview_ctrl_t lv, int Line 865  keylist_upd_col (listview_ctrl_t lv, int
865              s = get_key_created (key->subkeys->timestamp);              s = get_key_created (key->subkeys->timestamp);
866              listview_add_sub_item (lv, i, col, s);              listview_add_sub_item (lv, i, col, s);
867              break;              break;
868    
869            case KM_COL_DESC:
870                p = get_key_desc (key);
871                listview_add_sub_item (lv, i, col, p);
872                free_if_alloc (p);
873                break;
874          }          }
875      }      }
876  }  }
# Line 819  keylist_upd_col (listview_ctrl_t lv, int Line 879  keylist_upd_col (listview_ctrl_t lv, int
879  /* Update the listview item at position @pos with the data from  /* Update the listview item at position @pos with the data from
880     the key @key. */     the key @key. */
881  void  void
882  keylist_upd_key (listview_ctrl_t lv, int pos, gpgme_key_t key)  keylist_upd_key (listview_ctrl_t lv, int pos,
883                     struct keycache_s *ctx, gpgme_key_t key)
884  {  {
885      const char *s;      const char *s;
886      char *uid;      char *p;
887      char tmp[32];      char tmp[32];
888    
889      listview_set_item2 (lv, pos, (void *)key);      listview_set_item2 (lv, pos, (void *)ctx);
890      /* the only mode we support is KYLIST_LIST in the Key Manager */      /* the only mode we support is KEYLIST_LIST in the Key Manager */
891            
892      s = key->uids->uid;      s = ctx->uids->uid;
893      if (s) {      if (s)
894          uid = utf8_to_wincp2 (s);          listview_add_sub_item (lv, pos, KM_COL_UID, s);
         listview_add_sub_item (lv, pos, 0, uid);  
         free (uid);  
     }  
895    
896      s = key->subkeys->keyid;      s = key->subkeys->keyid;
897      if (s) {      if (s) {
898          sprintf (tmp, "0x%s", s+8);          sprintf (tmp, "0x%s", s+8);
899          listview_add_sub_item (lv, pos, 1, tmp);          listview_add_sub_item (lv, pos, KM_COL_KEYID, tmp);
900      }      }
901    
902      s = find_secret_key (key)? "pub/sec" : "pub";      s = find_secret_key (key)? "pub/sec" : "pub";
903      listview_add_sub_item (lv, pos, 2, s);      listview_add_sub_item (lv, pos, KM_COL_TYPE, s);
904    
905      s = get_key_size (key, 0);      s = get_key_size (key, 0);
906      if (s)      if (s)
907          listview_add_sub_item (lv, pos, 3, s);          listview_add_sub_item (lv, pos, KM_COL_SIZE, s);
908    
909      s = get_key_algo (key, 0);      s = get_key_algo (key, 0);
910      if (s)      if (s)
911          listview_add_sub_item (lv, pos, 4, s);          listview_add_sub_item (lv, pos, KM_COL_CIPHER, s);
912    
913      s = get_key_status (key, 0, 1);      p = get_key_status (key, 0, 1);
914      if (s)      if (p) {
915          listview_add_sub_item (lv, pos, 5, s);          listview_add_sub_item (lv, pos, KM_COL_VALID, p);
916            free_if_alloc (p);
917        }
918    
919      s = get_key_trust (key, 0, 1);      s = get_key_trust (key, 0, 1);
920      if (s)      if (s)
921          listview_add_sub_item (lv, pos, 6, s);          listview_add_sub_item (lv, pos, KM_COL_TRUST, s);
922    
923      long t = key->subkeys->timestamp;      long t = key->subkeys->timestamp;
924      s = get_key_created (t);      s = get_key_created (t);
925      if (s)      if (s)
926          listview_add_sub_item (lv, pos, 7, s);          listview_add_sub_item (lv, pos, KM_COL_CREAT, s);
927  }  }
928    
929    
930  int  int
931  keylist_add_key (listview_ctrl_t lv, int mode, gpgme_key_t key)  keylist_add_key (listview_ctrl_t lv, int mode,
932                     struct keycache_s *ctx, gpgme_key_t key)
933  {  {
934      int uids, rc = 0, i;      int uids, rc = 0, i;
935      gpgme_subkey_t k;      gpgme_subkey_t k;
# Line 885  keylist_add_key (listview_ctrl_t lv, int Line 946  keylist_add_key (listview_ctrl_t lv, int
946    
947          if (mode & KEYLIST_ALL) {          if (mode & KEYLIST_ALL) {
948              uids = count_userids (key);              uids = count_userids (key);
949              rc = do_addkey (lv, key, uids, i, 0);              rc = do_addkey (lv, ctx, key, uids, i, 0);
950              if (rc)              if (rc)
951                  return rc;                  return rc;
952          }          }
953          else if (mode & KEYLIST_LIST)          else if (mode & KEYLIST_LIST)
954              return do_addkey (lv, key, -1, i, 1);              return do_addkey (lv, ctx, key, -1, i, 1);
955          else if (mode & KEYLIST_ENCRYPT) {          else if (mode & KEYLIST_ENCRYPT) {
956              if (k->can_encrypt && key_is_useable (k)) {              if (k->can_encrypt && key_is_useable (k)) {
957                  if (mode & KEYLIST_FLAG_FILE) {                  if (mode & KEYLIST_FLAG_FILE) {
958                      rc = do_addkey (lv, key, -1, i, -1);                      rc = do_addkey (lv, ctx, key, -1, i, -1);
959                      if (rc)                      if (rc)
960                          return rc;                          return rc;
961                  }                  }
962                  else {                  else {
963                      for (uids = 0;  uids < count_userids (key); uids++) {                      for (uids = 0;  uids < count_userids (key); uids++) {
964                          rc = do_addkey (lv, key, uids, i, -1);                          rc = do_addkey (lv, ctx, key, uids, i, -1);
965                          if (rc)                          if (rc)
966                              return rc;                              return rc;
967                      }                      }
# Line 910  keylist_add_key (listview_ctrl_t lv, int Line 971  keylist_add_key (listview_ctrl_t lv, int
971          else if (mode & KEYLIST_ENCRYPT_MIN) {          else if (mode & KEYLIST_ENCRYPT_MIN) {
972              if( k->can_encrypt && key_is_useable (k))              if( k->can_encrypt && key_is_useable (k))
973              {              {
974                  rc = do_addkey (lv, key, -1, i, -1);                  rc = do_addkey (lv, ctx, key, -1, i, -1);
975                  return rc;                  return rc;
976              }              }
977          }                }      
# Line 918  keylist_add_key (listview_ctrl_t lv, int Line 979  keylist_add_key (listview_ctrl_t lv, int
979              if (k->can_sign              if (k->can_sign
980                  && find_secret_key (key)                  && find_secret_key (key)
981                  && key_is_useable (k)) {                  && key_is_useable (k)) {
982                  rc = do_addkey (lv, key, -1, i, -1);                  rc = do_addkey (lv, ctx, key, -1, i, -1);
983                  if (rc)                  if (rc)
984                      return rc;                        return rc;  
985              }              }
# Line 956  key_check_validity (gpgme_key_t key) Line 1017  key_check_validity (gpgme_key_t key)
1017     fully trusted. @r_count returns the number of selected keys.     fully trusted. @r_count returns the number of selected keys.
1018     Return value: the key list on success, NULL otherwise. */     Return value: the key list on success, NULL otherwise. */
1019  gpgme_key_t*  gpgme_key_t*
1020  keylist_get_recipients (listview_ctrl_t lv, int *r_force_trust, int *r_count)  keylist_get_recipients (listview_ctrl_t lv, int *r_force_trust, size_t *r_count)
1021  {  {
1022      key_array_s *ka = NULL;      key_array_s *ka = NULL;
1023        keycache_s *c;
1024      gpgme_key_t *keybuf, key;      gpgme_key_t *keybuf, key;
1025      int count = 0, force_trust = 0;      size_t count = 0;
1026        int force_trust = 0;
1027      int n, j, ka_pos = 0, rc = 0;      int n, j, ka_pos = 0, rc = 0;
1028      int k_pos=0;      int k_pos=0;
1029    
# Line 970  keylist_get_recipients (listview_ctrl_t Line 1033  keylist_get_recipients (listview_ctrl_t
1033      if (!ka)      if (!ka)
1034          BUG (NULL);          BUG (NULL);
1035    
1036      keybuf = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t));      keybuf = (gpgme_key_t*)calloc (n+1, sizeof (gpgme_key_t));
1037      if (!keybuf)      if (!keybuf)
1038          BUG (NULL);          BUG (NULL);
1039                    
1040      for (j = 0; j < n; j++) {      for (j = 0; j < n; j++) {
1041          if (listview_get_item_state (lv, j) || n == 1) {          if (listview_get_item_state (lv, j) || n == 1) {
1042              key = (gpgme_key_t)listview_get_item2 (lv, j);              key = km_get_key_ptr (lv, j, &c);
1043              if (!key)              if (!key)
1044                  BUG (0);                  BUG (0);
1045              if (!key_check_validity (key) &&              if (!key_check_validity (key) &&
1046                  !key_array_search (ka, ka_pos, key->subkeys->keyid)) {                  !key_array_search (ka, ka_pos, key->subkeys->keyid)) {
1047                  char *warn = new char[512+strlen (key->uids->uid) + 1];                  char *warn = new char[512+strlen (c->uids->uid) + 1];
1048                  if (!warn)                  if (!warn)
1049                      BUG (0);                      BUG (0);
1050                  sprintf (warn,                  sprintf (warn,
# Line 989  keylist_get_recipients (listview_ctrl_t Line 1052  keylist_get_recipients (listview_ctrl_t
1052                        "named in the user ID.  If you *really* know what you are\n"                        "named in the user ID.  If you *really* know what you are\n"
1053                        "doing, you may answer the next question with yes\n"                        "doing, you may answer the next question with yes\n"
1054                        "\n"                        "\n"
1055                        "Use \"%s\" anyway?"), key->uids->uid);                        "Use \"%s\" anyway?"), c->uids->uid);
1056                  if (reg_prefs.always_trust)                  if (reg_prefs.always_trust)
1057                      rc = IDYES;                      rc = IDYES;
1058                  else                  else
# Line 1035  keylist_get_keyflags (gpgme_key_t key) Line 1098  keylist_get_keyflags (gpgme_key_t key)
1098    
1099    
1100  gpgme_key_t*  gpgme_key_t*
1101  keylist_enum_recipients (listview_ctrl_t lv,  int listype, int *r_count)  keylist_enum_recipients (listview_ctrl_t lv,  int listype, size_t *r_count)
1102  {  {
1103        struct keycache_s *c;
1104      gpgme_key_t *rset;      gpgme_key_t *rset;
1105      gpgme_key_t key;      gpgme_key_t key;
1106      int i, n, id, k_pos=0;      size_t k_pos = 0;
1107        int i, n, id;
1108    
1109      n = listview_count_items (lv, 0);      n = listview_count_items (lv, 0);
1110      if (!n)      if (!n)
1111          return 0;          return 0;
1112      rset = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t));      rset = (gpgme_key_t*)calloc (n+1, sizeof (gpgme_key_t));
1113      if (!rset)      if (!rset)
1114          BUG (NULL);          BUG (NULL);
1115      for (i = 0; i < n; i++) {      for (i = 0; i < n; i++) {
1116          if (!listview_get_item_state (lv, i))          if (!listview_get_item_state (lv, i))
1117              continue;              continue;
1118          key = (gpgme_key_t)listview_get_item2 (lv, i);          key = km_get_key_ptr (lv, i, &c);
         if (!key)  
             BUG (0);  
1119          switch (listype) {          switch (listype) {
1120          case KEYLIST_LIST:          case KEYLIST_LIST:
1121              if (keylist_get_keyflags (key) & KEYFLAG_REVOKED) {              if (keylist_get_keyflags (key) & KEYFLAG_REVOKED) {
1122                  id = printf_box (_("Recipients"), MB_INFO|MB_YESNO,                  id = printf_box (_("Recipients"), MB_INFO|MB_YESNO,
1123                  _("KeyID %s.\nDo you really want to export a revoked key?"),                  _("KeyID %s.\nDo you really want to export a revoked key?"),
1124                                   key->uids->uid);                                   c->uids->uid);
1125                  if (id == IDNO)                  if (id == IDNO)
1126                      continue;                      continue;
1127              }              }
# Line 1119  seclist_init (HWND dlg, int ctlid, int f Line 1182  seclist_init (HWND dlg, int ctlid, int f
1182          if (key->disabled || !key_is_useable (key->subkeys))          if (key->disabled || !key_is_useable (key->subkeys))
1183              continue;              continue;
1184    
1185          uid = utf8_to_wincp (id, strlen (id));          uid = utf8_to_native (id);
1186          size = strlen (uid) + strlen (keyid) + 32;          size = strlen (uid) + strlen (keyid) + 32;
1187          inf = new char[size+1];          inf = new char[size+1];
1188          if (!inf)          if (!inf)

Legend:
Removed from v.161  
changed lines
  Added in v.273

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26