[Winpt-commits] r205 - in trunk: Include Src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Apr 27 14:46:18 CEST 2006


Author: twoaday
Date: 2006-04-27 14:46:03 +0200 (Thu, 27 Apr 2006)
New Revision: 205

Modified:
   trunk/Include/wptKeyCache.h
   trunk/Include/wptKeyManager.h
   trunk/Include/wptKeylist.h
   trunk/Include/wptW32API.h
   trunk/Src/ChangeLog
   trunk/Src/wptClipDecryptDlg.cpp
   trunk/Src/wptFileManager.cpp
   trunk/Src/wptImportList.cpp
   trunk/Src/wptKeyCache.cpp
   trunk/Src/wptKeyEdit.cpp
   trunk/Src/wptKeyEditDlgs.cpp
   trunk/Src/wptKeyManager.cpp
   trunk/Src/wptKeyManagerDlg.cpp
   trunk/Src/wptKeyRevokeDlg.cpp
   trunk/Src/wptKeylist.cpp
   trunk/Src/wptKeysigDlg.cpp
   trunk/Src/wptKeysignDlg.cpp
   trunk/Src/wptListView.cpp
   trunk/Src/wptMDSumDlg.cpp
   trunk/Src/wptNLS.c
   trunk/Src/wptPassphraseCB.cpp
   trunk/Src/wptSigTreeDlg.cpp
   trunk/Src/wptVerifyList.cpp
   trunk/Src/wptW32API.cpp
Log:
2006-04-27  Timo Schulz  <ts at g10code.de>
                                                                                
        * wptKeyManager.cpp (km_get_key_ptr): New.
        * wptListview.cpp (listview_get_item_text): Drop utf8 support.
        * wptKeyCache.cpp (keycache_decode_uids): New.
        (free_native_uids): New.
        * wptKeyEdit.cpp (uid_inf_colon_handler): Do utf8 decodig here.
                                                                                
2006-04-26  Timo Schulz  <ts at g10code.de>
                                                                                
        * wptKeylist.cpp (get_keyid_from_fpr): New.
        * wptDecryptClipDlg.cpp (clip_decrypt_dlg): Use it here.
        * wptVerifyList.cpp (verlist_add_sig): Likewise.



Modified: trunk/Include/wptKeyCache.h
===================================================================
--- trunk/Include/wptKeyCache.h	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Include/wptKeyCache.h	2006-04-27 12:46:03 UTC (rev 205)
@@ -20,6 +20,9 @@
 #ifndef WPT_KEYCACHE_H
 #define WPT_KEYCACHE_H
 
+#include <gpgme.h>
+
+/* key cache specific update flags. */
 enum keycache_flag_t {
     KC_FLAG_ADD = 1,
     KC_FLAG_UPD = 2
@@ -32,6 +35,21 @@
 };
 
 
+/* contains the UTF8 decoded user id. */
+struct native_uid_s {
+    struct native_uid_s *next;
+    unsigned int malloced:1;	    /* 1 if the follow parts are actually
+				       malloced or just referenced pointer. */
+    unsigned int revoked : 1;
+    gpgme_validity_t validity;
+
+    char *uid;
+    char *name;
+    char *comment;
+    char *email;
+};
+
+
 struct keycache_s {
     struct keycache_s *next;
     int flags;
@@ -52,6 +70,7 @@
     unsigned char *sym_prefs;/* symmetric cipher preferences. */
     char *pref_keyserver;   /* if != NULL preferred keyserver. */
     char *card_type;	    /* if != NULL key stored on smart card. */
+    struct native_uid_s *uids;
 };
 
 struct gpg_keycache_s {    
@@ -88,6 +107,8 @@
 				   int secret);
 gpgme_error_t gpg_keycache_next_key (gpg_keycache_t ctx, int flags,
 				       gpgme_key_t * r_key);
+gpgme_error_t gpg_keycache_next_key2 (gpg_keycache_t ctx, int flags, 
+				     struct keycache_s **c, gpgme_key_t *r_key);
 gpgme_error_t gpg_keycache_prepare (gpg_keycache_t ctx, 
 				      const char *pubring, 
 				      const char *secring);

Modified: trunk/Include/wptKeyManager.h
===================================================================
--- trunk/Include/wptKeyManager.h	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Include/wptKeyManager.h	2006-04-27 12:46:03 UTC (rev 205)
@@ -83,6 +83,8 @@
 void km_find_key (HWND dlg, listview_ctrl_t lv);
 char* km_gen_export_filename (const char *keyid, int is_secret);
 int km_get_key (listview_ctrl_t lv, int pos, winpt_key_t k);
+gpgme_key_t km_get_key_ptr (listview_ctrl_t lv, int idx, 
+			    struct keycache_s **r_ctx);
 void km_key_show_revoc_info (winpt_key_t k);
 
 #if 0

Modified: trunk/Include/wptKeylist.h
===================================================================
--- trunk/Include/wptKeylist.h	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Include/wptKeylist.h	2006-04-27 12:46:03 UTC (rev 205)
@@ -99,6 +99,7 @@
 const char* get_key_trust (gpgme_key_t key, int uididx, int listmode);
 const char* get_key_trust2 (gpgme_key_t key, int val, int uididx, int listmode);
 const char* get_key_trust_str (int val);
+const char* get_keyid_from_fpr (const char *fpr);
 
 char* get_key_desc (gpgme_key_t key);
 
@@ -112,8 +113,10 @@
 			     int mode, int sortby );
 int keylist_reload( listview_ctrl_t lv, gpg_keycache_t c, int mode, int sortby );
 void keylist_delete( listview_ctrl_t lv );
-int keylist_add_key (listview_ctrl_t lv, int mode, gpgme_key_t key);
-void keylist_upd_key (listview_ctrl_t lv, int pos, gpgme_key_t key);
+int keylist_add_key (listview_ctrl_t lv, int mode, 
+		     struct keycache_s *ctx, gpgme_key_t key);
+void keylist_upd_key (listview_ctrl_t lv, int pos, 
+		      struct keycache_s *ctx, gpgme_key_t key);
 void keylist_upd_col (listview_ctrl_t lv, int col);
 gpgme_key_t* keylist_get_recipients( listview_ctrl_t lv, 
 				        int *r_force_trust, int *r_count );

Modified: trunk/Include/wptW32API.h
===================================================================
--- trunk/Include/wptW32API.h	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Include/wptW32API.h	2006-04-27 12:46:03 UTC (rev 205)
@@ -83,8 +83,6 @@
 const char* get_locale_date (long tm_t, char *buf, DWORD buflen);
 int get_temp_name (char *buf, DWORD buflen, const char *name);
 
-void SetWindowText_utf8 (HWND hwnd, const char *txt);
-void SetDlgItemText_utf8 (HWND dlg, int id, const char *txt);
 int GetDlgItemText_utf8 (HWND dlg, int id, char **r_txt);
 
 #define listbox_add_string(lb, string) \

