VirtualBox

source: vbox/trunk/src/libs/curl-7.83.1/lib/idn_win32.c@ 97138

最後變更 在這個檔案從97138是 95312,由 vboxsync 提交於 3 年 前

libs/{curl,libxml2}: OSE export fixes, bugref:8515

  • 屬性 svn:eol-style 設為 native
檔案大小: 3.8 KB
 
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 1998 - 2022, Daniel Stenberg, <[email protected]>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ***************************************************************************/
22
23 /*
24 * IDN conversions using Windows kernel32 and normaliz libraries.
25 */
26
27#include "curl_setup.h"
28
29#ifdef USE_WIN32_IDN
30
31#include "curl_multibyte.h"
32#include "curl_memory.h"
33#include "warnless.h"
34
35 /* The last #include file should be: */
36#include "memdebug.h"
37
38#ifdef WANT_IDN_PROTOTYPES
39# if defined(_SAL_VERSION)
40WINNORMALIZEAPI int WINAPI
41IdnToAscii(_In_ DWORD dwFlags,
42 _In_reads_(cchUnicodeChar) LPCWSTR lpUnicodeCharStr,
43 _In_ int cchUnicodeChar,
44 _Out_writes_opt_(cchASCIIChar) LPWSTR lpASCIICharStr,
45 _In_ int cchASCIIChar);
46WINNORMALIZEAPI int WINAPI
47IdnToUnicode(_In_ DWORD dwFlags,
48 _In_reads_(cchASCIIChar) LPCWSTR lpASCIICharStr,
49 _In_ int cchASCIIChar,
50 _Out_writes_opt_(cchUnicodeChar) LPWSTR lpUnicodeCharStr,
51 _In_ int cchUnicodeChar);
52# else
53WINBASEAPI int WINAPI IdnToAscii(DWORD dwFlags,
54 const WCHAR *lpUnicodeCharStr,
55 int cchUnicodeChar,
56 WCHAR *lpASCIICharStr,
57 int cchASCIIChar);
58WINBASEAPI int WINAPI IdnToUnicode(DWORD dwFlags,
59 const WCHAR *lpASCIICharStr,
60 int cchASCIIChar,
61 WCHAR *lpUnicodeCharStr,
62 int cchUnicodeChar);
63# endif
64#endif
65
66#define IDN_MAX_LENGTH 255
67
68bool curl_win32_idn_to_ascii(const char *in, char **out);
69bool curl_win32_ascii_to_idn(const char *in, char **out);
70
71bool curl_win32_idn_to_ascii(const char *in, char **out)
72{
73 bool success = FALSE;
74
75 wchar_t *in_w = curlx_convert_UTF8_to_wchar(in);
76 if(in_w) {
77 wchar_t punycode[IDN_MAX_LENGTH];
78 int chars = IdnToAscii(0, in_w, -1, punycode, IDN_MAX_LENGTH);
79 curlx_unicodefree(in_w);
80 if(chars) {
81 char *mstr = curlx_convert_wchar_to_UTF8(punycode);
82 if(mstr) {
83 *out = strdup(mstr);
84 curlx_unicodefree(mstr);
85 if(*out)
86 success = TRUE;
87 }
88 }
89 }
90
91 return success;
92}
93
94bool curl_win32_ascii_to_idn(const char *in, char **out)
95{
96 bool success = FALSE;
97
98 wchar_t *in_w = curlx_convert_UTF8_to_wchar(in);
99 if(in_w) {
100 size_t in_len = wcslen(in_w) + 1;
101 wchar_t unicode[IDN_MAX_LENGTH];
102 int chars = IdnToUnicode(0, in_w, curlx_uztosi(in_len),
103 unicode, IDN_MAX_LENGTH);
104 curlx_unicodefree(in_w);
105 if(chars) {
106 char *mstr = curlx_convert_wchar_to_UTF8(unicode);
107 if(mstr) {
108 *out = strdup(mstr);
109 curlx_unicodefree(mstr);
110 if(*out)
111 success = TRUE;
112 }
113 }
114 }
115
116 return success;
117}
118
119#endif /* USE_WIN32_IDN */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette