1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

Show also the hostname in the locale when possible

This commit is contained in:
Saint Xavier 2008-07-02 16:37:28 +02:00
parent 85185bde1b
commit 99396653c2
4 changed files with 49 additions and 3 deletions

View 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

View File

@ -53,6 +53,7 @@ as that of the covered work. */
#include "host.h"
#include "url.h"
#include "hash.h"
#include "iri.h"
#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)
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
{

View File

@ -220,7 +220,7 @@ do_conversion (iconv_t cd, char *in, size_t inlen, char **out)
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)
{
@ -239,3 +239,22 @@ char *idn_encode (char *host)
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;
}

View File

@ -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);
char *idn_decode (char *host);
#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 idn_decode(str) NULL
#endif /* ENABLE_IRI */
#endif /* IRI_H */