Copy manual from right place.
[libidn.git] / profiles.c
blob4e7c6560cc71f6104cf78cda190e4be437fb5b09
1 /* profiles.c Definitions of stringprep profiles.
2 * Copyright (C) 2002, 2003 Simon Josefsson
4 * This file is part of GNU Libidn.
6 * GNU Libidn is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * GNU Libidn is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with GNU Libidn; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "internal.h"
24 Stringprep_profiles stringprep_profiles[] = {
25 {"generic", stringprep_generic}
27 {"Nameprep", stringprep_nameprep}
29 {"KRBprep", stringprep_kerberos5}
31 {"Nodeprep", stringprep_xmpp_nodeprep}
33 {"Resourceprep", stringprep_xmpp_resourceprep}
35 {"plain", stringprep_plain}
37 {"SASLprep", stringprep_saslprep}
39 {"ISCSIprep", stringprep_iscsi}
41 {NULL, NULL}
44 Stringprep_profile stringprep_generic[] = {
45 /* 1) Map -- For each character in the input, check if it has a
46 mapping and, if so, replace it with its mapping. This is
47 described in section 3. */
49 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_1, "B.1"}
51 {STRINGPREP_MAP_TABLE, ~STRINGPREP_NO_NFKC, stringprep_generic_B_2, "B.2"}
53 {STRINGPREP_MAP_TABLE, STRINGPREP_NO_NFKC, stringprep_generic_B_3, "B.3"}
56 /* 2) Normalize -- Possibly normalize the result of step 1 using
57 Unicode normalization. This is described in section 4. */
59 {STRINGPREP_NFKC, ~STRINGPREP_NO_NFKC, 0, "NFKC"}
62 /* 3) Prohibit -- Check for any characters that are not allowed in
63 the output. If any are found, return an error. This is
64 described in section 5. */
66 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_1_1, "C.1.1"}
68 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_1_2, "C.1.2"}
70 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_1, "C.2.1"}
72 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_2, "C.2.2"}
74 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_3, "C.3"}
76 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_4, "C.4"}
78 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_5, "C.5"}
80 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_6, "C.6"}
82 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_7, "C.7"}
84 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
86 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_9, "C.9"}
89 /* 4) Check bidi -- Possibly check for right-to-left characters, and
90 if any are found, make sure that the whole string satisfies
91 the requirements for bidirectional strings. If the string does
92 not satisfy the requirements for bidirectional strings, return
93 an error. This is described in section 6. */
95 {STRINGPREP_BIDI, ~STRINGPREP_NO_BIDI, 0, "BIDI"}
97 {STRINGPREP_BIDI_PROHIBIT_TABLE, ~STRINGPREP_NO_BIDI,
98 stringprep_generic_C_8, "C.8"}
100 {STRINGPREP_BIDI_RAL_TABLE, ~STRINGPREP_NO_BIDI, stringprep_generic_D_1,
101 "D.1"}
103 {STRINGPREP_BIDI_L_TABLE, ~STRINGPREP_NO_BIDI, stringprep_generic_D_2,
104 "D.2"}
107 /* 5) Check unassigned code points -- Possibly check the output for
108 unassigned code points, according to the profile. This is
109 described in section 7. */
111 {STRINGPREP_UNASSIGNED_TABLE, ~STRINGPREP_NO_UNASSIGNED,
112 stringprep_generic_A_1, "A.1"}
118 Stringprep_profile stringprep_nameprep[] = {
119 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_1, "B.1"}
121 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_2, "B.2"}
123 {STRINGPREP_NFKC, 0, 0, "NFKC"}
125 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_1_2, "C.1.2"}
127 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_2, "C.2.2"}
129 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_3, "C.3"}
131 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_4, "C.4"}
133 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_5, "C.5"}
135 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_6, "C.6"}
137 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_7, "C.7"}
139 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
141 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_9, "C.9"}
143 {STRINGPREP_BIDI, 0, 0, "BIDI"}
145 {STRINGPREP_BIDI_PROHIBIT_TABLE, ~STRINGPREP_NO_BIDI,
146 stringprep_generic_C_8, "C.8"}
148 {STRINGPREP_BIDI_RAL_TABLE, 0, stringprep_generic_D_1, "D.1"}
150 {STRINGPREP_BIDI_L_TABLE, 0, stringprep_generic_D_2, "D.2"}
152 {STRINGPREP_UNASSIGNED_TABLE, ~STRINGPREP_NO_UNASSIGNED,
153 stringprep_generic_A_1, "A.1"}
158 Stringprep_profile stringprep_kerberos5[] = {
159 /* XXX this is likely to be wrong as the specification is
160 a rough draft. */
161 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_1, "B.1"}
163 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_3, "B.2"}
165 {STRINGPREP_NFKC, 0, 0, "NFKC"}
167 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_1_2, "C.1.2"}
169 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_2, "C.2.2"}
171 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_3, "C.3"}
173 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_4, "C.4"}
175 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_5, "C.5"}
177 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_6, "C.6"}
179 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_7, "C.7"}
181 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
183 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_9, "C.9"}
185 {STRINGPREP_BIDI, 0, 0, "BIDI"}
187 {STRINGPREP_BIDI_PROHIBIT_TABLE, ~STRINGPREP_NO_BIDI,
188 stringprep_generic_C_8, "C.8"}
190 {STRINGPREP_BIDI_RAL_TABLE, 0, stringprep_generic_D_1, "D.1"}
192 {STRINGPREP_BIDI_L_TABLE, 0, stringprep_generic_D_2, "D.2"}
194 {STRINGPREP_UNASSIGNED_TABLE, ~STRINGPREP_NO_UNASSIGNED,
195 stringprep_generic_A_1, "A.1"}
200 Stringprep_table_element stringprep_xmpp_nodeprep_prohibit[] = {
201 {0x000022}
202 , /* #x22 (") */
203 {0x000026}
204 , /* #x26 (&) */
205 {0x000027}
206 , /* #x27 (') */
207 {0x00002F}
208 , /* #x2F (/) */
209 {0x00003A}
210 , /* #x3A (:) */
211 {0x00003C}
212 , /* #x3C (<) */
213 {0x00003E}
214 , /* #x3E (>) */
215 {0x000040} /* #x40 (@) */
220 Stringprep_profile stringprep_xmpp_nodeprep[] = {
221 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_1, "B.1"}
223 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_2, "B.2"}
225 {STRINGPREP_NFKC, 0, 0, "NFKC"}
227 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_1_1, "C.1.1"}
229 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_1_2, "C.1.2"}
231 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_1, "C.2.1"}
233 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_2, "C.2.2"}
235 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_3, "C.3"}
237 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_4, "C.4"}
239 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_5, "C.5"}
241 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_6, "C.6"}
243 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_7, "C.7"}
245 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
247 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_9, "C.9"}
249 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_xmpp_nodeprep_prohibit,
250 "XMPP-PROHIBIT"}
252 {STRINGPREP_BIDI, 0, 0, "BIDI"}
254 {STRINGPREP_BIDI_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
256 {STRINGPREP_BIDI_RAL_TABLE, 0, stringprep_generic_D_1, "D.1"}
258 {STRINGPREP_BIDI_L_TABLE, 0, stringprep_generic_D_2, "D.2"}
260 {STRINGPREP_UNASSIGNED_TABLE, ~STRINGPREP_NO_UNASSIGNED,
261 stringprep_generic_A_1, "A.1"}
266 Stringprep_profile stringprep_xmpp_resourceprep[] = {
267 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_1, "B.1"}
269 {STRINGPREP_NFKC, 0, 0, "NFKC"}
271 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_1_2, "C.1.2"}
273 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_1, "C.2.1"}
275 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_2, "C.2.2"}
277 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_3, "C.3"}
279 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_4, "C.4"}
281 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_5, "C.5"}
283 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_6, "C.6"}
285 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_7, "C.7"}
287 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
289 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_9, "C.9"}
291 {STRINGPREP_BIDI, 0, 0, "BIDI"}
293 {STRINGPREP_BIDI_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
295 {STRINGPREP_BIDI_RAL_TABLE, ~STRINGPREP_NO_BIDI, stringprep_generic_D_1,
296 "D.1"}
298 {STRINGPREP_BIDI_L_TABLE, ~STRINGPREP_NO_BIDI, stringprep_generic_D_2,
299 "D.2"}
301 {STRINGPREP_UNASSIGNED_TABLE, ~STRINGPREP_NO_UNASSIGNED,
302 stringprep_generic_A_1, "A.1"}
307 Stringprep_profile stringprep_plain[] = {
308 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_1, "C.2.1"}
310 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_2, "C.2.2"}
312 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_3, "C.3"}
314 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_4, "C.4"}
316 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_5, "C.5"}
318 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_6, "C.6"}
320 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
322 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_9, "C.9"}
324 {STRINGPREP_BIDI, 0, 0, "BIDI"}
326 {STRINGPREP_BIDI_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
328 {STRINGPREP_BIDI_RAL_TABLE, ~STRINGPREP_NO_BIDI, stringprep_generic_D_1,
329 "D.1"}
331 {STRINGPREP_BIDI_L_TABLE, ~STRINGPREP_NO_BIDI, stringprep_generic_D_2,
332 "D.2"}
337 Stringprep_table_element stringprep_iscsi_prohibit[] = {
338 {0x0000}
339 , /* [ASCII CONTROL CHARACTERS and SPACE through ,] */
340 {0x0001}
342 {0x0002}
344 {0x0003}
346 {0x0004}
348 {0x0005}
350 {0x0006}
352 {0x0007}
354 {0x0008}
356 {0x0009}
358 {0x000A}
360 {0x000B}
362 {0x000C}
364 {0x000D}
366 {0x000E}
368 {0x000F}
370 {0x0010}
372 {0x0011}
374 {0x0012}
376 {0x0013}
378 {0x0014}
380 {0x0015}
382 {0x0016}
384 {0x0017}
386 {0x0018}
388 {0x0019}
390 {0x001A}
392 {0x001B}
394 {0x001C}
396 {0x001D}
398 {0x001E}
400 {0x001F}
402 {0x0020}
404 {0x0021}
406 {0x0022}
408 {0x0023}
410 {0x0024}
412 {0x0025}
414 {0x0026}
416 {0x0027}
418 {0x0028}
420 {0x0029}
422 {0x002A}
424 {0x002B}
426 {0x002C}
428 {0x002F}
429 , /* [ASCII /] */
430 {0x003B}
431 , /* [ASCII ; through @] */
432 {0x003C}
434 {0x003D}
436 {0x003E}
438 {0x003F}
440 {0x0040}
442 {0x005B}
443 , /* [ASCII [ through `] */
444 {0x005C}
446 {0x005D}
448 {0x005E}
450 {0x005F}
452 {0x0060}
454 {0x007B}
455 , /* [ASCII { through DEL] */
456 {0x007C}
458 {0x007D}
460 {0x007E}
462 {0x007F}
464 {0x3002}
465 , /* ideographic full stop */
469 Stringprep_profile stringprep_iscsi[] = {
470 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_1, "B.1"}
472 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_2, "B.2"}
474 {STRINGPREP_NFKC, 0, 0, "NFKC"}
476 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_1, "C.1.1"}
478 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_2, "C.1.2"}
480 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_1, "C.2.1"}
482 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_2, "C.2.2"}
484 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_3, "C.3"}
486 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_4, "C.4"}
488 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_5, "C.5"}
490 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_6, "C.6"}
492 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
494 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_9, "C.9"}
496 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_iscsi_prohibit, "ISCSI-PROHIBIT"}
498 {STRINGPREP_BIDI, 0, 0, "BIDI"}
500 {STRINGPREP_BIDI_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
502 {STRINGPREP_BIDI_RAL_TABLE, ~STRINGPREP_NO_BIDI, stringprep_generic_D_1,
503 "D.1"}
505 {STRINGPREP_BIDI_L_TABLE, ~STRINGPREP_NO_BIDI, stringprep_generic_D_2,
506 "D.2"}
508 {STRINGPREP_UNASSIGNED_TABLE, ~STRINGPREP_NO_UNASSIGNED,
509 stringprep_generic_A_1, "A.1"}
514 Stringprep_table_element stringprep_saslprep_space_map[] = {
515 {0x0000A0, 0, {0x0020}
517 , /* 00A0; NO-BREAK SPACE */
518 {0x001680, 0, {0x0020}
520 , /* 1680; OGHAM SPACE MARK */
521 {0x002000, 0, {0x0020}
523 , /* 2000; EN QUAD */
524 {0x002001, 0, {0x0020}
526 , /* 2001; EM QUAD */
527 {0x002002, 0, {0x0020}
529 , /* 2002; EN SPACE */
530 {0x002003, 0, {0x0020}
532 , /* 2003; EM SPACE */
533 {0x002004, 0, {0x0020}
535 , /* 2004; THREE-PER-EM SPACE */
536 {0x002005, 0, {0x0020}
538 , /* 2005; FOUR-PER-EM SPACE */
539 {0x002006, 0, {0x0020}
541 , /* 2006; SIX-PER-EM SPACE */
542 {0x002007, 0, {0x0020}
544 , /* 2007; FIGURE SPACE */
545 {0x002008, 0, {0x0020}
547 , /* 2008; PUNCTUATION SPACE */
548 {0x002009, 0, {0x0020}
550 , /* 2009; THIN SPACE */
551 {0x00200A, 0, {0x0020}
553 , /* 200A; HAIR SPACE */
554 {0x00200B, 0, {0x0020}
556 , /* 200B; ZERO WIDTH SPACE */
557 {0x00202F, 0, {0x0020}
559 , /* 202F; NARROW NO-BREAK SPACE */
560 {0x00205F, 0, {0x0020}
562 , /* 205F; MEDIUM MATHEMATICAL SPACE */
563 {0x003000, 0, {0x0020}
565 , /* 3000; IDEOGRAPHIC SPACE */
569 Stringprep_profile stringprep_saslprep[] = {
570 {STRINGPREP_MAP_TABLE, 0, stringprep_saslprep_space_map, "SASL-SPACE-MAP"}
572 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_1, "B.1"}
574 {STRINGPREP_NFKC, 0, 0, "NFKC"}
576 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_2, "C.1.2"}
578 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_1, "C.2.1"}
580 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_2, "C.2.2"}
582 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_3, "C.3"}
584 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_4, "C.4"}
586 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_5, "C.5"}
588 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_6, "C.6"}
590 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
592 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_9, "C.9"}
594 {STRINGPREP_BIDI, 0, 0, "BIDI"}
596 {STRINGPREP_BIDI_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
598 {STRINGPREP_BIDI_RAL_TABLE, ~STRINGPREP_NO_BIDI, stringprep_generic_D_1,
599 "D.1"}
601 {STRINGPREP_BIDI_L_TABLE, ~STRINGPREP_NO_BIDI, stringprep_generic_D_2,
602 "D.2"}
604 {STRINGPREP_UNASSIGNED_TABLE, ~STRINGPREP_NO_UNASSIGNED,
605 stringprep_generic_A_1, "A.1"}