summaryrefslogtreecommitdiff
path: root/whois.c
diff options
context:
space:
mode:
authorMarco d'Itri <md@linux.it>2017-02-27 00:32:43 +0100
committerMarco d'Itri <md@linux.it>2017-02-27 00:32:43 +0100
commit8ed6d730959b1f988dd43a511c40b9419bb2b0db (patch)
tree10168e7c8e0e1e77cd2cdc32b2c74e70c6ee2d34 /whois.c
parentcf61394ded7532b339f22411cf048c83a70277bb (diff)
downloadwhois-8ed6d730959b1f988dd43a511c40b9419bb2b0db.tar.gz
Implement support for libidn2
Contributed by Tim Rühsen. Closes #49 from Github.
Diffstat (limited to 'whois.c')
-rw-r--r--whois.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/whois.c b/whois.c
index 06346ed..8f5f1f1 100644
--- a/whois.c
+++ b/whois.c
@@ -31,7 +31,9 @@
#ifdef HAVE_REGEXEC
#include <regex.h>
#endif
-#ifdef HAVE_LIBIDN
+#ifdef HAVE_LIBIDN2
+#include <idn2.h>
+#elif defined HAVE_LIBIDN
#include <idna.h>
#endif
#ifdef HAVE_INET_PTON
@@ -654,7 +656,7 @@ char *queryformat(const char *server, const char *flags, const char *query)
simple_recode_input_charset = "utf-8"; /* then try UTF-8 */
#endif
-#ifdef HAVE_LIBIDN
+#if defined HAVE_LIBIDN || defined HAVE_LIBIDN2
# define DENIC_PARAM_ACE ",ace"
#else
# define DENIC_PARAM_ACE ""
@@ -1144,7 +1146,7 @@ const char *is_new_gtld(const char *s)
char *normalize_domain(const char *dom)
{
char *p, *ret;
-#ifdef HAVE_LIBIDN
+#if defined HAVE_LIBIDN || defined HAVE_LIBIDN2
char *domain_start = NULL;
#endif
@@ -1159,7 +1161,7 @@ char *normalize_domain(const char *dom)
p--;
}
-#ifdef HAVE_LIBIDN
+#if defined HAVE_LIBIDN || defined HAVE_LIBIDN2
/* find the start of the last word if there are spaces in the query */
for (p = ret; *p; p++)
if (*p == ' ')
@@ -1169,8 +1171,13 @@ char *normalize_domain(const char *dom)
char *q, *r;
int prefix_len;
+#ifdef HAVE_LIBIDN2
+ if (idn2_lookup_ul(domain_start, &q, IDN2_NONTRANSITIONAL) != IDN2_OK)
+ return ret;
+#else
if (idna_to_ascii_lz(domain_start, &q, 0) != IDNA_SUCCESS)
return ret;
+#endif
/* reassemble the original query in a new buffer */
prefix_len = domain_start - ret;
@@ -1185,8 +1192,13 @@ char *normalize_domain(const char *dom)
} else {
char *q;
+#ifdef HAVE_LIBIDN2
+ if (idn2_lookup_ul(ret, &q, IDN2_NONTRANSITIONAL) != IDN2_OK)
+ return ret;
+#else
if (idna_to_ascii_lz(ret, &q, 0) != IDNA_SUCCESS)
return ret;
+#endif
free(ret);
return q;