/[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 150 by twoaday, Wed Jan 18 11:52:45 2006 UTC revision 201 by twoaday, Sat Apr 22 18:30:24 2006 UTC
# Line 303  get_key_pubalgo (gpgme_pubkey_algo_t alg Line 303  get_key_pubalgo (gpgme_pubkey_algo_t alg
303      case GPGME_PK_DSA: return "DSA";      case GPGME_PK_DSA: return "DSA";
304      case GPGME_PK_ELG:      case GPGME_PK_ELG:
305      case GPGME_PK_ELG_E: return "ELG";      case GPGME_PK_ELG_E: return "ELG";
306        case 0: /* XXX: gpgme returned pubkey algo 0 for a RSA made sig. */
307      case GPGME_PK_RSA: return "RSA";      case GPGME_PK_RSA: return "RSA";
308      default: return "???";      default: return "???";
309      }      }
# Line 362  get_key_trust2 (gpgme_key_t key, int val Line 363  get_key_trust2 (gpgme_key_t key, int val
363  }  }
364    
365    
366  const char *  const char*
367  get_key_trust (gpgme_key_t key, int uididx, int listmode)  get_key_trust (gpgme_key_t key, int uididx, int listmode)
368  {  {
369      return get_key_trust2 (key, 0, uididx, listmode);      return get_key_trust2 (key, 0, uididx, listmode);
370  }  }
371    
372    
373  const char *  const char*
374  get_key_trust_str (int val)  get_key_trust_str (int val)
375  {  {
376      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 409  get_key_status (gpgme_key_t key, int uid
409  }  }
410    
411    
412    /* Return human readable description of the key @key. */
413    char*
414    get_key_desc (gpgme_key_t key)
415    {
416        gpgme_key_t sk;
417        const char *state, *alg, *type;
418        char *p;
419    
420        /* XXX: problems with the German translation. */
421        state = "";
422        if (key->disabled)
423            state = _("Disabled");
424        if (key->expired)
425            state = _("Expired");
426        if (key->revoked)
427            state = _("Revoked");
428        alg = "OpenPGP";
429        if (strlen (key->subkeys->fpr) == 32)
430            alg = "RSA Legacy";
431        type = _("public key");
432        if (!get_seckey (key->subkeys->keyid+8, &sk))
433            type = _("key pair");
434        p = new char[strlen (state) + strlen (alg) + strlen (type) + 4 + 1];
435        if (!p)
436            BUG (0);
437        sprintf (p, "%s %s %s", state, alg, type);
438        return p;
439    }
440    
441    
442  /* Integer comparsion of @a and @b.  /* Integer comparsion of @a and @b.
443     Return values: same as in strcmp. */     Return values: same as in strcmp. */
444  static inline int  static inline int
# Line 498  keylist_cmp_cb (LPARAM first, LPARAM sec Line 529  keylist_cmp_cb (LPARAM first, LPARAM sec
529  }  }
530    
531    
 #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  
   
   
