2005-03-05 Roland McGrath <roland@redhat.com>
[glibc/history.git] / libidn / stringprep.h
blobdcc30b3d46b7da94e758aa52e985b51cd8961d8b
1 /* stringprep.h Header file for stringprep functions. -*- c -*-
2 * Copyright (C) 2002, 2003, 2004 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 <stdint.h> /* uint32_t */
34 #define STRINGPREP_VERSION "0.4.3"
36 /* Error codes. */
37 typedef enum
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
54 } Stringprep_rc;
56 /* Flags used when calling stringprep(). */
57 typedef enum
59 STRINGPREP_NO_NFKC = 1,
60 STRINGPREP_NO_BIDI = 2,
61 STRINGPREP_NO_UNASSIGNED = 4
62 } Stringprep_profile_flags;
64 /* Steps in a stringprep profile. */
65 typedef enum
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
75 } Stringprep_profile_steps;
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 Stringprep_profile_steps operation;
90 Stringprep_profile_flags flags;
91 const Stringprep_table_element *table;
93 typedef struct Stringprep_table Stringprep_profile;
95 struct Stringprep_profiles
97 const char *name;
98 const Stringprep_profile *tables;
100 typedef struct Stringprep_profiles Stringprep_profiles;
102 extern const Stringprep_profiles stringprep_profiles[];
104 /* Profiles */
105 extern const Stringprep_table_element stringprep_rfc3454_A_1[];
106 extern const Stringprep_table_element stringprep_rfc3454_B_1[];
107 extern const Stringprep_table_element stringprep_rfc3454_B_2[];
108 extern const Stringprep_table_element stringprep_rfc3454_B_3[];
109 extern const Stringprep_table_element stringprep_rfc3454_C_1_1[];
110 extern const Stringprep_table_element stringprep_rfc3454_C_1_2[];
111 extern const Stringprep_table_element stringprep_rfc3454_C_2_1[];
112 extern const Stringprep_table_element stringprep_rfc3454_C_2_2[];
113 extern const Stringprep_table_element stringprep_rfc3454_C_3[];
114 extern const Stringprep_table_element stringprep_rfc3454_C_4[];
115 extern const Stringprep_table_element stringprep_rfc3454_C_5[];
116 extern const Stringprep_table_element stringprep_rfc3454_C_6[];
117 extern const Stringprep_table_element stringprep_rfc3454_C_7[];
118 extern const Stringprep_table_element stringprep_rfc3454_C_8[];
119 extern const Stringprep_table_element stringprep_rfc3454_C_9[];
120 extern const Stringprep_table_element stringprep_rfc3454_D_1[];
121 extern const Stringprep_table_element stringprep_rfc3454_D_2[];
123 /* Nameprep */
125 extern const Stringprep_profile stringprep_nameprep[];
127 #define stringprep_nameprep(in, maxlen) \
128 stringprep(in, maxlen, 0, stringprep_nameprep)
130 #define stringprep_nameprep_no_unassigned(in, maxlen) \
131 stringprep(in, maxlen, STRINGPREP_NO_UNASSIGNED, stringprep_nameprep)
133 /* SASL */
135 extern const Stringprep_profile stringprep_saslprep[];
136 extern const Stringprep_profile stringprep_plain[];
137 extern const Stringprep_profile stringprep_trace[];
139 #define stringprep_plain(in, maxlen) \
140 stringprep(in, maxlen, 0, stringprep_plain)
142 /* Kerberos */
144 extern const Stringprep_profile stringprep_kerberos5[];
146 #define stringprep_kerberos5(in, maxlen) \
147 stringprep(in, maxlen, 0, stringprep_kerberos5)
149 /* XMPP */
151 extern const Stringprep_profile stringprep_xmpp_nodeprep[];
152 extern const Stringprep_profile stringprep_xmpp_resourceprep[];
153 extern const Stringprep_table_element stringprep_xmpp_nodeprep_prohibit[];
155 #define stringprep_xmpp_nodeprep(in, maxlen) \
156 stringprep(in, maxlen, 0, stringprep_xmpp_nodeprep)
157 #define stringprep_xmpp_resourceprep(in, maxlen) \
158 stringprep(in, maxlen, 0, stringprep_xmpp_resourceprep)
160 /* iSCSI */
162 extern const Stringprep_profile stringprep_iscsi[];
164 #define stringprep_iscsi(in, maxlen) \
165 stringprep(in, maxlen, 0, stringprep_iscsi)
167 /* API */
169 extern int stringprep_4i (uint32_t * ucs4, size_t * len, size_t maxucs4len,
170 Stringprep_profile_flags flags,
171 const Stringprep_profile * profile);
172 extern int stringprep_4zi (uint32_t * ucs4, size_t maxucs4len,
173 Stringprep_profile_flags flags,
174 const Stringprep_profile * profile);
175 extern int stringprep (char *in, size_t maxlen,
176 Stringprep_profile_flags flags,
177 const Stringprep_profile * profile);
179 extern int stringprep_profile (const char *in,
180 char **out,
181 const char *profile,
182 Stringprep_profile_flags flags);
184 extern const char *stringprep_check_version (const char *req_version);
186 /* Utility */
188 extern int stringprep_unichar_to_utf8 (uint32_t c, char *outbuf);
189 extern uint32_t stringprep_utf8_to_unichar (const char *p);
191 extern uint32_t *stringprep_utf8_to_ucs4 (const char *str, ssize_t len,
192 size_t * items_written);
193 extern char *stringprep_ucs4_to_utf8 (const uint32_t * str, ssize_t len,
194 size_t * items_read,
195 size_t * items_written);
197 extern char *stringprep_utf8_nfkc_normalize (const char *str, ssize_t len);
198 extern uint32_t *stringprep_ucs4_nfkc_normalize (uint32_t * str,
199 ssize_t len);
201 extern const char *stringprep_locale_charset (void);
202 extern char *stringprep_convert (const char *str,
203 const char *to_codeset,
204 const char *from_codeset);
205 extern char *stringprep_locale_to_utf8 (const char *str);
206 extern char *stringprep_utf8_to_locale (const char *str);
208 #ifdef __cplusplus
210 #endif
211 #endif /* _STRINGPREP_H */