Ignore idn-int.h.
[libidn.git] / stringprep.h.in
blob8728fa237ef302b44d129613dd1003d18f1c0018
1 /* stringprep.h Header file for stringprep functions. -*- c -*-
2 * Copyright (C) 2002, 2003 Simon Josefsson
4 * This file is part of GNU Libidn.
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #ifndef _STRINGPREP_H
23 #define _STRINGPREP_H
25 #ifdef __cplusplus
26 extern "C"
28 #endif
30 #include <stddef.h> /* size_t */
31 #include <unistd.h> /* ssize_t */
32 #include <idn-int.h> /* uint32_t */
34 #define STRINGPREP_VERSION "@PACKAGE_VERSION@"
36 /* Error codes. */
37 enum Stringprep_rc
39 STRINGPREP_OK = 0,
40 /* Stringprep errors. */
41 STRINGPREP_CONTAINS_UNASSIGNED = 1,
42 STRINGPREP_CONTAINS_PROHIBITED = 2,
43 STRINGPREP_BIDI_BOTH_L_AND_RAL = 3,
44 STRINGPREP_BIDI_LEADTRAIL_NOT_RAL = 4,
45 STRINGPREP_BIDI_CONTAINS_PROHIBITED = 5,
46 /* Error in calling application. */
47 STRINGPREP_TOO_SMALL_BUFFER = 100,
48 STRINGPREP_PROFILE_ERROR = 101,
49 STRINGPREP_FLAG_ERROR = 102,
50 STRINGPREP_UNKNOWN_PROFILE = 103,
51 /* Internal errors. */
52 STRINGPREP_NFKC_FAILED = 200,
53 STRINGPREP_MALLOC_ERROR = 201
56 /* Flags used when calling stringprep(). */
57 enum Stringprep_profile_flags
59 STRINGPREP_NO_NFKC = 1,
60 STRINGPREP_NO_BIDI = 2,
61 STRINGPREP_NO_UNASSIGNED = 4
64 /* Steps in a stringprep profile. */
65 enum Stringprep_profile_steps
67 STRINGPREP_NFKC = 1,
68 STRINGPREP_BIDI = 2,
69 STRINGPREP_MAP_TABLE = 3,
70 STRINGPREP_UNASSIGNED_TABLE = 4,
71 STRINGPREP_PROHIBIT_TABLE = 5,
72 STRINGPREP_BIDI_PROHIBIT_TABLE = 6,
73 STRINGPREP_BIDI_RAL_TABLE = 7,
74 STRINGPREP_BIDI_L_TABLE = 8
77 #define STRINGPREP_MAX_MAP_CHARS 4
79 struct Stringprep_table_element
81 uint32_t start;
82 uint32_t end; /* 0 if only one character */
83 uint32_t map[STRINGPREP_MAX_MAP_CHARS];/* NULL if end is not 0 */
85 typedef struct Stringprep_table_element Stringprep_table_element;
87 struct Stringprep_table
89 int operation;
90 int flags;
91 Stringprep_table_element *table;
92 char *name;
94 typedef struct Stringprep_table Stringprep_profile;
96 struct Stringprep_profiles
98 char *name;
99 Stringprep_profile *tables;
101 typedef struct Stringprep_profiles Stringprep_profiles;
103 extern Stringprep_profiles stringprep_profiles[];
105 /* Profiles */
106 extern Stringprep_table_element stringprep_generic_A_1[];
107 extern Stringprep_table_element stringprep_generic_B_1[];
108 extern Stringprep_table_element stringprep_generic_B_2[];
109 extern Stringprep_table_element stringprep_generic_B_3[];
110 extern Stringprep_table_element stringprep_generic_C_1_1[];
111 extern Stringprep_table_element stringprep_generic_C_1_2[];
112 extern Stringprep_table_element stringprep_generic_C_2_1[];
113 extern Stringprep_table_element stringprep_generic_C_2_2[];
114 extern Stringprep_table_element stringprep_generic_C_3[];
115 extern Stringprep_table_element stringprep_generic_C_4[];
116 extern Stringprep_table_element stringprep_generic_C_5[];
117 extern Stringprep_table_element stringprep_generic_C_6[];
118 extern Stringprep_table_element stringprep_generic_C_7[];
119 extern Stringprep_table_element stringprep_generic_C_8[];
120 extern Stringprep_table_element stringprep_generic_C_9[];
121 extern Stringprep_table_element stringprep_generic_D_1[];
122 extern Stringprep_table_element stringprep_generic_D_2[];
124 extern Stringprep_profile stringprep_generic[];
126 #define stringprep_generic(in, maxlen) \
127 stringprep(in, maxlen, 0, stringprep_generic)
129 extern Stringprep_profile stringprep_nameprep[];
131 #define stringprep_nameprep(in, maxlen) \
132 stringprep(in, maxlen, 0, stringprep_nameprep)
134 #define stringprep_nameprep_no_unassigned(in, maxlen) \
135 stringprep(in, maxlen, STRINGPREP_NO_UNASSIGNED, stringprep_nameprep)
137 extern Stringprep_profile stringprep_saslprep[];
139 extern Stringprep_profile stringprep_kerberos5[];
141 #define stringprep_kerberos5(in, maxlen) \
142 stringprep(in, maxlen, 0, stringprep_kerberos5)
144 extern Stringprep_profile stringprep_xmpp_nodeprep[];
145 extern Stringprep_profile stringprep_xmpp_resourceprep[];
146 extern Stringprep_table_element stringprep_xmpp_nodeprep_prohibit[];
148 #define stringprep_xmpp_nodeprep(in, maxlen) \
149 stringprep(in, maxlen, 0, stringprep_xmpp_nodeprep)
150 #define stringprep_xmpp_resourceprep(in, maxlen) \
151 stringprep(in, maxlen, 0, stringprep_xmpp_resourceprep)
153 extern Stringprep_profile stringprep_plain[];
155 #define stringprep_plain(in, maxlen) \
156 stringprep(in, maxlen, 0, stringprep_plain)
158 extern Stringprep_profile stringprep_iscsi[];
160 #define stringprep_iscsi(in, maxlen) \
161 stringprep(in, maxlen, 0, stringprep_iscsi)
163 /* API */
165 extern int stringprep (char *in, size_t maxlen, int flags,
166 Stringprep_profile * profile);
168 extern int stringprep_profile (char *in, char **out,
169 char *profile, int flags);
171 extern const char *stringprep_check_version (const char *req_version);
173 /* Utility */
175 extern int stringprep_unichar_to_utf8 (uint32_t c, char *outbuf);
176 extern uint32_t stringprep_utf8_to_unichar (const char *p);
178 extern uint32_t *stringprep_utf8_to_ucs4 (const char *str, ssize_t len,
179 size_t *items_written);
180 extern char *stringprep_ucs4_to_utf8 (const uint32_t *str, ssize_t len,
181 size_t *items_read,
182 size_t *items_written);
184 extern char *stringprep_utf8_nfkc_normalize (const char *str, ssize_t len);
185 extern uint32_t *stringprep_ucs4_nfkc_normalize (uint32_t *str,
186 ssize_t len);
188 extern const char *stringprep_locale_charset (void);
189 extern char *stringprep_convert (const char *str,
190 const char *to_codeset,
191 const char *from_codeset);
192 extern char *stringprep_locale_to_utf8 (const char *str);
193 extern char *stringprep_utf8_to_locale (const char *str);
195 #ifdef __cplusplus
197 #endif
198 #endif /* _STRINGPREP_H */