stringprep.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /* stringprep.h --- Header file for stringprep functions.
  2. * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 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. #ifndef STRINGPREP_H
  22. # define STRINGPREP_H
  23. # ifndef IDNAPI
  24. # if defined LIBIDN_BUILDING && defined HAVE_VISIBILITY && HAVE_VISIBILITY
  25. # define IDNAPI __attribute__((__visibility__("default")))
  26. # elif defined LIBIDN_BUILDING && defined _MSC_VER && ! defined LIBIDN_STATIC
  27. # define IDNAPI __declspec(dllexport)
  28. # elif defined _MSC_VER && ! defined LIBIDN_STATIC
  29. # define IDNAPI __declspec(dllimport)
  30. # else
  31. # define IDNAPI
  32. # endif
  33. # endif
  34. # include <stddef.h> /* size_t */
  35. # include <unistd.h> /* ssize_t */
  36. # include <idn-int.h> /* uint32_t */
  37. # ifdef __cplusplus
  38. extern "C"
  39. {
  40. # endif
  41. # define STRINGPREP_VERSION "1.18"
  42. /* Error codes. */
  43. typedef enum
  44. {
  45. STRINGPREP_OK = 0,
  46. /* Stringprep errors. */
  47. STRINGPREP_CONTAINS_UNASSIGNED = 1,
  48. STRINGPREP_CONTAINS_PROHIBITED = 2,
  49. STRINGPREP_BIDI_BOTH_L_AND_RAL = 3,
  50. STRINGPREP_BIDI_LEADTRAIL_NOT_RAL = 4,
  51. STRINGPREP_BIDI_CONTAINS_PROHIBITED = 5,
  52. /* Error in calling application. */
  53. STRINGPREP_TOO_SMALL_BUFFER = 100,
  54. STRINGPREP_PROFILE_ERROR = 101,
  55. STRINGPREP_FLAG_ERROR = 102,
  56. STRINGPREP_UNKNOWN_PROFILE = 103,
  57. /* Internal errors. */
  58. STRINGPREP_NFKC_FAILED = 200,
  59. STRINGPREP_MALLOC_ERROR = 201
  60. } Stringprep_rc;
  61. /* Flags used when calling stringprep(). */
  62. typedef enum
  63. {
  64. STRINGPREP_NO_NFKC = 1,
  65. STRINGPREP_NO_BIDI = 2,
  66. STRINGPREP_NO_UNASSIGNED = 4
  67. } Stringprep_profile_flags;
  68. /* Steps in a stringprep profile. */
  69. typedef enum
  70. {
  71. STRINGPREP_NFKC = 1,
  72. STRINGPREP_BIDI = 2,
  73. STRINGPREP_MAP_TABLE = 3,
  74. STRINGPREP_UNASSIGNED_TABLE = 4,
  75. STRINGPREP_PROHIBIT_TABLE = 5,
  76. STRINGPREP_BIDI_PROHIBIT_TABLE = 6,
  77. STRINGPREP_BIDI_RAL_TABLE = 7,
  78. STRINGPREP_BIDI_L_TABLE = 8
  79. } Stringprep_profile_steps;
  80. # define STRINGPREP_MAX_MAP_CHARS 4
  81. struct Stringprep_table_element
  82. {
  83. uint32_t start;
  84. uint32_t end; /* 0 if only one character */
  85. uint32_t map[STRINGPREP_MAX_MAP_CHARS]; /* NULL if end is not 0 */
  86. };
  87. typedef struct Stringprep_table_element Stringprep_table_element;
  88. struct Stringprep_table
  89. {
  90. Stringprep_profile_steps operation;
  91. Stringprep_profile_flags flags;
  92. const Stringprep_table_element *table;
  93. };
  94. typedef struct Stringprep_table Stringprep_profile;
  95. struct Stringprep_profiles
  96. {
  97. const char *name;
  98. const Stringprep_profile *tables;
  99. };
  100. typedef struct Stringprep_profiles Stringprep_profiles;
  101. extern IDNAPI const Stringprep_profiles stringprep_profiles[];
  102. /* Profiles */
  103. extern IDNAPI const Stringprep_table_element stringprep_rfc3454_A_1[];
  104. extern IDNAPI const Stringprep_table_element stringprep_rfc3454_B_1[];
  105. extern IDNAPI const Stringprep_table_element stringprep_rfc3454_B_2[];
  106. extern IDNAPI const Stringprep_table_element stringprep_rfc3454_B_3[];
  107. extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_1_1[];
  108. extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_1_2[];
  109. extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_2_1[];
  110. extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_2_2[];
  111. extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_3[];
  112. extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_4[];
  113. extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_5[];
  114. extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_6[];
  115. extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_7[];
  116. extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_8[];
  117. extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_9[];
  118. extern IDNAPI const Stringprep_table_element stringprep_rfc3454_D_1[];
  119. extern IDNAPI const Stringprep_table_element stringprep_rfc3454_D_2[];
  120. /* Nameprep */
  121. extern IDNAPI const Stringprep_profile stringprep_nameprep[];
  122. # define stringprep_nameprep(in, maxlen) \
  123. stringprep(in, maxlen, 0, stringprep_nameprep)
  124. # define stringprep_nameprep_no_unassigned(in, maxlen) \
  125. stringprep(in, maxlen, STRINGPREP_NO_UNASSIGNED, stringprep_nameprep)
  126. /* SASL */
  127. extern IDNAPI const Stringprep_profile stringprep_saslprep[];
  128. extern IDNAPI const Stringprep_table_element stringprep_saslprep_space_map[];
  129. extern IDNAPI const Stringprep_profile stringprep_plain[];
  130. extern IDNAPI const Stringprep_profile stringprep_trace[];
  131. # define stringprep_plain(in, maxlen) \
  132. stringprep(in, maxlen, 0, stringprep_plain)
  133. /* Kerberos */
  134. extern IDNAPI const Stringprep_profile stringprep_kerberos5[];
  135. # define stringprep_kerberos5(in, maxlen) \
  136. stringprep(in, maxlen, 0, stringprep_kerberos5)
  137. /* XMPP */
  138. extern IDNAPI const Stringprep_profile stringprep_xmpp_nodeprep[];
  139. extern IDNAPI const Stringprep_profile stringprep_xmpp_resourceprep[];
  140. extern IDNAPI const Stringprep_table_element stringprep_xmpp_nodeprep_prohibit[];
  141. # define stringprep_xmpp_nodeprep(in, maxlen) \
  142. stringprep(in, maxlen, 0, stringprep_xmpp_nodeprep)
  143. # define stringprep_xmpp_resourceprep(in, maxlen) \
  144. stringprep(in, maxlen, 0, stringprep_xmpp_resourceprep)
  145. /* iSCSI */
  146. extern IDNAPI const Stringprep_profile stringprep_iscsi[];
  147. extern IDNAPI const Stringprep_table_element stringprep_iscsi_prohibit[];
  148. # define stringprep_iscsi(in, maxlen) \
  149. stringprep(in, maxlen, 0, stringprep_iscsi)
  150. /* API */
  151. extern IDNAPI int stringprep_4i (uint32_t * ucs4, size_t * len,
  152. size_t maxucs4len,
  153. Stringprep_profile_flags flags,
  154. const Stringprep_profile * profile);
  155. extern IDNAPI int stringprep_4zi (uint32_t * ucs4, size_t maxucs4len,
  156. Stringprep_profile_flags flags,
  157. const Stringprep_profile * profile);
  158. extern IDNAPI int stringprep (char *in, size_t maxlen,
  159. Stringprep_profile_flags flags,
  160. const Stringprep_profile * profile);
  161. extern IDNAPI int stringprep_profile (const char *in,
  162. char **out,
  163. const char *profile,
  164. Stringprep_profile_flags flags);
  165. extern IDNAPI const char *stringprep_strerror (Stringprep_rc rc);
  166. extern IDNAPI const char *stringprep_check_version (const char
  167. *req_version);
  168. /* Utility */
  169. extern IDNAPI int stringprep_unichar_to_utf8 (uint32_t c, char *outbuf);
  170. extern IDNAPI uint32_t stringprep_utf8_to_unichar (const char *p);
  171. extern IDNAPI uint32_t *stringprep_utf8_to_ucs4 (const char *str,
  172. ssize_t len,
  173. size_t * items_written);
  174. extern IDNAPI char *stringprep_ucs4_to_utf8 (const uint32_t * str,
  175. ssize_t len,
  176. size_t * items_read,
  177. size_t * items_written);
  178. extern IDNAPI char *stringprep_utf8_nfkc_normalize (const char *str,
  179. ssize_t len);
  180. extern IDNAPI uint32_t *stringprep_ucs4_nfkc_normalize (uint32_t * str,
  181. ssize_t len);
  182. extern IDNAPI const char *stringprep_locale_charset (void);
  183. extern IDNAPI char *stringprep_convert (const char *str,
  184. const char *to_codeset,
  185. const char *from_codeset);
  186. extern IDNAPI char *stringprep_locale_to_utf8 (const char *str);
  187. extern IDNAPI char *stringprep_utf8_to_locale (const char *str);
  188. # ifdef __cplusplus
  189. }
  190. # endif
  191. #endif /* STRINGPREP_H */