Use process-environment instead of utility env.
[libidn.git] / profiles.c
blobda9014f050e1f5c0fd7f086046b4c5836c86e16e
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 },
26 { "Nameprep", stringprep_nameprep },
27 { "KRBprep", stringprep_kerberos5 },
28 { "Nodeprep", stringprep_xmpp_nodeprep },
29 { "Resourceprep", stringprep_xmpp_resourceprep },
30 { "plain", stringprep_plain },
31 { "SASLprep", stringprep_saslprep },
32 { "ISCSIprep", stringprep_iscsi },
33 { NULL, NULL }
36 Stringprep_profile stringprep_generic[] = {
37 /* 1) Map -- For each character in the input, check if it has a
38 mapping and, if so, replace it with its mapping. This is
39 described in section 3. */
41 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_1, "B.1"}
43 {STRINGPREP_MAP_TABLE, ~STRINGPREP_NO_NFKC, stringprep_generic_B_2, "B.2"}
45 {STRINGPREP_MAP_TABLE, STRINGPREP_NO_NFKC, stringprep_generic_B_3, "B.3"}
48 /* 2) Normalize -- Possibly normalize the result of step 1 using
49 Unicode normalization. This is described in section 4. */
51 {STRINGPREP_NFKC, ~STRINGPREP_NO_NFKC, 0, "NFKC"}
54 /* 3) Prohibit -- Check for any characters that are not allowed in
55 the output. If any are found, return an error. This is
56 described in section 5. */
58 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_1_1, "C.1.1"}
60 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_1_2, "C.1.2"}
62 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_1, "C.2.1"}
64 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_2, "C.2.2"}
66 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_3, "C.3"}
68 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_4, "C.4"}
70 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_5, "C.5"}
72 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_6, "C.6"}
74 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_7, "C.7"}
76 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
78 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_9, "C.9"}
81 /* 4) Check bidi -- Possibly check for right-to-left characters, and
82 if any are found, make sure that the whole string satisfies
83 the requirements for bidirectional strings. If the string does
84 not satisfy the requirements for bidirectional strings, return
85 an error. This is described in section 6. */
87 {STRINGPREP_BIDI, ~STRINGPREP_NO_BIDI, 0, "BIDI"}
89 {STRINGPREP_BIDI_PROHIBIT_TABLE, ~STRINGPREP_NO_BIDI,
90 stringprep_generic_C_8, "C.8"}
92 {STRINGPREP_BIDI_RAL_TABLE, ~STRINGPREP_NO_BIDI, stringprep_generic_D_1,
93 "D.1"}
95 {STRINGPREP_BIDI_L_TABLE, ~STRINGPREP_NO_BIDI, stringprep_generic_D_2,
96 "D.2"}
99 /* 5) Check unassigned code points -- Possibly check the output for
100 unassigned code points, according to the profile. This is
101 described in section 7. */
103 {STRINGPREP_UNASSIGNED_TABLE, ~STRINGPREP_NO_UNASSIGNED,
104 stringprep_generic_A_1, "A.1"}
110 Stringprep_profile stringprep_nameprep[] = {
111 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_1, "B.1"}
113 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_2, "B.2"}
115 {STRINGPREP_NFKC, 0, 0, "NFKC"}
117 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_1_2, "C.1.2"}
119 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_2, "C.2.2"}
121 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_3, "C.3"}
123 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_4, "C.4"}
125 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_5, "C.5"}
127 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_6, "C.6"}
129 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_7, "C.7"}
131 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
133 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_9, "C.9"}
135 {STRINGPREP_BIDI, 0, 0, "BIDI"}
137 {STRINGPREP_BIDI_PROHIBIT_TABLE, ~STRINGPREP_NO_BIDI,
138 stringprep_generic_C_8, "C.8"}
140 {STRINGPREP_BIDI_RAL_TABLE, 0, stringprep_generic_D_1, "D.1"}
142 {STRINGPREP_BIDI_L_TABLE, 0, stringprep_generic_D_2, "D.2"}
144 {STRINGPREP_UNASSIGNED_TABLE, ~STRINGPREP_NO_UNASSIGNED,
145 stringprep_generic_A_1, "A.1"}
150 Stringprep_profile stringprep_kerberos5[] = {
151 /* XXX this is likely to be wrong as the specification is
152 a rough draft. */
153 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_1, "B.1"}
155 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_3, "B.2"}
157 {STRINGPREP_NFKC, 0, 0, "NFKC"}
159 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_1_2, "C.1.2"}
161 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_2, "C.2.2"}
163 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_3, "C.3"}
165 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_4, "C.4"}
167 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_5, "C.5"}
169 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_6, "C.6"}
171 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_7, "C.7"}
173 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
175 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_9, "C.9"}
177 {STRINGPREP_BIDI, 0, 0, "BIDI"}
179 {STRINGPREP_BIDI_PROHIBIT_TABLE, ~STRINGPREP_NO_BIDI,
180 stringprep_generic_C_8, "C.8"}
182 {STRINGPREP_BIDI_RAL_TABLE, 0, stringprep_generic_D_1, "D.1"}
184 {STRINGPREP_BIDI_L_TABLE, 0, stringprep_generic_D_2, "D.2"}
186 {STRINGPREP_UNASSIGNED_TABLE, ~STRINGPREP_NO_UNASSIGNED,
187 stringprep_generic_A_1, "A.1"}
192 Stringprep_table_element stringprep_xmpp_nodeprep_prohibit[] = {
193 {0x000022}
194 , /* #x22 (") */
195 {0x000026}
196 , /* #x26 (&) */
197 {0x000027}
198 , /* #x27 (') */
199 {0x00002F}
200 , /* #x2F (/) */
201 {0x00003A}
202 , /* #x3A (:) */
203 {0x00003C}
204 , /* #x3C (<) */
205 {0x00003E}
206 , /* #x3E (>) */
207 {0x000040} /* #x40 (@) */
212 Stringprep_profile stringprep_xmpp_nodeprep[] = {
213 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_1, "B.1"}
215 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_2, "B.2"}
217 {STRINGPREP_NFKC, 0, 0, "NFKC"}
219 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_1_1, "C.1.1"}
221 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_1_2, "C.1.2"}
223 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_1, "C.2.1"}
225 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_2, "C.2.2"}
227 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_3, "C.3"}
229 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_4, "C.4"}
231 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_5, "C.5"}
233 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_6, "C.6"}
235 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_7, "C.7"}
237 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
239 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_9, "C.9"}
241 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_xmpp_nodeprep_prohibit,
242 "XMPP-PROHIBIT"}
244 {STRINGPREP_BIDI, 0, 0, "BIDI"}
246 {STRINGPREP_BIDI_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
248 {STRINGPREP_BIDI_RAL_TABLE, 0, stringprep_generic_D_1, "D.1"}
250 {STRINGPREP_BIDI_L_TABLE, 0, stringprep_generic_D_2, "D.2"}
252 {STRINGPREP_UNASSIGNED_TABLE, ~STRINGPREP_NO_UNASSIGNED,
253 stringprep_generic_A_1, "A.1"}
258 Stringprep_profile stringprep_xmpp_resourceprep[] = {
259 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_1, "B.1"}
261 {STRINGPREP_NFKC, 0, 0, "NFKC"}
263 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_1_2, "C.1.2"}
265 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_1, "C.2.1"}
267 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_2, "C.2.2"}
269 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_3, "C.3"}
271 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_4, "C.4"}
273 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_5, "C.5"}
275 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_6, "C.6"}
277 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_7, "C.7"}
279 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
281 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_9, "C.9"}
283 {STRINGPREP_BIDI, 0, 0, "BIDI"}
285 {STRINGPREP_BIDI_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
287 {STRINGPREP_BIDI_RAL_TABLE, ~STRINGPREP_NO_BIDI, stringprep_generic_D_1,
288 "D.1"}
290 {STRINGPREP_BIDI_L_TABLE, ~STRINGPREP_NO_BIDI, stringprep_generic_D_2,
291 "D.2"}
293 {STRINGPREP_UNASSIGNED_TABLE, ~STRINGPREP_NO_UNASSIGNED,
294 stringprep_generic_A_1, "A.1"}
299 Stringprep_profile stringprep_plain[] = {
300 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_1, "C.2.1"}
302 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_2, "C.2.2"}
304 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_3, "C.3"}
306 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_4, "C.4"}
308 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_5, "C.5"}
310 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_6, "C.6"}
312 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
314 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_9, "C.9"}
316 {STRINGPREP_BIDI, 0, 0, "BIDI"}
318 {STRINGPREP_BIDI_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
320 {STRINGPREP_BIDI_RAL_TABLE, ~STRINGPREP_NO_BIDI, stringprep_generic_D_1,
321 "D.1"}
323 {STRINGPREP_BIDI_L_TABLE, ~STRINGPREP_NO_BIDI, stringprep_generic_D_2,
324 "D.2"}
329 Stringprep_table_element stringprep_iscsi_prohibit[] = {
330 {0x0000}, /* [ASCII CONTROL CHARACTERS and SPACE through ,] */
331 {0x0001},
332 {0x0002},
333 {0x0003},
334 {0x0004},
335 {0x0005},
336 {0x0006},
337 {0x0007},
338 {0x0008},
339 {0x0009},
340 {0x000A},
341 {0x000B},
342 {0x000C},
343 {0x000D},
344 {0x000E},
345 {0x000F},
346 {0x0010},
347 {0x0011},
348 {0x0012},
349 {0x0013},
350 {0x0014},
351 {0x0015},
352 {0x0016},
353 {0x0017},
354 {0x0018},
355 {0x0019},
356 {0x001A},
357 {0x001B},
358 {0x001C},
359 {0x001D},
360 {0x001E},
361 {0x001F},
362 {0x0020},
363 {0x0021},
364 {0x0022},
365 {0x0023},
366 {0x0024},
367 {0x0025},
368 {0x0026},
369 {0x0027},
370 {0x0028},
371 {0x0029},
372 {0x002A},
373 {0x002B},
374 {0x002C},
375 {0x002F}, /* [ASCII /] */
376 {0x003B}, /* [ASCII ; through @] */
377 {0x003C},
378 {0x003D},
379 {0x003E},
380 {0x003F},
381 {0x0040},
382 {0x005B}, /* [ASCII [ through `] */
383 {0x005C},
384 {0x005D},
385 {0x005E},
386 {0x005F},
387 {0x0060},
388 {0x007B}, /* [ASCII { through DEL] */
389 {0x007C},
390 {0x007D},
391 {0x007E},
392 {0x007F},
393 {0x3002}, /* ideographic full stop */
397 Stringprep_profile stringprep_iscsi[] = {
398 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_1, "B.1"}
400 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_2, "B.2"}
402 {STRINGPREP_NFKC, 0, 0, "NFKC"}
404 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_1, "C.1.1"}
406 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_2, "C.1.2"}
408 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_1, "C.2.1"}
410 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_2, "C.2.2"}
412 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_3, "C.3"}
414 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_4, "C.4"}
416 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_5, "C.5"}
418 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_6, "C.6"}
420 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
422 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_9, "C.9"}
424 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_iscsi_prohibit, "ISCSI-PROHIBIT"}
426 {STRINGPREP_BIDI, 0, 0, "BIDI"}
428 {STRINGPREP_BIDI_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
430 {STRINGPREP_BIDI_RAL_TABLE, ~STRINGPREP_NO_BIDI, stringprep_generic_D_1,
431 "D.1"}
433 {STRINGPREP_BIDI_L_TABLE, ~STRINGPREP_NO_BIDI, stringprep_generic_D_2,
434 "D.2"}
436 {STRINGPREP_UNASSIGNED_TABLE, ~STRINGPREP_NO_UNASSIGNED,
437 stringprep_generic_A_1, "A.1"}
442 Stringprep_table_element stringprep_saslprep_space_map[] = {
443 { 0x0000A0, 0, { 0x0020 }}, /* 00A0; NO-BREAK SPACE */
444 { 0x001680, 0, { 0x0020 }}, /* 1680; OGHAM SPACE MARK */
445 { 0x002000, 0, { 0x0020 }}, /* 2000; EN QUAD */
446 { 0x002001, 0, { 0x0020 }}, /* 2001; EM QUAD */
447 { 0x002002, 0, { 0x0020 }}, /* 2002; EN SPACE */
448 { 0x002003, 0, { 0x0020 }}, /* 2003; EM SPACE */
449 { 0x002004, 0, { 0x0020 }}, /* 2004; THREE-PER-EM SPACE */
450 { 0x002005, 0, { 0x0020 }}, /* 2005; FOUR-PER-EM SPACE */
451 { 0x002006, 0, { 0x0020 }}, /* 2006; SIX-PER-EM SPACE */
452 { 0x002007, 0, { 0x0020 }}, /* 2007; FIGURE SPACE */
453 { 0x002008, 0, { 0x0020 }}, /* 2008; PUNCTUATION SPACE */
454 { 0x002009, 0, { 0x0020 }}, /* 2009; THIN SPACE */
455 { 0x00200A, 0, { 0x0020 }}, /* 200A; HAIR SPACE */
456 { 0x00200B, 0, { 0x0020 }}, /* 200B; ZERO WIDTH SPACE */
457 { 0x00202F, 0, { 0x0020 }}, /* 202F; NARROW NO-BREAK SPACE */
458 { 0x00205F, 0, { 0x0020 }}, /* 205F; MEDIUM MATHEMATICAL SPACE */
459 { 0x003000, 0, { 0x0020 }}, /* 3000; IDEOGRAPHIC SPACE */
460 { 0 }
463 Stringprep_profile stringprep_saslprep[] = {
464 {STRINGPREP_MAP_TABLE, 0, stringprep_saslprep_space_map, "SASL-SPACE-MAP"}
466 {STRINGPREP_MAP_TABLE, 0, stringprep_generic_B_1, "B.1"}
468 {STRINGPREP_NFKC, 0, 0, "NFKC"}
470 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_2, "C.1.2"}
472 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_1, "C.2.1"}
474 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_2_2, "C.2.2"}
476 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_3, "C.3"}
478 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_4, "C.4"}
480 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_5, "C.5"}
482 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_6, "C.6"}
484 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
486 {STRINGPREP_PROHIBIT_TABLE, 0, stringprep_generic_C_9, "C.9"}
488 {STRINGPREP_BIDI, 0, 0, "BIDI"}
490 {STRINGPREP_BIDI_PROHIBIT_TABLE, 0, stringprep_generic_C_8, "C.8"}
492 {STRINGPREP_BIDI_RAL_TABLE, ~STRINGPREP_NO_BIDI, stringprep_generic_D_1,
493 "D.1"}
495 {STRINGPREP_BIDI_L_TABLE, ~STRINGPREP_NO_BIDI, stringprep_generic_D_2,
496 "D.2"}
498 {STRINGPREP_UNASSIGNED_TABLE, ~STRINGPREP_NO_UNASSIGNED,
499 stringprep_generic_A_1, "A.1"}