00001 /* punycode.h --- Declarations for punycode functions. 00002 * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 00003 * Simon Josefsson 00004 * 00005 * This file is part of GNU Libidn. 00006 * 00007 * GNU Libidn is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * GNU Libidn is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with GNU Libidn; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00020 * 00021 */ 00022 00023 /* 00024 * This file is derived from RFC 3492bis written by Adam M. Costello. 00025 * 00026 * Disclaimer and license: Regarding this entire document or any 00027 * portion of it (including the pseudocode and C code), the author 00028 * makes no guarantees and is not responsible for any damage resulting 00029 * from its use. The author grants irrevocable permission to anyone 00030 * to use, modify, and distribute it in any way that does not diminish 00031 * the rights of anyone else to use, modify, and distribute it, 00032 * provided that redistributed derivative works do not contain 00033 * misleading author or version information. Derivative works need 00034 * not be licensed under similar terms. 00035 * 00036 * Copyright (C) The Internet Society (2003). All Rights Reserved. 00037 * 00038 * This document and translations of it may be copied and furnished to 00039 * others, and derivative works that comment on or otherwise explain it 00040 * or assist in its implementation may be prepared, copied, published 00041 * and distributed, in whole or in part, without restriction of any 00042 * kind, provided that the above copyright notice and this paragraph are 00043 * included on all such copies and derivative works. However, this 00044 * document itself may not be modified in any way, such as by removing 00045 * the copyright notice or references to the Internet Society or other 00046 * Internet organizations, except as needed for the purpose of 00047 * developing Internet standards in which case the procedures for 00048 * copyrights defined in the Internet Standards process must be 00049 * followed, or as required to translate it into languages other than 00050 * English. 00051 * 00052 * The limited permissions granted above are perpetual and will not be 00053 * revoked by the Internet Society or its successors or assigns. 00054 * 00055 * This document and the information contained herein is provided on an 00056 * "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING 00057 * TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING 00058 * BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION 00059 * HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF 00060 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 00061 */ 00062 00063 #ifndef PUNYCODE_H 00064 # define PUNYCODE_H 00065 00066 # ifndef IDNAPI 00067 # if defined LIBIDN_BUILDING && defined HAVE_VISIBILITY && HAVE_VISIBILITY 00068 # define IDNAPI __attribute__((__visibility__("default"))) 00069 # elif defined LIBIDN_BUILDING && defined _MSC_VER && ! defined LIBIDN_STATIC 00070 # define IDNAPI __declspec(dllexport) 00071 # elif defined _MSC_VER && ! defined LIBIDN_STATIC 00072 # define IDNAPI __declspec(dllimport) 00073 # else 00074 # define IDNAPI 00075 # endif 00076 # endif 00077 00078 #ifdef __cplusplus 00079 extern "C" 00080 { 00081 #endif 00082 00083 #include <stddef.h> /* size_t */ 00084 #include <idn-int.h> /* uint32_t */ 00085 00086 enum punycode_status 00087 { 00088 punycode_success = 0, 00089 punycode_bad_input = 1, /* Input is invalid. */ 00090 punycode_big_output = 2, /* Output would exceed the space provided. */ 00091 punycode_overflow = 3 /* Wider integers needed to process input. */ 00092 }; 00093 00094 typedef enum 00095 { 00096 PUNYCODE_SUCCESS = punycode_success, 00097 PUNYCODE_BAD_INPUT = punycode_bad_input, 00098 PUNYCODE_BIG_OUTPUT = punycode_big_output, 00099 PUNYCODE_OVERFLOW = punycode_overflow 00100 } Punycode_status; 00101 00102 extern IDNAPI const char *punycode_strerror (Punycode_status rc); 00103 00104 /* punycode_uint needs to be unsigned and needs to be */ 00105 /* at least 26 bits wide. */ 00106 00107 typedef uint32_t punycode_uint; 00108 00109 extern IDNAPI int punycode_encode (size_t input_length, 00110 const punycode_uint input[], 00111 const unsigned char case_flags[], 00112 size_t * output_length, char output[]); 00113 00114 /* 00115 punycode_encode() converts a sequence of code points (presumed to be 00116 Unicode code points) to Punycode. 00117 00118 Input arguments (to be supplied by the caller): 00119 00120 input_length 00121 The number of code points in the input array and the number 00122 of flags in the case_flags array. 00123 00124 input 00125 An array of code points. They are presumed to be Unicode 00126 code points, but that is not strictly REQUIRED. The 00127 array contains code points, not code units. UTF-16 uses 00128 code units D800 through DFFF to refer to code points 00129 10000..10FFFF. The code points D800..DFFF do not occur in 00130 any valid Unicode string. The code points that can occur in 00131 Unicode strings (0..D7FF and E000..10FFFF) are also called 00132 Unicode scalar values. 00133 00134 case_flags 00135 A null pointer or an array of boolean values parallel to 00136 the input array. Nonzero (true, flagged) suggests that the 00137 corresponding Unicode character be forced to uppercase after 00138 being decoded (if possible), and zero (false, unflagged) 00139 suggests that it be forced to lowercase (if possible). 00140 ASCII code points (0..7F) are encoded literally, except that 00141 ASCII letters are forced to uppercase or lowercase according 00142 to the corresponding case flags. If case_flags is a null 00143 pointer then ASCII letters are left as they are, and other 00144 code points are treated as unflagged. 00145 00146 Output arguments (to be filled in by the function): 00147 00148 output 00149 An array of ASCII code points. It is *not* null-terminated; 00150 it will contain zeros if and only if the input contains 00151 zeros. (Of course the caller can leave room for a 00152 terminator and add one if needed.) 00153 00154 Input/output arguments (to be supplied by the caller and overwritten 00155 by the function): 00156 00157 output_length 00158 The caller passes in the maximum number of ASCII code points 00159 that it can receive. On successful return it will contain 00160 the number of ASCII code points actually output. 00161 00162 Return value: 00163 00164 Can be any of the punycode_status values defined above except 00165 punycode_bad_input. If not punycode_success, then output_size 00166 and output might contain garbage. 00167 */ 00168 00169 extern IDNAPI int punycode_decode (size_t input_length, 00170 const char input[], 00171 size_t * output_length, 00172 punycode_uint output[], 00173 unsigned char case_flags[]); 00174 00175 /* 00176 punycode_decode() converts Punycode to a sequence of code points 00177 (presumed to be Unicode code points). 00178 00179 Input arguments (to be supplied by the caller): 00180 00181 input_length 00182 The number of ASCII code points in the input array. 00183 00184 input 00185 An array of ASCII code points (0..7F). 00186 00187 Output arguments (to be filled in by the function): 00188 00189 output 00190 An array of code points like the input argument of 00191 punycode_encode() (see above). 00192 00193 case_flags 00194 A null pointer (if the flags are not needed by the caller) 00195 or an array of boolean values parallel to the output array. 00196 Nonzero (true, flagged) suggests that the corresponding 00197 Unicode character be forced to uppercase by the caller (if 00198 possible), and zero (false, unflagged) suggests that it 00199 be forced to lowercase (if possible). ASCII code points 00200 (0..7F) are output already in the proper case, but their 00201 flags will be set appropriately so that applying the flags 00202 would be harmless. 00203 00204 Input/output arguments (to be supplied by the caller and overwritten 00205 by the function): 00206 00207 output_length 00208 The caller passes in the maximum number of code points 00209 that it can receive into the output array (which is also 00210 the maximum number of flags that it can receive into the 00211 case_flags array, if case_flags is not a null pointer). On 00212 successful return it will contain the number of code points 00213 actually output (which is also the number of flags actually 00214 output, if case_flags is not a null pointer). The decoder 00215 will never need to output more code points than the number 00216 of ASCII code points in the input, because of the way the 00217 encoding is defined. The number of code points output 00218 cannot exceed the maximum possible value of a punycode_uint, 00219 even if the supplied output_length is greater than that. 00220 00221 Return value: 00222 00223 Can be any of the punycode_status values defined above. If not 00224 punycode_success, then output_length, output, and case_flags 00225 might contain garbage. 00226 */ 00227 00228 #ifdef __cplusplus 00229 } 00230 #endif 00231 #endif /* PUNYCODE_H */