]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /* |
2 | ******************************************************************************* | |
3 | * | |
46f4442e | 4 | * Copyright (C) 2003-2007, International Business Machines |
b75a7d8f A |
5 | * Corporation and others. All Rights Reserved. |
6 | * | |
7 | ******************************************************************************* | |
8 | * file name: uidna.h | |
9 | * encoding: US-ASCII | |
10 | * tab size: 8 (not used) | |
11 | * indentation:4 | |
12 | * | |
13 | * created on: 2003feb1 | |
14 | * created by: Ram Viswanadha | |
15 | */ | |
16 | ||
17 | #ifndef __UIDNA_H__ | |
18 | #define __UIDNA_H__ | |
19 | ||
20 | #include "unicode/utypes.h" | |
21 | ||
22 | #if !UCONFIG_NO_IDNA | |
23 | ||
24 | #include "unicode/parseerr.h" | |
25 | ||
26 | /** | |
73c04bcf A |
27 | * \file |
28 | * \brief C API: Internationalized Domain Names in Applications Tranformation | |
29 | * | |
b75a7d8f A |
30 | * UIDNA API implements the IDNA protocol as defined in the IDNA RFC |
31 | * (http://www.ietf.org/rfc/rfc3490.txt). | |
32 | * The RFC defines 2 operations: ToASCII and ToUnicode. Domain labels | |
33 | * containing non-ASCII code points are required to be processed by | |
34 | * ToASCII operation before passing it to resolver libraries. Domain names | |
35 | * that are obtained from resolver libraries are required to be processed by | |
36 | * ToUnicode operation before displaying the domain name to the user. | |
37 | * IDNA requires that implementations process input strings with Nameprep | |
38 | * (http://www.ietf.org/rfc/rfc3491.txt), | |
39 | * which is a profile of Stringprep (http://www.ietf.org/rfc/rfc3454.txt), | |
40 | * and then with Punycode (http://www.ietf.org/rfc/rfc3492.txt). | |
41 | * Implementations of IDNA MUST fully implement Nameprep and Punycode; | |
42 | * neither Nameprep nor Punycode are optional. | |
43 | * The input and output of ToASCII and ToUnicode operations are Unicode | |
44 | * and are designed to be chainable, i.e., applying ToASCII or ToUnicode operations | |
45 | * multiple times to an input string will yield the same result as applying the operation | |
46 | * once. | |
47 | * ToUnicode(ToUnicode(ToUnicode...(ToUnicode(string)))) == ToUnicode(string) | |
48 | * ToASCII(ToASCII(ToASCII...(ToASCII(string))) == ToASCII(string). | |
374ca955 | 49 | * |
b75a7d8f A |
50 | */ |
51 | ||
52 | /** | |
53 | * Option to prohibit processing of unassigned codepoints in the input and | |
54 | * do not check if the input conforms to STD-3 ASCII rules. | |
55 | * | |
56 | * @see uidna_toASCII uidna_toUnicode | |
374ca955 | 57 | * @stable ICU 2.6 |
b75a7d8f A |
58 | */ |
59 | #define UIDNA_DEFAULT 0x0000 | |
60 | /** | |
61 | * Option to allow processing of unassigned codepoints in the input | |
62 | * | |
63 | * @see uidna_toASCII uidna_toUnicode | |
374ca955 | 64 | * @stable ICU 2.6 |
b75a7d8f A |
65 | */ |
66 | #define UIDNA_ALLOW_UNASSIGNED 0x0001 | |
67 | /** | |
68 | * Option to check if input conforms to STD-3 ASCII rules | |
69 | * | |
70 | * @see uidna_toASCII uidna_toUnicode | |
374ca955 | 71 | * @stable ICU 2.6 |
b75a7d8f A |
72 | */ |
73 | #define UIDNA_USE_STD3_RULES 0x0002 | |
374ca955 | 74 | |
b75a7d8f A |
75 | /** |
76 | * This function implements the ToASCII operation as defined in the IDNA RFC. | |
77 | * This operation is done on <b>single labels</b> before sending it to something that expects | |
78 | * ASCII names. A label is an individual part of a domain name. Labels are usually | |
79 | * separated by dots; e.g." "www.example.com" is composed of 3 labels | |
80 | * "www","example", and "com". | |
81 | * | |
82 | * | |
83 | * @param src Input UChar array containing label in Unicode. | |
84 | * @param srcLength Number of UChars in src, or -1 if NUL-terminated. | |
85 | * @param dest Output UChar array with ASCII (ACE encoded) label. | |
86 | * @param destCapacity Size of dest. | |
87 | * @param options A bit set of options: | |
88 | * | |
374ca955 A |
89 | * - UIDNA_DEFAULT Use default options, i.e., do not process unassigned code points |
90 | * and do not use STD3 ASCII rules | |
91 | * If unassigned code points are found the operation fails with | |
92 | * U_UNASSIGNED_ERROR error code. | |
b75a7d8f | 93 | * |
374ca955 A |
94 | * - UIDNA_ALLOW_UNASSIGNED Unassigned values can be converted to ASCII for query operations |
95 | * If this option is set, the unassigned code points are in the input | |
96 | * are treated as normal Unicode code points. | |
b75a7d8f | 97 | * |
374ca955 A |
98 | * - UIDNA_USE_STD3_RULES Use STD3 ASCII rules for host name syntax restrictions |
99 | * If this option is set and the input does not satisfy STD3 rules, | |
100 | * the operation will fail with U_IDNA_STD3_ASCII_RULES_ERROR | |
b75a7d8f A |
101 | * |
102 | * @param parseError Pointer to UParseError struct to receive information on position | |
103 | * of error if an error is encountered. Can be NULL. | |
104 | * @param status ICU in/out error code parameter. | |
105 | * U_INVALID_CHAR_FOUND if src contains | |
106 | * unmatched single surrogates. | |
107 | * U_INDEX_OUTOFBOUNDS_ERROR if src contains | |
108 | * too many code points. | |
109 | * U_BUFFER_OVERFLOW_ERROR if destCapacity is not enough | |
46f4442e A |
110 | * @return The length of the result string, if successful - or in case of a buffer overflow, |
111 | * in which case it will be greater than destCapacity. | |
374ca955 | 112 | * @stable ICU 2.6 |
b75a7d8f | 113 | */ |
374ca955 | 114 | U_STABLE int32_t U_EXPORT2 |
b75a7d8f A |
115 | uidna_toASCII(const UChar* src, int32_t srcLength, |
116 | UChar* dest, int32_t destCapacity, | |
117 | int32_t options, | |
118 | UParseError* parseError, | |
119 | UErrorCode* status); | |
120 | ||
121 | ||
122 | /** | |
123 | * This function implements the ToUnicode operation as defined in the IDNA RFC. | |
124 | * This operation is done on <b>single labels</b> before sending it to something that expects | |
125 | * Unicode names. A label is an individual part of a domain name. Labels are usually | |
126 | * separated by dots; for e.g." "www.example.com" is composed of 3 labels | |
127 | * "www","example", and "com". | |
128 | * | |
129 | * @param src Input UChar array containing ASCII (ACE encoded) label. | |
130 | * @param srcLength Number of UChars in src, or -1 if NUL-terminated. | |
131 | * @param dest Output Converted UChar array containing Unicode equivalent of label. | |
132 | * @param destCapacity Size of dest. | |
133 | * @param options A bit set of options: | |
134 | * | |
374ca955 A |
135 | * - UIDNA_DEFAULT Use default options, i.e., do not process unassigned code points |
136 | * and do not use STD3 ASCII rules | |
137 | * If unassigned code points are found the operation fails with | |
138 | * U_UNASSIGNED_ERROR error code. | |
b75a7d8f | 139 | * |
374ca955 A |
140 | * - UIDNA_ALLOW_UNASSIGNED Unassigned values can be converted to ASCII for query operations |
141 | * If this option is set, the unassigned code points are in the input | |
142 | * are treated as normal Unicode code points. <b> Note: </b> This option is | |
143 | * required on toUnicode operation because the RFC mandates | |
144 | * verification of decoded ACE input by applying toASCII and comparing | |
145 | * its output with source | |
b75a7d8f A |
146 | * |
147 | * | |
148 | * | |
374ca955 A |
149 | * - UIDNA_USE_STD3_RULES Use STD3 ASCII rules for host name syntax restrictions |
150 | * If this option is set and the input does not satisfy STD3 rules, | |
151 | * the operation will fail with U_IDNA_STD3_ASCII_RULES_ERROR | |
b75a7d8f A |
152 | * |
153 | * @param parseError Pointer to UParseError struct to receive information on position | |
154 | * of error if an error is encountered. Can be NULL. | |
155 | * @param status ICU in/out error code parameter. | |
156 | * U_INVALID_CHAR_FOUND if src contains | |
157 | * unmatched single surrogates. | |
158 | * U_INDEX_OUTOFBOUNDS_ERROR if src contains | |
159 | * too many code points. | |
160 | * U_BUFFER_OVERFLOW_ERROR if destCapacity is not enough | |
46f4442e A |
161 | * @return The length of the result string, if successful - or in case of a buffer overflow, |
162 | * in which case it will be greater than destCapacity. | |
374ca955 | 163 | * @stable ICU 2.6 |
b75a7d8f | 164 | */ |
374ca955 | 165 | U_STABLE int32_t U_EXPORT2 |
b75a7d8f A |
166 | uidna_toUnicode(const UChar* src, int32_t srcLength, |
167 | UChar* dest, int32_t destCapacity, | |
168 | int32_t options, | |
169 | UParseError* parseError, | |
170 | UErrorCode* status); | |
171 | ||
172 | ||
173 | /** | |
174 | * Convenience function that implements the IDNToASCII operation as defined in the IDNA RFC. | |
175 | * This operation is done on complete domain names, e.g: "www.example.com". | |
176 | * It is important to note that this operation can fail. If it fails, then the input | |
177 | * domain name cannot be used as an Internationalized Domain Name and the application | |
178 | * should have methods defined to deal with the failure. | |
179 | * | |
180 | * <b>Note:</b> IDNA RFC specifies that a conformant application should divide a domain name | |
181 | * into separate labels, decide whether to apply allowUnassigned and useSTD3ASCIIRules on each, | |
182 | * and then convert. This function does not offer that level of granularity. The options once | |
183 | * set will apply to all labels in the domain name | |
184 | * | |
185 | * @param src Input UChar array containing IDN in Unicode. | |
186 | * @param srcLength Number of UChars in src, or -1 if NUL-terminated. | |
187 | * @param dest Output UChar array with ASCII (ACE encoded) IDN. | |
188 | * @param destCapacity Size of dest. | |
189 | * @param options A bit set of options: | |
190 | * | |
374ca955 A |
191 | * - UIDNA_DEFAULT Use default options, i.e., do not process unassigned code points |
192 | * and do not use STD3 ASCII rules | |
193 | * If unassigned code points are found the operation fails with | |
194 | * U_UNASSIGNED_CODE_POINT_FOUND error code. | |
b75a7d8f | 195 | * |
374ca955 A |
196 | * - UIDNA_ALLOW_UNASSIGNED Unassigned values can be converted to ASCII for query operations |
197 | * If this option is set, the unassigned code points are in the input | |
198 | * are treated as normal Unicode code points. | |
b75a7d8f | 199 | * |
374ca955 A |
200 | * - UIDNA_USE_STD3_RULES Use STD3 ASCII rules for host name syntax restrictions |
201 | * If this option is set and the input does not satisfy STD3 rules, | |
202 | * the operation will fail with U_IDNA_STD3_ASCII_RULES_ERROR | |
b75a7d8f A |
203 | * |
204 | * @param parseError Pointer to UParseError struct to receive information on position | |
205 | * of error if an error is encountered. Can be NULL. | |
206 | * @param status ICU in/out error code parameter. | |
207 | * U_INVALID_CHAR_FOUND if src contains | |
208 | * unmatched single surrogates. | |
209 | * U_INDEX_OUTOFBOUNDS_ERROR if src contains | |
210 | * too many code points. | |
211 | * U_BUFFER_OVERFLOW_ERROR if destCapacity is not enough | |
46f4442e A |
212 | * @return The length of the result string, if successful - or in case of a buffer overflow, |
213 | * in which case it will be greater than destCapacity. | |
374ca955 | 214 | * @stable ICU 2.6 |
b75a7d8f | 215 | */ |
374ca955 | 216 | U_STABLE int32_t U_EXPORT2 |
b75a7d8f A |
217 | uidna_IDNToASCII( const UChar* src, int32_t srcLength, |
218 | UChar* dest, int32_t destCapacity, | |
219 | int32_t options, | |
220 | UParseError* parseError, | |
221 | UErrorCode* status); | |
222 | ||
223 | /** | |
224 | * Convenience function that implements the IDNToUnicode operation as defined in the IDNA RFC. | |
225 | * This operation is done on complete domain names, e.g: "www.example.com". | |
226 | * | |
227 | * <b>Note:</b> IDNA RFC specifies that a conformant application should divide a domain name | |
228 | * into separate labels, decide whether to apply allowUnassigned and useSTD3ASCIIRules on each, | |
229 | * and then convert. This function does not offer that level of granularity. The options once | |
230 | * set will apply to all labels in the domain name | |
231 | * | |
232 | * @param src Input UChar array containing IDN in ASCII (ACE encoded) form. | |
233 | * @param srcLength Number of UChars in src, or -1 if NUL-terminated. | |
234 | * @param dest Output UChar array containing Unicode equivalent of source IDN. | |
235 | * @param destCapacity Size of dest. | |
236 | * @param options A bit set of options: | |
237 | * | |
374ca955 A |
238 | * - UIDNA_DEFAULT Use default options, i.e., do not process unassigned code points |
239 | * and do not use STD3 ASCII rules | |
240 | * If unassigned code points are found the operation fails with | |
241 | * U_UNASSIGNED_CODE_POINT_FOUND error code. | |
b75a7d8f | 242 | * |
374ca955 A |
243 | * - UIDNA_ALLOW_UNASSIGNED Unassigned values can be converted to ASCII for query operations |
244 | * If this option is set, the unassigned code points are in the input | |
245 | * are treated as normal Unicode code points. | |
b75a7d8f | 246 | * |
374ca955 A |
247 | * - UIDNA_USE_STD3_RULES Use STD3 ASCII rules for host name syntax restrictions |
248 | * If this option is set and the input does not satisfy STD3 rules, | |
249 | * the operation will fail with U_IDNA_STD3_ASCII_RULES_ERROR | |
b75a7d8f A |
250 | * |
251 | * @param parseError Pointer to UParseError struct to receive information on position | |
252 | * of error if an error is encountered. Can be NULL. | |
253 | * @param status ICU in/out error code parameter. | |
254 | * U_INVALID_CHAR_FOUND if src contains | |
255 | * unmatched single surrogates. | |
256 | * U_INDEX_OUTOFBOUNDS_ERROR if src contains | |
257 | * too many code points. | |
258 | * U_BUFFER_OVERFLOW_ERROR if destCapacity is not enough | |
46f4442e A |
259 | * @return The length of the result string, if successful - or in case of a buffer overflow, |
260 | * in which case it will be greater than destCapacity. | |
374ca955 | 261 | * @stable ICU 2.6 |
b75a7d8f | 262 | */ |
374ca955 | 263 | U_STABLE int32_t U_EXPORT2 |
b75a7d8f A |
264 | uidna_IDNToUnicode( const UChar* src, int32_t srcLength, |
265 | UChar* dest, int32_t destCapacity, | |
266 | int32_t options, | |
267 | UParseError* parseError, | |
268 | UErrorCode* status); | |
269 | ||
270 | /** | |
374ca955 | 271 | * Compare two IDN strings for equivalence. |
b75a7d8f A |
272 | * This function splits the domain names into labels and compares them. |
273 | * According to IDN RFC, whenever two labels are compared, they are | |
274 | * considered equal if and only if their ASCII forms (obtained by | |
275 | * applying toASCII) match using an case-insensitive ASCII comparison. | |
276 | * Two domain names are considered a match if and only if all labels | |
277 | * match regardless of whether label separators match. | |
278 | * | |
279 | * @param s1 First source string. | |
280 | * @param length1 Length of first source string, or -1 if NUL-terminated. | |
281 | * | |
282 | * @param s2 Second source string. | |
283 | * @param length2 Length of second source string, or -1 if NUL-terminated. | |
284 | * @param options A bit set of options: | |
285 | * | |
374ca955 A |
286 | * - UIDNA_DEFAULT Use default options, i.e., do not process unassigned code points |
287 | * and do not use STD3 ASCII rules | |
288 | * If unassigned code points are found the operation fails with | |
289 | * U_UNASSIGNED_CODE_POINT_FOUND error code. | |
b75a7d8f | 290 | * |
374ca955 A |
291 | * - UIDNA_ALLOW_UNASSIGNED Unassigned values can be converted to ASCII for query operations |
292 | * If this option is set, the unassigned code points are in the input | |
293 | * are treated as normal Unicode code points. | |
b75a7d8f | 294 | * |
374ca955 A |
295 | * - UIDNA_USE_STD3_RULES Use STD3 ASCII rules for host name syntax restrictions |
296 | * If this option is set and the input does not satisfy STD3 rules, | |
297 | * the operation will fail with U_IDNA_STD3_ASCII_RULES_ERROR | |
b75a7d8f A |
298 | * |
299 | * @param status ICU error code in/out parameter. | |
300 | * Must fulfill U_SUCCESS before the function call. | |
301 | * @return <0 or 0 or >0 as usual for string comparisons | |
374ca955 | 302 | * @stable ICU 2.6 |
b75a7d8f | 303 | */ |
374ca955 | 304 | U_STABLE int32_t U_EXPORT2 |
b75a7d8f A |
305 | uidna_compare( const UChar *s1, int32_t length1, |
306 | const UChar *s2, int32_t length2, | |
307 | int32_t options, | |
308 | UErrorCode* status); | |
309 | ||
310 | #endif /* #if !UCONFIG_NO_IDNA */ | |
311 | ||
312 | #endif |