summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTim Rühsen <tim.ruehsen@gmx.de>2017-01-21 23:14:46 +0100
committerNikos Mavrogiannopoulos <nmav@redhat.com>2017-01-26 16:11:03 +0100
commit0d18eaea0bf9e29f27f6a6ec330c9f455d7472f6 (patch)
tree179be2ea41a86f7fe7266688cc34b541e825a4cf /src
parente173bec552096c7cecc918117a441921e964b8c8 (diff)
downloadgnutls-0d18eaea0bf9e29f27f6a6ec330c9f455d7472f6.tar.gz
Add support for libidn2 (IDNA 2008 + TR46)
Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
Diffstat (limited to 'src')
-rw-r--r--src/socket.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/socket.c b/src/socket.c
index f60479f5cc..2c7e9009c1 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -43,7 +43,9 @@
#include <c-ctype.h>
#include "sockets.h"
-#ifdef HAVE_LIBIDN
+#ifdef HAVE_LIBIDN2
+#include <idn2.h>
+#elif defined HAVE_LIBIDN
#include <idna.h>
#include <idn-free.h>
#endif
@@ -398,7 +400,26 @@ socket_open(socket_st * hd, const char *hostname, const char *service,
hd->rdata.size = rdata->size;
}
-#ifdef HAVE_LIBIDN
+#ifdef HAVE_LIBIDN2
+#if IDN2_VERSION_NUMBER >= 0x00140000
+ /* IDN2_NONTRANSITIONAL automatically converts to lowercase
+ * IDN2_NFC_INPUT converts to NFC before toASCII conversion
+ *
+ * Since IDN2_NONTRANSITIONAL implicitely does NFC conversion, we don't need
+ * the additional IDN2_NFC_INPUT. But just for the unlikely case that the linked
+ * library is not matching the headers when building and it doesn't support TR46,
+ * we provide IDN2_NFC_INPUT. */
+
+ err = idn2_lookup_u8((uint8_t *)hostname, (uint8_t **)&a_hostname, IDN2_NFC_INPUT | IDN2_NONTRANSITIONAL);
+#else
+ err = idn2_lookup_u8((uint8_t *)hostname, (uint8_t **)&a_hostname, IDN2_NFC_INPUT);
+#endif
+ if (err != IDN2_OK) {
+ fprintf(stderr, "Cannot convert %s to IDNA: %s\n", hostname,
+ idn2_strerror(err));
+ exit(1);
+ }
+#elif defined HAVE_LIBIDN
err = idna_to_ascii_8z(hostname, &a_hostname, IDNA_ALLOW_UNASSIGNED);
if (err != IDNA_SUCCESS) {
fprintf(stderr, "Cannot convert %s to IDNA: %s\n", hostname,