tld.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* tld.h --- Declarations for TLD restriction checking.
  2. * Copyright (C) 2004, 2005, 2006, 2007 Simon Josefsson.
  3. * Copyright (C) 2003, 2004 Free Software Foundation, Inc.
  4. *
  5. * Author: Thomas Jacob, Internet24.de
  6. *
  7. * This file is part of GNU Libidn.
  8. *
  9. * GNU Libidn is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  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. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with GNU Libidn; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. *
  23. */
  24. #ifndef _TLD_H
  25. #define _TLD_H
  26. #ifdef __cplusplus
  27. extern "C"
  28. {
  29. #endif
  30. /* Get size_t. */
  31. #include <stdlib.h>
  32. /* Get uint32_t. */
  33. #include "idn-int.h"
  34. /* Interval of valid code points in the TLD. */
  35. struct Tld_table_element
  36. {
  37. uint32_t start; /* Start of range. */
  38. uint32_t end; /* End of range, end == start if single. */
  39. };
  40. typedef struct Tld_table_element Tld_table_element;
  41. /* List valid code points in a TLD. */
  42. struct Tld_table
  43. {
  44. const char *name; /* TLD name, e.g., "no". */
  45. const char *version; /* Version string from TLD file. */
  46. size_t nvalid; /* Number of entries in data. */
  47. const Tld_table_element *valid; /* Sorted array of valid code points. */
  48. };
  49. typedef struct Tld_table Tld_table;
  50. /* Error codes. */
  51. typedef enum
  52. {
  53. TLD_SUCCESS = 0,
  54. TLD_INVALID = 1, /* Invalid character found. */
  55. TLD_NODATA = 2, /* Char, domain or inlen = 0. */
  56. TLD_MALLOC_ERROR = 3,
  57. TLD_ICONV_ERROR = 4,
  58. TLD_NO_TLD = 5,
  59. /* Workaround typo in earlier versions. */
  60. TLD_NOTLD = TLD_NO_TLD
  61. } Tld_rc;
  62. extern const char *tld_strerror (Tld_rc rc);
  63. /* Extract TLD, as ASCII string, of UCS4 domain name into "out". */
  64. int tld_get_4 (const uint32_t * in, size_t inlen, char **out);
  65. int tld_get_4z (const uint32_t * in, char **out);
  66. int tld_get_z (const char *in, char **out);
  67. /* Return structure corresponding to the named TLD from specified
  68. * list of TLD tables, or return NULL if no matching TLD can be
  69. * found. */
  70. const Tld_table *tld_get_table (const char *tld, const Tld_table ** tables);
  71. /* Return structure corresponding to the named TLD, first looking
  72. * thru overrides then thru built-in list, or return NULL if no
  73. * matching TLD can be found. */
  74. const Tld_table *tld_default_table (const char *tld,
  75. const Tld_table ** overrides);
  76. /* Check NAMEPREPPED domain name for valid characters as defined by
  77. * the relevant registering body (plus [a-z0-9.-]). If error is
  78. * TLD_INVALID, set errpos to position of offending character. */
  79. int tld_check_4t (const uint32_t * in, size_t inlen, size_t * errpos,
  80. const Tld_table * tld);
  81. int tld_check_4tz (const uint32_t * in, size_t * errpos,
  82. const Tld_table * tld);
  83. /* Utility interfaces that uses tld_get_4* to find TLD of string,
  84. then tld_default_table (with overrides) to find proper TLD table
  85. for the string, and then hands over to tld_check_4t*. */
  86. int tld_check_4 (const uint32_t * in, size_t inlen, size_t * errpos,
  87. const Tld_table ** overrides);
  88. int tld_check_4z (const uint32_t * in, size_t * errpos,
  89. const Tld_table ** overrides);
  90. int tld_check_8z (const char *in, size_t * errpos,
  91. const Tld_table ** overrides);
  92. int tld_check_lz (const char *in, size_t * errpos,
  93. const Tld_table ** overrides);
  94. #ifdef __cplusplus
  95. }
  96. #endif
  97. #endif /* _TLD_H */