Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "curl_setup.h"
00028
00029 #ifdef USE_WIN32_IDN
00030
00031 #include "curl_multibyte.h"
00032 #include "curl_memory.h"
00033 #include "warnless.h"
00034
00035
00036 #include "memdebug.h"
00037
00038 #ifdef WANT_IDN_PROTOTYPES
00039 # if defined(_SAL_VERSION)
00040 WINNORMALIZEAPI int WINAPI
00041 IdnToAscii(_In_ DWORD dwFlags,
00042 _In_reads_(cchUnicodeChar) LPCWSTR lpUnicodeCharStr,
00043 _In_ int cchUnicodeChar,
00044 _Out_writes_opt_(cchASCIIChar) LPWSTR lpASCIICharStr,
00045 _In_ int cchASCIIChar);
00046 WINNORMALIZEAPI int WINAPI
00047 IdnToUnicode(_In_ DWORD dwFlags,
00048 _In_reads_(cchASCIIChar) LPCWSTR lpASCIICharStr,
00049 _In_ int cchASCIIChar,
00050 _Out_writes_opt_(cchUnicodeChar) LPWSTR lpUnicodeCharStr,
00051 _In_ int cchUnicodeChar);
00052 # else
00053 WINBASEAPI int WINAPI IdnToAscii(DWORD dwFlags,
00054 const WCHAR *lpUnicodeCharStr,
00055 int cchUnicodeChar,
00056 WCHAR *lpASCIICharStr,
00057 int cchASCIIChar);
00058 WINBASEAPI int WINAPI IdnToUnicode(DWORD dwFlags,
00059 const WCHAR *lpASCIICharStr,
00060 int cchASCIIChar,
00061 WCHAR *lpUnicodeCharStr,
00062 int cchUnicodeChar);
00063 # endif
00064 #endif
00065
00066 #define IDN_MAX_LENGTH 255
00067
00068 bool curl_win32_idn_to_ascii(const char *in, char **out);
00069 bool curl_win32_ascii_to_idn(const char *in, char **out);
00070
00071 bool curl_win32_idn_to_ascii(const char *in, char **out)
00072 {
00073 bool success = FALSE;
00074
00075 wchar_t *in_w = Curl_convert_UTF8_to_wchar(in);
00076 if(in_w) {
00077 wchar_t punycode[IDN_MAX_LENGTH];
00078 int chars = IdnToAscii(0, in_w, -1, punycode, IDN_MAX_LENGTH);
00079 free(in_w);
00080 if(chars) {
00081 *out = Curl_convert_wchar_to_UTF8(punycode);
00082 if(*out)
00083 success = TRUE;
00084 }
00085 }
00086
00087 return success;
00088 }
00089
00090 bool curl_win32_ascii_to_idn(const char *in, char **out)
00091 {
00092 bool success = FALSE;
00093
00094 wchar_t *in_w = Curl_convert_UTF8_to_wchar(in);
00095 if(in_w) {
00096 size_t in_len = wcslen(in_w) + 1;
00097 wchar_t unicode[IDN_MAX_LENGTH];
00098 int chars = IdnToUnicode(0, in_w, curlx_uztosi(in_len),
00099 unicode, IDN_MAX_LENGTH);
00100 free(in_w);
00101 if(chars) {
00102 *out = Curl_convert_wchar_to_UTF8(unicode);
00103 if(*out)
00104 success = TRUE;
00105 }
00106 }
00107
00108 return success;
00109 }
00110
00111 #endif