idna.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* idna.h --- Declarations for Internationalized Domain Name in Applications.
  2. * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
  3. * Simon Josefsson
  4. *
  5. * This file is part of GNU Libidn.
  6. *
  7. * GNU Libidn is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * GNU Libidn is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with GNU Libidn; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  20. *
  21. */
  22. #ifndef IDNA_H
  23. # define IDNA_H
  24. # ifndef IDNAPI
  25. # if defined LIBIDN_BUILDING && defined HAVE_VISIBILITY && HAVE_VISIBILITY
  26. # define IDNAPI __attribute__((__visibility__("default")))
  27. # elif defined LIBIDN_BUILDING && defined _MSC_VER && ! defined LIBIDN_STATIC
  28. # define IDNAPI __declspec(dllexport)
  29. # elif defined _MSC_VER && ! defined LIBIDN_STATIC
  30. # define IDNAPI __declspec(dllimport)
  31. # else
  32. # define IDNAPI
  33. # endif
  34. # endif
  35. # include <stddef.h> /* size_t */
  36. # include <idn-int.h> /* uint32_t */
  37. # ifdef __cplusplus
  38. extern "C"
  39. {
  40. # endif
  41. /* Error codes. */
  42. typedef enum
  43. {
  44. IDNA_SUCCESS = 0,
  45. IDNA_STRINGPREP_ERROR = 1,
  46. IDNA_PUNYCODE_ERROR = 2,
  47. IDNA_CONTAINS_NON_LDH = 3,
  48. /* Workaround typo in earlier versions. */
  49. IDNA_CONTAINS_LDH = IDNA_CONTAINS_NON_LDH,
  50. IDNA_CONTAINS_MINUS = 4,
  51. IDNA_INVALID_LENGTH = 5,
  52. IDNA_NO_ACE_PREFIX = 6,
  53. IDNA_ROUNDTRIP_VERIFY_ERROR = 7,
  54. IDNA_CONTAINS_ACE_PREFIX = 8,
  55. IDNA_ICONV_ERROR = 9,
  56. /* Internal errors. */
  57. IDNA_MALLOC_ERROR = 201,
  58. IDNA_DLOPEN_ERROR = 202
  59. } Idna_rc;
  60. /* IDNA flags */
  61. typedef enum
  62. {
  63. IDNA_ALLOW_UNASSIGNED = 0x0001,
  64. IDNA_USE_STD3_ASCII_RULES = 0x0002
  65. } Idna_flags;
  66. # ifndef IDNA_ACE_PREFIX
  67. # define IDNA_ACE_PREFIX "xn--"
  68. # endif
  69. extern IDNAPI const char *idna_strerror (Idna_rc rc);
  70. /* Core functions */
  71. extern IDNAPI int idna_to_ascii_4i (const uint32_t * in, size_t inlen,
  72. char *out, int flags);
  73. extern IDNAPI int idna_to_unicode_44i (const uint32_t * in, size_t inlen,
  74. uint32_t * out, size_t * outlen,
  75. int flags);
  76. /* Wrappers that handle several labels */
  77. extern IDNAPI int idna_to_ascii_4z (const uint32_t * input,
  78. char **output, int flags);
  79. extern IDNAPI int idna_to_ascii_8z (const char *input, char **output,
  80. int flags);
  81. extern IDNAPI int idna_to_ascii_lz (const char *input, char **output,
  82. int flags);
  83. extern IDNAPI int idna_to_unicode_4z4z (const uint32_t * input,
  84. uint32_t ** output, int flags);
  85. extern IDNAPI int idna_to_unicode_8z4z (const char *input,
  86. uint32_t ** output, int flags);
  87. extern IDNAPI int idna_to_unicode_8z8z (const char *input,
  88. char **output, int flags);
  89. extern IDNAPI int idna_to_unicode_8zlz (const char *input,
  90. char **output, int flags);
  91. extern IDNAPI int idna_to_unicode_lzlz (const char *input,
  92. char **output, int flags);
  93. # ifdef __cplusplus
  94. }
  95. # endif
  96. #endif /* IDNA_H */