Modified: trunk/Src/ChangeLog
===================================================================
--- trunk/Src/ChangeLog	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Src/ChangeLog	2006-04-27 12:46:03 UTC (rev 205)
@@ -1,3 +1,17 @@
+2006-04-27  Timo Schulz  <ts at g10code.de>
+
+	* wptKeyManager.cpp (km_get_key_ptr): New.
+	* wptListview.cpp (listview_get_item_text): Drop utf8 support.
+	* wptKeyCache.cpp (keycache_decode_uids): New.
+	(free_native_uids): New.
+	* wptKeyEdit.cpp (uid_inf_colon_handler): Do utf8 decodig here.
+	
+2006-04-26  Timo Schulz  <ts at g10code.de>
+
+	* wptKeylist.cpp (get_keyid_from_fpr): New.
+	* wptDecryptClipDlg.cpp (clip_decrypt_dlg): Use it here.
+	* wptVerifyList.cpp (verlist_add_sig): Likewise.
+	
 2006-04-25  Timo Schulz  <ts at g10code.de>
 
 	* wptFileManagerDlg.cpp (file_manager_dlg_proc): Handle IDCANCEL.

Modified: trunk/Src/wptClipDecryptDlg.cpp
===================================================================
--- trunk/Src/wptClipDecryptDlg.cpp	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Src/wptClipDecryptDlg.cpp	2006-04-27 12:46:03 UTC (rev 205)
@@ -169,11 +169,7 @@
 	sig = sigres->signatures;
 	if (!sig->fpr)
 	    BUG (NULL);
-	if (strlen (sig->fpr) > 16)
-	    keyid = strlen (sig->fpr) == 40? sig->fpr+24 : sig->fpr+16;
-	else
-	    keyid = sig->fpr;
-
+	keyid = get_keyid_from_fpr (sig->fpr);
 	get_pubkey (keyid, &key);
 	if (key) {
 	    if (key->owner_trust == GPGME_VALIDITY_FULL || 
@@ -201,7 +197,7 @@
 		   "%s %s"),
 		   s, get_gpg_sigstat (sig->summary), 
 		   strtimestamp (sig->timestamp),
-		   uid, keyid+8, 
+		   uid, keyid, 
 		   novalid? "\nPrimary key fingerprint: " : "",
 		   novalid? get_key_fpr (key) : "");
 	safe_free (uid);

Modified: trunk/Src/wptFileManager.cpp
===================================================================
--- trunk/Src/wptFileManager.cpp	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Src/wptFileManager.cpp	2006-04-27 12:46:03 UTC (rev 205)
@@ -1210,11 +1210,11 @@
 /* Show the human readable verify result from @sigres. */
 static void
 show_verify_result (gpgme_verify_result_t sigres)
