1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/common/unicode/usprep.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,269 @@ 1.4 +/* 1.5 + ******************************************************************************* 1.6 + * 1.7 + * Copyright (C) 2003-2010, International Business Machines 1.8 + * Corporation and others. All Rights Reserved. 1.9 + * 1.10 + ******************************************************************************* 1.11 + * file name: usprep.h 1.12 + * encoding: US-ASCII 1.13 + * tab size: 8 (not used) 1.14 + * indentation:4 1.15 + * 1.16 + * created on: 2003jul2 1.17 + * created by: Ram Viswanadha 1.18 + */ 1.19 + 1.20 +#ifndef __USPREP_H__ 1.21 +#define __USPREP_H__ 1.22 + 1.23 +/** 1.24 + * \file 1.25 + * \brief C API: Implements the StringPrep algorithm. 1.26 + */ 1.27 + 1.28 +#include "unicode/utypes.h" 1.29 +#include "unicode/localpointer.h" 1.30 + 1.31 +/** 1.32 + * 1.33 + * StringPrep API implements the StingPrep framework as described by RFC 3454. 1.34 + * StringPrep prepares Unicode strings for use in network protocols. 1.35 + * Profiles of StingPrep are set of rules and data according to with the 1.36 + * Unicode Strings are prepared. Each profiles contains tables which describe 1.37 + * how a code point should be treated. The tables are broadly classied into 1.38 + * <ul> 1.39 + * <li> Unassinged Table: Contains code points that are unassigned 1.40 + * in the Unicode Version supported by StringPrep. Currently 1.41 + * RFC 3454 supports Unicode 3.2. </li> 1.42 + * <li> Prohibited Table: Contains code points that are prohibted from 1.43 + * the output of the StringPrep processing function. </li> 1.44 + * <li> Mapping Table: Contains code ponts that are deleted from the output or case mapped. </li> 1.45 + * </ul> 1.46 + * 1.47 + * The procedure for preparing Unicode strings: 1.48 + * <ol> 1.49 + * <li> Map: For each character in the input, check if it has a mapping 1.50 + * and, if so, replace it with its mapping. </li> 1.51 + * <li> Normalize: Possibly normalize the result of step 1 using Unicode 1.52 + * normalization. </li> 1.53 + * <li> Prohibit: Check for any characters that are not allowed in the 1.54 + * output. If any are found, return an error.</li> 1.55 + * <li> Check bidi: Possibly check for right-to-left characters, and if 1.56 + * any are found, make sure that the whole string satisfies the 1.57 + * requirements for bidirectional strings. If the string does not 1.58 + * satisfy the requirements for bidirectional strings, return an 1.59 + * error. </li> 1.60 + * </ol> 1.61 + * @author Ram Viswanadha 1.62 + */ 1.63 +#if !UCONFIG_NO_IDNA 1.64 + 1.65 +#include "unicode/parseerr.h" 1.66 + 1.67 +/** 1.68 + * The StringPrep profile 1.69 + * @stable ICU 2.8 1.70 + */ 1.71 +typedef struct UStringPrepProfile UStringPrepProfile; 1.72 + 1.73 + 1.74 +/** 1.75 + * Option to prohibit processing of unassigned code points in the input 1.76 + * 1.77 + * @see usprep_prepare 1.78 + * @stable ICU 2.8 1.79 + */ 1.80 +#define USPREP_DEFAULT 0x0000 1.81 + 1.82 +/** 1.83 + * Option to allow processing of unassigned code points in the input 1.84 + * 1.85 + * @see usprep_prepare 1.86 + * @stable ICU 2.8 1.87 + */ 1.88 +#define USPREP_ALLOW_UNASSIGNED 0x0001 1.89 + 1.90 +/** 1.91 + * enums for the standard stringprep profile types 1.92 + * supported by usprep_openByType. 1.93 + * @see usprep_openByType 1.94 + * @stable ICU 4.2 1.95 + */ 1.96 +typedef enum UStringPrepProfileType { 1.97 + /** 1.98 + * RFC3491 Nameprep 1.99 + * @stable ICU 4.2 1.100 + */ 1.101 + USPREP_RFC3491_NAMEPREP, 1.102 + /** 1.103 + * RFC3530 nfs4_cs_prep 1.104 + * @stable ICU 4.2 1.105 + */ 1.106 + USPREP_RFC3530_NFS4_CS_PREP, 1.107 + /** 1.108 + * RFC3530 nfs4_cs_prep with case insensitive option 1.109 + * @stable ICU 4.2 1.110 + */ 1.111 + USPREP_RFC3530_NFS4_CS_PREP_CI, 1.112 + /** 1.113 + * RFC3530 nfs4_cis_prep 1.114 + * @stable ICU 4.2 1.115 + */ 1.116 + USPREP_RFC3530_NFS4_CIS_PREP, 1.117 + /** 1.118 + * RFC3530 nfs4_mixed_prep for prefix 1.119 + * @stable ICU 4.2 1.120 + */ 1.121 + USPREP_RFC3530_NFS4_MIXED_PREP_PREFIX, 1.122 + /** 1.123 + * RFC3530 nfs4_mixed_prep for suffix 1.124 + * @stable ICU 4.2 1.125 + */ 1.126 + USPREP_RFC3530_NFS4_MIXED_PREP_SUFFIX, 1.127 + /** 1.128 + * RFC3722 iSCSI 1.129 + * @stable ICU 4.2 1.130 + */ 1.131 + USPREP_RFC3722_ISCSI, 1.132 + /** 1.133 + * RFC3920 XMPP Nodeprep 1.134 + * @stable ICU 4.2 1.135 + */ 1.136 + USPREP_RFC3920_NODEPREP, 1.137 + /** 1.138 + * RFC3920 XMPP Resourceprep 1.139 + * @stable ICU 4.2 1.140 + */ 1.141 + USPREP_RFC3920_RESOURCEPREP, 1.142 + /** 1.143 + * RFC4011 Policy MIB Stringprep 1.144 + * @stable ICU 4.2 1.145 + */ 1.146 + USPREP_RFC4011_MIB, 1.147 + /** 1.148 + * RFC4013 SASLprep 1.149 + * @stable ICU 4.2 1.150 + */ 1.151 + USPREP_RFC4013_SASLPREP, 1.152 + /** 1.153 + * RFC4505 trace 1.154 + * @stable ICU 4.2 1.155 + */ 1.156 + USPREP_RFC4505_TRACE, 1.157 + /** 1.158 + * RFC4518 LDAP 1.159 + * @stable ICU 4.2 1.160 + */ 1.161 + USPREP_RFC4518_LDAP, 1.162 + /** 1.163 + * RFC4518 LDAP for case ignore, numeric and stored prefix 1.164 + * matching rules 1.165 + * @stable ICU 4.2 1.166 + */ 1.167 + USPREP_RFC4518_LDAP_CI 1.168 +} UStringPrepProfileType; 1.169 + 1.170 +/** 1.171 + * Creates a StringPrep profile from the data file. 1.172 + * 1.173 + * @param path string containing the full path pointing to the directory 1.174 + * where the profile reside followed by the package name 1.175 + * e.g. "/usr/resource/my_app/profiles/mydata" on a Unix system. 1.176 + * if NULL, ICU default data files will be used. 1.177 + * @param fileName name of the profile file to be opened 1.178 + * @param status ICU error code in/out parameter. Must not be NULL. 1.179 + * Must fulfill U_SUCCESS before the function call. 1.180 + * @return Pointer to UStringPrepProfile that is opened. Should be closed by 1.181 + * calling usprep_close() 1.182 + * @see usprep_close() 1.183 + * @stable ICU 2.8 1.184 + */ 1.185 +U_STABLE UStringPrepProfile* U_EXPORT2 1.186 +usprep_open(const char* path, 1.187 + const char* fileName, 1.188 + UErrorCode* status); 1.189 + 1.190 +/** 1.191 + * Creates a StringPrep profile for the specified profile type. 1.192 + * 1.193 + * @param type The profile type 1.194 + * @param status ICU error code in/out parameter. Must not be NULL. 1.195 + * Must fulfill U_SUCCESS before the function call. 1.196 + * @return Pointer to UStringPrepProfile that is opened. Should be closed by 1.197 + * calling usprep_close() 1.198 + * @see usprep_close() 1.199 + * @stable ICU 4.2 1.200 + */ 1.201 +U_STABLE UStringPrepProfile* U_EXPORT2 1.202 +usprep_openByType(UStringPrepProfileType type, 1.203 + UErrorCode* status); 1.204 + 1.205 +/** 1.206 + * Closes the profile 1.207 + * @param profile The profile to close 1.208 + * @stable ICU 2.8 1.209 + */ 1.210 +U_STABLE void U_EXPORT2 1.211 +usprep_close(UStringPrepProfile* profile); 1.212 + 1.213 +#if U_SHOW_CPLUSPLUS_API 1.214 + 1.215 +U_NAMESPACE_BEGIN 1.216 + 1.217 +/** 1.218 + * \class LocalUStringPrepProfilePointer 1.219 + * "Smart pointer" class, closes a UStringPrepProfile via usprep_close(). 1.220 + * For most methods see the LocalPointerBase base class. 1.221 + * 1.222 + * @see LocalPointerBase 1.223 + * @see LocalPointer 1.224 + * @stable ICU 4.4 1.225 + */ 1.226 +U_DEFINE_LOCAL_OPEN_POINTER(LocalUStringPrepProfilePointer, UStringPrepProfile, usprep_close); 1.227 + 1.228 +U_NAMESPACE_END 1.229 + 1.230 +#endif 1.231 + 1.232 +/** 1.233 + * Prepare the input buffer for use in applications with the given profile. This operation maps, normalizes(NFKC), 1.234 + * checks for prohited and BiDi characters in the order defined by RFC 3454 1.235 + * depending on the options specified in the profile. 1.236 + * 1.237 + * @param prep The profile to use 1.238 + * @param src Pointer to UChar buffer containing the string to prepare 1.239 + * @param srcLength Number of characters in the source string 1.240 + * @param dest Pointer to the destination buffer to receive the output 1.241 + * @param destCapacity The capacity of destination array 1.242 + * @param options A bit set of options: 1.243 + * 1.244 + * - USPREP_NONE Prohibit processing of unassigned code points in the input 1.245 + * 1.246 + * - USPREP_ALLOW_UNASSIGNED Treat the unassigned code points are in the input 1.247 + * as normal Unicode code points. 1.248 + * 1.249 + * @param parseError Pointer to UParseError struct to receive information on position 1.250 + * of error if an error is encountered. Can be NULL. 1.251 + * @param status ICU in/out error code parameter. 1.252 + * U_INVALID_CHAR_FOUND if src contains 1.253 + * unmatched single surrogates. 1.254 + * U_INDEX_OUTOFBOUNDS_ERROR if src contains 1.255 + * too many code points. 1.256 + * U_BUFFER_OVERFLOW_ERROR if destCapacity is not enough 1.257 + * @return The number of UChars in the destination buffer 1.258 + * @stable ICU 2.8 1.259 + */ 1.260 + 1.261 +U_STABLE int32_t U_EXPORT2 1.262 +usprep_prepare( const UStringPrepProfile* prep, 1.263 + const UChar* src, int32_t srcLength, 1.264 + UChar* dest, int32_t destCapacity, 1.265 + int32_t options, 1.266 + UParseError* parseError, 1.267 + UErrorCode* status ); 1.268 + 1.269 + 1.270 +#endif /* #if !UCONFIG_NO_IDNA */ 1.271 + 1.272 +#endif