Use __attribute_used__.
[glibc.git] / libidn / stringprep.h
blob5f504e8e81d70e8ef950e730b510b680d2e81eb3
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 #ifdef _LIBC
33 # include <stdint.h>
34 #else
35 # include <idn-int.h> /* uint32_t */
36 #endif
38 #define STRINGPREP_VERSION "0.4.1"
40 /* Error codes. */
41 typedef enum
43 STRINGPREP_OK = 0,
44 /* Stringprep errors. */
45 STRINGPREP_CONTAINS_UNASSIGNED = 1,
46 STRINGPREP_CONTAINS_PROHIBITED = 2,
47 STRINGPREP_BIDI_BOTH_L_AND_RAL = 3,
48 STRINGPREP_BIDI_LEADTRAIL_NOT_RAL = 4,
49 STRINGPREP_BIDI_CONTAINS_PROHIBITED = 5,
50 /* Error in calling application. */
51 STRINGPREP_TOO_SMALL_BUFFER = 100,
52 STRINGPREP_PROFILE_ERROR = 101,
53 STRINGPREP_FLAG_ERROR = 102,
54 STRINGPREP_UNKNOWN_PROFILE = 103,
55 /* Internal errors. */
56 STRINGPREP_NFKC_FAILED = 200,
57 STRINGPREP_MALLOC_ERROR = 201
58 } Stringprep_rc;
60 /* Flags used when calling stringprep(). */
61 typedef enum
63 STRINGPREP_NO_NFKC = 1,
64 STRINGPREP_NO_BIDI = 2,
65 STRINGPREP_NO_UNASSIGNED = 4
66 } Stringprep_profile_flags;
68 /* Steps in a stringprep profile. */
69 typedef enum
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;
81 #define STRINGPREP_MAX_MAP_CHARS 4
83 struct Stringprep_table_element
85 uint32_t start;
86 uint32_t end; /* 0 if only one character */
87 uint32_t map[STRINGPREP_MAX_MAP_CHARS]; /* NULL if end is not 0 */
89 typedef struct Stringprep_table_element Stringprep_table_element;
91 struct Stringprep_table
93 Stringprep_profile_steps operation;
94 Stringprep_profile_flags flags;
95 const Stringprep_table_element *table;
97 typedef struct Stringprep_table Stringprep_profile;
99 struct Stringprep_profiles
101 const char *name;
102 const Stringprep_profile *tables;
104 typedef struct Stringprep_profiles Stringprep_profiles;
106 extern const Stringprep_profiles stringprep_profiles[];
108 /* Profiles */
109 extern const Stringprep_table_element stringprep_rfc3454_A_1[];
110 extern const Stringprep_table_element stringprep_rfc3454_B_1[];
111 extern const Stringprep_table_element stringprep_rfc3454_B_2[];
112 extern const Stringprep_table_element stringprep_rfc3454_B_3[];
113 extern const Stringprep_table_element stringprep_rfc3454_C_1_1[];
114 extern const Stringprep_table_element stringprep_rfc3454_C_1_2[];
115 extern const Stringprep_table_element stringprep_rfc3454_C_2_1[];
116 extern const Stringprep_table_element stringprep_rfc3454_C_2_2[];
117 extern const Stringprep_table_element stringprep_rfc3454_C_3[];
118 extern const Stringprep_table_element stringprep_rfc3454_C_4[];
119 extern const Stringprep_table_element stringprep_rfc3454_C_5[];
120 extern const Stringprep_table_element stringprep_rfc3454_C_6[];
121 extern const Stringprep_table_element stringprep_rfc3454_C_7[];
122 extern const Stringprep_table_element stringprep_rfc3454_C_8[];
123 extern const Stringprep_table_element stringprep_rfc3454_C_9[];
124 extern const Stringprep_table_element stringprep_rfc3454_D_1[];
125 extern const Stringprep_table_element stringprep_rfc3454_D_2[];
127 /* Nameprep */
129 extern const 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 /* SASL */
139 extern const Stringprep_profile stringprep_saslprep[];
140 extern const Stringprep_profile stringprep_plain[];
141 extern const Stringprep_profile stringprep_trace[];
143 #define stringprep_plain(in, maxlen) \
144 stringprep(in, maxlen, 0, stringprep_plain)
146 /* Kerberos */
148 extern const Stringprep_profile stringprep_kerberos5[];
150 #define stringprep_kerberos5(in, maxlen) \
151 stringprep(in, maxlen, 0, stringprep_kerberos5)
153 /* XMPP */
155 extern const Stringprep_profile stringprep_xmpp_nodeprep[];
156 extern const Stringprep_profile stringprep_xmpp_resourceprep[];
157 extern const Stringprep_table_element stringprep_xmpp_nodeprep_prohibit[];
159 #define stringprep_xmpp_nodeprep(in, maxlen) \
160 stringprep(in, maxlen, 0, stringprep_xmpp_nodeprep)
161 #define stringprep_xmpp_resourceprep(in, maxlen) \
162 stringprep(in, maxlen, 0, stringprep_xmpp_resourceprep)
164 /* iSCSI */
166 extern const Stringprep_profile stringprep_iscsi[];
168 #define stringprep_iscsi(in, maxlen) \
169 stringprep(in, maxlen, 0, stringprep_iscsi)
171 /* API */
173 extern int stringprep_4i (uint32_t * ucs4, size_t * len, size_t maxucs4len,
174 Stringprep_profile_flags flags,
175 const Stringprep_profile * profile);
176 extern int stringprep_4zi (uint32_t * ucs4, size_t maxucs4len,
177 Stringprep_profile_flags flags,
178 const Stringprep_profile * profile);
179 extern int stringprep (char *in, size_t maxlen,
180 Stringprep_profile_flags flags,
181 const Stringprep_profile * profile);
183 extern int stringprep_profile (const char *in,
184 char **out,
185 const char *profile,
186 Stringprep_profile_flags flags);
188 extern const char *stringprep_check_version (const char *req_version);
190 /* Utility */
192 extern int stringprep_unichar_to_utf8 (uint32_t c, char *outbuf);
193 extern uint32_t stringprep_utf8_to_unichar (const char *p);
195 extern uint32_t *stringprep_utf8_to_ucs4 (const char *str, ssize_t len,
196 size_t * items_written);
197 extern char *stringprep_ucs4_to_utf8 (const uint32_t * str, ssize_t len,
198 size_t * items_read,
199 size_t * items_written);
201 extern char *stringprep_utf8_nfkc_normalize (const char *str, ssize_t len);
202 extern uint32_t *stringprep_ucs4_nfkc_normalize (uint32_t * str,
203 ssize_t len);
205 extern const char *stringprep_locale_charset (void);
206 extern char *stringprep_convert (const char *str,
207 const char *to_codeset,
208 const char *from_codeset);
209 extern char *stringprep_locale_to_utf8 (const char *str);
210 extern char *stringprep_utf8_to_locale (const char *str);
212 #ifdef __cplusplus
214 #endif
215 #endif /* _STRINGPREP_H */