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