jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ******************************************************************************* jpayne@69: * jpayne@69: * Copyright (C) 2003-2014, International Business Machines jpayne@69: * Corporation and others. All Rights Reserved. jpayne@69: * jpayne@69: ******************************************************************************* jpayne@69: * file name: usprep.h jpayne@69: * encoding: UTF-8 jpayne@69: * tab size: 8 (not used) jpayne@69: * indentation:4 jpayne@69: * jpayne@69: * created on: 2003jul2 jpayne@69: * created by: Ram Viswanadha jpayne@69: */ jpayne@69: jpayne@69: #ifndef __USPREP_H__ jpayne@69: #define __USPREP_H__ jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C API: Implements the StringPrep algorithm. jpayne@69: */ jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: #include "unicode/localpointer.h" jpayne@69: jpayne@69: /** jpayne@69: * jpayne@69: * StringPrep API implements the StingPrep framework as described by RFC 3454. jpayne@69: * StringPrep prepares Unicode strings for use in network protocols. jpayne@69: * Profiles of StingPrep are set of rules and data according to with the jpayne@69: * Unicode Strings are prepared. Each profiles contains tables which describe jpayne@69: * how a code point should be treated. The tables are broadly classified into jpayne@69: * jpayne@69: * jpayne@69: * The procedure for preparing Unicode strings: jpayne@69: *
    jpayne@69: *
  1. Map: For each character in the input, check if it has a mapping jpayne@69: * and, if so, replace it with its mapping.
  2. jpayne@69: *
  3. Normalize: Possibly normalize the result of step 1 using Unicode jpayne@69: * normalization.
  4. jpayne@69: *
  5. Prohibit: Check for any characters that are not allowed in the jpayne@69: * output. If any are found, return an error.
  6. jpayne@69: *
  7. Check bidi: Possibly check for right-to-left characters, and if jpayne@69: * any are found, make sure that the whole string satisfies the jpayne@69: * requirements for bidirectional strings. If the string does not jpayne@69: * satisfy the requirements for bidirectional strings, return an jpayne@69: * error.
  8. jpayne@69: *
