Add debug.
[libidn.git] / stringprep.h.in
blob58bf61f13f434c3859634ec2c2dd4a436febbdbd
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 */
33 #define STRINGPREP_VERSION "@PACKAGE_VERSION@"
35 /* Error codes. */
36 enum
38 STRINGPREP_OK = 0,
39 /* Stringprep errors. */
40 STRINGPREP_CONTAINS_UNASSIGNED = 1,
41 STRINGPREP_CONTAINS_PROHIBITED = 2,
42 STRINGPREP_BIDI_BOTH_L_AND_RAL = 3,
43 STRINGPREP_BIDI_LEADTRAIL_NOT_RAL = 4,
44 STRINGPREP_BIDI_CONTAINS_PROHIBITED = 5,
45 /* Error in calling application. */
46 STRINGPREP_TOO_SMALL_BUFFER = 100,
47 STRINGPREP_PROFILE_ERROR = 101,
48 STRINGPREP_FLAG_ERROR = 102,
49 STRINGPREP_UNKNOWN_PROFILE = 103,
50 /* Internal errors. */
51 STRINGPREP_NFKC_FAILED = 200,
52 STRINGPREP_MALLOC_ERROR = 201
53 } Stringprep_rc;
55 /* Flags used when calling stringprep(). */
56 enum
58 STRINGPREP_NO_NFKC = 1,
59 STRINGPREP_NO_BIDI = 2,
60 STRINGPREP_NO_UNASSIGNED = 4
61 } Stringprep_profile_flags;
63 /* Steps in a stringprep profile. */
64 enum
66 STRINGPREP_NFKC = 1,
67 STRINGPREP_BIDI = 2,
68 STRINGPREP_MAP_TABLE = 3,
69 STRINGPREP_UNASSIGNED_TABLE = 4,
70 STRINGPREP_PROHIBIT_TABLE = 5,
71 STRINGPREP_BIDI_PROHIBIT_TABLE = 6,
72 STRINGPREP_BIDI_RAL_TABLE = 7,
73 STRINGPREP_BIDI_L_TABLE = 8
74 } Stringprep_profile_steps;
76 #define STRINGPREP_MAX_MAP_CHARS 4
78 struct Stringprep_table_element
80 unsigned long start;
81 unsigned long end; /* 0 if only one character */
82 unsigned long map[STRINGPREP_MAX_MAP_CHARS];/* NULL if end is not 0 */
84 typedef struct Stringprep_table_element Stringprep_table_element;
86 struct Stringprep_table
88 int operation;
89 int flags;
90 Stringprep_table_element *table;
91 char *name;
93 typedef struct Stringprep_table Stringprep_profile;
95 struct Stringprep_profiles
97 char *name;
98 Stringprep_profile *tables;
100 typedef struct Stringprep_profiles Stringprep_profiles;
102 extern Stringprep_profiles stringprep_profiles[];
104 /* Profiles */
105 extern Stringprep_table_element stringprep_generic_A_1[];
106 extern Stringprep_table_element stringprep_generic_B_1[];
107 extern Stringprep_table_element stringprep_generic_B_2[];
108 extern Stringprep_table_element stringprep_generic_B_3[];
109 extern Stringprep_table_element stringprep_generic_C_1_1[];
110 extern Stringprep_table_element stringprep_generic_C_1_2[];
111 extern Stringprep_table_element stringprep_generic_C_2_1[];
112 extern Stringprep_table_element stringprep_generic_C_2_2[];
113 extern Stringprep_table_element stringprep_generic_C_3[];
114 extern Stringprep_table_element stringprep_generic_C_4[];
115 extern Stringprep_table_element stringprep_generic_C_5[];
116 extern Stringprep_table_element stringprep_generic_C_6[];
117 extern Stringprep_table_element stringprep_generic_C_7[];
118 extern Stringprep_table_element stringprep_generic_C_8[];
119 extern Stringprep_table_element stringprep_generic_C_9[];
120 extern Stringprep_table_element stringprep_generic_D_1[];
121 extern Stringprep_table_element stringprep_generic_D_2[];
123 extern Stringprep_profile stringprep_generic[];
125 #define stringprep_generic(in, maxlen) \
126 stringprep(in, maxlen, 0, stringprep_generic)
128 extern Stringprep_profile stringprep_nameprep[];
130 #define stringprep_nameprep(in, maxlen) \
131 stringprep(in, maxlen, 0, stringprep_nameprep)
133 #define stringprep_nameprep_no_unassigned(in, maxlen) \
134 stringprep(in, maxlen, STRINGPREP_NO_UNASSIGNED, stringprep_nameprep)
136 extern Stringprep_profile stringprep_saslprep[];
138 extern Stringprep_profile stringprep_kerberos5[];
140 #define stringprep_kerberos5(in, maxlen) \
141 stringprep(in, maxlen, 0, stringprep_kerberos5)
143 extern Stringprep_profile stringprep_xmpp_nodeprep[];
144 extern Stringprep_profile stringprep_xmpp_resourceprep[];
145 extern Stringprep_table_element stringprep_xmpp_nodeprep_prohibit[];
147 #define stringprep_xmpp_nodeprep(in, maxlen) \
148 stringprep(in, maxlen, 0, stringprep_xmpp_nodeprep)
149 #define stringprep_xmpp_resourceprep(in, maxlen) \
150 stringprep(in, maxlen, 0, stringprep_xmpp_resourceprep)
152 extern Stringprep_profile stringprep_plain[];
154 #define stringprep_plain(in, maxlen) \
155 stringprep(in, maxlen, 0, stringprep_plain)
157 extern Stringprep_profile stringprep_iscsi[];
159 #define stringprep_iscsi(in, maxlen) \
160 stringprep(in, maxlen, 0, stringprep_iscsi)
162 /* API */
164 extern int stringprep (char *in, size_t maxlen, int flags,
165 Stringprep_profile * profile);
167 extern int stringprep_profile (char *in, char **out,
168 char *profile, int flags);
170 extern const char *stringprep_check_version (const char *req_version);
172 /* Utility */
174 extern int stringprep_unichar_to_utf8 (unsigned long c, char *outbuf);
175 extern unsigned long stringprep_utf8_to_unichar (const char *p);
177 extern unsigned long *stringprep_utf8_to_ucs4 (const char *str, ssize_t len,
178 size_t *items_written);
179 extern char *stringprep_ucs4_to_utf8 (const unsigned long *str, ssize_t len,
180 size_t *items_read,
181 size_t *items_written);
183 extern char *stringprep_utf8_nfkc_normalize (const char *str, ssize_t len);
184 extern unsigned long *stringprep_ucs4_nfkc_normalize (unsigned long *str,
185 ssize_t len);
187 extern const char *stringprep_locale_charset (void);
188 extern char *stringprep_convert (const char *str,
189 const char *to_codeset,
190 const char *from_codeset);
191 extern char *stringprep_locale_to_utf8 (const char *str);
192 extern char *stringprep_utf8_to_locale (const char *str);
194 #ifdef __cplusplus
196 #endif
197 #endif /* _STRINGPREP_H */