summaryrefslogtreecommitdiff
path: root/lib/idn.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2022-12-26 10:58:37 +0100
committerDaniel Stenberg <daniel@haxx.se>2022-12-26 23:29:23 +0100
commit901392cbb7939f43b7e7ed2b39135b45416a2714 (patch)
treefd74a1a6370ba56fcd76cd15cb052d352fbcb076 /lib/idn.c
parentcf174810db32c362775349e9afe5543c0e9cc18b (diff)
downloadcurl-901392cbb7939f43b7e7ed2b39135b45416a2714.tar.gz
urlapi: add CURLU_PUNYCODE
Allows curl_url_get() get the punycode version of host names for the host name and URL parts. Extend test 1560 to verify. Closes #10109
Diffstat (limited to 'lib/idn.c')
-rw-r--r--lib/idn.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/lib/idn.c b/lib/idn.c
index 6255221ae..758900bdd 100644
--- a/lib/idn.c
+++ b/lib/idn.c
@@ -116,7 +116,7 @@ bool Curl_is_ASCII_name(const char *hostname)
* Curl_idn_decode() returns an allocated IDN decoded string if it was
* possible. NULL on error.
*/
-static char *Curl_idn_decode(const char *input)
+static char *idn_decode(const char *input)
{
char *decoded = NULL;
#ifdef USE_LIBIDN2
@@ -144,24 +144,29 @@ static char *Curl_idn_decode(const char *input)
return decoded;
}
+char *Curl_idn_decode(const char *input)
+{
+ char *d = idn_decode(input);
+#ifdef USE_LIBIDN2
+ if(d) {
+ char *c = strdup(d);
+ idn2_free(d);
+ d = c;
+ }
+#endif
+ return d;
+}
+
/*
* Frees data allocated by idnconvert_hostname()
*/
void Curl_free_idnconverted_hostname(struct hostname *host)
{
-#if defined(USE_LIBIDN2)
if(host->encalloc) {
- idn2_free(host->encalloc); /* must be freed with idn2_free() since this was
- allocated by libidn */
+ /* must be freed with idn2_free() if allocated by libidn */
+ Curl_idn_free(host->encalloc);
host->encalloc = NULL;
}
-#elif defined(USE_WIN32_IDN)
- free(host->encalloc); /* must be freed with free() since this was
- allocated by Curl_win32_idn_to_ascii */
- host->encalloc = NULL;
-#else
- (void)host;
-#endif
}
#endif /* USE_IDN */
@@ -177,7 +182,7 @@ CURLcode Curl_idnconvert_hostname(struct hostname *host)
#ifdef USE_IDN
/* Check name for non-ASCII and convert hostname if we can */
if(!Curl_is_ASCII_name(host->name)) {
- char *decoded = Curl_idn_decode(host->name);
+ char *decoded = idn_decode(host->name);
if(decoded) {
/* successful */
host->encalloc = decoded;
@@ -190,4 +195,3 @@ CURLcode Curl_idnconvert_hostname(struct hostname *host)
#endif
return CURLE_OK;
}
-