File: error.c

package info (click to toggle)
libidn2-0 0.10-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 7,124 kB
  • sloc: ansic: 23,358; sh: 13,686; perl: 720; makefile: 153
file content (283 lines) | stat: -rw-r--r-- 6,417 bytes parent folder | download | duplicates (2)
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/* error.c - libidn2 error handling helpers.
   Copyright (C) 2011-2014 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) 0

/**
 * 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)
{
  const char *p;

  bindtextdomain (PACKAGE, LOCALEDIR);

  switch (rc)
    {
    case IDN2_OK:
      p = _("success");
      break;

    case IDN2_MALLOC:
      p = _("out of memory");
      break;

    case IDN2_NO_CODESET:
      p = _("could not determine locale encoding format");
      break;

    case IDN2_ICONV_FAIL:
      p = _("could not convert string to UTF-8");
      break;

    case IDN2_ENCODING_ERROR:
      p = _("string encoding error");
      break;

    case IDN2_NFC:
      p = _("string could not be NFC normalized");
      break;

    case IDN2_PUNYCODE_BAD_INPUT:
      p = _("string contains invalid punycode data");
      break;

    case IDN2_PUNYCODE_BIG_OUTPUT:
      p = _("punycode encoded data will be too large");
      break;

    case IDN2_PUNYCODE_OVERFLOW:
      p = _("punycode conversion resulted in overflow");
      break;

    case IDN2_TOO_BIG_DOMAIN:
      p = _("domain name longer than 255 characters");
      break;

    case IDN2_TOO_BIG_LABEL:
      p = _("domain label longer than 63 characters");
      break;

    case IDN2_INVALID_ALABEL:
      p = _("input A-label is not valid");
      break;

    case IDN2_UALABEL_MISMATCH:
      p = _("input A-label and U-label does not match");
      break;

    case IDN2_NOT_NFC:
      p = _("string is not in Unicode NFC format");
      break;

    case IDN2_2HYPHEN:
      p = _("string contains forbidden two hyphens pattern");
      break;

    case IDN2_HYPHEN_STARTEND:
      p = _("string start/ends with forbidden hyphen");
      break;

    case IDN2_LEADING_COMBINING:
      p = _("string contains a forbidden leading combining character");
      break;

    case IDN2_DISALLOWED:
      p = _("string contains a disallowed character");
      break;

    case IDN2_CONTEXTJ:
      p = _("string contains a forbidden context-j character");
      break;

    case IDN2_CONTEXTJ_NO_RULE:
      p = _("string contains a context-j character with null rule");
      break;

    case IDN2_CONTEXTO:
      p = _("string contains a forbidden context-o character");
      break;

    case IDN2_CONTEXTO_NO_RULE:
      p = _("string contains a context-o character with null rule");
      break;

    case IDN2_UNASSIGNED:
      p = _("string contains unassigned code point");
      break;

    case IDN2_BIDI:
      p = _("string has forbidden bi-directional properties");
      break;

    default:
      p = _("Unknown error");
      break;
    }

  return p;
}

#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)
{
  const char *p;

  switch (rc)
    {
    case IDN2_OK:
      p = ERR2STR (IDN2_OK);
      break;

    case IDN2_MALLOC:
      p = ERR2STR (IDN2_MALLOC);
      break;

    case IDN2_NO_CODESET:
      p = ERR2STR (IDN2_NO_NODESET);
      break;

    case IDN2_ICONV_FAIL:
      p = ERR2STR (IDN2_ICONV_FAIL);
      break;

    case IDN2_ENCODING_ERROR:
      p = ERR2STR (IDN2_ENCODING_ERROR);
      break;

    case IDN2_NFC:
      p = ERR2STR (IDN2_NFC);
      break;

    case IDN2_PUNYCODE_BAD_INPUT:
      p = ERR2STR (IDN2_PUNYCODE_BAD_INPUT);
      break;

    case IDN2_PUNYCODE_BIG_OUTPUT:
      p = ERR2STR (IDN2_PUNYCODE_BIG_OUTPUT);
      break;

    case IDN2_PUNYCODE_OVERFLOW:
      p = ERR2STR (IDN2_PUNYCODE_OVERFLOW);
      break;

    case IDN2_TOO_BIG_DOMAIN:
      p = ERR2STR (IDN2_TOO_BIG_DOMAIN);
      break;

    case IDN2_TOO_BIG_LABEL:
      p = ERR2STR (IDN2_TOO_BIG_LABEL);
      break;

    case IDN2_INVALID_ALABEL:
      p = ERR2STR (IDN2_INVALID_ALABEL);
      break;

    case IDN2_UALABEL_MISMATCH:
      p = ERR2STR (IDN2_UALABEL_MISMATCH);
      break;

    case IDN2_NOT_NFC:
      p = ERR2STR (IDN2_NOT_NFC);
      break;

    case IDN2_2HYPHEN:
      p = ERR2STR (IDN2_2HYPHEN);
      break;

    case IDN2_HYPHEN_STARTEND:
      p = ERR2STR (IDN2_HYPHEN_STARTEND);
      break;

    case IDN2_LEADING_COMBINING:
      p = ERR2STR (IDN2_LEADING_COMBINING);
      break;

    case IDN2_DISALLOWED:
      p = ERR2STR (IDN2_DISALLOWED);
      break;

    case IDN2_CONTEXTJ:
      p = ERR2STR (IDN2_CONTEXTJ);
      break;

    case IDN2_CONTEXTJ_NO_RULE:
      p = ERR2STR (IDN2_CONTEXTJ_NO_RULE);
      break;

    case IDN2_CONTEXTO:
      p = ERR2STR (IDN2_CONTEXTO);
      break;

    case IDN2_CONTEXTO_NO_RULE:
      p = ERR2STR (IDN2_CONTEXTO_NO_RULE);
      break;

    case IDN2_UNASSIGNED:
      p = ERR2STR (IDN2_UNASSIGNED);
      break;

    case IDN2_BIDI:
      p = ERR2STR (IDN2_BIDI);
      break;

    default:
      p = "IDN2_UNKNOWN";
      break;
    }

  return p;
}