stringprep.c 24 KB

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