stringprep.c 22 KB

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