[svn] GPGol - r158 - trunk/src

svn author twoaday cvs at cvs.gnupg.org
Fri Aug 25 09:31:40 CEST 2006


Author: twoaday
Date: 2006-08-25 09:31:39 +0200 (Fri, 25 Aug 2006)
New Revision: 158

Modified:
   trunk/src/ChangeLog
   trunk/src/engine-gpgme.c
   trunk/src/olflange-dlgs.cpp
   trunk/src/olflange-rsrcs.rc
   trunk/src/passphrase-dialog.c
   trunk/src/recipient-dialog.c
Log:


Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2006-08-16 10:43:13 UTC (rev 157)
+++ trunk/src/ChangeLog	2006-08-25 07:31:39 UTC (rev 158)
@@ -1,3 +1,21 @@
+2008-08-21  Timo Schulz  <ts at g10code.de>
+
+	* engine-gpgme.c (op_lookup_keys): Only add useable keys
+	and add all invalid keys to unknown.
+	* recipient-dialog.c (copy_item): Rewritten.
+	(initialize_keybox): Add comment to clarify use of fnd_keys.
+	(recipient_dialog_box): Simplified.
+	(find_item): Support partial search.
+	
+2006-08-19  Timo Schulz  <ts at g10code.de>
+
+	* olflange-rsrcs.rc: Correct some dialog sizes.
+	* passphrase-dialog.c (decrypt_key_dlg_proc): Automatically
+	select the secret key if only one is available.
+	* config-dialog.c (GPGOptionsDlgProc): Passphrase cache
+	time is now requested in minutes but still internally
+	stored as seconds.
+	
 2006-08-15  Timo Schulz  <ts at g10code.de>
 
 	* decrypt.bmp, encrypt.bmp: Restore format.

Modified: trunk/src/engine-gpgme.c
===================================================================
--- trunk/src/engine-gpgme.c	2006-08-16 10:43:13 UTC (rev 157)
+++ trunk/src/engine-gpgme.c	2006-08-25 07:31:39 UTC (rev 158)
@@ -1333,9 +1333,22 @@
         }
       gpgme_op_keylist_end (ctx);
 
-      if (k)
+      
+      /* only useable keys will be added otherwise they will be stored
+         in unknown (marked with their status). */
+      if (k && !k->revoked && !k->disabled && !k->expired)
         (*keys)[kpos++] = k;
-      else
+      else if (k)
+	{
+	  char *p, *fmt = "%s (%s)";
+	  char *warn = k->revoked? "revoked" : k->expired? "expired" : "disabled";
+	  
+	  p = xcalloc (1, strlen (names[i]) + strlen (warn) + strlen (fmt) +1);
+	  sprintf (p, fmt, names[i], warn);
+	  (*unknown)[upos++] = p;
+	  gpgme_key_release (k);
+	}
+      else if (!k)
         (*unknown)[upos++] = xstrdup (names[i]);
     }
 

Modified: trunk/src/olflange-dlgs.cpp
===================================================================
--- trunk/src/olflange-dlgs.cpp	2006-08-16 10:43:13 UTC (rev 157)
+++ trunk/src/olflange-dlgs.cpp	2006-08-25 07:31:39 UTC (rev 158)
@@ -148,8 +148,8 @@
 		SetDlgItemText (hDlg, IDC_ENCRYPT_TO, opt.default_key);
             else
 		SetDlgItemText (hDlg, IDC_ENCRYPT_TO, "");
