[svn] GnuPG - r4598 - in trunk: agent common g10 sm tools

svn author wk cvs at cvs.gnupg.org
Fri Oct 19 17:58:49 CEST 2007


Author: wk
Date: 2007-10-19 17:58:38 +0200 (Fri, 19 Oct 2007)
New Revision: 4598

Modified:
   trunk/agent/ChangeLog
   trunk/agent/protect-tool.c
   trunk/common/ChangeLog
   trunk/common/i18n.c
   trunk/common/i18n.h
   trunk/g10/ChangeLog
   trunk/g10/passphrase.c
   trunk/sm/ChangeLog
   trunk/sm/certdump.c
   trunk/sm/qualified.c
   trunk/tools/ChangeLog
   trunk/tools/symcryptrun.c
Log:
Factored utf8 switching code out to i18n.c.


Modified: trunk/agent/ChangeLog
===================================================================
--- trunk/agent/ChangeLog	2007-10-19 14:51:39 UTC (rev 4597)
+++ trunk/agent/ChangeLog	2007-10-19 15:58:38 UTC (rev 4598)
@@ -1,3 +1,7 @@
+2007-10-19  Werner Koch  <wk at g10code.com>
+
+	* protect-tool.c (get_passphrase): Use new utf8 switch fucntions.
+
 2007-10-15  Daiki Ueno  <ueno at unixuser.org>  (wk)
 
 	* command-ssh.c (reenter_compare_cb): New function; imported from

Modified: trunk/agent/protect-tool.c
===================================================================
--- trunk/agent/protect-tool.c	2007-10-19 14:51:39 UTC (rev 4597)
+++ trunk/agent/protect-tool.c	2007-10-19 15:58:38 UTC (rev 4598)
@@ -1171,38 +1171,16 @@
   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 @@
                        _("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)
     {

Modified: trunk/common/ChangeLog
===================================================================
--- trunk/common/ChangeLog	2007-10-19 14:51:39 UTC (rev 4597)
+++ trunk/common/ChangeLog	2007-10-19 15:58:38 UTC (rev 4598)
@@ -1,3 +1,7 @@
+2007-10-19  Werner Koch  <wk at g10code.com>
+
+	* i18n.c (i18n_switchto_utf8, i18n_switchback): New.
+
 2007-10-01  Werner Koch  <wk at g10code.com>
 
 	* sysutils.h (FD2INT, INT2FD): New.

Modified: trunk/common/i18n.c
===================================================================
--- trunk/common/i18n.c	2007-10-19 14:51:39 UTC (rev 4597)
+++ trunk/common/i18n.c	2007-10-19 15:58:38 UTC (rev 4598)
@@ -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 @@
 #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;
+}

Modified: trunk/common/i18n.h
===================================================================
--- trunk/common/i18n.h	2007-10-19 14:51:39 UTC (rev 4597)
+++ trunk/common/i18n.h	2007-10-19 15:58:38 UTC (rev 4598)
@@ -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*/

Modified: trunk/g10/ChangeLog
===================================================================
--- trunk/g10/ChangeLog	2007-10-19 14:51:39 UTC (rev 4597)
+++ trunk/g10/ChangeLog	2007-10-19 15:58:38 UTC (rev 4598)
@@ -1,3 +1,7 @@
+2007-10-19  Werner Koch  <wk at g10code.com>
+
+	* passphrase.c (passphrase_get): Use new utf8 switching fucntions.
+
 2007-09-14  Werner Koch  <wk at g10code.com>
 
 	* gpg.c (build_lib_list): New.

Modified: trunk/g10/passphrase.c
===================================================================
--- trunk/g10/passphrase.c	2007-10-19 14:51:39 UTC (rev 4597)
+++ trunk/g10/passphrase.c	2007-10-19 15:58:38 UTC (rev 4598)
@@ -257,9 +257,7 @@
   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 @@
       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 @@
   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 @@
       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)

Modified: trunk/sm/ChangeLog
===================================================================
--- trunk/sm/ChangeLog	2007-10-19 14:51:39 UTC (rev 4597)
+++ trunk/sm/ChangeLog	2007-10-19 15:58:38 UTC (rev 4598)
@@ -1,3 +1,9 @@
+2007-10-19  Werner Koch  <wk at 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 at g10code.com>
 
 	* gpgsm.c (build_lib_list): New.

Modified: trunk/sm/certdump.c
===================================================================
--- trunk/sm/certdump.c	2007-10-19 14:51:39 UTC (rev 4597)
+++ trunk/sm/certdump.c	2007-10-19 15:58:38 UTC (rev 4598)
@@ -891,9 +891,7 @@
   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,29 +907,8 @@
   else
     *created = 0;
 
+  orig_codeset = i18n_switchto_utf8 ();
 
-#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
-
-
   rc = asprintf (&name,
                  _("Please enter the passphrase to unlock the"
                    " secret key for:\n"
@@ -942,13 +919,7 @@
                  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)
     {

Modified: trunk/sm/qualified.c
===================================================================
--- trunk/sm/qualified.c	2007-10-19 14:51:39 UTC (rev 4597)
+++ trunk/sm/qualified.c	2007-10-19 15:58:38 UTC (rev 4598)
@@ -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 @@
   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 @@
   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 @@
   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,28 +271,8 @@
   subject = gpgsm_format_name2 (name, 0);
   ksba_free (name); name = NULL;
 
+  orig_codeset = i18n_switchto_utf8 ();
 
-#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
-
   if (asprintf (&name,
                 _("You are about to create a signature using your "
                   "certificate:\n"
@@ -334,13 +284,7 @@
   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)

Modified: trunk/tools/ChangeLog
===================================================================
--- trunk/tools/ChangeLog	2007-10-19 14:51:39 UTC (rev 4597)
+++ trunk/tools/ChangeLog	2007-10-19 15:58:38 UTC (rev 4598)
@@ -1,5 +1,7 @@
 2007-10-19  Werner Koch  <wk at 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.

Modified: trunk/tools/symcryptrun.c
===================================================================
--- trunk/tools/symcryptrun.c	2007-10-19 14:51:39 UTC (rev 4597)
+++ trunk/tools/symcryptrun.c	2007-10-19 15:58:38 UTC (rev 4598)
@@ -424,47 +424,18 @@
 {
   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);
+  i18n_switchback (orig_codeset);
 
-#ifdef ENABLE_NLS
-  if (orig_codeset)
-    {
-      bind_textdomain_codeset (PACKAGE_GT, orig_codeset);
-      xfree (orig_codeset);
-    }
-#endif
-
   if (!pw)
     {
       if (err)




More information about the Gnupg-commits mailing list