Update.
[libidn.git] / lib / strerror-idna.c
blob75299e4451884b2279590f51a2feeea4190e6b28
1 /* strerror-idna.c --- Convert IDNA errors into text.
2 * Copyright (C) 2004 Simon Josefsson
4 * This file is part of GNU Libidn.
6 * GNU Libidn is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * GNU Libidn is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with GNU Libidn; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "idna.h"
24 #include "gettext.h"
25 #define _(String) dgettext (PACKAGE, String)
27 /**
28 * idna_strerror - return string describing idna error code
29 * @rc: an #Idna_rc return code.
31 * Convert a return code integer to a text string. This string can be
32 * used to output a diagnostic message to the user.
34 * IDNA_SUCCESS: Successful operation. This value is guaranteed to
35 * always be zero, the remaining ones are only guaranteed to hold
36 * non-zero values, for logical comparison purposes.
37 * IDNA_STRINGPREP_ERROR: Error during string preparation.
38 * IDNA_PUNYCODE_ERROR: Error during punycode operation.
39 * IDNA_CONTAINS_NON_LDH: For IDNA_USE_STD3_ASCII_RULES, indicate that
40 * the string contains non-LDH ASCII characters.
41 * IDNA_CONTAINS_MINUS: For IDNA_USE_STD3_ASCII_RULES, indicate that
42 * the string contains a leading or trailing hyphen-minus (U+002D).
43 * IDNA_INVALID_LENGTH: The final output string is not within the
44 * (inclusive) range 1 to 63 characters.
45 * IDNA_NO_ACE_PREFIX: The string does not contain the ACE prefix
46 * (for ToUnicode).
47 * IDNA_ROUNDTRIP_VERIFY_ERROR: The ToASCII operation on output
48 * string does not equal the input.
49 * IDNA_CONTAINS_ACE_PREFIX: The input contains the ACE prefix (for
50 * ToASCII).
51 * IDNA_ICONV_ERROR: Could not convert string in locale encoding.
52 * IDNA_MALLOC_ERROR: Could not allocate buffer (this is typically a
53 * fatal error).
54 * IDNA_DLOPEN_ERROR: Could not dlopen the libcidn DSO (only used
55 * internally in libc).
57 * Return value: Returns a pointer to a statically allocated string
58 * containing a description of the error with the return code @rc.
59 **/
60 const char *
61 idna_strerror (Idna_rc rc)
63 const char *p;
65 bindtextdomain (PACKAGE, LOCALEDIR);
67 switch (rc)
69 case IDNA_SUCCESS:
70 p = _("Success");
71 break;
73 case IDNA_STRINGPREP_ERROR:
74 p = _("String preparation failed");
75 break;
77 case IDNA_PUNYCODE_ERROR:
78 p = _("Punycode failed");
79 break;
81 case IDNA_CONTAINS_NON_LDH:
82 p = _("Non-digit/letter/hyphen in input");
83 break;
85 case IDNA_CONTAINS_MINUS:
86 p = _("Forbidden leading or trailing minus sign (`-')");
87 break;
89 case IDNA_INVALID_LENGTH:
90 p = _("Output would be too large or too small");
91 break;
93 case IDNA_NO_ACE_PREFIX:
94 p = _("Input does not start with ACE prefix (`xn--')");
95 break;
97 case IDNA_ROUNDTRIP_VERIFY_ERROR:
98 p = _("String not idempotent under ToASCII");
99 break;
101 case IDNA_CONTAINS_ACE_PREFIX:
102 p = _("Input already contain ACE prefix (`xn--')");
103 break;
105 case IDNA_ICONV_ERROR:
106 p = _("System iconv failed");
107 break;
109 case IDNA_MALLOC_ERROR:
110 p = _("Cannot allocate memory");
111 break;
113 case IDNA_DLOPEN_ERROR:
114 p = _("System dlopen failed");
115 break;
117 default:
118 p = _("Unknown error");
119 break;
122 return p;