libidn: stringprep.h Source File

libidn 1.33

stringprep.h
Go to the documentation of this file.
1 /* stringprep.h --- Header file for stringprep functions.
2 Copyright (C) 2002-2016 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 #ifndef STRINGPREP_H
31 # define STRINGPREP_H
32
33 # ifndef IDNAPI
34 # if defined LIBIDN_BUILDING && defined HAVE_VISIBILITY && HAVE_VISIBILITY
35 # define IDNAPI __attribute__((__visibility__("default")))
36 # elif defined LIBIDN_BUILDING && defined _MSC_VER && ! defined LIBIDN_STATIC
37 # define IDNAPI __declspec(dllexport)
38 # elif defined _MSC_VER && ! defined LIBIDN_STATIC
39 # define IDNAPI __declspec(dllimport)
40 # else
41 # define IDNAPI
42 # endif
43 # endif
44
45 # include <stddef.h> /* size_t */
46 # include <sys/types.h> /* ssize_t */
47 # include <idn-int.h> /* uint32_t */
48
49 # ifdef __cplusplus
50 extern "C"
51 {
52 # endif
53
54 # define STRINGPREP_VERSION "1.33"
55
56 /* Error codes. */
57 typedef enum
58 {
59 STRINGPREP_OK = 0,
60 /* Stringprep errors. */
61 STRINGPREP_CONTAINS_UNASSIGNED = 1,
62 STRINGPREP_CONTAINS_PROHIBITED = 2,
63 STRINGPREP_BIDI_BOTH_L_AND_RAL = 3,
64 STRINGPREP_BIDI_LEADTRAIL_NOT_RAL = 4,
65 STRINGPREP_BIDI_CONTAINS_PROHIBITED = 5,
66 /* Error in calling application. */
67 STRINGPREP_TOO_SMALL_BUFFER = 100,
68 STRINGPREP_PROFILE_ERROR = 101,
69 STRINGPREP_FLAG_ERROR = 102,
70 STRINGPREP_UNKNOWN_PROFILE = 103,
71 STRINGPREP_ICONV_ERROR = 104,
72 /* Internal errors. */
73 STRINGPREP_NFKC_FAILED = 200,
74 STRINGPREP_MALLOC_ERROR = 201
75 } Stringprep_rc;
76
77 /* Flags used when calling stringprep(). */
78 typedef enum
79 {
80 STRINGPREP_NO_NFKC = 1,
81 STRINGPREP_NO_BIDI = 2,
82 STRINGPREP_NO_UNASSIGNED = 4
83 } Stringprep_profile_flags;
84
85 /* Steps in a stringprep profile. */
86 typedef enum
87 {
88 STRINGPREP_NFKC = 1,
89 STRINGPREP_BIDI = 2,
90 STRINGPREP_MAP_TABLE = 3,
91 STRINGPREP_UNASSIGNED_TABLE = 4,
92 STRINGPREP_PROHIBIT_TABLE = 5,
93 STRINGPREP_BIDI_PROHIBIT_TABLE = 6,
94 STRINGPREP_BIDI_RAL_TABLE = 7,
95 STRINGPREP_BIDI_L_TABLE = 8
96 } Stringprep_profile_steps;
97
98 # define STRINGPREP_MAX_MAP_CHARS 4
99
100 struct Stringprep_table_element
101 {
102 uint32_t start;
103 uint32_t end; /* 0 if only one character */
104 uint32_t map[STRINGPREP_MAX_MAP_CHARS]; /* NULL if end is not 0 */
105 };
106 typedef struct Stringprep_table_element Stringprep_table_element;
107
108 struct Stringprep_table
109 {
110 Stringprep_profile_steps operation;
111 Stringprep_profile_flags flags;
112 const Stringprep_table_element *table;
113 };
114 typedef struct Stringprep_table Stringprep_profile;
115
116 struct Stringprep_profiles
117 {
118 const char *name;
119 const Stringprep_profile *tables;
120 };
121 typedef struct Stringprep_profiles Stringprep_profiles;
122
123 extern IDNAPI const Stringprep_profiles stringprep_profiles[];
124
125 /* Profiles */
126 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_A_1[];
127 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_B_1[];
128 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_B_2[];
129 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_B_3[];
130 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_1_1[];
131 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_1_2[];
132 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_2_1[];
133 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_2_2[];
134 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_3[];
135 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_4[];
136 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_5[];
137 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_6[];
138 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_7[];
139 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_8[];
140 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_9[];
141 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_D_1[];
142 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_D_2[];
143
144 /* Nameprep */
145
146 extern IDNAPI const Stringprep_profile stringprep_nameprep[];
147
148 # define stringprep_nameprep(in, maxlen) \
149 stringprep(in, maxlen, 0, stringprep_nameprep)
150
151 # define stringprep_nameprep_no_unassigned(in, maxlen) \
152 stringprep(in, maxlen, STRINGPREP_NO_UNASSIGNED, stringprep_nameprep)
153
154 /* SASL */
155
156 extern IDNAPI const Stringprep_profile stringprep_saslprep[];
157 extern IDNAPI const Stringprep_table_element stringprep_saslprep_space_map[];
158 extern IDNAPI const Stringprep_profile stringprep_plain[];
159 extern IDNAPI const Stringprep_profile stringprep_trace[];
160
161 # define stringprep_plain(in, maxlen) \
162 stringprep(in, maxlen, 0, stringprep_plain)
163
164 /* Kerberos */
165
166 extern IDNAPI const Stringprep_profile stringprep_kerberos5[];
167
168 # define stringprep_kerberos5(in, maxlen) \
169 stringprep(in, maxlen, 0, stringprep_kerberos5)
170
171 /* XMPP */
172
173 extern IDNAPI const Stringprep_profile stringprep_xmpp_nodeprep[];
174 extern IDNAPI const Stringprep_profile stringprep_xmpp_resourceprep[];
175 extern IDNAPI const Stringprep_table_element stringprep_xmpp_nodeprep_prohibit[];
176
177 # define stringprep_xmpp_nodeprep(in, maxlen) \
178 stringprep(in, maxlen, 0, stringprep_xmpp_nodeprep)
179 # define stringprep_xmpp_resourceprep(in, maxlen) \
180 stringprep(in, maxlen, 0, stringprep_xmpp_resourceprep)
181
182 /* iSCSI */
183
184 extern IDNAPI const Stringprep_profile stringprep_iscsi[];
185 extern IDNAPI const Stringprep_table_element stringprep_iscsi_prohibit[];
186
187 # define stringprep_iscsi(in, maxlen) \
188 stringprep(in, maxlen, 0, stringprep_iscsi)
189
190 /* API */
191
192 extern IDNAPI int stringprep_4i (uint32_t * ucs4, size_t * len,
193 size_t maxucs4len,
194 Stringprep_profile_flags flags,
195 const Stringprep_profile * profile);
196 extern IDNAPI int stringprep_4zi (uint32_t * ucs4, size_t maxucs4len,
197 Stringprep_profile_flags flags,
198 const Stringprep_profile * profile);
199 extern IDNAPI int stringprep (char *in, size_t maxlen,
200 Stringprep_profile_flags flags,
201 const Stringprep_profile * profile);
202
203 extern IDNAPI int stringprep_profile (const char *in,
204 char **out,
205 const char *profile,
206 Stringprep_profile_flags flags);
207
208 extern IDNAPI const char *stringprep_strerror (Stringprep_rc rc);
209
210 extern IDNAPI const char *stringprep_check_version (const char
211 *req_version);
212
213 /* Utility */
214
215 extern IDNAPI int stringprep_unichar_to_utf8 (uint32_t c, char *outbuf);
216 extern IDNAPI uint32_t stringprep_utf8_to_unichar (const char *p);
217
218 extern IDNAPI uint32_t *stringprep_utf8_to_ucs4 (const char *str,
219 ssize_t len,
220 size_t * items_written);
221 extern IDNAPI char *stringprep_ucs4_to_utf8 (const uint32_t * str,
222 ssize_t len,
223 size_t * items_read,
224 size_t * items_written);
225
226 extern IDNAPI char *stringprep_utf8_nfkc_normalize (const char *str,
227 ssize_t len);
228 extern IDNAPI uint32_t *stringprep_ucs4_nfkc_normalize (const uint32_t * str,
229 ssize_t len);
230
231 extern IDNAPI const char *stringprep_locale_charset (void);
232 extern IDNAPI char *stringprep_convert (const char *str,
233 const char *to_codeset,
234 const char *from_codeset);
235 extern IDNAPI char *stringprep_locale_to_utf8 (const char *str);
236 extern IDNAPI char *stringprep_utf8_to_locale (const char *str);
237
238 # ifdef __cplusplus
239 }
240 # endif
241
242 #endif /* STRINGPREP_H */
stringprep_rfc3454_C_5
IDNAPI const Stringprep_table_element stringprep_rfc3454_C_5[]
Definition: rfc3454.c:3752
stringprep_4zi
IDNAPI int stringprep_4zi(uint32_t *ucs4, size_t maxucs4len, Stringprep_profile_flags flags, const Stringprep_profile *profile)
Definition: stringprep.c:327
stringprep_utf8_to_ucs4
IDNAPI uint32_t * stringprep_utf8_to_ucs4(const char *str, ssize_t len, size_t *items_written)
Definition: nfkc.c:1024
Stringprep_profile_steps
Stringprep_profile_steps
Definition: stringprep.h:86
stringprep_rfc3454_C_3
IDNAPI const Stringprep_table_element stringprep_rfc3454_C_3[]
Definition: rfc3454.c:3709
STRINGPREP_FLAG_ERROR
Definition: stringprep.h:69
stringprep_profile
IDNAPI int stringprep_profile(const char *in, char **out, const char *profile, Stringprep_profile_flags flags)
Definition: stringprep.c:447
STRINGPREP_BIDI_BOTH_L_AND_RAL
Definition: stringprep.h:63
STRINGPREP_BIDI_L_TABLE
Definition: stringprep.h:95
STRINGPREP_PROHIBIT_TABLE
Definition: stringprep.h:92
STRINGPREP_NFKC
Definition: stringprep.h:88
stringprep_rfc3454_C_7
IDNAPI const Stringprep_table_element stringprep_rfc3454_C_7[]
Definition: rfc3454.c:3778
stringprep_rfc3454_C_4
IDNAPI const Stringprep_table_element stringprep_rfc3454_C_4[]
Definition: rfc3454.c:3723
stringprep_4i
IDNAPI int stringprep_4i(uint32_t *ucs4, size_t *len, size_t maxucs4len, Stringprep_profile_flags flags, const Stringprep_profile *profile)
Definition: stringprep.c:146
Stringprep_table::table
const Stringprep_table_element * table
Definition: stringprep.h:112
stringprep_convert
IDNAPI char * stringprep_convert(const char *str, const char *to_codeset, const char *from_codeset)
Definition: toutf8.c:116
STRINGPREP_CONTAINS_PROHIBITED
Definition: stringprep.h:62
Stringprep_profile_flags
Stringprep_profile_flags
Definition: stringprep.h:78
STRINGPREP_NO_BIDI
Definition: stringprep.h:81
STRINGPREP_UNASSIGNED_TABLE
Definition: stringprep.h:91
STRINGPREP_PROFILE_ERROR
Definition: stringprep.h:68
stringprep_xmpp_resourceprep
#define stringprep_xmpp_resourceprep(in, maxlen)
Definition: stringprep.h:179
STRINGPREP_BIDI_RAL_TABLE
Definition: stringprep.h:94
stringprep_rfc3454_B_2
IDNAPI const Stringprep_table_element stringprep_rfc3454_B_2[]
Definition: rfc3454.c:456
stringprep_rfc3454_D_1
IDNAPI const Stringprep_table_element stringprep_rfc3454_D_1[]
Definition: rfc3454.c:3846
STRINGPREP_TOO_SMALL_BUFFER
Definition: stringprep.h:67
stringprep
IDNAPI int stringprep(char *in, size_t maxlen, Stringprep_profile_flags flags, const Stringprep_profile *profile)
Definition: stringprep.c:367
STRINGPREP_BIDI_PROHIBIT_TABLE
Definition: stringprep.h:93
stringprep_profiles
IDNAPI const Stringprep_profiles stringprep_profiles[]
Definition: profiles.c:33
stringprep_trace
IDNAPI const Stringprep_profile stringprep_trace[]
Definition: profiles.c:169
stringprep_rfc3454_C_1_2
IDNAPI const Stringprep_table_element stringprep_rfc3454_C_1_2[]
Definition: rfc3454.c:3524
stringprep_utf8_nfkc_normalize
IDNAPI char * stringprep_utf8_nfkc_normalize(const char *str, ssize_t len)
Definition: nfkc.c:1087
stringprep_saslprep_space_map
IDNAPI const Stringprep_table_element stringprep_saslprep_space_map[]
Definition: profiles.c:280
Stringprep_table_element::start
uint32_t start
Definition: stringprep.h:102
stringprep_locale_to_utf8
IDNAPI char * stringprep_locale_to_utf8(const char *str)
Definition: toutf8.c:143
stringprep_rfc3454_C_8
IDNAPI const Stringprep_table_element stringprep_rfc3454_C_8[]
Definition: rfc3454.c:3791
STRINGPREP_MALLOC_ERROR
Definition: stringprep.h:74
STRINGPREP_CONTAINS_UNASSIGNED
Definition: stringprep.h:61
STRINGPREP_BIDI_CONTAINS_PROHIBITED
Definition: stringprep.h:65
stringprep_kerberos5
#define stringprep_kerberos5(in, maxlen)
Definition: stringprep.h:168
stringprep_check_version
IDNAPI const char * stringprep_check_version(const char *req_version)
Definition: version.c:53
Stringprep_profiles::tables
const Stringprep_profile * tables
Definition: stringprep.h:119
STRINGPREP_NFKC_FAILED
Definition: stringprep.h:73
stringprep_utf8_to_locale
IDNAPI char * stringprep_utf8_to_locale(const char *str)
Definition: toutf8.c:159
stringprep_utf8_to_unichar
IDNAPI uint32_t stringprep_utf8_to_unichar(const char *p)
Definition: nfkc.c:983
stringprep_iscsi
#define stringprep_iscsi(in, maxlen)
Definition: stringprep.h:187
stringprep_plain
#define stringprep_plain(in, maxlen)
Definition: stringprep.h:161
Stringprep_table_element::end
uint32_t end
Definition: stringprep.h:103
stringprep_rfc3454_C_6
IDNAPI const Stringprep_table_element stringprep_rfc3454_C_6[]
Definition: rfc3454.c:3763
stringprep_rfc3454_C_2_2
IDNAPI const Stringprep_table_element stringprep_rfc3454_C_2_2[]
Definition: rfc3454.c:3682
stringprep_rfc3454_B_1
IDNAPI const Stringprep_table_element stringprep_rfc3454_B_1[]
Definition: rfc3454.c:419
stringprep_strerror
IDNAPI const char * stringprep_strerror(Stringprep_rc rc)
Definition: strerror-stringprep.c:78
stringprep_rfc3454_D_2
IDNAPI const Stringprep_table_element stringprep_rfc3454_D_2[]
Definition: rfc3454.c:3890
STRINGPREP_BIDI
Definition: stringprep.h:89
Stringprep_table_element
Definition: stringprep.h:100
STRINGPREP_MAX_MAP_CHARS
#define STRINGPREP_MAX_MAP_CHARS
Definition: stringprep.h:98
Stringprep_rc
Stringprep_rc
Definition: stringprep.h:57
stringprep_locale_charset
IDNAPI const char * stringprep_locale_charset(void)
Definition: toutf8.c:85
STRINGPREP_OK
Definition: stringprep.h:59
stringprep_xmpp_nodeprep
#define stringprep_xmpp_nodeprep(in, maxlen)
Definition: stringprep.h:177
stringprep_nameprep
#define stringprep_nameprep(in, maxlen)
Definition: stringprep.h:148
Stringprep_table::flags
Stringprep_profile_flags flags
Definition: stringprep.h:111
stringprep_rfc3454_A_1
IDNAPI const Stringprep_table_element stringprep_rfc3454_A_1[]
Definition: rfc3454.c:13
STRINGPREP_NO_NFKC
Definition: stringprep.h:80
STRINGPREP_ICONV_ERROR
Definition: stringprep.h:71
Stringprep_profiles::name
const char * name
Definition: stringprep.h:118
stringprep_rfc3454_C_9
IDNAPI const Stringprep_table_element stringprep_rfc3454_C_9[]
Definition: rfc3454.c:3834
stringprep_ucs4_to_utf8
IDNAPI char * stringprep_ucs4_to_utf8(const uint32_t *str, ssize_t len, size_t *items_read, size_t *items_written)
Definition: nfkc.c:1057
stringprep_iscsi_prohibit
IDNAPI const Stringprep_table_element stringprep_iscsi_prohibit[]
Definition: profiles.c:185
stringprep_rfc3454_C_1_1
IDNAPI const Stringprep_table_element stringprep_rfc3454_C_1_1[]
Definition: rfc3454.c:3473
Stringprep_profiles
Definition: stringprep.h:116
Stringprep_table
Definition: stringprep.h:108
Stringprep_table_element::map
uint32_t map[STRINGPREP_MAX_MAP_CHARS]
Definition: stringprep.h:104
STRINGPREP_MAP_TABLE
Definition: stringprep.h:90
stringprep_xmpp_nodeprep_prohibit
IDNAPI const Stringprep_table_element stringprep_xmpp_nodeprep_prohibit[]
Definition: profiles.c:94
IDNAPI
#define IDNAPI
Definition: stringprep.h:41
stringprep_unichar_to_utf8
IDNAPI int stringprep_unichar_to_utf8(uint32_t c, char *outbuf)
Definition: nfkc.c:1000
STRINGPREP_NO_UNASSIGNED
Definition: stringprep.h:82
STRINGPREP_BIDI_LEADTRAIL_NOT_RAL
Definition: stringprep.h:64
STRINGPREP_UNKNOWN_PROFILE
Definition: stringprep.h:70
stringprep_saslprep
IDNAPI const Stringprep_profile stringprep_saslprep[]
Definition: profiles.c:301
stringprep_rfc3454_C_2_1
IDNAPI const Stringprep_table_element stringprep_rfc3454_C_2_1[]
Definition: rfc3454.c:3609
Stringprep_table::operation
Stringprep_profile_steps operation
Definition: stringprep.h:110
stringprep_rfc3454_B_3
IDNAPI const Stringprep_table_element stringprep_rfc3454_B_3[]
Definition: rfc3454.c:2484
stringprep_ucs4_nfkc_normalize
IDNAPI uint32_t * stringprep_ucs4_nfkc_normalize(const uint32_t *str, ssize_t len)
Definition: nfkc.c:1114