2010-12-28 13:55:00 -05:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2016-03-10 16:52:09 -05:00
|
|
|
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2010-12-28 13:55:00 -05:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2016-02-02 18:19:02 -05:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2010-12-28 13:55:00 -05:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2011-07-26 11:23:27 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* IDN conversions using Windows kernel32 and normaliz libraries.
|
|
|
|
*/
|
|
|
|
|
2013-01-06 13:06:49 -05:00
|
|
|
#include "curl_setup.h"
|
2011-07-26 11:23:27 -04:00
|
|
|
|
|
|
|
#ifdef USE_WIN32_IDN
|
|
|
|
|
2012-06-15 12:05:11 -04:00
|
|
|
#include "curl_multibyte.h"
|
2012-11-16 18:59:42 -05:00
|
|
|
#include "curl_memory.h"
|
2016-03-10 16:52:09 -05:00
|
|
|
#include "warnless.h"
|
2016-03-10 17:32:45 -05:00
|
|
|
|
2016-03-10 16:52:09 -05:00
|
|
|
/* The last #include file should be: */
|
2013-01-03 20:50:28 -05:00
|
|
|
#include "memdebug.h"
|
2012-11-16 18:59:42 -05:00
|
|
|
|
2011-04-26 21:45:18 -04:00
|
|
|
#ifdef WANT_IDN_PROTOTYPES
|
2014-12-14 16:16:23 -05:00
|
|
|
# if defined(_SAL_VERSION)
|
|
|
|
WINNORMALIZEAPI int WINAPI
|
|
|
|
IdnToAscii(_In_ DWORD dwFlags,
|
|
|
|
_In_reads_(cchUnicodeChar) LPCWSTR lpUnicodeCharStr,
|
|
|
|
_In_ int cchUnicodeChar,
|
|
|
|
_Out_writes_opt_(cchASCIIChar) LPWSTR lpASCIICharStr,
|
|
|
|
_In_ int cchASCIIChar);
|
|
|
|
WINNORMALIZEAPI int WINAPI
|
|
|
|
IdnToUnicode(_In_ DWORD dwFlags,
|
|
|
|
_In_reads_(cchASCIIChar) LPCWSTR lpASCIICharStr,
|
|
|
|
_In_ int cchASCIIChar,
|
|
|
|
_Out_writes_opt_(cchUnicodeChar) LPWSTR lpUnicodeCharStr,
|
|
|
|
_In_ int cchUnicodeChar);
|
|
|
|
# else
|
|
|
|
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
|
2011-04-26 21:45:18 -04:00
|
|
|
#endif
|
|
|
|
|
2010-12-28 13:55:00 -05:00
|
|
|
#define IDN_MAX_LENGTH 255
|
|
|
|
|
2016-03-11 02:24:39 -05:00
|
|
|
bool curl_win32_idn_to_ascii(const char *in, char **out);
|
|
|
|
bool curl_win32_ascii_to_idn(const char *in, char **out);
|
2012-07-26 21:27:51 -04:00
|
|
|
|
2016-03-11 02:24:39 -05:00
|
|
|
bool curl_win32_idn_to_ascii(const char *in, char **out)
|
2010-12-28 13:55:00 -05:00
|
|
|
{
|
2016-03-11 02:24:39 -05:00
|
|
|
bool success = FALSE;
|
|
|
|
|
2012-06-15 12:05:11 -04:00
|
|
|
wchar_t *in_w = Curl_convert_UTF8_to_wchar(in);
|
2011-04-20 09:17:42 -04:00
|
|
|
if(in_w) {
|
2010-12-28 13:55:00 -05:00
|
|
|
wchar_t punycode[IDN_MAX_LENGTH];
|
2016-02-05 15:15:43 -05:00
|
|
|
int chars = IdnToAscii(0, in_w, -1, punycode, IDN_MAX_LENGTH);
|
2010-12-28 13:55:00 -05:00
|
|
|
free(in_w);
|
2016-02-05 15:15:43 -05:00
|
|
|
if(chars) {
|
|
|
|
*out = Curl_convert_wchar_to_UTF8(punycode);
|
|
|
|
if(*out)
|
2016-03-11 02:24:39 -05:00
|
|
|
success = TRUE;
|
2016-02-05 15:15:43 -05:00
|
|
|
}
|
2010-12-28 13:55:00 -05:00
|
|
|
}
|
2016-03-11 02:24:39 -05:00
|
|
|
|
|
|
|
return success;
|
2010-12-28 13:55:00 -05:00
|
|
|
}
|
|
|
|
|
2016-03-11 02:24:39 -05:00
|
|
|
bool curl_win32_ascii_to_idn(const char *in, char **out)
|
2010-12-28 13:55:00 -05:00
|
|
|
{
|
2016-03-11 02:24:39 -05:00
|
|
|
bool success = FALSE;
|
|
|
|
|
2016-02-05 15:15:43 -05:00
|
|
|
wchar_t *in_w = Curl_convert_UTF8_to_wchar(in);
|
|
|
|
if(in_w) {
|
2016-03-10 16:52:09 -05:00
|
|
|
size_t in_len = wcslen(in_w) + 1;
|
2016-02-05 15:15:43 -05:00
|
|
|
wchar_t unicode[IDN_MAX_LENGTH];
|
2016-03-10 16:52:09 -05:00
|
|
|
int chars = IdnToUnicode(0, in_w, curlx_uztosi(in_len),
|
|
|
|
unicode, IDN_MAX_LENGTH);
|
2016-02-05 15:15:43 -05:00
|
|
|
free(in_w);
|
|
|
|
if(chars) {
|
|
|
|
*out = Curl_convert_wchar_to_UTF8(unicode);
|
|
|
|
if(*out)
|
2016-03-11 02:24:39 -05:00
|
|
|
success = TRUE;
|
2010-12-28 13:55:00 -05:00
|
|
|
}
|
|
|
|
}
|
2016-03-11 02:24:39 -05:00
|
|
|
|
|
|
|
return success;
|
2010-12-28 13:55:00 -05:00
|
|
|
}
|
2011-07-26 11:23:27 -04:00
|
|
|
|
|
|
|
#endif /* USE_WIN32_IDN */
|