/[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 105 by twoaday, Wed Nov 30 10:22:00 2005 UTC revision 129 by twoaday, Fri Dec 30 13:56:10 2005 UTC
# Line 18  Line 18 
18   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
19   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20   */   */
21    
22  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
23  #include <config.h>  #include <config.h>
24  #endif  #endif
# Line 200  const char* Line 201  const char*
201  get_key_created (long timestamp)  get_key_created (long timestamp)
202  {  {
203      static char timebuf[128];      static char timebuf[128];
204        const char *dat;
205      struct tm *warp;      struct tm *warp;
206    
207      if (timestamp == 0 || timestamp == -1)      if (timestamp == 0 || timestamp == -1)
208          return "????" "-??" "-??";          return "????" "-??" "-??";
209      warp = localtime( &timestamp );      dat = get_locale_date (timestamp, timebuf, sizeof (timebuf)-1);
210      _snprintf( timebuf, sizeof timebuf - 1, "%04d-%02d-%02d",      if (dat)
211                  warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday );          return dat;
212        warp = localtime (&timestamp);
213        _snprintf (timebuf, sizeof timebuf - 1, "%04d-%02d-%02d",
214                   warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday);
215      return timebuf;      return timebuf;
216  } /* get_key_created */  }
217    
218    
219  /* Return a string presentation of the time @timestamp. */  /* Return a string presentation of the time @timestamp. */
# Line 237  get_key_type (gpgme_key_t key) Line 242  get_key_type (gpgme_key_t key)
242      else if (type == 2)      else if (type == 2)
243          return _("Key Pair (Card)");          return _("Key Pair (Card)");
244      return _("Public Key");      return _("Public Key");
245  } /* get_key_type */  }
246    
247    
248  const char*  const char*
# Line 263  get_key_size (gpgme_key_t key, int keyid Line 268  get_key_size (gpgme_key_t key, int keyid
268      }      }
269      _snprintf( size_id, sizeof (size_id) - 1, "%d", size_main );      _snprintf( size_id, sizeof (size_id) - 1, "%d", size_main );
270      return size_id;      return size_id;
271  } /* get_key_size */  }
272    
273    
274  const char*  const char*
275    get_key_pubalgo2 (gpgme_pubkey_algo_t alg)
276    {
277        switch (alg) {
278        case GPGME_PK_DSA: return "D";
279        case GPGME_PK_RSA: return "R";
280        case GPGME_PK_ELG: return "G";
281        default: return "?";
282        }
283        return "?";
284    }
285    
286    const char*
287  get_key_pubalgo (gpgme_pubkey_algo_t alg)  get_key_pubalgo (gpgme_pubkey_algo_t alg)
288  {  {
289      switch (alg) {      switch (alg) {
# Line 308  get_key_fpr (gpgme_key_t key) Line 325  get_key_fpr (gpgme_key_t key)
325          }          }
326      }      }
327      return fpr_md;      return fpr_md;
328  } /* get_key_fpr */  }
329    
330    
331  const char *  const char *
# Line 358  get_key_status (gpgme_key_t key, int uid Line 375  get_key_status (gpgme_key_t key, int uid
375          uididx = 0;          uididx = 0;
376      if (listmode) {      if (listmode) {
377          const char *s;          const char *s;
           
378          if (key->revoked)          if (key->revoked)
379              s = _("Revoked");              s = _("Revoked");
380          else if (key->expired)          else if (key->expired)
# Line 367  get_key_status (gpgme_key_t key, int uid Line 383  get_key_status (gpgme_key_t key, int uid
383              s = _("Disabled");              s = _("Disabled");
384          else          else
385              s = "";              s = "";
           
386          /* if the key has a special status, we don't continue to figure out          /* if the key has a special status, we don't continue to figure out
387             what any user-id validities. */             what any user-id validities. */
388          if (*s)          if (*s)
# Line 472  keylist_cmp_cb (LPARAM first, LPARAM sec Line 487  keylist_cmp_cb (LPARAM first, LPARAM sec
487  static const char*  static const char*
488  calc_validity (gpg_group_t grp)  calc_validity (gpg_group_t grp)
489  {  {
490      int valid=0;      int valid = 0;
491      gpg_member_t mbr;      gpg_member_t mbr;
492      gpgme_key_t key;      gpgme_key_t key;
493    
# Line 532  keylist_build (listview_ctrl_t *r_lv, HW Line 547  keylist_build (listview_ctrl_t *r_lv, HW
547      };      };
548    
549      struct listview_column_s klist[] = {      struct listview_column_s klist[] = {
550      {0, 242, (char *)_("User ID")},      {0, 240, (char *)_("User ID")},
551      {1, 78, (char *)_("Key ID")},      {1, 78, (char *)_("Key ID")},
552      {2, 52, (char *)_("Type")},          {2, 52, (char *)_("Type")},    
553      {3, 68, (char *)_("Size")},      {3, 66, (char *)_("Size")},
554      {4, 66, (char *)_("Cipher")},      {4, 60, (char *)_("Cipher")},
555      {5, 70, (char *)_("Validity")},      {5, 66, (char *)_("Validity")},
556      {6, 40, (char *)_("Trust")},      {6, 58, (char *)_("Trust")},
557      {7, 72, (char *)_("Creation")},      {7, 72, (char *)_("Creation")},
558      {0, 0, NULL}      {0, 0, NULL}
559      };      };
# Line 546  keylist_build (listview_ctrl_t *r_lv, HW Line 561  keylist_build (listview_ctrl_t *r_lv, HW
561      listview_ctrl_t lv;      listview_ctrl_t lv;
562      listview_column_t col;      listview_column_t col;
563      int j, n = 0;      int j, n = 0;
     int kl_nolist = 0;  
564      int rc = 0;      int rc = 0;
565            
566      rc = listview_new (&lv);      rc = listview_new (&lv);
# Line 676  do_addkey (listview_ctrl_t lv, gpgme_key Line 690  do_addkey (listview_ctrl_t lv, gpgme_key
690      /* we check the pubkey algorithm here to make sure that no ElGamal      /* we check the pubkey algorithm here to make sure that no ElGamal
691         sign+encrypt key is used in _any_ mode */         sign+encrypt key is used in _any_ mode */
692      if (list != 1 && key->subkeys->pubkey_algo == GPGME_PK_ELG) {      if (list != 1 && key->subkeys->pubkey_algo == GPGME_PK_ELG) {
693          log_debug ("ElGamal (E+S) key found: %s (%s)\n",          log_debug ("ElGamal (E+S) key found: %s (%s)\n",
694                     key->uids->name, key->subkeys->keyid);                     key->uids->name, key->subkeys->keyid);
695          return 0;          return 0;
696      }      }
697    
698                    
699      if (listview_add_item2 (lv, " ", (void *)key))            if (listview_add_item2 (lv, " ", (void *)key))
700          return WPTERR_GENERAL;          return WPTERR_GENERAL;
701            
702      attr = key->uids->uid;      attr = key->uids->uid;
703      memset (&lvi, 0, sizeof lvi);      memset (&lvi, 0, sizeof lvi);
704      lvi.mask = LVIF_TEXT | LVIF_PARAM;      lvi.mask = LVIF_TEXT | LVIF_PARAM;
705      lvi.pszText = (char *)attr;      lvi.pszText = (char *)attr;
706      lvi.lParam = (LPARAM )key;      lvi.lParam = (LPARAM )key;
707      if (ListView_SetItem( lv->ctrl, &lvi ) == FALSE)      if (ListView_SetItem (lv->ctrl, &lvi) == FALSE)
708          return WPTERR_GENERAL;          return WPTERR_GENERAL;
709                    
710      if (uididx == -1) { /* request the primary user-id of the key. */      if (uididx == -1) { /* request the primary user-id of the key. */
# Line 762  do_addkey (listview_ctrl_t lv, gpgme_key Line 776  do_addkey (listview_ctrl_t lv, gpgme_key
776  }  }
777    
778    
779    /* Update a single column @col but for each element in the
780       listview @lv. */
781    void
782    keylist_upd_col (listview_ctrl_t lv, int col)
783    {
784        gpgme_key_t key;
785        const char *s;
786        char buf[32];
787        int i;
788    
789        for (i=0; i < listview_count_items (lv, 0); i++) {
790            key = (gpgme_key_t)listview_get_item2 (lv, i);
791            if (!key)
792                continue;
793            switch (col) {
794            case KM_COL_KEYID:
795                _snprintf (buf, sizeof (buf)-1, "0x%s", key->subkeys->keyid+8);
796                listview_add_sub_item (lv, i, col, buf);
797                break;
798    
799            case KM_COL_CIPHER:
800                s = get_key_algo (key, 0);
801                listview_add_sub_item (lv, i, col, s);
802                break;
803    
804            case KM_COL_TYPE:
805                s = find_secret_key (key)? "pub/sec" : "pub";
806                listview_add_sub_item (lv, i, col, s);
807                break;
808    
809            case KM_COL_CREAT:
810                s = get_key_created (key->subkeys->timestamp);
811                listview_add_sub_item (lv, i, col, s);
812                break;
813            }
814        }
815    }
816    
817    /* Update the listview item at position @pos with the data from
818       the key @key. */
819  void  void
820  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)
821  {  {
822      const char *s;      const char *s;
823        char *uid;
824      char tmp[32];      char tmp[32];
825    
826      listview_set_item2 (lv, pos, (void *)key);      listview_set_item2 (lv, pos, (void *)key);
827      /* the only mode we support is KYLIST_LIST in the Key Manager */      /* the only mode we support is KYLIST_LIST in the Key Manager */
828            
829      s = key->uids->uid;      s = key->uids->uid;
830      if (s)      if (s) {
831          listview_add_sub_item (lv, pos, 0, s);          uid = utf8_to_wincp2 (s);
832            listview_add_sub_item (lv, pos, 0, uid);
833            free (uid);
834        }
835    
836      s = key->subkeys->keyid;      s = key->subkeys->keyid;
837      if (s) {      if (s) {
# Line 826  keylist_add_key (listview_ctrl_t lv, int Line 884  keylist_add_key (listview_ctrl_t lv, int
884          if (mode & KEYLIST_ALL) {          if (mode & KEYLIST_ALL) {
885              uids = count_userids (key);              uids = count_userids (key);
886              rc = do_addkey (lv, key, uids, i, 0);              rc = do_addkey (lv, key, uids, i, 0);
887              if( rc )              if (rc)
888                  return rc;                  return rc;
889          }          }
890          else if (mode & KEYLIST_LIST)          else if (mode & KEYLIST_LIST)
# Line 839  keylist_add_key (listview_ctrl_t lv, int Line 897  keylist_add_key (listview_ctrl_t lv, int
897                          return rc;                          return rc;
898                  }                  }
899                  else {                  else {
900                      for( uids = 0;  uids < count_userids (key); uids++ ) {                      for (uids = 0;  uids < count_userids (key); uids++) {
901                          rc = do_addkey( lv, key, uids, i, -1 );                          rc = do_addkey (lv, key, uids, i, -1);
902                          if( rc )                          if (rc)
903                              return rc;                              return rc;
904                      }                      }
905                  }                  }

Legend:
Removed from v.105  
changed lines
  Added in v.129

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26