532  int  int
533  keylist_add_groups (listview_ctrl_t lv)  keylist_add_groups (listview_ctrl_t lv)
534  {  {
# Line 557  keylist_build (listview_ctrl_t *r_lv, HW Line 563  keylist_build (listview_ctrl_t *r_lv, HW
563      HICON ico[2];      HICON ico[2];
564      listview_ctrl_t lv;      listview_ctrl_t lv;
565      listview_column_t col;      listview_column_t col;
566      int j, n = 0;      int j, n = 0, ext_chk = 0;
567      int rc = 0;      int rc = 0;
568            
569      rc = listview_new (&lv);      rc = listview_new (&lv);
# Line 565  keylist_build (listview_ctrl_t *r_lv, HW Line 571  keylist_build (listview_ctrl_t *r_lv, HW
571          return rc;          return rc;
572            
573      lv->ctrl = ctrl;      lv->ctrl = ctrl;
574      if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN)) {      if (mode & KEYLIST_ENCRYPT_MIN) {
575          col = klist_enc;          col = klist_enc;
576          n = (DIM(klist_enc) -1);          n = (DIM(klist_enc) -1);
577            ext_chk = 1;
578      }        }  
579      else if ((mode & KEYLIST_SIGN)) {      else if ((mode & KEYLIST_SIGN)) {
580          col = klist_enc;          col = klist_enc;
581          n = (DIM(klist_enc) - 1) - 1;          n = (DIM(klist_enc) - 1) - 1;
582            ext_chk = 1;
583      }      }
584      else {      else {
585          col = klist;          col = klist;
# Line 579  keylist_build (listview_ctrl_t *r_lv, HW Line 587  keylist_build (listview_ctrl_t *r_lv, HW
587      }      }
588            
589      for (j = 0; j < n; j++)      for (j = 0; j < n; j++)
590          listview_add_column (lv, &col[j]);          listview_add_column (lv, &col[j]);    
591      listview_set_ext_style (lv);      listview_set_ext_style (lv);
592        if (ext_chk)
593            listview_set_chkbox_style (lv);
594      ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_PUBKEY);      ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_PUBKEY);
595      ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEYPAIR);      ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEYPAIR);
596      listview_set_image_list (lv, ico, 2);      listview_set_image_list (lv, 22, 14, ico, 2);
597      listview_del_all_items (lv);      listview_del_all_items (lv);
598    
599      *r_lv = lv;      *r_lv = lv;
# Line 632  keylist_load (HWND ctrl, gpg_keycache_t Line 642  keylist_load (HWND ctrl, gpg_keycache_t
642          return NULL;                      return NULL;            
643      keylist_load_keycache (lv, mode, pubkc, seckc);      keylist_load_keycache (lv, mode, pubkc, seckc);
644      keylist_sort (lv, sortby);      keylist_sort (lv, sortby);
645      if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN))      if (mode & KEYLIST_ENCRYPT_MIN)
646          keylist_add_groups (lv);          keylist_add_groups (lv);
647      return lv;      return lv;
648  }  }
# Line 643  int Line 653  int
653  keylist_reload (listview_ctrl_t lv, gpg_keycache_t pubkc, int mode, int sortby)  keylist_reload (listview_ctrl_t lv, gpg_keycache_t pubkc, int mode, int sortby)
654  {  {
655      listview_del_all_items (lv);      listview_del_all_items (lv);
656      keylist_load_keycache( lv, mode, pubkc, NULL );      keylist_load_keycache (lv, mode, pubkc, NULL);
657      keylist_sort (lv, sortby);      keylist_sort (lv, sortby);
658      return 0;      return 0;
659  }  }
# Line 724  do_addkey (listview_ctrl_t lv, gpgme_key Line 734  do_addkey (listview_ctrl_t lv, gpgme_key
734          listview_add_sub_item (lv, 0, idx++, attr);          listview_add_sub_item (lv, 0, idx++, attr);
735      }        }  
736      else {      else {
737          char *uid = utf8_to_wincp (attr, strlen (attr));          char *uid = utf8_to_native (attr);
738          if (uid) {          if (uid) {
739              listview_add_sub_item (lv, 0, idx++, uid);              listview_add_sub_item (lv, 0, idx++, uid);
740              free (uid);              free (uid);
# Line 753  do_addkey (listview_ctrl_t lv, gpgme_key Line 763  do_addkey (listview_ctrl_t lv, gpgme_key
763          if (attr)          if (attr)
764              listview_add_sub_item( lv, 0, idx++, attr);              listview_add_sub_item( lv, 0, idx++, attr);
765      }      }
766      if( lv->cols >= 4 ) {      if (lv->cols >= 4) {
767          p = get_key_status( key, uididx, list > 0? 1 : 0 );          p = get_key_status( key, uididx, list > 0? 1 : 0 );
768          if (!p)          if (!p)
769              return WPTERR_GENERAL;              return WPTERR_GENERAL;
# Line 784  keylist_upd_col (listview_ctrl_t lv, int Line 794  keylist_upd_col (listview_ctrl_t lv, int
794  {  {
795      gpgme_key_t key;      gpgme_key_t key;
796      const char *s;      const char *s;
797      char buf[32];      char buf[32], *p;
798      int i;      int i;
799    
800      for (i=0; i < listview_count_items (lv, 0); i++) {      for (i=0; i < listview_count_items (lv, 0); i++) {
# Line 811  keylist_upd_col (listview_ctrl_t lv, int Line 821  keylist_upd_col (listview_ctrl_t lv, int
821              s = get_key_created (key->subkeys->timestamp);              s = get_key_created (key->subkeys->timestamp);
822              listview_add_sub_item (lv, i, col, s);              listview_add_sub_item (lv, i, col, s);
823              break;              break;
824    
825            case KM_COL_DESC:
826                p = get_key_desc (key);
827                listview_add_sub_item (lv, i, col, p);
828                free_if_alloc (p);
829                break;
830          }          }
831      }      }
832  }  }
# Line 822  void Line 838  void
838  keylist_upd_key (listview_ctrl_t lv, int pos, gpgme_key_t key)  keylist_upd_key (listview_ctrl_t lv, int pos, gpgme_key_t key)
839  {  {
840      const char *s;      const char *s;
841      char *uid;      char *uid, *p;
842      char tmp[32];      char tmp[32];
843    
844      listview_set_item2 (lv, pos, (void *)key);      listview_set_item2 (lv, pos, (void *)key);
# Line 830  keylist_upd_key (listview_ctrl_t lv, int Line 846  keylist_upd_key (listview_ctrl_t lv, int
846            
847      s = key->uids->uid;      s = key->uids->uid;
848      if (s) {      if (s) {
849          uid = utf8_to_wincp2 (s);          uid = utf8_to_native (s);
850          listview_add_sub_item (lv, pos, 0, uid);          listview_add_sub_item (lv, pos, KM_COL_UID, uid);
851          free (uid);          free (uid);
852      }      }
853    
854      s = key->subkeys->keyid;      s = key->subkeys->keyid;
855      if (s) {      if (s) {
856          sprintf (tmp, "0x%s", s+8);          sprintf (tmp, "0x%s", s+8);
857          listview_add_sub_item (lv, pos, 1, tmp);          listview_add_sub_item (lv, pos, KM_COL_KEYID, tmp);
858      }      }
859    
860      s = find_secret_key (key)? "pub/sec" : "pub";      s = find_secret_key (key)? "pub/sec" : "pub";
861      listview_add_sub_item (lv, pos, 2, s);      listview_add_sub_item (lv, pos, KM_COL_TYPE, s);
862    
863      s = get_key_size (key, 0);      s = get_key_size (key, 0);
864      if (s)      if (s)
865          listview_add_sub_item (lv, pos, 3, s);          listview_add_sub_item (lv, pos, KM_COL_SIZE, s);
866    
867      s = get_key_algo (key, 0);      s = get_key_algo (key, 0);
868      if (s)      if (s)
869          listview_add_sub_item (lv, pos, 4, s);          listview_add_sub_item (lv, pos, KM_COL_CIPHER, s);
870    
871      s = get_key_status (key, 0, 1);      p = get_key_status (key, 0, 1);
872      if (s)      if (p) {
873          listview_add_sub_item (lv, pos, 5, s);          listview_add_sub_item (lv, pos, KM_COL_VALID, p);
874            free_if_alloc (p);
875        }
876    
877      s = get_key_trust (key, 0, 1);      s = get_key_trust (key, 0, 1);
878      if (s)      if (s)
879          listview_add_sub_item (lv, pos, 6, s);          listview_add_sub_item (lv, pos, KM_COL_TRUST, s);
880    
881      long t = key->subkeys->timestamp;      long t = key->subkeys->timestamp;
882      s = get_key_created (t);      s = get_key_created (t);
883      if (s)      if (s)
884          listview_add_sub_item (lv, pos, 7, s);          listview_add_sub_item (lv, pos, KM_COL_CREAT, s);
885  }  }
886    
887    
# Line 970  keylist_get_recipients (listview_ctrl_t Line 988  keylist_get_recipients (listview_ctrl_t
988      if (!ka)      if (!ka)
989          BUG (NULL);          BUG (NULL);
990    
991      keybuf = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t));      keybuf = (gpgme_key_t*)calloc (n+1, sizeof (gpgme_key_t));
992      if (!keybuf)      if (!keybuf)
993          BUG (NULL);          BUG (NULL);
994                    
# Line 981  keylist_get_recipients (listview_ctrl_t Line 999  keylist_get_recipients (listview_ctrl_t
999                  BUG (0);                  BUG (0);
1000              if (!key_check_validity (key) &&              if (!key_check_validity (key) &&
1001                  !key_array_search (ka, ka_pos, key->subkeys->keyid)) {                  !key_array_search (ka, ka_pos, key->subkeys->keyid)) {
1002                  char *warn = new char[512+strlen (key->uids->uid) + 1];                  char *utf8_uid = utf8_to_native (key->uids->uid);
1003                    char *warn = new char[512+strlen (utf8_uid) + 1];
1004                  if (!warn)                  if (!warn)
1005                      BUG (0);                      BUG (0);
1006                  sprintf (warn,                  sprintf (warn,
# Line 989  keylist_get_recipients (listview_ctrl_t Line 1008  keylist_get_recipients (listview_ctrl_t
1008                        "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"
1009                        "doing, you may answer the next question with yes\n"                        "doing, you may answer the next question with yes\n"
1010                        "\n"                        "\n"
1011                        "Use \"%s\" anyway?"), key->uids->uid);                        "Use \"%s\" anyway?"), utf8_uid);
1012                  if (reg_prefs.always_trust)                  if (reg_prefs.always_trust)
1013                      rc = IDYES;                      rc = IDYES;
1014                  else                  else
# Line 1001  keylist_get_recipients (listview_ctrl_t Line 1020  keylist_get_recipients (listview_ctrl_t
1020                      strcpy (ka[ka_pos++].keyid, key->subkeys->keyid);                      strcpy (ka[ka_pos++].keyid, key->subkeys->keyid);
1021                      count++;                      count++;
1022                  }                  }
1023                    safe_free (utf8_uid);
1024                  free_if_alloc (warn);                  free_if_alloc (warn);
1025              }              }
1026              else {              else {
# Line 1044  keylist_enum_recipients (listview_ctrl_t Line 1064  keylist_enum_recipients (listview_ctrl_t
1064      n = listview_count_items (lv, 0);      n = listview_count_items (lv, 0);
1065      if (!n)      if (!n)
1066          return 0;          return 0;
1067      rset = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t));      rset = (gpgme_key_t*)calloc (n+1, sizeof (gpgme_key_t));
1068      if (!rset)      if (!rset)
1069          BUG (NULL);          BUG (NULL);
1070      for (i = 0; i < n; i++) {      for (i = 0; i < n; i++) {
# Line 1119  seclist_init (HWND dlg, int ctlid, int f Line 1139  seclist_init (HWND dlg, int ctlid, int f
1139          if (key->disabled || !key_is_useable (key->subkeys))          if (key->disabled || !key_is_useable (key->subkeys))
1140              continue;              continue;
1141    
1142          uid = utf8_to_wincp (id, strlen (id));          uid = utf8_to_native (id);
1143          size = strlen (uid) + strlen (keyid) + 32;          size = strlen (uid) + strlen (keyid) + 32;
1144          inf = new char[size+1];          inf = new char[size+1];
1145          if (!inf)          if (!inf)

Legend:
Removed from v.150  
changed lines
  Added in v.201

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26