[Winpt-commits] r278 - trunk/Src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Jan 15 23:02:10 CET 2007
Author: twoaday
Date: 2007-01-15 23:02:04 +0100 (Mon, 15 Jan 2007)
New Revision: 278
Modified:
trunk/Src/ChangeLog
trunk/Src/Makefile.am
trunk/Src/WinPT.cpp
trunk/Src/wptCardDlg.cpp
trunk/Src/wptCardManager.cpp
trunk/Src/wptClipDecryptDlg.cpp
trunk/Src/wptClipEncryptDlg.cpp
trunk/Src/wptClipVerifyDlg.cpp
trunk/Src/wptErrors.cpp
trunk/Src/wptFileCBS.cpp
trunk/Src/wptFileManagerDlg.cpp
trunk/Src/wptGPGPrefsDlg.cpp
trunk/Src/wptGPGUtil.cpp
trunk/Src/wptImportList.cpp
trunk/Src/wptKeyEdit.cpp
trunk/Src/wptKeyEditCB.cpp
trunk/Src/wptKeyEditDlgs.cpp
trunk/Src/wptKeyManager.cpp
trunk/Src/wptKeygenDlg.cpp
trunk/Src/wptKeylist.cpp
trunk/Src/wptKeyserver.cpp
trunk/Src/wptKeyserverDlg.cpp
trunk/Src/wptKeysignDlg.cpp
trunk/Src/wptMainProc.cpp
trunk/Src/wptNLS.cpp
trunk/Src/wptPassphraseCB.cpp
trunk/Src/wptPassphraseDlg.cpp
trunk/Src/wptRegistry.cpp
trunk/Src/wptSymEnc.cpp
trunk/Src/wptUTF8.cpp
trunk/Src/wptUtil.cpp
trunk/Src/wptVerifyList.cpp
trunk/Src/wptW32API.cpp
Log:
See ChangeLog.
Modified: trunk/Src/ChangeLog
===================================================================
--- trunk/Src/ChangeLog 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/ChangeLog 2007-01-15 22:02:04 UTC (rev 278)
@@ -1,3 +1,23 @@
+2006-12-30 Timo Schulz <twoaday at freakmail.de>
+
+ * StringBuffer.cpp (StringBuffer): New.
+ * wptPassphraseDlg.cpp (set_passphrase_hint): Replace error prone
+ sprintf code with the new string buffer implementation.
+ * wptPassphraseCB.cpp (passphrase_callback_proc): Likewise.
+
+2006-12-28 Timo Schulz <twoaday at freakmail.de>
+
+ * wptKeylist.cpp (get_key_desc): Avoid possible overflow.
+ * wptW32API.cpp (get_locale_time): New.
+ (get_locale_timedate): New.
+ * wptVerifyList.cpp (strtimestamp): Deleted. Changed all
+ callers to get_locale_timedate.
+ * wptMainProc.cpp (winpt_main_proc): Cleanup gettext resources.
+ * wptNLS.cpp (gettext_free_current_domain): New.
+ (gettext_set_file): Removed all '/' code.
+ * wptPassphraseCb.cpp (passphrase_callback_proc): Make sprintf
+ code more robust.
+
2006-12-21 Timo Schulz <twoaday at freakmail.de>
* wptCryptDisk.cpp, wptCryptDiskSrv.cpp: Deleted.
Modified: trunk/Src/Makefile.am
===================================================================
--- trunk/Src/Makefile.am 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/Makefile.am 2007-01-15 22:02:04 UTC (rev 278)
@@ -14,7 +14,7 @@
bin_PROGRAMS = WinPT
EXTRA_DIST = versioninfo.rc.in
-AM_CPPFLAGS = -I$(top_srcdir)/Include \
+AM_CPPFLAGS = -I$(top_srcdir)/Include -I$(top_srcdir)/Generic \
-I$(top_srcdir)/Gnupg -I$(top_srcdir)/PTD \
-DWIN32 -D_WINDOWS -D_MBCS
AM_CFLAGS = -fexceptions $(GPGME_CFLAGS)
@@ -31,6 +31,8 @@
pubkey.ico \
keypair.ico
+generic_files = ../Generic/StringBuffer.cpp
+
dialog_files = \
wptAboutDlgs.cpp \
wptCardDlg.cpp \
@@ -124,7 +126,7 @@
wptMisc.c
-WinPT_SOURCES = $(resource_files) $(dialog_files) $(code_files)
+WinPT_SOURCES = $(resource_files) $(dialog_files) $(code_files) $(generic_files)
WinPT_LDADD = WinPT-en.o -L../Gnupg\
-lgnupg ../PTD/PTD.dll \
$(GPGME_LIBS) $(W32LIBS) \
Modified: trunk/Src/WinPT.cpp
===================================================================
--- trunk/Src/WinPT.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/WinPT.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -12,10 +12,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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>
@@ -107,7 +103,7 @@
/* Return the name of the gettext language file. */
nls = get_reg_entry_mo ();
if (nls != NULL) {
- set_gettext_file ("winpt", nls);
+ gettext_set_file ("winpt", nls);
free_if_alloc (nls);
}
}
@@ -300,8 +296,8 @@
}
else if (rc) {
log_box (_("WinPT Error"), MB_ERR,
- _("Sorry, you need a newer GPG version.\n"
- "GPG version %d.%d.%d required GPG version "NEED_GPG_VERSION),
+ _("A newer GPG version is needed.\n"
+ "Current GPG version %d.%d.%d, required "NEED_GPG_VERSION),
ma, mi, pa);
return false;
}
@@ -528,10 +524,10 @@
return 0;
}
- #ifdef _DEBUG
+#ifdef _DEBUG
gpg_set_debug_mode (1);
debug = 1;
- #endif
+#endif
get_file_version ("WinPT.exe", &ver[0], &ver[1], &ver[2], &ver[3]);
ec = get_file_version ("PTD.dll", &ptdver[0], &ptdver[1],
@@ -691,14 +687,14 @@
return 0;
}
- #ifndef WINPT_MOBILE
+#ifndef WINPT_MOBILE
if (cmdline && (stristr (cmdline, "--enable-debug") ||
stristr (cmdline, "--debug"))) {
gpg_set_debug_mode (1);
winpt_debug_msg ();
debug = 1;
}
- #endif
+#endif
wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT));
rc = RegisterClass (&wc);
Modified: trunk/Src/wptCardDlg.cpp
===================================================================
--- trunk/Src/wptCardDlg.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptCardDlg.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -13,10 +13,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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
@@ -41,6 +37,7 @@
#include "wptCardEdit.h"
#include "wptCard.h"
#include "wptContext.h"
+#include "StringBuffer.h"
int keygen_check_date (SYSTEMTIME * st);
@@ -415,10 +412,8 @@
do_askpin (HWND dlg, int which, gpg_card_t card,
struct pin_cb_ctx_s *cb)
{
- const char *s, *fmt;
- const char *n1, *n2, *serial;
+ const char *s;
char *p;
- size_t n;
if( (which == CARD_ADMIN_PIN && cb->apin) ||
(which == CARD_USER_PIN && cb->upin) )
@@ -431,22 +426,15 @@
else
s = _("Please enter the PIN");
cb->which = which;
- free_if_alloc( cb->info_text );
- if( card ) {
- fmt = _("%s\nName: %s %s\nSerial-No: %s\n");
- n1 = card->givenname;
- n2 = card->surname;
- if( !n1 || !n2 ) {
- n1 = "No"; n2 = "Name";
- }
- serial = card->serial;
- if (!serial)
- serial = "No Serial ID";
- n = strlen( n1 ) + strlen( n2 ) + strlen( fmt ) + strlen( serial ) + 3;
- p = cb->info_text = new char[strlen (s)+n+1];
- if( !p )
- BUG (0);
- sprintf (p, fmt, s, n1, n2, serial);
+ free_if_alloc (cb->info_text);
+ if (card) {
+ StringBuffer buf;
+
+ buf = s;
+ buf = buf + "\nName: " + (card->givenname?card->givenname: "No");
+ buf = buf + " " + (card->surname?card->surname : "Name");
+ buf = buf + "\nSerial-No:" + card->serial;
+ p = buf.getBufferCopy ();
}
else
p = cb->info_text = m_strdup (s);
Modified: trunk/Src/wptCardManager.cpp
===================================================================
--- trunk/Src/wptCardManager.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptCardManager.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -13,12 +13,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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
Modified: trunk/Src/wptClipDecryptDlg.cpp
===================================================================
--- trunk/Src/wptClipDecryptDlg.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptClipDecryptDlg.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -35,6 +35,7 @@
#include "wptKeylist.h"
#include "wptUTF8.h"
#include "resource.h"
+#include "StringBuffer.h"
bool is_seckey_available (gpgme_recipient_t rset);
char* get_pka_status (gpgme_signature_t sig);
@@ -46,20 +47,20 @@
get_key_userid (const char *keyid)
{
winpt_key_s key;
- const char *fmt, *userid;
+ StringBuffer p;
+ const char *userid;
char *uid;
- fmt = "\n \"%s\"";
+ p = "\n ";
memset (&key, 0, sizeof (key));
if (winpt_get_pubkey (keyid, &key))
userid = (_("user ID not found"));
else
userid = key.ext->uids->uid;
- uid = new char[strlen (userid) + strlen (fmt)+ 2];
- if (!uid)
- BUG (NULL);
- sprintf (uid, fmt, userid);
+ p = p + "\"" + userid + "\"";
+
winpt_release_pubkey (&key);
+ uid = p.getBufferCopy ();
return uid;
}
@@ -129,8 +130,9 @@
"*** Signer: %s (0x%s)\r\n"
"*** BEGIN PGP DECRYPTED TEXT ***\r\n");
const char *foot = _("\r\n*** END PGP DECRYPTED TEXT ***");
- const char *s, *ver, *ot, *uid;
- char *p, *made;
+ const char *stat, *ot, *uid;
+ char made[128], ver[128];
+ char *p;
if (winpt_get_pubkey (sig->fpr, &pk)) {
uid = _("user ID not found");
@@ -141,18 +143,19 @@
ot = verify_get_key_ownertrust (pk.ctx->owner_trust, NULL);
}
- made = m_strdup (strtimestamp (sig->timestamp));
- ver = strtimestamp (time (NULL));
- s = get_gpg_sigstat (sig->summary);
- p = new char[strlen (head) + strlen (s) + strlen (made) +
+ if (!get_locale_timedate (sig->timestamp, made, DIM (made)-1))
+ _snprintf (made, DIM (made)-1, "'unknown time'");
+ if (!get_locale_timedate (time (NULL), ver, DIM (ver)-1))
+ _snprintf (ver, DIM (ver)-1, "'unknown time'");
+ stat = get_gpg_sigstat (sig->summary);
+ p = new char[strlen (head) + strlen (stat) + strlen (made) +
strlen (sig->fpr) + strlen (ot) + strlen (ver) +
strlen (uid) + 1];
if (!p)
BUG (0);
- sprintf (p, head, made, ver, ot, s, uid, get_keyid_from_fpr (sig->fpr));
+ sprintf (p, head, made, ver, ot, stat, uid, get_keyid_from_fpr (sig->fpr));
*r_header = p;
*r_footer = m_strdup (foot);
- free_if_alloc (made);
}
@@ -163,7 +166,7 @@
winpt_key_s key;
const char *keyid, *uid;
const char *s;
- char *pka_info = NULL;
+ char *pka_info = NULL, timebuf[128];
int novalid = 0;
assert (sig->fpr != NULL);
@@ -179,6 +182,9 @@
uid = _("user ID not found");
}
+ if (!get_locale_timedate (sig->timestamp, timebuf, DIM (timebuf)-1))
+ _snprintf (timebuf, DIM (timebuf)-1, "'unknown time'");
+
pka_info = get_pka_status (sig);
log_box (_("Decrypt Verify"), novalid? MB_WARN : MB_OK,
_("%s\n"
@@ -187,8 +193,7 @@
"From \"%s\" using key ID 0x%s"
"%s %s\n%s"),
s, get_gpg_sigstat (sig->summary),
- strtimestamp (sig->timestamp),
- uid, keyid,
+ timebuf, uid, keyid,
novalid? "\nPrimary key fingerprint: " : "",
novalid? get_key_fpr (key.ctx) : "",
pka_info? pka_info : ""
Modified: trunk/Src/wptClipEncryptDlg.cpp
===================================================================
--- trunk/Src/wptClipEncryptDlg.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptClipEncryptDlg.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -39,6 +39,7 @@
#include "wptRegistry.h"
#include "wptDlgs.h"
#include "wptUTF8.h"
+#include "StringBuffer.h"
/* Encrypt the contents of the clipboard with the keys in @rset.
@@ -99,10 +100,11 @@
gpgme_encrypt_result_t res;
gpgme_invalid_key_t k;
gpgme_key_t key;
+ StringBuffer p;
size_t len=0;
const char *keyid;
const char *warn = _("key not found");
- char *uid, *p;
+ char *uid;
if (!ctx)
return -1;
@@ -117,10 +119,7 @@
len += strlen (warn) + strlen (k->fpr)+8 + 2 + 4;
}
- p = (char *)calloc (1, len+64);
- if (!p)
- BUG (NULL);
- strcpy (p, _("Recipients unsuable for encryption:\n"));
+ p = _("Recipients unsuable for encryption:\n");
for (k = res->invalid_recipients; k; k = k->next) {
if (!get_pubkey (k->fpr, &key)) {
uid = utf8_to_native (key->uids->name);
@@ -130,14 +129,10 @@
uid = strdup (warn);
keyid = k->fpr;
}
- strcat (p, keyid);
- strcat (p, " : ");
- strcat (p, uid);
- strcat (p, "\n");
+ p = p + keyid + " : " + uid + "\n";
safe_free (uid);
}
- msg_box (dlg, p, _("Encryption"), MB_ERR);
- safe_free (p);
+ msg_box (dlg, p.getBuffer (), _("Encryption"), MB_ERR);
return 0;
}
Modified: trunk/Src/wptClipVerifyDlg.cpp
===================================================================
--- trunk/Src/wptClipVerifyDlg.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptClipVerifyDlg.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -36,6 +36,7 @@
#include "wptDlgs.h"
#include "wptErrors.h"
#include "wptVersion.h"
+#include "StringBuffer.h"
/* XXX use @out directly and do not use gpg_data_extract to store the plain text. */
@@ -105,39 +106,23 @@
gpgme_sig_notation_t nota;
gpgme_sig_notation_t n;
gpgme_verify_result_t res;
- size_t len=0;
- char *p;
+ StringBuffer p;
res = gpgme_op_verify_result (ctx);
if (!res || !res->signatures || !res->signatures->notations)
return;
nota = res->signatures->notations;
+
+ p = "Notation data:\n";
for (n=nota; n; n = n->next) {
- if (n->name)
- len += strlen (n->name) + 1 + 2;
+ if (!n->name)
+ p = p + "policy url: ";
else
- len += strlen ("policy URL") + 1 + 2;
- len += strlen (n->value) + 1 + 2;
- len += 6;
+ p = p + n->name + " : " ;
+ p = p + "\"" + n->value + "\"\n";
}
- p = (char *)calloc (1, len+64);
- if (!p)
- BUG (NULL);
- strcpy (p, "Notation data:\n");
- for (n=nota; n; n = n->next) {
- if (!n->name)
- strcat (p, "policy url: ");
- else {
- strcat (p, n->name);
- strcat (p, " : ");
- }
- strcat (p, "\"");
- strcat (p, n->value);
- strcat (p, "\"\n");
- }
- msg_box (dlg, p, _("Signature Information"), MB_INFO);
- safe_free (p);
+ msg_box (dlg, p.getBuffer (), _("Signature Information"), MB_INFO);
}
Modified: trunk/Src/wptErrors.cpp
===================================================================
--- trunk/Src/wptErrors.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptErrors.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -32,30 +32,34 @@
#include "wptGPG.h"
#include "wptNLS.h"
+static FILE *log_fp = NULL;
-static char *
-gpg_strerror( int errid )
+
+/* Return a GPG specific error message. */
+static char*
+gpg_strerror (int errid)
{
- static char buf[512];
- char * path = NULL;
+ static char buf[2*MAX_PATH+1];
+ char *path;
- path = get_gnupg_path();
- if( !path )
- BUG( NULL );
- switch( errid ) {
+ path = get_gnupg_path ();
+ if (!path)
+ BUG (NULL);
+ switch (errid) {
case WPTERR_GPG_EXEFILE:
- _snprintf( buf, sizeof buf - 1, _("Could not locate GPG.exe in %s."), path );
+ _snprintf (buf, DIM (buf) - 1,
+ _("Could not locate GPG.exe in %s."), path);
break;
case WPTERR_GPG_OPT_KEYRINGS:
case WPTERR_GPG_KEYRINGS:
- _snprintf( buf, sizeof buf - 1,
+ _snprintf (buf, DIM (buf) - 1,
_("Could not find keyring entries in the config file in %s "
- "or the file does NOT exist."), path );
+ "or the file does NOT exist."), path);
break;
}
- free_if_alloc( path );
+ free_if_alloc (path);
return buf;
-} /* gpg_strerror */
+}
static void
@@ -66,6 +70,7 @@
buf, buflen, NULL);
}
+
/* Return an error specific message.
If there is a translation available, it returns the translated text. */
const char*
@@ -73,8 +78,8 @@
{
static char buf[256];
- switch( errid ) {
- case -1: w32_fmt_msg (buf, 255); return buf;
+ switch (errid) {
+ case -1: w32_fmt_msg (buf, DIM (buf)-1); return buf;
case WPTERR_GENERAL: return _("General error occured");
case WPTERR_FILE_OPEN: return _("Could not open file");
case WPTERR_FILE_CREAT: return _("Could not create file");
@@ -91,9 +96,9 @@
case WPTERR_CLIP_ISEMPTY: return _("There is no text in the Clipboard");
case WPTERR_CLIP_SECURED: return _("The Clipboard already contains GPG data");
case WPTERR_CLIP: return _("General Clipboard error");
- case WPTERR_REGISTRY: sprintf (buf, "%s", _("Registry error: "));
- w32_fmt_msg (buf + strlen (buf), 128);
- return buf;
+ case WPTERR_REGISTRY: _snprintf (buf, DIM (buf)-1, "%s", _("Registry error: "));
+ w32_fmt_msg (buf + strlen (buf), DIM (buf)/2);
+ return buf;
case WPTERR_WINSOCK_INIT: return _("Could not startup Winsock 2 interface");
case WPTERR_WINSOCK_RESOLVE: return _("Could not resolve hostname");
case WPTERR_WINSOCK_SOCKET: return _("Could not create new socket");
@@ -101,10 +106,10 @@
case WPTERR_WINSOCK_SENDKEY: return _("Could not send the key to the keyserver");
case WPTERR_WINSOCK_RECVKEY: return _("Could not receive the key from the keyserver");
case WPTERR_WINSOCK_TIMEOUT: return _("Socket timed out, no data");
- case WPTERR_WINSOCK_PROXY: return _("Could not forward request to proxy");
+ case WPTERR_WINSOCK_PROXY: return _("Could not forward request to proxy");
case WPTERR_KEYSERVER_NOTFOUND: return _("Keyserver returned: no matching keys in database");
- case WPTERR_HOTKEY: sprintf (buf, "%s", _("Could not register hotkey: "));
- w32_fmt_msg (buf + strlen (buf), 128);
+ case WPTERR_HOTKEY: _snprintf (buf, DIM (buf)-1, "%s", _("Could not register hotkey: "));
+ w32_fmt_msg (buf + strlen (buf), DIM (buf)/2);
return buf;
case WPTERR_DIR_OPEN: return _("Could not open directory");
case WPTERR_DIR_CREAT: return _("Could not create directory");
@@ -124,16 +129,18 @@
case WPTERR_CDISK_OPEN: return _("Could not open volume");
case WPTERR_CDISK_BUSY: return _("Drive that belongs to the volume is busy");
case WPTERR_CDISK_QUERY: return _("Could not query volume information");
- */
- default: _snprintf (buf, sizeof (buf) - 1, _("Unknown error=%d"), errid); return buf;
+ */
+ default: _snprintf (buf, DIM (buf) - 1,
+ _("Unknown error=%d"), errid); return buf;
}
return NULL;
-} /* winpt_strerror */
+}
+/* Display a message box with the last system error. */
void
-winpt_errmsg (const char * name, int is_file)
+winpt_errmsg (const char *name, int is_file)
{
TCHAR buf[500], head[500];
DWORD last_err;
@@ -153,87 +160,75 @@
}
-
-/* This function is used to cleanup static debug resources. */
+/* Show debug message. */
void
-debug_end (void)
+debug_box (const char *msg, const char *file, int line)
{
-}
-
-
-
-void
-debug_box( const char *msg, const char *file, int line )
-{
-#if _DEBUG
+ #if _DEBUG
char output[4096];
memset( output, 0, sizeof output );
_snprintf( output, sizeof output -1,
"WinPT DBG:\n \"%s\", file %s, line %d\n", msg, file, line );
MessageBox( NULL, output, PGM_NAME, MB_OK | MB_ICONERROR );
-#endif
-} /* debug_box */
+ #endif
+}
void
-debug_f( const char *msg, const char *file, int line )
+debug_f (const char *msg, const char *file, int line)
{
-#if _DEBUG
- FILE *fp;
- char temp_path[ 1024 ];
- char output[ 4096 ];
+ #if _DEBUG
+ log_debug ("DBG:\n \"%s\", file %s, line %d\n", msg, file, line);
+ #endif
+}
- GetTempPath( sizeof temp_path - 1, temp_path );
- strcat( temp_path, "\\WinPT.DEBUG" );
- fp = fopen( temp_path, "a+b" );
- if( !fp )
- return;
- memset( output, 0, sizeof output );
- _snprintf( output, sizeof output -1,
- "WinPT DBG:\n \"%s\", file %s, line %d\n", msg, file, line );
- fwrite( output, 1, strlen( output ), fp );
- fflush( fp );
- fclose( fp );
-#endif
-} /* debug_f */
-
+/* Log a message into the log file. */
void
log_debug (const char *format, ...)
-{
- FILE *fp;
- char temp_path[384];
+{
+ char tmpdir[384];
va_list arg_ptr;
if (!debug)
return;
- GetTempPath (sizeof temp_path - 1, temp_path);
- strcat (temp_path, "\\WinPT.LOG");
- fp = fopen (temp_path, "a+b");
- if (!fp)
- return;
+ if (log_fp == NULL) {
+ GetTempPath (sizeof (tmpdir) - 32, tmpdir);
+ strcat (tmpdir, "\\WinPT.LOG");
+ log_fp = fopen (tmpdir, "a+b");
+ if (!log_fp)
+ return;
+ }
va_start (arg_ptr, format);
- vfprintf (fp, format, arg_ptr);
+ vfprintf (log_fp, format, arg_ptr);
va_end (arg_ptr);
- fflush (fp);
- fclose (fp);
+ fflush (log_fp);
}
+/* Cleanup */
+void
+debug_end (void)
+{
+ if (log_fp != NULL)
+ fclose (log_fp);
+}
+
+
+/* Emulate an MessageBox with variable input. */
int
printf_box (const char *title, int style, const char *format, ...)
{
va_list arg_ptr;
- char log[8192];
+ char log[4096];
int id;
va_start (arg_ptr, format);
_vsnprintf (log, sizeof (log)-1, format, arg_ptr);
- id = msg_box (NULL, log, title? title : "Log Output", style);
- va_end( arg_ptr );
+ id = msg_box (NULL, log, title, style);
+ va_end (arg_ptr);
return id;
}
-
Modified: trunk/Src/wptFileCBS.cpp
===================================================================
--- trunk/Src/wptFileCBS.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptFileCBS.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -13,12 +13,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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
@@ -111,6 +106,7 @@
HANDLE fd = NULL;
SECURITY_ATTRIBUTES sec_attr;
+ *r_cb = NULL; /* reset */
memset (&sec_attr, 0, sizeof (sec_attr));
sec_attr.bInheritHandle = FALSE;
sec_attr.nLength = sizeof (sec_attr);
@@ -137,18 +133,18 @@
}
err = gpgme_data_new_from_cbs (&cb->dat, &cb->cbs, cb);
- if (err) {
+ if (!err)
+ *r_cb = cb;
+ else {
CloseHandle (fd);
free_if_alloc (cb);
- return err;
- }
+ }
- *r_cb = cb;
return err;
}
-/* Activate the progress callback for the given object @ctx. */
+/* Set the progress callback for the given object @ctx. */
void
gpg_file_data_set_cb (file_data_t ctx, struct progress_filter_s *pfx)
{
@@ -164,7 +160,8 @@
}
-/* Release the context in @cb. Close all internal handles if possible. */
+/* Release the context in @cb.
+ Close all internal handles if possible. */
void
gpg_file_data_release (file_data_t cb)
{
Modified: trunk/Src/wptFileManagerDlg.cpp
===================================================================
--- trunk/Src/wptFileManagerDlg.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptFileManagerDlg.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -12,12 +12,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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
@@ -213,12 +208,12 @@
return TRUE;
}
else {
- const char *s = _("%s contain(s) %d key(s).");
- char *p = new char[strlen (s) + 32];
+ const char *fmt = _("%s contain(s) %d key(s).");
+ const char *name = c->import.is_clip? _("Clipboard") : _("File");
+ char *p = new char[strlen (fmt) + strlen (name) + 32 + 1];
if (!p)
BUG (NULL);
- sprintf (p, s, c->import.is_clip? _("Clipboard") : _("File"),
- listview_count_items (lv, 0));
+ sprintf (p, fmt, name, listview_count_items (lv, 0));
SetDlgItemText (dlg, IDC_IMPORT_INFO, p);
free_if_alloc (p);
}
Modified: trunk/Src/wptGPGPrefsDlg.cpp
===================================================================
--- trunk/Src/wptGPGPrefsDlg.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptGPGPrefsDlg.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -36,7 +36,7 @@
/* Enable all edit items if @val is TRUE, disable them otherwise. */
static void
-enable_disable_items (HWND dlg, BOOL val)
+activate_items (HWND dlg, BOOL val)
{
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_EXEDIR), val);
EnableWindow (GetDlgItem (dlg, IDC_GPGREFS_EXEDLG), val);
@@ -192,6 +192,15 @@
}
}
+#ifdef WINPT_MOBILE
+ /* In mobile mode we do not allow to change the default settings
+ because this would not make any sense. */
+ CheckDlgButton (dlg, IDC_GPGPREFS_OVRDEFAULT, BST_UNCHECKED);
+ EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_OVRDEFAULT), FALSE);
+ activate_items (dlg, FALSE);
+#endif
+
+
center_window (dlg, NULL);
SetForegroundWindow (dlg);
return TRUE;
@@ -204,11 +213,11 @@
if (HIWORD (wparam) == BN_CLICKED &&
LOWORD (wparam) == IDC_GPGPREFS_OVRDEFAULT) {
if (IsDlgButtonChecked (dlg, LOWORD (wparam))) {
- enable_disable_items (dlg, TRUE);
+ activate_items (dlg, TRUE);
gpg4win = false;
}
else {
- enable_disable_items (dlg, FALSE);
+ activate_items (dlg, FALSE);
gpg4win = true;
}
break;
@@ -259,7 +268,7 @@
}
if (!gpg4win)
set_reg_entry_mo (locale_dir);
- set_gettext_file ("winpt", locale_dir);
+ gettext_set_file ("winpt", locale_dir);
}
else if (!gpg4win)
set_reg_entry_mo ("");
Modified: trunk/Src/wptGPGUtil.cpp
===================================================================
--- trunk/Src/wptGPGUtil.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptGPGUtil.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -14,7 +14,6 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
-
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -30,8 +29,10 @@
#include "wptW32API.h"
#include "wptGPG.h"
#include "wptRegistry.h"
+#include "StringBuffer.h"
#include "openpgp.h"
+
static char*
char_alloc (size_t n)
{
@@ -278,8 +279,8 @@
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
- const char *fmt;
- char *p, *cmd;
+ StringBuffer cmd;
+ char *p;
DWORD ec;
memset (&si, 0, sizeof (si));
@@ -290,21 +291,19 @@
p = read_gpg_program ();
if (!p)
return 1; /* general error */
- fmt = "%s %s";
- cmd = char_alloc (strlen (p) + strlen (args)+strlen (fmt)+1);
- sprintf (cmd, fmt, p, args);
+ cmd = p;
+ cmd = cmd + " " + args;
free_if_alloc (p);
- if (!CreateProcess (NULL, cmd, NULL, NULL,
- FALSE, 0, NULL, NULL, &si, &pi)) {
- free_if_alloc (cmd);
+
+ if (!CreateProcess (NULL, (char*)cmd.getBuffer (), NULL, NULL,
+ FALSE, 0, NULL, NULL, &si, &pi))
return 1; /* general error */
- }
+
WaitForSingleObject (pi.hProcess, INFINITE);
GetExitCodeProcess (pi.hProcess, &ec);
CloseHandle (pi.hProcess);
CloseHandle (pi.hThread);
- free_if_alloc (cmd);
return (int)ec;
}
@@ -316,25 +315,23 @@
{
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);
struct stat st;
- const char *fmt;
char *p;
- char *cmd;
+ StringBuffer cmd;
p = read_gpg_program ();
if (!p)
return gpg_error (GPG_ERR_INV_ARG);
- fmt = "%s --armor --yes --output \"%s\" --export-secret-key %s";
- cmd = char_alloc (strlen (p) + strlen (keyid)
- + strlen (outfile) + strlen (fmt) + 2);
- sprintf (cmd, fmt, p, outfile, keyid);
- if (create_process (cmd, NULL, NULL, NULL))
+ cmd = p;
+ cmd = cmd + " --armor --yes --output \"" + outfile + "\"";
+ cmd = cmd + " --export-secret-key " + keyid;
+
+ if (create_process (cmd.getBuffer (), NULL, NULL, NULL))
err = gpg_error (GPG_ERR_MODULE_NOT_FOUND);
if (stat (outfile, &st) == -1 || st.st_size == 0)
err = gpg_error (GPG_ERR_NO_DATA);
free_if_alloc (p);
- free_if_alloc (cmd);
return err;
}
@@ -346,19 +343,16 @@
gpg_manage_ownertrust (char **data, int do_export)
{
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);
- HANDLE out = NULL, in = NULL;
- const char *fmt, *opt;
+ HANDLE out = NULL, in = NULL;
+ StringBuffer cmd;
char *p;
- char *cmd;
p = read_gpg_program ();
if (!p)
return gpg_error (GPG_ERR_INV_ARG);
- opt = do_export? "--export-ownertrust" : "--import-ownertrust";
- fmt = "%s %s";
- cmd = char_alloc (strlen (p) + strlen (opt) + strlen (fmt) + 1);
- sprintf (cmd, fmt, p, opt);
+ cmd = p;
+ cmd = cmd + (do_export? " --export-ownertrust" : " --import-ownertrust");
if (do_export)
out = create_tmpfile ("tmp_gpg_ot_out");
@@ -369,11 +363,10 @@
WriteFile (in, *data, strlen (*data), &nw, NULL);
FlushFileBuffers (in);
}
- if (create_process (cmd, in, out, NULL))
+ if (create_process (cmd.getBuffer (), in, out, NULL))
err = gpg_error (GPG_ERR_MODULE_NOT_FOUND);
free_if_alloc (p);
- free_if_alloc (cmd);
if (in)
CloseHandle (in);
@@ -392,21 +385,19 @@
{
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);
HANDLE out = NULL;
- const char *fmt;
- char *p;
- char *cmd;
+ StringBuffer cmd;
+ char *p;
p = read_gpg_program ();
if (!p)
return gpg_error (GPG_ERR_INV_ARG);
- fmt = "%s --logger-fd=1 --batch --rebuild-keydb-caches";
- cmd = char_alloc (strlen (p) + strlen (fmt) + 1);
- sprintf (cmd, fmt, p);
+ cmd = p;
+ cmd = cmd + " --logger-fd=1 --batch --rebuild-keydb-caches";
if (r_inf)
out = create_tmpfile ("tmp_gpg_rebuild_cache");
- if (create_process (cmd, NULL, out, NULL))
+ if (create_process (cmd.getBuffer (), NULL, out, NULL))
err = gpg_error (GPG_ERR_MODULE_NOT_FOUND);
if (r_inf)
@@ -414,7 +405,6 @@
if (out)
CloseHandle (out);
free_if_alloc (p);
- free_if_alloc (cmd);
return err;
}
@@ -425,22 +415,20 @@
{
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);
HANDLE out;
- const char *fmt;
- char *p, *cmd;
+ StringBuffer cmd;
+ char *p;
p = read_gpg_program ();
if (!p)
return gpg_error (GPG_ERR_INV_ARG);
- fmt = "%s --version";
- cmd = char_alloc (strlen (p) + strlen (fmt) + 1);
- sprintf (cmd, fmt, p);
+ cmd = p;
+ cmd = cmd + " --version";
out = create_tmpfile ("tmp_gpg_out");
- if (create_process (cmd, NULL, out, NULL))
+ if (create_process (cmd.getBuffer (), NULL, out, NULL))
err = gpg_error (GPG_ERR_MODULE_NOT_FOUND);
free_if_alloc (p);
- free_if_alloc (cmd);
*r_inf = map_tmpfile (out, NULL);
CloseHandle (out);
@@ -454,24 +442,23 @@
gpg_import_key_list (const char *fname, char **r_out)
{
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);
- const char *fmt;
- char *cmd, *p;
HANDLE out;
-
+ StringBuffer cmd;
+ char *p;
+
p = read_gpg_program ();
if (!p)
return gpg_error (GPG_ERR_INV_ARG);
- fmt = "%s --fixed-list-mode --with-colons \"%s\"";
- cmd = char_alloc (strlen (p) + strlen (fname) + strlen (fmt) + 2);
- sprintf (cmd, fmt, p, fname);
+ cmd = p;
+ cmd = cmd + " --fixed-list-mode --with-colons ";
+ cmd = cmd + "\"" + fname + "\"";
out = create_tmpfile ("tmp_gpg_keys");
- if (create_process (cmd, NULL, out, NULL))
+ if (create_process (cmd.getBuffer (), NULL, out, NULL))
err = gpg_error (GPG_ERR_MODULE_NOT_FOUND);
free_if_alloc (p);
- free_if_alloc (cmd);
*r_out = map_tmpfile (out, NULL);
CloseHandle (out);
@@ -490,24 +477,23 @@
const char *keyid, char **r_revcert)
{
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);
- const char *fmt, *revcmd;
- char *rcrt;
- char *cmd, *p;
HANDLE in, out;
+ StringBuffer cmd;
+ char *rcrt;
+ char *p;
p = read_gpg_program ();
if (!p)
return gpg_error (GPG_ERR_INV_ARG);
- revcmd = desig_revoke? "--desig-revoke" : "--gen-revoke";
- fmt = "%s --pgp7 --command-fd=0 --status-fd=2 %s %s";
- cmd = char_alloc (strlen (p) + strlen (revcmd) +
- strlen (keyid) + strlen (fmt) + 2);
- sprintf (cmd, fmt, p, revcmd, keyid);
+ cmd = p;
+ cmd = cmd + " --pgp7 --command-fd=0 --status-fd=2 ";
+ cmd = cmd + (desig_revoke? "--desig-revoke" : "--gen-revoke");
+ cmd = cmd + " " + keyid;
in = create_in_pipe (inp_data);
out = create_tmpfile ("tmp_gpg_revcert");
- if (create_process (cmd, in, out, NULL)) {
+ if (create_process (cmd.getBuffer (), in, out, NULL)) {
*r_revcert = NULL;
err = gpg_error (GPG_ERR_MODULE_NOT_FOUND);
}
@@ -519,7 +505,6 @@
}
free_if_alloc (p);
- free_if_alloc (cmd);
CloseHandle (in);
CloseHandle (out);
@@ -537,30 +522,29 @@
{
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);
HANDLE herr, hdat;
- const char *fmt;
- char *p, *cmd;
- DWORD n;
+ StringBuffer cmd;
+ char *p;
if (ndata)
*ndata = 0;
p = read_gpg_program ();
if (!p)
return gpg_error (GPG_ERR_INV_ARG);
- fmt = "%s --attribute-fd=%d --status-fd=2 --list-keys %s";
- n = strlen (p) + strlen (fmt) + 1;
- if (keyid)
- n += strlen (keyid) + 1;
- cmd = char_alloc (n+1);
- /* XXX: add --list-options show-unsuable-uid to display
- revoked attribute IDs */
hdat = create_tmpfile ("tmp_gpg_uat_data");
herr = create_tmpfile ("tmp_gpg_uat_status");
- sprintf (cmd, fmt, p, (int)hdat, keyid? keyid : "");
- if (create_process (cmd, NULL, NULL, herr))
+
+ /* XXX: add --list-options show-unsuable-uid to display
+ revoked attribute IDs */
+ cmd = p;
+ cmd = cmd + " --attribute-fd=" + ((int)hdat);
+ cmd = cmd + " --status-fd=2 --list-keys ";
+ if (keyid != NULL)
+ cmd = cmd + keyid;
+
+ if (create_process (cmd.getBuffer (), NULL, NULL, herr))
err = gpg_error (GPG_ERR_MODULE_NOT_FOUND);
free_if_alloc (p);
- free_if_alloc (cmd);
*r_data = (BYTE*)map_tmpfile (hdat, ndata);
*r_status_data = map_tmpfile (herr, NULL);
@@ -580,10 +564,10 @@
char **new_keyfile)
{
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);
- const char *fmt;
- char *p, *cmd;
+ StringBuffer cmd;
+ char *p;
char tmpnam[MAX_PATH], tmpdir[MAX_PATH];
- int i, n;
+ int i;
/* copy key file to temp dir. */
GetTempPath (MAX_PATH-1, tmpdir);
@@ -599,26 +583,19 @@
p = read_gpg_program ();
if (!p)
return gpg_error (GPG_ERR_INV_ARG);
-
+
/* Use the temp key file as a keyring and export the selected
keys from it. */
- fmt = "%s --yes --output %s --no-options --homedir %s --keyring %s --export ";
- n = strlen (fmt) + strlen (p)+1 + strlen (tmpdir)+1 + strlen (tmpnam) + 1;
- n += strlen (*new_keyfile)+1;
+ cmd = p;
+ cmd = cmd + " --yes --output " + "\"" + *new_keyfile + "\"";
+ cmd = cmd + " --no-options --homedir " + tmpdir + " --keyring " + tmpnam + " --export ";
for (i=0; i < (int)nkeys; i++)
- n += strlen (keys[i])+1+2;
- cmd = char_alloc (n+1);
- sprintf (cmd, fmt, p, *new_keyfile, tmpdir, tmpnam);
- for (i=0; i < (int)nkeys; i++) {
- strcat (cmd, keys[i]);
- strcat (cmd, " " );
- }
+ cmd = cmd + keys[i] + " ";
- if (create_process (cmd, NULL, NULL, NULL))
+ if (create_process (cmd.getBuffer (), NULL, NULL, NULL))
err = gpgme_error (GPG_ERR_MODULE_NOT_FOUND);
DeleteFile (tmpnam);
- free_if_alloc (cmd);
free_if_alloc (p);
return err;
}
@@ -631,25 +608,23 @@
{
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);
HANDLE out;
- const char *fmt;
- char *p, *cmd;
+ StringBuffer cmd;
+ char *p;
char *uat;
*r_valid = GPGME_VALIDITY_UNKNOWN;
p = read_gpg_program ();
if (!p)
return gpg_error (GPG_ERR_INV_ARG);
+ cmd = p;
+ cmd = cmd + " --with-colons --fixed-list-mode";
+ cmd = cmd + " --list-keys " + "\"" + keyid + "\"";
- fmt = "%s --with-colons --fixed-list-mode --list-keys \"%s\"";
- cmd = char_alloc (strlen (p) + strlen (keyid) + strlen (fmt) + 2);
- sprintf (cmd, fmt, p, keyid);
-
out = create_tmpfile ("tmp_gpg_keys");
- if (create_process (cmd, NULL, out, NULL))
+ if (create_process (cmd.getBuffer (), NULL, out, NULL))
err = gpg_error (GPG_ERR_MODULE_NOT_FOUND);
free_if_alloc (p);
- free_if_alloc (cmd);
p = map_tmpfile (out, NULL);
if ((uat = strstr (p, "uat:"))) {
@@ -774,23 +749,22 @@
gpg_find_key_subpacket (const char *key, int subpktid, char **value)
{
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);
- const char *fmt;
- const char *spk;
- char *p, *cmd;
+ StringBuffer cmd;
HANDLE out;
+ const char *spk;
+ char *p;
*value = NULL;
p = read_gpg_program ();
- fmt = "%s --with-colons --no-options --list-options show-sig-subpackets=%d --list-sigs %s";
- cmd = char_alloc (strlen (fmt) + strlen (p) + strlen (key) + 32 + 1);
- sprintf (cmd, fmt, p, subpktid, key);
+ cmd = p;
+ cmd = cmd + " --with-colons --no-options --list-options ";
+ cmd = cmd + "show-sig-subpackets=" + subpktid + " --list-sigs " + key;
out = create_tmpfile ("tmp_gpg_subpackets");
- if (create_process (cmd, NULL, out, NULL))
+ if (create_process (cmd.getBuffer (), NULL, out, NULL))
err = gpg_error (GPG_ERR_MODULE_NOT_FOUND);
free_if_alloc (p);
- free_if_alloc (cmd);
p = map_tmpfile (out, NULL);
if (p && (spk=strstr (p, "spk"))) {
Modified: trunk/Src/wptImportList.cpp
===================================================================
--- trunk/Src/wptImportList.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptImportList.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -13,12 +13,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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
@@ -38,6 +33,7 @@
#include "wptW32API.h"
#include "wptRegistry.h"
#include "wptVersion.h"
+#include "StringBuffer.h"
#include "openpgp.h"
@@ -255,39 +251,26 @@
static char*
key_description (import_key_t key)
{
- gpgme_pubkey_algo_t pkalgo;
gpgme_pubkey_algo_t subalgo = (gpgme_pubkey_algo_t)0;
- const char *type, *state;
- char *p;
- int n=0;
-
- pkalgo = key->pubkey_algo;
+ StringBuffer p;
+ const char *state;
+ char *desc;
+
if (key->subkey_algo)
subalgo = key->subkey_algo;
if (key->revoked)
- state = _("Revoked" );
+ state = _("Revoked");
else if (key->expired)
- state = _("Expired" );
+ state = _("Expired");
else
- state = "";
- if (key->secret)
- type = _("secret key");
- else
- type = _("public key");
-
- n = strlen (state) + strlen (type) + 2*8 + 8;
- p = new char[n+1];
- if (!p)
- BUG (NULL);
-
- if (!subalgo)
- _snprintf (p, n, "%s %s %s", state,
- get_key_pubalgo (pkalgo),type);
- else
- _snprintf (p, n, "%s %s/%s %s", state,
- get_key_pubalgo (pkalgo),
- get_key_pubalgo (subalgo), type);
- return p;
+ state = " ";
+ p = state;
+ p = p + " " + get_key_pubalgo (key->pubkey_algo) + " ";
+ if (subalgo != 0)
+ p = p + "/" + get_key_pubalgo (subalgo) + " ";
+ p = p + (key->secret? _("secret key") : _("public key")) ;
+ desc = p.getBufferCopy ();
+ return desc;
}
@@ -327,10 +310,8 @@
listview_add_sub_item (lv, pos, IMPL_COL_CREATION, (char *)t);
desc = key_description (key);
- if (desc) {
- listview_add_sub_item (lv, pos, IMPL_COL_KTYPE, desc);
- free_if_alloc (desc);
- }
+ listview_add_sub_item (lv, pos, IMPL_COL_KTYPE, desc);
+ free_if_alloc (desc);
return 0;
}
Modified: trunk/Src/wptKeyEdit.cpp
===================================================================
--- trunk/Src/wptKeyEdit.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptKeyEdit.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -353,6 +353,14 @@
}
+GpgKeyEdit::GpgKeyEdit (void)
+{
+ clear ();
+ key = NULL;
+ gpgme_new (&ctx); /*FIXME */
+}
+
+
/* Construct an object with the given key in @key. */
GpgKeyEdit::GpgKeyEdit (gpgme_key_t _key)
{
Modified: trunk/Src/wptKeyEditCB.cpp
===================================================================
--- trunk/Src/wptKeyEditCB.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptKeyEditCB.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -13,12 +13,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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
@@ -34,7 +29,9 @@
#include "wptContext.h"
#include "wptKeyEdit.h"
#include "wptErrors.h"
+#include "wptTypes.h"
+
/* Possible errors for the edit key operation. */
enum editkey_error_t {
EDITKEY_ERR_ALREADY_SIGNED = 1,
@@ -54,7 +51,7 @@
int uid = ctx->getUseridIndex ();
ctx->cmd_sent = 1;
if (uid != -1) {
- sprintf (buf, "uid %d", ctx->getUseridIndex ());
+ _snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ());
return buf;
}
}
@@ -81,7 +78,7 @@
int uid = ctx->getUseridIndex ();
ctx->cmd_sent = 1;
if (uid != -1) {
- sprintf (buf, "uid %d", ctx->getUseridIndex ());
+ _snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ());
return buf;
}
}
@@ -113,7 +110,7 @@
if (ctx->getUseridIndex () != -1 &&
ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
ctx->cnt++;
- sprintf (buf, "uid %d", ctx->getUseridIndex ());
+ _snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ());
return buf;
}
@@ -216,7 +213,7 @@
static char buf[64];
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
- sprintf (buf, "uid %d", ctx->getUseridIndex ());
+ _snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ());
ctx->cnt = 1;
return buf;
}
@@ -244,7 +241,7 @@
static int sig_cnt = 0;
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
- sprintf (buf, "uid %d", ctx->getUseridIndex ());
+ _snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ());
ctx->cnt = 1;
return buf;
}
@@ -278,7 +275,7 @@
static char buf[64];
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
- sprintf (buf, "key %d", ctx->getKeyIndex ());
+ _snprintf (buf, DIM (buf)-1, "key %d", ctx->getKeyIndex ());
ctx->cnt = 1;
return buf;
}
@@ -432,7 +429,7 @@
static char buf[64];
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
- sprintf (buf, "uid %d", ctx->getUseridIndex ());
+ _snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ());
ctx->cnt = 1;
return buf;
}
@@ -460,7 +457,7 @@
static char buf[64];
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
- sprintf (buf, "key %d", ctx->getKeyIndex ());
+ _snprintf (buf, DIM (buf)-1, "key %d", ctx->getKeyIndex ());
ctx->cnt = 1;
return buf;
}
@@ -495,7 +492,7 @@
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
ctx->cnt = 1;
- sprintf (buf, "uid %d", ctx->getUseridIndex ());
+ _snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ());
return buf;
}
else if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {
@@ -537,7 +534,7 @@
static char buf[64];
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt" )) {
- sprintf( buf, "uid %d", ctx->getUseridIndex ());
+ _snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ());
ctx->cnt = 1;
return buf;
}
@@ -586,7 +583,7 @@
static char buf[64];
if (ctx->cnt == 0 && !strcmp ( key, "keyedit.prompt" ) ) {
- sprintf( buf, "key %d", ctx->getKeyIndex ());
+ _snprintf (buf, DIM (buf)-1, "key %d", ctx->getKeyIndex ());
ctx->cnt = 1;
return buf;
}
Modified: trunk/Src/wptKeyEditDlgs.cpp
===================================================================
--- trunk/Src/wptKeyEditDlgs.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptKeyEditDlgs.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -41,7 +41,9 @@
#include "wptKeyManager.h"
#include "wptRegistry.h"
#include "wptKeyEdit.h"
+#include "StringBuffer.h"
+
/* All edit key commands. */
enum keyedit_commands {
CMD_ADDKEY = 0,
@@ -208,21 +210,14 @@
const char *utf8_name, const char *email,
const char *utf8_comment)
{
- char *p, *native;
- size_t n;
+ StringBuffer p;
+ char *native;
- n = strlen (utf8_name) + strlen (email) + 16;
- if (utf8_comment)
- n += strlen (utf8_comment);
- p = new char[n+1];
- if (!p)
- BUG (NULL);
- if (utf8_comment)
- sprintf (p, "%s (%s)", utf8_name, utf8_comment);
+ if (utf8_comment != NULL)
+ p = p + utf8_name + " (" + utf8_comment + ")";
else
- sprintf (p, "%s", utf8_name);
- native = utf8_to_native (p);
- free_if_alloc (p);
+ p = p + utf8_name;
+ native = utf8_to_native (p.getBuffer ());
listview_add_item (lv, "");
listview_add_sub_item (lv, 0, UID_COL_VALID, _("Ultimate" ));
Modified: trunk/Src/wptKeyManager.cpp
===================================================================
--- trunk/Src/wptKeyManager.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptKeyManager.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -13,12 +13,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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
@@ -50,6 +45,7 @@
#include "wptCrypto.h"
#include "wptUTF8.h"
#include "wptGPGME.h"
+#include "StringBuffer.h"
/* Remove all kind of invalid characters which would
@@ -99,21 +95,17 @@
km_key_get_info (winpt_key_t key, int is_sec)
{
gpgme_key_t pk;
- const char *fmt = "%s %04d%s/0x%s %s\n \"%s\"";
- char *p;
- int n;
+ StringBuffer p;
+ char *inf;
pk = key->ctx;
- n = strlen (fmt) + 8 + 2 + 16 + 12 + strlen (pk->uids->uid) + 32;
- p = new char[n+1];
- if (!p)
- BUG (NULL);
- _snprintf (p, n, fmt, is_sec? "sec" : "pub",
- pk->subkeys->length,
- get_key_pubalgo2 (pk->subkeys->pubkey_algo),
- pk->subkeys->keyid+8, get_key_created (pk->subkeys->timestamp),
- key->ext->uids->uid);
- return p;
+ p = (is_sec? "sec": "pub");
+ p = p + (int)pk->subkeys->length + get_key_pubalgo2 (pk->subkeys->pubkey_algo);
+ p = p + "/0x" + (pk->subkeys->keyid+8);
+ p = p + " " + get_key_created (pk->subkeys->timestamp) + "\n";
+ p = p + " \"" + key->ext->uids->uid + "\"";
+ inf = p.getBufferCopy ();
+ return inf;
}
@@ -497,7 +489,7 @@
return WPTERR_GENERAL;
}
- get_temp_name (tmpfile, DIM (tmpfile)-1, "winpt_http.tmp");
+ get_temp_name (tmpfile, DIM (tmpfile)-1, "tmp_winpt_http");
fp = fopen (tmpfile, "wb");
if (!fp) {
log_box (_("Key Import HTTP"), MB_ERR, "%s: %s", tmpfile,
@@ -985,13 +977,11 @@
listview_scroll (lv, oldpos, n);
}
else {
- const char *s = _("String pattern \"%s\" not found.");
- char *p = new char[strlen (s) + strlen (name) + 2];
- if (!p)
- BUG (0);
- sprintf (p, s, name);
- msg_box (dlg, p, _("Key Manager"), MB_INFO);
- free_if_alloc (p);
+ StringBuffer s;
+
+ s = _("String pattern not found:");
+ s = s + " \"" + name + "\"";
+ msg_box (dlg, s.getBuffer (), _("Key Manager"), MB_INFO);
}
free_if_alloc (name);
}
@@ -1003,18 +993,19 @@
km_gen_export_filename (const char *keyid, int is_secret)
{
winpt_key_s key;
- char *p;
+ StringBuffer p;
+ char *name;
memset (&key, 0, sizeof (key));
if (winpt_get_pubkey (keyid, &key))
return m_strdup (keyid);
- p = new char[strlen (key.ext->uids->name) + 8 + 16];
- if (!p)
- BUG (0);
- sprintf (p, "%s%s.asc", key.ext->uids->name, is_secret? "_sec" : "");
- secure_filename (p, strlen (p));
- return p;
+ p = key.ext->uids->name;
+ p = p + (is_secret? "_sec" : "") + ".asc";
+
+ name = p.getBufferCopy ();
+ secure_filename (name, strlen (name));
+ return name;
}
Modified: trunk/Src/wptKeygenDlg.cpp
===================================================================
--- trunk/Src/wptKeygenDlg.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptKeygenDlg.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -234,7 +234,7 @@
gpgme_error_t
gpg_genkey (const char *params, gpgme_progress_cb_t prog_cb, char **fpr)
{
- gpgme_error_t err = 0;
+ gpgme_error_t err;
gpgme_ctx_t ctx;
gpgme_genkey_result_t res;
Modified: trunk/Src/wptKeylist.cpp
===================================================================
--- trunk/Src/wptKeylist.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptKeylist.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -13,12 +13,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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
@@ -40,8 +35,8 @@
#include "wptContext.h"
#include "wptVersion.h"
#include "resource.h"
+#include "StringBuffer.h"
-#define key_is_useable(key) (!(key)->revoked && !(key)->expired && !(key)->disabled)
struct key_array_s {
char keyid[32];
@@ -52,18 +47,18 @@
static key_array_s*
-key_array_new (int items)
+key_array_new (DWORD items)
{
key_array_s *ka;
- int j;
+ DWORD i;
if (items == 0)
return NULL;
ka = new key_array_s[items + 1];
if (!ka)
BUG (NULL);
- for (j = 0; j < items; j++)
- ka[j].checked = 0;
+ for (i = 0; i < items; i++)
+ ka[i].checked = 0;
return ka;
}
@@ -78,12 +73,12 @@
/* Check if the keyid @keyid is in the key array @ka.
Return value: 1 if it exists, 0 otherwise. */
static int
-key_array_search (key_array_s *ka, int items, const char *keyid)
+key_array_search (key_array_s *ka, DWORD items, const char *keyid)
{
- int j;
+ DWORD i;
- for (j = 0; j < items; j++) {
- if (!strcmp (keyid, ka[j].keyid))
+ for (i = 0; i < items; i++) {
+ if (!strcmp (keyid, ka[i].keyid))
return 1;
}
return 0;
@@ -168,7 +163,7 @@
if (!strcmp (s->keyid+off, keyid) && s->timestamp > timestamp) {
self_sig = s;
timestamp = s->timestamp;
- if (first)
+ if (first) /* do not search for later self sigs. */
break;
}
}
@@ -215,19 +210,12 @@
const char*
get_key_created (long timestamp)
{
- static char timebuf[128];
- struct tm *warp;
- const char *dat;
+ static char timebuf[128];
if (timestamp < 1)
return "????" "-??" "-??";
- dat = get_locale_date (timestamp, timebuf, DIM (timebuf)-1);
- if (dat)
- return dat;
- /* Fallback if locate date conversion failed. */
- warp = localtime (×tamp);
- _snprintf (timebuf, DIM (timebuf) - 1, "%04d-%02d-%02d",
- warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday);
+ if (!get_locale_date (timestamp, timebuf, DIM (timebuf)-1))
+ return "????" "-??" "-??";
return timebuf;
}
@@ -237,17 +225,11 @@
get_key_expire_date (long timestamp)
{
static char timebuf[64];
- struct tm *warp;
- const char *dat;
if (timestamp == 0)
return _("Never");
- dat = get_locale_date (timestamp, timebuf, DIM (timebuf)-1);
- if (dat)
- return dat;
- warp = localtime (×tamp);
- _snprintf (timebuf, DIM (timebuf) -1, "%04d-%02d-%02d",
- warp->tm_year + 1900, warp->tm_mon + 1, warp->tm_mday);
+ if (!get_locale_date (timestamp, timebuf, DIM (timebuf)-1))
+ return "????" "-??" "-??";
return timebuf;
}
@@ -447,9 +429,9 @@
{
gpgme_key_t sk;
const char *state, *alg, *type;
- char *p;
+ char *desc;
+ StringBuffer p;
- /* XXX: problems with the German translation. */
state = "";
if (key->disabled)
state = _("Disabled");
@@ -457,17 +439,21 @@
state = _("Expired");
if (key->revoked)
state = _("Revoked");
- alg = "OpenPGP";
+
+ /* If the fingerprint has 32 octets, we assume MD5 and thus
+ an old, version 3, RSA key which is called 'Legacy' by other
+ OpenPGP programs. */
if (strlen (key->subkeys->fpr) == 32)
alg = "RSA Legacy";
+ else
+ alg = "OpenPGP";
type = _("public key");
if (!get_seckey (key->subkeys->keyid+8, &sk))
type = _("key pair");
- p = new char[strlen (state) + strlen (alg) + strlen (type) + 4 + 1];
- if (!p)
- BUG (0);
- sprintf (p, "%s %s %s", state, alg, type);
- return p;
+ p = state;
+ p = p + " " + alg + " " + type;
+ desc = m_strdup (p.getBuffer ());
+ return desc;
}
@@ -969,8 +955,7 @@
}
}
else if (mode & KEYLIST_ENCRYPT_MIN) {
- if( k->can_encrypt && key_is_useable (k))
- {
+ if(k->can_encrypt && key_is_useable (k)) {
rc = do_addkey (lv, ctx, key, -1, i, -1);
return rc;
}
@@ -1030,9 +1015,6 @@
n = listview_count_items (lv, 0);
ka = key_array_new (n);
- if (!ka)
- BUG (NULL);
-
keybuf = (gpgme_key_t*)calloc (n+1, sizeof (gpgme_key_t));
if (!keybuf)
BUG (NULL);
@@ -1044,19 +1026,16 @@
BUG (0);
if (!key_check_validity (key) &&
!key_array_search (ka, ka_pos, key->subkeys->keyid)) {
- char *warn = new char[512+strlen (c->uids->uid) + 1];
- if (!warn)
- BUG (0);
- sprintf (warn,
- _("It is NOT certain that the key belongs to the person\n"
- "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?"), c->uids->uid);
+ StringBuffer warn;
+
+ warn = warn + _("It is NOT certain that the key belongs to the person\n"
+ "named in the user ID. If you *really* know what you are\n"
+ "doing, you may answer the next question with yes\n"
+ "\nStill proceed?");
if (reg_prefs.always_trust)
rc = IDYES;
else
- rc = msg_box (NULL, warn, _("Recipients"), MB_ERR_ASK);
+ rc = msg_box (NULL, warn.getBuffer (), c->uids->uid, MB_ERR_ASK);
if (rc == IDYES) {
keybuf[k_pos++] = key;
force_trust++;
@@ -1064,7 +1043,6 @@
strcpy (ka[ka_pos++].keyid, key->subkeys->keyid);
count++;
}
- free_if_alloc (warn);
}
else {
keybuf[k_pos++] = key;
@@ -1139,6 +1117,7 @@
seclist_destroy (keylist_t *list)
{
keylist_t l2;
+
while (*list) {
l2 = (*list)->next;
safe_free (*list);
@@ -1165,33 +1144,27 @@
gpg_keycache_rewind (kc);
while (!gpg_keycache_next_key (kc, 1, &key)) {
- char *inf = NULL, *uid = NULL;
+ StringBuffer inf;
+ char *uid;
const char *id;
- const char *keyid;
- int algo;
- size_t size = 0;
+ if (key->disabled || !key_is_useable (key->subkeys))
+ continue;
+
if (flags & KEYLIST_FLAG_SHORT)
id = key->uids->name;
else
id = key->uids->uid;
- keyid = key->subkeys->keyid;
- algo = key->subkeys->pubkey_algo;
- if (!id || !keyid)
- continue;
- if (key->disabled || !key_is_useable (key->subkeys))
- continue;
+ if (!id || !key->subkeys->keyid)
+ continue;
uid = utf8_to_native (id);
- size = strlen (uid) + strlen (keyid) + 32;
- inf = new char[size+1];
- if (!inf)
- BUG (NULL);
- _snprintf (inf, size, "%s (%s/0x%s)", uid,
- get_key_pubalgo (key->subkeys->pubkey_algo), keyid + 8);
- combox_add_string (kb, inf);
- free_if_alloc (inf);
- free (uid);
+ inf = uid;
+ inf = inf + " (" + get_key_pubalgo (key->subkeys->pubkey_algo) + "/";
+ inf = inf + "0x" + (key->subkeys->keyid+8) + ")";
+
+ combox_add_string (kb, inf.getBuffer ());
+ safe_free (uid);
l = (struct keylist_s *)calloc (1, sizeof * l);
if (!l)
BUG (0);
Modified: trunk/Src/wptKeyserver.cpp
===================================================================
--- trunk/Src/wptKeyserver.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptKeyserver.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -38,6 +38,7 @@
#include "wptRegistry.h"
#include "wptUTF8.h"
#include "wptVersion.h"
+#include "StringBuffer.h"
/* Map net_errno to a winsock error. */
@@ -1409,8 +1410,8 @@
do_spawn_ldap_helper (const char *host, const char *keyid)
{
FILE *fp = NULL;
- char *p, *sep;
- char *ksprg;
+ StringBuffer cmd;
+ char *sep, *p, *ksprg;
char outf[256], inf[256];
size_t n;
@@ -1451,9 +1452,9 @@
host? skip_type_prefix (host): "64.94.85.200", keyid);
fclose (fp);
- p = safe_alloc (strlen (ksprg) + strlen (inf) + strlen (outf) + 32);
- sprintf (p, "%s -o %s %s", ksprg, outf, inf);
- if (spawn_application (p)) {
+ cmd = ksprg;
+ cmd = cmd + " -o " + outf + " " + inf;
+ if (spawn_application ((char*)cmd.getBuffer ())) {
fp = NULL;
goto leave;
}
@@ -1465,7 +1466,6 @@
leave:
DeleteFile (inf);
DeleteFile (outf);
- free_if_alloc (p);
free_if_alloc (ksprg);
return fp;
}
@@ -1539,7 +1539,7 @@
return WPTERR_WINSOCK_RECVKEY;
for (;;) {
- if (sock_getline (fd, buf, DIM (buf)-2, &nread))
+ if (sock_getline (fd, buf, DIM (buf)-1, &nread))
break;
strcat (buf, "\n");
if (strstr (buf, "BEGIN PGP PUBLIC KEY BLOCK")) {
Modified: trunk/Src/wptKeyserverDlg.cpp
===================================================================
--- trunk/Src/wptKeyserverDlg.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptKeyserverDlg.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -143,7 +143,7 @@
s = _("Key(s) successfully received but nothing was changed.");
else
s = _("Key(s) sucessfully received and imported.");
- // nice to have the amount of new signatures...
+ // nice to have the amount of new signatures...
gpgme_data_write (msg, s, strlen (s));
gpgme_data_write (msg, "\n\n", 2);
@@ -268,17 +268,19 @@
fetch_key_from_keyserver (HWND dlg, gpgme_signature_t sig)
{
const char *keyid;
+ char timebuf[128];
int id;
if (!sig->fpr)
return FALSE;
+ if (!get_locale_timedate (sig->timestamp, timebuf, DIM (timebuf)-1))
+ _snprintf (timebuf, DIM (timebuf)-1, "'unknown time'");
keyid = get_keyid_from_fpr (sig->fpr);
id = log_box (_("Verify"), MB_INFO|MB_YESNO,
_("Signature made %s using %s key ID 0x%s\n"
"Cannot check signature: public key not found\n\n"
"Do you want to try to retrieve the key from the keyserver?"),
- strtimestamp (sig->timestamp),
- get_key_pubalgo (sig->pubkey_algo), keyid);
+ timebuf, get_key_pubalgo (sig->pubkey_algo), keyid);
if (id == IDNO) {
msg_box (dlg, get_gpg_sigstat (GPGME_SIGSUM_KEY_MISSING),
_("Verify"), MB_WARN);
Modified: trunk/Src/wptKeysignDlg.cpp
===================================================================
--- trunk/Src/wptKeysignDlg.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptKeysignDlg.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -12,10 +12,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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>
@@ -40,6 +36,7 @@
#include "wptRegistry.h"
#include "wptKeylist.h"
#include "wptKeyEdit.h"
+#include "StringBuffer.h"
void key_unload_photo (HWND dlg);
@@ -93,15 +90,16 @@
{
gpg_keycache_t sec;
gpgme_key_t pk, defkey;
- const char *s, *inf;
- char *uid, *p;
+ const char *s;
+ char *uid;
int i = 0, n = 0, curr_sel = 0;
- int len = 0;
sec = keycache_get_ctx (0);
gpg_keycache_get_default_key (sec, &defkey);
gpg_keycache_rewind (sec);
while (!gpg_keycache_next_key (sec, 1, &pk)) {
+ StringBuffer p;
+
if (!pk)
continue;
s = pk->subkeys->keyid;
@@ -118,18 +116,14 @@
continue;
if (defkey && !strcmp (defkey->subkeys->keyid, pk->subkeys->keyid))
curr_sel = i;
+
uid = utf8_to_native (s);
- inf = get_keyinfo (pk);
- len = strlen (uid) + strlen (inf) + 8;
- p = new char[len+1];
- if (!p)
- BUG (NULL);
- _snprintf (p, len, "%s (%s)", uid, inf);
+ p = uid;
+ p = p + " (" + get_keyinfo (pk) + ")";
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST,
- CB_ADDSTRING, i, (LPARAM)(char *)p);
+ CB_ADDSTRING, i, (LPARAM)(char *)p.getBuffer ());
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST,
CB_SETITEMDATA, i++, (LPARAM)(DWORD)pk);
- free_if_alloc (p);
safe_free (uid);
n++;
}
@@ -214,7 +208,7 @@
sig_class_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
{
HWND parent;
- int sig_class;
+ int sig_class = 0;
switch (msg) {
case WM_INITDIALOG:
@@ -294,12 +288,11 @@
static void
display_keyinfo (HWND dlg, winpt_key_t key)
{
- gpgme_data_t kinf;
+ StringBuffer kinf;
struct native_uid_s *u;
- char tmp[256], *p;
- size_t len;
-
- gpgme_data_new (&kinf);
+ char tmp[256];
+ int len=0;
+
_snprintf (tmp, DIM (tmp) -1,
_("pub %d/0x%s created: %s expires: %s\n\n"
"Primary key fingerprint: %s\n\n"),
@@ -307,40 +300,103 @@
key->ctx->subkeys->keyid+8,
get_key_created (key->ctx->subkeys->timestamp),
get_expire_date (key->ctx),
- get_printable_fpr (key->ctx->subkeys->fpr));
- gpgme_data_write (kinf, tmp, strlen (tmp));
+ get_printable_fpr (key->ctx->subkeys->fpr));
+ kinf = tmp;
for (len=0, u = key->ext->uids; u; u = u->next) {
if (u->revoked)
continue;
if (len++ > 2)
break;
- gpgme_data_write (kinf, "\t\"", 2);
- gpgme_data_write (kinf, u->uid, strlen (u->uid));
- gpgme_data_write (kinf, "\"\n", 2);
+ kinf = kinf + "\t\"" + u->uid + "\"\n";
}
- p = (char*)_("\n\nAre you really sure that you want to sign this key with YOUR key?\n");
- gpgme_data_write (kinf, p, strlen (p));
- gpgme_data_write (kinf, "\0", 1);
- p = gpgme_data_release_and_get_mem (kinf, &len);
- SetDlgItemText (dlg, IDC_KEYSIGN_INFOS, p);
- gpgme_free (p);
+ kinf = kinf + _("\n\nAre you really sure that you want to sign this key with YOUR key?\n");
+ SetDlgItemText (dlg, IDC_KEYSIGN_INFOS, kinf.getBuffer ());
}
-/* Dialog box procedure to sign a key. */
-BOOL CALLBACK
-keysign_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
+/* Perform the actual procedure to sign the key. */
+static BOOL
+on_click_ok (HWND dlg, winpt_key_t key)
{
- static winpt_key_t key;
- GpgKeyEdit *ke;
- gpgme_error_t err;
gpgme_key_t k;
+ gpgme_error_t err;
SYSTEMTIME st;
+ GpgKeyEdit ke;
+ int sig_class = 0;
char keymsg[64], *pwd;
- const char *keyid, *s;
int type, expires=0, idx;
- int sig_class = 0;
+
+ if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_ASKLEVEL))
+ sig_class = dialog_box_param (glob_hinst,
+ (LPCSTR)IDD_WINPT_SIGCLASS, dlg,
+ sig_class_dlg_proc, (LPARAM)dlg,
+ _("Choose Signature Class"),
+ IDS_WINPT_SIGCLASS);
+ type = IsDlgButtonChecked (dlg, IDC_KEYSIGN_LOCAL);
+ if (type)
+ type = GPG_EDITKEY_LSIGN;
+ else
+ type = GPG_EDITKEY_SIGN;
+
+
+ if (reg_prefs.expert && IsDlgButtonChecked (dlg, IDC_KEYSIGN_NREV)) {
+ type = GPG_EDITKEY_NRSIGN;
+ if (type == GPG_EDITKEY_LSIGN)
+ type = GPG_EDITKEY_NRLSIGN;
+ }
+
+ if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG)) {
+ DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), &st);
+ if (date_is_today (&st)) {
+ msg_box (dlg, _("You cannot select today as the expiration date."),
+ _("Key Signing"), MB_INFO);
+ return TRUE;
+ }
+ else
+ expires = 1;
+ _snprintf (keymsg, DIM (keymsg)-1, "%04d-%02d-%02d",
+ st.wYear, st.wMonth, st.wDay);
+ }
+
+ /* XXX: check for --ask-cert-level and --ask-cert-expire in the gpg.conf
+ if an advanced button is checked and offer to add it to the config
+ file. */
+ GetDlgItemText_utf8 (dlg, IDC_KEYSIGN_PASSPHRASE, &pwd);
+ assert (key->ctx->subkeys->keyid != NULL); /* should be always true. */
+ ke.setKeyID (key->ctx->subkeys->keyid);
+ ke.setPassphrase (pwd);
+ idx = SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0);
+ k = (gpgme_key_t)SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST,
+ CB_GETITEMDATA, (WPARAM)idx, 0);
+ if (k != NULL)
+ ke.setLocalUser (k);
+
+ err = ke.signKey (type, sig_class, expires? keymsg : "0");
+ sfree_if_alloc (pwd);
+ if (err) {
+ msg_box (dlg, gpgme_strerror (err), _("Key Signing"), MB_ERR);
+ return TRUE;
+ }
+ else if (ke.getResult () != 0)
+ msg_box (dlg, _("This key is already signed by your key"),
+ _("Key Signing"), MB_INFO);
+ else {
+ status_box (dlg, _("Key successfully signed."), _("Key Signing"));
+ key->update = 1;
+ }
+ EndDialog (dlg, TRUE);
+ return TRUE;
+}
+
+
+/* Dialog box procedure to sign a key. */
+BOOL CALLBACK
+keysign_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+ static winpt_key_t key;
+ const char *s;
+
switch (msg) {
case WM_INITDIALOG:
key = (winpt_key_t) lparam;
@@ -402,70 +458,7 @@
switch (LOWORD (wparam)) {
case IDOK:
- if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_ASKLEVEL))
- sig_class = dialog_box_param (glob_hinst,
- (LPCSTR)IDD_WINPT_SIGCLASS, dlg,
- sig_class_dlg_proc, (LPARAM)dlg,
- _("Choose Signature Class"),
- IDS_WINPT_SIGCLASS);
- type = IsDlgButtonChecked (dlg, IDC_KEYSIGN_LOCAL);
- if (type)
- type = GPG_EDITKEY_LSIGN;
- else
- type = GPG_EDITKEY_SIGN;
-
- if (reg_prefs.expert && IsDlgButtonChecked (dlg, IDC_KEYSIGN_NREV)) {
- type = GPG_EDITKEY_NRSIGN;
- if (type == GPG_EDITKEY_LSIGN)
- type = GPG_EDITKEY_NRLSIGN;
- }
- if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG)) {
- DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), &st);
- if (date_is_today (&st)) {
- msg_box (dlg, _("You cannot select today as the expiration date."),
- _("Key Signing"), MB_INFO);
- return TRUE;
- }
- else
- expires = 1;
- _snprintf (keymsg, DIM (keymsg)-1, "%04d-%02d-%02d",
- st.wYear, st.wMonth, st.wDay);
- }
-
- /* XXX: check for --ask-cert-level and --ask-cert-expire in the gpg.conf
- if an advanced button is checked and offer to add it to the config
- file. */
-
- GetDlgItemText_utf8 (dlg, IDC_KEYSIGN_PASSPHRASE, &pwd);
- keyid = key->ctx->subkeys->keyid;
- assert (keyid != NULL); /* should be always true. */
- ke = new GpgKeyEdit (keyid);
- if (!ke)
- BUG (NULL);
- ke->setPassphrase (pwd);
- idx = SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0);
- k = (gpgme_key_t)SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST,
- CB_GETITEMDATA, (WPARAM)idx, 0);
- if (k)
- ke->setLocalUser (k);
-
- err = ke->signKey (type, sig_class, expires? keymsg : "0");
- sfree_if_alloc (pwd);
- if (err) {
- msg_box (dlg, gpgme_strerror (err), _("Key Signing"), MB_ERR);
- delete ke;
- return TRUE;
- }
- else if (ke->getResult () != 0)
- msg_box (dlg, _("This key is already signed by your key"),
- _("Key Signing"), MB_INFO);
- else {
- status_box (dlg, _("Key successfully signed."), _("Key Signing"));
- key->update = 1;
- }
- delete ke;
- EndDialog (dlg, TRUE);
- return TRUE;
+ return on_click_ok (dlg, key);
case IDCANCEL:
EndDialog (dlg, FALSE);
Modified: trunk/Src/wptMainProc.cpp
===================================================================
--- trunk/Src/wptMainProc.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptMainProc.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -363,6 +363,7 @@
reg_prefs.backup.include_secr);
free_reg_prefs ();
free_gnupg_table ();
+ gettext_free_current_domain ();
hotkeys_unregister (hwnd);
PTD_delete ();
agent_flush_cache ();
Modified: trunk/Src/wptNLS.cpp
===================================================================
--- trunk/Src/wptNLS.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptNLS.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -2,8 +2,8 @@
* Copyright (C) 2001, 2002, 2003, 2006 Timo Schulz
* Copyright (C) 1995-1999 Free Software Foundation, Inc.
*
- * This code based on the simple-gettext.c code from the GnuPG
- * by Ulrich Drepper.
+ * This code is a stripped down version of simple-gettext.c
+ * written by by Ulrich Drepper from the GPG project.
*
* WinPT is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -14,12 +14,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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
@@ -33,6 +28,7 @@
#include <windows.h>
#include "wptNLS.h"
+#include "wptTypes.h"
/* The magic number of the GNU message catalog format. */
@@ -83,10 +79,12 @@
{"de", "German", LANG_GERMAN},
{"fr", "French", LANG_FRENCH},
{"jp", "Japanese", LANG_JAPANESE},
+ // XXX: add new languages.
{"pt_BR", "Portuguese (Brazil)", SUBLANG_PORTUGUESE_BRAZILIAN},
{NULL, 0}
};
+
/* The current domain. */
static struct loaded_domain *the_domain;
@@ -101,7 +99,6 @@
/* 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)
{
@@ -121,6 +118,7 @@
return hval;
}
+
/* Missing W32 functions. */
static char*
w32_stpcpy (char *a,const char *b)
@@ -132,9 +130,8 @@
}
-
-static struct loaded_domain *
-load_domain( const char *filename )
+static struct loaded_domain*
+load_domain (const char *filename)
{
FILE *fp;
size_t size;
@@ -144,9 +141,9 @@
size_t to_read;
char *read_ptr;
- fp = fopen( filename, "rb" );
- if( !fp )
- return NULL; /* can't open the file */
+ fp = fopen (filename, "rb");
+ if (!fp)
+ return NULL;
/* we must know about the size of the file */
if( fstat( fileno(fp ), &st )
|| (size = (size_t)st.st_size) != (size_t)st.st_size
@@ -155,11 +152,9 @@
return NULL;
}
- data = (struct mo_file_header *) malloc( size );
- if( !data ) {
- fclose( fp );
- return NULL; /* out of memory */
- }
+ data = (struct mo_file_header *) malloc (size);
+ if (!data)
+ BUG (0);
to_read = size;
read_ptr = (char *) data;
@@ -185,10 +180,8 @@
}
domain = (struct loaded_domain *)calloc( 1, sizeof *domain );
- if( !domain ) {
- free( data );
- return NULL;
- }
+ if (!domain)
+ BUG (0);
domain->data = (char *) data;
domain->must_swap = data->magic != MAGIC;
@@ -213,54 +206,57 @@
/* allocate an array to keep track of code page mappings */
domain->mapped = (char *)calloc( 1, domain->nstrings );
- if( !domain->mapped ) {
- free( data );
- free( domain );
- return NULL;
- }
+ if (!domain->mapped)
+ BUG (0);
return domain;
-} /* load_domain */
+}
+/* Deallocate static resources. */
+void
+gettext_free_current_domain (void)
+{
+ if (!the_domain)
+ return;
+ free (the_domain->data);
+ free (the_domain->mapped);
+ free (the_domain);
+ the_domain = NULL;
+}
+
+
/* Set the file used for translations. Pass a NULL to disable translation.
A new filename may be set at anytime. */
int
-set_gettext_file( const char *filename, const char *nls_dir )
+gettext_set_file (const char *filename, const char *nls_dir)
{
struct loaded_domain *domain = NULL;
- if( filename && *filename ) {
- if( filename[0] == '/'
- || ( isalpha(filename[0])
- && filename[1] == ':'
- && (filename[2] == '/' || filename[2] == '\\') )
- ) {
- /* absolute path - use it as is */
- domain = load_domain( filename );
- }
+ if (filename && *filename) {
+ if (filename[1] == ':' && filename[2] == '\\')
+ domain = load_domain (filename); /* absolute path - use it as is */
else { /* relative path - append ".mo" and get dir from the environment */
- char *buf = NULL;
- char *dir;
+ char *buf, *dir;
- dir = strdup( nls_dir );
- if( dir && (buf= (char *)malloc(strlen(dir)+strlen(filename)+1+3+1)) ) {
- strcpy(w32_stpcpy(w32_stpcpy(w32_stpcpy( buf, dir),"/"), filename),".mo");
- domain = load_domain( buf );
- free(buf);
- }
- free(dir);
+ dir = strdup (nls_dir);
+ if (!dir)
+ BUG (0);
+ buf= (char *)malloc (strlen (dir) + strlen (filename)+1+3+1);
+ if (!buf)
+ BUG (0);
+
+ strcpy (w32_stpcpy (w32_stpcpy (
+ w32_stpcpy (buf, dir),"\\"), filename),".mo");
+ domain = load_domain(buf);
+ free (buf);
+ free (dir);
}
- if( !domain )
+ if (!domain)
return -1;
}
- if( the_domain ) {
- free( the_domain->data );
- free( the_domain->mapped );
- free( the_domain );
- the_domain = NULL;
- }
+ gettext_free_current_domain ();
the_domain = domain;
return 0;
}
@@ -352,7 +348,7 @@
/* Map the user specific language ID to a gettext conform language string.
Example: LANG_GERMAN -> "de" */
const char*
-get_gettext_langid (void)
+gettext_get_langid (void)
{
LANGID lang;
int i;
Modified: trunk/Src/wptPassphraseCB.cpp
===================================================================
--- trunk/Src/wptPassphraseCB.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptPassphraseCB.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -13,12 +13,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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
@@ -40,6 +35,7 @@
#include "wptAgent.h"
#include "wptRegistry.h"
#include "wptUTF8.h"
+#include "StringBuffer.h"
/* Return the control ID dependent on the mode (sign or decrypt). */
@@ -75,8 +71,6 @@
gpgme_recipient_t recip=NULL, r;
winpt_key_s key;
void *item;
- const char *id;
- char *info;
int n;
switch (msg) {
@@ -116,36 +110,26 @@
recip = res->recipients;
}
if (recip != NULL && c->gpg_cmd == GPG_CMD_DECRYPT) {
+ StringBuffer inf;
+
for (r = recip; r; r = r->next) {
memset (&key, 0, sizeof (key));
if (!winpt_get_pubkey (r->keyid, &key)) {
gpgme_user_id_t u = key.ctx->uids;
-
- id = u->name;
- if (!id)
- id = _("Invalid User ID");
- n = 32+strlen (id)+1+4+strlen (r->keyid)+1;
- if (u->email)
- n += strlen (u->email)+1;
- info = new char [n+1];
- if (!info)
- BUG (NULL);
- if (!u->email || strlen (u->email) < 1)
- sprintf (info, "%s (%s, 0x%s)", id,
- get_key_pubalgo (r->pubkey_algo), r->keyid+8);
- else
- sprintf (info, "%s <%s> (%s, 0x%s)", id, u->email,
- get_key_pubalgo (r->pubkey_algo), r->keyid+8);
+
+ inf = (u->name? u->name : _("Invalid User ID"));
+ if (u->email != NULL && strlen (u->email) > 1)
+ inf = inf + " <" + u->email + ">";
+ inf = inf + " (" + get_key_pubalgo (r->pubkey_algo);
+ inf = inf + ", 0x" + (r->keyid+8) + ")";
}
else {
- info = new char [32 + strlen (r->keyid)+1 + 4];
- if (!info)
- BUG (NULL);
- sprintf (info, _("Unknown key ID (%s, 0x%s)"),
- get_key_pubalgo (r->pubkey_algo), r->keyid+8);
+ inf = _("Unknown key ID");
+ inf = inf + " (" + get_key_pubalgo (r->pubkey_algo);
+ inf = inf + ", 0x" + (r->keyid+8) + ")";
}
- ListBox_AddString_utf8 (GetDlgItem (dlg, IDC_DECRYPT_LIST), info);
- free_if_alloc (info);
+ ListBox_AddString_utf8 (GetDlgItem (dlg, IDC_DECRYPT_LIST),
+ inf.getBuffer ());
winpt_release_pubkey (&key);
}
}
@@ -158,15 +142,12 @@
if (c->gpg_cmd == GPG_CMD_DECRYPT) {
SetFocus (GetDlgItem (dlg, IDC_DECRYPT_PWD));
if (res && !res->recipients) {
- const char *s = _("Symmetric encryption.\n"
- "%s encrypted data.");
- const char *alg = get_symkey_algo (c->sym.sym_algo);
- info = new char[strlen (s) + strlen (alg) + 2];
- if (!info)
- BUG (NULL);
- sprintf (info, s, alg);
- SetDlgItemText (dlg, IDC_DECRYPT_MSG, info);
- free_if_alloc (info);
+ StringBuffer sinf;
+
+ sinf = _("Symmetric encryption.");
+ sinf = sinf + "\n" + get_symkey_algo (c->sym.sym_algo);
+ sinf = sinf + " " + _("encrypted data.");
+ SetDlgItemText (dlg, IDC_DECRYPT_MSG, sinf.getBuffer ());
}
else
SetDlgItemText (dlg, IDC_DECRYPT_MSG, c->info);
@@ -391,7 +372,7 @@
const char *s=passphrase_info;
while (s && *s && *s != 'D')
s++;
- _snprintf (c->info, sizeof c->info-1,
+ _snprintf (c->info, sizeof (c->info)-1,
_("Please enter the PIN to unlock your secret card key\n"
"Card: %s"), extract_serial_no (s));
c->is_card = 1;
Modified: trunk/Src/wptPassphraseDlg.cpp
===================================================================
--- trunk/Src/wptPassphraseDlg.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptPassphraseDlg.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -12,10 +12,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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>
@@ -33,6 +29,7 @@
#include "wptUTF8.h"
#include "wptVersion.h"
#include "wptTypes.h"
+#include "StringBuffer.h"
struct passphrase_s {
@@ -55,22 +52,16 @@
static void
set_passphrase_hint (HWND dlg, gpgme_key_t key)
{
- const char *inf;
- char *uid, *p;
- size_t len;
+ StringBuffer p;
+ char *uid;
uid = utf8_to_native (key->uids->name);
- inf = get_keyinfo (key);
- len = strlen (uid) + strlen (inf) + 8;
- p = new char[len+1];
- if (!p)
- BUG (NULL);
- _snprintf (p, len, "%s (%s)", uid, inf);
+ p = p + uid + " (" + get_keyinfo (key) + ")";
+
SendDlgItemMessage (dlg, IDC_PASSWD_KEYINF,
- CB_ADDSTRING, 0, (LPARAM)(char *)p);
+ CB_ADDSTRING, 0, (LPARAM)(char *)p.getBuffer ());
SendDlgItemMessage (dlg, IDC_PASSWD_KEYINF, CB_SETCURSEL, 0, 0);
- EnableWindow (GetDlgItem (dlg, IDC_PASSWD_KEYINF), FALSE);
- free_if_alloc (p);
+ EnableWindow (GetDlgItem (dlg, IDC_PASSWD_KEYINF), FALSE);
free_if_alloc (uid);
}
Modified: trunk/Src/wptRegistry.cpp
===================================================================
--- trunk/Src/wptRegistry.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptRegistry.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -475,7 +475,7 @@
if (p)
return p;
- lang = get_gettext_langid ();
+ lang = gettext_get_langid ();
if (!lang)
return NULL;
fmt = "share\\locale\\%s\\LC_MESSAGES";
Modified: trunk/Src/wptSymEnc.cpp
===================================================================
--- trunk/Src/wptSymEnc.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptSymEnc.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -12,12 +12,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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
@@ -47,7 +42,6 @@
if (!pass)
return gpg_error (GPG_ERR_INV_ARG);
- /* XXX: check for passphrase.enter. */
if (!WriteFile (hd, pass, strlen (pass), &n, NULL))
log_debug ("sym_passphrase_cb: WriteFile() failed ec=%d\n", w32_errno);
if (!WriteFile (hd, "\n", 1, &n, NULL))
Modified: trunk/Src/wptUTF8.cpp
===================================================================
--- trunk/Src/wptUTF8.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptUTF8.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -12,12 +12,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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
Modified: trunk/Src/wptUtil.cpp
===================================================================
--- trunk/Src/wptUtil.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptUtil.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -12,12 +12,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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
@@ -30,6 +25,7 @@
#include "wptTypes.h"
+
/* code taken from glibc-2.2.1/sysdeps/generic/strsep.c */
char*
strsep (char **stringp, const char *delim)
@@ -79,12 +75,12 @@
size_t n;
size_t buflen = strlen (buf);
- for( t=buf, n=buflen, s=sub ; n ; t++, n-- ) {
- if( toupper(*t) == toupper(*s) ) {
+ for (t=buf, n=buflen, s=sub ; n ; t++, n--) {
+ if (toupper (*t) == toupper (*s)) {
for( buf=t++, buflen = n--, s++;
n && toupper(*t) == toupper(*s); t++, s++, n-- )
;
- if( !*s )
+ if (!*s)
return buf;
t = buf; n = buflen; s = sub ;
}
@@ -103,10 +99,8 @@
/* If we are not in path mode (@is_path = 1) we also consider
path separators as illegal chars. */
- if (!is_path) {
- if (strchr (fname, ':') || strchr (fname, '\\'))
- return -1;
- }
+ if (!is_path && (strchr (fname, ':') || strchr (fname, '\\')))
+ return -1;
for (i=0; i < strlen (fname); i++) {
if (strchr (not_allowed, fname[i]))
Modified: trunk/Src/wptVerifyList.cpp
===================================================================
--- trunk/Src/wptVerifyList.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptVerifyList.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -13,10 +13,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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
@@ -70,32 +66,6 @@
}
-/* String representaton of the time in @timestamp.
- Format YEAR-MON-DAY HOUR:MIN:SEC.
- Return value: time as formatted string. */
-const char*
-strtimestamp (long timestamp)
-{
- static char timebuf[64];
- struct tm *warp;
- const char *dat;
-
- dat = get_locale_date (timestamp, timebuf, DIM (timebuf)-1);
- warp = localtime (×tamp);
- if (!dat)
- _snprintf (timebuf, DIM (timebuf) - 1,
- "%04d-%02d-%02d %02d:%02d:%02d",
- warp->tm_year+1900, warp->tm_mon+1, warp->tm_mday,
- warp->tm_hour, warp->tm_min, warp->tm_sec);
- else
- _snprintf (timebuf, DIM (timebuf)-1,
- "%s %02d:%02d:%02d", dat,
- warp->tm_hour, warp->tm_min, warp->tm_sec);
-
- return timebuf;
-}
-
-
/* Return human printable PKA status.
If no pka information is available, return NULL. */
char*
@@ -220,7 +190,7 @@
listview_ctrl_t lv;
struct winpt_key_s key;
const char *attr;
- char keyid[32+1];
+ char keyid[32+1], timebuf[128];
u32 key_attr;
int is_bad;
@@ -240,7 +210,9 @@
if (attr)
listview_add_sub_item (lv, 0, VER_COL_STAT, (char *)attr);
- attr = strtimestamp (sig->timestamp);
+ attr = get_locale_timedate (sig->timestamp, timebuf, DIM (timebuf)-1);
+ if (!attr)
+ attr = _("Unknown");
listview_add_sub_item (lv, 0, VER_COL_SIGNED, (char *)attr);
attr = _("Unknown");
@@ -272,7 +244,7 @@
struct listview_ctrl_s *lv;
struct winpt_key_s key;
const char *attr;
- char t[64], *name;
+ char t[64], timebuf[128], *name;
int is_bad;
lv = vlv->lv;
@@ -299,10 +271,12 @@
if (attr)
listview_add_sub_item (lv, 0, VER_COL_STAT, attr);
- if (sig->timestamp > 0)
- attr = strtimestamp (sig->timestamp);
- else
- attr = "No time";
+ if (sig->timestamp > 0) {
+ attr = get_locale_timedate (sig->timestamp, timebuf, DIM (timebuf)-1);
+ if (!attr)
+ attr = _("Unknown");
+ }
+ attr = _("Unknown");
listview_add_sub_item (lv, 0, VER_COL_SIGNED, attr);
if (key.ctx != NULL)
Modified: trunk/Src/wptW32API.cpp
===================================================================
--- trunk/Src/wptW32API.cpp 2006-12-21 08:25:20 UTC (rev 277)
+++ trunk/Src/wptW32API.cpp 2007-01-15 22:02:04 UTC (rev 278)
@@ -12,12 +12,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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
@@ -539,26 +534,65 @@
/* Return date in a format which complies with the
- system locale settings. */
+ locale user settings. */
const char*
get_locale_date (long tm_t, char *buf, DWORD buflen)
{
SYSTEMTIME st;
struct tm *ptm;
- ptm = localtime (&tm_t);
- st.wYear = (WORD)ptm->tm_year;
- st.wMonth = (WORD)ptm->tm_mon;
+ ptm = localtime (&tm_t);
+ memset (&st, 0, sizeof (st));
+ st.wYear = (WORD)ptm->tm_year+1900;
+ st.wMonth = (WORD)ptm->tm_mon+1;
st.wDay = (WORD)ptm->tm_mday;
- st.wYear += 1900;
- st.wMonth += 1;
if (!GetDateFormat (LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st,
NULL, buf, buflen))
return NULL;
return buf;
}
+/* Return the time in a format which complies with the locale user
+ settings. */
+const char*
+get_locale_time (long tm_t, char *buf, DWORD buflen)
+{
+ SYSTEMTIME st;
+ struct tm *ptm;
+ ptm = localtime (&tm_t);
+ memset (&st, 0, sizeof (st));
+ st.wMinute = (WORD)ptm->tm_min;
+ st.wHour = (WORD)ptm->tm_hour;
+ st.wSecond = (WORD)ptm->tm_sec;
+
+ if (!GetTimeFormat (LOCALE_USER_DEFAULT, TIME_FORCE24HOURFORMAT, &st,
+ NULL, buf, buflen))
+ return NULL;
+ return buf;
+}
+
+
+/* Return a combination of date+time which complies to the
+ local user settings. */
+const char*
+get_locale_timedate (long tm_t, char *buf, DWORD buflen)
+{
+ DWORD nleft = buflen;
+
+ if (!get_locale_date (tm_t, buf, buflen))
+ return NULL;
+ nleft -= strlen (buf)+1;
+ if (nleft < 1)
+ return NULL;
+ strcat (buf, " ");
+ nleft--;
+ if (!get_locale_time (tm_t, buf+strlen (buf), nleft))
+ return NULL;
+ return buf;
+}
+
+
/* Generate a temporary file name by using the users
temp path and optionally a name @name provided by the caller.
Return value: 0 on success. */
@@ -606,7 +640,6 @@
void
ComboBox_AddString_utf8 (HWND cb, const char *txt)
{
-
char *utf8_txt;
utf8_txt = utf8_to_native (txt);
More information about the Winpt-commits
mailing list