strerror-stringprep.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /* strerror-stringprep.c --- Convert stringprep 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 "stringprep.h"
  25. #include "gettext.h"
  26. #define _(String) dgettext (PACKAGE, String)
  27. /**
  28. * stringprep_strerror:
  29. * @rc: a #Stringprep_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. * STRINGPREP_OK: 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. * STRINGPREP_CONTAINS_UNASSIGNED: String contain unassigned Unicode
  38. * code points, which is forbidden by the profile.
  39. * STRINGPREP_CONTAINS_PROHIBITED: String contain code points
  40. * prohibited by the profile.
  41. * STRINGPREP_BIDI_BOTH_L_AND_RAL: String contain code points with
  42. * conflicting bidirection category.
  43. * STRINGPREP_BIDI_LEADTRAIL_NOT_RAL: Leading and trailing character
  44. * in string not of proper bidirectional category.
  45. * STRINGPREP_BIDI_CONTAINS_PROHIBITED: Contains prohibited code
  46. * points detected by bidirectional code.
  47. * STRINGPREP_TOO_SMALL_BUFFER: Buffer handed to function was too
  48. * small. This usually indicate a problem in the calling
  49. * application.
  50. * STRINGPREP_PROFILE_ERROR: The stringprep profile was inconsistent.
  51. * This usually indicate an internal error in the library.
  52. * STRINGPREP_FLAG_ERROR: The supplied flag conflicted with profile.
  53. * This usually indicate a problem in the calling application.
  54. * STRINGPREP_UNKNOWN_PROFILE: The supplied profile name was not
  55. * known to the library.
  56. * STRINGPREP_ICONV_ERROR: Character encoding conversion error.
  57. * STRINGPREP_NFKC_FAILED: The Unicode NFKC operation failed. This
  58. * usually indicate an internal error in the library.
  59. * STRINGPREP_MALLOC_ERROR: The malloc() was out of memory. This is
  60. * usually a fatal error.
  61. *
  62. * Return value: Returns a pointer to a statically allocated string
  63. * containing a description of the error with the return code @rc.
  64. **/
  65. const char *
  66. stringprep_strerror (Stringprep_rc rc)
  67. {
  68. const char *p;
  69. bindtextdomain (PACKAGE, LOCALEDIR);
  70. switch (rc)
  71. {
  72. case STRINGPREP_OK:
  73. p = _("Success");
  74. break;
  75. case STRINGPREP_CONTAINS_UNASSIGNED:
  76. p = _("Forbidden unassigned code points in input");
  77. break;
  78. case STRINGPREP_CONTAINS_PROHIBITED:
  79. p = _("Prohibited code points in input");
  80. break;
  81. case STRINGPREP_BIDI_BOTH_L_AND_RAL:
  82. p = _("Conflicting bidirectional properties in input");
  83. break;
  84. case STRINGPREP_BIDI_LEADTRAIL_NOT_RAL:
  85. p = _("Malformed bidirectional string");
  86. break;
  87. case STRINGPREP_BIDI_CONTAINS_PROHIBITED:
  88. p = _("Prohibited bidirectional code points in input");
  89. break;
  90. case STRINGPREP_TOO_SMALL_BUFFER:
  91. p = _("Output would exceed the buffer space provided");
  92. break;
  93. case STRINGPREP_PROFILE_ERROR:
  94. p = _("Error in stringprep profile definition");
  95. break;
  96. case STRINGPREP_FLAG_ERROR:
  97. p = _("Flag conflict with profile");
  98. break;
  99. case STRINGPREP_UNKNOWN_PROFILE:
  100. p = _("Unknown profile");
  101. break;
  102. case STRINGPREP_ICONV_ERROR:
  103. p = _("Character encoding conversion error");
  104. break;
  105. case STRINGPREP_NFKC_FAILED:
  106. p = _("Unicode normalization failed (internal error)");
  107. break;
  108. case STRINGPREP_MALLOC_ERROR:
  109. p = _("Cannot allocate memory");
  110. break;
  111. default:
  112. p = _("Unknown error");
  113. break;
  114. }
  115. return p;
  116. }