]> sjero.net Git - wget/commitdiff
Show also the hostname in the locale when possible
authorSaint Xavier <wget@sxav.eu>
Wed, 2 Jul 2008 14:37:28 +0000 (16:37 +0200)
committerSaint Xavier <wget@sxav.eu>
Wed, 2 Jul 2008 14:37:28 +0000 (16:37 +0200)
src/ChangeLog
src/host.c
src/iri.c
src/iri.h

index 9e31b1c44fd89f83f9cef3a22519f9774daefd9e..7aca052701951708624a479b1f793e21f1dfe1c9 100644 (file)
@@ -1,3 +1,11 @@
+2008-07-02  Xavier Saint  <wget@sxav.eu>
+
+       * iri.c, iri.h  : New function idn_decode() to decode ASCII
+       encoded hostname to the locale.
+
+       * host.c : Show hostname to be resolved both in locale and
+       ASCII encoded.
+
 2008-06-26  Xavier Saint  <wget@sxav.eu>
 
        * iri.c, iri.h : New functions locale_to_utf8() and
 2008-06-26  Xavier Saint  <wget@sxav.eu>
 
        * iri.c, iri.h : New functions locale_to_utf8() and
index fdb35b1cad2bc92c5fa935eb2f7f5fbdfcbea493..8a1495f072f99e48c6b4c25f7b1d9edcb5cee521 100644 (file)
@@ -53,6 +53,7 @@ as that of the covered work.  */
 #include "host.h"
 #include "url.h"
 #include "hash.h"
 #include "host.h"
 #include "url.h"
 #include "hash.h"
+#include "iri.h"
 
 #ifndef NO_ADDRESS
 # define NO_ADDRESS NO_DATA
 
 #ifndef NO_ADDRESS
 # define NO_ADDRESS NO_DATA
@@ -712,8 +713,24 @@ lookup_host (const char *host, int flags)
   /* No luck with the cache; resolve HOST. */
 
   if (!silent && !numeric_address)
   /* No luck with the cache; resolve HOST. */
 
   if (!silent && !numeric_address)
-    logprintf (LOG_VERBOSE, _("Resolving %s... "), 
-               quotearg_style (escape_quoting_style, host));
+    {
+      char *str = NULL, *name = NULL;
+
+      if (opt.enable_iri && (name = idn_decode (host)) != NULL)
+        {
+          int len = strlen (host) + strlen (name) + 4;
+          str = xmalloc (len);
+          snprintf (str, len, "%s (%s)", name, host);
+          str[len-1] = '\0';
+          xfree (name);
+        }
+
+      logprintf (LOG_VERBOSE, _("Resolving %s... "), 
+                 quotearg_style (escape_quoting_style, str ? str : host));
+
+      if (str)
+        xfree (str);
+    }
 
 #ifdef ENABLE_IPV6
   {
 
 #ifdef ENABLE_IPV6
   {
index dfcb05783fa9fce2661275427b9ef18f5ba1c9ae..000f655037eeafb222d8078302551cee707104d1 100644 (file)
--- a/src/iri.c
+++ b/src/iri.c
@@ -220,7 +220,7 @@ do_conversion (iconv_t cd, char *in, size_t inlen, char **out)
     return false;
 }
 
     return false;
 }
 
-/* Try to encode UTF-8 host to ASCII. Return the new domain on success or NULL
+/* Try to ASCII encode UTF-8 host. Return the new domain on success or NULL
    on error. */
 char *idn_encode (char *host)
 {
    on error. */
 char *idn_encode (char *host)
 {
@@ -239,3 +239,22 @@ char *idn_encode (char *host)
   return new;
 }
 
   return new;
 }
 
+/* Try to decode an ASCII encoded host. Return the new domain in the locale on
+   success or NULL on error. */
+char *idn_decode (char *host)
+{
+  char *new;
+  int ret;
+
+  ret = idna_to_unicode_8zlz (host, &new, 0);
+  if (ret != IDNA_SUCCESS)
+    {
+      logprintf (LOG_VERBOSE, "idn_decode failed (%d): %s\n", ret,
+                 quote (idna_strerror (ret)));
+      return NULL;
+    }
+
+  return new;
+}
+
+
index 6485847676e1a33b8dc5e78e01f2f70fa58fc018..3992d76d793c77d738b50b17b0b5cbd85f42caa9 100644 (file)
--- a/src/iri.h
+++ b/src/iri.h
@@ -37,6 +37,7 @@ char *find_locale (void);
 bool check_encoding_name (char *encoding);
 const char *locale_to_utf8 (const char *str);
 char *idn_encode (char *host);
 bool check_encoding_name (char *encoding);
 const char *locale_to_utf8 (const char *str);
 char *idn_encode (char *host);
+char *idn_decode (char *host);
 
 #else /* ENABLE_IRI */
 
 
 #else /* ENABLE_IRI */
 
@@ -45,6 +46,7 @@ char *idn_encode (char *host);
 #define check_encoding_name(str)    false
 #define locale_to_utf8(str)         (str)
 #define idn_encode(str)             NULL
 #define check_encoding_name(str)    false
 #define locale_to_utf8(str)         (str)
 #define idn_encode(str)             NULL
+#define idn_decode(str)             NULL
 
 #endif /* ENABLE_IRI */
 #endif /* IRI_H */
 
 #endif /* ENABLE_IRI */
 #endif /* IRI_H */