1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
/* error.c - libidn2 error handling helpers.
Copyright (C) 2011-2025 Simon Josefsson
Libidn2 is free software: you can redistribute it and/or modify it
under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at
your option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at
your option) any later version.
or both in parallel, as here.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include "idn2.h"
/* Prepare for gettext. */
#define _(x) x
#define bindtextdomain(a,b)
/**
* idn2_strerror:
* @rc: return code from another libidn2 function.
*
* Convert internal libidn2 error code to a humanly readable string.
* The returned pointer must not be de-allocated by the caller.
*
* Return value: A humanly readable string describing error.
**/
const char *
idn2_strerror (int rc)
{
bindtextdomain (PACKAGE, LOCALEDIR);
switch (rc)
{
case IDN2_OK:
return _("success");
case IDN2_MALLOC:
return _("out of memory");
case IDN2_NO_CODESET:
return _("could not determine locale encoding format");
case IDN2_ICONV_FAIL:
return _("could not convert string to UTF-8");
case IDN2_ENCODING_ERROR:
return _("string encoding error");
case IDN2_NFC:
return _("string could not be NFC normalized");
case IDN2_PUNYCODE_BAD_INPUT:
return _("string contains invalid punycode data");
case IDN2_PUNYCODE_BIG_OUTPUT:
return _("punycode encoded data will be too large");
case IDN2_PUNYCODE_OVERFLOW:
return _("punycode conversion resulted in overflow");
case IDN2_TOO_BIG_DOMAIN:
return _("domain name longer than 255 characters");
case IDN2_TOO_BIG_LABEL:
return _("domain label longer than 63 characters");
case IDN2_INVALID_ALABEL:
return _("input A-label is not valid");
case IDN2_UALABEL_MISMATCH:
return _("input A-label and U-label does not match");
case IDN2_NOT_NFC:
return _("string is not in Unicode NFC format");
case IDN2_2HYPHEN:
return _("string contains forbidden two hyphens pattern");
case IDN2_HYPHEN_STARTEND:
return _("string start/ends with forbidden hyphen");
case IDN2_LEADING_COMBINING:
return _("string contains a forbidden leading combining character");
case IDN2_DISALLOWED:
return _("string contains a disallowed character");
case IDN2_CONTEXTJ:
return _("string contains a forbidden context-j character");
case IDN2_CONTEXTJ_NO_RULE:
return _("string contains a context-j character with null rule");
case IDN2_CONTEXTO:
return _("string contains a forbidden context-o character");
case IDN2_CONTEXTO_NO_RULE:
return _("string contains a context-o character with null rule");
case IDN2_UNASSIGNED:
return _("string contains unassigned code point");
case IDN2_BIDI:
return _("string has forbidden bi-directional properties");
case IDN2_DOT_IN_LABEL:
return _("domain label has forbidden dot (TR46)");
case IDN2_INVALID_TRANSITIONAL:
return
_("domain label has character forbidden in transitional mode (TR46)");
case IDN2_INVALID_NONTRANSITIONAL:
return
_
("domain label has character forbidden in non-transitional mode (TR46)");
case IDN2_ALABEL_ROUNDTRIP_FAILED:
return _("A-label roundtrip failed");
default:
return _("Unknown error");
}
}
#define ERR2STR(name) #name
/**
* idn2_strerror_name:
* @rc: return code from another libidn2 function.
*
* Convert internal libidn2 error code to a string corresponding to
* internal header file symbols. For example,
* idn2_strerror_name(IDN2_MALLOC) will return the string
* "IDN2_MALLOC".
*
* The caller must not attempt to de-allocate the returned string.
*
* Return value: A string corresponding to error code symbol.
**/
const char *
idn2_strerror_name (int rc)
{
switch (rc)
{
case IDN2_OK:
return ERR2STR (IDN2_OK);
case IDN2_MALLOC:
return ERR2STR (IDN2_MALLOC);
case IDN2_NO_CODESET:
return ERR2STR (IDN2_NO_NODESET);
case IDN2_ICONV_FAIL:
return ERR2STR (IDN2_ICONV_FAIL);
case IDN2_ENCODING_ERROR:
return ERR2STR (IDN2_ENCODING_ERROR);
case IDN2_NFC:
return ERR2STR (IDN2_NFC);
case IDN2_PUNYCODE_BAD_INPUT:
return ERR2STR (IDN2_PUNYCODE_BAD_INPUT);
case IDN2_PUNYCODE_BIG_OUTPUT:
return ERR2STR (IDN2_PUNYCODE_BIG_OUTPUT);
case IDN2_PUNYCODE_OVERFLOW:
return ERR2STR (IDN2_PUNYCODE_OVERFLOW);
case IDN2_TOO_BIG_DOMAIN:
return ERR2STR (IDN2_TOO_BIG_DOMAIN);
case IDN2_TOO_BIG_LABEL:
return ERR2STR (IDN2_TOO_BIG_LABEL);
case IDN2_INVALID_ALABEL:
return ERR2STR (IDN2_INVALID_ALABEL);
case IDN2_UALABEL_MISMATCH:
return ERR2STR (IDN2_UALABEL_MISMATCH);
case IDN2_INVALID_FLAGS:
return ERR2STR (IDN2_INVALID_FLAGS);
case IDN2_NOT_NFC:
return ERR2STR (IDN2_NOT_NFC);
case IDN2_2HYPHEN:
return ERR2STR (IDN2_2HYPHEN);
case IDN2_HYPHEN_STARTEND:
return ERR2STR (IDN2_HYPHEN_STARTEND);
case IDN2_LEADING_COMBINING:
return ERR2STR (IDN2_LEADING_COMBINING);
case IDN2_DISALLOWED:
return ERR2STR (IDN2_DISALLOWED);
case IDN2_CONTEXTJ:
return ERR2STR (IDN2_CONTEXTJ);
case IDN2_CONTEXTJ_NO_RULE:
return ERR2STR (IDN2_CONTEXTJ_NO_RULE);
case IDN2_CONTEXTO:
return ERR2STR (IDN2_CONTEXTO);
case IDN2_CONTEXTO_NO_RULE:
return ERR2STR (IDN2_CONTEXTO_NO_RULE);
case IDN2_UNASSIGNED:
return ERR2STR (IDN2_UNASSIGNED);
case IDN2_BIDI:
return ERR2STR (IDN2_BIDI);
case IDN2_DOT_IN_LABEL:
return ERR2STR (IDN2_DOT_IN_LABEL);
case IDN2_INVALID_TRANSITIONAL:
return ERR2STR (IDN2_INVALID_TRANSITIONAL);
case IDN2_INVALID_NONTRANSITIONAL:
return ERR2STR (IDN2_INVALID_NONTRANSITIONAL);
case IDN2_ALABEL_ROUNDTRIP_FAILED:
return ERR2STR (IDN2_ALABEL_ROUNDTRIP_FAILED);
default:
return "IDN2_UNKNOWN";
}
}
|