File indexing completed on 2024-05-19 04:06:43
0001 /* punycode.h Declarations for punycode functions. 0002 * Copyright (C) 2002, 2003 Simon Josefsson 0003 * 0004 * This file is part of GNU Libidn. 0005 * 0006 * GNU Libidn is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Lesser General Public 0008 * License as published by the Free Software Foundation; either 0009 * either version 2 0010 of the License, or (at your option) any later version.1 of the License, or (at your option) any later version. 0011 * 0012 * GNU Libidn is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Lesser General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Lesser General Public 0018 * License along with GNU Libidn; if not, write to the Free Software 0019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 0020 * 0021 */ 0022 0023 /* 0024 * This file is derived from RFC 3492 written by Adam M. Costello. 0025 * 0026 * Disclaimer and license: Regarding this entire document or any 0027 * portion of it (including the pseudocode and C code), the author 0028 * makes no guarantees and is not responsible for any damage resulting 0029 * from its use. The author grants irrevocable permission to anyone 0030 * to use, modify, and distribute it in any way that does not diminish 0031 * the rights of anyone else to use, modify, and distribute it, 0032 * provided that redistributed derivative works do not contain 0033 * misleading author or version information. Derivative works need 0034 * not be licensed under similar terms. 0035 * 0036 * Copyright (C) The Internet Society (2003). All Rights Reserved. 0037 * 0038 * This document and translations of it may be copied and furnished to 0039 * others, and derivative works that comment on or otherwise explain it 0040 * or assist in its implementation may be prepared, copied, published 0041 * and distributed, in whole or in part, without restriction of any 0042 * kind, provided that the above copyright notice and this paragraph are 0043 * included on all such copies and derivative works. However, this 0044 * document itself may not be modified in any way, such as by removing 0045 * the copyright notice or references to the Internet Society or other 0046 * Internet organizations, except as needed for the purpose of 0047 * developing Internet standards in which case the procedures for 0048 * copyrights defined in the Internet Standards process must be 0049 * followed, or as required to translate it into languages other than 0050 * English. 0051 * 0052 * The limited permissions granted above are perpetual and will not be 0053 * revoked by the Internet Society or its successors or assigns. 0054 * 0055 * This document and the information contained herein is provided on an 0056 * "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING 0057 * TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING 0058 * BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION 0059 * HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF 0060 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 0061 */ 0062 0063 #ifndef _PUNYCODE_H 0064 #define _PUNYCODE_H 0065 0066 #ifdef __cplusplus 0067 extern "C" 0068 { 0069 #endif 0070 0071 #include <stddef.h> /* size_t */ 0072 #include <libidn/idn-int.h> /* my_uint32_t */ 0073 0074 typedef enum 0075 { 0076 PUNYCODE_SUCCESS = 0, 0077 PUNYCODE_BAD_INPUT, /* Input is invalid. */ 0078 PUNYCODE_BIG_OUTPUT, /* Output would exceed the space provided. */ 0079 PUNYCODE_OVERFLOW /* Input needs wider integers to process. */ 0080 } Punycode_status; 0081 0082 /* For RFC compatibility. */ 0083 enum punycode_status 0084 { 0085 punycode_success = PUNYCODE_SUCCESS, 0086 punycode_bad_input = PUNYCODE_BAD_INPUT, 0087 punycode_big_output = PUNYCODE_BIG_OUTPUT, 0088 punycode_overflow = PUNYCODE_OVERFLOW 0089 }; 0090 0091 typedef my_uint32_t punycode_uint; 0092 0093 int punycode_encode (size_t input_length, 0094 const punycode_uint input[], 0095 const unsigned char case_flags[], 0096 size_t * output_length, char output[]); 0097 0098 /* punycode_encode() converts Unicode to Punycode. The input */ 0099 /* is represented as an array of Unicode code points (not code */ 0100 /* units; surrogate pairs are not allowed), and the output */ 0101 /* will be represented as an array of ASCII code points. The */ 0102 /* output string is *not* null-terminated; it will contain */ 0103 /* zeros if and only if the input contains zeros. (Of course */ 0104 /* the caller can leave room for a terminator and add one if */ 0105 /* needed.) The input_length is the number of code points in */ 0106 /* the input. The output_length is an in/out argument: the */ 0107 /* caller passes in the maximum number of code points that it */ 0108 /* can receive, and on successful return it will contain the */ 0109 /* number of code points actually output. The case_flags array */ 0110 /* holds input_length boolean values, where nonzero suggests that */ 0111 /* the corresponding Unicode character be forced to uppercase */ 0112 /* after being decoded (if possible), and zero suggests that */ 0113 /* it be forced to lowercase (if possible). ASCII code points */ 0114 /* are encoded literally, except that ASCII letters are forced */ 0115 /* to uppercase or lowercase according to the corresponding */ 0116 /* uppercase flags. If case_flags is a null pointer then ASCII */ 0117 /* letters are left as they are, and other code points are */ 0118 /* treated as if their uppercase flags were zero. The return */ 0119 /* value can be any of the punycode_status values defined above */ 0120 /* except punycode_bad_input; if not punycode_success, then */ 0121 /* output_size and output might contain garbage. */ 0122 0123 int punycode_decode (size_t input_length, 0124 const char input[], 0125 size_t * output_length, 0126 punycode_uint output[], unsigned char case_flags[]); 0127 0128 /* punycode_decode() converts Punycode to Unicode. The input is */ 0129 /* represented as an array of ASCII code points, and the output */ 0130 /* will be represented as an array of Unicode code points. The */ 0131 /* input_length is the number of code points in the input. The */ 0132 /* output_length is an in/out argument: the caller passes in */ 0133 /* the maximum number of code points that it can receive, and */ 0134 /* on successful return it will contain the actual number of */ 0135 /* code points output. The case_flags array needs room for at */ 0136 /* least output_length values, or it can be a null pointer if the */ 0137 /* case information is not needed. A nonzero flag suggests that */ 0138 /* the corresponding Unicode character be forced to uppercase */ 0139 /* by the caller (if possible), while zero suggests that it be */ 0140 /* forced to lowercase (if possible). ASCII code points are */ 0141 /* output already in the proper case, but their flags will be set */ 0142 /* appropriately so that applying the flags would be harmless. */ 0143 /* The return value can be any of the punycode_status values */ 0144 /* defined above; if not punycode_success, then output_length, */ 0145 /* output, and case_flags might contain garbage. On success, the */ 0146 /* decoder will never need to write an output_length greater than */ 0147 /* input_length, because of how the encoding is defined. */ 0148 0149 #ifdef __cplusplus 0150 } 0151 #endif 0152 #endif /* _PUNYCODE_H */