strerror-idna.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* strerror-idna.c --- Convert IDNA errors into text.
  2. Copyright (C) 2004-2024 Simon Josefsson
  3. This file is part of GNU Libidn.
  4. GNU Libidn is free software: you can redistribute it and/or
  5. modify it under the terms of either:
  6. * the GNU Lesser General Public License as published by the Free
  7. Software Foundation; either version 3 of the License, or (at
  8. your option) any later version.
  9. or
  10. * the GNU General Public License as published by the Free
  11. Software Foundation; either version 2 of the License, or (at
  12. your option) any later version.
  13. or both in parallel, as here.
  14. GNU Libidn is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. General Public License for more details.
  18. You should have received copies of the GNU General Public License and
  19. the GNU Lesser General Public License along with this program. If
  20. not, see <https://www.gnu.org/licenses/>. */
  21. #ifdef HAVE_CONFIG_H
  22. # include "config.h"
  23. #endif
  24. #include "idna.h"
  25. #include "gettext.h"
  26. #define _(String) dgettext (PACKAGE, String)
  27. /**
  28. * idna_strerror:
  29. * @rc: an #Idna_rc return code.
  30. *
  31. * Convert a return code integer to a text string. This string can be
  32. * used to output a diagnostic message to the user.
  33. *
  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: Character encoding conversion error.
  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).
  56. *
  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)
  62. {
  63. const char *p;
  64. bindtextdomain (PACKAGE, LOCALEDIR);
  65. switch (rc)
  66. {
  67. case IDNA_SUCCESS:
  68. p = _("Success");
  69. break;
  70. case IDNA_STRINGPREP_ERROR:
  71. p = _("String preparation failed");
  72. break;
  73. case IDNA_PUNYCODE_ERROR:
  74. p = _("Punycode failed");
  75. break;
  76. case IDNA_CONTAINS_NON_LDH:
  77. p = _("Non-digit/letter/hyphen in input");
  78. break;
  79. case IDNA_CONTAINS_MINUS:
  80. p = _("Forbidden leading or trailing minus sign ('-')");
  81. break;
  82. case IDNA_INVALID_LENGTH:
  83. p = _("Output would be too large or too small");
  84. break;
  85. case IDNA_NO_ACE_PREFIX:
  86. p = _("Input does not start with ACE prefix ('xn--')");
  87. break;
  88. case IDNA_ROUNDTRIP_VERIFY_ERROR:
  89. p = _("String not idempotent under ToASCII");
  90. break;
  91. case IDNA_CONTAINS_ACE_PREFIX:
  92. p = _("Input already contain ACE prefix ('xn--')");
  93. break;
  94. case IDNA_ICONV_ERROR:
  95. p = _("Character encoding conversion error");
  96. break;
  97. case IDNA_MALLOC_ERROR:
  98. p = _("Cannot allocate memory");
  99. break;
  100. case IDNA_DLOPEN_ERROR:
  101. p = _("System dlopen failed");
  102. break;
  103. default:
  104. p = _("Unknown error");
  105. break;
  106. }
  107. return p;
  108. }