jpayne@69: * @author Ram Viswanadha jpayne@69: */ jpayne@69: #if !UCONFIG_NO_IDNA jpayne@69: jpayne@69: #include "unicode/parseerr.h" jpayne@69: jpayne@69: /** jpayne@69: * The StringPrep profile jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: typedef struct UStringPrepProfile UStringPrepProfile; jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Option to prohibit processing of unassigned code points in the input jpayne@69: * jpayne@69: * @see usprep_prepare jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: #define USPREP_DEFAULT 0x0000 jpayne@69: jpayne@69: /** jpayne@69: * Option to allow processing of unassigned code points in the input jpayne@69: * jpayne@69: * @see usprep_prepare jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: #define USPREP_ALLOW_UNASSIGNED 0x0001 jpayne@69: jpayne@69: /** jpayne@69: * enums for the standard stringprep profile types jpayne@69: * supported by usprep_openByType. jpayne@69: * @see usprep_openByType jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: typedef enum UStringPrepProfileType { jpayne@69: /** jpayne@69: * RFC3491 Nameprep jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: USPREP_RFC3491_NAMEPREP, jpayne@69: /** jpayne@69: * RFC3530 nfs4_cs_prep jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: USPREP_RFC3530_NFS4_CS_PREP, jpayne@69: /** jpayne@69: * RFC3530 nfs4_cs_prep with case insensitive option jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: USPREP_RFC3530_NFS4_CS_PREP_CI, jpayne@69: /** jpayne@69: * RFC3530 nfs4_cis_prep jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: USPREP_RFC3530_NFS4_CIS_PREP, jpayne@69: /** jpayne@69: * RFC3530 nfs4_mixed_prep for prefix jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: USPREP_RFC3530_NFS4_MIXED_PREP_PREFIX, jpayne@69: /** jpayne@69: * RFC3530 nfs4_mixed_prep for suffix jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: USPREP_RFC3530_NFS4_MIXED_PREP_SUFFIX, jpayne@69: /** jpayne@69: * RFC3722 iSCSI jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: USPREP_RFC3722_ISCSI, jpayne@69: /** jpayne@69: * RFC3920 XMPP Nodeprep jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: USPREP_RFC3920_NODEPREP, jpayne@69: /** jpayne@69: * RFC3920 XMPP Resourceprep jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: USPREP_RFC3920_RESOURCEPREP, jpayne@69: /** jpayne@69: * RFC4011 Policy MIB Stringprep jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: USPREP_RFC4011_MIB, jpayne@69: /** jpayne@69: * RFC4013 SASLprep jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: USPREP_RFC4013_SASLPREP, jpayne@69: /** jpayne@69: * RFC4505 trace jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: USPREP_RFC4505_TRACE, jpayne@69: /** jpayne@69: * RFC4518 LDAP jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: USPREP_RFC4518_LDAP, jpayne@69: /** jpayne@69: * RFC4518 LDAP for case ignore, numeric and stored prefix jpayne@69: * matching rules jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: USPREP_RFC4518_LDAP_CI jpayne@69: } UStringPrepProfileType; jpayne@69: jpayne@69: /** jpayne@69: * Creates a StringPrep profile from the data file. jpayne@69: * jpayne@69: * @param path string containing the full path pointing to the directory jpayne@69: * where the profile reside followed by the package name jpayne@69: * e.g. "/usr/resource/my_app/profiles/mydata" on a Unix system. jpayne@69: * if NULL, ICU default data files will be used. jpayne@69: * @param fileName name of the profile file to be opened jpayne@69: * @param status ICU error code in/out parameter. Must not be NULL. jpayne@69: * Must fulfill U_SUCCESS before the function call. jpayne@69: * @return Pointer to UStringPrepProfile that is opened. Should be closed by jpayne@69: * calling usprep_close() jpayne@69: * @see usprep_close() jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: U_STABLE UStringPrepProfile* U_EXPORT2 jpayne@69: usprep_open(const char* path, jpayne@69: const char* fileName, jpayne@69: UErrorCode* status); jpayne@69: jpayne@69: /** jpayne@69: * Creates a StringPrep profile for the specified profile type. jpayne@69: * jpayne@69: * @param type The profile type jpayne@69: * @param status ICU error code in/out parameter. Must not be NULL. jpayne@69: * Must fulfill U_SUCCESS before the function call. jpayne@69: * @return Pointer to UStringPrepProfile that is opened. Should be closed by jpayne@69: * calling usprep_close() jpayne@69: * @see usprep_close() jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: U_STABLE UStringPrepProfile* U_EXPORT2 jpayne@69: usprep_openByType(UStringPrepProfileType type, jpayne@69: UErrorCode* status); jpayne@69: jpayne@69: /** jpayne@69: * Closes the profile jpayne@69: * @param profile The profile to close jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: usprep_close(UStringPrepProfile* profile); jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: /** jpayne@69: * \class LocalUStringPrepProfilePointer jpayne@69: * "Smart pointer" class, closes a UStringPrepProfile via usprep_close(). jpayne@69: * For most methods see the LocalPointerBase base class. jpayne@69: * jpayne@69: * @see LocalPointerBase jpayne@69: * @see LocalPointer jpayne@69: * @stable ICU 4.4 jpayne@69: */ jpayne@69: U_DEFINE_LOCAL_OPEN_POINTER(LocalUStringPrepProfilePointer, UStringPrepProfile, usprep_close); jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif jpayne@69: jpayne@69: /** jpayne@69: * Prepare the input buffer for use in applications with the given profile. This operation maps, normalizes(NFKC), jpayne@69: * checks for prohibited and BiDi characters in the order defined by RFC 3454 jpayne@69: * depending on the options specified in the profile. jpayne@69: * jpayne@69: * @param prep The profile to use jpayne@69: * @param src Pointer to UChar buffer containing the string to prepare jpayne@69: * @param srcLength Number of characters in the source string jpayne@69: * @param dest Pointer to the destination buffer to receive the output jpayne@69: * @param destCapacity The capacity of destination array jpayne@69: * @param options A bit set of options: jpayne@69: * jpayne@69: * - USPREP_DEFAULT Prohibit processing of unassigned code points in the input jpayne@69: * jpayne@69: * - USPREP_ALLOW_UNASSIGNED Treat the unassigned code points are in the input jpayne@69: * as normal Unicode code points. jpayne@69: * jpayne@69: * @param parseError Pointer to UParseError struct to receive information on position jpayne@69: * of error if an error is encountered. Can be NULL. jpayne@69: * @param status ICU in/out error code parameter. jpayne@69: * U_INVALID_CHAR_FOUND if src contains jpayne@69: * unmatched single surrogates. jpayne@69: * U_INDEX_OUTOFBOUNDS_ERROR if src contains jpayne@69: * too many code points. jpayne@69: * U_BUFFER_OVERFLOW_ERROR if destCapacity is not enough jpayne@69: * @return The number of UChars in the destination buffer jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: usprep_prepare( const UStringPrepProfile* prep, jpayne@69: const UChar* src, int32_t srcLength, jpayne@69: UChar* dest, int32_t destCapacity, jpayne@69: int32_t options, jpayne@69: UParseError* parseError, jpayne@69: UErrorCode* status ); jpayne@69: jpayne@69: jpayne@69: #endif /* #if !UCONFIG_NO_IDNA */ jpayne@69: jpayne@69: #endif