(Tld_table): Change valid definition.
[libidn.git] / lib / tld.h
blobf2e14df70ff152afd5a0a9cdfd73f5644e8863e3
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 char *name; /* TLD name, e.g., "no". */
51 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_NOTLD = 5
66 } Tld_rc;
68 /* Extract TLD, as ASCII string, of UCS4 domain name into "out". */
69 int tld_get_4 (const uint32_t * in, size_t inlen, char **out);
70 int tld_get_4z (const uint32_t * in, char **out);
71 int tld_get_z (const char *in, char **out);
73 /* Return structure corresponding to the named TLD from specified
74 * list of TLD tables, or return NULL if no matching TLD can be
75 * found. */
76 const Tld_table *tld_get_table (const char *tld, const Tld_table ** tables);
78 /* Return structure corresponding to the named TLD, first looking
79 * thru overrides then thru built-in list, or return NULL if no
80 * matching TLD can be found. */
81 const Tld_table *tld_default_table (const char *tld,
82 const Tld_table ** overrides);
84 /* Check NAMEPREPPED domain name for valid characters as defined by
85 * the relevant registering body (plus [a-z0-9.-]). If error is
86 * TLD_INVALID, set errpos to position of offending character. */
87 int tld_check_4t (const uint32_t * in, size_t inlen, size_t * errpos,
88 const Tld_table * tld);
89 int tld_check_4tz (const uint32_t * in, size_t * errpos,
90 const Tld_table * tld);
92 /* Utility interfaces that uses tld_get_4* to find TLD of string,
93 then tld_default_table (with overrides) to find proper TLD table
94 for the string, and then hands over to tld_check_4t*. */
95 int tld_check_4 (const uint32_t * in, size_t inlen, size_t * errpos,
96 const Tld_table ** overrides);
97 int tld_check_4z (const uint32_t * in, size_t * errpos,
98 const Tld_table ** overrides);
99 int tld_check_8z (const char *in, size_t * errpos,
100 const Tld_table ** overrides);
101 int tld_check_lz (const char *in, size_t * errpos,
102 const Tld_table ** overrides);
104 #ifdef __cplusplus
106 #endif
107 #endif /* _TLD_H */