-	    wsprintf(s, "%d", opt.passwd_ttl);
-	    SendDlgItemMessage(hDlg, IDC_TIME_PHRASES, WM_SETTEXT,
+	    wsprintf (s, "%d", opt.passwd_ttl/60);
+	    SendDlgItemMessage (hDlg, IDC_TIME_PHRASES, WM_SETTEXT,
                                0, (LPARAM) s);
 	    hWndPage = pnmhdr->hwndFrom;   // to be used in WM_COMMAND
 	    SendDlgItemMessage (hDlg, IDC_ENCRYPT_DEFAULT, BM_SETCHECK, 
@@ -191,7 +191,7 @@
  
 	    SendDlgItemMessage (hDlg, IDC_TIME_PHRASES, WM_GETTEXT,
                                 20, (LPARAM)s);		
-	    opt.passwd_ttl = (int)atol (s);
+	    opt.passwd_ttl = (int)atol (s)*60;
 		
 	    opt.encrypt_default = !!SendDlgItemMessage
               (hDlg, IDC_ENCRYPT_DEFAULT, BM_GETCHECK, 0, 0L);

Modified: trunk/src/olflange-rsrcs.rc
===================================================================
--- trunk/src/olflange-rsrcs.rc	2006-08-16 10:43:13 UTC (rev 157)
+++ trunk/src/olflange-rsrcs.rc	2006-08-25 07:31:39 UTC (rev 158)
@@ -51,7 +51,7 @@
 // Dialog
 //
 
-IDD_GPG_OPTIONS_DE DIALOG DISCARDABLE  0, 0, 266, 201
+IDD_GPG_OPTIONS_DE DIALOG DISCARDABLE  0, 0, 266, 274
 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 CAPTION "GnuPG"
 FONT 8, "MS Sans Serif"
@@ -77,18 +77,18 @@
                     IDC_PREVIEW_DECRYPT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,
                     24,95,162,10
 
-    CONTROL         "Wenn möglich, HTML Darstellung anzeigen",
+    CONTROL         "HTML Darstellung anzeigen wenn möglich",
                     IDC_PREFER_HTML,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,
                     24,107,162,10
 
     GROUPBOX        "Passphrase",IDC_STATIC,9,124,242,31
     LTEXT           "Passphrase speichern für",IDC_STATIC,24,136,80,8
     EDITTEXT        IDC_TIME_PHRASES,107,135,39,14,ES_AUTOHSCROLL
-    LTEXT           "Sekunden",IDC_STATIC,151,137,34,8
+    LTEXT           "Minuten",IDC_STATIC,151,137,34,8
 
     PUSHBUTTON      "&Erweitert...",IDC_GPG_OPTIONS,202,166,50,14
     LTEXT           "GPGol by g10 Code GmbH", IDC_STATIC,8,185,100,8
-    LTEXT           "Version x ",IDC_VERSION_INFO,150,185,200,9
+    LTEXT           "Version x ",IDC_VERSION_INFO,150,185,109,9						  
     CONTROL         IDB_BANNER,IDC_BITMAP,"Static",
                     SS_BITMAP | SS_REALSIZEIMAGE,8,200,150,64
 END
@@ -131,7 +131,7 @@
 // Dialog
 //
 
-IDD_GPG_OPTIONS DIALOG DISCARDABLE  0, 0, 266, 201
+IDD_GPG_OPTIONS DIALOG DISCARDABLE  0, 0, 266, 271
 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 CAPTION "GnuPG"
 FONT 8, "MS Sans Serif"
@@ -155,7 +155,7 @@
                     IDC_PREVIEW_DECRYPT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,
                     24,95,162,10
 
-    CONTROL         "Show HTML View if possible",
+    CONTROL         "Show HTML view if possible",
                     IDC_PREFER_HTML,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,
                     24,107,162,10
 
@@ -163,12 +163,12 @@
     GROUPBOX        "Passphrase",IDC_STATIC,9,124,242,31
     LTEXT           "Cache &passphrase for",IDC_STATIC,24,136,70,8
     EDITTEXT        IDC_TIME_PHRASES,107,135,39,14,ES_AUTOHSCROLL
-    LTEXT           "seconds",IDC_STATIC,151,137,28,8
+    LTEXT           "minutes",IDC_STATIC,151,137,28,8
 
 
     PUSHBUTTON      "Ad&vanced..",IDC_GPG_OPTIONS,202,166,50,14
     LTEXT           "GPGol by g10 Code GmbH", IDC_STATIC,8,185,100,8
-    LTEXT           "Version x ",IDC_VERSION_INFO,150,185,200,9
+    LTEXT           "Version x ",IDC_VERSION_INFO,150,183,109,9
     CONTROL         IDB_BANNER,IDC_BITMAP,"Static",
                     SS_BITMAP | SS_REALSIZEIMAGE,8,200,150,64
 END

Modified: trunk/src/passphrase-dialog.c
===================================================================
--- trunk/src/passphrase-dialog.c	2006-08-16 10:43:13 UTC (rev 157)
+++ trunk/src/passphrase-dialog.c	2006-08-25 07:31:39 UTC (rev 158)
@@ -202,17 +202,16 @@
 }
 
 
-/* Fill a combo box with all keys and return an error with those
-   keys. */
-static gpgme_key_t *
-load_secbox (HWND dlg, int ctlid)
+/* Fill a combo box with all keys and return an error with those keys. 
+   set *R_NKEYS to the amount of keys if requested. */
+static gpgme_key_t*
+load_secbox (HWND dlg, int ctlid, size_t *r_nkeys)
 {
   gpg_error_t err;
   gpgme_ctx_t ctx;
   gpgme_key_t key;
-  int pos;
   gpgme_key_t *keyarray;
-  size_t keyarray_size;
+  size_t pos, keyarray_size;
 
   err = gpgme_new (&ctx);
   if (err)
@@ -298,6 +297,8 @@
 
   gpgme_op_keylist_end (ctx);
   gpgme_release (ctx);
+  if (r_nkeys)
+    *r_nkeys = pos;
   return keyarray;
 }
 
@@ -328,8 +329,18 @@
                         (dec && dec->last_was_bad)?
                         _("Invalid passphrase; please try again..."):"");
 
