[Winpt-commits] r307 - trunk/Src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Mar 23 15:14:03 CET 2007


Author: twoaday
Date: 2007-03-23 15:14:02 +0100 (Fri, 23 Mar 2007)
New Revision: 307

Modified:
   trunk/Src/wptKeyEditDlgs.cpp
Log:


Modified: trunk/Src/wptKeyEditDlgs.cpp
===================================================================
--- trunk/Src/wptKeyEditDlgs.cpp	2007-03-23 14:07:24 UTC (rev 306)
+++ trunk/Src/wptKeyEditDlgs.cpp	2007-03-23 14:14:02 UTC (rev 307)
@@ -154,19 +154,6 @@
 void ComboBox_AddString_utf8 (HWND cb, const char *txt);
 
 
-/* Safe wrapper for allocation. */
-static GpgKeyEdit*
-create_GpgKeyEdit (const char *keyid)
-{
-    GpgKeyEdit *ke;
-
-    ke = new GpgKeyEdit (keyid);
-    if (!ke)
-	BUG (NULL);
-    return ke;
-}
-
-
 /* Associate each key with a combo box entry. 
    Skip the key in @k. */
 static void
@@ -180,8 +167,7 @@
     pub = keycache_get_ctx (1);
     gpg_keycache_rewind (pub);
     while (!gpg_keycache_next_key (pub, 0, &key)) {
-	if (key->expired || key->revoked || 
-	    key->disabled || key->invalid)
+	if (!key_is_useable (key) || key->invalid)
 	    continue;
 	s = key->uids->uid;
 	kid = key->subkeys->keyid;
@@ -189,7 +175,9 @@
 	    continue;
 	ComboBox_AddString_utf8 (GetDlgItem (dlg, IDC_ADDREV_KEYLIST), s);
     }
+    
     gpg_keycache_rewind (pub);
+    /* In the second loop, we set a key pointer for each element. */
     n = SendDlgItemMessage (dlg, IDC_ADDREV_KEYLIST, CB_GETCOUNT, 0, 0);
     for (i = 0; i < n; i++) {
 	gpg_keycache_next_key (pub, 0, &key);
@@ -219,7 +207,8 @@
     listview_add_sub_item (lv, 0, UID_COL_VALID, _("Ultimate" ));
     listview_add_sub_item (lv, 0, UID_COL_NAME, native);
     listview_add_sub_item (lv, 0, UID_COL_EMAIL, email && *email? email : "");
-    listview_add_sub_item (lv, 0, UID_COL_CREATION, get_key_created (time (NULL)));
+    listview_add_sub_item (lv, 0, UID_COL_CREATION, 
+			   get_key_created (time (NULL)));
     free_if_alloc (native);
 }
 
@@ -232,11 +221,10 @@
     int n;
     
     expdate = keygen->expire? get_key_expire_date (keygen->expire) : _("Never");
