1 // © 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 3 /* 4 ******************************************************************************* 5 * 6 * Copyright (C) 2003-2014, International Business Machines 7 * Corporation and others. All Rights Reserved. 8 * 9 ******************************************************************************* 10 * file name: usprep.h 11 * encoding: UTF-8 12 * tab size: 8 (not used) 13 * indentation:4 14 * 15 * created on: 2003jul2 16 * created by: Ram Viswanadha 17 */ 18 19 #ifndef __USPREP_H__ 20 #define __USPREP_H__ 21 22 /** 23 * \file 24 * \brief C API: Implements the StringPrep algorithm. 25 */ 26 27 #include "unicode/utypes.h" 28 29 #if U_SHOW_CPLUSPLUS_API 30 #include "unicode/localpointer.h" 31 #endif // U_SHOW_CPLUSPLUS_API 32 33 /** 34 * 35 * StringPrep API implements the StingPrep framework as described by RFC 3454. 36 * StringPrep prepares Unicode strings for use in network protocols. 37 * Profiles of StingPrep are set of rules and data according to with the 38 * Unicode Strings are prepared. Each profiles contains tables which describe 39 * how a code point should be treated. The tables are broadly classified into 40 * <ul> 41 * <li> Unassigned Table: Contains code points that are unassigned 42 * in the Unicode Version supported by StringPrep. Currently 43 * RFC 3454 supports Unicode 3.2. </li> 44 * <li> Prohibited Table: Contains code points that are prohibited from 45 * the output of the StringPrep processing function. </li> 46 * <li> Mapping Table: Contains code points that are deleted from the output or case mapped. </li> 47 * </ul> 48 * 49 * The procedure for preparing Unicode strings: 50 * <ol> 51 * <li> Map: For each character in the input, check if it has a mapping 52 * and, if so, replace it with its mapping. </li> 53 * <li> Normalize: Possibly normalize the result of step 1 using Unicode 54 * normalization. </li> 55 * <li> Prohibit: Check for any characters that are not allowed in the 56 * output. If any are found, return an error.</li> 57 * <li> Check bidi: Possibly check for right-to-left characters, and if 58 * any are found, make sure that the whole string satisfies the 59 * requirements for bidirectional strings. If the string does not 60 * satisfy the requirements for bidirectional strings, return an 61 * error. </li> 62 * </ol> 63 * @author Ram Viswanadha 64 */ 65 #if !UCONFIG_NO_IDNA 66 67 #include "unicode/parseerr.h" 68 69 /** 70 * The StringPrep profile 71 * @stable ICU 2.8 72 */ 73 typedef struct UStringPrepProfile UStringPrepProfile; 74 75 76 /** 77 * Option to prohibit processing of unassigned code points in the input 78 * 79 * @see usprep_prepare 80 * @stable ICU 2.8 81 */ 82 #define USPREP_DEFAULT 0x0000 83 84 /** 85 * Option to allow processing of unassigned code points in the input 86 * 87 * @see usprep_prepare 88 * @stable ICU 2.8 89 */ 90 #define USPREP_ALLOW_UNASSIGNED 0x0001 91 92 /** 93 * enums for the standard stringprep profile types 94 * supported by usprep_openByType. 95 * @see usprep_openByType 96 * @stable ICU 4.2 97 */ 98 typedef enum UStringPrepProfileType { 99 /** 100 * RFC3491 Nameprep 101 * @stable ICU 4.2 102 */ 103 USPREP_RFC3491_NAMEPREP, 104 /** 105 * RFC3530 nfs4_cs_prep 106 * @stable ICU 4.2 107 */ 108 USPREP_RFC3530_NFS4_CS_PREP, 109 /** 110 * RFC3530 nfs4_cs_prep with case insensitive option 111 * @stable ICU 4.2 112 */ 113 USPREP_RFC3530_NFS4_CS_PREP_CI, 114 /** 115 * RFC3530 nfs4_cis_prep 116 * @stable ICU 4.2 117 */ 118 USPREP_RFC3530_NFS4_CIS_PREP, 119 /** 120 * RFC3530 nfs4_mixed_prep for prefix 121 * @stable ICU 4.2 122 */ 123 USPREP_RFC3530_NFS4_MIXED_PREP_PREFIX, 124 /** 125 * RFC3530 nfs4_mixed_prep for suffix 126 * @stable ICU 4.2 127 */ 128 USPREP_RFC3530_NFS4_MIXED_PREP_SUFFIX, 129 /** 130 * RFC3722 iSCSI 131 * @stable ICU 4.2 132 */ 133 USPREP_RFC3722_ISCSI, 134 /** 135 * RFC3920 XMPP Nodeprep 136 * @stable ICU 4.2 137 */ 138 USPREP_RFC3920_NODEPREP, 139 /** 140 * RFC3920 XMPP Resourceprep 141 * @stable ICU 4.2 142 */ 143 USPREP_RFC3920_RESOURCEPREP, 144 /** 145 * RFC4011 Policy MIB Stringprep 146 * @stable ICU 4.2 147 */ 148 USPREP_RFC4011_MIB, 149 /** 150 * RFC4013 SASLprep 151 * @stable ICU 4.2 152 */ 153 USPREP_RFC4013_SASLPREP, 154 /** 155 * RFC4505 trace 156 * @stable ICU 4.2 157 */ 158 USPREP_RFC4505_TRACE, 159 /** 160 * RFC4518 LDAP 161 * @stable ICU 4.2 162 */ 163 USPREP_RFC4518_LDAP, 164 /** 165 * RFC4518 LDAP for case ignore, numeric and stored prefix 166 * matching rules 167 * @stable ICU 4.2 168 */ 169 USPREP_RFC4518_LDAP_CI 170 } UStringPrepProfileType; 171 172 /** 173 * Creates a StringPrep profile from the data file. 174 * 175 * @param path string containing the full path pointing to the directory 176 * where the profile reside followed by the package name 177 * e.g. "/usr/resource/my_app/profiles/mydata" on a Unix system. 178 * if NULL, ICU default data files will be used. 179 * @param fileName name of the profile file to be opened 180 * @param status ICU error code in/out parameter. Must not be NULL. 181 * Must fulfill U_SUCCESS before the function call. 182 * @return Pointer to UStringPrepProfile that is opened. Should be closed by 183 * calling usprep_close() 184 * @see usprep_close() 185 * @stable ICU 2.8 186 */ 187 U_CAPI UStringPrepProfile* U_EXPORT2 188 usprep_open(const char* path, 189 const char* fileName, 190 UErrorCode* status); 191 192 /** 193 * Creates a StringPrep profile for the specified profile type. 194 * 195 * @param type The profile type 196 * @param status ICU error code in/out parameter. Must not be NULL. 197 * Must fulfill U_SUCCESS before the function call. 198 * @return Pointer to UStringPrepProfile that is opened. Should be closed by 199 * calling usprep_close() 200 * @see usprep_close() 201 * @stable ICU 4.2 202 */ 203 U_CAPI UStringPrepProfile* U_EXPORT2 204 usprep_openByType(UStringPrepProfileType type, 205 UErrorCode* status); 206 207 /** 208 * Closes the profile 209 * @param profile The profile to close 210 * @stable ICU 2.8 211 */ 212 U_CAPI void U_EXPORT2 213 usprep_close(UStringPrepProfile* profile); 214 215 #if U_SHOW_CPLUSPLUS_API 216 217 U_NAMESPACE_BEGIN 218 219 /** 220 * \class LocalUStringPrepProfilePointer 221 * "Smart pointer" class, closes a UStringPrepProfile via usprep_close(). 222 * For most methods see the LocalPointerBase base class. 223 * 224 * @see LocalPointerBase 225 * @see LocalPointer 226 * @stable ICU 4.4 227 */ 228 U_DEFINE_LOCAL_OPEN_POINTER(LocalUStringPrepProfilePointer, UStringPrepProfile, usprep_close); 229 230 U_NAMESPACE_END 231 232 #endif 233 234 /** 235 * Prepare the input buffer for use in applications with the given profile. This operation maps, normalizes(NFKC), 236 * checks for prohibited and BiDi characters in the order defined by RFC 3454 237 * depending on the options specified in the profile. 238 * 239 * @param prep The profile to use 240 * @param src Pointer to UChar buffer containing the string to prepare 241 * @param srcLength Number of characters in the source string 242 * @param dest Pointer to the destination buffer to receive the output 243 * @param destCapacity The capacity of destination array 244 * @param options A bit set of options: 245 * 246 * - USPREP_DEFAULT Prohibit processing of unassigned code points in the input 247 * 248 * - USPREP_ALLOW_UNASSIGNED Treat the unassigned code points are in the input 249 * as normal Unicode code points. 250 * 251 * @param parseError Pointer to UParseError struct to receive information on position 252 * of error if an error is encountered. Can be NULL. 253 * @param status ICU in/out error code parameter. 254 * U_INVALID_CHAR_FOUND if src contains 255 * unmatched single surrogates. 256 * U_INDEX_OUTOFBOUNDS_ERROR if src contains 257 * too many code points. 258 * U_BUFFER_OVERFLOW_ERROR if destCapacity is not enough 259 * @return The number of UChars in the destination buffer 260 * @stable ICU 2.8 261 */ 262 263 U_CAPI int32_t U_EXPORT2 264 usprep_prepare( const UStringPrepProfile* prep, 265 const UChar* src, int32_t srcLength, 266 UChar* dest, int32_t destCapacity, 267 int32_t options, 268 UParseError* parseError, 269 UErrorCode* status ); 270 271 272 #endif /* #if !UCONFIG_NO_IDNA */ 273 274 #endif 275