-{
-    gpgme_key_t key=NULL;
+{    
     gpgme_signature_t sig=sigres->signatures;
-    const char *s, *keyid;
-    char *uid, *pka_info;
+    winpt_key_s key;
+    const char *s, *keyid, *uid;
+    char *pka_info;
     char buf[384];
     int sigok = 0;
 
@@ -1225,14 +1225,12 @@
     if (!keyid)
 	return;
     pka_info = get_pka_status (sig);
-    keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr + 24;
-    get_pubkey (sig->fpr, &key);
-
-    if (key)
-	uid = utf8_to_native (key->uids->uid);
+    keyid = get_keyid_from_fpr (sig->fpr);
+    memset (&key, 0, sizeof (key));
+    if (!winpt_get_pubkey (sig->fpr, &key))
+	uid = key.ext->uids->uid;
     else
-	uid = strdup (_("user ID not found"));
-
+	uid = _("user ID not found");
     _snprintf (buf, sizeof (buf)-1, _("Signature made %s using %s key ID %s\n"
 				      "%s from \"%s\"\n%s"),
 		strtimestamp (sig->timestamp), 
@@ -1240,7 +1238,6 @@
 		keyid, s, uid, pka_info? pka_info : "");
     msg_box (NULL, buf, _("Decrypt Verify"), sigok? MB_OK: MB_ICONWARNING|MB_OK);
     free_if_alloc (pka_info);
-    safe_free (uid);
 }
 
 

Modified: trunk/Src/wptImportList.cpp
===================================================================
--- trunk/Src/wptImportList.cpp	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Src/wptImportList.cpp	2006-04-27 12:46:03 UTC (rev 205)
@@ -144,7 +144,7 @@
 	case 1:
 	    if (rectype != KEY_primary)
 		break;
-	    for (s = pend; *s && !isdigit (*s); s++) {
+	    for (s = pend; *s && !isdigit ((unsigned int)*s); s++) {
 		switch (*s) {
 		case 'd': c->disabled = 1;break;
 		case 'e': c->expired = 1; break;
@@ -287,7 +287,7 @@
 /* Add the key @key to the list view control @lv at position @pos. */
 static int
 implist_add_key (listview_ctrl_t lv, int pos, import_key_t key)
-{	
+{
     char buf[128], * desc;
     const char *t;
     u32 tt, tt2=0;

Modified: trunk/Src/wptKeyCache.cpp
===================================================================
--- trunk/Src/wptKeyCache.cpp	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Src/wptKeyCache.cpp	2006-04-27 12:46:03 UTC (rev 205)
@@ -37,6 +37,7 @@
 #include "wptW32API.h"
 #include "wptGPG.h"
 #include "wptTypes.h"
+#include "wptUTF8.h"
 
 
 /* Attribute list which holds the image data. */
@@ -250,6 +251,70 @@
 }
 
 
+/* Store utf8 decoded user IDs in the code to avoid in-place decoding. */
+static gpgme_error_t
+keycache_decode_uids (gpg_keycache_t ctx)
+{
+    struct native_uid_s *n, *t;
+    struct keycache_s *c;
+    gpgme_user_id_t u;
+
+    for (c = ctx->item; c; c = c->next) {
+	for (u = c->key->uids; u; u = u->next) {
+	    n = (struct native_uid_s*)calloc (1, sizeof *n);
+	    if (!n)
+		BUG (0);
+	    if (is_8bit_string (u->uid)) {
+		n->malloced = 1;
+		n->uid = utf8_to_native (u->uid);
+		if (u->name != NULL)
+		    n->name = utf8_to_native (u->name);
+		if (u->email != NULL)
+    		    n->email = strdup (u->email);
+		if (u->comment != NULL)
+		    n->comment = utf8_to_native (u->comment);
+	    }
+	    else {
+		n->malloced = 0;
+		n->uid = u->uid;
+		n->name = u->name;
+		n->comment = u->comment;
+		n->email = u->email;
+	    }
+	    if (!c->uids)
+		c->uids = n;
+	    else {
+		for (t = c->uids; t->next; t=t->next)
+		    ;
+		t->next = n;
+	    }
+	}
+    }	
+    return 0;
+}
+
+
+static void
+free_native_uids (struct native_uid_s *n)
+{
+    struct native_uid_s *t;
+
+    while (n != NULL) {
+	t = n->next;
+	if (n->malloced) {
+	    safe_free (n->uid);
+	    safe_free (n->name);
+	    safe_free (n->comment);
+	    safe_free (n->email);
+	    safe_free (n->uid);
+	}
+	safe_free (n);
+	n = t;
+    }
+}
+
+
+
 /* Merge the information from the keyrings into the key cache structure. */
 gpgme_error_t
 keycache_prepare2 (gpg_keycache_t ctx, const char *kid,
@@ -380,6 +445,7 @@
 	safe_free (c->sym_prefs);
 	safe_free (c->attrib.d);
 	safe_free (c->card_type);
+	free_native_uids (c->uids);
 	safe_free (c);
     }
     safe_free (ctx);
@@ -658,6 +724,7 @@
     if (gpgme_err_code (err) == GPG_ERR_EOF)
 	err = gpg_error (GPG_ERR_NO_ERROR);
     keycache_update_photos (ctx);
+    keycache_decode_uids (ctx);
     /* XXX: make sure the progress dialog is closed. */
     gpgme_op_keylist_end (c);
     gpgme_release (c);
@@ -772,7 +839,8 @@
     if (flags && ctx->tmp->pubpart == NULL)
 	flags = 0;
     *r_key = flags? ctx->tmp->pubpart->key : ctx->tmp->key;
-    *c = ctx->tmp = ctx->tmp->next;
+    *c = ctx->tmp;
+    ctx->tmp = ctx->tmp->next;    
     ctx->pos++;
 
     return 0;
@@ -786,13 +854,20 @@
 gpg_keycache_next_key (gpg_keycache_t ctx, int flags, gpgme_key_t *r_key)
 {
     struct keycache_s *c=NULL;
-    gpgme_error_t err = 0;
+    gpgme_error_t err;
 
     err = keycache_next_key (ctx, flags, &c, r_key);
     return err;
 }
 
+gpgme_error_t
+gpg_keycache_next_key2 (gpg_keycache_t ctx, int flags, 
+			struct keycache_s **c, gpgme_key_t *r_key)
+{
+    return keycache_next_key (ctx, flags, c, r_key);
+}
 
+
 /* Search for a key with the pattern @pattern and mark
    this key as the default signing key if found.
    Return value: 0 on success. */
@@ -931,4 +1006,3 @@
     safe_free (val);
     return err;
 }
-

Modified: trunk/Src/wptKeyEdit.cpp
===================================================================
--- trunk/Src/wptKeyEdit.cpp	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Src/wptKeyEdit.cpp	2006-04-27 12:46:03 UTC (rev 205)
@@ -22,9 +22,8 @@
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
-
+#include <time.h>
 #include <windows.h>
-#include <time.h>
 
 #include "gpgme.h"
 #include "wptCommonCtl.h"
@@ -34,6 +33,7 @@
 #include "wptW32API.h"
 #include "wptGPG.h"
 #include "wptErrors.h"
+#include "wptUTF8.h"
 
 
 /* Parse the colon status information of @line and store
@@ -92,6 +92,7 @@
 {
     gpg_uid_info_t i, t;
     char *p, *pend;
+    char *name;
     int field = 0, len = 0;
 
     if (!line || strlen (line) < 3 || strncmp (line, "uid", 3))
@@ -122,10 +123,12 @@
             break;
 
         case 10: /* user ID */
-            i->name = (char *)calloc (1, strlen (pend)+1);
-	    if (!i->name)
+            name = (char *)calloc (1, strlen (pend)+1);
+	    if (!name)
 		return gpg_error (GPG_ERR_ENOMEM);;
-	    gpg_decode_c_string (pend, &i->name, strlen (pend)+ 1);
+	    gpg_decode_c_string (pend, &name, strlen (pend)+ 1);
+	    i->name = utf8_to_native (name);
+	    safe_free (name);
 	    if (strchr (pend, '<') != NULL && strchr (pend, '>') != NULL) {
 		int pos = strchr (i->name, '<')- i->name + 1;
 		int end = strchr (i->name, '>') - i->name;

Modified: trunk/Src/wptKeyEditDlgs.cpp
===================================================================
--- trunk/Src/wptKeyEditDlgs.cpp	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Src/wptKeyEditDlgs.cpp	2006-04-27 12:46:03 UTC (rev 205)
@@ -269,7 +269,6 @@
     GpgKeyEdit *ke;
     gpgme_error_t err;
     gpg_uid_info_t inf, ui;
-    char *ui_name = NULL;
     int pos = -1;
 
     ke = create_GpgKeyEdit (keyid);
@@ -283,11 +282,9 @@
     }
 
     for (ui = inf; ui; ui = ui->next) {
-	safe_free (ui_name);
-	ui_name = utf8_to_native (ui->name);
-	if (name && email && ui->email && ui_name) {
+	if (name && email && ui->email && ui->name) {
 	    if (!strcmp (ui->email, email) && 
-		!strncmp (ui_name, name, strlen (name))) {
+		!strncmp (ui->name, name, strlen (name))) {
 		pos = ui->index;
 		break;
 	    }
@@ -302,7 +299,7 @@
 	       as the fallbck when no email address is available. */
 	    continue;
 	}
-	if (ui_name && name && !strcmp (ui_name, name)) {
+	if (ui->name && name && !strcmp (ui->name, name)) {
 	    pos = ui->index;
 	    break;
 	}
@@ -311,7 +308,6 @@
 	*r_inf = inf;
     else
 	gpg_uid_info_release (inf);
-    safe_free (ui_name);
     return pos;
 }
 

Modified: trunk/Src/wptKeyManager.cpp
===================================================================
--- trunk/Src/wptKeyManager.cpp	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Src/wptKeyManager.cpp	2006-04-27 12:46:03 UTC (rev 205)
@@ -57,12 +57,13 @@
 static void 
 key_get_clip_info (const char *keyid, char *buf, size_t buflen)
 {
+    winpt_key_s key;
     gpgme_key_t pk;
-    char *uid;
 
-    if (get_pubkey (keyid, &pk))
+    memset (&key, 0, sizeof (key));
+    if (winpt_get_pubkey (keyid, &key))
 	BUG (NULL);
-    uid = utf8_to_native (pk->uids->uid);
+    pk = key.ctx;
     _snprintf (buf, buflen-1, 
 	       "pub %04d%s/%s %s %s\r\n"
 	       "    Primary key fingerprint: %s\r\n",
@@ -70,9 +71,8 @@
 	       get_key_pubalgo2 (pk->subkeys->pubkey_algo),
 	       pk->subkeys->keyid+8,
 	       get_key_created (pk->subkeys->timestamp),
-	       uid,
+	       key.ext->uids->uid,
 	       get_key_fpr (pk));
-    safe_free (uid);
 }
 
 
@@ -99,6 +99,22 @@
 }
 
 
+/* Retrieve the opaque 32-bit param stored within the list view item
+   at position @idx and return the gpgme key context. */
+gpgme_key_t
+km_get_key_ptr (listview_ctrl_t lv, int idx, struct keycache_s **r_ctx)
+{
+    struct keycache_s *ctx;
+
+    ctx = (struct keycache_s *)listview_get_item2 (lv, idx);
+    if (!ctx)
+	BUG (0);
+    if (r_ctx)
+	*r_ctx = ctx;
+    return ctx->key;
+}
+
+
 /* Check if list view @lv contains a secret key at position @pos.
    If utrust is valid, set it to 1 if the key is valid -1 otherwise.
    Return value: 1 normal key, 2 smart card key. */
@@ -109,9 +125,7 @@
     winpt_key_s sk;
     int type = 0;
     
-    key = (gpgme_key_t)listview_get_item2 (lv, pos);
-    if (!key)
-	BUG (NULL);
+    key = km_get_key_ptr (lv, pos, NULL);
     if (utrust)
 	*utrust = 0;
     memset (&sk, 0, sizeof (sk));
@@ -134,7 +148,7 @@
     gpgme_key_t key;
     winpt_key_s k;
 
-    key = (gpgme_key_t)listview_get_item2 (lv, pos);
+    key = km_get_key_ptr (lv, pos, NULL);
     if (!key)
 	return 1; /* assume yes */
     winpt_get_pubkey (key->subkeys->keyid, &k);
@@ -173,7 +187,7 @@
 
     if (pos == -1)
 	return 0;
-    key = (gpgme_key_t)listview_get_item2 (lv, pos);
+    key = km_get_key_ptr (lv, pos, NULL);
     if (!key)
 	return 0;
 
@@ -196,9 +210,7 @@
     gpgme_key_t key;
     GpgKeyEdit *ke;
 
-    key = (gpgme_key_t)listview_get_item2 (lv, pos);
-    if (!key)
-	BUG (NULL);
+    key = km_get_key_ptr (lv, pos, NULL);
     ke = new GpgKeyEdit (key->subkeys->keyid);
     if (!ke)
 	BUG (NULL);
@@ -691,9 +703,7 @@
 	BUG (NULL);
     for (i = 0; i < n; i++) {
         if (listview_get_item_state(lv, i)) {
-	    key = (gpgme_key_t)listview_get_item2 (lv, i);
-	    if (!key)
-		BUG (NULL);
+	    key = km_get_key_ptr (lv, i, NULL);
 	    seckey_type = km_check_for_seckey (lv, i, NULL);
             if (confirm && !seckey_type) {
 		p = km_key_get_info (key, 0);
@@ -774,9 +784,7 @@
 	return WPTERR_GENERAL;
     }
 
-    key = (gpgme_key_t)listview_get_item2 (lv, id);
-    if (!key)
-	BUG (NULL);
+    key = km_get_key_ptr (lv, id, NULL);
     id = log_box (_("Key Manager"), MB_YESNO,
 		  _("Do you really want to send '0x%s' to keyserver %s?"),
 		    key->subkeys->keyid+8, host);
@@ -794,8 +802,8 @@
     gpgme_key_t key;
     gpgme_error_t rc;
     GPGME *ctx;
+    struct keycache_s *c;
     char *fname;
-    char *name;
     int pos;
     int n;
 
@@ -809,14 +817,11 @@
 	msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);
 	return WPTERR_GENERAL;
     }
-    key = (gpgme_key_t)listview_get_item2 (lv, pos);
-    if (!key)
-	BUG (NULL);
+    key = km_get_key_ptr (lv, pos, &c);
 
-    name = utf8_to_native (key->uids->name);
-    n = strlen (name)+1 + MAX_PATH + 5;
+    n = strlen (c->uids->name)+1 + MAX_PATH + 5;
     fname = new char[n+1];
-    get_temp_name (fname, n-5, name);
+    get_temp_name (fname, n-5, c->uids->name);
     for (pos=0; pos < (int)strlen (fname); pos++) {
 	if (fname[pos] == ' ')
 	    fname[pos] = '_';
@@ -831,7 +836,6 @@
 	mapi_send_pubkey (key->subkeys->keyid+8, fname);
 
     delete ctx;
-    safe_free (name);
     free_if_alloc (fname);
     return rc;
 }
@@ -853,9 +857,8 @@
     else
 	idx = listview_get_curr_pos (lv);
     if (idx != -1) {
-	key = (gpgme_key_t)listview_get_item2 (lv, idx);
-	if (!key)
-	    BUG (0);
+	key = km_get_key_ptr (lv, idx, NULL);
+
 	/* In single refresh mode, try to use the users preferred keyserver. */
 	if (flags == 0 &&
 	    !winpt_get_pubkey (key->subkeys->keyid+8, &pk) &&
@@ -919,9 +922,7 @@
 {
     gpgme_key_t pk;
 
-    pk = (gpgme_key_t)listview_get_item2 (lv, pos);
-    if (!pk)
-	BUG (NULL);
+    pk = km_get_key_ptr (lv, pos, NULL);
     if (strlen (pk->subkeys->fpr) == 32 && 
 	pk->subkeys->pubkey_algo == GPGME_PK_RSA)
 	return -1;
@@ -937,9 +938,7 @@
     gpgme_key_t key;
     GpgKeyEdit *ke;
 
-    key = (gpgme_key_t)listview_get_item2 (lv, pos);
-    if (!key)
-	BUG (NULL);
+    key = km_get_key_ptr (lv, pos, NULL);
     ke = new GpgKeyEdit (key->subkeys->keyid);
     if (!ke)
 	BUG (0);
@@ -988,23 +987,21 @@
 char*
 km_gen_export_filename (const char *keyid, int is_secret)
 {
-    gpgme_key_t key;
-    char *p, *uid;
+    winpt_key_s key;
+    char *p;
 
-    if (get_pubkey (keyid, &key))
+    memset (&key, 0, sizeof (key));
+    if (winpt_get_pubkey (keyid, &key))
 	return m_strdup (keyid);
-    uid = utf8_to_native (key->uids->name);
-    if (!uid)
-	return m_strdup (keyid);
-    p = new char[strlen (uid) + 8 + 16];
+    
+    p = new char[strlen (key.ext->uids->name) + 8 + 16];
     if (!p)
 	BUG (0);
-    sprintf (p, "%s%s.asc", uid, is_secret? "_sec" : "");
+    sprintf (p, "%s%s.asc", key.ext->uids->name, is_secret? "_sec" : "");
     for (size_t i=0; i < strlen (p); i++) {
 	if (p[i] == ' ' || p[i] == ':' || p[i] == '?' || p[i] == '|')
 	    p[i] = '_';
     }
-    safe_free (uid);
     return p;
 }
 
@@ -1018,9 +1015,7 @@
 
     if (pos == -1)
 	return -1;
-    key = (gpgme_key_t)listview_get_item2 (lv, pos);
-    if (!key)
-	BUG (NULL);
+    key = km_get_key_ptr (lv, pos, NULL);
     memset (k, 0, sizeof (*k));
     strncpy (k->tmp_keyid, key->subkeys->keyid+8, 8);
     k->keyid = k->tmp_keyid;

Modified: trunk/Src/wptKeyManagerDlg.cpp
===================================================================
--- trunk/Src/wptKeyManagerDlg.cpp	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Src/wptKeyManagerDlg.cpp	2006-04-27 12:46:03 UTC (rev 205)
@@ -798,7 +798,7 @@
 static void
 update_key (listview_ctrl_t lv, int pos, const char *keyid, int keypair)
 {
-    gpgme_key_t key;
+    struct winpt_key_s key;
 
     keycache_update (0, keyid);
     if (keypair)
@@ -806,8 +806,9 @@
 
     /* because we replaced the key item, we need to update the
        address of the pointer in the ListView control. */
-    get_pubkey (keyid, &key);
-    keylist_upd_key (lv, pos, key);
+    memset (&key, 0, sizeof (key));
+    winpt_get_pubkey (keyid, &key);
+    keylist_upd_key (lv, pos, key.ext, key.ctx);
     keyring_check_last_access ();
 }
 
@@ -1038,11 +1039,11 @@
     kc = keycache_get_ctx (1);
     while (!gpg_keycache_next_updated_key (kc, &ctx, &status)) {
 	if (status == KC_FLAG_ADD)
-	    keylist_add_key (kmi->lv, KEYLIST_LIST, ctx->key);
+	    keylist_add_key (kmi->lv, KEYLIST_LIST, ctx, ctx->key);
 	else {
 	    pos = find_keypos (kmi->lv, ctx->key);
 	    if (pos != -1)
-		keylist_upd_key (kmi->lv, pos, ctx->key);
+		keylist_upd_key (kmi->lv, pos, ctx, ctx->key);
 	}
     }
     keylist_sort (kmi->lv, KEY_SORT_USERID);
@@ -1125,6 +1126,7 @@
     struct km_info_s *kmi = NULL;
     HWND kl;
     HMENU hm;
+    struct keycache_s *kci;
     gpg_keycache_t c;
     gpgme_key_t key;
     struct genkey_s genkey;
@@ -1678,7 +1680,7 @@
 	    if (listview_count_items (kmi->lv, 1) > 1)
 		name = m_strdup ("Exported_GPG_Keys.asc");
 	    else {
-		key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);		
+		key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL);
 		name = km_gen_export_filename (key->subkeys->keyid+8, 0);
 	    }
             t = get_filesave_dlg (dlg, _("Choose Name for Key File"), NULL, name);
@@ -1711,9 +1713,7 @@
                             "Do you really want to export the key?"),
                           _("WARNING"), MB_INFO|MB_YESNO);
             if (i == IDYES) {
-		key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
-		if (!key)
-		    BUG (NULL);
+		key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL);
 		name = km_gen_export_filename (key->subkeys->keyid+8, 1);
                 t = get_filesave_dlg (dlg, _("Choose Name for Key File"), NULL, name);
                 if (t != NULL)		
@@ -1850,28 +1850,25 @@
 	case ID_KEYCTX_UID_COPY:
 	    /* XXX: add generic function to support multiple selection
 	            with a callback */
-	    key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
-	    name = utf8_to_native (key->uids->uid);
+	    key = km_get_key_ptr (kmi->lv, kmi->lv_idx, &kci);
+	    name = kci->uids->name;
 	    set_clip_text (NULL, name, strlen (name));
-	    safe_free (name);
 	    break;
 
 	case ID_KEYCTX_KEYID_COPY:
-	    key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
+	    key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL);
 	    set_clip_text (NULL, key->subkeys->keyid+8, 
 			   strlen (key->subkeys->keyid+8));
 	    break;
 
 	case ID_KEYCTX_FPR_COPY:
-	    key = (gpgme_key_t) listview_get_item2 (kmi->lv, kmi->lv_idx);
+	    key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL);
 	    t = key->subkeys->fpr;
 	    set_clip_text (NULL, t? t : "", t? strlen (t): 0);
 	    break;
 
 	case ID_KEYCTX_KINFO_COPY:
-	    key = (gpgme_key_t) listview_get_item2 (kmi->lv, kmi->lv_idx);
-	    if (!key)
-		BUG (NULL);
+	    key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL);
 	    km_set_clip_info (key->subkeys->keyid+8);
 	    break;
 
@@ -1907,7 +1904,7 @@
 
         case ID_KEYCTX_SETDEFKEY:
 	    if (!km_check_key_status (kmi->lv, kmi->lv_idx)) {
-		key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
+		key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL);
 		rc = set_gnupg_default_key (key->subkeys->keyid+8);
 		if (rc)
 		    msg_box (dlg, winpt_strerror (rc), _("Key Manager"), MB_ERR);

Modified: trunk/Src/wptKeyRevokeDlg.cpp
===================================================================
--- trunk/Src/wptKeyRevokeDlg.cpp	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Src/wptKeyRevokeDlg.cpp	2006-04-27 12:46:03 UTC (rev 205)
@@ -42,19 +42,17 @@
 static void
 mk_cert_fname (const char *keyid, char *fname, size_t flen)
 {
-    gpgme_key_t k;
+    winpt_key_s k;
     size_t i;
-    char *uid;
 
-    if (get_pubkey (keyid, &k))
+    memset (&k, 0, sizeof (k));
+    if (winpt_get_pubkey (keyid, &k))
 	BUG (NULL);
-    uid = utf8_to_native (k->uids->name);
-    _snprintf (fname, flen-1, "%s_RevocationCert.asc", uid);
+    _snprintf (fname, flen-1, "%s_RevocationCert.asc", k.ext->uids->name);
     for (i=0; i < strlen (fname); i++) {
 	if (fname[i] == ' ')
 	    fname[i] = '_';
     }
-    safe_free (uid);
 }
 
 

Modified: trunk/Src/wptKeylist.cpp
===================================================================
--- trunk/Src/wptKeylist.cpp	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Src/wptKeylist.cpp	2006-04-27 12:46:03 UTC (rev 205)
@@ -342,7 +342,26 @@
 }
 
 
