sl@0: /*
sl@0: *******************************************************************************
sl@0: *
sl@0: * Copyright (C) 2003-2005, International Business Machines
sl@0: * Corporation and others. All Rights Reserved.
sl@0: *
sl@0: *******************************************************************************
sl@0: * file name: uidna.h
sl@0: * encoding: US-ASCII
sl@0: * tab size: 8 (not used)
sl@0: * indentation:4
sl@0: *
sl@0: * created on: 2003feb1
sl@0: * created by: Ram Viswanadha
sl@0: */
sl@0:
sl@0: #ifndef __UIDNA_H__
sl@0: #define __UIDNA_H__
sl@0:
sl@0: #include "unicode/utypes.h"
sl@0:
sl@0: #if !UCONFIG_NO_IDNA
sl@0:
sl@0: #include "unicode/parseerr.h"
sl@0:
sl@0: /**
sl@0: * \file
sl@0: * \brief C API: Internationalized Domain Names in Applications Tranformation
sl@0: *
sl@0: * UIDNA API implements the IDNA protocol as defined in the IDNA RFC
sl@0: * (http://www.ietf.org/rfc/rfc3490.txt).
sl@0: * The RFC defines 2 operations: ToASCII and ToUnicode. Domain labels
sl@0: * containing non-ASCII code points are required to be processed by
sl@0: * ToASCII operation before passing it to resolver libraries. Domain names
sl@0: * that are obtained from resolver libraries are required to be processed by
sl@0: * ToUnicode operation before displaying the domain name to the user.
sl@0: * IDNA requires that implementations process input strings with Nameprep
sl@0: * (http://www.ietf.org/rfc/rfc3491.txt),
sl@0: * which is a profile of Stringprep (http://www.ietf.org/rfc/rfc3454.txt),
sl@0: * and then with Punycode (http://www.ietf.org/rfc/rfc3492.txt).
sl@0: * Implementations of IDNA MUST fully implement Nameprep and Punycode;
sl@0: * neither Nameprep nor Punycode are optional.
sl@0: * The input and output of ToASCII and ToUnicode operations are Unicode
sl@0: * and are designed to be chainable, i.e., applying ToASCII or ToUnicode operations
sl@0: * multiple times to an input string will yield the same result as applying the operation
sl@0: * once.
sl@0: * ToUnicode(ToUnicode(ToUnicode...(ToUnicode(string)))) == ToUnicode(string)
sl@0: * ToASCII(ToASCII(ToASCII...(ToASCII(string))) == ToASCII(string).
sl@0: *
sl@0: */
sl@0:
sl@0: #ifndef U_HIDE_DRAFT_API
sl@0:
sl@0: /**
sl@0: * Option to prohibit processing of unassigned codepoints in the input and
sl@0: * do not check if the input conforms to STD-3 ASCII rules.
sl@0: *
sl@0: * @see uidna_toASCII uidna_toUnicode
sl@0: * @stable ICU 2.6
sl@0: */
sl@0: #define UIDNA_DEFAULT 0x0000
sl@0: /**
sl@0: * Option to allow processing of unassigned codepoints in the input
sl@0: *
sl@0: * @see uidna_toASCII uidna_toUnicode
sl@0: * @stable ICU 2.6
sl@0: */
sl@0: #define UIDNA_ALLOW_UNASSIGNED 0x0001
sl@0: /**
sl@0: * Option to check if input conforms to STD-3 ASCII rules
sl@0: *
sl@0: * @see uidna_toASCII uidna_toUnicode
sl@0: * @stable ICU 2.6
sl@0: */
sl@0: #define UIDNA_USE_STD3_RULES 0x0002
sl@0:
sl@0: #endif /*U_HIDE_DRAFT_API*/
sl@0:
sl@0: /**
sl@0: * This function implements the ToASCII operation as defined in the IDNA RFC.
sl@0: * This operation is done on single labels before sending it to something that expects
sl@0: * ASCII names. A label is an individual part of a domain name. Labels are usually
sl@0: * separated by dots; e.g." "www.example.com" is composed of 3 labels
sl@0: * "www","example", and "com".
sl@0: *
sl@0: *
sl@0: * @param src Input UChar array containing label in Unicode.
sl@0: * @param srcLength Number of UChars in src, or -1 if NUL-terminated.
sl@0: * @param dest Output UChar array with ASCII (ACE encoded) label.
sl@0: * @param destCapacity Size of dest.
sl@0: * @param options A bit set of options:
sl@0: *
sl@0: * - UIDNA_DEFAULT Use default options, i.e., do not process unassigned code points
sl@0: * and do not use STD3 ASCII rules
sl@0: * If unassigned code points are found the operation fails with
sl@0: * U_UNASSIGNED_ERROR error code.
sl@0: *
sl@0: * - UIDNA_ALLOW_UNASSIGNED Unassigned values can be converted to ASCII for query operations
sl@0: * If this option is set, the unassigned code points are in the input
sl@0: * are treated as normal Unicode code points.
sl@0: *
sl@0: * - UIDNA_USE_STD3_RULES Use STD3 ASCII rules for host name syntax restrictions
sl@0: * If this option is set and the input does not satisfy STD3 rules,
sl@0: * the operation will fail with U_IDNA_STD3_ASCII_RULES_ERROR
sl@0: *
sl@0: * @param parseError Pointer to UParseError struct to receive information on position
sl@0: * of error if an error is encountered. Can be NULL.
sl@0: * @param status ICU in/out error code parameter.
sl@0: * U_INVALID_CHAR_FOUND if src contains
sl@0: * unmatched single surrogates.
sl@0: * U_INDEX_OUTOFBOUNDS_ERROR if src contains
sl@0: * too many code points.
sl@0: * U_BUFFER_OVERFLOW_ERROR if destCapacity is not enough
sl@0: * @return Number of ASCII characters converted.
sl@0: * @stable ICU 2.6
sl@0: */
sl@0: U_STABLE int32_t U_EXPORT2
sl@0: uidna_toASCII(const UChar* src, int32_t srcLength,
sl@0: UChar* dest, int32_t destCapacity,
sl@0: int32_t options,
sl@0: UParseError* parseError,
sl@0: UErrorCode* status);
sl@0:
sl@0:
sl@0: /**
sl@0: * This function implements the ToUnicode operation as defined in the IDNA RFC.
sl@0: * This operation is done on single labels before sending it to something that expects
sl@0: * Unicode names. A label is an individual part of a domain name. Labels are usually
sl@0: * separated by dots; for e.g." "www.example.com" is composed of 3 labels
sl@0: * "www","example", and "com".
sl@0: *
sl@0: * @param src Input UChar array containing ASCII (ACE encoded) label.
sl@0: * @param srcLength Number of UChars in src, or -1 if NUL-terminated.
sl@0: * @param dest Output Converted UChar array containing Unicode equivalent of label.
sl@0: * @param destCapacity Size of dest.
sl@0: * @param options A bit set of options:
sl@0: *
sl@0: * - UIDNA_DEFAULT Use default options, i.e., do not process unassigned code points
sl@0: * and do not use STD3 ASCII rules
sl@0: * If unassigned code points are found the operation fails with
sl@0: * U_UNASSIGNED_ERROR error code.
sl@0: *
sl@0: * - UIDNA_ALLOW_UNASSIGNED Unassigned values can be converted to ASCII for query operations
sl@0: * If this option is set, the unassigned code points are in the input
sl@0: * are treated as normal Unicode code points. Note: This option is
sl@0: * required on toUnicode operation because the RFC mandates
sl@0: * verification of decoded ACE input by applying toASCII and comparing
sl@0: * its output with source
sl@0: *
sl@0: *
sl@0: *
sl@0: * - UIDNA_USE_STD3_RULES Use STD3 ASCII rules for host name syntax restrictions
sl@0: * If this option is set and the input does not satisfy STD3 rules,
sl@0: * the operation will fail with U_IDNA_STD3_ASCII_RULES_ERROR
sl@0: *
sl@0: * @param parseError Pointer to UParseError struct to receive information on position
sl@0: * of error if an error is encountered. Can be NULL.
sl@0: * @param status ICU in/out error code parameter.
sl@0: * U_INVALID_CHAR_FOUND if src contains
sl@0: * unmatched single surrogates.
sl@0: * U_INDEX_OUTOFBOUNDS_ERROR if src contains
sl@0: * too many code points.
sl@0: * U_BUFFER_OVERFLOW_ERROR if destCapacity is not enough
sl@0: * @return Number of Unicode characters converted.
sl@0: * @stable ICU 2.6
sl@0: */
sl@0: U_STABLE int32_t U_EXPORT2
sl@0: uidna_toUnicode(const UChar* src, int32_t srcLength,
sl@0: UChar* dest, int32_t destCapacity,
sl@0: int32_t options,
sl@0: UParseError* parseError,
sl@0: UErrorCode* status);
sl@0:
sl@0:
sl@0: /**
sl@0: * Convenience function that implements the IDNToASCII operation as defined in the IDNA RFC.
sl@0: * This operation is done on complete domain names, e.g: "www.example.com".
sl@0: * It is important to note that this operation can fail. If it fails, then the input
sl@0: * domain name cannot be used as an Internationalized Domain Name and the application
sl@0: * should have methods defined to deal with the failure.
sl@0: *
sl@0: * Note: IDNA RFC specifies that a conformant application should divide a domain name
sl@0: * into separate labels, decide whether to apply allowUnassigned and useSTD3ASCIIRules on each,
sl@0: * and then convert. This function does not offer that level of granularity. The options once
sl@0: * set will apply to all labels in the domain name
sl@0: *
sl@0: * @param src Input UChar array containing IDN in Unicode.
sl@0: * @param srcLength Number of UChars in src, or -1 if NUL-terminated.
sl@0: * @param dest Output UChar array with ASCII (ACE encoded) IDN.
sl@0: * @param destCapacity Size of dest.
sl@0: * @param options A bit set of options:
sl@0: *
sl@0: * - UIDNA_DEFAULT Use default options, i.e., do not process unassigned code points
sl@0: * and do not use STD3 ASCII rules
sl@0: * If unassigned code points are found the operation fails with
sl@0: * U_UNASSIGNED_CODE_POINT_FOUND error code.
sl@0: *
sl@0: * - UIDNA_ALLOW_UNASSIGNED Unassigned values can be converted to ASCII for query operations
sl@0: * If this option is set, the unassigned code points are in the input
sl@0: * are treated as normal Unicode code points.
sl@0: *
sl@0: * - UIDNA_USE_STD3_RULES Use STD3 ASCII rules for host name syntax restrictions
sl@0: * If this option is set and the input does not satisfy STD3 rules,
sl@0: * the operation will fail with U_IDNA_STD3_ASCII_RULES_ERROR
sl@0: *
sl@0: * @param parseError Pointer to UParseError struct to receive information on position
sl@0: * of error if an error is encountered. Can be NULL.
sl@0: * @param status ICU in/out error code parameter.
sl@0: * U_INVALID_CHAR_FOUND if src contains
sl@0: * unmatched single surrogates.
sl@0: * U_INDEX_OUTOFBOUNDS_ERROR if src contains
sl@0: * too many code points.
sl@0: * U_BUFFER_OVERFLOW_ERROR if destCapacity is not enough
sl@0: * @return Number of ASCII characters converted.
sl@0: * @stable ICU 2.6
sl@0: */
sl@0: U_STABLE int32_t U_EXPORT2
sl@0: uidna_IDNToASCII( const UChar* src, int32_t srcLength,
sl@0: UChar* dest, int32_t destCapacity,
sl@0: int32_t options,
sl@0: UParseError* parseError,
sl@0: UErrorCode* status);
sl@0:
sl@0: /**
sl@0: * Convenience function that implements the IDNToUnicode operation as defined in the IDNA RFC.
sl@0: * This operation is done on complete domain names, e.g: "www.example.com".
sl@0: *
sl@0: * Note: IDNA RFC specifies that a conformant application should divide a domain name
sl@0: * into separate labels, decide whether to apply allowUnassigned and useSTD3ASCIIRules on each,
sl@0: * and then convert. This function does not offer that level of granularity. The options once
sl@0: * set will apply to all labels in the domain name
sl@0: *
sl@0: * @param src Input UChar array containing IDN in ASCII (ACE encoded) form.
sl@0: * @param srcLength Number of UChars in src, or -1 if NUL-terminated.
sl@0: * @param dest Output UChar array containing Unicode equivalent of source IDN.
sl@0: * @param destCapacity Size of dest.
sl@0: * @param options A bit set of options:
sl@0: *
sl@0: * - UIDNA_DEFAULT Use default options, i.e., do not process unassigned code points
sl@0: * and do not use STD3 ASCII rules
sl@0: * If unassigned code points are found the operation fails with
sl@0: * U_UNASSIGNED_CODE_POINT_FOUND error code.
sl@0: *
sl@0: * - UIDNA_ALLOW_UNASSIGNED Unassigned values can be converted to ASCII for query operations
sl@0: * If this option is set, the unassigned code points are in the input
sl@0: * are treated as normal Unicode code points.
sl@0: *
sl@0: * - UIDNA_USE_STD3_RULES Use STD3 ASCII rules for host name syntax restrictions
sl@0: * If this option is set and the input does not satisfy STD3 rules,
sl@0: * the operation will fail with U_IDNA_STD3_ASCII_RULES_ERROR
sl@0: *
sl@0: * @param parseError Pointer to UParseError struct to receive information on position
sl@0: * of error if an error is encountered. Can be NULL.
sl@0: * @param status ICU in/out error code parameter.
sl@0: * U_INVALID_CHAR_FOUND if src contains
sl@0: * unmatched single surrogates.
sl@0: * U_INDEX_OUTOFBOUNDS_ERROR if src contains
sl@0: * too many code points.
sl@0: * U_BUFFER_OVERFLOW_ERROR if destCapacity is not enough
sl@0: * @return Number of ASCII characters converted.
sl@0: * @stable ICU 2.6
sl@0: */
sl@0: U_STABLE int32_t U_EXPORT2
sl@0: uidna_IDNToUnicode( const UChar* src, int32_t srcLength,
sl@0: UChar* dest, int32_t destCapacity,
sl@0: int32_t options,
sl@0: UParseError* parseError,
sl@0: UErrorCode* status);
sl@0:
sl@0: /**
sl@0: * Compare two IDN strings for equivalence.
sl@0: * This function splits the domain names into labels and compares them.
sl@0: * According to IDN RFC, whenever two labels are compared, they are
sl@0: * considered equal if and only if their ASCII forms (obtained by
sl@0: * applying toASCII) match using an case-insensitive ASCII comparison.
sl@0: * Two domain names are considered a match if and only if all labels
sl@0: * match regardless of whether label separators match.
sl@0: *
sl@0: * @param s1 First source string.
sl@0: * @param length1 Length of first source string, or -1 if NUL-terminated.
sl@0: *
sl@0: * @param s2 Second source string.
sl@0: * @param length2 Length of second source string, or -1 if NUL-terminated.
sl@0: * @param options A bit set of options:
sl@0: *
sl@0: * - UIDNA_DEFAULT Use default options, i.e., do not process unassigned code points
sl@0: * and do not use STD3 ASCII rules
sl@0: * If unassigned code points are found the operation fails with
sl@0: * U_UNASSIGNED_CODE_POINT_FOUND error code.
sl@0: *
sl@0: * - UIDNA_ALLOW_UNASSIGNED Unassigned values can be converted to ASCII for query operations
sl@0: * If this option is set, the unassigned code points are in the input
sl@0: * are treated as normal Unicode code points.
sl@0: *
sl@0: * - UIDNA_USE_STD3_RULES Use STD3 ASCII rules for host name syntax restrictions
sl@0: * If this option is set and the input does not satisfy STD3 rules,
sl@0: * the operation will fail with U_IDNA_STD3_ASCII_RULES_ERROR
sl@0: *
sl@0: * @param status ICU error code in/out parameter.
sl@0: * Must fulfill U_SUCCESS before the function call.
sl@0: * @return <0 or 0 or >0 as usual for string comparisons
sl@0: * @stable ICU 2.6
sl@0: */
sl@0: U_STABLE int32_t U_EXPORT2
sl@0: uidna_compare( const UChar *s1, int32_t length1,
sl@0: const UChar *s2, int32_t length2,
sl@0: int32_t options,
sl@0: UErrorCode* status);
sl@0:
sl@0: #endif /* #if !UCONFIG_NO_IDNA */
sl@0:
sl@0: #endif