[Winpt-commits] r185 - trunk/Src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Mar 20 13:48:55 CET 2006
Author: twoaday
Date: 2006-03-20 13:48:52 +0100 (Mon, 20 Mar 2006)
New Revision: 185
Modified:
trunk/Src/ChangeLog
trunk/Src/WinPT-en.rc
trunk/Src/wptAboutDlgs.cpp
trunk/Src/wptCardDlg.cpp
trunk/Src/wptCardManager.cpp
trunk/Src/wptCryptdisk.cpp
trunk/Src/wptKeyEditDlgs.cpp
trunk/Src/wptKeyManagerDlg.cpp
trunk/Src/wptKeygenCBDlg.cpp
trunk/Src/wptKeyserver.cpp
trunk/Src/wptKeyserverDlg.cpp
trunk/Src/wptKeyserverSearchDlg.cpp
trunk/Src/wptMainProc.cpp
trunk/Src/wptProxySettingsDlg.cpp
trunk/Src/wptUTF8.cpp
Log:
2006-03-20 Timo Schulz <ts at g10code.de>
* wptUTF8.cpp (get_native_charset): Removed.
(utf8_to_native): Rewritten.
* wptKeyEditDlgs.cpp (do_add_new_userid): Correct charset
handling.
* wptKeygenCBDlg.cpp (keygen_cb): Do proper reset if needed.
Modified: trunk/Src/ChangeLog
===================================================================
--- trunk/Src/ChangeLog 2006-03-14 11:04:28 UTC (rev 184)
+++ trunk/Src/ChangeLog 2006-03-20 12:48:52 UTC (rev 185)
@@ -1,3 +1,28 @@
+2006-03-20 Timo Schulz <ts at g10code.de>
+
+ * wptUTF8.cpp (get_native_charset): Removed.
+ (utf8_to_native): Rewritten.
+ * wptKeyEditDlgs.cpp (do_add_new_userid): Correct charset
+ handling.
+ * wptKeygenCBDlg.cpp (keygen_cb): Do proper reset if needed.
+
+2006-03-16 Timo Schulz <ts at g10code.de>
+
+ * wptMainProc.cpp (winpt_main_proc): Disable all CryptDisk code.
+ * wptCryptDisk.cpp: Disable code.
+ * wptProxySettingsDlg.cpp (proxy_settings_dlg_proc): Support for
+ NONE proxy protocol.
+ (init_proxy_procotol): Likewise.
+ (read_proxy): Likewise.
+ * wptKeyserverSearchDlg.cpp (on_init_dialog): New.
+ (keyserver_search_dlg_proc): Use it here.
+ * wptKeyserverDlg.cpp (hkp_send_key): Use GPGME wrapper.
+ * wptKeyserver.cpp (kserver_search_end): New.
+ (kserver_search_begin): Be more strict on mem allocation.
+ * wptKeyManagerDlg.cpp (keymanager_dlg_proc): Fix 'redraw'
+ problem.
+ * wptAboutDlgs.cpp (about_dlg_proc): Hide 'Help' button.
+
2006-03-12 Timo Schulz <ts at g10code.de>
* wptGPG.cpp (gnupg_load_config): Search for 'ask-cert-expire'.
Modified: trunk/Src/WinPT-en.rc
===================================================================
--- trunk/Src/WinPT-en.rc 2006-03-14 11:04:28 UTC (rev 184)
+++ trunk/Src/WinPT-en.rc 2006-03-20 12:48:52 UTC (rev 185)
@@ -2016,14 +2016,6 @@
MENUITEM "GPG", ID_WINPT_GPGPREFS
END
MENUITEM SEPARATOR
- POPUP "Cryptdisk", GRAYED
- BEGIN
- MENUITEM "New Disk...", ID_WINPT_CDISKNEW
- MENUITEM "Mount Disk...", ID_WINPT_CDISKMOUNT
- MENUITEM "Unmount...", ID_WINPT_CDISKUNMOUNT
- MENUITEM "Unmount all disks", ID_WINPT_CDISKUMOUNTALL
- END
- MENUITEM SEPARATOR
MENUITEM "About...", ID_WINPT_ABOUT
MENUITEM "Exit", ID_WINPT_QUIT
END
@@ -2145,7 +2137,6 @@
END
POPUP "&?"
BEGIN
- MENUITEM "&Help", ID_KEYMISC_HELP
MENUITEM "WinPT &Website", ID_KEYMISC_WEBSITE
MENUITEM SEPARATOR
MENUITEM "&Info", ID_KEYMISC_INFO
Modified: trunk/Src/wptAboutDlgs.cpp
===================================================================
--- trunk/Src/wptAboutDlgs.cpp 2006-03-14 11:04:28 UTC (rev 184)
+++ trunk/Src/wptAboutDlgs.cpp 2006-03-20 12:48:52 UTC (rev 185)
@@ -112,8 +112,10 @@
SetDlgItemText (dlg, IDC_ABOUT_GPG, _("&About GPG..."));
SetDlgItemText (dlg, IDC_ABOUT_HELP, _("&Help"));
SetDlgItemText (dlg, IDC_WINPT_VERSION, PACKAGE_FULL_VERSION);
+
/* XXX provide full CHM help file. */
- EnableWindow (GetDlgItem (dlg, IDC_ABOUT_HELP), FALSE);
+ //EnableWindow (GetDlgItem (dlg, IDC_ABOUT_HELP), FALSE);
+ ShowWindow (GetDlgItem (dlg, IDC_ABOUT_HELP), SW_HIDE);
center_window (dlg, NULL);
SetForegroundWindow (dlg);
@@ -132,7 +134,7 @@
switch (LOWORD (wparam)) {
case IDC_ABOUT_GPG:
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_ABOUTGPG,
- GetDesktopWindow(), about_gpg_dlg_proc,
+ dlg, about_gpg_dlg_proc,
0, _("About the GNU Privacy Guard"), 0);
return TRUE;
Modified: trunk/Src/wptCardDlg.cpp
===================================================================
--- trunk/Src/wptCardDlg.cpp 2006-03-14 11:04:28 UTC (rev 184)
+++ trunk/Src/wptCardDlg.cpp 2006-03-20 12:48:52 UTC (rev 185)
@@ -528,7 +528,7 @@
return TRUE;
}
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_CARD_KEYGEN,
- glob_hwnd, card_keygen_dlg_proc, 0);
+ dlg, card_keygen_dlg_proc, 0);
break;
case IDOK:
Modified: trunk/Src/wptCardManager.cpp
===================================================================
--- trunk/Src/wptCardManager.cpp 2006-03-14 11:04:28 UTC (rev 184)
+++ trunk/Src/wptCardManager.cpp 2006-03-20 12:48:52 UTC (rev 185)
@@ -24,7 +24,6 @@
#endif
#include <stdio.h>
-#include <stdio.h>
#include <windows.h>
#include "wptTypes.h"
@@ -45,8 +44,8 @@
switch( msg ) {
case WM_INITDIALOG:
ctx = (struct card_cb_s *)lparam;
- if( !ctx )
- BUG( NULL );
+ if (!ctx)
+ BUG (NULL);
switch (ctx->code) {
case CARD_CTL_INSERT:
ShowWindow (GetDlgItem (dlg, IDC_CCTRL_VAL), FALSE);
Modified: trunk/Src/wptCryptdisk.cpp
===================================================================
--- trunk/Src/wptCryptdisk.cpp 2006-03-14 11:04:28 UTC (rev 184)
+++ trunk/Src/wptCryptdisk.cpp 2006-03-20 12:48:52 UTC (rev 185)
@@ -1,5 +1,5 @@
/* wptCryptdisk.cpp
- * Copyright (C) 2004 Timo Schulz
+ * Copyright (C) 2004, 2006 Timo Schulz
*
* This file is part of WinPT.
*
@@ -21,6 +21,7 @@
#include <config.h>
#endif
+#if 0 /* disabled until the code really works on all systems. */
#include <windows.h>
#include <winioctl.h>
#include <stdio.h>
@@ -705,4 +706,4 @@
CloseServiceHandle (hd);
return rc;
}
-
+#endif
Modified: trunk/Src/wptKeyEditDlgs.cpp
===================================================================
--- trunk/Src/wptKeyEditDlgs.cpp 2006-03-14 11:04:28 UTC (rev 184)
+++ trunk/Src/wptKeyEditDlgs.cpp 2006-03-20 12:48:52 UTC (rev 185)
@@ -186,21 +186,23 @@
/* Add a new user-id to the list view @lv. */
static void
do_add_new_userid (listview_ctrl_t lv,
- const char * name, const char *email, const char * comment)
+ const char *utf8_name, const char *email, const char *comment)
{
- char * p;
+ char *p, *uid;
size_t n;
- n = strlen (name) + strlen (email) + 16;
+ n = strlen (utf8_name) + strlen (email) + 16;
if (comment)
n += strlen (comment);
+ uid = utf8_to_wincp (utf8_name, strlen (utf8_name));
p = new char[n+1];
if (!p)
- BUG( NULL );
+ BUG (NULL);
if (comment)
- sprintf (p, "%s (%s)", name, comment);
+ sprintf (p, "%s (%s)", uid, comment);
else
- sprintf (p, "%s", name);
+ sprintf (p, "%s", uid);
+ free (uid);
listview_add_item (lv, "");
listview_add_sub_item (lv, 0, 0, _("Ultimate" ));
@@ -565,10 +567,10 @@
msg_box (dlg, _("user ID successfully added."), _("GnuPG Status"), MB_OK);
ctx->finished = 1;
}
- delete ke;
+ delete ke;
+ if (!err && ctx->lv)
+ do_add_new_userid (ctx->lv, utf8_name, email, rc?comment : NULL);
free (utf8_name);
- if (!err && ctx->lv)
- do_add_new_userid (ctx->lv, name, email, rc?comment : NULL);
EndDialog (dlg, TRUE);
return TRUE;
Modified: trunk/Src/wptKeyManagerDlg.cpp
===================================================================
--- trunk/Src/wptKeyManagerDlg.cpp 2006-03-14 11:04:28 UTC (rev 184)
+++ trunk/Src/wptKeyManagerDlg.cpp 2006-03-20 12:48:52 UTC (rev 185)
@@ -1752,10 +1752,9 @@
return TRUE;
case ID_KEYMISC_INFO:
- dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_ABOUT, glob_hwnd,
+ dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_ABOUT, dlg,
about_winpt_dlg_proc, 0, _("About WinPT"),
IDS_WINPT_ABOUT);
- SetForegroundWindow (dlg);
break;
case ID_KEYMISC_WEBSITE:
@@ -1769,7 +1768,7 @@
case ID_KEYMISC_OT:
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_OWNERTRUST,
- glob_hwnd, ownertrust_dlg_proc, 0,
+ dlg, ownertrust_dlg_proc, 0,
_("Ownertrust"), IDS_WINPT_OWNERTRUST);
break;
Modified: trunk/Src/wptKeygenCBDlg.cpp
===================================================================
--- trunk/Src/wptKeygenCBDlg.cpp 2006-03-14 11:04:28 UTC (rev 184)
+++ trunk/Src/wptKeygenCBDlg.cpp 2006-03-20 12:48:52 UTC (rev 185)
@@ -17,7 +17,6 @@
* along with WinPT; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
-
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -43,7 +42,7 @@
case WM_INITDIALOG:
SetDlgItemText (dlg, IDC_KEYPROG_CB, "");
SetForegroundWindow (dlg);
- SetWindowText (dlg, _("Key Generation - Progress Dialog"));
+ SetWindowText (dlg, _("Key Generation - Progress Dialog"));
center_window (dlg, NULL);
dlg_hwnd = dlg;
return TRUE;
@@ -115,8 +114,10 @@
return;
}
- if (cb_pos >= (DIM (cb)-1))
+ if (cb_pos >= (DIM (cb)-1)) {
+ SetDlgItemText (dlg_hwnd, IDC_KEYPROG_CB, "");
cb_pos = 0;
+ }
cb[cb_pos] = (char)type;
cb_pos++;
cb[cb_pos] = '\0';
Modified: trunk/Src/wptKeyserver.cpp
===================================================================
--- trunk/Src/wptKeyserver.cpp 2006-03-14 11:04:28 UTC (rev 184)
+++ trunk/Src/wptKeyserver.cpp 2006-03-20 12:48:52 UTC (rev 185)
@@ -716,7 +716,7 @@
return WPTERR_WINSOCK_CONNECT;
}
- if (proxy.proto != PROXY_PROTO_HTTP) {
+ if (proxy.proto == PROXY_PROTO_SOCKS5) {
rc = socks_handshake (&proxy, fd, hostname, port);
if (rc) {
closesocket (fd);
@@ -882,7 +882,7 @@
if (r_keylen)
*r_keylen = n;
- log_debug("%s\r\n", *r_key);
+ log_debug ("%s\r\n", *r_key);
rc = check_hkp_response (*r_key, 1);
if (rc)
goto leave;
@@ -965,13 +965,43 @@
}
+/* Check keyserver response. */
+static int
+kserver_search_chkresp (int fd)
+{
+ char buf[128];
+ int n=0;
+
+ /* parse response 'HTTP/1.0 500 OK' */
+ if (sock_getline (fd, buf, 127, &n))
+ return WPTERR_KEYSERVER_NOTFOUND;
+
+ log_debug ("kserver_search_chkpresp: %s\r\n", buf);
+ if (strncmp (buf, "HTTP/1.", 7))
+ return WPTERR_KEYSERVER_NOTFOUND;
+ if (strncmp (buf+(8+1), "200", 3))
+ return WPTERR_KEYSERVER_NOTFOUND;
+ return 0;
+}
+
+
+/* End the keyserver search procedure. */
+void
+kserver_search_end (int conn_fd)
+{
+ log_debug ("kserver_search_end: fd=%d\r\n", conn_fd);
+ closesocket (conn_fd);
+}
+
+
+/* Begin keyserver search procedure. */
int
-kserver_search_init (const char *hostname, WORD port,
- const char *keyid, int *conn_fd)
+kserver_search_begin (const char *hostname, WORD port,
+ const char *pattern, int *conn_fd)
{
char *request = NULL;
- char *enc_keyid = NULL;
- int n = 0;
+ char *enc_patt = NULL;
+ int n;
int rc, sock_fd;
rc = kserver_connect (hostname, port, &sock_fd);
@@ -980,8 +1010,10 @@
goto leave;
}
- enc_keyid = URL_encode (keyid, strlen (keyid), NULL);
- n=300;
+ enc_patt = URL_encode (pattern, strlen (pattern), NULL);
+ n = 140 + strlen (enc_patt) + strlen (hostname) + 32 + 2;
+ if (proxy.base64_user)
+ n += strlen (proxy.base64_user) + 1;
request = new char[n+1];
if (!request)
BUG (0);
@@ -990,55 +1022,43 @@
_snprintf (request, n,
"GET http://%s:%d/pks/lookup?op=index&search=%s HTTP/1.0\r\n"
"Proxy-Authorization: Basic %s\r\n\r\n",
- skip_type_prefix (hostname), port, enc_keyid, proxy.base64_user);
+ skip_type_prefix (hostname), port, enc_patt, proxy.base64_user);
}
else if (proxy.host && proxy.proto == PROXY_PROTO_HTTP) {
_snprintf (request, n,
"GET http://%s:%d/pks/lookup?op=index&search=%s HTTP/1.0\r\n\r\n",
- skip_type_prefix (hostname), port, enc_keyid);
+ skip_type_prefix (hostname), port, enc_patt);
}
else {
_snprintf (request, n,
"GET /pks/lookup?op=index&search=%s HTTP/1.0\r\n\r\n",
- enc_keyid);
+ enc_patt);
}
- log_debug ("kserver_search_init:\r\n%s\r\n", request);
+ log_debug ("kserver_search_begin:\r\n%s\r\n", request);
if (sock_write (sock_fd, request, strlen (request)) == SOCKET_ERROR) {
rc = WPTERR_GENERAL;
goto leave;
}
+ rc = kserver_search_chkresp (sock_fd);
+ if (rc) {
+ closesocket (sock_fd);
+ sock_fd = 0;
+ }
+
*conn_fd = sock_fd;
leave:
free_if_alloc (request);
- free_if_alloc (enc_keyid);
+ free_if_alloc (enc_patt);
return rc;
}
-/* Check keyserver response. */
-int
-kserver_search_chkresp (int fd)
-{
- char buf[128];
- int n=0;
-
- /* parse response 'HTTP/1.0 500 OK' */
- if (sock_getline (fd, buf, 127, &n))
- return WPTERR_KEYSERVER_NOTFOUND;
- log_debug ("kserver_search_chkpresp: %s\r\n", buf);
- if (strncmp (buf, "HTTP/1.", 7))
- return WPTERR_KEYSERVER_NOTFOUND;
- if (strncmp (buf+(8+1), "200", 3))
- return WPTERR_KEYSERVER_NOTFOUND;
- return 0;
-}
-
/* Convert an iso date @iso_date (YYYY-MM-DD) into the locale
representation and store it into @loc_date.
Return value: 0 on success. */
@@ -1071,16 +1091,17 @@
int
-kserver_search (int fd, keyserver_key *key)
+kserver_search_next (int fd, keyserver_key *key)
{
char buf[1024], *p;
int uidlen, nbytes, pos = 0;
- log_debug ("keyserver_search:\r\n");
+ log_debug ("keyserver_search_next:\r\n");
if (sock_getline (fd, buf, sizeof (buf) - 1, &nbytes))
return WPTERR_GENERAL;
+ /* XXX: use maschine readable option. */
log_debug ("%s\r\n", buf);
if (!strncmp (buf, "pub", 3)) {
@@ -1148,6 +1169,7 @@
free_if_alloc (ctx->host);
free_if_alloc (ctx->pass);
free_if_alloc (ctx->user);
+ ctx->port = ctx->proto = 0;
}
Modified: trunk/Src/wptKeyserverDlg.cpp
===================================================================
--- trunk/Src/wptKeyserverDlg.cpp 2006-03-14 11:04:28 UTC (rev 184)
+++ trunk/Src/wptKeyserverDlg.cpp 2006-03-20 12:48:52 UTC (rev 185)
@@ -1,5 +1,5 @@
/* wptKeyserverDlg.cpp - Keyserver dialog
- * Copyright (C) 2000-2005 Timo Schulz
+ * Copyright (C) 2000-2006 Timo Schulz
* Copyright (C) 2005 g10 Code GmbH
*
* This file is part of WinPT.
@@ -35,6 +35,7 @@
#include "wptW32API.h"
#include "wptVersion.h"
#include "wptGPG.h"
+#include "wptGPGME.h"
#include "wptKeyManager.h"
#include "wptContext.h" /* for passphrase_s */
#include "wptDlgs.h"
@@ -76,27 +77,19 @@
int
hkp_send_key (HWND dlg, const char *kserver, WORD port, const char *pattern)
{
- gpgme_ctx_t ctx;
- gpgme_data_t keydata;
+ GPGME *gpg;
gpgme_error_t ec;
char *rawkey = NULL;
char msg[384];
- size_t n;
- ec = gpgme_new (&ctx);
- if (ec)
- BUG (NULL);
- gpgme_set_armor (ctx, 1);
- ec = gpgme_data_new (&keydata);
- if (ec)
- BUG (NULL);
- ec = gpgme_op_export (ctx, pattern, 0, keydata);
+ gpg = new GPGME ();
+ gpg->setArmor (true);
+ ec = gpg->exportToBuffer (pattern, &rawkey);
if (ec) {
msg_box (dlg, gpgme_strerror (ec), _("Export"), MB_ERR);
goto leave;
}
- rawkey = gpgme_data_release_and_get_mem (keydata, &n);
- ec = kserver_sendkey (kserver, port, rawkey, n);
+ ec = kserver_sendkey (kserver, port, rawkey, strlen (rawkey));
if (ec) {
hkp_err_box (dlg, kserver, port, ec);
goto leave;
@@ -106,9 +99,8 @@
status_box (dlg, msg, _("GnuPG status"));
leave:
- gpgme_release (ctx);
- if (rawkey)
- gpgme_free (rawkey);
+ delete gpg;
+ free_if_alloc (rawkey);
return ec? -1 : 0;
}
@@ -305,7 +297,7 @@
leave:
return rc;
-} /* check_pattern */
+}
/* Return human readable name for the proxy protocol. */
@@ -315,14 +307,16 @@
const char *s;
switch (proto) {
- case PROXY_PROTO_HTTP: s = "HTTP"; break;
- case PROXY_PROTO_SOCKS5: s = "SOCKS5"; break;
- default: s= "HTTP"; break;
+ case PROXY_PROTO_NONE: s = ""; break;
+ case PROXY_PROTO_HTTP: s = "HTTP"; break;
+ case PROXY_PROTO_SOCKS5: s = "SOCKS5"; break;
+ default: s= "HTTP"; break;
}
return s;
}
+/* Format the proxy host and display it in the dialog. */
static void
set_proxy (HWND dlg)
{
@@ -728,7 +722,7 @@
return FALSE;
}
if (proto_nr == KSPROTO_LDAP && strchr (pattern, '@')) {
- msg_box (dlg, _("Only keyids are allowed."),
+ msg_box (dlg, _("Only keyids are allowed."),
_("Keyserver"), MB_INFO);
return FALSE;
}
Modified: trunk/Src/wptKeyserverSearchDlg.cpp
===================================================================
--- trunk/Src/wptKeyserverSearchDlg.cpp 2006-03-14 11:04:28 UTC (rev 184)
+++ trunk/Src/wptKeyserverSearchDlg.cpp 2006-03-20 12:48:52 UTC (rev 185)
@@ -35,18 +35,17 @@
#include "wptNLS.h"
+enum { KSS_COL_BITS = 0, KSS_COL_KEYID, KSS_COL_DATE, KSS_COL_UID };
+
int
hkp_recv_key2 (HWND dlg, const char *kserver, WORD port,
const char *pattern, int proto, char **r_fpr);
-/* Dialog box procedur for keyserver searching. */
-BOOL CALLBACK
-hkpsearch_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
+/* Initialize dialog. */
+static listview_ctrl_t
+on_init_dialog (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
{
- static listview_ctrl_t lv = NULL;
- static keyserver_ctx * ksc;
- keyserver_key key;
struct listview_column_s keysearch[] = {
{0, 48, (char *)_("Size")},
{1, 64, (char *)_("Key ID")},
@@ -54,55 +53,79 @@
{3, 256, (char *)_("User ID")},
{0, 0, NULL}
};
- char t[32], info[384], *fpr = NULL;
- int i, rc;
+ char info[384];
+ int i;
+ listview_ctrl_t lv = NULL;
+
+ SetDlgItemText (dlg, IDC_HKPSEARCH_RECV, _("&Receive"));
+ SetDlgItemText (dlg, IDOK, _("&Cancel"));
+ _snprintf (info, sizeof (info) - 1,
+ _("Connect to '%s' to search for \"%s\""),
+ ((keyserver_ctx *)lparam)->name, ((keyserver_ctx *)lparam)->pattern);
+ SetDlgItemText (dlg, IDC_HKPSEARCH_INFO, info);
+ SetWindowText (dlg, _("Keyserver Searching"));
+ SetForegroundWindow (dlg);
+ listview_new (&lv);
+ lv->ctrl = GetDlgItem (dlg, IDC_HKPSEARCH_LIST);
+ for (i = 0; keysearch[i].width; i++)
+ listview_add_column (lv, &keysearch[i]);
+ listview_set_ext_style (lv);
+ return lv;
+}
+
+
+
+static int
+search_hkp_keys (HWND dlg, keyserver_ctx *ksc, listview_ctrl_t lv)
+{
+ int rc;
int conn_fd = 0;
+ char t[32];
+ keyserver_key key;
+
+ rc = kserver_search_begin (ksc->name, ksc->port, ksc->pattern, &conn_fd);
+ if (rc) {
+ msg_box (dlg, winpt_strerror (rc), _("Keyserver Search"), MB_ERR);
+ return rc;
+ }
+
+ while (!kserver_search_next (conn_fd, &key)) {
+ if (!key.bits)
+ continue;
+ _snprintf (t, sizeof (t) - 1, "%d", key.bits);
+ listview_add_item (lv, " ");
+ listview_add_sub_item (lv, 0, KSS_COL_BITS, t);
+ listview_add_sub_item (lv, 0, KSS_COL_KEYID, key.keyid);
+ listview_add_sub_item (lv, 0, KSS_COL_DATE, key.date);
+ listview_add_sub_item (lv, 0, KSS_COL_UID, key.uid);
+ }
+
+ kserver_search_end (conn_fd);
+ return 0;
+}
+
+
+/* Dialog box procedure for keyserver searching. */
+BOOL CALLBACK
+hkpsearch_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+ static listview_ctrl_t lv = NULL;
+ static keyserver_ctx *ksc;
+ char *fpr = NULL, t[32];
+ int pos;
+ int rc;
switch (msg) {
case WM_INITDIALOG:
ksc = (keyserver_ctx *)lparam;
if (!ksc)
dlg_fatal_error (dlg, "Could not get dialog param.");
- SetWindowText (dlg, _("Keyserver Searching"));
- SetDlgItemText (dlg, IDC_HKPSEARCH_RECV, _("&Receive"));
- SetDlgItemText (dlg, IDOK, _("&Cancel"));
- _snprintf (info, sizeof (info) - 1,
- _("Connect to '%s' to search for \"%s\""),
- ksc->name, ksc->pattern);
- SetDlgItemText (dlg, IDC_HKPSEARCH_INFO, info);
- listview_new (&lv);
- lv->ctrl = GetDlgItem (dlg, IDC_HKPSEARCH_LIST);
- for (i = 0; keysearch[i].width; i++)
- listview_add_column (lv, &keysearch[i]);
- listview_set_ext_style (lv);
- rc = kserver_search_init (ksc->name, ksc->port, ksc->pattern, &conn_fd);
+ lv = on_init_dialog (dlg, msg, wparam, lparam);
+ rc = search_hkp_keys (dlg, ksc, lv);
if (rc) {
- msg_box (dlg, winpt_strerror (rc), _("Keyserver Search"), MB_ERR);
EndDialog (dlg, FALSE);
- return FALSE;
- }
- rc = kserver_search_chkresp (conn_fd);
- if (rc) {
- msg_box (dlg, winpt_strerror (rc), _("Keyserver Search"), MB_ERR);
- closesocket (conn_fd);
- EndDialog (dlg, FALSE);
return FALSE;
}
- for (;;) {
- rc = kserver_search (conn_fd, &key);
- if (rc)
- break;
- if (!key.bits)
- continue;
- _snprintf (t, sizeof (t) - 1, "%d", key.bits);
- listview_add_item (lv, " ");
- listview_add_sub_item (lv, 0, 0, t);
- listview_add_sub_item (lv, 0, 1, key.keyid);
- listview_add_sub_item (lv, 0, 2, key.date);
- listview_add_sub_item (lv, 0, 3, key.uid);
- }
- closesocket (conn_fd);
- SetForegroundWindow (dlg);
return TRUE;
case WM_DESTROY:
@@ -128,11 +151,11 @@
return FALSE;
case IDC_HKPSEARCH_RECV:
- if ((i = listview_get_curr_pos (lv)) == -1) {
+ if ((pos = listview_get_curr_pos (lv)) == -1) {
msg_box (dlg, _("Please select a key."), _("Keyserver Search"), MB_ERR);
return FALSE;
}
- listview_get_item_text (lv, i, 1, t, sizeof (t) -1);
+ listview_get_item_text (lv, pos, 1, t, sizeof (t) -1);
rc = hkp_recv_key2 (dlg, ksc->name, ksc->port, t, 0, &fpr);
if (!rc && fpr != NULL) {
keycache_update (0, fpr);
Modified: trunk/Src/wptMainProc.cpp
===================================================================
--- trunk/Src/wptMainProc.cpp 2006-03-14 11:04:28 UTC (rev 184)
+++ trunk/Src/wptMainProc.cpp 2006-03-20 12:48:52 UTC (rev 185)
@@ -357,7 +357,7 @@
case WM_DESTROY:
case WM_CLOSE:
case WM_QUIT:
- cryptdisk_cleanup ();
+ /*cryptdisk_cleanup ();*/
mapi_deinit ();
wsock_end ();
keycache_release (1);
@@ -402,11 +402,13 @@
set_menu_text( popup, ID_WINPT_CARD, _("Card Manager") );
if (!scard_support)
set_menu_state (popup, ID_WINPT_CARD, MF_DISABLED|MF_GRAYED);
+ /*
if (!cryptdisk_available ()) {
set_menu_state (popup, ID_WINPT_CDISKNEW, MF_DISABLED|MF_GRAYED);
set_menu_state (popup, ID_WINPT_CDISKMOUNT, MF_DISABLED|MF_GRAYED);
set_menu_state (popup, ID_WINPT_CDISKUNMOUNT, MF_DISABLED|MF_GRAYED);
}
+ */
set_menu_text (popup, ID_WINPT_EDIT, _("Edit Clipboard"));
set_menu_text (popup, ID_WINPT_ABOUT, _("About..."));
@@ -593,6 +595,7 @@
_("GnuPG Preferences"), IDS_WINPT_GPGPREFS);
break;
+ /*
case ID_WINPT_CDISKNEW:
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_CDISK_NEW,
GetDesktopWindow (), cryptdisk_new_dlg_proc, 0);
@@ -611,6 +614,7 @@
case ID_WINPT_CDISKUMOUNTALL:
cryptdisk_unmount (0, 0);
break;
+ */
case ID_WINPT_QUIT:
SendMessage (hwnd, WM_DESTROY, 0, 0);
Modified: trunk/Src/wptProxySettingsDlg.cpp
===================================================================
--- trunk/Src/wptProxySettingsDlg.cpp 2006-03-14 11:04:28 UTC (rev 184)
+++ trunk/Src/wptProxySettingsDlg.cpp 2006-03-20 12:48:52 UTC (rev 185)
@@ -33,6 +33,8 @@
#include "wptKeyserver.h"
#include "wptRegistry.h"
+#define combo_get_sel(dlg, id) \
+ SendDlgItemMessage ((dlg), (id), CB_GETCURSEL, 0, 0)
static int
check_number (HWND dlg, int id)
@@ -72,6 +74,12 @@
pos = 7;
ctx->host = strdup (t + pos);
}
+ else {
+ msg_box (dlg, _("Please enter the proxy hostname."),
+ _("Proxy Settings"), MB_ERR);
+ return -1;
+ }
+
if (check_number (dlg, IDC_PROXY_PORT)) {
msg_box (dlg, _("Invalid port number."), _("Proxy Settings"), MB_ERR);
return -1;
@@ -93,6 +101,7 @@
_("Proxy Settings"), MB_INFO);
return -1;
}
+ ctx->proto = combo_get_sel (dlg, IDC_PROXY_PROTO);
return 0;
}
@@ -110,6 +119,7 @@
init_proxy_protocols (HWND dlg)
{
HWND cb = GetDlgItem (dlg, IDC_PROXY_PROTO);
+ combox_add_string (cb, (char *)"NONE");
combox_add_string (cb, (char *)"HTTP");
/*combox_add_string (cb, (char *)"SOCKS5");*/
SendMessage (cb, CB_SETCURSEL, (WPARAM)0, 0);
@@ -146,6 +156,8 @@
SetDlgItemText (dlg, IDC_PROXY_AUTHINF, _("Authentication"));
SetWindowText (dlg, _("Proxy Settings"));
init_proxy_protocols (dlg);
+ SendDlgItemMessage (dlg, IDC_PROXY_PROTO, CB_SETCURSEL,
+ (WPARAM)proxy.proto, 0);
center_window (dlg, NULL);
SetForegroundWindow (dlg);
break;
@@ -157,6 +169,13 @@
case WM_COMMAND:
switch (HIWORD (wparam)) {
+ case CBN_SELCHANGE:
+ if (combo_get_sel (dlg, (int)LOWORD (wparam))) {
+ }
+ else {
+ }
+ break;
+
case BN_CLICKED:
switch ((int)LOWORD (wparam)) {
case IDC_PROXY_AUTH:
@@ -172,7 +191,6 @@
switch (LOWORD (wparam)) {
case IDOK:
if (IsDlgButtonChecked (dlg, IDC_PROXY_AUTH) &&
- item_get_text_length (dlg, IDC_PROXY_HOST) == 0 &&
item_get_text_length (dlg, IDC_PROXY_USER) == 0 &&
item_get_text_length (dlg, IDC_PROXY_PWD) == 0) {
msg_box (dlg, _("Please fill out all required fields for authentication."),
@@ -180,9 +198,12 @@
return TRUE;
}
kserver_proxy_release (&proxy);
- if (read_proxy (dlg, &proxy))
- return FALSE;
+ if (combo_get_sel (dlg, IDC_PROXY_PROTO) != PROXY_PROTO_NONE) {
+ if (read_proxy (dlg, &proxy))
+ return FALSE;
+ }
set_reg_proxy_prefs (&proxy);
+ log_box ("debug", 0, "%d", proxy.proto);
EndDialog (dlg, TRUE);
return TRUE;
Modified: trunk/Src/wptUTF8.cpp
===================================================================
--- trunk/Src/wptUTF8.cpp 2006-03-14 11:04:28 UTC (rev 184)
+++ trunk/Src/wptUTF8.cpp 2006-03-20 12:48:52 UTC (rev 185)
@@ -1,6 +1,6 @@
/* wptUTF8.cpp - UTF8 conversation
* Copyright (C) 1994, 1998-2001 Free Software Foundation, Inc.
- * Copyright (C) 2002, 2004, 2005 Timo Schulz
+ * Copyright (C) 2002, 2004, 2005, 2006 Timo Schulz
*
* This file is part of WinPT.
*
@@ -33,321 +33,93 @@
#include "wptErrors.h"
-static WORD latin2_unicode[128] = {
- 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,
- 0x0088,0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,
- 0x0090,0x0091,0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,
- 0x0098,0x0099,0x009A,0x009B,0x009C,0x009D,0x009E,0x009F,
- 0x00A0,0x0104,0x02D8,0x0141,0x00A4,0x013D,0x015A,0x00A7,
- 0x00A8,0x0160,0x015E,0x0164,0x0179,0x00AD,0x017D,0x017B,
- 0x00B0,0x0105,0x02DB,0x0142,0x00B4,0x013E,0x015B,0x02C7,
- 0x00B8,0x0161,0x015F,0x0165,0x017A,0x02DD,0x017E,0x017C,
- 0x0154,0x00C1,0x00C2,0x0102,0x00C4,0x0139,0x0106,0x00C7,
- 0x010C,0x00C9,0x0118,0x00CB,0x011A,0x00CD,0x00CE,0x010E,
- 0x0110,0x0143,0x0147,0x00D3,0x00D4,0x0150,0x00D6,0x00D7,
- 0x0158,0x016E,0x00DA,0x0170,0x00DC,0x00DD,0x0162,0x00DF,
- 0x0155,0x00E1,0x00E2,0x0103,0x00E4,0x013A,0x0107,0x00E7,
- 0x010D,0x00E9,0x0119,0x00EB,0x011B,0x00ED,0x00EE,0x010F,
- 0x0111,0x0144,0x0148,0x00F3,0x00F4,0x0151,0x00F6,0x00F7,
- 0x0159,0x016F,0x00FA,0x0171,0x00FC,0x00FD,0x0163,0x02D9
-};
-
-
-static const char *active_charset_name = "iso-8859-1";
-static WORD *active_charset = NULL;
-static int no_translation = 0;
-
-
-static int
-ascii_strcasecmp( const char *a, const char *b )
+/* convert latin1 string @string into utf8. */
+char *
+native_to_utf8( const char *string )
{
- if( a == b )
- return 0;
+ const byte *s;
+ char *buffer;
+ byte *p;
+ size_t length=0;
- for (; *a && *b; a++, b++) {
- if (*a != *b && toupper(*a) != toupper(*b))
- break;
+ for (s=(byte*)string; *s; s++) {
+ length++;
+ if (*s & 0x80)
+ length++;
}
-
- return *a == *b? 0 : (toupper (*a) - toupper (*b));
+ buffer = (char*)malloc (length + 1);
+ for (p = (byte*)buffer, s=(byte*)string; *s; s++) {
+ if (*s & 0x80) {
+ *p++ = 0xc0 | ((*s >> 6) & 3);
+ *p++ = 0x80 | ( *s & 0x3f );
+ }
+ else
+ *p++ = *s;
+ }
+ *p = 0;
+ return buffer;
}
-int
-set_native_charset( const char *newset )
-{
- if( !ascii_strcasecmp( newset, "iso-8859-1" ) ) {
- active_charset_name = "iso-8859-1";
- no_translation = 0;
- active_charset = NULL;
- }
- else if( !ascii_strcasecmp( newset, "iso-8859-2" ) ) {
- active_charset_name = "iso-8859-2";
- no_translation = 0;
- active_charset = latin2_unicode;
- }
- else if( !ascii_strcasecmp (newset, "utf8" )
- || !ascii_strcasecmp(newset, "utf-8") ) {
- active_charset_name = "utf-8";
- no_translation = 1;
- active_charset = NULL;
- }
- else
- return WPTERR_GENERAL;
- return 0;
-}
-const char*
-get_native_charset( void )
-{
- return active_charset_name;
-}
+/* Convert utf8 string @str to native CP. */
+static char*
+utf8_to_native (const char *string)
+{
+ wchar_t *result;
+ char *native;
+ int n;
+ /* Convert utf8 to unicode. */
+ n = MultiByteToWideChar (CP_UTF8, 0, string, -1, NULL, 0);
+ if (n < 0)
+ return NULL;
-/****************
- * Convert string, which is in native encoding to UTF8 and return the
- * new allocated UTF8 string.
- */
-char *
-native_to_utf8( const char *string )
-{
- const byte *s;
- char *buffer;
- byte *p;
- size_t length=0;
+ result = (wchar_t*)malloc ((n+1) * sizeof *result);
+ if (!result)
+ BUG (0);
- if (no_translation)
- buffer = strdup( string );
- else if( active_charset ) {
- for(s=(byte*)string; *s; s++ ) {
- length++;
- if( *s & 0x80 )
- length += 2; /* we may need 3 bytes */
- }
- buffer = (char *)malloc( length + 1 );
- for(p=(byte *)buffer, s=(byte *)string; *s; s++ ) {
- if( *s & 0x80 ) {
- WORD val = active_charset[ *s & 0x7f ];
- if( val < 0x0800 ) {
- *p++ = 0xc0 | ( (val >> 6) & 0x1f );
- *p++ = 0x80 | ( val & 0x3f );
- }
- else {
- *p++ = 0xe0 | ( (val >> 12) & 0x0f );
- *p++ = 0x80 | ( (val >> 6) & 0x3f );
- *p++ = 0x80 | ( val & 0x3f );
- }
- }
- else
- *p++ = *s;
- }
- *p = 0;
- }
- else {
- for(s=(byte*)string; *s; s++ ) {
- length++;
- if( *s & 0x80 )
- length++;
- }
- buffer = (char*)malloc( length + 1 );
- for(p=(byte*)buffer, s=(byte*)string; *s; s++ ) {
- if( *s & 0x80 ) {
- *p++ = 0xc0 | ((*s >> 6) & 3);
- *p++ = 0x80 | ( *s & 0x3f );
- }
- else
- *p++ = *s;
- }
- *p = 0;
- }
+ n = MultiByteToWideChar (CP_UTF8, 0, string, -1, result, n);
+ if (n < 0) {
+ free (result);
+ return NULL;
+ }
- return buffer;
-} /* native_to_utf8 */
+ /* Convert wide char into native char. */
+ /*
+ n = WideCharToMultiByte (GetACP (), 0, result, -1, NULL, 0, NULL, NULL);
+ if (n < 0)
+ return NULL;
+ */
+ n = wcstombs (NULL, result, wcslen (result));
+ if (n < 0)
+ return NULL;
-/****************
- * Convert string, which is in UTF8 to native encoding. illegal
- * encodings by some "\xnn" and quote all control characters. A
- * character with value DELIM will always be quoted, it must be a
- * vanilla ASCII character.
- */
-char *
-utf8_to_native( const char *string, size_t length, int delim )
-{
- int nleft;
- int i;
- byte encbuf[8];
- int encidx;
- const byte *s;
- size_t n;
- byte *buffer = NULL, *p = NULL;
- unsigned long val = 0;
- size_t slen;
- int resync = 0;
-
- /* 1. pass (p==NULL): count the extended utf-8 characters */
- /* 2. pass (p!=NULL): create string */
- for( ;; ) {
- for( slen=length, nleft=encidx=0, n=0, s=(byte*)string; slen; s++, slen-- ) {
- if( resync ) {
- if( !(*s < 128 || (*s >= 0xc0 && *s <= 0xfd)) ) {
- /* still invalid */
- if( p ) {
- sprintf((char*)p, "\\x%02x", *s );
- p += 4;
- }
- n += 4;
- continue;
- }
- resync = 0;
- }
- if( !nleft ) {
- if( !(*s & 0x80) ) { /* plain ascii */
- if( *s < 0x20 || *s == 0x7f || *s == delim) {
- n++;
- if( p )
- *p++ = '\\';
- switch( *s ) {
- case '\n': n++; if( p ) *p++ = 'n'; break;
- case '\r': n++; if( p ) *p++ = 'r'; break;
- case '\f': n++; if( p ) *p++ = 'f'; break;
- case '\v': n++; if( p ) *p++ = 'v'; break;
- case '\b': n++; if( p ) *p++ = 'b'; break;
- case 0 : n++; if( p ) *p++ = '0'; break;
- default:
- n += 3;
- if ( p ) {
- sprintf( (char*)p, "x%02x", *s );
- p += 3;
- }
- break;
- }
- }
- else {
- if( p ) *p++ = *s;
- n++;
- }
- }
- else if( (*s & 0xe0) == 0xc0 ) { /* 110x xxxx */
- val = *s & 0x1f;
- nleft = 1;
- encidx = 0;
- encbuf[encidx++] = *s;
- }
- else if( (*s & 0xf0) == 0xe0 ) { /* 1110 xxxx */
- val = *s & 0x0f;
- nleft = 2;
- encidx = 0;
- encbuf[encidx++] = *s;
- }
- else if( (*s & 0xf8) == 0xf0 ) { /* 1111 0xxx */
- val = *s & 0x07;
- nleft = 3;
- encidx = 0;
- encbuf[encidx++] = *s;
- }
- else if( (*s & 0xfc) == 0xf8 ) { /* 1111 10xx */
- val = *s & 0x03;
- nleft = 4;
- encidx = 0;
- encbuf[encidx++] = *s;
- }
- else if( (*s & 0xfe) == 0xfc ) { /* 1111 110x */
- val = *s & 0x01;
- nleft = 5;
- encidx = 0;
- encbuf[encidx++] = *s;
- }
- else { /* invalid encoding: print as \xnn */
- if( p ) {
- sprintf((char*)p, "\\x%02x", *s );
- p += 4;
- }
- n += 4;
- resync = 1;
- }
- }
- else if( *s < 0x80 || *s >= 0xc0 ) { /* invalid */
- if( p ) {
- for(i=0; i < encidx; i++ ) {
- sprintf((char*)p, "\\x%02x", encbuf[i] );
- p += 4;
- }
- sprintf((char*)p, "\\x%02x", *s );
- p += 4;
- }
- n += 4 + 4*encidx;
- nleft = 0;
- encidx = 0;
- resync = 1;
- }
- else {
- encbuf[encidx++] = *s;
- val <<= 6;
- val |= *s & 0x3f;
- if( !--nleft ) { /* ready */
- if (no_translation) {
- if( p ) {
- for(i=0; i < encidx; i++ )
- *p++ = encbuf[i];
- }
- n += encidx;
- encidx = 0;
- }
- else if( active_charset ) { /* table lookup */
- for(i=0; i < 128; i++ ) {
- if( active_charset[i] == val )
- break;
- }
- if( i < 128 ) { /* we can print this one */
- if( p ) *p++ = i+128;
- n++;
- }
- else { /* we do not have a translation: print utf8 */
- if( p ) {
- for(i=0; i < encidx; i++ ) {
- sprintf((char*)p, "\\x%02x", encbuf[i] );
- p += 4;
- }
- }
- n += encidx*4;
- encidx = 0;
- }
- }
- else { /* native set */
- if( val >= 0x80 && val < 256 ) {
- n++; /* we can simply print this character */
- if( p ) *p++ = val;
- }
- else { /* we do not have a translation: print utf8 */
- if( p ) {
- for(i=0; i < encidx; i++ ) {
- sprintf((char*)p, "\\x%02x", encbuf[i] );
- p += 4;
- }
- }
- n += encidx*4;
- encidx = 0;
- }
- }
- }
-
- }
- }
- if( !buffer ) { /* allocate the buffer after the first pass */
- buffer = p = (byte *)malloc( n + 1 );
- }
- else {
- *p = 0; /* make a string */
- return (char*)buffer;
- }
+ native = (char*)malloc (n+1);
+ if (!native)
+ BUG (0);
+
+ /*
+ n = WideCharToMultiByte (CP_ACP, 0, string, -1, result, n, NULL, NULL);
+ if (n < 0) {
+ free (result);
+ return NULL;
}
+ */
+ n = wcstombs (native, result, -1);
+ if (n < 0) {
+ free (result);
+ return NULL;
+ }
+
+ return native;
}
-
+/* CP850 -> CP1251 */
static void
conv_charset (byte *string, size_t size, int what)
{
- int i;
+ size_t i;
if( what == 0 ) {
for( i = 0; i < size; i++, string++ ) {
@@ -555,7 +327,7 @@
}
}
}
-} /* conv_charset */
+}
/* XXX: the conv_charset() call fails when the user-id was created
@@ -565,7 +337,7 @@
utf8_to_wincp (const char * s, size_t len)
{
char *decs;
- decs = utf8_to_native (s, len, 0);
+ decs = utf8_to_native (s);
conv_charset ((byte *)decs, strlen (decs), 1);
return decs;
}
More information about the Winpt-commits
mailing list