Branch data Line data Source code
1 : : /* strerror-idna.c --- Convert IDNA errors into text.
2 : : Copyright (C) 2004-2013 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 <http://www.gnu.org/licenses/>. */
29 : :
30 : : #ifdef HAVE_CONFIG_H
31 : : # include "config.h"
32 : : #endif
33 : :
34 : : #include "idna.h"
35 : :
36 : : #include "gettext.h"
37 : : #define _(String) dgettext (PACKAGE, String)
38 : :
39 : : /**
40 : : * idna_strerror:
41 : : * @rc: an #Idna_rc return code.
42 : : *
43 : : * Convert a return code integer to a text string. This string can be
44 : : * used to output a diagnostic message to the user.
45 : : *
46 : : * IDNA_SUCCESS: Successful operation. This value is guaranteed to
47 : : * always be zero, the remaining ones are only guaranteed to hold
48 : : * non-zero values, for logical comparison purposes.
49 : : * IDNA_STRINGPREP_ERROR: Error during string preparation.
50 : : * IDNA_PUNYCODE_ERROR: Error during punycode operation.
51 : : * IDNA_CONTAINS_NON_LDH: For IDNA_USE_STD3_ASCII_RULES, indicate that
52 : : * the string contains non-LDH ASCII characters.
53 : : * IDNA_CONTAINS_MINUS: For IDNA_USE_STD3_ASCII_RULES, indicate that
54 : : * the string contains a leading or trailing hyphen-minus (U+002D).
55 : : * IDNA_INVALID_LENGTH: The final output string is not within the
56 : : * (inclusive) range 1 to 63 characters.
57 : : * IDNA_NO_ACE_PREFIX: The string does not contain the ACE prefix
58 : : * (for ToUnicode).
59 : : * IDNA_ROUNDTRIP_VERIFY_ERROR: The ToASCII operation on output
60 : : * string does not equal the input.
61 : : * IDNA_CONTAINS_ACE_PREFIX: The input contains the ACE prefix (for
62 : : * ToASCII).
63 : : * IDNA_ICONV_ERROR: Could not convert string in locale encoding.
64 : : * IDNA_MALLOC_ERROR: Could not allocate buffer (this is typically a
65 : : * fatal error).
66 : : * IDNA_DLOPEN_ERROR: Could not dlopen the libcidn DSO (only used
67 : : * internally in libc).
68 : : *
69 : : * Return value: Returns a pointer to a statically allocated string
70 : : * containing a description of the error with the return code @rc.
71 : : **/
72 : : const char *
73 : 18 : idna_strerror (Idna_rc rc)
74 : : {
75 : : const char *p;
76 : :
77 : 18 : bindtextdomain (PACKAGE, LOCALEDIR);
78 : :
79 [ + + + + : 18 : switch (rc)
+ + + + +
+ + + + ]
80 : : {
81 : : case IDNA_SUCCESS:
82 : 2 : p = _("Success");
83 : 2 : break;
84 : :
85 : : case IDNA_STRINGPREP_ERROR:
86 : 1 : p = _("String preparation failed");
87 : 1 : break;
88 : :
89 : : case IDNA_PUNYCODE_ERROR:
90 : 1 : p = _("Punycode failed");
91 : 1 : break;
92 : :
93 : : case IDNA_CONTAINS_NON_LDH:
94 : 1 : p = _("Non-digit/letter/hyphen in input");
95 : 1 : break;
96 : :
97 : : case IDNA_CONTAINS_MINUS:
98 : 1 : p = _("Forbidden leading or trailing minus sign (`-')");
99 : 1 : break;
100 : :
101 : : case IDNA_INVALID_LENGTH:
102 : 1 : p = _("Output would be too large or too small");
103 : 1 : break;
104 : :
105 : : case IDNA_NO_ACE_PREFIX:
106 : 1 : p = _("Input does not start with ACE prefix (`xn--')");
107 : 1 : break;
108 : :
109 : : case IDNA_ROUNDTRIP_VERIFY_ERROR:
110 : 1 : p = _("String not idempotent under ToASCII");
111 : 1 : break;
112 : :
113 : : case IDNA_CONTAINS_ACE_PREFIX:
114 : 1 : p = _("Input already contain ACE prefix (`xn--')");
115 : 1 : break;
116 : :
117 : : case IDNA_ICONV_ERROR:
118 : 1 : p = _("System iconv failed");
119 : 1 : break;
120 : :
121 : : case IDNA_MALLOC_ERROR:
122 : 1 : p = _("Cannot allocate memory");
123 : 1 : break;
124 : :
125 : : case IDNA_DLOPEN_ERROR:
126 : 1 : p = _("System dlopen failed");
127 : 1 : break;
128 : :
129 : : default:
130 : 5 : p = _("Unknown error");
131 : 5 : break;
132 : : }
133 : :
134 : 18 : return p;
135 : : }
|