Factored utf8 switching code out to i18n.c.

This commit is contained in:
Werner Koch 2007-10-19 15:58:38 +00:00
parent 259a40c830
commit c12ce55b25
12 changed files with 107 additions and 184 deletions

View File

@ -1,3 +1,7 @@
2007-10-19 Werner Koch <wk@g10code.com>
* protect-tool.c (get_passphrase): Use new utf8 switch fucntions.
2007-10-15 Daiki Ueno <ueno@unixuser.org> (wk)
* command-ssh.c (reenter_compare_cb): New function; imported from

View File

@ -1171,38 +1171,16 @@ get_passphrase (int promptno, int opt_check)
char *pw;
int err;
const char *desc;
#ifdef ENABLE_NLS
char *orig_codeset = NULL;
#endif
char *orig_codeset;
int error_msgno;
if (opt_passphrase)
return xstrdup (opt_passphrase);
error_msgno = promptno / 100;
promptno %= 100;
#ifdef ENABLE_NLS
/* The Assuan agent protocol requires us to transmit utf-8 strings */
orig_codeset = bind_textdomain_codeset (PACKAGE_GT, NULL);
#ifdef HAVE_LANGINFO_CODESET
if (!orig_codeset)
orig_codeset = nl_langinfo (CODESET);
#endif
if (orig_codeset && !strcmp (orig_codeset, "UTF-8"))
orig_codeset = NULL;
if (orig_codeset)
{
/* We only switch when we are able to restore the codeset later. */
orig_codeset = xstrdup (orig_codeset);
if (!bind_textdomain_codeset (PACKAGE_GT, "utf-8"))
{
xfree (orig_codeset);
orig_codeset = NULL;
}
}
#endif
orig_codeset = i18n_switchto_utf8 ();
if (promptno == 1 && opt_prompt)
desc = opt_prompt;
@ -1226,13 +1204,7 @@ get_passphrase (int promptno, int opt_check)
_("Passphrase:"), desc, opt_check, &err);
err = map_spwq_error (err);
#ifdef ENABLE_NLS
if (orig_codeset)
{
bind_textdomain_codeset (PACKAGE_GT, orig_codeset);
xfree (orig_codeset);
}
#endif
i18n_switchback (orig_codeset);
if (!pw)
{

View File

@ -1,3 +1,7 @@
2007-10-19 Werner Koch <wk@g10code.com>
* i18n.c (i18n_switchto_utf8, i18n_switchback): New.
2007-10-01 Werner Koch <wk@g10code.com>
* sysutils.h (FD2INT, INT2FD): New.

View File

@ -18,9 +18,17 @@
*/
#include <config.h>
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
#ifdef HAVE_LANGINFO_CODESET
#include <langinfo.h>
#endif
#include "util.h"
#include "i18n.h"
void
i18n_init (void)
{
@ -35,3 +43,59 @@ i18n_init (void)
#endif
}
/* The Assuan agent protocol requires us to transmit utf-8 strings
thus we need a fucntion to temporary switch gettext from native to
utf8. */
char *
i18n_switchto_utf8 (void)
{
#ifdef ENABLE_NLS
char *orig_codeset = bind_textdomain_codeset (PACKAGE_GT, NULL);
#ifdef HAVE_LANGINFO_CODESET
if (!orig_codeset)
orig_codeset = nl_langinfo (CODESET);
#endif
if (orig_codeset)
{ /* We only switch when we are able to restore the codeset later.
Note that bind_textdomain_codeset does only return on memory
errors but not if a codeset is not available. Thus we don't
bother printing a diagnostic here. */
orig_codeset = xstrdup (orig_codeset);
if (!bind_textdomain_codeset (PACKAGE_GT, "utf-8"))
{
xfree (orig_codeset);
orig_codeset = NULL;
}
}
return orig_codeset;
#else
return NULL;
#endif
}
/* Switch back to the saved codeset. */
void
i18n_switchback (char *saved_codeset)
{
#ifdef ENABLE_NLS
if (saved_codeset)
{
bind_textdomain_codeset (PACKAGE_GT, saved_codeset);
xfree (saved_codeset);
}
#else
(void)saved_codeset;
#endif
}
/* Gettext variant which temporary switches to utf-8 for string. */
const char *
i18n_utf8 (const char *string)
{
char *saved = i18n_switchto_utf8 ();
const char *result = _(string);
i18n_switchback (saved);
return result;
}

View File

@ -39,6 +39,9 @@
#endif /*!USE_SIMPLE_GETTEXT*/
void i18n_init (void);
char *i18n_switchto_utf8 (void);
void i18n_switchback (char *saved_codeset);
const char *i18n_utf8 (const char *string);
#endif /*GNUPG_COMMON_I18N_H*/

View File

@ -1,3 +1,7 @@
2007-10-19 Werner Koch <wk@g10code.com>
* passphrase.c (passphrase_get): Use new utf8 switching fucntions.
2007-09-14 Werner Koch <wk@g10code.com>
* gpg.c (build_lib_list): New.

View File

@ -257,9 +257,7 @@ passphrase_get ( u32 *keyid, int mode, const char *cacheid,
PKT_public_key *pk = xmalloc_clear( sizeof *pk );
byte fpr[MAX_FINGERPRINT_LEN];
int have_fpr = 0;
#ifdef ENABLE_NLS
char *orig_codeset = NULL;
#endif
char *orig_codeset;
char *my_prompt;
char hexfprbuf[20*2+1];
const char *my_cacheid;
@ -279,23 +277,7 @@ passphrase_get ( u32 *keyid, int mode, const char *cacheid,
pk = NULL; /* oops: no key for some reason */
}
#ifdef ENABLE_NLS
/* The Assuan agent protocol requires us to transmit utf-8 strings */
orig_codeset = bind_textdomain_codeset (PACKAGE_GT, NULL);
#ifdef HAVE_LANGINFO_CODESET
if (!orig_codeset)
orig_codeset = nl_langinfo (CODESET);
#endif
if (orig_codeset)
{ /* We only switch when we are able to restore the codeset later. */
orig_codeset = xstrdup (orig_codeset);
if (!bind_textdomain_codeset (PACKAGE_GT, "utf-8"))
{
xfree (orig_codeset);
orig_codeset = NULL;
}
}
#endif
orig_codeset = i18n_switchto_utf8 ();
if (custom_description)
atext = native_to_utf8 (custom_description);
@ -371,6 +353,9 @@ passphrase_get ( u32 *keyid, int mode, const char *cacheid,
xfree (my_prompt);
xfree (atext); atext = NULL;
i18n_switchback (orig_codeset);
if (!rc)
;
else if ( gpg_err_code (rc) == GPG_ERR_CANCELED )
@ -392,14 +377,7 @@ passphrase_get ( u32 *keyid, int mode, const char *cacheid,
if (canceled)
*canceled = 1;
}
#ifdef ENABLE_NLS
if (orig_codeset)
{
bind_textdomain_codeset (PACKAGE_GT, orig_codeset);
xfree (orig_codeset);
}
#endif
if (pk)
free_public_key( pk );
if (rc)

View File

@ -1,3 +1,9 @@
2007-10-19 Werner Koch <wk@g10code.com>
* qualified.c (gpgsm_qualified_consent): Use i18N-swicth functions.
(gpgsm_not_qualified_warning): Ditto.
* certdump.c (gpgsm_format_keydesc): Ditto.
2007-09-14 Werner Koch <wk@g10code.com>
* gpgsm.c (build_lib_list): New.

View File

@ -891,9 +891,7 @@ gpgsm_format_keydesc (ksba_cert_t cert)
char created[20];
char *sn;
ksba_sexp_t sexp;
#ifdef ENABLE_NLS
char *orig_codeset = NULL;
#endif
char *orig_codeset;
name = ksba_cert_get_subject (cert, 0);
subject = name? gpgsm_format_name2 (name, 0) : NULL;
@ -909,28 +907,7 @@ gpgsm_format_keydesc (ksba_cert_t cert)
else
*created = 0;
#ifdef ENABLE_NLS
/* The Assuan agent protocol requires us to transmit utf-8 strings */
orig_codeset = bind_textdomain_codeset (PACKAGE_GT, NULL);
#ifdef HAVE_LANGINFO_CODESET
if (!orig_codeset)
orig_codeset = nl_langinfo (CODESET);
#endif
if (orig_codeset)
{ /* We only switch when we are able to restore the codeset later.
Note that bind_textdomain_codeset does only return on memory
errors but not if a codeset is not available. Thus we don't
bother printing a diagnostic here. */
orig_codeset = xstrdup (orig_codeset);
if (!bind_textdomain_codeset (PACKAGE_GT, "utf-8"))
{
xfree (orig_codeset);
orig_codeset = NULL;
}
}
#endif
orig_codeset = i18n_switchto_utf8 ();
rc = asprintf (&name,
_("Please enter the passphrase to unlock the"
@ -942,13 +919,7 @@ gpgsm_format_keydesc (ksba_cert_t cert)
gpgsm_get_short_fingerprint (cert),
created);
#ifdef ENABLE_NLS
if (orig_codeset)
{
bind_textdomain_codeset (PACKAGE_GT, orig_codeset);
xfree (orig_codeset);
}
#endif
i18n_switchback (orig_codeset);
if (rc < 0)
{

View File

@ -24,12 +24,6 @@
#include <stdarg.h>
#include <assert.h>
#include <errno.h>
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
#ifdef HAVE_LANGINFO_CODESET
#include <langinfo.h>
#endif
#include "gpgsm.h"
#include "i18n.h"
@ -200,26 +194,7 @@ gpgsm_qualified_consent (ctrl_t ctrl, ksba_cert_t cert)
subject = gpgsm_format_name2 (name, 0);
ksba_free (name); name = NULL;
#ifdef ENABLE_NLS
/* The Assuan agent protocol requires us to transmit utf-8 strings */
orig_codeset = bind_textdomain_codeset (PACKAGE_GT, NULL);
#ifdef HAVE_LANGINFO_CODESET
if (!orig_codeset)
orig_codeset = nl_langinfo (CODESET);
#endif
if (orig_codeset)
{ /* We only switch when we are able to restore the codeset later.
Note that bind_textdomain_codeset does only return on memory
errors but not if a codeset is not available. Thus we don't
bother printing a diagnostic here. */
orig_codeset = xstrdup (orig_codeset);
if (!bind_textdomain_codeset (PACKAGE_GT, "utf-8"))
{
xfree (orig_codeset);
orig_codeset = NULL;
}
}
#endif
orig_codeset = i18n_switchto_utf8 ();
if (asprintf (&name,
_("You are about to create a signature using your "
@ -239,10 +214,7 @@ gpgsm_qualified_consent (ctrl_t ctrl, ksba_cert_t cert)
else
err = 0;
#ifdef ENABLE_NLS
if (orig_codeset)
bind_textdomain_codeset (PACKAGE_GT, orig_codeset);
#endif
i18n_switchback (orig_codeset);
xfree (orig_codeset);
xfree (subject);
@ -288,9 +260,7 @@ gpgsm_not_qualified_warning (ctrl_t ctrl, ksba_cert_t cert)
gpg_error_t err;
char *name, *subject, *buffer, *p;
const char *s;
#ifdef ENABLE_NLS
char *orig_codeset = NULL;
#endif
char *orig_codeset;
if (!opt.qualsig_approval)
return 0;
@ -301,27 +271,7 @@ gpgsm_not_qualified_warning (ctrl_t ctrl, ksba_cert_t cert)
subject = gpgsm_format_name2 (name, 0);
ksba_free (name); name = NULL;
#ifdef ENABLE_NLS
/* The Assuan agent protocol requires us to transmit utf-8 strings */
orig_codeset = bind_textdomain_codeset (PACKAGE_GT, NULL);
#ifdef HAVE_LANGINFO_CODESET
if (!orig_codeset)
orig_codeset = nl_langinfo (CODESET);
#endif
if (orig_codeset)
{ /* We only switch when we are able to restore the codeset later.
Note that bind_textdomain_codeset does only return on memory
errors but not if a codeset is not available. Thus we don't
bother printing a diagnostic here. */
orig_codeset = xstrdup (orig_codeset);
if (!bind_textdomain_codeset (PACKAGE_GT, "utf-8"))
{
xfree (orig_codeset);
orig_codeset = NULL;
}
}
#endif
orig_codeset = i18n_switchto_utf8 ();
if (asprintf (&name,
_("You are about to create a signature using your "
@ -334,13 +284,7 @@ gpgsm_not_qualified_warning (ctrl_t ctrl, ksba_cert_t cert)
else
err = 0;
#ifdef ENABLE_NLS
if (orig_codeset)
{
bind_textdomain_codeset (PACKAGE_GT, orig_codeset);
xfree (orig_codeset);
}
#endif
i18n_switchback (orig_codeset);
xfree (subject);
if (err)

View File

@ -1,5 +1,7 @@
2007-10-19 Werner Koch <wk@g10code.com>
* symcryptrun.c (confucius_get_pass): Use utf8 switching functions.
* gpg-connect-agent.c (get_var_ext): New.
(substitute_line): Use it.
(assign_variable): Implement /slet in terms of get_var_ext.

View File

@ -424,46 +424,17 @@ confucius_get_pass (const char *cacheid, int again, int *canceled)
{
int err;
char *pw;
#ifdef ENABLE_NLS
char *orig_codeset = NULL;
#endif
char *orig_codeset;
if (canceled)
*canceled = 0;
#ifdef ENABLE_NLS
/* The Assuan agent protocol requires us to transmit utf-8 strings */
orig_codeset = bind_textdomain_codeset (PACKAGE_GT, NULL);
#ifdef HAVE_LANGINFO_CODESET
if (!orig_codeset)
orig_codeset = nl_langinfo (CODESET);
#endif
if (orig_codeset && !strcmp (orig_codeset, "UTF-8"))
orig_codeset = NULL;
if (orig_codeset)
{
/* We only switch when we are able to restore the codeset later. */
orig_codeset = xstrdup (orig_codeset);
if (!bind_textdomain_codeset (PACKAGE_GT, "utf-8"))
{
xfree (orig_codeset);
orig_codeset = NULL;
}
}
#endif
orig_codeset = i18n_switchto_utf8 ();
pw = simple_pwquery (cacheid,
again ? _("does not match - try again"):NULL,
_("Passphrase:"), NULL, 0, &err);
err = map_spwq_error (err);
#ifdef ENABLE_NLS
if (orig_codeset)
{
bind_textdomain_codeset (PACKAGE_GT, orig_codeset);
xfree (orig_codeset);
}
#endif
i18n_switchback (orig_codeset);
if (!pw)
{