nsIDNKitInterface.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved.
  3. *
  4. * By using this file, you agree to the terms and conditions set forth bellow.
  5. *
  6. * LICENSE TERMS AND CONDITIONS
  7. *
  8. * The following License Terms and Conditions apply, unless a different
  9. * license is obtained from Japan Network Information Center ("JPNIC"),
  10. * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
  11. * Chiyoda-ku, Tokyo 101-0047, Japan.
  12. * 1. Use, Modification and Redistribution (including distribution of any
  13. * modified or derived work) in source and/or binary forms is permitted
  14. * under this License Terms and Conditions.
  15. *
  16. * 2. Redistribution of source code must retain the copyright notices as they
  17. * appear in each source code file, this License Terms and Conditions.
  18. *
  19. * 3. Redistribution in binary form must reproduce the Copyright Notice,
  20. * this License Terms and Conditions, in the documentation and/or other
  21. * materials provided with the distribution. For the purposes of binary
  22. * distribution the "Copyright Notice" refers to the following language:
  23. * "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved."
  24. *
  25. * 4. The name of JPNIC may not be used to endorse or promote products
  26. * derived from this Software without specific prior written approval of
  27. * JPNIC.
  28. *
  29. * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
  30. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  31. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  32. * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
  33. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  34. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  35. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  36. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  37. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  38. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  39. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  40. */
  41. #ifndef nsIDNKitWrapper_h__
  42. #define nsIDNKitWrapper_h__
  43. #include <stdint.h>
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif /* __cplusplus */
  47. /*
  48. * libidnkit result code.
  49. */
  50. typedef enum {
  51. idn_success,
  52. idn_notfound,
  53. idn_invalid_encoding,
  54. idn_invalid_syntax,
  55. idn_invalid_name,
  56. idn_invalid_message,
  57. idn_invalid_action,
  58. idn_invalid_codepoint,
  59. idn_invalid_length,
  60. idn_buffer_overflow,
  61. idn_noentry,
  62. idn_nomemory,
  63. idn_nofile,
  64. idn_nomapping,
  65. idn_context_required,
  66. idn_prohibited,
  67. idn_failure /* !!This must be the last one!! */
  68. } idn_result_t;
  69. /*
  70. * BIDI type codes.
  71. */
  72. typedef enum {
  73. idn_biditype_r_al,
  74. idn_biditype_l,
  75. idn_biditype_others
  76. } idn_biditype_t;
  77. /*
  78. * A Handle for nameprep operations.
  79. */
  80. typedef struct idn_nameprep *idn_nameprep_t;
  81. /*
  82. * The latest version of nameprep.
  83. */
  84. #define IDN_NAMEPREP_CURRENT "nameprep-11"
  85. #undef assert
  86. #define assert(a)
  87. #define TRACE(a)
  88. /* race.c */
  89. idn_result_t race_decode_decompress(const char *from,
  90. uint16_t *buf,
  91. size_t buflen);
  92. idn_result_t race_compress_encode(const uint16_t *p,
  93. int compress_mode,
  94. char *to, size_t tolen);
  95. int get_compress_mode(uint16_t *p);
  96. /* nameprep.c */
  97. /*
  98. * Create a handle for nameprep operations.
  99. * The handle is stored in '*handlep', which is used other functions
  100. * in this module.
  101. * The version of the NAMEPREP specification can be specified with
  102. * 'version' parameter. If 'version' is nullptr, the latest version
  103. * is used.
  104. *
  105. * Returns:
  106. * idn_success -- ok.
  107. * idn_notfound -- specified version not found.
  108. */
  109. idn_result_t
  110. idn_nameprep_create(const char *version, idn_nameprep_t *handlep);
  111. /*
  112. * Close a handle, which was created by 'idn_nameprep_create'.
  113. */
  114. void
  115. idn_nameprep_destroy(idn_nameprep_t handle);
  116. /*
  117. * Perform character mapping on an UCS4 string specified by 'from', and
  118. * store the result into 'to', whose length is specified by 'tolen'.
  119. *
  120. * Returns:
  121. * idn_success -- ok.
  122. * idn_buffer_overflow -- result buffer is too small.
  123. */
  124. idn_result_t
  125. idn_nameprep_map(idn_nameprep_t handle, const uint32_t *from,
  126. uint32_t *to, size_t tolen);
  127. /*
  128. * Check if an UCS4 string 'str' contains any prohibited characters specified
  129. * by the draft. If found, the pointer to the first such character is stored
  130. * into '*found'. Otherwise '*found' will be nullptr.
  131. *
  132. * Returns:
  133. * idn_success -- check has been done properly. (But this
  134. * does not mean that no prohibited character
  135. * was found. Check '*found' to see the
  136. * result.)
  137. */
  138. idn_result_t
  139. idn_nameprep_isprohibited(idn_nameprep_t handle, const uint32_t *str,
  140. const uint32_t **found);
  141. /*
  142. * Check if an UCS4 string 'str' contains any unassigned characters specified
  143. * by the draft. If found, the pointer to the first such character is stored
  144. * into '*found'. Otherwise '*found' will be nullptr.
  145. *
  146. * Returns:
  147. * idn_success -- check has been done properly. (But this
  148. * does not mean that no unassinged character
  149. * was found. Check '*found' to see the
  150. * result.)
  151. */
  152. idn_result_t
  153. idn_nameprep_isunassigned(idn_nameprep_t handle, const uint32_t *str,
  154. const uint32_t **found);
  155. /*
  156. * Check if an UCS4 string 'str' is valid string specified by ``bidi check''
  157. * of the draft. If it is not valid, the pointer to the first invalid
  158. * character is stored into '*found'. Otherwise '*found' will be nullptr.
  159. *
  160. * Returns:
  161. * idn_success -- check has been done properly. (But this
  162. * does not mean that the string was valid.
  163. * Check '*found' to see the result.)
  164. */
  165. idn_result_t
  166. idn_nameprep_isvalidbidi(idn_nameprep_t handle, const uint32_t *str,
  167. const uint32_t **found);
  168. #ifdef __cplusplus
  169. }
  170. #endif /* __cplusplus */
  171. #endif /* nsIDNKitWrapper_h__ */