-      if (dec && !context->use_as_cb)
-	context->keyarray = load_secbox (dlg, IDC_DEC_KEYLIST);
+      if (dec && !context->use_as_cb) {
+	context->keyarray = load_secbox (dlg, IDC_DEC_KEYLIST, &n);
+	/* if only one secret key is availble, it makes no sense to
+	   ask the user to select one. */
+	if (n == 1) 
+	  {
+	    dec->signer = context->keyarray[0];
+	    gpgme_key_ref (context->keyarray[0]);
+	    EndDialog (dlg, TRUE);
+	    return FALSE;
+	  }
+      }
 
       CheckDlgButton (dlg, IDC_DEC_HIDE, BST_CHECKED);
       center_window (dlg, NULL);

Modified: trunk/src/recipient-dialog.c
===================================================================
--- trunk/src/recipient-dialog.c	2006-08-16 10:43:13 UTC (rev 157)
+++ trunk/src/recipient-dialog.c	2006-08-25 07:31:39 UTC (rev 158)
@@ -48,12 +48,7 @@
   char **unknown_keys;  /* A string array with the names of the
                            unknown recipients. */
 
-  char **fnd_keys;      /* A string array with the user IDs of already
-                           found keys.  I am not sure why they are
-                           needed here at all - they won't get
-                           displayed for unknown reasons. */
-  gpgme_key_t *fnd_keys_key; /* Same as above but the actual gpgme object. */
-  
+  gpgme_key_t *fnd_keys; /* email address to key mapping list. */  
 
   /* A bit vector used to return selected options. */
   unsigned int opts;
@@ -68,17 +63,21 @@
   size_t      selected_keys_count;
 };
 
-struct key_item_s 
+
+/* Symbolic column IDs. */
+enum klist_col_t 
 {
-  char name [150];
-  char e_mail[100];
-  char key_info[64];
-  char keyid[32];
-  char validity[32];
-  char idx[20];
+  KL_COL_NAME = 0,
+  KL_COL_EMAIL = 1,
+  KL_COL_INFO = 2,
+  KL_COL_KEYID = 3,
+  KL_COL_VALID = 4,
+  KL_COL_INDEX = 5,
+  /* number of columns. */
+  KL_COL_N = 6
 };
 
