2022-12-14 21:49:59 +08:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2023-01-02 20:51:48 +08:00
|
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
2022-12-14 21:49:59 +08:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: curl
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IDN conversions
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "curl_setup.h"
|
|
|
|
#include "urldata.h"
|
|
|
|
#include "idn.h"
|
|
|
|
#include "sendf.h"
|
|
|
|
#include "curl_multibyte.h"
|
|
|
|
#include "warnless.h"
|
|
|
|
|
|
|
|
#ifdef USE_LIBIDN2
|
|
|
|
#include <idn2.h>
|
|
|
|
|
2023-11-22 00:54:49 +08:00
|
|
|
#if defined(_WIN32) && defined(UNICODE)
|
2022-12-14 21:49:59 +08:00
|
|
|
#define IDN2_LOOKUP(name, host, flags) \
|
|
|
|
idn2_lookup_u8((const uint8_t *)name, (uint8_t **)host, flags)
|
|
|
|
#else
|
|
|
|
#define IDN2_LOOKUP(name, host, flags) \
|
|
|
|
idn2_lookup_ul((const char *)name, (char **)host, flags)
|
|
|
|
#endif
|
|
|
|
#endif /* USE_LIBIDN2 */
|
|
|
|
|
|
|
|
/* The last 3 #include files should be in this order */
|
|
|
|
#include "curl_printf.h"
|
|
|
|
#include "curl_memory.h"
|
|
|
|
#include "memdebug.h"
|
|
|
|
|
2024-03-31 17:55:27 +08:00
|
|
|
/* for macOS and iOS targets */
|
|
|
|
#if defined(USE_APPLE_IDN)
|
|
|
|
#include <unicode/uidna.h>
|
2024-08-07 10:14:57 +08:00
|
|
|
#include <iconv.h>
|
|
|
|
#include <langinfo.h>
|
2024-03-31 17:55:27 +08:00
|
|
|
|
2024-07-17 00:40:13 +08:00
|
|
|
#define MAX_HOST_LENGTH 512
|
|
|
|
|
2024-08-07 10:14:57 +08:00
|
|
|
static CURLcode iconv_to_utf8(const char *in, size_t inlen,
|
|
|
|
char **out, size_t *outlen)
|
|
|
|
{
|
|
|
|
iconv_t cd = iconv_open("UTF-8", nl_langinfo(CODESET));
|
|
|
|
if(cd != (iconv_t)-1) {
|
|
|
|
size_t iconv_outlen = *outlen;
|
|
|
|
char *iconv_in = (char *)in;
|
|
|
|
size_t iconv_inlen = inlen;
|
|
|
|
size_t iconv_result = iconv(cd, &iconv_in, &iconv_inlen,
|
|
|
|
out, &iconv_outlen);
|
|
|
|
*outlen -= iconv_outlen;
|
|
|
|
iconv_close(cd);
|
|
|
|
if(iconv_result == (size_t)-1) {
|
|
|
|
if(errno == ENOMEM)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
else
|
|
|
|
return CURLE_URL_MALFORMAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(errno == ENOMEM)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
else
|
|
|
|
return CURLE_FAILED_INIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-31 17:55:27 +08:00
|
|
|
static CURLcode mac_idn_to_ascii(const char *in, char **out)
|
|
|
|
{
|
2024-07-17 00:40:13 +08:00
|
|
|
size_t inlen = strlen(in);
|
|
|
|
if(inlen < MAX_HOST_LENGTH) {
|
2024-08-07 10:14:57 +08:00
|
|
|
char iconv_buffer[MAX_HOST_LENGTH] = {0};
|
|
|
|
char *iconv_outptr = iconv_buffer;
|
|
|
|
size_t iconv_outlen = sizeof(iconv_buffer);
|
|
|
|
CURLcode iconv_result = iconv_to_utf8(in, inlen,
|
|
|
|
&iconv_outptr, &iconv_outlen);
|
|
|
|
if(!iconv_result) {
|
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
|
|
|
UIDNA* idna = uidna_openUTS46(
|
|
|
|
UIDNA_CHECK_BIDI|UIDNA_NONTRANSITIONAL_TO_ASCII, &err);
|
2024-07-17 00:40:13 +08:00
|
|
|
if(!U_FAILURE(err)) {
|
2024-08-07 10:14:57 +08:00
|
|
|
UIDNAInfo info = UIDNA_INFO_INITIALIZER;
|
|
|
|
char buffer[MAX_HOST_LENGTH] = {0};
|
|
|
|
(void)uidna_nameToASCII_UTF8(idna, iconv_buffer, (int)iconv_outlen,
|
|
|
|
buffer, sizeof(buffer) - 1, &info, &err);
|
|
|
|
uidna_close(idna);
|
2024-08-07 10:18:34 +08:00
|
|
|
if(!U_FAILURE(err) && !info.errors) {
|
2024-08-07 10:14:57 +08:00
|
|
|
*out = strdup(buffer);
|
|
|
|
if(*out)
|
|
|
|
return CURLE_OK;
|
|
|
|
else
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
2024-07-17 00:40:13 +08:00
|
|
|
}
|
2024-03-31 17:55:27 +08:00
|
|
|
}
|
2024-08-07 10:14:57 +08:00
|
|
|
else
|
|
|
|
return iconv_result;
|
2024-03-31 17:55:27 +08:00
|
|
|
}
|
2024-07-17 00:40:13 +08:00
|
|
|
return CURLE_URL_MALFORMAT;
|
2024-03-31 17:55:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static CURLcode mac_ascii_to_idn(const char *in, char **out)
|
|
|
|
{
|
2024-07-17 00:40:13 +08:00
|
|
|
size_t inlen = strlen(in);
|
|
|
|
if(inlen < MAX_HOST_LENGTH) {
|
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
|
|
|
UIDNA* idna = uidna_openUTS46(
|
|
|
|
UIDNA_CHECK_BIDI|UIDNA_NONTRANSITIONAL_TO_UNICODE, &err);
|
|
|
|
if(!U_FAILURE(err)) {
|
|
|
|
UIDNAInfo info = UIDNA_INFO_INITIALIZER;
|
|
|
|
char buffer[MAX_HOST_LENGTH] = {0};
|
|
|
|
(void)uidna_nameToUnicodeUTF8(idna, in, -1, buffer,
|
|
|
|
sizeof(buffer) - 1, &info, &err);
|
|
|
|
uidna_close(idna);
|
|
|
|
if(!U_FAILURE(err)) {
|
|
|
|
*out = strdup(buffer);
|
|
|
|
if(*out)
|
|
|
|
return CURLE_OK;
|
|
|
|
else
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
2024-03-31 17:55:27 +08:00
|
|
|
}
|
|
|
|
}
|
2024-07-17 00:40:13 +08:00
|
|
|
return CURLE_URL_MALFORMAT;
|
2024-03-31 17:55:27 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-12-14 21:49:59 +08:00
|
|
|
#ifdef USE_WIN32_IDN
|
|
|
|
/* using Windows kernel32 and normaliz libraries. */
|
|
|
|
|
configure: fix WinIDN builds targeting old Windows
1. GHA/windows: enable WinIDN in Linux cross-builds.
(to reveal the issue in CI.)
2. fix compiler warning when building with mingw-w64 supporting
WinIDN, while targeting pre-Vista Windows, with a `WINVER` set to
target Vista or newer. (Such was Ubuntu's mingw-w64 with the
classic-mingw-specific trick in point 3 of this PR.)
```
../../lib/idn.c:154:23: error: redundant redeclaration of ‘IdnToAscii’ [-Werror=redundant-decls]
154 | WINBASEAPI int WINAPI IdnToAscii(DWORD dwFlags,
| ^~~~~~~~~~
In file included from /usr/share/mingw-w64/include/windows.h:73,
from /usr/share/mingw-w64/include/winsock2.h:23,
from ../../lib/setup-win32.h:91,
from ../../lib/curl_setup.h:308,
from ../../lib/idn.c:29:
/usr/share/mingw-w64/include/winnls.h:1075:30: note: previous declaration of ‘IdnToAscii’ was here
1075 | WINNORMALIZEAPI int WINAPI IdnToAscii (DWORD dwFlags, LPCWSTR lpUnicodeCharStr, int cchUnicodeChar, LPWSTR lpASCIICharStr, int cchASCIIChar);
| ^~~~~~~~~~
[...same for IdnToUnicode...]
```
Ref: https://github.com/curl/curl/actions/runs/10542832783/job/29210098553#step:7:89
3. drop `WINVER` override for classic-mingw. curl no longer supports
building with classic-mingw.
Reverts 37f1c21cb9c809ec870803fc40e1ed2afd9534ac #7581
4. sync `if IdnToUnicode can be linked` detection snippet with the live
code in `lib/idn.c`. It fixes detection for the scenario in point 2.
5. delete unused `WINIDN_DIR` variable.
Bug: https://github.com/curl/curl/pull/12606#issuecomment-1885381038
Previous abandoned attempt: #12684
Reviewed-by: Jay Satiro
Closes #14680
2024-08-26 01:32:10 +08:00
|
|
|
#if (!defined(_WIN32_WINNT) || _WIN32_WINNT < 0x600) && \
|
|
|
|
(!defined(WINVER) || WINVER < 0x600)
|
2022-12-14 21:49:59 +08:00
|
|
|
WINBASEAPI int WINAPI IdnToAscii(DWORD dwFlags,
|
|
|
|
const WCHAR *lpUnicodeCharStr,
|
|
|
|
int cchUnicodeChar,
|
|
|
|
WCHAR *lpASCIICharStr,
|
|
|
|
int cchASCIIChar);
|
|
|
|
WINBASEAPI int WINAPI IdnToUnicode(DWORD dwFlags,
|
|
|
|
const WCHAR *lpASCIICharStr,
|
|
|
|
int cchASCIIChar,
|
|
|
|
WCHAR *lpUnicodeCharStr,
|
|
|
|
int cchUnicodeChar);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define IDN_MAX_LENGTH 255
|
|
|
|
|
2023-08-15 15:16:54 +08:00
|
|
|
static CURLcode win32_idn_to_ascii(const char *in, char **out)
|
2022-12-14 21:49:59 +08:00
|
|
|
{
|
|
|
|
wchar_t *in_w = curlx_convert_UTF8_to_wchar(in);
|
2023-08-15 15:16:54 +08:00
|
|
|
*out = NULL;
|
2022-12-14 21:49:59 +08:00
|
|
|
if(in_w) {
|
|
|
|
wchar_t punycode[IDN_MAX_LENGTH];
|
2023-08-11 15:41:28 +08:00
|
|
|
int chars = IdnToAscii(0, in_w, (int)(wcslen(in_w) + 1), punycode,
|
|
|
|
IDN_MAX_LENGTH);
|
2022-12-14 21:49:59 +08:00
|
|
|
curlx_unicodefree(in_w);
|
|
|
|
if(chars) {
|
|
|
|
char *mstr = curlx_convert_wchar_to_UTF8(punycode);
|
|
|
|
if(mstr) {
|
|
|
|
*out = strdup(mstr);
|
|
|
|
curlx_unicodefree(mstr);
|
2023-08-15 15:16:54 +08:00
|
|
|
if(!*out)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2022-12-14 21:49:59 +08:00
|
|
|
}
|
2023-08-15 15:16:54 +08:00
|
|
|
else
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2022-12-14 21:49:59 +08:00
|
|
|
}
|
2023-08-15 15:16:54 +08:00
|
|
|
else
|
|
|
|
return CURLE_URL_MALFORMAT;
|
2022-12-14 21:49:59 +08:00
|
|
|
}
|
2023-09-29 15:15:19 +08:00
|
|
|
else
|
|
|
|
return CURLE_URL_MALFORMAT;
|
2022-12-14 21:49:59 +08:00
|
|
|
|
2023-08-15 15:16:54 +08:00
|
|
|
return CURLE_OK;
|
2022-12-14 21:49:59 +08:00
|
|
|
}
|
|
|
|
|
2023-08-15 15:16:54 +08:00
|
|
|
static CURLcode win32_ascii_to_idn(const char *in, char **output)
|
2023-08-11 15:41:28 +08:00
|
|
|
{
|
|
|
|
char *out = NULL;
|
|
|
|
|
|
|
|
wchar_t *in_w = curlx_convert_UTF8_to_wchar(in);
|
|
|
|
if(in_w) {
|
|
|
|
WCHAR idn[IDN_MAX_LENGTH]; /* stores a UTF-16 string */
|
|
|
|
int chars = IdnToUnicode(0, in_w, (int)(wcslen(in_w) + 1), idn,
|
|
|
|
IDN_MAX_LENGTH);
|
|
|
|
if(chars) {
|
|
|
|
/* 'chars' is "the number of characters retrieved" */
|
|
|
|
char *mstr = curlx_convert_wchar_to_UTF8(idn);
|
|
|
|
if(mstr) {
|
|
|
|
out = strdup(mstr);
|
|
|
|
curlx_unicodefree(mstr);
|
2023-08-15 15:16:54 +08:00
|
|
|
if(!out)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2023-08-11 15:41:28 +08:00
|
|
|
}
|
|
|
|
}
|
2023-08-15 15:16:54 +08:00
|
|
|
else
|
|
|
|
return CURLE_URL_MALFORMAT;
|
2023-08-11 15:41:28 +08:00
|
|
|
}
|
2023-08-15 15:16:54 +08:00
|
|
|
else
|
|
|
|
return CURLE_URL_MALFORMAT;
|
|
|
|
*output = out;
|
|
|
|
return CURLE_OK;
|
2023-08-11 15:41:28 +08:00
|
|
|
}
|
|
|
|
|
2022-12-14 21:49:59 +08:00
|
|
|
#endif /* USE_WIN32_IDN */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helpers for IDNA conversions.
|
|
|
|
*/
|
|
|
|
bool Curl_is_ASCII_name(const char *hostname)
|
|
|
|
{
|
|
|
|
/* get an UNSIGNED local version of the pointer */
|
|
|
|
const unsigned char *ch = (const unsigned char *)hostname;
|
|
|
|
|
|
|
|
if(!hostname) /* bad input, consider it ASCII! */
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
while(*ch) {
|
|
|
|
if(*ch++ & 0x80)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_IDN
|
|
|
|
/*
|
|
|
|
* Curl_idn_decode() returns an allocated IDN decoded string if it was
|
|
|
|
* possible. NULL on error.
|
2023-08-15 15:16:54 +08:00
|
|
|
*
|
2024-07-01 22:47:21 +08:00
|
|
|
* CURLE_URL_MALFORMAT - the hostname could not be converted
|
2023-08-15 15:16:54 +08:00
|
|
|
* CURLE_OUT_OF_MEMORY - memory problem
|
|
|
|
*
|
2022-12-14 21:49:59 +08:00
|
|
|
*/
|
2023-08-15 15:16:54 +08:00
|
|
|
static CURLcode idn_decode(const char *input, char **output)
|
2022-12-14 21:49:59 +08:00
|
|
|
{
|
|
|
|
char *decoded = NULL;
|
2023-08-15 15:16:54 +08:00
|
|
|
CURLcode result = CURLE_OK;
|
2022-12-14 21:49:59 +08:00
|
|
|
#ifdef USE_LIBIDN2
|
|
|
|
if(idn2_check_version(IDN2_VERSION)) {
|
|
|
|
int flags = IDN2_NFC_INPUT
|
|
|
|
#if IDN2_VERSION_NUMBER >= 0x00140000
|
|
|
|
/* IDN2_NFC_INPUT: Normalize input string using normalization form C.
|
|
|
|
IDN2_NONTRANSITIONAL: Perform Unicode TR46 non-transitional
|
|
|
|
processing. */
|
|
|
|
| IDN2_NONTRANSITIONAL
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
int rc = IDN2_LOOKUP(input, &decoded, flags);
|
|
|
|
if(rc != IDN2_OK)
|
|
|
|
/* fallback to TR46 Transitional mode for better IDNA2003
|
|
|
|
compatibility */
|
|
|
|
rc = IDN2_LOOKUP(input, &decoded, IDN2_TRANSITIONAL);
|
|
|
|
if(rc != IDN2_OK)
|
2023-08-15 15:16:54 +08:00
|
|
|
result = CURLE_URL_MALFORMAT;
|
2022-12-14 21:49:59 +08:00
|
|
|
}
|
2023-09-20 17:10:16 +08:00
|
|
|
else
|
|
|
|
/* a too old libidn2 version */
|
|
|
|
result = CURLE_NOT_BUILT_IN;
|
2022-12-14 21:49:59 +08:00
|
|
|
#elif defined(USE_WIN32_IDN)
|
2023-08-15 15:16:54 +08:00
|
|
|
result = win32_idn_to_ascii(input, &decoded);
|
2024-03-31 17:55:27 +08:00
|
|
|
#elif defined(USE_APPLE_IDN)
|
|
|
|
result = mac_idn_to_ascii(input, &decoded);
|
2022-12-14 21:49:59 +08:00
|
|
|
#endif
|
2023-08-15 15:16:54 +08:00
|
|
|
if(!result)
|
|
|
|
*output = decoded;
|
|
|
|
return result;
|
2022-12-14 21:49:59 +08:00
|
|
|
}
|
|
|
|
|
2023-08-15 15:16:54 +08:00
|
|
|
static CURLcode idn_encode(const char *puny, char **output)
|
2023-08-11 15:41:28 +08:00
|
|
|
{
|
|
|
|
char *enc = NULL;
|
|
|
|
#ifdef USE_LIBIDN2
|
|
|
|
int rc = idn2_to_unicode_8z8z(puny, &enc, 0);
|
|
|
|
if(rc != IDNA_SUCCESS)
|
2023-08-15 15:16:54 +08:00
|
|
|
return rc == IDNA_MALLOC_ERROR ? CURLE_OUT_OF_MEMORY : CURLE_URL_MALFORMAT;
|
2023-08-11 15:41:28 +08:00
|
|
|
#elif defined(USE_WIN32_IDN)
|
2023-08-15 15:16:54 +08:00
|
|
|
CURLcode result = win32_ascii_to_idn(puny, &enc);
|
|
|
|
if(result)
|
|
|
|
return result;
|
2024-03-31 17:55:27 +08:00
|
|
|
#elif defined(USE_APPLE_IDN)
|
|
|
|
CURLcode result = mac_ascii_to_idn(puny, &enc);
|
|
|
|
if(result)
|
|
|
|
return result;
|
2023-08-11 15:41:28 +08:00
|
|
|
#endif
|
2023-08-15 15:16:54 +08:00
|
|
|
*output = enc;
|
|
|
|
return CURLE_OK;
|
2023-08-11 15:41:28 +08:00
|
|
|
}
|
|
|
|
|
2023-08-15 15:16:54 +08:00
|
|
|
CURLcode Curl_idn_decode(const char *input, char **output)
|
2022-12-26 17:58:37 +08:00
|
|
|
{
|
2023-08-15 15:16:54 +08:00
|
|
|
char *d = NULL;
|
|
|
|
CURLcode result = idn_decode(input, &d);
|
2022-12-26 17:58:37 +08:00
|
|
|
#ifdef USE_LIBIDN2
|
2023-08-15 15:16:54 +08:00
|
|
|
if(!result) {
|
2022-12-26 17:58:37 +08:00
|
|
|
char *c = strdup(d);
|
|
|
|
idn2_free(d);
|
2023-08-15 15:16:54 +08:00
|
|
|
if(c)
|
|
|
|
d = c;
|
|
|
|
else
|
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
2022-12-26 17:58:37 +08:00
|
|
|
}
|
|
|
|
#endif
|
2023-08-15 15:16:54 +08:00
|
|
|
if(!result)
|
|
|
|
*output = d;
|
|
|
|
return result;
|
2022-12-26 17:58:37 +08:00
|
|
|
}
|
|
|
|
|
2023-08-15 15:16:54 +08:00
|
|
|
CURLcode Curl_idn_encode(const char *puny, char **output)
|
2023-08-11 15:41:28 +08:00
|
|
|
{
|
2023-08-15 15:16:54 +08:00
|
|
|
char *d = NULL;
|
|
|
|
CURLcode result = idn_encode(puny, &d);
|
2023-08-11 15:41:28 +08:00
|
|
|
#ifdef USE_LIBIDN2
|
2023-08-15 15:16:54 +08:00
|
|
|
if(!result) {
|
2023-08-11 15:41:28 +08:00
|
|
|
char *c = strdup(d);
|
|
|
|
idn2_free(d);
|
2023-08-15 15:16:54 +08:00
|
|
|
if(c)
|
|
|
|
d = c;
|
|
|
|
else
|
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
2023-08-11 15:41:28 +08:00
|
|
|
}
|
|
|
|
#endif
|
2023-08-15 15:16:54 +08:00
|
|
|
if(!result)
|
|
|
|
*output = d;
|
|
|
|
return result;
|
2023-08-11 15:41:28 +08:00
|
|
|
}
|
|
|
|
|
2022-12-14 21:49:59 +08:00
|
|
|
/*
|
|
|
|
* Frees data allocated by idnconvert_hostname()
|
|
|
|
*/
|
|
|
|
void Curl_free_idnconverted_hostname(struct hostname *host)
|
|
|
|
{
|
2024-03-31 05:56:48 +08:00
|
|
|
Curl_safefree(host->encalloc);
|
2022-12-14 21:49:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* USE_IDN */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform any necessary IDN conversion of hostname
|
|
|
|
*/
|
|
|
|
CURLcode Curl_idnconvert_hostname(struct hostname *host)
|
|
|
|
{
|
2024-07-01 22:47:21 +08:00
|
|
|
/* set the name we use to display the hostname */
|
2022-12-14 21:49:59 +08:00
|
|
|
host->dispname = host->name;
|
|
|
|
|
|
|
|
#ifdef USE_IDN
|
|
|
|
/* Check name for non-ASCII and convert hostname if we can */
|
|
|
|
if(!Curl_is_ASCII_name(host->name)) {
|
2023-08-15 15:16:54 +08:00
|
|
|
char *decoded;
|
2024-03-31 05:56:48 +08:00
|
|
|
CURLcode result = Curl_idn_decode(host->name, &decoded);
|
|
|
|
if(result)
|
2023-08-15 15:16:54 +08:00
|
|
|
return result;
|
2024-03-31 05:56:48 +08:00
|
|
|
/* successful */
|
|
|
|
host->name = host->encalloc = decoded;
|
2022-12-14 21:49:59 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|