strerror-stringprep.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* strerror-stringprep.c --- Convert stringprep errors into text.
  2. * Copyright (C) 2004, 2005, 2006, 2007, 2008 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. #ifdef HAVE_CONFIG_H
  22. # include "idn_config.h"
  23. #endif
  24. #include "stringprep.h"
  25. #include "gettext.h"
  26. #define _(String) dgettext (PACKAGE, String)
  27. /**
  28. * stringprep_strerror - return string describing stringprep error code
  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_NFKC_FAILED: The Unicode NFKC operation failed. This
  57. * usually indicate an internal error in the library.
  58. * STRINGPREP_MALLOC_ERROR: The malloc() was out of memory. This is
  59. * usually a fatal error.
  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. stringprep_strerror (Stringprep_rc rc)
  66. {
  67. const char *p;
  68. bindtextdomain (PACKAGE, LOCALEDIR);
  69. switch (rc)
  70. {
  71. case STRINGPREP_OK:
  72. p = _("Success");
  73. break;
  74. case STRINGPREP_CONTAINS_UNASSIGNED:
  75. p = _("Forbidden unassigned code points in input");
  76. break;
  77. case STRINGPREP_CONTAINS_PROHIBITED:
  78. p = _("Prohibited code points in input");
  79. break;
  80. case STRINGPREP_BIDI_BOTH_L_AND_RAL:
  81. p = _("Conflicting bidirectional properties in input");
  82. break;
  83. case STRINGPREP_BIDI_LEADTRAIL_NOT_RAL:
  84. p = _("Malformed bidirectional string");
  85. break;
  86. case STRINGPREP_BIDI_CONTAINS_PROHIBITED:
  87. p = _("Prohibited bidirectional code points in input");
  88. break;
  89. case STRINGPREP_TOO_SMALL_BUFFER:
  90. p = _("Output would exceed the buffer space provided");
  91. break;
  92. case STRINGPREP_PROFILE_ERROR:
  93. p = _("Error in stringprep profile definition");
  94. break;
  95. case STRINGPREP_FLAG_ERROR:
  96. p = _("Flag conflict with profile");
  97. break;
  98. case STRINGPREP_UNKNOWN_PROFILE:
  99. p = _("Unknown profile");
  100. break;
  101. case STRINGPREP_NFKC_FAILED:
  102. p = _("Unicode normalization failed (internal error)");
  103. break;
  104. case STRINGPREP_MALLOC_ERROR:
  105. p = _("Cannot allocate memory");
  106. break;
  107. default:
  108. p = _("Unknown error");
  109. break;
  110. }
  111. return p;
  112. }