Branch data Line data Source code
1 : : /* stringprep.c --- Core stringprep implementation.
2 : : Copyright (C) 2002-2013 Simon Josefsson
3 : :
4 : : This file is part of GNU Libidn.
5 : :
6 : : GNU Libidn is free software: you can redistribute it and/or
7 : : modify it under the terms of either:
8 : :
9 : : * the GNU Lesser General Public License as published by the Free
10 : : Software Foundation; either version 3 of the License, or (at
11 : : your option) any later version.
12 : :
13 : : or
14 : :
15 : : * the GNU General Public License as published by the Free
16 : : Software Foundation; either version 2 of the License, or (at
17 : : your option) any later version.
18 : :
19 : : or both in parallel, as here.
20 : :
21 : : GNU Libidn is distributed in the hope that it will be useful,
22 : : but WITHOUT ANY WARRANTY; without even the implied warranty of
23 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 : : General Public License for more details.
25 : :
26 : : You should have received copies of the GNU General Public License and
27 : : the GNU Lesser General Public License along with this program. If
28 : : not, see <http://www.gnu.org/licenses/>. */
29 : :
30 : : #ifdef HAVE_CONFIG_H
31 : : # include "config.h"
32 : : #endif
33 : :
34 : : #include <stdlib.h>
35 : : #include <string.h>
36 : :
37 : : #include "stringprep.h"
38 : :
39 : : static ssize_t
40 : 22590 : stringprep_find_character_in_table (uint32_t ucs4,
41 : : const Stringprep_table_element * table)
42 : : {
43 : : ssize_t i;
44 : :
45 : : /* This is where typical uses of Libidn spends very close to all CPU
46 : : time and causes most cache misses. One could easily do a binary
47 : : search instead. Before rewriting this, I want hard evidence this
48 : : slowness is at all relevant in typical applications. (I don't
49 : : dispute optimization may improve matters significantly, I'm
50 : : mostly interested in having someone give real-world benchmark on
51 : : the impact of libidn.) */
52 : :
53 [ + + ][ + + ]: 3859821 : for (i = 0; table[i].start || table[i].end; i++)
54 [ + + ][ + + ]: 4559106 : if (ucs4 >= table[i].start &&
55 [ + + ]: 721516 : ucs4 <= (table[i].end ? table[i].end : table[i].start))
56 : 359 : return i;
57 : :
58 : 22590 : return -1;
59 : : }
60 : :
61 : : static ssize_t
62 : 3090 : stringprep_find_string_in_table (uint32_t * ucs4,
63 : : size_t ucs4len,
64 : : size_t * tablepos,
65 : : const Stringprep_table_element * table)
66 : : {
67 : : size_t j;
68 : : ssize_t pos;
69 : :
70 [ + + ]: 25319 : for (j = 0; j < ucs4len; j++)
71 [ + + ]: 22570 : if ((pos = stringprep_find_character_in_table (ucs4[j], table)) != -1)
72 : : {
73 [ + + ]: 341 : if (tablepos)
74 : 119 : *tablepos = pos;
75 : 341 : return j;
76 : : }
77 : :
78 : 3090 : return -1;
79 : : }
80 : :
81 : : static int
82 : 449 : stringprep_apply_table_to_string (uint32_t * ucs4,
83 : : size_t * ucs4len,
84 : : size_t maxucs4len,
85 : : const Stringprep_table_element * table)
86 : : {
87 : : ssize_t pos;
88 : : size_t i, maplen;
89 : :
90 [ + + ]: 568 : while ((pos = stringprep_find_string_in_table (ucs4, *ucs4len,
91 : : &i, table)) != -1)
92 : : {
93 [ + + ]: 446 : for (maplen = STRINGPREP_MAX_MAP_CHARS;
94 [ + + ]: 429 : maplen > 0 && table[i].map[maplen - 1] == 0; maplen--)
95 : : ;
96 : :
97 [ - + ]: 119 : if (*ucs4len - 1 + maplen >= maxucs4len)
98 : 0 : return STRINGPREP_TOO_SMALL_BUFFER;
99 : :
100 : 119 : memmove (&ucs4[pos + maplen], &ucs4[pos + 1],
101 : 119 : sizeof (uint32_t) * (*ucs4len - pos - 1));
102 : 119 : memcpy (&ucs4[pos], table[i].map, sizeof (uint32_t) * maplen);
103 : 119 : *ucs4len = *ucs4len - 1 + maplen;
104 : : }
105 : :
106 : 449 : return STRINGPREP_OK;
107 : : }
108 : :
109 : : #define INVERTED(x) ((x) & ((~0UL) >> 1))
110 : : #define UNAPPLICAPLEFLAGS(flags, profileflags) \
111 : : ((!INVERTED(profileflags) && !(profileflags & flags) && profileflags) || \
112 : : ( INVERTED(profileflags) && (profileflags & flags)))
113 : :
114 : : /**
115 : : * stringprep_4i:
116 : : * @ucs4: input/output array with string to prepare.
117 : : * @len: on input, length of input array with Unicode code points,
118 : : * on exit, length of output array with Unicode code points.
119 : : * @maxucs4len: maximum length of input/output array.
120 : : * @flags: a #Stringprep_profile_flags value, or 0.
121 : : * @profile: pointer to #Stringprep_profile to use.
122 : : *
123 : : * Prepare the input UCS-4 string according to the stringprep profile,
124 : : * and write back the result to the input string.
125 : : *
126 : : * The input is not required to be zero terminated (@ucs4[@len] = 0).
127 : : * The output will not be zero terminated unless @ucs4[@len] = 0.
128 : : * Instead, see stringprep_4zi() if your input is zero terminated or
129 : : * if you want the output to be.
130 : : *
131 : : * Since the stringprep operation can expand the string, @maxucs4len
132 : : * indicate how large the buffer holding the string is. This function
133 : : * will not read or write to code points outside that size.
134 : : *
135 : : * The @flags are one of #Stringprep_profile_flags values, or 0.
136 : : *
137 : : * The @profile contain the #Stringprep_profile instructions to
138 : : * perform. Your application can define new profiles, possibly
139 : : * re-using the generic stringprep tables that always will be part of
140 : : * the library, or use one of the currently supported profiles.
141 : : *
142 : : * Return value: Returns %STRINGPREP_OK iff successful, or an
143 : : * #Stringprep_rc error code.
144 : : **/
145 : : int
146 : 226 : stringprep_4i (uint32_t * ucs4, size_t * len, size_t maxucs4len,
147 : : Stringprep_profile_flags flags,
148 : : const Stringprep_profile * profile)
149 : : {
150 : : size_t i, j;
151 : : ssize_t k;
152 : 226 : size_t ucs4len = *len;
153 : : int rc;
154 : :
155 [ + + ]: 3655 : for (i = 0; profile[i].operation; i++)
156 : : {
157 [ + + + + : 3479 : switch (profile[i].operation)
+ + - ]
158 : : {
159 : : case STRINGPREP_NFKC:
160 : : {
161 : 225 : uint32_t *q = 0;
162 : :
163 [ + - ][ + - ]: 225 : if (UNAPPLICAPLEFLAGS (flags, profile[i].flags))
[ + - ][ - + ]
[ # # ]
164 : : break;
165 : :
166 [ + + ][ + - ]: 225 : if (flags & STRINGPREP_NO_NFKC && !profile[i].flags)
167 : : /* Profile requires NFKC, but callee asked for no NFKC. */
168 : 1 : return STRINGPREP_FLAG_ERROR;
169 : :
170 : 224 : q = stringprep_ucs4_nfkc_normalize (ucs4, ucs4len);
171 [ - + ]: 224 : if (!q)
172 : 0 : return STRINGPREP_NFKC_FAILED;
173 : :
174 [ + + ]: 1827 : for (ucs4len = 0; q[ucs4len]; ucs4len++)
175 : : ;
176 : :
177 [ - + ]: 224 : if (ucs4len >= maxucs4len)
178 : : {
179 : 0 : free (q);
180 : 0 : return STRINGPREP_TOO_SMALL_BUFFER;
181 : : }
182 : :
183 : 224 : memcpy (ucs4, q, ucs4len * sizeof (ucs4[0]));
184 : :
185 : 224 : free (q);
186 : : }
187 : 224 : break;
188 : :
189 : : case STRINGPREP_PROHIBIT_TABLE:
190 : 1900 : k = stringprep_find_string_in_table (ucs4, ucs4len,
191 : 1900 : NULL, profile[i].table);
192 [ + + ]: 1900 : if (k != -1)
193 : 35 : return STRINGPREP_CONTAINS_PROHIBITED;
194 : 1865 : break;
195 : :
196 : : case STRINGPREP_UNASSIGNED_TABLE:
197 [ - + ][ # # ]: 178 : if (UNAPPLICAPLEFLAGS (flags, profile[i].flags))
[ # # ][ + - ]
[ + - ]
198 : : break;
199 [ + + ]: 178 : if (flags & STRINGPREP_NO_UNASSIGNED)
200 : : {
201 : 52 : k = stringprep_find_string_in_table
202 : 52 : (ucs4, ucs4len, NULL, profile[i].table);
203 [ + + ]: 52 : if (k != -1)
204 : 3 : return STRINGPREP_CONTAINS_UNASSIGNED;
205 : : }
206 : 175 : break;
207 : :
208 : : case STRINGPREP_MAP_TABLE:
209 [ + - ][ + - ]: 449 : if (UNAPPLICAPLEFLAGS (flags, profile[i].flags))
[ + - ][ - + ]
[ # # ]
210 : : break;
211 : 449 : rc = stringprep_apply_table_to_string
212 : 449 : (ucs4, &ucs4len, maxucs4len, profile[i].table);
213 [ - + ]: 449 : if (rc != STRINGPREP_OK)
214 : 0 : return rc;
215 : 449 : break;
216 : :
217 : : case STRINGPREP_BIDI_PROHIBIT_TABLE:
218 : : case STRINGPREP_BIDI_RAL_TABLE:
219 : : case STRINGPREP_BIDI_L_TABLE:
220 : 537 : break;
221 : :
222 : : case STRINGPREP_BIDI:
223 : : {
224 : 190 : int done_prohibited = 0;
225 : 190 : int done_ral = 0;
226 : 190 : int done_l = 0;
227 : 190 : size_t contains_ral = SIZE_MAX;
228 : 190 : size_t contains_l = SIZE_MAX;
229 : :
230 [ + + ]: 3427 : for (j = 0; profile[j].operation; j++)
231 [ + + ]: 3237 : if (profile[j].operation == STRINGPREP_BIDI_PROHIBIT_TABLE)
232 : : {
233 : 190 : done_prohibited = 1;
234 : 190 : k = stringprep_find_string_in_table (ucs4, ucs4len,
235 : : NULL,
236 : 190 : profile[j].table);
237 [ - + ]: 190 : if (k != -1)
238 : 0 : return STRINGPREP_BIDI_CONTAINS_PROHIBITED;
239 : : }
240 [ + + ]: 3047 : else if (profile[j].operation == STRINGPREP_BIDI_RAL_TABLE)
241 : : {
242 : 190 : done_ral = 1;
243 [ + + ]: 190 : if (stringprep_find_string_in_table
244 : 190 : (ucs4, ucs4len, NULL, profile[j].table) != -1)
245 : 19 : contains_ral = j;
246 : : }
247 [ + + ]: 2857 : else if (profile[j].operation == STRINGPREP_BIDI_L_TABLE)
248 : : {
249 : 190 : done_l = 1;
250 [ + + ]: 190 : if (stringprep_find_string_in_table
251 : 190 : (ucs4, ucs4len, NULL, profile[j].table) != -1)
252 : 165 : contains_l = j;
253 : : }
254 : :
255 [ + - ][ + - ]: 190 : if (!done_prohibited || !done_ral || !done_l)
[ - + ]
256 : 0 : return STRINGPREP_PROFILE_ERROR;
257 : :
258 [ + + ][ + + ]: 190 : if (contains_ral != SIZE_MAX && contains_l != SIZE_MAX)
259 : 9 : return STRINGPREP_BIDI_BOTH_L_AND_RAL;
260 : :
261 [ + + ]: 181 : if (contains_ral != SIZE_MAX)
262 : : {
263 [ + - + + ]: 20 : if (!(stringprep_find_character_in_table
264 : 10 : (ucs4[0], profile[contains_ral].table) != -1 &&
265 : : stringprep_find_character_in_table
266 : 10 : (ucs4[ucs4len - 1], profile[contains_ral].table) != -1))
267 : 2 : return STRINGPREP_BIDI_LEADTRAIL_NOT_RAL;
268 : : }
269 : : }
270 : 179 : break;
271 : :
272 : : default:
273 : 0 : return STRINGPREP_PROFILE_ERROR;
274 : : break;
275 : : }
276 : : }
277 : :
278 : 176 : *len = ucs4len;
279 : :
280 : 226 : return STRINGPREP_OK;
281 : : }
282 : :
283 : : static int
284 : 0 : stringprep_4zi_1 (uint32_t * ucs4, size_t ucs4len, size_t maxucs4len,
285 : : Stringprep_profile_flags flags,
286 : : const Stringprep_profile * profile)
287 : : {
288 : : int rc;
289 : :
290 : 0 : rc = stringprep_4i (ucs4, &ucs4len, maxucs4len, flags, profile);
291 [ # # ]: 0 : if (rc != STRINGPREP_OK)
292 : 0 : return rc;
293 : :
294 [ # # ]: 0 : if (ucs4len >= maxucs4len)
295 : 0 : return STRINGPREP_TOO_SMALL_BUFFER;
296 : :
297 : 0 : ucs4[ucs4len] = 0;
298 : :
299 : 0 : return STRINGPREP_OK;
300 : : }
301 : :
302 : : /**
303 : : * stringprep_4zi:
304 : : * @ucs4: input/output array with zero terminated string to prepare.
305 : : * @maxucs4len: maximum length of input/output array.
306 : : * @flags: a #Stringprep_profile_flags value, or 0.
307 : : * @profile: pointer to #Stringprep_profile to use.
308 : : *
309 : : * Prepare the input zero terminated UCS-4 string according to the
310 : : * stringprep profile, and write back the result to the input string.
311 : : *
312 : : * Since the stringprep operation can expand the string, @maxucs4len
313 : : * indicate how large the buffer holding the string is. This function
314 : : * will not read or write to code points outside that size.
315 : : *
316 : : * The @flags are one of #Stringprep_profile_flags values, or 0.
317 : : *
318 : : * The @profile contain the #Stringprep_profile instructions to
319 : : * perform. Your application can define new profiles, possibly
320 : : * re-using the generic stringprep tables that always will be part of
321 : : * the library, or use one of the currently supported profiles.
322 : : *
323 : : * Return value: Returns %STRINGPREP_OK iff successful, or an
324 : : * #Stringprep_rc error code.
325 : : **/
326 : : int
327 : 0 : stringprep_4zi (uint32_t * ucs4, size_t maxucs4len,
328 : : Stringprep_profile_flags flags,
329 : : const Stringprep_profile * profile)
330 : : {
331 : : size_t ucs4len;
332 : :
333 [ # # ][ # # ]: 0 : for (ucs4len = 0; ucs4len < maxucs4len && ucs4[ucs4len] != 0; ucs4len++)
334 : : ;
335 : :
336 : 0 : return stringprep_4zi_1 (ucs4, ucs4len, maxucs4len, flags, profile);
337 : : }
338 : :
339 : : /**
340 : : * stringprep:
341 : : * @in: input/ouput array with string to prepare.
342 : : * @maxlen: maximum length of input/output array.
343 : : * @flags: a #Stringprep_profile_flags value, or 0.
344 : : * @profile: pointer to #Stringprep_profile to use.
345 : : *
346 : : * Prepare the input zero terminated UTF-8 string according to the
347 : : * stringprep profile, and write back the result to the input string.
348 : : *
349 : : * Note that you must convert strings entered in the systems locale
350 : : * into UTF-8 before using this function, see
351 : : * stringprep_locale_to_utf8().
352 : : *
353 : : * Since the stringprep operation can expand the string, @maxlen
354 : : * indicate how large the buffer holding the string is. This function
355 : : * will not read or write to characters outside that size.
356 : : *
357 : : * The @flags are one of #Stringprep_profile_flags values, or 0.
358 : : *
359 : : * The @profile contain the #Stringprep_profile instructions to
360 : : * perform. Your application can define new profiles, possibly
361 : : * re-using the generic stringprep tables that always will be part of
362 : : * the library, or use one of the currently supported profiles.
363 : : *
364 : : * Return value: Returns %STRINGPREP_OK iff successful, or an error code.
365 : : **/
366 : : int
367 : 226 : stringprep (char *in,
368 : : size_t maxlen,
369 : : Stringprep_profile_flags flags,
370 : : const Stringprep_profile * profile)
371 : : {
372 : : int rc;
373 : 226 : char *utf8 = NULL;
374 : 226 : uint32_t *ucs4 = NULL;
375 : 226 : size_t ucs4len, maxucs4len, adducs4len = 50;
376 : :
377 : : do
378 : : {
379 : : uint32_t *newp;
380 : :
381 : 226 : free (ucs4);
382 : 226 : ucs4 = stringprep_utf8_to_ucs4 (in, -1, &ucs4len);
383 : 226 : maxucs4len = ucs4len + adducs4len;
384 : 226 : newp = realloc (ucs4, maxucs4len * sizeof (uint32_t));
385 [ - + ]: 226 : if (!newp)
386 : : {
387 : 0 : free (ucs4);
388 : 0 : return STRINGPREP_MALLOC_ERROR;
389 : : }
390 : 226 : ucs4 = newp;
391 : :
392 : 226 : rc = stringprep_4i (ucs4, &ucs4len, maxucs4len, flags, profile);
393 : 226 : adducs4len += 50;
394 : : }
395 [ - + ]: 226 : while (rc == STRINGPREP_TOO_SMALL_BUFFER);
396 [ + + ]: 226 : if (rc != STRINGPREP_OK)
397 : : {
398 : 50 : free (ucs4);
399 : 50 : return rc;
400 : : }
401 : :
402 : 176 : utf8 = stringprep_ucs4_to_utf8 (ucs4, ucs4len, 0, 0);
403 : 176 : free (ucs4);
404 [ - + ]: 176 : if (!utf8)
405 : 0 : return STRINGPREP_MALLOC_ERROR;
406 : :
407 [ + + ]: 176 : if (strlen (utf8) >= maxlen)
408 : : {
409 : 5 : free (utf8);
410 : 5 : return STRINGPREP_TOO_SMALL_BUFFER;
411 : : }
412 : :
413 : 171 : strcpy (in, utf8); /* flawfinder: ignore */
414 : :
415 : 171 : free (utf8);
416 : :
417 : 226 : return STRINGPREP_OK;
418 : : }
419 : :
420 : : /**
421 : : * stringprep_profile:
422 : : * @in: input array with UTF-8 string to prepare.
423 : : * @out: output variable with pointer to newly allocate string.
424 : : * @profile: name of stringprep profile to use.
425 : : * @flags: a #Stringprep_profile_flags value, or 0.
426 : : *
427 : : * Prepare the input zero terminated UTF-8 string according to the
428 : : * stringprep profile, and return the result in a newly allocated
429 : : * variable.
430 : : *
431 : : * Note that you must convert strings entered in the systems locale
432 : : * into UTF-8 before using this function, see
433 : : * stringprep_locale_to_utf8().
434 : : *
435 : : * The output @out variable must be deallocated by the caller.
436 : : *
437 : : * The @flags are one of #Stringprep_profile_flags values, or 0.
438 : : *
439 : : * The @profile specifies the name of the stringprep profile to use.
440 : : * It must be one of the internally supported stringprep profiles.
441 : : *
442 : : * Return value: Returns %STRINGPREP_OK iff successful, or an error code.
443 : : **/
444 : : int
445 : 74 : stringprep_profile (const char *in,
446 : : char **out,
447 : : const char *profile, Stringprep_profile_flags flags)
448 : : {
449 : : const Stringprep_profiles *p;
450 : 74 : char *str = NULL;
451 : 74 : size_t len = strlen (in) + 1;
452 : : int rc;
453 : :
454 [ + - ]: 187 : for (p = &stringprep_profiles[0]; p->name; p++)
455 [ + + ]: 187 : if (strcmp (p->name, profile) == 0)
456 : 74 : break;
457 : :
458 [ + - ][ + - ]: 74 : if (!p || !p->name || !p->tables)
[ - + ]
459 : 0 : return STRINGPREP_UNKNOWN_PROFILE;
460 : :
461 : : do
462 : : {
463 : 79 : free (str);
464 : 79 : str = (char *) malloc (len);
465 [ - + ]: 79 : if (str == NULL)
466 : 0 : return STRINGPREP_MALLOC_ERROR;
467 : :
468 : 79 : strcpy (str, in);
469 : :
470 : 79 : rc = stringprep (str, len, flags, p->tables);
471 : 79 : len += 50;
472 : : }
473 [ + + ]: 79 : while (rc == STRINGPREP_TOO_SMALL_BUFFER);
474 : :
475 [ + + ]: 74 : if (rc == STRINGPREP_OK)
476 : 41 : *out = str;
477 : : else
478 : 33 : free (str);
479 : :
480 : 74 : return rc;
481 : : }
482 : :
483 : : /*! \mainpage GNU Internationalized Domain Name Library
484 : : *
485 : : * \section intro Introduction
486 : : *
487 : : * GNU Libidn is an implementation of the Stringprep, Punycode and IDNA
488 : : * specifications defined by the IETF Internationalized Domain Names
489 : : * (IDN) working group, used for internationalized domain names. The
490 : : * package is available under the GNU Lesser General Public License.
491 : : *
492 : : * The library contains a generic Stringprep implementation that does
493 : : * Unicode 3.2 NFKC normalization, mapping and prohibitation of
494 : : * characters, and bidirectional character handling. Profiles for
495 : : * Nameprep, iSCSI, SASL and XMPP are included. Punycode and ASCII
496 : : * Compatible Encoding (ACE) via IDNA are supported. A mechanism to
497 : : * define Top-Level Domain (TLD) specific validation tables, and to
498 : : * compare strings against those tables, is included. Default tables
499 : : * for some TLDs are also included.
500 : : *
501 : : * The Stringprep API consists of two main functions, one for
502 : : * converting data from the system's native representation into UTF-8,
503 : : * and one function to perform the Stringprep processing. Adding a
504 : : * new Stringprep profile for your application within the API is
505 : : * straightforward. The Punycode API consists of one encoding
506 : : * function and one decoding function. The IDNA API consists of the
507 : : * ToASCII and ToUnicode functions, as well as an high-level interface
508 : : * for converting entire domain names to and from the ACE encoded
509 : : * form. The TLD API consists of one set of functions to extract the
510 : : * TLD name from a domain string, one set of functions to locate the
511 : : * proper TLD table to use based on the TLD name, and core functions
512 : : * to validate a string against a TLD table, and some utility wrappers
513 : : * to perform all the steps in one call.
514 : : *
515 : : * The library is used by, e.g., GNU SASL and Shishi to process user
516 : : * names and passwords. Libidn can be built into GNU Libc to enable a
517 : : * new system-wide getaddrinfo() flag for IDN processing.
518 : : *
519 : : * Libidn is developed for the GNU/Linux system, but runs on over 20 Unix
520 : : * platforms (including Solaris, IRIX, AIX, and Tru64) and Windows.
521 : : * Libidn is written in C and (parts of) the API is accessible from C,
522 : : * C++, Emacs Lisp, Python and Java.
523 : : *
524 : : * The project web page:\n
525 : : * http://www.gnu.org/software/libidn/
526 : : *
527 : : * The software archive:\n
528 : : * ftp://alpha.gnu.org/pub/gnu/libidn/
529 : : *
530 : : * For more information see:\n
531 : : * http://www.ietf.org/html.charters/idn-charter.html\n
532 : : * http://www.ietf.org/rfc/rfc3454.txt (stringprep specification)\n
533 : : * http://www.ietf.org/rfc/rfc3490.txt (idna specification)\n
534 : : * http://www.ietf.org/rfc/rfc3491.txt (nameprep specification)\n
535 : : * http://www.ietf.org/rfc/rfc3492.txt (punycode specification)\n
536 : : * http://www.ietf.org/internet-drafts/draft-ietf-ips-iscsi-string-prep-04.txt\n
537 : : * http://www.ietf.org/internet-drafts/draft-ietf-krb-wg-utf8-profile-01.txt\n
538 : : * http://www.ietf.org/internet-drafts/draft-ietf-sasl-anon-00.txt\n
539 : : * http://www.ietf.org/internet-drafts/draft-ietf-sasl-saslprep-00.txt\n
540 : : * http://www.ietf.org/internet-drafts/draft-ietf-xmpp-nodeprep-01.txt\n
541 : : * http://www.ietf.org/internet-drafts/draft-ietf-xmpp-resourceprep-01.txt\n
542 : : *
543 : : * Further information and paid contract development:\n
544 : : * Simon Josefsson <simon@josefsson.org>
545 : : *
546 : : * \section examples Examples
547 : : *
548 : : * \include example.c
549 : : * \include example3.c
550 : : * \include example4.c
551 : : * \include example5.c
552 : : */
553 : :
554 : : /**
555 : : * STRINGPREP_VERSION
556 : : *
557 : : * String defined via CPP denoting the header file version number.
558 : : * Used together with stringprep_check_version() to verify header file
559 : : * and run-time library consistency.
560 : : */
561 : :
562 : : /**
563 : : * STRINGPREP_MAX_MAP_CHARS
564 : : *
565 : : * Maximum number of code points that can replace a single code point,
566 : : * during stringprep mapping.
567 : : */
568 : :
569 : : /**
570 : : * Stringprep_rc:
571 : : * @STRINGPREP_OK: Successful operation. This value is guaranteed to
572 : : * always be zero, the remaining ones are only guaranteed to hold
573 : : * non-zero values, for logical comparison purposes.
574 : : * @STRINGPREP_CONTAINS_UNASSIGNED: String contain unassigned Unicode
575 : : * code points, which is forbidden by the profile.
576 : : * @STRINGPREP_CONTAINS_PROHIBITED: String contain code points
577 : : * prohibited by the profile.
578 : : * @STRINGPREP_BIDI_BOTH_L_AND_RAL: String contain code points with
579 : : * conflicting bidirection category.
580 : : * @STRINGPREP_BIDI_LEADTRAIL_NOT_RAL: Leading and trailing character
581 : : * in string not of proper bidirectional category.
582 : : * @STRINGPREP_BIDI_CONTAINS_PROHIBITED: Contains prohibited code
583 : : * points detected by bidirectional code.
584 : : * @STRINGPREP_TOO_SMALL_BUFFER: Buffer handed to function was too
585 : : * small. This usually indicate a problem in the calling
586 : : * application.
587 : : * @STRINGPREP_PROFILE_ERROR: The stringprep profile was inconsistent.
588 : : * This usually indicate an internal error in the library.
589 : : * @STRINGPREP_FLAG_ERROR: The supplied flag conflicted with profile.
590 : : * This usually indicate a problem in the calling application.
591 : : * @STRINGPREP_UNKNOWN_PROFILE: The supplied profile name was not
592 : : * known to the library.
593 : : * @STRINGPREP_NFKC_FAILED: The Unicode NFKC operation failed. This
594 : : * usually indicate an internal error in the library.
595 : : * @STRINGPREP_MALLOC_ERROR: The malloc() was out of memory. This is
596 : : * usually a fatal error.
597 : : *
598 : : * Enumerated return codes of stringprep(), stringprep_profile()
599 : : * functions (and macros using those functions). The value 0 is
600 : : * guaranteed to always correspond to success.
601 : : */
602 : :
603 : : /**
604 : : * Stringprep_profile_flags:
605 : : * @STRINGPREP_NO_NFKC: Disable the NFKC normalization, as well as
606 : : * selecting the non-NFKC case folding tables. Usually the profile
607 : : * specifies BIDI and NFKC settings, and applications should not
608 : : * override it unless in special situations.
609 : : * @STRINGPREP_NO_BIDI: Disable the BIDI step. Usually the profile
610 : : * specifies BIDI and NFKC settings, and applications should not
611 : : * override it unless in special situations.
612 : : * @STRINGPREP_NO_UNASSIGNED: Make the library return with an error if
613 : : * string contains unassigned characters according to profile.
614 : : *
615 : : * Stringprep profile flags.
616 : : */
617 : :
618 : : /**
619 : : * Stringprep_profile_steps:
620 : : * @STRINGPREP_NFKC: The NFKC step.
621 : : * @STRINGPREP_BIDI: The BIDI step.
622 : : * @STRINGPREP_MAP_TABLE: The MAP step.
623 : : * @STRINGPREP_UNASSIGNED_TABLE: The Unassigned step.
624 : : * @STRINGPREP_PROHIBIT_TABLE: The Prohibited step.
625 : : * @STRINGPREP_BIDI_PROHIBIT_TABLE: The BIDI-Prohibited step.
626 : : * @STRINGPREP_BIDI_RAL_TABLE: The BIDI-RAL step.
627 : : * @STRINGPREP_BIDI_L_TABLE: The BIDI-L step.
628 : : *
629 : : * Various steps in the stringprep algorithm. You really want to
630 : : * study the source code to understand this one. Only useful if you
631 : : * want to add another profile.
632 : : */
633 : :
634 : : /**
635 : : * stringprep_nameprep:
636 : : * @in: input/ouput array with string to prepare.
637 : : * @maxlen: maximum length of input/output array.
638 : : *
639 : : * Prepare the input UTF-8 string according to the nameprep profile.
640 : : * The AllowUnassigned flag is true, use
641 : : * stringprep_nameprep_no_unassigned() if you want a false
642 : : * AllowUnassigned. Returns 0 iff successful, or an error code.
643 : : **/
644 : :
645 : : /**
646 : : * stringprep_nameprep_no_unassigned:
647 : : * @in: input/ouput array with string to prepare.
648 : : * @maxlen: maximum length of input/output array.
649 : : *
650 : : * Prepare the input UTF-8 string according to the nameprep profile.
651 : : * The AllowUnassigned flag is false, use stringprep_nameprep() for
652 : : * true AllowUnassigned. Returns 0 iff successful, or an error code.
653 : : **/
654 : :
655 : : /**
656 : : * stringprep_iscsi:
657 : : * @in: input/ouput array with string to prepare.
658 : : * @maxlen: maximum length of input/output array.
659 : : *
660 : : * Prepare the input UTF-8 string according to the draft iSCSI
661 : : * stringprep profile. Returns 0 iff successful, or an error code.
662 : : **/
663 : :
664 : : /**
665 : : * stringprep_plain:
666 : : * @in: input/ouput array with string to prepare.
667 : : * @maxlen: maximum length of input/output array.
668 : : *
669 : : * Prepare the input UTF-8 string according to the draft SASL
670 : : * ANONYMOUS profile. Returns 0 iff successful, or an error code.
671 : : **/
672 : :
673 : : /**
674 : : * stringprep_xmpp_nodeprep:
675 : : * @in: input/ouput array with string to prepare.
676 : : * @maxlen: maximum length of input/output array.
677 : : *
678 : : * Prepare the input UTF-8 string according to the draft XMPP node
679 : : * identifier profile. Returns 0 iff successful, or an error code.
680 : : **/
681 : :
682 : : /**
683 : : * stringprep_xmpp_resourceprep:
684 : : * @in: input/ouput array with string to prepare.
685 : : * @maxlen: maximum length of input/output array.
686 : : *
687 : : * Prepare the input UTF-8 string according to the draft XMPP resource
688 : : * identifier profile. Returns 0 iff successful, or an error code.
689 : : **/
|