[Winpt-commits] r190 - trunk/Src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Mar 27 12:05:15 CEST 2006
Author: twoaday
Date: 2006-03-27 12:05:14 +0200 (Mon, 27 Mar 2006)
New Revision: 190
Modified:
trunk/Src/ChangeLog
trunk/Src/WinPT.cpp
trunk/Src/wptErrors.cpp
trunk/Src/wptKeyEditDlgs.cpp
trunk/Src/wptKeygenDlg.cpp
trunk/Src/wptKeyserverDlg.cpp
trunk/Src/wptMainProc.cpp
trunk/Src/wptSigTreeDlg.cpp
trunk/Src/wptUtil.cpp
trunk/Src/wptW32API.cpp
Log:
2006-03-26 Timo Schulz <ts at g10code.de>
* wptSigTreeDlg.cpp (sigtree_load): Always use UTF8.
* wptMainProc.cpp (winpt_main_proc): Reload key cache
when the GPG settings were changed.
* wptKeygenDlg.cpp (keygen_wizard_dlg_proc,
keygen_dlg_proc): Improved check for the email address.
* wptKeyEditDlgs.cpp (keyedit_adduid_dlg_proc): Likewise.
* wptKeyserverDlg.cpp (keyserver_dlg_proc): Modified design.
Modified: trunk/Src/ChangeLog
===================================================================
--- trunk/Src/ChangeLog 2006-03-27 10:05:04 UTC (rev 189)
+++ trunk/Src/ChangeLog 2006-03-27 10:05:14 UTC (rev 190)
@@ -1,3 +1,13 @@
+2006-03-26 Timo Schulz <ts at g10code.de>
+
+ * wptSigTreeDlg.cpp (sigtree_load): Always use UTF8.
+ * wptMainProc.cpp (winpt_main_proc): Reload key cache
+ when the GPG settings were changed.
+ * wptKeygenDlg.cpp (keygen_wizard_dlg_proc,
+ keygen_dlg_proc): Improved check for the email address.
+ * wptKeyEditDlgs.cpp (keyedit_adduid_dlg_proc): Likewise.
+ * wptKeyserverDlg.cpp (keyserver_dlg_proc): Modified design.
+
2006-03-22 Timo Schulz <ts at g10code.de>
* wptClipSignDlg.cpp (on_init_dialog): New.
Modified: trunk/Src/WinPT.cpp
===================================================================
--- trunk/Src/WinPT.cpp 2006-03-27 10:05:04 UTC (rev 189)
+++ trunk/Src/WinPT.cpp 2006-03-27 10:05:14 UTC (rev 190)
@@ -40,6 +40,7 @@
#include "wptContext.h"
#include "wptCardEdit.h"
#include "wptCrypto.h"
+#include "wptUTF8.h"
void remove_crit_file_attrs (const char *fname, int force);
@@ -49,13 +50,13 @@
HWND activ_hwnd;
int scard_support = 0;
int debug = 0;
-int mobile = 0;
+int mobile_mode_active = 0;
int gpg_read_only = 0;
char gpgver[3];
/* Load the key cache and rebuild the signature cache. */
-static void
+void
update_keycache (HWND hwnd)
{
refresh_cache_s rcs = {0};
@@ -71,9 +72,15 @@
void
gpg_set_debug_mode (int val)
{
- /* XXX: create the file in $user\$temp */
- if (val)
- putenv ("GPGME_DEBUG=5:gpgme.dbg");
+ static char buf[256];
+ char tmp[128];
+
+ /* XXX: no gpgme.dbg is created. */
+ if (val > 0) {
+ GetTempPath (sizeof (tmp)-1, tmp);
+ _snprintf (buf, sizeof (buf)-1, "GPGME_DEBUG=5:%sgpgme.dbg", tmp);
+ putenv (buf);
+ }
else
putenv ("GPGME_DEBUG=");
}
@@ -117,6 +124,7 @@
p = get_reg_entry_gpg ("gpgProgram");
if (!p || file_exist_check (p) != 0) {
free_if_alloc (p);
+ log_debug ("gpg_prefs_ok: could not locate gpg.exe");
return false;
}
}
@@ -127,6 +135,7 @@
p = get_reg_entry_gpg ("HomeDir");
if (!p || dir_exist_check (p) != 0) {
free_if_alloc (p);
+ log_debug ("gpg_prefs_ok: could not determine home directory");
return false;
}
}
@@ -361,9 +370,17 @@
/* Enable the mobility mode. */
-static void
+static int
enable_mobile_mode (void)
{
+ if (dir_exist_check ("temp") != 0) {
+ if (!CreateDirectory ("temp", NULL)) {
+ MessageBox (NULL, "Could not create mobile temp directory",
+ "WinPT Mobile Error", MB_ERR);
+ return -1;
+ }
+ }
+
memset (®_prefs, 0, sizeof (reg_prefs));
reg_prefs.always_trust = 0;
reg_prefs.auto_backup = 0;
@@ -374,6 +391,7 @@
reg_prefs.use_tmpfiles = 1;
reg_prefs.word_wrap = 80;
reg_prefs.use_viewer = 0; /* XXX */
+ return 0;
}
@@ -396,6 +414,21 @@
}
+/* Display info message that WinPT is now in debug mode. */
+void
+winpt_debug_msg (void)
+{
+ char output[512];
+ char temp[128];
+
+ GetTempPath (sizeof temp -1, temp);
+ _snprintf (output, sizeof output - 1,
+ "The GPGME output file is %sgpgme.dbg\n"
+ "The WinPT output file is %swinpt.log\n", temp, temp);
+ MessageBox (NULL, output, "WinPT now runs in DEBUG MODE", MB_INFO);
+}
+
+
/* Main entry point. */
int WINAPI
WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd)
@@ -468,19 +501,19 @@
if (cmdline && stristr (cmdline, "--mobile")) {
msg_box (NULL, "WARNING: mobile modus is not fully implemented yet!",
"WinPT", MB_INFO);
- mobile = 1;
+ mobile_mode_active = 1;
}
-
+
set_default_keyserver ();
load_gettext (winpt_inst_found);
- if (!mobile) {
+ if (!mobile_mode_active) {
regist_inst_gnupg (1);
regist_inst_winpt (1, &created);
}
else {
- enable_mobile_mode ();
- /* XXX: ask for GPG path */
+ if (enable_mobile_mode ())
+ return 0;
created = 1; /* Disable registry writing */
}
@@ -612,13 +645,11 @@
return 0;
}
- if (cmdline) {
- if (stristr (cmdline, "--enable-debug") ||
- stristr (cmdline, "--debug")) {
- gpg_set_debug_mode (1);
- winpt_debug_msg ();
- debug = 1;
- }
+ if (cmdline && (stristr (cmdline, "--enable-debug") ||
+ stristr (cmdline, "--debug"))) {
+ gpg_set_debug_mode (1);
+ winpt_debug_msg ();
+ debug = 1;
}
wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT));
Modified: trunk/Src/wptErrors.cpp
===================================================================
--- trunk/Src/wptErrors.cpp 2006-03-27 10:05:04 UTC (rev 189)
+++ trunk/Src/wptErrors.cpp 2006-03-27 10:05:14 UTC (rev 190)
@@ -1,5 +1,5 @@
/* wptErrors.cpp - Error management
- * Copyright (C) 2000-2004 Timo Schulz
+ * Copyright (C) 2000-2006 Timo Schulz
*
* This file is part of WinPT.
*
@@ -147,29 +147,14 @@
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
buf, DIM (buf)-1, NULL);
MessageBox (NULL, buf, head, MB_OK);
-} /* winpt_errmsg */
+}
+/* This function is used to cleanup static debug resources. */
void
-winpt_debug_msg( void )
-{
- char output[768], temp[384];
-
- GetTempPath( sizeof temp -1, temp );
- _snprintf( output, sizeof output - 1,
- "The GPGME output file is gpgme.dbg\n"
- "The WinPT output file is %swinpt.log\n", temp );
- MessageBox( NULL, output, "WinPT now runs in DEBUG MODE", MB_INFO );
-} /* winpt_debug_msg */
-
-
-/* Dummy function. Not sure for what it is used. */
-void
debug_end (void)
{
-
-
}
@@ -247,4 +232,5 @@
va_end( arg_ptr );
return id;
-} /* log_box */
+}
+
Modified: trunk/Src/wptKeyEditDlgs.cpp
===================================================================
--- trunk/Src/wptKeyEditDlgs.cpp 2006-03-27 10:05:04 UTC (rev 189)
+++ trunk/Src/wptKeyEditDlgs.cpp 2006-03-27 10:05:14 UTC (rev 190)
@@ -545,7 +545,7 @@
msg_box( dlg, _("Please enter an email address."), _("UserID"), MB_ERR );
return FALSE;
}
- if (!strchr (email, '@' ) || strchr (email, ' ')) {
+ if (check_email_address (email)) {
msg_box (dlg, _("Invalid email address."), _("UserID"), MB_ERR);
return FALSE;
}
Modified: trunk/Src/wptKeygenDlg.cpp
===================================================================
--- trunk/Src/wptKeygenDlg.cpp 2006-03-27 10:05:04 UTC (rev 189)
+++ trunk/Src/wptKeygenDlg.cpp 2006-03-27 10:05:14 UTC (rev 190)
@@ -427,7 +427,7 @@
return FALSE;
}
if (!GetDlgItemText (dlg, IDC_KEYGEN_EMAIL, email, sizeof (email) -1)
- || !strchr (email, '@')) {
+ || check_email_address (email)) {
msg_box (dlg, _("Please enter a valid email address."),
_("Key Generation"), MB_ERR);
return FALSE;
@@ -472,7 +472,7 @@
char *utf8_name, *utf8_comment;
utf8_name = native_to_utf8 (name);
utf8_comment = native_to_utf8 (comment);
- if (!utf8_name || !utf8_comment)
+ if( !utf8_name || !utf8_comment )
BUG (0);
p = gpg_genkey_params (keytype, bits, utf8_name, utf8_comment,
email, expire, pwd);
@@ -572,10 +572,10 @@
_("Key Generation Wizard"), MB_WARN);
return FALSE;
}
- if( !GetDlgItemText( dlg, IDC_KEYWIZARD_EMAIL, email, sizeof email-1 )
- || !strchr( email, '@' ) ) {
- msg_box( dlg, _("Please enter a valid email address."),
- _("Key Generation Wizard"), MB_ERR );
+ if (!GetDlgItemText(dlg, IDC_KEYWIZARD_EMAIL, email, sizeof email-1 )
+ || check_email_address (email)) {
+ msg_box (dlg, _("Please enter a valid email address."),
+ _("Key Generation Wizard"), MB_ERR);
return FALSE;
}
if (strchr (email, '<') || strchr (email, '>')) {
@@ -587,8 +587,8 @@
if (cancel)
return FALSE;
utf8_name = native_to_utf8 (name);
- if( !utf8_name )
- BUG( NULL );
+ if (!utf8_name)
+ BUG (0);
if (IsDlgButtonChecked (dlg, IDC_KEYWIZARD_USERSA))
pubkey_algo = GPG_KEYGEN_DSA_RSA;
p = gpg_genkey_params (pubkey_algo, DFAULT_KEYSIZE, utf8_name,
Modified: trunk/Src/wptKeyserverDlg.cpp
===================================================================
--- trunk/Src/wptKeyserverDlg.cpp 2006-03-27 10:05:04 UTC (rev 189)
+++ trunk/Src/wptKeyserverDlg.cpp 2006-03-27 10:05:14 UTC (rev 190)
@@ -46,7 +46,7 @@
char* get_reg_entry_keyserver (const char *);
int set_reg_entry_keyserver (const char *, const char *);
-enum { KS_COL_NAME = 0, KS_COL_PORT, KS_COL_DEFAULT };
+enum { KS_COL_NAME = 0, KS_COL_PORT };
/* Callback context to modify (add, edit) keyserver items. */
struct keyserver_rec_s {
@@ -316,21 +316,6 @@
}
-/* Format the proxy host and display it in the dialog. */
-static void
-set_proxy (HWND dlg)
-{
- char buf[384];
-
- if (proxy.host)
- _snprintf (buf, sizeof (buf)-1, "%s proxy: \"%s:%d\"",
- name_from_proto (proxy.proto), proxy.host, proxy.port);
- else
- strcpy (buf, _("Proxy: none"));
- SetDlgItemText (dlg, IDC_KEYSERVER_PROXY, buf);
-}
-
-
static int inline
kserver_get_pos (listview_ctrl_t lv)
{
@@ -350,20 +335,19 @@
}
-/* Load the default keyserver and mark it in @lv. */
static void
-load_default_ks (listview_ctrl_t lv)
+set_default_ks (listview_ctrl_t lv)
{
- char * p, buf[192];
+ char *p, buf[200];
int i;
p = get_reg_entry_keyserver ("Default");
if (!p)
return;
- for (i = 0; i < listview_count_items (lv, 0); i++) {
- listview_get_item_text (lv, i, KS_COL_NAME, buf, sizeof (buf)-1);
- if (!strncmp (p, buf, strlen (p))) {
- listview_add_sub_item (lv, i, KS_COL_DEFAULT, "x");
+ for (i=0; i < listview_count_items (lv, 0); i++) {
+ listview_get_item_text (lv, i, KS_COL_NAME, buf, sizeof (buf)-1);
+ if (!strcmp (buf, p)) {
+ listview_select_one (lv, i);
break;
}
}
@@ -383,15 +367,11 @@
return -1;
}
listview_get_item_text (lv, idx, KS_COL_NAME, buf, sizeof (buf)-1);
- if (!strncmp (buf, "http", 4) && !strncmp (buf, "hkp", 3)) {
+ if (strncmp (buf, "http", 4) && strncmp (buf, "hkp", 3)) {
msg_box (NULL, _("Only HTTP keyserver can be used."),
_("Keyserver"), MB_ERR);
return -1;
}
- for (i = 0; i < listview_count_items (lv, 0); i++)
- listview_add_sub_item (lv, i, KS_COL_DEFAULT, "");
- listview_add_sub_item (lv, idx, KS_COL_DEFAULT, "x");
- listview_get_item_text (lv, idx, KS_COL_NAME, buf, sizeof (buf)-1);
set_reg_entry_keyserver ("Default", buf);
i = kserver_get_port (lv);
sprintf (port, "%d", i);
@@ -405,9 +385,8 @@
keyserver_list_build (listview_ctrl_t *r_lv, HWND hwnd)
{
struct listview_column_s keyserver[] = {
- {0, 160, (char *)_("DNS Name")},
- {1, 46, (char *)_("Port")},
- {2, 60, (char *)_("Default")},
+ {0, 180, (char *)_("DNS Name")},
+ {1, 55, (char *)_("Port")},
{0, 0, NULL}
};
HICON ico[1];
@@ -429,7 +408,6 @@
sprintf (buf, "%d", server[j].port);
listview_add_sub_item (lv, 0, KS_COL_PORT, buf);
}
- load_default_ks (lv);
if (listview_count_items (lv, 0) == 0) {
listview_add_item (lv, "");
listview_add_sub_item (lv, 0, KS_COL_NAME, DEF_HKP_KEYSERVER);
@@ -540,7 +518,7 @@
EnableWindow (GetDlgItem (dlg, IDC_KSERVADD_TYPES), FALSE);
}
else
- SetDlgItemInt (dlg, IDC_KSERVADD_PORT, 11371, FALSE);
+ SetDlgItemInt (dlg, IDC_KSERVADD_PORT, 11371, FALSE);
SetWindowText (dlg, _("Edit Keyserver"));
SetDlgItemText (dlg, IDOK, _("&Add"));
SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
@@ -609,12 +587,12 @@
SetDlgItemText (dlg, IDC_KEYSERVER_INFO,
_("Please enter the key ID or email address you search for"));
SetDlgItemText (dlg, IDC_KEYSERVER_INDEX, _("&Search"));
- SetDlgItemText (dlg, IDC_KEYSERVER_PROXSETT, _("C&hange"));
+ SetDlgItemText (dlg, IDC_KEYSERVER_PROXSETT, _("C&hange proxy"));
SetDlgItemText (dlg, IDC_KEYSERVER_DEFAULT, _("Set &default"));
SetDlgItemText (dlg, IDCANCEL, _("&Close"));
-
- set_proxy (dlg);
+
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST));
+ set_default_ks (lv);
center_window (dlg, NULL);
SetForegroundWindow (dlg);
return TRUE;
@@ -663,7 +641,6 @@
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY,
dlg, keyserver_proxy_dlg_proc, NULL,
_("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY);
- set_proxy (dlg);
return TRUE;
case IDC_KEYSERVER_INDEX:
Modified: trunk/Src/wptMainProc.cpp
===================================================================
--- trunk/Src/wptMainProc.cpp 2006-03-27 10:05:04 UTC (rev 189)
+++ trunk/Src/wptMainProc.cpp 2006-03-27 10:05:14 UTC (rev 190)
@@ -45,6 +45,9 @@
#include "wptCryptdisk.h"
#include "wptCardEdit.h"
+
+void update_keycache (HWND hwnd);
+
static int cmd = 0;
static int wipe_contents = 0;
@@ -590,9 +593,11 @@
break;
case ID_WINPT_GPGPREFS:
- dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GPGPREFS, GetDesktopWindow(),
- gpgprefs_dlg_proc, 0,
+ rc = dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GPGPREFS,
+ GetDesktopWindow(), gpgprefs_dlg_proc, 0,
_("GnuPG Preferences"), IDS_WINPT_GPGPREFS);
+ if (rc == TRUE)
+ update_keycache (GetDesktopWindow ());
break;
/*
Modified: trunk/Src/wptSigTreeDlg.cpp
===================================================================
--- trunk/Src/wptSigTreeDlg.cpp 2006-03-27 10:05:04 UTC (rev 189)
+++ trunk/Src/wptSigTreeDlg.cpp 2006-03-27 10:05:14 UTC (rev 190)
@@ -57,7 +57,8 @@
for (u=key->uids; u; u = u->next) {
if (u->revoked)
continue;
- tvi.pszText = u->uid;
+ p = utf8_to_native (u->uid);
+ tvi.pszText = p;
tvi.state = TVIS_BOLD;
tvi.mask = TVIF_TEXT;
tvi.iImage = 0;
@@ -65,6 +66,7 @@
ctx.hParent = TVI_ROOT;
ctx.item = tvi;
uid = TreeView_InsertItem (dlg, &ctx);
+ safe_free (p);
for (s = u->signatures; s; s=s->next) {
if (get_pubkey (s->keyid+8, &signer))
continue;
@@ -154,7 +156,7 @@
static HIMAGELIST hil;
HICON ico[2];
NMHDR *nft;
- char inf[256];
+ char inf[256], *p;
switch (msg) {
case WM_INITDIALOG:
@@ -166,8 +168,9 @@
tree = GetDlgItem (dlg, IDC_VKEYSIG_TREE);
hil = treeview_set_image_list (tree, ico, 2);
sigtree_load (tree, key->ctx);
- _snprintf (inf, sizeof (inf)-1, _("Signature Tree for \"%s\""),
- key->ctx->uids->uid);
+ p = utf8_to_native (key->ctx->uids->uid);
+ _snprintf (inf, sizeof (inf)-1, _("Signature Tree for \"%s\""), p);
+ safe_free (p);
SetDlgItemText (dlg, IDC_VKEYSIG_EDIT, _("Edit..."));
SetWindowText (dlg, inf);
SetForegroundWindow (dlg);
Modified: trunk/Src/wptUtil.cpp
===================================================================
--- trunk/Src/wptUtil.cpp 2006-03-27 10:05:04 UTC (rev 189)
+++ trunk/Src/wptUtil.cpp 2006-03-27 10:05:14 UTC (rev 190)
@@ -17,17 +17,17 @@
* 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
#include <string.h>
-#include <string.h>
#include <stdio.h>
#include <ctype.h>
/* code taken from glibc-2.2.1/sysdeps/generic/strsep.c */
-extern "C" char*
+char*
strsep (char **stringp, const char *delim)
{
char *begin, *end;
@@ -68,7 +68,7 @@
/* Like strstr but this version is case in-sentensive. */
-extern "C" const char *
+const char *
stristr (const char *buf, const char *sub)
{
const char *t, *s ;
@@ -88,3 +88,23 @@
return NULL ;
}
+
+/* Check if the email address @email only contain valid characters.
+ Return 0 on success. */
+int
+check_email_address (const char *email)
+{
+ const char *allowed = "@._-%+";
+ size_t i;
+
+ if (!strchr (email, '@'))
+ return -1;
+ for (i=0; i < strlen (email); i++) {
+ if (isdigit (email[i]) || isalpha (email[i])
+ || strchr (allowed, email[i]))
+ continue;
+ else
+ return -1;
+ }
+ return 0;
+}
Modified: trunk/Src/wptW32API.cpp
===================================================================
--- trunk/Src/wptW32API.cpp 2006-03-27 10:05:04 UTC (rev 189)
+++ trunk/Src/wptW32API.cpp 2006-03-27 10:05:14 UTC (rev 190)
@@ -555,6 +555,14 @@
sprintf (tmp, "%08lX", GetTickCount ());
name = tmp;
}
+
+ /* in the mobile mode we use a local temp folder
+ with the fixed name 'temp'. */
+ if (mobile_mode_active) {
+ _snprintf (buf, buflen-1, "temp\\%s", name);
+ return 0;
+ }
+
if (!GetTempPath (buflen - strlen (name) -2, buf)) {
log_debug ("GetTempPath() failed ec=%d\n", (int)GetLastError ());
return -1;
More information about the Winpt-commits
mailing list