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