-    _snprintf (info, sizeof (info)-1, "%d-bit %s",
-	       keygen->bits,
+    _snprintf (info, DIM (info)-1, "%d-bit %s", keygen->bits,
 	       get_key_pubalgo ((gpgme_pubkey_algo_t)keygen->algo));
     kid = get_keyid_from_fpr (keygen->fpr);
-    _snprintf (keyid, sizeof (keyid)-1, "0x%s", kid);
+    _snprintf (keyid, DIM (keyid)-1, "0x%s", kid);
     s = get_key_created (time (NULL));
     n = listview_count_items (lv, 0);
     listview_add_item_pos (lv, n);
@@ -572,6 +560,7 @@
 static void
 init_keysize_box (HWND dlg, int ctlid)
 {
+    /* Array with standard key-length in bits. */
     const char *sizelist[] = {
 	"1024", "1536", 
 	"2048", "3072", 
@@ -760,7 +749,7 @@
     }
 
     memset (&keygen, 0, sizeof (keygen));
-    memset (&cb, 0, sizeof cb);
+    memset (&cb, 0, sizeof (cb));
     cb.parent = dlg;
     cb.opaque = &keygen;
     cb.is_protected = k->is_protected;
@@ -1107,12 +1096,12 @@
         
     listview_set_ext_style (lv);
     for (i = 0, sub = k->ctx->subkeys; i < nkeys; i++, sub = sub->next) {
-	_snprintf (buf, sizeof buf-1, "%d-bit %s", sub->length,
+	_snprintf (buf, DIM (buf)-1, "%d-bit %s", sub->length,
 				get_key_pubalgo (sub->pubkey_algo));
 	listview_add_sub_item (lv, i, SUBK_COL_DESC, buf);
 	t = sub->keyid;
 	assert (t != NULL);
-	_snprintf (tmp, sizeof tmp-1, "0x%s", t+8);
+	_snprintf (tmp, DIM (tmp)-1, "0x%s", t+8);
 	listview_add_sub_item (lv, i, SUBK_COL_KEYID, tmp);
 
 	t = get_key_created (sub->timestamp);
@@ -1309,7 +1298,7 @@
         return FALSE;
     }
 
-    listview_get_item_text (lv, pos, 0, tmp, sizeof (tmp) -1);
+    listview_get_item_text (lv, pos, 0, tmp, DIM (tmp) -1);
     subk = get_subkey_bypos (k->keyid, pos);
     /* Issue different warning for the different key capabilities. */
     if (subk->can_encrypt)
@@ -1365,7 +1354,7 @@
 
     /* If a key already expired, it is possible the user wants to
        set a new expiration date.. */
-    listview_get_item_text (lv, pos, SUBK_COL_STATUS, buf, sizeof (buf)-1);
+    listview_get_item_text (lv, pos, SUBK_COL_STATUS, buf, DIM (buf)-1);
     if (!strcmp (buf, _("Expired"))) {
 	cancel = msg_box (dlg, _("Key already expired.\n\n"
 			  "Do you want to change the expiration date?"),
@@ -1375,7 +1364,7 @@
 	cancel = 0;
     }
 
-    memset (&udd, 0, sizeof udd);
+    memset (&udd, 0, sizeof (udd));
     udd.text = _("Key Expiration Date");
     dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_DATE, dlg,    
 		      date_dlg_proc, (LPARAM)&udd,
@@ -1403,7 +1392,7 @@
     if (err)
 	msg_box (dlg, gpgme_strerror (err), _("Expire Subkey"), MB_ERR);
     else {
-	_snprintf (buf, sizeof (buf)-1, "%s", get_key_created (exp));
+	_snprintf (buf, DIM (buf)-1, "%s", get_key_created (exp));
 	listview_add_sub_item (lv, pos, SUBK_COL_EXPIRES, buf);
 	k->update = 1;
 	msg_box (dlg, _("Subkey expire date successfully set."), 
@@ -1443,7 +1432,7 @@
 	return FALSE;
     }
 	    
-    listview_get_item_text (lv, j, SUBK_COL_STATUS, buf, sizeof (buf)-1);
+    listview_get_item_text (lv, j, SUBK_COL_STATUS, buf, DIM (buf)-1);
     if (!strcmp (buf, _("Revoked"))) {
 	msg_box (dlg, _("Key already revoked."), _("Key Edit"), MB_ERR);
 	return FALSE;
@@ -1497,11 +1486,11 @@
     }
 
     if( (j = listview_get_curr_pos( lv )) == -1 ) {
-	msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR );	
+	msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR );
 	return FALSE;	
     }
 	    
-    listview_get_item_text( lv, j, UID_COL_VALID, buf, sizeof buf - 1);
+    listview_get_item_text( lv, j, UID_COL_VALID, buf, DIM (buf) - 1);
     if (strstr (buf, _("Revoked"))) {
 	msg_box (dlg, _("This user ID has been already revoked."), 
 		 _("Key Edit"), MB_INFO);
@@ -1509,7 +1498,7 @@
     }
 	    
     listview_get_item_text (lv, j, UID_COL_NAME, buf, sizeof buf -1);
-    _snprintf (inf, sizeof (inf) -1, _("user ID \"%s\".\n\n"
+    _snprintf (inf, DIM (inf) -1, _("user ID \"%s\".\n\n"
 	       "Do you really want to revoke this user ID?"), buf);
     if (msg_box (dlg, inf, _("Key Edit"), MB_WARN_ASK) == IDNO)
 	return FALSE;
@@ -1518,8 +1507,8 @@
 	if (cancel)
 	    return FALSE;	    
     }
-    listview_get_item_text (lv, j, UID_COL_EMAIL, email, sizeof (email)-1);
-    listview_get_item_text (lv, j, UID_COL_NAME, buf, sizeof (buf)-1);
+    listview_get_item_text (lv, j, UID_COL_EMAIL, email, DIM (email)-1);
+    listview_get_item_text (lv, j, UID_COL_NAME, buf, DIM (buf)-1);
     id = do_find_userid (k->keyid, email, buf, NULL);
     if (id == -1)
 	BUG (NULL);
@@ -1556,7 +1545,7 @@
 	msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);
 	return FALSE;
     }
-    listview_get_item_text (lv, pos, 2, buf, sizeof buf-1);
+    listview_get_item_text (lv, pos, 2, buf, DIM (buf)-1);
     id = do_find_userid (k->keyid, buf, NULL, &uidinf);
     if (id == -1)
 	BUG (NULL);
@@ -1608,10 +1597,10 @@
 	msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);
 	return FALSE;
     }
