1 /* 2 * TERMS AND CONDITIONS 3 * FOR 4 * OPEN SOURCE CODE LICENSE 5 * Version 1.1 6 * 7 * Japan Registry Services Co., Ltd. ("JPRS"), a Japanese corporation 8 * having its head office at Chiyoda First Bldg. East 13F 3-8-1 Nishi-Kanda, 9 * Chiyoda-ku, Tokyo 101-0065, Japan, grants you the license for open source 10 * code specified in EXHIBIT A the "Code" subject to the following Terms and 11 * Conditions ("OSCL"). 12 * 13 * 1. License Grant. 14 * JPRS hereby grants you a worldwide, royalty-free, non-exclusive 15 * license, subject to third party intellectual property claims: 16 * (a) under intellectual property rights (other than patent or 17 * trademark) licensable by JPRS to use, reproduce, modify, display, 18 * perform, sublicense and distribute the Code (or portions thereof) 19 * with or without modifications, and/or as part of a derivative work; 20 * or 21 * (b) under claims of the infringement through the making, using, 22 * offering to sell and/or otherwise disposing the JPRS Revised Code 23 * (or portions thereof); 24 * (c) the licenses granted in this Section 1(a) and (b) are effective on 25 * the date JPRS first distributes the Code to you under the terms of 26 * this OSCL; 27 * (d) Notwithstanding the above stated terms, no patent license is 28 * granted: 29 * 1) for a code that you delete from the Code; 30 * 2) separate from the Code; or 31 * 3) for infringements caused by: 32 * i) modification of the Code; or 33 * ii) combination of the Code with other software or devices. 34 * 35 * 2. Consents. 36 * You agree that: 37 * (a) you must include a copy of this OSCL and the notice set forth in 38 * EXHIBIT A with every copy of the Code you distribute; 39 * (b) you must include a copy of this OSCL and the notice set forth in 40 * EXHIBIT A with every copy of binary form of the Code in the 41 * documentation and/or other materials provided with the distribution; 42 * (c) you may not offer or impose any terms on any source code version 43 * that alters or restricts the applicable version of this OSCL or 44 * the recipients' rights hereunder. 45 * (d) If the terms and conditions are set forth in EXHIBIT A, you must 46 * comply with those terms and conditions. 47 * 48 * 3. Proprietary Information. 49 * All trademarks, service marks, patents, copyrights, trade secrets, and 50 * other proprietary rights in or related to the Code are and will remain 51 * the exclusive property of JPRS or its licensors, whether or not 52 * specifically recognized or perfected under local law except specified 53 * in this OSCL; provided however you agree and understand that the JPRS 54 * name may not be used to endorse or promote this Code without prior 55 * written approval of JPRS. 56 * 57 * 4. WARRANTY DISCLAIMER. 58 * JPRS MAKES NO REPRESENTATIONS AND WARRANTIES REGARDING THE USE OF THE 59 * CODE, NOR DOES JPRS MAKE ANY REPRESENTATIONS THAT THE CODE WILL BECOME 60 * COMMERCIALLY AVAILABLE. JPRS, ITS AFFILIATES, AND ITS SUPPLIERS DO NOT 61 * WARRANT OR REPRESENT THAT THE CODE IS FREE OF ERRORS OR THAT THE CODE 62 * IS SUITABLE FOR TRANSLATION AND/OR LOCALIZATION. THE CODE IS PROVIDED 63 * ON AN "AS IS" BASIS AND JPRS AND ITS SUPPLIERS HAVE NO OBLIGATION TO 64 * CORRECT ERRORS OR TO SUPPORT THE CODE UNDER THIS OSCL FOR ANY REASON. 65 * TO THE FULL EXTENT PERMITTED BY LAW, ALL OBLIGATIONS ARE HEREBY 66 * EXCLUDED WHETHER EXPRESS, STATUTORY OR IMPLIED UNDER LAW, COURSE OF 67 * DEALING, CUSTOM, TRADE USAGE, ORAL OR WRITTEN STATEMENT OR OTHERWISE, 68 * INCLUDING BUT NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY 69 * OR FITNESS FOR A PARTICULAR PURPOSE CONCERNING THE CODE. 70 * 71 * 5. NO LIABILITY. 72 * UNDER NO CIRCUMSTANCES SHALL JPRS AND/OR ITS AFFILIATES, LICENSORS, OR 73 * REPRESENTATIVES BE LIABLE FOR ANY DAMAGES INCLUDING BUT NOT LIMITED TO 74 * CONSEQUENTIAL, INDIRECT, SPECIAL, PUNITIVE OR INCIDENTAL DAMAGES, 75 * WHETHER FORESEEABLE OR UNFORESEEABLE, BASED ON YOUR CLAIMS, INCLUDING, 76 * BUT NOT LIMITED TO, CLAIMS FOR LOSS OF DATA, GOODWILL, PROFITS, USE OF 77 * MONEY, INTERRUPTION IN USE OR AVAILABILITY OF DATA, STOPPAGE, IMPLIED 78 * WARRANTY, BREACH OF CONTRACT, MISREPRESENTATION, NEGLIGENCE, STRICT 79 * LIABILITY IN TORT, OR OTHERWISE. 80 * 81 * 6. Indemnification. 82 * You hereby agree to indemnify, defend, and hold harmless JPRS for any 83 * liability incurred by JRPS due to your terms of warranty, support, 84 * indemnity, or liability offered by you to any third party. 85 * 86 * 7. Termination. 87 * 7.1 This OSCL shall be automatically terminated in the events that: 88 * (a) You fail to comply with the terms herein and fail to cure such 89 * breach within 30 days of becoming aware of the breach; 90 * (b) You initiate patent or copyright infringement litigation against 91 * any party (including a cross-claim or counterclaim in a lawsuit) 92 * alleging that the Code constitutes a direct or indirect patent or 93 * copyright infringement, in such case, this OSCL to you shall 94 * terminate as of the date such litigation is filed; 95 * 7.2 In the event of termination under Sections 7.1(a) or 7.1(b) above, 96 * all end user license agreements (excluding distributors and 97 * resellers) which have been validly granted by You or any distributor 98 * hereunder prior to termination shall survive termination. 99 * 100 * 101 * 8. General. 102 * This OSCL shall be governed by, and construed and enforced in 103 * accordance with, the laws of Japan. Any litigation or arbitration 104 * between the parties shall be conducted exclusively in Tokyo, Japan 105 * except written consent of JPRS provides other venue. 106 * 107 * 108 * EXHIBIT A 109 * 110 * The original open source code of idnkit-2 is idnkit-1.0 developed and 111 * conceived by Japan Network Information Center ("JPNIC"), a Japanese 112 * association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda, 113 * Chiyoda-ku, Tokyo 101-0047, Japan, and JPRS modifies above original code 114 * under following Terms and Conditions set forth by JPNIC. 115 * 116 * JPNIC 117 * 118 * Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved. 119 * 120 * By using this file, you agree to the terms and conditions set forth bellow. 121 * 122 * LICENSE TERMS AND CONDITIONS 123 * 124 * The following License Terms and Conditions apply, unless a different 125 * license is obtained from Japan Network Information Center ("JPNIC"), 126 * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda, 127 * Chiyoda-ku, Tokyo 101-0047, Japan. 128 * 129 * 1. Use, Modification and Redistribution (including distribution of any 130 * modified or derived work) in source and/or binary forms is permitted 131 * under this License Terms and Conditions. 132 * 133 * 2. Redistribution of source code must retain the copyright notices as they 134 * appear in each source code file, this License Terms and Conditions. 135 * 136 * 3. Redistribution in binary form must reproduce the Copyright Notice, 137 * this License Terms and Conditions, in the documentation and/or other 138 * materials provided with the distribution. For the purposes of binary 139 * distribution the "Copyright Notice" refers to the following language: 140 * "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved." 141 * 142 * 4. The name of JPNIC may not be used to endorse or promote products 143 * derived from this Software without specific prior written approval of 144 * JPNIC. 145 * 146 * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC 147 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 148 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 149 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE 150 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 151 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 152 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 153 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 154 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 155 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 156 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 157 * 158 * 159 * JPRS Public License Notice 160 * For 161 * idnkit-2. 162 * 163 * The contents of this file are subject to the Terms and Conditions for 164 * the Open Source Code License (the "OSCL"). You may not use this file 165 * except in compliance with above terms and conditions. A copy of the OSCL 166 * is available at <http://jprs.co.jp/idn/>. 167 * The JPRS Revised Code is idnkit-2. 168 * The Initial Developer of the JPRS Revised Code is Japan Network 169 * Information Center ("JPNIC"), a Japanese association, 170 * Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda, Chiyoda-ku, Tokyo 171 * 101-0047, Japan. 172 * "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved." 173 * "Copyright (c) 2010-2012 Japan Registry Services Co., Ltd. All rights reserved." 174 * Contributor(s): ______________________________________. 175 * 176 * If you wish to allow use of your version of this file only under the 177 * above License(s) and not to allow others to use your version of this 178 * file, please indicate your decision by deleting the relevant provisions 179 * above and replacing them with the notice and other provisions required 180 * by the above License(s). If you do not delete the relevant provisions, 181 * a recipient may use your version of this file under either the above 182 * License(s). 183 */ 184 185 /* 186 * High level API module of libidnkit. 187 * 188 * This module provides high-level APIs for ordinary applications. 189 * Low-level APIs are also available. See "res.h" for details. 190 */ 191 192 #ifndef IDN_API_H 193 #define IDN_API_H 1 194 195 #ifdef __cplusplus 196 extern "C" { 197 #endif 198 199 #include <stddef.h> 200 #include <idn/result.h> 201 #include <idn/export.h> 202 #include <idn/res.h> 203 204 /* 205 * Set configuration file name. 206 * This function is for private use only. 207 * 208 * When idn_nameinit(1) is called, this module loads `file'. 209 * 210 * Returns: 211 * idn_success -- ok. 212 * idn_nomemory -- malloc failed. 213 * idn_failure -- idn_nameinit() has already been 214 * called. 215 */ 216 extern idn_result_t 217 idn__setconffile(const char *file); 218 219 /* 220 * Initialize this module, and load configuration from the default 221 * configuration file (idn.conf). 222 * 223 * The initialization will be done only once when this function is 224 * called first, while either loading of the configuration file or 225 * setting the defaults behavior without the configuration file will 226 * be done every time it is called. 227 * 228 * If load_file is 0, this will set the defaults behavior without the 229 * configuration file. Otherwise, loading of the configuration file 230 * occurs. 231 * 232 * If 'idn_encodename' or 'idn_decodename' is called without calling 233 * this function, implicit initialization without the configuration 234 * file will be done prior to encoding/decoding process. 235 * 236 * Returns: 237 * idn_success -- ok. 238 * idn_nofile -- cannot open the configuration file. 239 * idn_invalid_syntax -- syntax error found in the file. 240 * idn_invalid_name -- there are invalid names (encoding, 241 * normalization etc.). 242 * idn_nomemory -- malloc failed. 243 */ 244 IDN_EXPORT idn_result_t 245 idn_nameinit(int load_file); 246 247 /* 248 * Encode an internationalized domain name. 249 * 250 * The function encodes a domain name 'from' and writes the result on 'to', 251 * at most 'tolen' bytes. Note that 'from' must be terminated by NUL, and 252 * 'tolen' includes room for a NUL character. 253 * 254 * The argument 'actions' specifies which steps in the entire encoding 255 * process should be performed. The following list shows action names 256 * corresponding with steps of the encoding process. The function 257 * performs the steps in that order. 258 * 259 * 1. IDN_UNICODECONV 260 * Convert a domain name from local encoding (e.g. ISO-8859-1) to UTF-8. 261 * 2. IDN_MAP 262 * Perform mappings (NFC, Lowercase conversion, etc.). 263 * 3. IDN_ASCLOWER 264 * Convert ASCII uppercase letters (A..Z) to lowercase (a..z). 265 * 4. IDN_RTCONV 266 * Convert A-labels to U-labels. 267 * 5. IDN_PROHCHECK 268 * Check prohibited code points. 269 * 6. IDN_UNASCHECK 270 * Check unassigned code points. 271 * 7. IDN_NFCCHECK 272 * Check labels are in NFC. 273 * 8. IDN_PREFCHECK 274 * Check labels containing "--" in the 3rd and 4th characters. 275 * 9. IDN_HYPHCHECK 276 * Check labels beginning/ending with "-". 277 * 10. IDN_COMBCHECK 278 * Check labels beginning with a combining mark. 279 * 11. IDN_CTXJCHECK 280 * Check CONTEXTJ code points. 281 * 12a. IDN_CTXOCHECK 282 * Check CONTEXTO code points for the registration protocol. 283 * 12b. IDN_CTXOLITECHECK 284 * Check CONTEXTO code points for the lookup protocol. 285 * 13. IDN_BIDICHECK 286 * Check requirements specified in [IDNA2008-BIDI]. 287 * 14. IDN_LOCALCHECK 288 * Perform local check (optional). 289 * 15. IDN_IDNCONV 290 * Convert labels in UTF-8 to Punycode. 291 * 16. IDN_LENCHECK 292 * Check length of each label. 293 * 17. IDN_RTCHECK 294 * Perform round trip check for each label. 295 * 296 * A value of bitwise-OR of some actions can be specified, like: 297 * 298 * result = idn_encodename(IDN_UNICODECONV | IDN_MAP, from, to, tolen); 299 * 300 * Also the following actions are provided for convenience: 301 * 302 * IDN_ENCODE_REGIST -- Encode a domain name with IDNA2008 registration 303 * protocol. On libidnkit, 1..11, 12a, 13 and 304 * 15..17 are performed. On libidnkitlite, 2..11, 305 * 12a, 13 and 15..17 are performed. 306 * IDN_ENCODE_LOOKUP -- Encode a domain name with IDNA2008 lookup 307 * protocol. On libidnkit, 1..8, 10, 11, 12b, 13 308 * and 15..17 are performed. 309 * On libidnkitlite, 2..8, 10, 11, 12b, 13 and 310 * 15..17 are performed. 311 * 312 * The following action is not an actual step of the encoding process, 313 * but it can be specified with other actions described above. 314 * 315 * IDN_UNDOIFERR -- If any step fails, the original input name is 316 * returned. 317 * 318 * If no flags are specified, the function just copies 'from' to 'to'. 319 * 320 * Returns: 321 * idn_success -- Ok. 322 * idn_invalid_action -- Invalid action flag specified. 323 * idn_invalid_encoding -- The given string has invalid byte sequence. 324 * idn_buffer_overflow -- 'tolen' is too small. 325 * idn_nomemory -- malloc() failed. 326 * idn_nomapping -- At IDN_LOCALCONV or IDN_UNICODECONV, the 327 * corresponding character doesn't exist in 328 * the destination encoding. 329 * idn_prohcheck_error -- IDN_PROHCHECK failed. 330 * idn_unascheck_error -- IDN_UNASCHECK failed. 331 * idn_nfccheck_error -- IDN_NFCCHECK failed. 332 * idn_prefcheck_error -- IDN_PREFCHECK failed. 333 * idn_hyphcheck_error -- IDN_HYPHCHECK failed. 334 * idn_combcheck_error -- IDN_COMBCHECK failed. 335 * idn_ctxjcheck_error -- IDN_CTXJCHECK failed. 336 * idn_ctxocheck_error -- IDN_CTXOCHECK or IDN_CTXOLITECHECK failed. 337 * idn_bidicheck_error -- IDN_BIDICHECK failed. 338 * idn_localcheck_error -- IDN_LOCALCHECK failed. 339 * idn_lencheck_error -- IDN_LENCHECK failed. 340 * idn_rtcheck_error -- IDN_RTCHECK failed. 341 */ 342 IDN_EXPORT idn_result_t 343 idn_encodename(idn_action_t actions, const char *from, char *to, size_t tolen); 344 345 /* 346 * Decode an internationalized domain name. 347 * 348 * The function decodes a domain name 'from' and writes the result on 'to', 349 * at most 'tolen' bytes. Note that 'from' must be terminated by NUL, and 350 * 'tolen' includes room for a NUL character. 351 * 352 * The argument 'actions' specifies which steps in the entire decoding 353 * process should be performed. The following list shows action names 354 * corresponding with steps of the decoding process. The function 355 * performs the steps in that order. 356 * 357 * 1. IDN_UNICODECONV 358 * Convert a domain name from local encoding (e.g. ISO-8859-1) to UTF-8. 359 * 2. IDN_MAP 360 * Perform mappings (NFC, Lowercase conversion, etc.). 361 * 3. IDN_ASCLOWER 362 * Convert ASCII uppercase letters (A..Z) to lowercase (a..z). 363 * 4. IDN_IDNCONV 364 * Convert A-labels to U-labels. 365 * 5. IDN_PROHCHECK 366 * Check prohibited code points. 367 * 6. IDN_UNASCHECK 368 * Check unassigned code points. 369 * 7. IDN_NFCCHECK 370 * Check labels are in NFC. 371 * 8. IDN_PREFCHECK 372 * Check labels containing "--" in the 3rd and 4th characters. 373 * 9. IDN_HYPHCHECK 374 * Check labels beginning/ending with "-". 375 * 10. IDN_COMBCHECK 376 * Check labels beginning with a combining mark. 377 * 11. IDN_CTXJCHECK 378 * Check CONTEXTJ code points. 379 * 12a. IDN_CTXOCHECK 380 * Check CONTEXTO code points for the registration protocol. 381 * 12b. IDN_CTXOLITECHECK 382 * Check CONTEXTO code points for the lookup protocol. 383 * 13. IDN_BIDICHECK 384 * Check requirements specified in [IDNA2008-BIDI]. 385 * 14. IDN_LOCALCHECK 386 * Perform local check (optional). 387 * 15. IDN_RTCHECK 388 * Perform round trip check for each label. 389 * 16. IDN_LOCALCONV 390 * Convert a domain name from UTF-8 to local encoding (e.g. ISO-8859-1). 391 * 392 * A value of bitwise-OR of some actions can be specified, like: 393 * 394 * result = idn_decodename(IDN_IDNCONV | IDN_LOCALCONV, from, to, tolen); 395 * 396 * Also the following actions are provided for convinience: 397 * 398 * IDN_DECODE_REGIST -- Perform 1..11, 12a, 13, 15, 16. 399 * On libidnkitlite, 1 and 16 are skipped. 400 * IDN_DECODE_LOOKUP -- Perform 1..8, 10, 11, 12b, 13, 15, 16. 401 * On libidnkitlite, 1 and 16 are skipped. 402 * 403 * The following action is not an actual step of the decoding process, 404 * but it can be specified with other actions described above. 405 * 406 * IDN_UNDOIFERR -- If any step fails, the original input name is 407 * returned. 408 * 409 * If no flags are specified, the function just copies 'from' to 'to'. 410 * 411 * Returns: 412 * idn_success -- Ok. 413 * idn_invalid_action -- Invalid action flag specified. 414 * idn_invalid_encoding -- The given string has invalid byte sequence. 415 * idn_buffer_overflow -- 'tolen' is too small. 416 * idn_nomemory -- malloc() failed. 417 * idn_nomapping -- At IDN_LOCALCONV or IDN_UNICODECONV, the 418 * corresponding character doesn't exist in 419 * the destination encoding. 420 * idn_prohcheck_error -- IDN_PROHCHECK failed. 421 * idn_unascheck_error -- IDN_UNASCHECK failed. 422 * idn_nfccheck_error -- IDN_NFCCHECK failed. 423 * idn_prefcheck_error -- IDN_PREFCHECK failed. 424 * idn_hyphcheck_error -- IDN_HYPHCHECK failed. 425 * idn_combcheck_error -- IDN_COMBCHECK failed. 426 * idn_ctxjcheck_error -- IDN_CTXJCHECK failed. 427 * idn_ctxocheck_error -- IDN_CTXOCHECK or IDN_CTXOLITECHECK failed. 428 * idn_bidicheck_error -- IDN_BIDICHECK failed. 429 * idn_localcheck_error -- IDN_LOCALCHECK failed. 430 */ 431 IDN_EXPORT idn_result_t 432 idn_decodename(idn_action_t actions, const char *from, char *to, size_t tolen); 433 434 /* 435 * Decode an internationalized domain name with auxiliary encoding 436 * support. 437 * 438 * The function works the same as idn_decodename(), but an encoding 439 * conversion from 'auxencoding' to UTF-8 is performed prior to the actual 440 * decoding process (see idn_decodename() above), but IDN_UNICODECONV 441 * action is ignored, instead. 442 * 443 * If 'auxencoding' is NULL, 'from' is treated as UTF-8. 444 */ 445 IDN_EXPORT idn_result_t 446 idn_decodename2(idn_action_t actions, const char *from, char *to, size_t tolen, 447 const char *auxencoding); 448 449 /* 450 * Compare two domain names. 451 * 452 * The function encodes domain names 'name1' and 'name2' as 453 * idn_encodename() does, and then compares them. 454 * If they are equivalent, it returns 'idn_success'. Otherwise, 455 * it returns 'idn_neq'. When an error occurs in the encoding process, 456 * the function returns the correspoinding error code 457 * (see idn_encodename() above). 458 * 459 * Returns: 460 * idn_success -- 'name1' and 'name2' are equivalent. 461 * idn_neq -- 'name1' and 'name2' are different. 462 * (other error codes) -- See idn_encodename(). 463 */ 464 IDN_EXPORT idn_result_t 465 idn_comparenames(idn_action_t actions, 466 const char *name1, const char *name2); 467 468 /* 469 * Compare two domain names. 470 * 471 * The function works the same as idn_comparenames(), but it performs 472 * 'actions1' when it encodes 'name1' and it performs 'actions2' when 473 * it encodes 'name2' respectively. 474 */ 475 IDN_EXPORT idn_result_t 476 idn_comparenames2(idn_action_t actions1, const char *name1, 477 idn_action_t actions2, const char *name2); 478 479 /* 480 * Check a domain name. 481 * 482 * The function internally creates a copy of 'name', performs 483 * the encoding process 'actions' for it, and returns its error code 484 * as idn_encodename() does. 485 */ 486 IDN_EXPORT idn_result_t 487 idn_checkname(idn_action_t actions, const char *name); 488 489 /* 490 * Set the local encoding name. 491 */ 492 IDN_EXPORT idn_result_t 493 idn_setlocalencoding(const char *name); 494 495 /* 496 * Set the current language. 497 */ 498 IDN_EXPORT idn_result_t 499 idn_setlanguage(const char *name); 500 501 /* 502 * Set the localcheck file. 503 */ 504 IDN_EXPORT idn_result_t 505 idn_setlocalcheckfile(const char *file); 506 507 /* 508 * The function is provided for backward compatibility to idnkit 1.x. 509 */ 510 IDN_EXPORT void 511 idn_enable(int on_off); 512 513 #ifdef __cplusplus 514 } 515 #endif 516 517 #endif /* IDN_API_H */ 518