39{
40 enum {
41 UNASSIGNED = 0x1,
42 PROHIBITED = 0x2,
43 BIDI_RAL = 0x4,
44 BIDI_L = 0x8
45 };
46
51 WCHAR buf[64], *map_str, norm_str[64], ch;
52 DWORD i, map_len, norm_len,
mask, label_start, label_end,
out = 0;
53 BOOL have_bidi_ral, prohibit_bidi_ral, ascii_only;
54
55 DPRINT(
"%x %p %d %p %d\n",
dwFlags, lpUnicodeCharStr, cchUnicodeChar,
56 lpNameprepCharStr, cchNameprepChar);
57
58 if(
dwFlags & ~(IDN_ALLOW_UNASSIGNED|IDN_USE_STD3_ASCII_RULES)) {
60 return 0;
61 }
62
63 if(!lpUnicodeCharStr || cchUnicodeChar<-1) {
65 return 0;
66 }
67
68 if(cchUnicodeChar == -1)
70 if(!cchUnicodeChar || (cchUnicodeChar==1 && lpUnicodeCharStr[0]==0)) {
72 return 0;
73 }
74
75 for(label_start=0; label_start<(
UINT)cchUnicodeChar;) {
77 for(
i=label_start;
i<(
UINT)cchUnicodeChar;
i++) {
78 ch = lpUnicodeCharStr[
i];
79
80 if(
i!=cchUnicodeChar-1 && !ch) {
82 return 0;
83 }
84
85 if(!ch || ch=='.' || ch==0x3002 || ch==0xff0e || ch==0xff61)
86 break;
87
88 if(ch > 0x7f) {
90 continue;
91 }
92
93 if((
dwFlags&IDN_USE_STD3_ASCII_RULES) == 0)
94 continue;
95 if((ch>='a' && ch<='z') || (ch>='A' && ch<='Z')
96 || (ch>='0' && ch<='9') || ch=='-')
97 continue;
98
100 return 0;
101 }
103
104 if(label_start==label_end && ch) {
106 return 0;
107 }
108
109 if((
dwFlags&IDN_USE_STD3_ASCII_RULES) && (lpUnicodeCharStr[label_start]==
'-' ||
110 lpUnicodeCharStr[label_end-1]=='-')) {
112 return 0;
113 }
114
115 if(ascii_only) {
116
117 if(label_end-label_start > 63) {
119 return 0;
120 }
121 if(label_end < (
UINT)cchUnicodeChar)
122 label_end++;
123
124 if(!lpNameprepCharStr) {
125 out += label_end-label_start;
126 }
else if(
out+label_end-label_start <= (
UINT)cchNameprepChar) {
127 memcpy(lpNameprepCharStr+
out, lpUnicodeCharStr+label_start,
128 (label_end-label_start)*
sizeof(
WCHAR));
129 if(lpUnicodeCharStr[label_end-1] > 0x7f)
130 lpNameprepCharStr[
out+label_end-label_start-1] =
'.';
131 out += label_end-label_start;
132 }else {
134 return 0;
135 }
136
137 label_start = label_end;
138 continue;
139 }
140
141 map_len = 0;
142 for(
i=label_start;
i<label_end;
i++) {
143 ch = lpUnicodeCharStr[
i];
146
147 if(!
ptr[0]) map_len++;
148 else if(!
ptr[1]) map_len++;
149 else if(!
ptr[2]) map_len += 2;
150 else if(
ptr[0]!=0xffff ||
ptr[1]!=0xffff ||
ptr[2]!=0xffff) map_len += 3;
151 }
152 if(map_len*
sizeof(
WCHAR) >
sizeof(
buf)) {
154 if(!map_str) {
156 return 0;
157 }
158 }else {
160 }
161 map_len = 0;
162 for(
i=label_start;
i<label_end;
i++) {
163 ch = lpUnicodeCharStr[
i];
166
168 map_str[map_len++] = ch;
170 map_str[map_len++] =
ptr[0];
172 map_str[map_len++] =
ptr[0];
173 map_str[map_len++] =
ptr[1];
174 }
else if(
ptr[0]!=0xffff ||
ptr[1]!=0xffff ||
ptr[2]!=0xffff) {
175 map_str[map_len++] =
ptr[0];
176 map_str[map_len++] =
ptr[1];
177 map_str[map_len++] =
ptr[2];
178 }
179 }
180
182 norm_str,
sizeof(norm_str)/
sizeof(
WCHAR)-1);
185 if(!norm_len) {
188 return 0;
189 }
190
191 if(label_end < (
UINT)cchUnicodeChar) {
192 norm_str[norm_len++] = lpUnicodeCharStr[label_end] ? '.' : 0;
193 label_end++;
194 }
195
196 if(!lpNameprepCharStr) {
198 }
else if(
out+norm_len <= (
UINT)cchNameprepChar) {
201 }else {
203 return 0;
204 }
205
206 have_bidi_ral = prohibit_bidi_ral =
FALSE;
208 if((
dwFlags&IDN_ALLOW_UNASSIGNED) == 0)
210 for(
i=0;
i<norm_len;
i++) {
213
217 return 0;
218 }
219
221 have_bidi_ral =
TRUE;
223 prohibit_bidi_ral =
TRUE;
224 }
225
226 if(have_bidi_ral) {
227 ch = norm_str[0];
229 if((
flags & BIDI_RAL) == 0)
230 prohibit_bidi_ral =
TRUE;
231
232 ch = norm_str[norm_len-1];
234 if((
flags & BIDI_RAL) == 0)
235 prohibit_bidi_ral =
TRUE;
236 }
237
238 if(have_bidi_ral && prohibit_bidi_ral) {
240 return 0;
241 }
242
243 label_start = label_end;
244 }
245
247}
static unsigned short get_table_entry(const unsigned short *table, WCHAR ch)
#define ERROR_INVALID_PARAMETER
INT WINAPI FoldStringW(DWORD dwFlags, LPCWSTR src, INT srclen, LPWSTR dst, INT dstlen)
GLenum GLuint GLenum GLsizei const GLchar * buf
const unsigned short nameprep_char_type[4432]
const unsigned short nameprep_mapping[5856]
DWORD WINAPI GetLastError(void)
#define ERROR_NO_UNICODE_TRANSLATION
#define ERROR_INVALID_FLAGS