Use icu library for IDN feature 98/176298/1
authorSeonah Moon <seonah1.moon@samsung.com>
Wed, 16 Aug 2017 09:21:40 +0000 (18:21 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Wed, 18 Apr 2018 07:21:53 +0000 (16:21 +0900)
Change-Id: I13eaf3ca85d8b516dbc091acae9646e705a75f5e

lib/url.c
packaging/curl.spec

index 945d4e3..03c2057 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -63,6 +63,8 @@
 #elif defined(USE_WIN32_IDN)
 /* prototype for curl_win32_idn_to_ascii() */
 bool curl_win32_idn_to_ascii(const char *in, char **out);
+#elif defined(USE_ICU_IDNA)
+#include <unicode/uidna.h>
 #endif  /* USE_LIBIDN2 */
 
 #include "urldata.h"
@@ -125,6 +127,10 @@ bool curl_win32_idn_to_ascii(const char *in, char **out);
 #include "curl_memory.h"
 #include "memdebug.h"
 
+#if defined(USE_ICU_IDNA)
+#define MAX_DOMAIN_NAME_LEN 256
+#endif  /* USE_ICU_IDNA */
+
 static void conn_free(struct connectdata *conn);
 static void free_fixed_hostname(struct hostname *host);
 static void signalPipeClose(struct curl_llist *pipeline, bool pipe_broke);
@@ -1731,6 +1737,23 @@ static CURLcode fix_hostname(struct connectdata *conn, struct hostname *host)
     else {
       failf(data, "Failed to convert %s to ACE;\n", host->name);
       return CURLE_URL_MALFORMAT;
+#elif defined(USE_ICU_IDNA)
+    char *ace_hostname = malloc(MAX_DOMAIN_NAME_LEN * sizeof(char));
+    UErrorCode errorCode = U_ZERO_ERROR;
+    UIDNAInfo info = UIDNA_INFO_INITIALIZER;
+    UIDNA *uts46 =
+      uidna_openUTS46(UIDNA_USE_STD3_RULES|UIDNA_NONTRANSITIONAL_TO_UNICODE,
+      &errorCode);
+    int32_t length = uidna_nameToASCII_UTF8(uts46,
+      host->name, strlen(host->name),
+      ace_hostname, MAX_DOMAIN_NAME_LEN, &info, &errorCode);
+    uidna_close(uts46);
+
+    if(errorCode != U_ZERO_ERROR || info.errors || length < 1)
+      infof(data, "Failed to convert %s to ACE;\n", host->name);
+    else {
+      host->encalloc = ace_hostname;
+      host->name = host->encalloc;
     }
 #else
     infof(data, "IDN support not present, can't parse Unicode domains\n");
@@ -1763,6 +1786,9 @@ static void free_fixed_hostname(struct hostname *host)
   free(host->encalloc); /* must be freed with free() since this was
                            allocated by curl_win32_idn_to_ascii */
   host->encalloc = NULL;
+#elif defined(USE_ICU_IDNA)
+  free(host->encalloc);
+  host->encalloc = NULL;
 #else
   (void)host;
 #endif
index 1230c20..627c279 100644 (file)
@@ -9,6 +9,7 @@ URL:        http://curl.haxx.se/
 Source0:    %{name}-%{version}.tar.gz
 Source1001:     %{name}.manifest
 
+BuildRequires:  pkgconfig(icu-uc)
 BuildRequires:  pkgconfig(openssl)
 BuildRequires:  pkgconfig(zlib)
 BuildRequires:  pkgconfig(libcares)
@@ -68,6 +69,7 @@ CFLAGS+=" -DTIZEN_TV_EXT"
 %endif
 --with-ca-path==/etc/ssl/certs \
 --with-ca-bundle=/etc/ssl/ca-bundle.pem \
+--with-icu-uc \
 --with-lber-lib=lber \
 --enable-manual --enable-versioned-symbols --enable-ares --enable-debug --enable-curldebug \
 --disable-static \