Update.
[libidn.git] / lib / tld.h
blob206106c31b587fa6b569ed571f46c735def466d3
1 /* tld.h --- Declarations for TLD restriction checking.
2 * Copyright (C) 2004 Simon Josefsson.
3 * Copyright (C) 2003, 2004 Free Software Foundation, Inc.
5 * Author: Thomas Jacob, Internet24.de
7 * This file is part of GNU Libidn.
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.
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.
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
25 #ifndef _TLD_H
26 #define _TLD_H
28 #ifdef __cplusplus
29 extern "C"
31 #endif
33 /* Get size_t. */
34 #include <stdlib.h>
36 /* Get uint32_t. */
37 #include <idn-int.h>
39 /* Interval of valid code points in the TLD. */
40 struct Tld_table_element
42 uint32_t start; /* Start of range. */
43 uint32_t end; /* End of range, end == start if single. */
45 typedef struct Tld_table_element Tld_table_element;
47 /* List valid code points in a TLD. */
48 struct Tld_table
50 const char *name; /* TLD name, e.g., "no". */
51 const char *version; /* Version string from TLD file. */
52 size_t nvalid; /* Number of entries in data. */
53 const Tld_table_element *valid; /* Sorted array of valid code points. */
55 typedef struct Tld_table Tld_table;
57 /* Error codes. */
58 typedef enum
60 TLD_SUCCESS = 0,
61 TLD_INVALID = 1, /* Invalid character found. */
62 TLD_NODATA = 2, /* Char, domain or inlen = 0. */
63 TLD_MALLOC_ERROR = 3,
64 TLD_ICONV_ERROR = 4,
65 TLD_NO_TLD = 5,
66 /* Workaround typo in earlier versions. */
67 TLD_NOTLD = TLD_NO_TLD
68 } Tld_rc;
70 extern const char *tld_strerror (Tld_rc rc);
72 /* Extract TLD, as ASCII string, of UCS4 domain name into "out". */
73 int tld_get_4 (const uint32_t * in, size_t inlen, char **out);
74 int tld_get_4z (const uint32_t * in, char **out);
75 int tld_get_z (const char *in, char **out);
77 /* Return structure corresponding to the named TLD from specified
78 * list of TLD tables, or return NULL if no matching TLD can be
79 * found. */
80 const Tld_table *tld_get_table (const char *tld, const Tld_table ** tables);
82 /* Return structure corresponding to the named TLD, first looking
83 * thru overrides then thru built-in list, or return NULL if no
84 * matching TLD can be found. */
85 const Tld_table *tld_default_table (const char *tld,
86 const Tld_table ** overrides);
88 /* Check NAMEPREPPED domain name for valid characters as defined by
89 * the relevant registering body (plus [a-z0-9.-]). If error is
90 * TLD_INVALID, set errpos to position of offending character. */
91 int tld_check_4t (const uint32_t * in, size_t inlen, size_t * errpos,
92 const Tld_table * tld);
93 int tld_check_4tz (const uint32_t * in, size_t * errpos,
94 const Tld_table * tld);
96 /* Utility interfaces that uses tld_get_4* to find TLD of string,
97 then tld_default_table (with overrides) to find proper TLD table
98 for the string, and then hands over to tld_check_4t*. */
99 int tld_check_4 (const uint32_t * in, size_t inlen, size_t * errpos,
100 const Tld_table ** overrides);
101 int tld_check_4z (const uint32_t * in, size_t * errpos,
102 const Tld_table ** overrides);
103 int tld_check_8z (const char *in, size_t * errpos,
104 const Tld_table ** overrides);
105 int tld_check_lz (const char *in, size_t * errpos,
106 const Tld_table ** overrides);
108 #ifdef __cplusplus
110 #endif
111 #endif /* _TLD_H */