idna.h (3982B)
1 /* idna.h --- Prototypes for Internationalized Domain Name library. 2 Copyright (C) 2002-2024 Simon Josefsson 3 4 This file is part of GNU Libidn. 5 6 GNU Libidn is free software: you can redistribute it and/or 7 modify it under the terms of either: 8 9 * the GNU Lesser General Public License as published by the Free 10 Software Foundation; either version 3 of the License, or (at 11 your option) any later version. 12 13 or 14 15 * the GNU General Public License as published by the Free 16 Software Foundation; either version 2 of the License, or (at 17 your option) any later version. 18 19 or both in parallel, as here. 20 21 GNU Libidn is distributed in the hope that it will be useful, 22 but WITHOUT ANY WARRANTY; without even the implied warranty of 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 General Public License for more details. 25 26 You should have received copies of the GNU General Public License and 27 the GNU Lesser General Public License along with this program. If 28 not, see <https://www.gnu.org/licenses/>. */ 29 30 #ifndef IDNA_H 31 # define IDNA_H 32 33 /** 34 * SECTION:idna 35 * @title: idna.h 36 * @short_description: IDNA-related functions 37 * 38 * IDNA-related functions. 39 */ 40 41 /** 42 * IDNAPI: 43 * 44 * Symbol holding shared library API visibility decorator. 45 * 46 * This is used internally by the library header file and should never 47 * be used or modified by the application. 48 * 49 * https://www.gnu.org/software/gnulib/manual/html_node/Exported-Symbols-of-Shared-Libraries.html 50 */ 51 # ifndef IDNAPI 52 # if defined LIBIDN_BUILDING && defined HAVE_VISIBILITY && HAVE_VISIBILITY 53 # define IDNAPI __attribute__((__visibility__("default"))) 54 # elif defined LIBIDN_BUILDING && defined _MSC_VER && ! defined LIBIDN_STATIC 55 # define IDNAPI __declspec(dllexport) 56 # elif defined _MSC_VER && ! defined LIBIDN_STATIC 57 # define IDNAPI __declspec(dllimport) 58 # else 59 # define IDNAPI 60 # endif 61 # endif 62 63 # include <stddef.h> /* size_t */ 64 # include <idn-int.h> /* uint32_t */ 65 66 # ifdef __cplusplus 67 extern "C" 68 { 69 # endif 70 71 /* Error codes. */ 72 typedef enum 73 { 74 IDNA_SUCCESS = 0, 75 IDNA_STRINGPREP_ERROR = 1, 76 IDNA_PUNYCODE_ERROR = 2, 77 IDNA_CONTAINS_NON_LDH = 3, 78 /* Workaround typo in earlier versions. */ 79 IDNA_CONTAINS_LDH = IDNA_CONTAINS_NON_LDH, 80 IDNA_CONTAINS_MINUS = 4, 81 IDNA_INVALID_LENGTH = 5, 82 IDNA_NO_ACE_PREFIX = 6, 83 IDNA_ROUNDTRIP_VERIFY_ERROR = 7, 84 IDNA_CONTAINS_ACE_PREFIX = 8, 85 IDNA_ICONV_ERROR = 9, 86 /* Internal errors. */ 87 IDNA_MALLOC_ERROR = 201, 88 IDNA_DLOPEN_ERROR = 202 89 } Idna_rc; 90 91 /* IDNA flags */ 92 typedef enum 93 { 94 IDNA_ALLOW_UNASSIGNED = 0x0001, 95 IDNA_USE_STD3_ASCII_RULES = 0x0002 96 } Idna_flags; 97 98 # ifndef IDNA_ACE_PREFIX 99 # define IDNA_ACE_PREFIX "xn--" 100 # endif 101 102 extern IDNAPI const char *idna_strerror (Idna_rc rc); 103 104 /* Core functions */ 105 extern IDNAPI int idna_to_ascii_4i (const uint32_t * in, size_t inlen, 106 char *out, int flags); 107 extern IDNAPI int idna_to_unicode_44i (const uint32_t * in, size_t inlen, 108 uint32_t * out, size_t *outlen, 109 int flags); 110 111 /* Wrappers that handle several labels */ 112 113 extern IDNAPI int idna_to_ascii_4z (const uint32_t * input, 114 char **output, int flags); 115 116 extern IDNAPI int idna_to_ascii_8z (const char *input, char **output, 117 int flags); 118 119 extern IDNAPI int idna_to_ascii_lz (const char *input, char **output, 120 int flags); 121 122 extern IDNAPI int idna_to_unicode_4z4z (const uint32_t * input, 123 uint32_t ** output, int flags); 124 125 extern IDNAPI int idna_to_unicode_8z4z (const char *input, 126 uint32_t ** output, int flags); 127 128 extern IDNAPI int idna_to_unicode_8z8z (const char *input, 129 char **output, int flags); 130 131 extern IDNAPI int idna_to_unicode_8zlz (const char *input, 132 char **output, int flags); 133 134 extern IDNAPI int idna_to_unicode_lzlz (const char *input, 135 char **output, int flags); 136 137 # ifdef __cplusplus 138 } 139 # endif 140 141 #endif /* IDNA_H */