idna.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* idna.h --- Prototypes for Internationalized Domain Name library.
  2. Copyright (C) 2002-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. #ifndef IDNA_H
  22. # define IDNA_H
  23. /**
  24. * SECTION:idna
  25. * @title: idna.h
  26. * @short_description: IDNA-related functions
  27. *
  28. * IDNA-related functions.
  29. */
  30. /**
  31. * IDNAPI:
  32. *
  33. * Symbol holding shared library API visibility decorator.
  34. *
  35. * This is used internally by the library header file and should never
  36. * be used or modified by the application.
  37. *
  38. * https://www.gnu.org/software/gnulib/manual/html_node/Exported-Symbols-of-Shared-Libraries.html
  39. */
  40. # ifndef IDNAPI
  41. # define IDNAPI
  42. # endif
  43. # include <stddef.h> /* size_t */
  44. # include "idn-int.h" /* uint32_t */
  45. # ifdef __cplusplus
  46. extern "C"
  47. {
  48. # endif
  49. /* Error codes. */
  50. typedef enum
  51. {
  52. IDNA_SUCCESS = 0,
  53. IDNA_STRINGPREP_ERROR = 1,
  54. IDNA_PUNYCODE_ERROR = 2,
  55. IDNA_CONTAINS_NON_LDH = 3,
  56. /* Workaround typo in earlier versions. */
  57. IDNA_CONTAINS_LDH = IDNA_CONTAINS_NON_LDH,
  58. IDNA_CONTAINS_MINUS = 4,
  59. IDNA_INVALID_LENGTH = 5,
  60. IDNA_NO_ACE_PREFIX = 6,
  61. IDNA_ROUNDTRIP_VERIFY_ERROR = 7,
  62. IDNA_CONTAINS_ACE_PREFIX = 8,
  63. IDNA_ICONV_ERROR = 9,
  64. /* Internal errors. */
  65. IDNA_MALLOC_ERROR = 201,
  66. IDNA_DLOPEN_ERROR = 202
  67. } Idna_rc;
  68. /* IDNA flags */
  69. typedef enum
  70. {
  71. IDNA_ALLOW_UNASSIGNED = 0x0001,
  72. IDNA_USE_STD3_ASCII_RULES = 0x0002
  73. } Idna_flags;
  74. # ifndef IDNA_ACE_PREFIX
  75. # define IDNA_ACE_PREFIX "xn--"
  76. # endif
  77. # ifndef IDNA_LABEL_MAX_LENGTH
  78. # define IDNA_LABEL_MAX_LENGTH 255
  79. # endif
  80. extern IDNAPI const char *idna_strerror (Idna_rc rc);
  81. /* Core functions */
  82. extern IDNAPI int idna_to_ascii_4i (const uint32_t * in, size_t inlen,
  83. char *out, int flags);
  84. extern IDNAPI int idna_to_unicode_44i (const uint32_t * in, size_t inlen,
  85. uint32_t * out, size_t *outlen,
  86. int flags);
  87. /* Wrappers that handle several labels */
  88. extern IDNAPI int idna_to_ascii_4z (const uint32_t * input,
  89. char **output, int flags);
  90. extern IDNAPI int idna_to_ascii_8z (const char *input, char **output,
  91. int flags);
  92. extern IDNAPI int idna_to_ascii_lz (const char *input, char **output,
  93. int flags);
  94. extern IDNAPI int idna_to_unicode_4z4z (const uint32_t * input,
  95. uint32_t ** output, int flags);
  96. extern IDNAPI int idna_to_unicode_8z4z (const char *input,
  97. uint32_t ** output, int flags);
  98. extern IDNAPI int idna_to_unicode_8z8z (const char *input,
  99. char **output, int flags);
  100. extern IDNAPI int idna_to_unicode_8zlz (const char *input,
  101. char **output, int flags);
  102. extern IDNAPI int idna_to_unicode_lzlz (const char *input,
  103. char **output, int flags);
  104. # ifdef __cplusplus
  105. }
  106. # endif
  107. #endif /* IDNA_H */