aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGisle Vanem <gvanem@broadpark.no>2004-10-06 18:40:10 +0000
committerGisle Vanem <gvanem@broadpark.no>2004-10-06 18:40:10 +0000
commitf0d6cc23ae53ce7e51bdb56ad03a2f9fd3aae2df (patch)
tree6af26638fdfa22c3fd6baf326abb70650cb93d04
parentceefe2e24822a36f3104a6f21006eb8b928d27cd (diff)
USE_LIBIDN: Added Top-level-domain (TLD) check for host->name.
Only print a warning if check fails.
-rw-r--r--lib/url.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/url.c b/lib/url.c
index 07d85fd71..e83836e74 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -86,6 +86,7 @@
#ifdef USE_LIBIDN
#include <idna.h>
+#include <tld.h>
#include <stringprep.h>
#ifdef HAVE_IDN_FREE_H
#include <idn-free.h>
@@ -2075,6 +2076,36 @@ static bool is_ASCII_name (const char *hostname)
}
return TRUE;
}
+
+/*
+ * Check if characters in hostname is allowed in Top Level Domain.
+ */
+static bool tld_check_name (struct connectdata *conn,
+ const char *ace_hostname)
+{
+ struct SessionHandle *data = conn->data;
+ size_t err_pos;
+ char *uc_name = NULL;
+ int rc;
+
+ /* Convert (and downcase) ACE-name back into locale's character set */
+ rc = idna_to_unicode_lzlz(ace_hostname, &uc_name, 0);
+ if (rc != IDNA_SUCCESS)
+ infof(data, "Failed to convert %s from ACE; %s\n",
+ ace_hostname, Curl_idn_strerror(conn,rc));
+
+ rc = tld_check_lz(uc_name, &err_pos, NULL);
+ if (rc == TLD_INVALID)
+ infof(data, "WARNING: %s; pos %u = `%c'/0x%02X\n",
+ tld_strerror(rc), err_pos, uc_name[err_pos],
+ uc_name[err_pos] & 255);
+ else if (rc != TLD_SUCCESS)
+ infof(data, "WARNING: TLD check for %s failed; %s\n",
+ uc_name, tld_strerror(rc));
+ if (uc_name)
+ idn_free(uc_name);
+ return (rc == TLD_SUCCESS);
+}
#endif
static void fix_hostname(struct connectdata *conn, struct hostname *host)
@@ -2097,6 +2128,8 @@ static void fix_hostname(struct connectdata *conn, struct hostname *host)
infof(data, "Failed to convert %s to ACE; %s\n",
host->name, Curl_idn_strerror(conn,rc));
else {
+ tld_check_name(conn, ace_hostname);
+
host->encalloc = ace_hostname;
/* change the name pointer to point to the encoded hostname */
host->name = host->encalloc;