2
*******************************************************************************
4
* Copyright (C) 2003-2010, International Business Machines
5
* Corporation and others. All Rights Reserved.
7
*******************************************************************************
10
* tab size: 8 (not used)
13
* created on: 2003jul2
14
* created by: Ram Viswanadha
22
* \brief C API: Implements the StringPrep algorithm.
25
#include "unicode/utypes.h"
26
#include "unicode/localpointer.h"
30
* StringPrep API implements the StingPrep framework as described by RFC 3454.
31
* StringPrep prepares Unicode strings for use in network protocols.
32
* Profiles of StingPrep are set of rules and data according to with the
33
* Unicode Strings are prepared. Each profiles contains tables which describe
34
* how a code point should be treated. The tables are broadly classied into
36
* <li> Unassinged Table: Contains code points that are unassigned
37
* in the Unicode Version supported by StringPrep. Currently
38
* RFC 3454 supports Unicode 3.2. </li>
39
* <li> Prohibited Table: Contains code points that are prohibted from
40
* the output of the StringPrep processing function. </li>
41
* <li> Mapping Table: Contains code ponts that are deleted from the output or case mapped. </li>
44
* The procedure for preparing Unicode strings:
46
* <li> Map: For each character in the input, check if it has a mapping
47
* and, if so, replace it with its mapping. </li>
48
* <li> Normalize: Possibly normalize the result of step 1 using Unicode
49
* normalization. </li>
50
* <li> Prohibit: Check for any characters that are not allowed in the
51
* output. If any are found, return an error.</li>
52
* <li> Check bidi: Possibly check for right-to-left characters, and if
53
* any are found, make sure that the whole string satisfies the
54
* requirements for bidirectional strings. If the string does not
55
* satisfy the requirements for bidirectional strings, return an
58
* @author Ram Viswanadha
62
#include "unicode/parseerr.h"
65
* The StringPrep profile
68
typedef struct UStringPrepProfile UStringPrepProfile;
72
* Option to prohibit processing of unassigned code points in the input
77
#define USPREP_DEFAULT 0x0000
80
* Option to allow processing of unassigned code points in the input
85
#define USPREP_ALLOW_UNASSIGNED 0x0001
88
* enums for the standard stringprep profile types
89
* supported by usprep_openByType.
90
* @see usprep_openByType
93
typedef enum UStringPrepProfileType {
98
USPREP_RFC3491_NAMEPREP,
100
* RFC3530 nfs4_cs_prep
103
USPREP_RFC3530_NFS4_CS_PREP,
105
* RFC3530 nfs4_cs_prep with case insensitive option
108
USPREP_RFC3530_NFS4_CS_PREP_CI,
110
* RFC3530 nfs4_cis_prep
113
USPREP_RFC3530_NFS4_CIS_PREP,
115
* RFC3530 nfs4_mixed_prep for prefix
118
USPREP_RFC3530_NFS4_MIXED_PREP_PREFIX,
120
* RFC3530 nfs4_mixed_prep for suffix
123
USPREP_RFC3530_NFS4_MIXED_PREP_SUFFIX,
128
USPREP_RFC3722_ISCSI,
130
* RFC3920 XMPP Nodeprep
133
USPREP_RFC3920_NODEPREP,
135
* RFC3920 XMPP Resourceprep
138
USPREP_RFC3920_RESOURCEPREP,
140
* RFC4011 Policy MIB Stringprep
148
USPREP_RFC4013_SASLPREP,
153
USPREP_RFC4505_TRACE,
160
* RFC4518 LDAP for case ignore, numeric and stored prefix
164
USPREP_RFC4518_LDAP_CI
165
} UStringPrepProfileType;
168
* Creates a StringPrep profile from the data file.
170
* @param path string containing the full path pointing to the directory
171
* where the profile reside followed by the package name
172
* e.g. "/usr/resource/my_app/profiles/mydata" on a Unix system.
173
* if NULL, ICU default data files will be used.
174
* @param fileName name of the profile file to be opened
175
* @param status ICU error code in/out parameter. Must not be NULL.
176
* Must fulfill U_SUCCESS before the function call.
177
* @return Pointer to UStringPrepProfile that is opened. Should be closed by
178
* calling usprep_close()
179
* @see usprep_close()
182
U_STABLE UStringPrepProfile* U_EXPORT2
183
usprep_open(const char* path,
184
const char* fileName,
188
* Creates a StringPrep profile for the specified profile type.
190
* @param type The profile type
191
* @param status ICU error code in/out parameter. Must not be NULL.
192
* Must fulfill U_SUCCESS before the function call.
193
* @return Pointer to UStringPrepProfile that is opened. Should be closed by
194
* calling usprep_close()
195
* @see usprep_close()
198
U_STABLE UStringPrepProfile* U_EXPORT2
199
usprep_openByType(UStringPrepProfileType type,
204
* @param profile The profile to close
207
U_STABLE void U_EXPORT2
208
usprep_close(UStringPrepProfile* profile);
210
#if U_SHOW_CPLUSPLUS_API
215
* \class LocalUStringPrepProfilePointer
216
* "Smart pointer" class, closes a UStringPrepProfile via usprep_close().
217
* For most methods see the LocalPointerBase base class.
219
* @see LocalPointerBase
223
U_DEFINE_LOCAL_OPEN_POINTER(LocalUStringPrepProfilePointer, UStringPrepProfile, usprep_close);
230
* Prepare the input buffer for use in applications with the given profile. This operation maps, normalizes(NFKC),
231
* checks for prohited and BiDi characters in the order defined by RFC 3454
232
* depending on the options specified in the profile.
234
* @param prep The profile to use
235
* @param src Pointer to UChar buffer containing the string to prepare
236
* @param srcLength Number of characters in the source string
237
* @param dest Pointer to the destination buffer to receive the output
238
* @param destCapacity The capacity of destination array
239
* @param options A bit set of options:
241
* - USPREP_NONE Prohibit processing of unassigned code points in the input
243
* - USPREP_ALLOW_UNASSIGNED Treat the unassigned code points are in the input
244
* as normal Unicode code points.
246
* @param parseError Pointer to UParseError struct to receive information on position
247
* of error if an error is encountered. Can be NULL.
248
* @param status ICU in/out error code parameter.
249
* U_INVALID_CHAR_FOUND if src contains
250
* unmatched single surrogates.
251
* U_INDEX_OUTOFBOUNDS_ERROR if src contains
252
* too many code points.
253
* U_BUFFER_OVERFLOW_ERROR if destCapacity is not enough
254
* @return The number of UChars in the destination buffer
258
U_STABLE int32_t U_EXPORT2
259
usprep_prepare( const UStringPrepProfile* prep,
260
const UChar* src, int32_t srcLength,
261
UChar* dest, int32_t destCapacity,
263
UParseError* parseError,
264
UErrorCode* status );
267
#endif /* #if !UCONFIG_NO_IDNA */