You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

punycode.h 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Copyright (c) 2014, Vsevolod Stakhov
  2. * All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above copyright
  9. * notice, this list of conditions and the following disclaimer in the
  10. * documentation and/or other materials provided with the distribution.
  11. *
  12. * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
  13. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  15. * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
  16. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  17. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  18. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  19. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  20. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. */
  23. #ifndef PUNYCODE_H_
  24. #define PUNYCODE_H_
  25. #include <stdbool.h>
  26. #include <stdint.h>
  27. /**
  28. * Convert an UCS4 string to a puny-coded DNS label string suitable
  29. * when combined with delimiters and other labels for DNS lookup.
  30. *
  31. * @param in an UCS4 string to convert
  32. * @param in_len the length of in.
  33. * @param out the resulting puny-coded string. The string is not NULL
  34. * terminated.
  35. * @param out_len before processing out_len should be the length of
  36. * the out variable, after processing it will be the length of the out
  37. * string.
  38. *
  39. * @return returns 0 on success, an wind error code otherwise
  40. */
  41. bool rdns_punycode_label_toascii (const uint32_t *in, size_t in_len, char *out, size_t *out_len);
  42. /**
  43. * Convert an UTF-8 string to an UCS4 string.
  44. *
  45. * @param in an UTF-8 string to convert.
  46. * @param out the resulting UCS4 string
  47. * @param out_len before processing out_len should be the length of
  48. * the out variable, after processing it will be the length of the out
  49. * string.
  50. *
  51. * @return returns 0 on success, an -1 otherwise
  52. * @ingroup wind
  53. */
  54. int rdns_utf8_to_ucs4 (const char *in, size_t in_len, uint32_t **out, size_t *out_len);
  55. #endif /* PUNYCODE_H_ */