1 /* $NetBSD: converter.h,v 1.4 2014/12/10 04:37:55 christos Exp $ */ 2 3 /* Id: converter.h,v 1.1 2003/06/04 00:25:36 marka Exp */ 4 /* 5 * Copyright (c) 2000 Japan Network Information Center. All rights reserved. 6 * 7 * By using this file, you agree to the terms and conditions set forth bellow. 8 * 9 * LICENSE TERMS AND CONDITIONS 10 * 11 * The following License Terms and Conditions apply, unless a different 12 * license is obtained from Japan Network Information Center ("JPNIC"), 13 * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda, 14 * Chiyoda-ku, Tokyo 101-0047, Japan. 15 * 16 * 1. Use, Modification and Redistribution (including distribution of any 17 * modified or derived work) in source and/or binary forms is permitted 18 * under this License Terms and Conditions. 19 * 20 * 2. Redistribution of source code must retain the copyright notices as they 21 * appear in each source code file, this License Terms and Conditions. 22 * 23 * 3. Redistribution in binary form must reproduce the Copyright Notice, 24 * this License Terms and Conditions, in the documentation and/or other 25 * materials provided with the distribution. For the purposes of binary 26 * distribution the "Copyright Notice" refers to the following language: 27 * "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved." 28 * 29 * 4. The name of JPNIC may not be used to endorse or promote products 30 * derived from this Software without specific prior written approval of 31 * JPNIC. 32 * 33 * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC 34 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 35 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 36 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE 37 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 38 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 39 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 40 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 41 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 42 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 43 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 44 */ 45 46 #ifndef IDN_CONVERTER_H 47 #define IDN_CONVERTER_H 1 48 49 #ifdef __cplusplus 50 extern "C" { 51 #endif 52 53 /* 54 * Codeset converter. 55 * 56 * This module provides conversions from some local codeset to UCS4 57 * and vice versa. 58 */ 59 60 #include <idn/export.h> 61 #include <idn/result.h> 62 63 /* 64 * Converter context type (opaque). 65 */ 66 typedef struct idn_converter *idn_converter_t; 67 68 /* 69 * Conversion flags. 70 */ 71 #define IDN_CONVERTER_DELAYEDOPEN 1 72 #define IDN_CONVERTER_RTCHECK 2 73 74 /* 75 * Encoding types. 76 */ 77 #define IDN_NONACE 0 78 #define IDN_ACE_STRICTCASE 1 79 #define IDN_ACE_LOOSECASE 2 80 81 /* 82 * Initialize module. Must be called before any other calls of 83 * the functions of this module. 84 * 85 * Returns: 86 * idn_success -- ok. 87 * idn_nomemory -- malloc failed. 88 */ 89 IDN_EXPORT idn_result_t 90 idn_converter_initialize(void); 91 92 /* 93 * Create a conversion context. 94 * 95 * Returns: 96 * idn_success -- ok. 97 * idn_invalid_name -- specified codeset is not supported. 98 * idn_nomemory -- malloc failed. 99 * idn_failure -- other failure (unknown cause). 100 */ 101 IDN_EXPORT idn_result_t 102 idn_converter_create(const char *name, idn_converter_t *ctxp, 103 int flags); 104 105 /* 106 * Decrement reference count of the converter `ctx' created by 107 * 'idn_converter_create', if it is still refered by another object. 108 * Otherwise, release all the memory allocated to the converter. 109 */ 110 IDN_EXPORT void 111 idn_converter_destroy(idn_converter_t ctx); 112 113 /* 114 * Increment reference count of the converter `ctx' created by 115 * 'idn_converter_create'. 116 */ 117 IDN_EXPORT void 118 idn_converter_incrref(idn_converter_t ctx); 119 120 /* 121 * Convert between local codeset and UCS4. Note that each conversion 122 * is started with initial state. 123 * 124 * Returns: 125 * idn_success -- ok. 126 * idn_buffer_overflow -- output buffer is too small. 127 * idn_invalid_encoding -- the input string has invalid/illegal 128 * byte sequence. 129 * idn_invalid_name -- codeset is not supported (this error 130 * should happen only if 'delayedopen' 131 * flag was set when idn_converter_create 132 * was called) 133 * idn_failure -- other failure. 134 */ 135 IDN_EXPORT idn_result_t 136 idn_converter_convfromucs4(idn_converter_t ctx, 137 const unsigned long *from, char *to, size_t tolen); 138 139 IDN_EXPORT idn_result_t 140 idn_converter_convtoucs4(idn_converter_t ctx, 141 const char *from, unsigned long *to, size_t tolen); 142 143 /* 144 * Get the name of local codeset. The returned name may be different from 145 * the one specified to idn_converter_create, if the specified one was an 146 * alias. 147 * 148 * Returns: 149 * the local codeset name. 150 */ 151 IDN_EXPORT char * 152 idn_converter_localencoding(idn_converter_t ctx); 153 154 /* 155 * Return the encoding type of this local encoding. 156 * 157 * Returns: 158 * IDN_NONACE -- encoding is not ACE. 159 * IDN_ACE_STRICTCASE -- encoding is ACE. 160 * decoder of this ACE preserve letter case. 161 * IDN_ACE_LOOSECASE -- encoding type is ACE. 162 * decoder cannot preserve letter case. 163 */ 164 IDN_EXPORT int 165 idn_converter_encodingtype(idn_converter_t ctx); 166 167 /* 168 * Return if this local encoding is ACE (Ascii Compatible Encoding). 169 * 170 * Returns: 171 * 1 -- yes, it is ACE. 172 * 0 -- no. 173 */ 174 IDN_EXPORT int 175 idn_converter_isasciicompatible(idn_converter_t ctx); 176 177 /* 178 * Register an alias for a codeset name. 179 * 180 * If first_item is 0, alias pattern is placed as the last item of the 181 * alias list. Otherwise, it is done as the first item. 182 * 183 * Returns: 184 * idn_success -- ok. 185 * idn_nomemory -- malloc failed. 186 */ 187 IDN_EXPORT idn_result_t 188 idn_converter_addalias(const char *alias_name, const char *real_name, 189 int first_item); 190 191 /* 192 * Register aliases defined by the specified file. 193 * 194 * Returns: 195 * idn_success -- ok. 196 * idn_nofile -- no such file. 197 * idn_invalid_syntax -- file is malformed. 198 * idn_nomemory -- malloc failed. 199 */ 200 IDN_EXPORT idn_result_t 201 idn_converter_aliasfile(const char *path); 202 203 /* 204 * Unregister all the aliases. 205 */ 206 IDN_EXPORT idn_result_t 207 idn_converter_resetalias(void); 208 209 /* 210 * resolve real encoding name from alias information. 211 */ 212 IDN_EXPORT const char * 213 idn_converter_getrealname(const char *name); 214 215 216 /* 217 * New converter registration. 218 */ 219 220 /* 221 * Conversion operation functions. 222 */ 223 typedef idn_result_t (*idn_converter_openproc_t)(idn_converter_t ctx, 224 void **privdata); 225 typedef idn_result_t (*idn_converter_closeproc_t)(idn_converter_t ctx, 226 void *privdata); 227 typedef idn_result_t 228 (*idn_converter_convfromucs4proc_t)(idn_converter_t ctx, 229 void *privdata, 230 const unsigned long *from, 231 char *to, size_t tolen); 232 typedef idn_result_t 233 (*idn_converter_convtoucs4proc_t)(idn_converter_t ctx, 234 void *privdata, 235 const char *from, 236 unsigned long *to, 237 size_t tolen); 238 239 /* 240 * Register a new converter. 241 * 'encoding_type' is a value which idn_converter_encodingtype() returns. 242 * 243 * Returns: 244 * idn_success -- ok. 245 * idn_nomemory -- malloc failed. 246 */ 247 IDN_EXPORT idn_result_t 248 idn_converter_register(const char *name, 249 idn_converter_openproc_t openfromucs4, 250 idn_converter_openproc_t opentoucs4, 251 idn_converter_convfromucs4proc_t convfromucs4, 252 idn_converter_convtoucs4proc_t convtoucs4, 253 idn_converter_closeproc_t close, 254 int encoding_type); 255 256 #ifdef __cplusplus 257 } 258 #endif 259 260 #endif /* IDN_CONVERTER_H */ 261