1
/* stringprep.h --- Header file for stringprep functions. -*- c -*-
2
* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
30
#include <stddef.h> /* size_t */
31
#include <unistd.h> /* ssize_t */
32
#include <idn-int.h> /* uint32_t */
34
/* On Windows, variables that may be in a DLL must be marked
35
* specially. This is only active when not building libidn itself
36
* (!LIBIDN_BUILDING). It is only used for MinGW which declare
37
* __DECLSPEC_SUPPORTED or MSVC (_MSC_VER && _DLL). */
38
#if !defined (LIBIDN_BUILDING) && (defined(__DECLSPEC_SUPPORTED) || (defined(_MSC_VER) && defined(_DLL)))
39
# define IDN_DLL_VAR __declspec (dllimport)
44
#define STRINGPREP_VERSION "@PACKAGE_VERSION@"
50
/* Stringprep errors. */
51
STRINGPREP_CONTAINS_UNASSIGNED = 1,
52
STRINGPREP_CONTAINS_PROHIBITED = 2,
53
STRINGPREP_BIDI_BOTH_L_AND_RAL = 3,
54
STRINGPREP_BIDI_LEADTRAIL_NOT_RAL = 4,
55
STRINGPREP_BIDI_CONTAINS_PROHIBITED = 5,
56
/* Error in calling application. */
57
STRINGPREP_TOO_SMALL_BUFFER = 100,
58
STRINGPREP_PROFILE_ERROR = 101,
59
STRINGPREP_FLAG_ERROR = 102,
60
STRINGPREP_UNKNOWN_PROFILE = 103,
61
/* Internal errors. */
62
STRINGPREP_NFKC_FAILED = 200,
63
STRINGPREP_MALLOC_ERROR = 201
66
/* Flags used when calling stringprep(). */
69
STRINGPREP_NO_NFKC = 1,
70
STRINGPREP_NO_BIDI = 2,
71
STRINGPREP_NO_UNASSIGNED = 4
72
} Stringprep_profile_flags;
74
/* Steps in a stringprep profile. */
79
STRINGPREP_MAP_TABLE = 3,
80
STRINGPREP_UNASSIGNED_TABLE = 4,
81
STRINGPREP_PROHIBIT_TABLE = 5,
82
STRINGPREP_BIDI_PROHIBIT_TABLE = 6,
83
STRINGPREP_BIDI_RAL_TABLE = 7,
84
STRINGPREP_BIDI_L_TABLE = 8
85
} Stringprep_profile_steps;
87
#define STRINGPREP_MAX_MAP_CHARS 4
89
struct Stringprep_table_element
92
uint32_t end; /* 0 if only one character */
93
uint32_t map[STRINGPREP_MAX_MAP_CHARS]; /* NULL if end is not 0 */
95
typedef struct Stringprep_table_element Stringprep_table_element;
97
struct Stringprep_table
99
Stringprep_profile_steps operation;
100
Stringprep_profile_flags flags;
101
const Stringprep_table_element *table;
103
typedef struct Stringprep_table Stringprep_profile;
105
struct Stringprep_profiles
108
const Stringprep_profile *tables;
110
typedef struct Stringprep_profiles Stringprep_profiles;
112
extern IDN_DLL_VAR const Stringprep_profiles stringprep_profiles[];
115
extern IDN_DLL_VAR const Stringprep_table_element stringprep_rfc3454_A_1[];
116
extern IDN_DLL_VAR const Stringprep_table_element stringprep_rfc3454_B_1[];
117
extern IDN_DLL_VAR const Stringprep_table_element stringprep_rfc3454_B_2[];
118
extern IDN_DLL_VAR const Stringprep_table_element stringprep_rfc3454_B_3[];
119
extern IDN_DLL_VAR const Stringprep_table_element stringprep_rfc3454_C_1_1[];
120
extern IDN_DLL_VAR const Stringprep_table_element stringprep_rfc3454_C_1_2[];
121
extern IDN_DLL_VAR const Stringprep_table_element stringprep_rfc3454_C_2_1[];
122
extern IDN_DLL_VAR const Stringprep_table_element stringprep_rfc3454_C_2_2[];
123
extern IDN_DLL_VAR const Stringprep_table_element stringprep_rfc3454_C_3[];
124
extern IDN_DLL_VAR const Stringprep_table_element stringprep_rfc3454_C_4[];
125
extern IDN_DLL_VAR const Stringprep_table_element stringprep_rfc3454_C_5[];
126
extern IDN_DLL_VAR const Stringprep_table_element stringprep_rfc3454_C_6[];
127
extern IDN_DLL_VAR const Stringprep_table_element stringprep_rfc3454_C_7[];
128
extern IDN_DLL_VAR const Stringprep_table_element stringprep_rfc3454_C_8[];
129
extern IDN_DLL_VAR const Stringprep_table_element stringprep_rfc3454_C_9[];
130
extern IDN_DLL_VAR const Stringprep_table_element stringprep_rfc3454_D_1[];
131
extern IDN_DLL_VAR const Stringprep_table_element stringprep_rfc3454_D_2[];
135
extern IDN_DLL_VAR const Stringprep_profile stringprep_nameprep[];
137
#define stringprep_nameprep(in, maxlen) \
138
stringprep(in, maxlen, 0, stringprep_nameprep)
140
#define stringprep_nameprep_no_unassigned(in, maxlen) \
141
stringprep(in, maxlen, STRINGPREP_NO_UNASSIGNED, stringprep_nameprep)
145
extern IDN_DLL_VAR const Stringprep_profile stringprep_saslprep[];
146
extern IDN_DLL_VAR const Stringprep_profile stringprep_plain[];
147
extern IDN_DLL_VAR const Stringprep_profile stringprep_trace[];
149
#define stringprep_plain(in, maxlen) \
150
stringprep(in, maxlen, 0, stringprep_plain)
154
extern IDN_DLL_VAR const Stringprep_profile stringprep_kerberos5[];
156
#define stringprep_kerberos5(in, maxlen) \
157
stringprep(in, maxlen, 0, stringprep_kerberos5)
161
extern IDN_DLL_VAR const Stringprep_profile stringprep_xmpp_nodeprep[];
162
extern IDN_DLL_VAR const Stringprep_profile stringprep_xmpp_resourceprep[];
163
extern IDN_DLL_VAR const Stringprep_table_element stringprep_xmpp_nodeprep_prohibit[];
165
#define stringprep_xmpp_nodeprep(in, maxlen) \
166
stringprep(in, maxlen, 0, stringprep_xmpp_nodeprep)
167
#define stringprep_xmpp_resourceprep(in, maxlen) \
168
stringprep(in, maxlen, 0, stringprep_xmpp_resourceprep)
172
extern IDN_DLL_VAR const Stringprep_profile stringprep_iscsi[];
174
#define stringprep_iscsi(in, maxlen) \
175
stringprep(in, maxlen, 0, stringprep_iscsi)
179
extern int stringprep_4i (uint32_t * ucs4, size_t * len, size_t maxucs4len,
180
Stringprep_profile_flags flags,
181
const Stringprep_profile * profile);
182
extern int stringprep_4zi (uint32_t * ucs4, size_t maxucs4len,
183
Stringprep_profile_flags flags,
184
const Stringprep_profile * profile);
185
extern int stringprep (char *in, size_t maxlen,
186
Stringprep_profile_flags flags,
187
const Stringprep_profile * profile);
189
extern int stringprep_profile (const char *in,
192
Stringprep_profile_flags flags);
194
extern const char *stringprep_strerror (Stringprep_rc rc);
196
extern const char *stringprep_check_version (const char *req_version);
200
extern int stringprep_unichar_to_utf8 (uint32_t c, char *outbuf);
201
extern uint32_t stringprep_utf8_to_unichar (const char *p);
203
extern uint32_t *stringprep_utf8_to_ucs4 (const char *str, ssize_t len,
204
size_t * items_written);
205
extern char *stringprep_ucs4_to_utf8 (const uint32_t * str, ssize_t len,
207
size_t * items_written);
209
extern char *stringprep_utf8_nfkc_normalize (const char *str, ssize_t len);
210
extern uint32_t *stringprep_ucs4_nfkc_normalize (uint32_t * str,
213
extern const char *stringprep_locale_charset (void);
214
extern char *stringprep_convert (const char *str,
215
const char *to_codeset,
216
const char *from_codeset);
217
extern char *stringprep_locale_to_utf8 (const char *str);
218
extern char *stringprep_utf8_to_locale (const char *str);
223
#endif /* _STRINGPREP_H */