-
+/* Insert the columns, needed to display keys, into the list view HWND. */
 static void
 initialize_rsetbox (HWND hwnd)
 {
@@ -88,39 +87,41 @@
     col.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
     col.pszText = "Name";
     col.cx = 100;
-    col.iSubItem = 0;
-    ListView_InsertColumn (hwnd, 0, &col);
+    col.iSubItem = KL_COL_NAME;
+    ListView_InsertColumn (hwnd, KL_COL_NAME, &col);
 
     col.pszText = "E-Mail";
     col.cx = 100;
-    col.iSubItem = 1;
-    ListView_InsertColumn (hwnd, 1, &col);
+    col.iSubItem = KL_COL_EMAIL;
+    ListView_InsertColumn (hwnd, KL_COL_EMAIL, &col);
 
     col.pszText = "Key-Info";
     col.cx = 100;
-    col.iSubItem = 2;
-    ListView_InsertColumn (hwnd, 2, &col);
+    col.iSubItem = KL_COL_INFO;
+    ListView_InsertColumn (hwnd, KL_COL_INFO, &col);
 
     col.pszText = "Key ID";
     col.cx = 80;
-    col.iSubItem = 3;
-    ListView_InsertColumn (hwnd, 3, &col);
+    col.iSubItem = KL_COL_KEYID;
+    ListView_InsertColumn (hwnd, KL_COL_KEYID, &col);
 
     col.pszText = "Validity";
     col.cx = 70;
-    col.iSubItem = 4;
-    ListView_InsertColumn (hwnd, 4, &col);
+    col.iSubItem = KL_COL_VALID;
+    ListView_InsertColumn (hwnd, KL_COL_VALID, &col);
 
     col.pszText = "Index";
     col.cx = 0;  /* Hide it. */
-    col.iSubItem = 5;
-    ListView_InsertColumn (hwnd, 5, &col);
+    col.iSubItem = KL_COL_INDEX;
+    ListView_InsertColumn (hwnd, KL_COL_INDEX, &col);
 
     ListView_SetExtendedListViewStyleEx (hwnd, 0, LVS_EX_FULLROWSELECT);
 }
 
 
-static gpgme_key_t *
+/* Load the key list view control HWND with all useable keys 
+   for encryption. Return the array size in *R_ARRAYSIZE. */
+static gpgme_key_t*
 load_rsetbox (HWND hwnd, size_t *r_arraysize)
 {
   LVITEM lvi;
@@ -275,14 +276,16 @@
 }
 
 
+#define ITEMSIZE 200
 
+/* Copy one list view item from one view to another. */
 static void
 copy_item (HWND dlg, int id_from, int pos)
 {
   HWND src, dst;
   LVITEM lvi;
-  struct key_item_s from;
-  int idx = pos;
+  char item[KL_COL_N][ITEMSIZE];
+  int idx = pos, i;
   
   src = GetDlgItem (dlg, id_from);
   dst = GetDlgItem (dlg, id_from==IDC_ENC_RSET1 ?
@@ -295,27 +298,19 @@
         return;
     }
   
-  memset (&from, 0, sizeof (from));
-  ListView_GetItemText (src, idx, 0, from.name, sizeof (from.name)-1);
-  ListView_GetItemText (src, idx, 1, from.e_mail, sizeof (from.e_mail)-1);
-  ListView_GetItemText (src, idx, 2, from.key_info, sizeof (from.key_info)-1);
-  ListView_GetItemText (src, idx, 3, from.keyid, sizeof (from.keyid)-1);
-  ListView_GetItemText (src, idx, 4, from.validity, sizeof (from.validity)-1);
-  ListView_GetItemText (src, idx, 5, from.idx, sizeof (from.idx)-1);
-
+  for (i=0; i < KL_COL_N; i++)
+    ListView_GetItemText (src, idx, i, item[i], ITEMSIZE-1);
   ListView_DeleteItem (src, idx);
   
   memset (&lvi, 0, sizeof (lvi));
   ListView_InsertItem (dst, &lvi);
-  ListView_SetItemText (dst, 0, 0, from.name);
-  ListView_SetItemText (dst, 0, 1, from.e_mail);
-  ListView_SetItemText (dst, 0, 2, from.key_info);
-  ListView_SetItemText (dst, 0, 3, from.keyid);
-  ListView_SetItemText (dst, 0, 4, from.validity);
-  ListView_SetItemText (dst, 0, 5, from.idx);
+  for (i=0; i < KL_COL_N; i++)
+    ListView_SetItemText (dst, 0, i, item[i]);
 }
 
 
