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