-    listview_get_item_text (lv, j, UID_COL_VALID, valid, sizeof (valid)-1);
+    listview_get_item_text (lv, j, UID_COL_VALID, valid, DIM (valid)-1);
     if (!strcmp (valid, _("Revoked")))
 	return FALSE;
-    listview_get_item_text (lv, j, UID_COL_EMAIL, buf, sizeof (buf)-1);
+    listview_get_item_text (lv, j, UID_COL_EMAIL, buf, DIM (buf)-1);
     id = do_find_userid (k->keyid, buf, NULL, NULL);
     if (id == -1)
 	BUG (NULL);
@@ -1704,7 +1693,7 @@
 	    BUG (NULL);
 	key = (gpgme_key_t)cb->opaque;
 	listview_get_item_text (cb->lv, cb->lv_pos, 
-				UID_COL_EMAIL, buf, sizeof (buf)-1);
+				UID_COL_EMAIL, buf, DIM (buf)-1);
 	pos = do_find_userid (cb->keyid, buf, NULL, &inf);
 	if (pos < 0 || !inf) {
 	    gpg_uid_info_release (inf);
@@ -1713,7 +1702,7 @@
 	}
 	for (u=inf; u; u = u->next) {
 	    if (u->index == pos && u->prefs && *u->prefs) {
-		_snprintf (buf, sizeof (buf)-1, "%s", u->name);
+		_snprintf (buf, DIM (buf)-1, "%s", u->name);
 		SetDlgItemText (dlg, IDC_SHOWPREF_INFO, buf);
 		if (parse_preflist (dlg, u->prefs) <= 0)
 		    pos = -1;
@@ -1773,7 +1762,7 @@
     cb.lv_pos = listview_get_curr_pos (lv);
 
     listview_get_item_text (lv, cb.lv_pos, UID_COL_VALID, 
-			    status, sizeof (status)-1);
+			    status, DIM (status)-1);
     if (!strcmp (status, _("Revoked")))
 	return TRUE;
     
@@ -1972,7 +1961,7 @@
 	msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);
 	return FALSE;
     }
-    listview_get_item_text (lv, uid_index, UID_COL_VALID, valid, sizeof (valid)-1);
+    listview_get_item_text (lv, uid_index, UID_COL_VALID, valid, DIM (valid)-1);
     if (!strcmp (valid, _("Revoked")))
 	return TRUE;
     if (mode == CMD_SIGN) {
@@ -1981,8 +1970,8 @@
 	if (cancel == IDNO)
 	    return FALSE;
     }
-    listview_get_item_text (lv, uid_index, UID_COL_EMAIL, email, sizeof (email)-1);
-    listview_get_item_text (lv, uid_index, UID_COL_NAME, name, sizeof (name)-1);
+    listview_get_item_text (lv, uid_index, UID_COL_EMAIL, email, DIM (email)-1);
+    listview_get_item_text (lv, uid_index, UID_COL_NAME, name, DIM (name)-1);
     uid_index = do_find_userid (k->keyid, email, name, NULL);
 
     defkey = get_gnupg_default_key ();
@@ -2027,7 +2016,7 @@
     i = SendDlgItemMessage (dlg, IDC_KEYEDIT_CMD, CB_GETCURSEL, 0, 0);
     if (i == LB_ERR)
 	return LB_ERR;
-    GetDlgItemText (dlg, IDC_KEYEDIT_CMD, buf, sizeof (buf)-1);
+    GetDlgItemText (dlg, IDC_KEYEDIT_CMD, buf, DIM (buf)-1);
     for (i=0; cmdlist[i].name != NULL; i++) {
 	if (!strcmp (buf, cmdlist[i].name))
 	    return cmdlist[i].id;
@@ -2103,7 +2092,7 @@
     if (!tt)
 	BUG (NULL);
     memset (&ti, 0, sizeof (ti));
-    ti.cbSize = sizeof(TOOLINFO); 
+    ti.cbSize = sizeof (TOOLINFO); 
     ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS;     
     ti.hwnd = dlg;     
     ti.uId = (UINT) ListView_GetHeader (GetDlgItem (dlg, IDC_KEYEDIT_KEYLIST));



More information about the Winpt-commits mailing list