+/* Extract the key ID from the fingerprint.
+   A long ID will be converted into a short ID. */
 const char*
+get_keyid_from_fpr (const char *fpr)
+{
+    if (!fpr)
+	return "????????";
+    if (strlen (fpr) == 40)
+	fpr += 32;
+    else if (strlen (fpr) == 32)
+	fpr += 24;
+    else if (strlen (fpr) == 16)
+	fpr += 8;
+    else
+	return "????????";
+    return fpr;
+}
+
+
+const char*
 get_key_trust2 (gpgme_key_t key, int val, int uididx, int listmode)
 {
     if (key)
@@ -470,13 +489,16 @@
 static int CALLBACK
 keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby)
 {
+    struct keycache_s *aa, *bb;
     gpgme_key_t a, b;
     int cmpresult = 0;
     
-    a = (gpgme_key_t)first;
-    b = (gpgme_key_t)second;
-    if (!a || !b)
+    aa = (struct keycache_s *)first;
+    bb = (struct keycache_s *)second;
+    if (!aa || !bb)
 	BUG (NULL);
+    a = aa->key;
+    b = bb->key;
     
     switch (sortby & ~KEYLIST_SORT_DESC) {
     case KEY_SORT_USERID:
@@ -607,22 +629,23 @@
 {
     gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);
     gpgme_key_t key, skey;
-    const char * keyid;
+    struct keycache_s *c;
+    const char *keyid;
 
     if (pubkc && seckc) {
 	gpg_keycache_rewind (pubkc);
-        while (!gpg_keycache_next_key (pubkc, 0, &key)) {
+        while (!gpg_keycache_next_key2 (pubkc, 0, &c, &key)) {
             keyid = key->subkeys->keyid;
             if (keyid && !gpg_keycache_find_key (seckc, keyid, 0, &skey))
-		keylist_add_key (lv, mode, key);
+		keylist_add_key (lv, mode, c, key);
         }	
     }
     else if (pubkc) {
 	gpg_keycache_rewind (pubkc);
 	while (!err) {    
-	    err = gpg_keycache_next_key (pubkc, 0, &key);
+	    err = gpg_keycache_next_key2 (pubkc, 0, &c, &key);
 	    if (!err)
-		keylist_add_key (lv, mode, key);
+		keylist_add_key (lv, mode, c, key);
 	}
     }
 }
@@ -688,7 +711,8 @@
 
 
 static int
-do_addkey (listview_ctrl_t lv, gpgme_key_t key, int uididx, int keyidx, int list)
+do_addkey (listview_ctrl_t lv, struct keycache_s *ctx, gpgme_key_t key, 
+	   int uididx, int keyidx, int list)
 {    
     LV_ITEM lvi;
     gpgme_user_id_t u;
@@ -705,21 +729,21 @@
 		   key->uids->name, key->subkeys->keyid);
 	return 0;
     }
-        
-    if (listview_add_item2 (lv, " ", (void *)key))
+
+    if (listview_add_item2 (lv, " ", (void *)ctx))
 	return WPTERR_GENERAL;
 
-    attr = key->uids->uid;
+    attr = ctx->uids->uid;
     memset (&lvi, 0, sizeof lvi);
     lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
     lvi.pszText = (char *)attr;
     lvi.iImage = find_secret_key (key)? 1 : 0;
-    lvi.lParam = (LPARAM )key;
+    lvi.lParam = (LPARAM )ctx;
     if (ListView_SetItem (lv->ctrl, &lvi) == FALSE)
 	return WPTERR_GENERAL;
         
     if (uididx == -1) { /* request the primary user-id of the key. */
-	attr = key->uids->uid;
+	attr = ctx->uids->uid;
 	uididx = 0;
     }
     else {
@@ -738,7 +762,7 @@
     k = get_nth_key (key, keyidx);
     if (k && k->keyid) {
 	_snprintf (fmt, sizeof fmt -1, "0x%s", k->keyid + 8);
-	listview_add_sub_item( lv, 0, idx++, fmt );
+	listview_add_sub_item (lv, 0, idx++, fmt);
     }
     if (list > 0) {
 	key_attr = find_secret_key (key);
@@ -793,7 +817,7 @@
     int i;
 
     for (i=0; i < listview_count_items (lv, 0); i++) {
-	key = (gpgme_key_t)listview_get_item2 (lv, i);
+	key = km_get_key_ptr (lv, i, NULL);
 	if (!key)
 	    continue;
 	switch (col) {
@@ -830,16 +854,17 @@
 /* Update the listview item at position @pos with the data from
    the key @key. */
 void
-keylist_upd_key (listview_ctrl_t lv, int pos, gpgme_key_t key)
+keylist_upd_key (listview_ctrl_t lv, int pos, 
+		 struct keycache_s *ctx, gpgme_key_t key)
 {
     const char *s;
     char *p;
     char tmp[32];
 
-    listview_set_item2 (lv, pos, (void *)key);
-    /* the only mode we support is KYLIST_LIST in the Key Manager */
+    listview_set_item2 (lv, pos, (void *)ctx);
+    /* the only mode we support is KEYLIST_LIST in the Key Manager */
     
-    s = key->uids->uid;
+    s = ctx->uids->uid;
     if (s)
 	listview_add_sub_item (lv, pos, KM_COL_UID, s);
 
@@ -878,7 +903,8 @@
 
 
 int
-keylist_add_key (listview_ctrl_t lv, int mode, gpgme_key_t key)
+keylist_add_key (listview_ctrl_t lv, int mode, 
+		 struct keycache_s *ctx, gpgme_key_t key)
 {
     int uids, rc = 0, i;
     gpgme_subkey_t k;
@@ -895,22 +921,22 @@
 
 	if (mode & KEYLIST_ALL) {
 	    uids = count_userids (key);
-	    rc = do_addkey (lv, key, uids, i, 0);
+	    rc = do_addkey (lv, ctx, key, uids, i, 0);
 	    if (rc)
 		return rc;
 	}
 	else if (mode & KEYLIST_LIST)
-	    return do_addkey (lv, key, -1, i, 1);
+	    return do_addkey (lv, ctx, key, -1, i, 1);
 	else if (mode & KEYLIST_ENCRYPT) {
 	    if (k->can_encrypt && key_is_useable (k)) {
 		if (mode & KEYLIST_FLAG_FILE) {
-		    rc = do_addkey (lv, key, -1, i, -1);
+		    rc = do_addkey (lv, ctx, key, -1, i, -1);
 		    if (rc)
 			return rc;
 		}
 		else {
 		    for (uids = 0;  uids < count_userids (key); uids++) {
-			rc = do_addkey (lv, key, uids, i, -1);
+			rc = do_addkey (lv, ctx, key, uids, i, -1);
 			if (rc)
 			    return rc;
 		    }
@@ -920,7 +946,7 @@
 	else if (mode & KEYLIST_ENCRYPT_MIN) {
 	    if( k->can_encrypt && key_is_useable (k))
 	    {
-		rc = do_addkey (lv, key, -1, i, -1);
+		rc = do_addkey (lv, ctx, key, -1, i, -1);
 		return rc;
 	    }
 	}	
@@ -928,7 +954,7 @@
 	    if (k->can_sign 
 		&& find_secret_key (key)
 		&& key_is_useable (k)) {
-		rc = do_addkey (lv, key, -1, i, -1);
+		rc = do_addkey (lv, ctx, key, -1, i, -1);
 		if (rc)
 		    return rc;	
 	    }
@@ -969,6 +995,7 @@
 keylist_get_recipients (listview_ctrl_t lv, int *r_force_trust, int *r_count)
 {
     key_array_s *ka = NULL;
+    keycache_s *c;
     gpgme_key_t *keybuf, key;
     int count = 0, force_trust = 0;
     int n, j, ka_pos = 0, rc = 0;
@@ -986,13 +1013,12 @@
 	
     for (j = 0; j < n; j++) {
 	if (listview_get_item_state (lv, j) || n == 1) {
-	    key = (gpgme_key_t)listview_get_item2 (lv, j);
+	    key = km_get_key_ptr (lv, j, &c);
 	    if (!key)
 		BUG (0);
 	    if (!key_check_validity (key) &&
 		!key_array_search (ka, ka_pos, key->subkeys->keyid)) {
-		char *utf8_uid = utf8_to_native (key->uids->uid);
-		char *warn = new char[512+strlen (utf8_uid) + 1];
+		char *warn = new char[512+strlen (c->uids->uid) + 1];
 		if (!warn)
 		    BUG (0);
 		sprintf (warn,
@@ -1000,7 +1026,7 @@
 		      "named in the user ID.  If you *really* know what you are\n"
 		      "doing, you may answer the next question with yes\n"
 		      "\n"
-		      "Use \"%s\" anyway?"), utf8_uid);
+		      "Use \"%s\" anyway?"), c->uids->uid);
 		if (reg_prefs.always_trust)
 		    rc = IDYES;
 		else
@@ -1012,7 +1038,6 @@
 		    strcpy (ka[ka_pos++].keyid, key->subkeys->keyid);
 		    count++;
 		}
-		safe_free (utf8_uid);
 		free_if_alloc (warn);
 	    }
 	    else {
@@ -1049,6 +1074,7 @@
 gpgme_key_t*
 keylist_enum_recipients (listview_ctrl_t lv,  int listype, int *r_count)
 {
+    struct keycache_s *c;
     gpgme_key_t *rset;
     gpgme_key_t key;
     int i, n, id, k_pos=0;
@@ -1062,15 +1088,13 @@
     for (i = 0; i < n; i++) {
 	if (!listview_get_item_state (lv, i))
 	    continue;
-	key = (gpgme_key_t)listview_get_item2 (lv, i);
-	if (!key)
-	    BUG (0);
+	key = km_get_key_ptr (lv, i, &c);
 	switch (listype) {
 	case KEYLIST_LIST:
 	    if (keylist_get_keyflags (key) & KEYFLAG_REVOKED) {
 		id = printf_box (_("Recipients"), MB_INFO|MB_YESNO,
 		_("KeyID %s.\nDo you really want to export a revoked key?"),
-				 key->uids->uid);
+				 c->uids->uid);
 		if (id == IDNO)
 		    continue;
 	    }

Modified: trunk/Src/wptKeysigDlg.cpp
===================================================================
--- trunk/Src/wptKeysigDlg.cpp	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Src/wptKeysigDlg.cpp	2006-04-27 12:46:03 UTC (rev 205)
@@ -128,7 +128,7 @@
 	int _class;
     } ctx;
     const char *fmt_templ = _("%s %s signature");
-    const char *s;
+    char *s;
 
     switch (msg) {
     case WM_SYSCOMMAND:
@@ -170,10 +170,11 @@
 	if (ctx.exportable)
 	    CheckDlgButton (dlg, IDC_SIGPROPS_EXP, BST_CHECKED);
 	if (!get_pubkey (ks->keyid+8, &issuer))
-	    s = issuer->uids->uid;
+	    s = utf8_to_native (issuer->uids->uid);
 	else
-	    s = _("  user ID not found");
-	SetDlgItemText_utf8 (dlg, IDC_SIGPROPS_ISSUER, s);
+	    s = strdup (_("  user ID not found"));
+	SetDlgItemText (dlg, IDC_SIGPROPS_ISSUER, s);
+	safe_free (s);
 	if (ks->expires == 0) {
 	    ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPSTR), SW_HIDE);
 	    ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), SW_HIDE);
@@ -389,9 +390,12 @@
         k = (winpt_key_t) lparam;
 	if (!k)
 	    BUG (0);
-        if (k->uid)
-            _snprintf (inf, DIM (inf)-1, _("Signature List for \"%s\""), k->uid);
-        SetWindowText_utf8 (dlg, inf);
+        if (k->uid) {
+	    char *p = utf8_to_native (k->uid);
+            _snprintf (inf, DIM (inf)-1, _("Signature List for \"%s\""), p);
+	    safe_free (p);
+	}
+        SetWindowText (dlg, inf);
         SetDlgItemText (dlg, IDC_KEYSIG_RECVKEY, _("&Receive Key"));
 	SetDlgItemText (dlg, IDC_KEYSIG_SIGPROPS, _("&Properties"));
 

Modified: trunk/Src/wptKeysignDlg.cpp
===================================================================
--- trunk/Src/wptKeysignDlg.cpp	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Src/wptKeysignDlg.cpp	2006-04-27 12:46:03 UTC (rev 205)
@@ -247,7 +247,6 @@
     SYSTEMTIME st;
     HWND h;
     char keymsg[2048], pwd[256];
-    char *uid = NULL;
     const char *keyid, *s;
     int type, expires=0, idx;
     int sig_class = 0;
@@ -268,7 +267,7 @@
                    get_key_created (key->ctx->subkeys->timestamp),
 		   get_expire_date (key->ctx),
                    get_printable_fpr (key->ctx->subkeys->fpr),
-                   key->ctx->uids->uid);
+                   key->ext->uids->uid);
 	s = key->ctx->subkeys->keyid;
 	if (do_fill_seckeylist (dlg, s)) {
 	    msg_box (dlg, _("No valid secret key found."), _("Key Signing"), MB_ERR);
@@ -276,7 +275,7 @@
 	    break;
 	}
 	do_check_protection (dlg);
-        SetDlgItemText_utf8 (dlg, IDC_KEYSIGN_INFOS, keymsg);
+        SetDlgItemText (dlg, IDC_KEYSIGN_INFOS, keymsg);
         SetDlgItemText (dlg, IDC_KEYSIGN_LOCAL, _("Sign local only (non exportable signature)"));
 	SetDlgItemText (dlg, IDC_KEYSIGN_EXPSIG, _("Signature expires on"));
 	SetDlgItemText (dlg, IDC_KEYSIGN_NREV, _("Sign non-revocably"));

Modified: trunk/Src/wptListView.cpp
===================================================================
--- trunk/Src/wptListView.cpp	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Src/wptListView.cpp	2006-04-27 12:46:03 UTC (rev 205)
@@ -201,11 +201,7 @@
 void
 listview_add_sub_item (listview_ctrl_t ctx, int pos, int col, const char *text)
 {
-    char *utf8_txt;
-
-    utf8_txt = utf8_to_native (text);
-    ListView_SetItemText (ctx->ctrl, pos, col, utf8_txt);
-    safe_free (utf8_txt);
+    ListView_SetItemText (ctx->ctrl, pos, col, (char*)text);
 }
 
 

Modified: trunk/Src/wptMDSumDlg.cpp
===================================================================
--- trunk/Src/wptMDSumDlg.cpp	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Src/wptMDSumDlg.cpp	2006-04-27 12:46:03 UTC (rev 205)
@@ -55,6 +55,7 @@
     case GPGME_MD_SHA1:	    return "SHA1";
     case GPGME_MD_RMD160:   return "RMD160";
     case GPGME_MD_SHA256:   return "SHA256";
+    default: return "";
     }
     return "";
 }

Modified: trunk/Src/wptNLS.c
===================================================================
--- trunk/Src/wptNLS.c	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Src/wptNLS.c	2006-04-27 12:46:03 UTC (rev 205)
@@ -48,10 +48,6 @@
 /* We assume to have `unsigned long int' value with at least 32 bits.  */
 #define HASHWORDBITS 32
 
-/* The so called `hashpjw' function by P.J. Weinberger
-   [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools,
-   1986, 1987 Bell Telephone Laboratories, Inc.]  */
-
 /* Header for binary .mo file format.  */
 struct mo_file_header {
     DWORD magic;	    /* The magic number.	*/
@@ -101,18 +97,10 @@
 }
 
 
-/* Missing W32 functions. */
-static char*
-w32_stpcpy (char *a,const char *b)
-{
-    while (*b)
-	*a++ = *b++;
-    *a = 0;
-    return (char*)a;
-}
+/* The so called `hashpjw' function by P.J. Weinberger
+   [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools,
+   1986, 1987 Bell Telephone Laboratories, Inc.]  */
 
-
-
 static DWORD
 hash_string (const char *str_param)
 {
@@ -132,7 +120,18 @@
     return hval;
 }
 
+/* Missing W32 functions. */
+static char*
+w32_stpcpy (char *a,const char *b)
+{
+    while (*b)
+	*a++ = *b++;
+    *a = 0;
+    return (char*)a;
+}
 
+
+
 static struct loaded_domain *
 load_domain( const char *filename )
 {
@@ -285,7 +284,7 @@
     size_t act = 0;
     size_t top, bottom;
 
-    if( !(domain = the_domain) )	
+    if (!(domain = the_domain))
 	goto not_found;
 
     /* Locate the MSGID and its translation.  */

Modified: trunk/Src/wptPassphraseCB.cpp
===================================================================
--- trunk/Src/wptPassphraseCB.cpp	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Src/wptPassphraseCB.cpp	2006-04-27 12:46:03 UTC (rev 205)
@@ -39,6 +39,7 @@
 #include "wptKeylist.h"
 #include "wptAgent.h"
 #include "wptRegistry.h"
+#include "wptUTF8.h"
 
 const char* get_symkey_algo (int algo);
 
@@ -165,11 +166,11 @@
 		free_if_alloc (info);
 	    }
 	    else
-		SetDlgItemText_utf8 (dlg, IDC_DECRYPT_MSG, c->info);
+		SetDlgItemText (dlg, IDC_DECRYPT_MSG, c->info);
 	}
 	else {
 	    SetFocus (GetDlgItem (dlg, IDC_DECRYPT_SIGN_PWD));
-	    SetDlgItemText_utf8 (dlg, IDC_DECRYPT_SIGN_MSG, c->info);
+	    SetDlgItemText (dlg, IDC_DECRYPT_SIGN_MSG, c->info);
 	}
 	center_window (dlg, NULL);
 	SetForegroundWindow (dlg);
@@ -274,7 +275,7 @@
     gpgme_pubkey_algo_t algo;
     char usedkey[16+1];
     char mainkey[16+1];
-    char *p;
+    char *p, *uid;
     int n=0;
 
     algo = (gpgme_pubkey_algo_t)0;
@@ -295,18 +296,20 @@
     uid_hint += 16; /* skip keyid */
     uid_hint += 1;  /* space */
 
+    uid = utf8_to_native (uid_hint);
     if (strcmp (usedkey, mainkey))
 	_snprintf (desc, size-1, 
 		   _("You need a passphrase to unlock the secret key for\n"
 		     "user: \"%s\"\n"
 		     "%s key, ID %s (main key ID %s)\n"),
-		   uid_hint, get_key_pubalgo (algo), usedkey+8, mainkey+8);
+		   uid, get_key_pubalgo (algo), usedkey+8, mainkey+8);
     else if (!strcmp (usedkey, mainkey))
 	_snprintf (desc, size-1,
 		   _("You need a passphrase to unlock the secret key for\n"
 		     "user: \"%s\"\n"
 		     "%s key, ID %s\n"),
-		     uid_hint, get_key_pubalgo (algo), usedkey+8);
+		     uid, get_key_pubalgo (algo), usedkey+8);
+    safe_free (uid);
     return 0;
 }
 

Modified: trunk/Src/wptSigTreeDlg.cpp
===================================================================
--- trunk/Src/wptSigTreeDlg.cpp	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Src/wptSigTreeDlg.cpp	2006-04-27 12:46:03 UTC (rev 205)
@@ -147,7 +147,7 @@
     static HIMAGELIST hil;
     HICON ico[2];
     NMHDR *nft;
-    char inf[300];
+    char inf[300], *p;
 
     switch (msg) {
     case WM_INITDIALOG:
@@ -159,12 +159,14 @@
 	tree = GetDlgItem (dlg, IDC_VKEYSIG_TREE);
 	hil = treeview_set_image_list (tree, ico, 2);
 	sigtree_load (tree, key->ctx);
+	p = utf8_to_native (key->ctx->uids->uid);
 	_snprintf (inf, sizeof (inf)-1, 
 		   _("Signature Tree for \"%s\" (0x%s)"), 
-		   key->ctx->uids->uid/*p*/, key->ctx->subkeys->keyid+8);
+		   p, key->ctx->subkeys->keyid+8);
 	SetDlgItemText (dlg, IDC_VKEYSIG_EDIT, _("Edit..."));
-	SetWindowText_utf8 (dlg, inf);
+	SetWindowText (dlg, inf);
 	SetForegroundWindow (dlg);
+	safe_free (p);
 	break;
 
     case WM_DESTROY:

Modified: trunk/Src/wptVerifyList.cpp
===================================================================
--- trunk/Src/wptVerifyList.cpp	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Src/wptVerifyList.cpp	2006-04-27 12:46:03 UTC (rev 205)
@@ -145,10 +145,9 @@
 verlist_add_sig (listview_ctrl_t lv, gpgme_signature_t sig)
 {
     gpgme_key_t key = NULL;
-    const char * attr;
     u32 key_attr;
+    const char *attr;
     char keyid[32+1];
-    char *uid = NULL;
     
     if (listview_add_item (lv, " "))
 	return WPTERR_GENERAL;
@@ -173,19 +172,9 @@
     }
     listview_add_sub_item (lv, 0, VER_COL_TRUST, (char *)attr);
     
-    attr = sig->fpr;
-    if (!attr || strlen (attr) < 8)
-	listview_add_sub_item (lv, 0, VER_COL_KEYID, "????????");
-    else {
-	if (strlen (attr) == 40)
-	    attr += 32;
-	else if (strlen (attr) == 32)
-	    attr += 24;
-	else
-	    attr += 8;
-	_snprintf (keyid, sizeof keyid -1, "0x%s", attr);
-	listview_add_sub_item (lv, 0, VER_COL_KEYID, keyid);
-    }
+    attr = get_keyid_from_fpr (sig->fpr);	
+    _snprintf (keyid, sizeof keyid -1, "0x%s", attr);
+    listview_add_sub_item (lv, 0, VER_COL_KEYID, keyid);
     
     if (!key)
 	attr = _("user ID not found");
@@ -206,7 +195,6 @@
     gpgme_key_t key = NULL;
     const char *attr;
     char t[64], *name;
-    int off = 0;
 
     if (listview_add_item (lv, "")) {
 	log_debug ("verlist_add_sig_log: listview_add_item() failed.\n");
@@ -240,12 +228,9 @@
     else
 	attr = _("Unknown");
     listview_add_sub_item (lv, 0, VER_COL_TRUST, attr);
-    
-    if (strlen (sig->fpr) == 16)
-	off = 8;
-    else
-	off = strlen (sig->fpr) == 40? 32 : 24;
-    _snprintf (t, sizeof (t)-1, "0x%s", sig->fpr + off);
+
+    attr = get_keyid_from_fpr (sig->fpr);
+    _snprintf (t, sizeof (t)-1, "0x%s", attr);
     listview_add_sub_item (lv, 0, VER_COL_KEYID, t);
     listview_add_sub_item (lv, 0, VER_COL_UID, 
 			   log->user_id? 

Modified: trunk/Src/wptW32API.cpp
===================================================================
--- trunk/Src/wptW32API.cpp	2006-04-26 06:37:23 UTC (rev 204)
+++ trunk/Src/wptW32API.cpp	2006-04-27 12:46:03 UTC (rev 205)
@@ -591,30 +591,7 @@
 }
 
 
-/* SetDlgItemText replacement with UTF8 support. */  
 void
-SetDlgItemText_utf8 (HWND dlg, int id, const char *txt)
-{
-    char *utf8_txt;
-
-    utf8_txt = utf8_to_native (txt);
-    SetDlgItemText (dlg, id, utf8_txt);
-    safe_free (utf8_txt);
-}
-
-/* SetWindowText replacement with UTF8 support. */
-void
-SetWindowText_utf8 (HWND hwnd, const char *txt)
-{
-    char *utf8_txt;
-
-    utf8_txt = utf8_to_native (txt);
-    SetWindowText (hwnd, utf8_txt);
-    safe_free (utf8_txt);
-}
-
-
-void
 ListBox_AddString_utf8 (HWND lb, const char *txt)
 {
     char *utf8_txt;



More information about the Winpt-commits mailing list