[svn] GPGol - r150 - trunk/src
svn author wk
cvs at cvs.gnupg.org
Tue Apr 25 16:51:55 CEST 2006
Author: wk
Date: 2006-04-25 16:51:54 +0200 (Tue, 25 Apr 2006)
New Revision: 150
Added:
trunk/src/xmalloc.h
Modified:
trunk/src/ChangeLog
trunk/src/Makefile.am
trunk/src/common.c
trunk/src/gpgmsg.cpp
trunk/src/passphrase-dialog.c
trunk/src/pgpmime.c
trunk/src/recipient-dialog.c
trunk/src/util.h
trunk/src/verify-dialog.c
trunk/src/w32-gettext.c
trunk/src/w32-gettext.h
Log:
Umlaut bug fixes
Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog 2006-04-24 15:19:59 UTC (rev 149)
+++ trunk/src/ChangeLog 2006-04-25 14:51:54 UTC (rev 150)
@@ -1,3 +1,19 @@
+2006-04-25 Werner Koch <wk at g10code.com>
+
+ * xmalloc.h: New. Moved prototypes from util.h
+ * w32-gettext.h: Include it.
+ * common.c (utf8_to_wincp): Removed and replaced all callers by
+ utf8_to_native.
+ * common.c (wchar_to_utf8, utf8_to_wchar): Moved to ..
+ * w32-gettext.c: .. here.
+ (utf8_to_native): Make sure that we always return
+ a string and never NULL.
+ (native_to_utf8): New.
+ (native_to_wchar): New.
+ * gpgmsg.cpp (decrypt): Use native_to_utf8 for i18n strings
+ expected to be utf-8.
+ * pgpmime.c (pgpmime_decrypt, pgpmime_verify): Ditto.
+
2006-04-24 Werner Koch <wk at g10code.com>
* gpgmsg.cpp (decrypt): New arg INFO_ONLY.
Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am 2006-04-24 15:19:59 UTC (rev 149)
+++ trunk/src/Makefile.am 2006-04-25 14:51:54 UTC (rev 150)
@@ -35,7 +35,7 @@
msgcache.c msgcache.h \
engine-gpgme.c engine.h \
rfc822parse.c rfc822parse.h \
- common.c util.h intern.h \
+ common.c util.h intern.h xmalloc.h \
passcache.c passcache.h \
config-dialog.c \
passphrase-dialog.c \
Modified: trunk/src/common.c
===================================================================
--- trunk/src/common.c 2006-04-24 15:19:59 UTC (rev 149)
+++ trunk/src/common.c 2006-04-25 14:51:54 UTC (rev 150)
@@ -17,6 +17,8 @@
* along with GPGol; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+
+#include <config.h>
#include <windows.h>
#include <time.h>
@@ -187,34 +189,7 @@
}
-/* Return a malloced string encoded in UTF-8 from the wide char input
- string STRING. Caller must xfree this value. On failure returns
- NULL; caller may use GetLastError to get the actual error number.
- The result of calling this function with STRING set to NULL is not
- defined. */
-char *
-wchar_to_utf8 (const wchar_t *string)
-{
- int n;
- char *result;
- /* Note, that CP_UTF8 is not defined in Windows versions earlier
- than NT.*/
- n = WideCharToMultiByte (CP_UTF8, 0, string, -1, NULL, 0, NULL, NULL);
- if (n < 0)
- return NULL;
-
- result = xmalloc (n+1);
- n = WideCharToMultiByte (CP_UTF8, 0, string, -1, result, n, NULL, NULL);
- if (n < 0)
- {
- xfree (result);
- return NULL;
- }
- return result;
-}
-
-
/* Same as above, but only convert the first LEN wchars. */
char *
wchar_to_utf8_2 (const wchar_t *string, size_t len)
@@ -238,32 +213,7 @@
return result;
}
-/* Return a malloced wide char string from an UTF-8 encoded input
- string STRING. Caller must xfree this value. On failure returns
- NULL; caller may use GetLastError to get the actual error number.
- The result of calling this function with STRING set to NULL is not
- defined. */
-wchar_t *
-utf8_to_wchar (const char *string)
-{
- int n;
- wchar_t *result;
- n = MultiByteToWideChar (CP_UTF8, 0, string, -1, NULL, 0);
- if (n < 0)
- return NULL;
-
- result = xmalloc ((n+1) * sizeof *result);
- n = MultiByteToWideChar (CP_UTF8, 0, string, -1, result, n);
- if (n < 0)
- {
- xfree (result);
- return NULL;
- }
- return result;
-}
-
-
/* Same as above but convert only the first LEN characters. STRING
must be at least LEN characters long. */
wchar_t *
@@ -288,17 +238,6 @@
}
-char *utf8_to_native (const char *string);
-
-/* Convert the UTF8 encoding string STRING into the current
- Windows charset and return it. */
-char *
-utf8_to_wincp (const char *string)
-{
- return utf8_to_native (string);
-}
-
-
/* Assume STRING is a Latin-1 encoded and convert it to utf-8.
Returns a newly malloced UTF-8 string. */
char *
Modified: trunk/src/gpgmsg.cpp
===================================================================
--- trunk/src/gpgmsg.cpp 2006-04-24 15:19:59 UTC (rev 149)
+++ trunk/src/gpgmsg.cpp 2006-04-25 14:51:54 UTC (rev 150)
@@ -1208,10 +1208,15 @@
because this might lead to storing the new text in the
message. */
if (is_pgpmime_sig || is_pgpmime_enc)
- update_display (hwnd, this, NULL, 0,
- _("[This is a PGP/MIME message]\r\n\r\n"
- "[Use the \"Decrypt\" button in the message window "
- "to show its content.]"));
+ {
+ char *tmp = native_to_utf8
+ (_("[This is a PGP/MIME message]\r\n\r\n"
+ "[Use the \"Decrypt\" button in the message window "
+ "to show its content.]"));
+ update_display (hwnd, this, NULL, 0, tmp);
+ xfree (tmp);
+ }
+
release_attach_info (table);
xfree (body);
return 0;
@@ -1284,9 +1289,13 @@
message. This is useful in case of such messages with
longish attachments which might take long to decrypt. */
if (!body || !*body)
- update_display (hwnd, this, exchange_cb, 0,
- _("[This is a PGP/MIME message]"));
-
+ {
+ char *tmp = native_to_utf8 (_("[This is a PGP/MIME message]"));
+ update_display (hwnd, this, exchange_cb, 0, tmp);
+ xfree (tmp);
+ }
+
+
hr = message->OpenAttach (1, NULL, MAPI_BEST_ACCESS, &att);
if (FAILED (hr))
{
Modified: trunk/src/passphrase-dialog.c
===================================================================
--- trunk/src/passphrase-dialog.c 2006-04-24 15:19:59 UTC (rev 149)
+++ trunk/src/passphrase-dialog.c 2006-04-25 14:51:54 UTC (rev 150)
@@ -153,7 +153,7 @@
{
if (key && key->uids && key->uids->uid)
{
- char *utf8_uid = utf8_to_wincp (key->uids->uid);
+ char *utf8_uid = utf8_to_native (key->uids->uid);
SendDlgItemMessage (dlg, ctlid, LB_ADDSTRING, 0,
(LPARAM)(const char *)utf8_uid);
xfree (utf8_uid);
@@ -249,7 +249,7 @@
if (!key->uids->name)
name = strdup ("");
else
- name = utf8_to_wincp (key->uids->name);
+ name = utf8_to_native (key->uids->name);
email = key->uids->email;
if (!email)
email = "";
@@ -739,7 +739,7 @@
else
s = "[no user Id]";
xfree (dec->user_id);
- dec->user_id = utf8_to_wincp (s);
+ dec->user_id = utf8_to_native (s);
dec->last_was_bad = prev_was_bad;
if (dec->flags & 0x01)
{
Modified: trunk/src/pgpmime.c
===================================================================
--- trunk/src/pgpmime.c 2006-04-24 15:19:59 UTC (rev 149)
+++ trunk/src/pgpmime.c 2006-04-25 14:51:54 UTC (rev 150)
@@ -686,6 +686,7 @@
struct gpgme_data_cbs cbs;
gpgme_data_t plaintext;
pgpmime_context_t ctx;
+ char *tmp;
*body = NULL;
@@ -709,9 +710,10 @@
if (err)
goto leave;
- err = op_decrypt_stream_to_gpgme (instream, plaintext, ttl,
- _("[PGP/MIME message]"), attestation,
- preview_mode);
+ tmp = native_to_utf8 (_("[PGP/MIME message]"));
+ err = op_decrypt_stream_to_gpgme (instream, plaintext, ttl, tmp,
+ attestation, preview_mode);
+ xfree (tmp);
if (!err && (ctx->parser_error || ctx->line_too_long))
err = gpg_error (GPG_ERR_GENERAL);
@@ -727,7 +729,10 @@
}
}
else
- *body = xstrdup (_("[PGP/MIME message without plain text body]"));
+ {
+ *body = native_to_utf8 (_("[PGP/MIME message "
+ "without plain text body]"));
+ }
}
leave:
@@ -799,18 +804,23 @@
}
}
else
- *body = xstrdup (_("[PGP/MIME signed message without a "
- "plain text body]"));
+ {
+ *body = native_to_utf8 (_("[PGP/MIME signed message without a "
+ "plain text body]"));
+ }
}
/* Now actually verify the signature. */
if (!err && ctx->signed_data && ctx->sig_data)
{
+ char *tmp;
+
gpgme_data_seek (ctx->signed_data, 0, SEEK_SET);
gpgme_data_seek (ctx->sig_data, 0, SEEK_SET);
+ tmp = native_to_utf8 (_("[PGP/MIME signature]"));
err = op_verify_detached_sig_gpgme (ctx->signed_data, ctx->sig_data,
- _("[PGP/MIME signature]"),
- attestation);
+ tmp, attestation);
+ xfree (tmp);
}
Modified: trunk/src/recipient-dialog.c
===================================================================
--- trunk/src/recipient-dialog.c 2006-04-24 15:19:59 UTC (rev 149)
+++ trunk/src/recipient-dialog.c 2006-04-25 14:51:54 UTC (rev 150)
@@ -179,7 +179,7 @@
ListView_InsertItem (hwnd, &lvi);
- s = utf8_to_wincp (key->uids->name);
+ s = utf8_to_native (key->uids->name);
ListView_SetItemText (hwnd, 0, COL_NAME, s);
xfree (s);
Modified: trunk/src/util.h
===================================================================
--- trunk/src/util.h 2006-04-24 15:19:59 UTC (rev 149)
+++ trunk/src/util.h 2006-04-25 14:51:54 UTC (rev 150)
@@ -50,15 +50,10 @@
/*-- common.c --*/
-void* xmalloc (size_t n);
-void* xcalloc (size_t m, size_t n);
-char* xstrdup (const char *s);
-void xfree (void *p);
-void out_of_core (void);
-char *wchar_to_utf8 (const wchar_t *string);
+#include "xmalloc.h"
+
char *wchar_to_utf8_2 (const wchar_t *string, size_t len);
-wchar_t *utf8_to_wchar (const char *string);
wchar_t *utf8_to_wchar2 (const char *string, size_t len);
char *latin1_to_utf8 (const char *string);
Modified: trunk/src/verify-dialog.c
===================================================================
--- trunk/src/verify-dialog.c 2006-04-24 15:19:59 UTC (rev 149)
+++ trunk/src/verify-dialog.c 2006-04-25 14:51:54 UTC (rev 150)
@@ -67,7 +67,7 @@
return n;
for (u=u->next; u; u=u->next)
{
- uid = utf8_to_wincp (u->uid);
+ uid = utf8_to_native (u->uid);
SendDlgItemMessage (dlg, IDC_VRY_AKALIST, LB_ADDSTRING,
0, (LPARAM)(const char*)uid);
xfree (uid);
@@ -143,7 +143,7 @@
if (key && key->uids)
{
- p = utf8_to_wincp (key->uids->uid);
+ p = utf8_to_native (key->uids->uid);
SetDlgItemText (dlg, IDC_VRY_ISSUER, p);
xfree (p);
Modified: trunk/src/w32-gettext.c
===================================================================
--- trunk/src/w32-gettext.c 2006-04-24 15:19:59 UTC (rev 149)
+++ trunk/src/w32-gettext.c 2006-04-25 14:51:54 UTC (rev 150)
@@ -33,6 +33,7 @@
#include <stdint.h>
#include "w32-gettext.h"
+#include "xmalloc.h"
/* localname.c from gettext. */
@@ -1432,12 +1433,36 @@
}
+static wchar_t *
+native_to_wchar (const char *string)
+{
+ int n;
+ wchar_t *result;
+
+ n = MultiByteToWideChar (CP_ACP, 0, string, -1, NULL, 0);
+ if (n < 0)
+ return NULL;
+
+ result = malloc ((n+1) * sizeof *result);
+ if (!result)
+ return NULL;
+
+ n = MultiByteToWideChar (CP_ACP, 0, string, -1, result, n);
+ if (n < 0)
+ {
+ free (result);
+ return NULL;
+ }
+ return result;
+}
+
+
/* Return a malloced wide char string from an UTF-8 encoded input
string STRING. Caller must free this value. On failure returns
NULL; caller may use GetLastError to get the actual error number.
The result of calling this function with STRING set to NULL is not
defined. */
-static wchar_t *
+wchar_t *
utf8_to_wchar (const char *string)
{
int n;
@@ -1461,7 +1486,37 @@
}
+/* Return a malloced string encoded in UTF-8 from the wide char input
+ string STRING. Caller must xfree this value. On failure returns
+ NULL; caller may use GetLastError to get the actual error number.
+ The result of calling this function with STRING set to NULL is not
+ defined. */
char *
+wchar_to_utf8 (const wchar_t *string)
+{
+ int n;
+ char *result;
+
+ /* Note, that CP_UTF8 is not defined in Windows versions earlier
+ than NT.*/
+ n = WideCharToMultiByte (CP_UTF8, 0, string, -1, NULL, 0, NULL, NULL);
+ if (n < 0)
+ return NULL;
+
+ result = xmalloc (n+1);
+ n = WideCharToMultiByte (CP_UTF8, 0, string, -1, result, n, NULL, NULL);
+ if (n < 0)
+ {
+ xfree (result);
+ return NULL;
+ }
+ return result;
+}
+
+
+/* Convert UTF8 to the native codepage. This function is guaranteed
+ to never return NULL. Caller must xfree the return value. */
+char *
utf8_to_native (const char *string)
{
wchar_t *wstring;
@@ -1469,15 +1524,41 @@
wstring = utf8_to_wchar (string);
if (!wstring)
- return NULL;
+ return xstrdup ("[Error: utf8_to_wchar failed]");
result = wchar_to_native (wstring);
free (wstring);
+ if (!result)
+ result = xstrdup ("[Error: wchar_to_native failed]");
return result;
}
+/* Convert native character set to utf-8. This is required if we want
+ to get an utf-8 string from a gettext translated function which
+ internally uses utf8_to_native. It is guaranteed that NULL is
+ never returned. Caller must xfree the return value. */
+char *
+native_to_utf8 (const char *string)
+{
+ char *result;
+ wchar_t *wstring;
+
+ wstring = native_to_wchar (string);
+ if (!wstring)
+ return xstrdup ("[Error: native_to_wchar failed]");
+
+ result = wchar_to_utf8 (wstring);
+ free (wstring);
+ if (!result)
+ result = xstrdup ("[Error: wchar_to_utf8 failed]");
+
+ return result;
+}
+
+
+
static const char*
get_string (struct loaded_domain *domain, u32 idx)
{
Modified: trunk/src/w32-gettext.h
===================================================================
--- trunk/src/w32-gettext.h 2006-04-24 15:19:59 UTC (rev 149)
+++ trunk/src/w32-gettext.h 2006-04-25 14:51:54 UTC (rev 150)
@@ -53,4 +53,14 @@
static inline const char *gettext_localename (void) { return ""; }
+
#endif /* !ENABLE_NLS */
+
+/* Conversion function. */
+char *wchar_to_utf8 (const wchar_t *string);
+wchar_t *utf8_to_wchar (const char *string);
+
+char *utf8_to_native (const char *string);
+char *native_to_utf8 (const char *string);
+
+
Added: trunk/src/xmalloc.h
===================================================================
--- trunk/src/xmalloc.h 2006-04-24 15:19:59 UTC (rev 149)
+++ trunk/src/xmalloc.h 2006-04-25 14:51:54 UTC (rev 150)
@@ -0,0 +1,43 @@
+/* xmalloc.h - xmalloc prototypes
+ * Copyright (C) 2006 g10 Code GmbH
+ *
+ * This file is part of GPGol.
+ *
+ * GPGol is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * GPGol is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef XMALLOC_H
+#define XMALLOC_H
+
+#ifdef __cplusplus
+extern "C" {
+#if 0
+}
+#endif
+#endif
+
+/*-- common.c --*/
+void* xmalloc (size_t n);
+void* xcalloc (size_t m, size_t n);
+char* xstrdup (const char *s);
+void xfree (void *p);
+void out_of_core (void);
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif /*XMALLOC_H*/
More information about the Gnupg-commits
mailing list