+/* Try to find an item with STR as the text in the first column.
+   Return the index of the item or -1 if no item was found. */
 static int
 find_item (HWND hwnd, const char *str)
 {
@@ -323,7 +318,7 @@
     int pos;
 
     memset (&fnd, 0, sizeof (fnd));
-    fnd.flags = LVFI_STRING;
+    fnd.flags = LVFI_STRING|LVFI_PARTIAL;;
     fnd.psz = str;
     pos = ListView_FindItem (hwnd, -1, &fnd);
     if (pos != -1)
@@ -347,13 +342,19 @@
                      (LPARAM)(const char *)cb->unknown_keys[i]);
     }
 
+  /* copy all requested keys into the second recipient listview
+     to indicate that these key were automatically picked via
+     the 'From' mailing header. */
   if (cb->fnd_keys)
     {
       for (i=0; cb->fnd_keys[i]; i++) 
         {
-          n = find_item (rset, cb->fnd_keys[i]);
+	  char *uid = utf8_to_native (cb->fnd_keys[i]->uids->name);
+
+          n = find_item (rset, uid);
           if (n != -1)
             copy_item (dlg, IDC_ENC_RSET1, n);
+	  xfree (uid);
         }
     }
 }
@@ -376,7 +377,6 @@
       initialize_rsetbox (GetDlgItem (dlg, IDC_ENC_RSET1));
       rset_cb->keyarray = load_rsetbox (GetDlgItem (dlg, IDC_ENC_RSET1),
                                         &rset_cb->keyarray_count);
-
       initialize_rsetbox (GetDlgItem (dlg, IDC_ENC_RSET2));
 
       if (rset_cb->unknown_keys)
@@ -412,7 +412,7 @@
               return FALSE;
 	    }
 
-          for (j=0; rset_cb->fnd_keys_key && rset_cb->fnd_keys_key[j]; j++)
+          for (j=0; rset_cb->fnd_keys && rset_cb->fnd_keys[j]; j++)
             ;
           rset_cb->selected_keys_count = ListView_GetItemCount (hrset);
           rset_cb->selected_keys = xcalloc (rset_cb->selected_keys_count
@@ -455,10 +455,10 @@
                 log_debug ("List item not correctly initialized - ignored\n");
             }
           /* Add the already found keys. */
-          for (i=0; rset_cb->fnd_keys_key && rset_cb->fnd_keys_key[i]; i++)
+          for (i=0; rset_cb->fnd_keys && rset_cb->fnd_keys[i]; i++)
             {
-              gpgme_key_ref (rset_cb->fnd_keys_key[i]);
-              rset_cb->selected_keys[pos++] = rset_cb->fnd_keys_key[i];
+              gpgme_key_ref (rset_cb->fnd_keys[i]);
+              rset_cb->selected_keys[pos++] = rset_cb->fnd_keys[i];
             }
 
           rset_cb->selected_keys_count = pos;
@@ -521,27 +521,12 @@
 		       gpgme_key_t **ret_rset)
 {
   struct recipient_cb_s cb;
-  int i;
-  size_t n;
   int resid;
-
+  
   *ret_rset = NULL;
 
   memset (&cb, 0, sizeof (cb));
-
-  for (n=0; fnd[n]; n++)
-    ;
-  cb.fnd_keys = xcalloc (n+1, sizeof *cb.fnd_keys);
-
-  for (i = 0; i < n; i++) 
-    {
-      if (fnd[i] && fnd[i]->uids && fnd[i]->uids->uid)
-        cb.fnd_keys[i] = xstrdup (fnd[i]->uids->uid);
-      else
-	cb.fnd_keys[i] = xstrdup (_("User-ID not found"));
-    }
-
-  cb.fnd_keys_key = fnd;
+  cb.fnd_keys = fnd;
   cb.unknown_keys = unknown;
 
   if (!strncmp (gettext_localename (), "de", 2))
@@ -557,8 +542,6 @@
     *ret_rset = cb.selected_keys;
 
   release_keyarray (cb.keyarray, cb.keyarray_count);
-  for (i = 0; i < n; i++) 
-    xfree (cb.fnd_keys[i]);
   xfree (cb.fnd_keys);
   return cb.opts;
 }




More information about the Gnupg-commits mailing list