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