libidn: tld.h Source File

libidn 1.38

tld.h
Go to the documentation of this file.
1 /* tld.h --- Declarations for TLD restriction checking.
2 Copyright (C) 2004-2021 Simon Josefsson.
3 Copyright (C) 2003-2021 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 either:
11
12 * the GNU Lesser General Public License as published by the Free
13 Software Foundation; either version 3 of the License, or (at
14 your option) any later version.
15
16 or
17
18 * the GNU General Public License as published by the Free
19 Software Foundation; either version 2 of the License, or (at
20 your option) any later version.
21
22 or both in parallel, as here.
23
24 GNU Libidn is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 General Public License for more details.
28
29 You should have received copies of the GNU General Public License and
30 the GNU Lesser General Public License along with this program. If
31 not, see <http://www.gnu.org/licenses/>. */
32
33 #ifndef TLD_H
34 # define TLD_H
35
44 # ifndef IDNAPI
45 # if defined LIBIDN_BUILDING && defined HAVE_VISIBILITY && HAVE_VISIBILITY
46 # define IDNAPI __attribute__((__visibility__("default")))
47 # elif defined LIBIDN_BUILDING && defined _MSC_VER && ! defined LIBIDN_STATIC
48 # define IDNAPI __declspec(dllexport)
49 # elif defined _MSC_VER && ! defined LIBIDN_STATIC
50 # define IDNAPI __declspec(dllimport)
51 # else
52 # define IDNAPI
53 # endif
54 # endif
55
56 # ifdef __cplusplus
57 extern "C"
58 {
59 # endif
60
61 /* Get size_t. */
62 # include <stdlib.h>
63
64 /* Get uint32_t. */
65 # include <idn-int.h>
66
67 /* *INDENT-OFF* */
68
69 /* Why INDENT-OFF? See stringprep.h */
70
78 struct Tld_table_element
79 {
80 uint32_t start;
81 uint32_t end;
82 };
83 typedef struct Tld_table_element Tld_table_element;
84
94 struct Tld_table
95 {
96 const char *name;
97 const char *version;
98 size_t nvalid;
99 const Tld_table_element *valid;
100 };
101 typedef struct Tld_table Tld_table;
102 /* *INDENT-ON* */
103
104 /* Error codes. */
105 typedef enum
106 {
107 TLD_SUCCESS = 0,
108 TLD_INVALID = 1, /* Invalid character found. */
109 TLD_NODATA = 2, /* Char, domain or inlen = 0. */
110 TLD_MALLOC_ERROR = 3,
111 TLD_ICONV_ERROR = 4,
112 TLD_NO_TLD = 5,
113 /* Workaround typo in earlier versions. */
114 TLD_NOTLD = TLD_NO_TLD
115 } Tld_rc;
116
117 extern IDNAPI const char *tld_strerror (Tld_rc rc);
118
119 /* Extract TLD, as ASCII string, of UCS4 domain name into "out". */
120 extern IDNAPI int tld_get_4 (const uint32_t * in, size_t inlen, char **out);
121 extern IDNAPI int tld_get_4z (const uint32_t * in, char **out);
122 extern IDNAPI int tld_get_z (const char *in, char **out);
123
124 /* Return structure corresponding to the named TLD from specified
125 * list of TLD tables, or return NULL if no matching TLD can be
126 * found. */
127 extern IDNAPI const Tld_table *tld_get_table (const char *tld,
128 const Tld_table ** tables);
129
130 /* Return structure corresponding to the named TLD, first looking
131 * thru overrides then thru built-in list, or return NULL if no
132 * matching TLD can be found. */
133 extern IDNAPI const Tld_table *tld_default_table (const char *tld,
134 const Tld_table **
135 overrides);
136
137 /* Check NAMEPREPPED domain name for valid characters as defined by
138 * the relevant registering body (plus [a-z0-9.-]). If error is
139 * TLD_INVALID, set errpos to position of offending character. */
140 extern IDNAPI int tld_check_4t (const uint32_t * in, size_t inlen,
141 size_t *errpos, const Tld_table * tld);
142 extern IDNAPI int tld_check_4tz (const uint32_t * in, size_t *errpos,
143 const Tld_table * tld);
144
145 /* Utility interfaces that uses tld_get_4* to find TLD of string,
146 then tld_default_table (with overrides) to find proper TLD table
147 for the string, and then hands over to tld_check_4t*. */
148 extern IDNAPI int tld_check_4 (const uint32_t * in, size_t inlen,
149 size_t *errpos,
150 const Tld_table ** overrides);
151 extern IDNAPI int tld_check_4z (const uint32_t * in, size_t *errpos,
152 const Tld_table ** overrides);
153 extern IDNAPI int tld_check_8z (const char *in, size_t *errpos,
154 const Tld_table ** overrides);
155 extern IDNAPI int tld_check_lz (const char *in, size_t *errpos,
156 const Tld_table ** overrides);
157
158 # ifdef __cplusplus
159 }
160 # endif
161
162 #endif /* TLD_H */
Tld_table_element
Definition: tld.h:79
Tld_table_element::start
uint32_t start
Definition: tld.h:80
Tld_table_element::end
uint32_t end
Definition: tld.h:81
Tld_table
Definition: tld.h:95
Tld_table::valid
const Tld_table_element * valid
Definition: tld.h:99
Tld_table::name
const char * name
Definition: tld.h:96
Tld_table::nvalid
size_t nvalid
Definition: tld.h:98
Tld_table::version
const char * version
Definition: tld.h:97
Tld_rc
Tld_rc
Definition: tld.h:106
TLD_ICONV_ERROR
@ TLD_ICONV_ERROR
Definition: tld.h:111
TLD_MALLOC_ERROR
@ TLD_MALLOC_ERROR
Definition: tld.h:110
TLD_SUCCESS
@ TLD_SUCCESS
Definition: tld.h:107
TLD_NODATA
@ TLD_NODATA
Definition: tld.h:109
TLD_NOTLD
@ TLD_NOTLD
Definition: tld.h:114
TLD_NO_TLD
@ TLD_NO_TLD
Definition: tld.h:112
TLD_INVALID
@ TLD_INVALID
Definition: tld.h:108
tld_strerror
IDNAPI const char * tld_strerror(Tld_rc rc)
Definition: strerror-tld.c:59
tld_check_4t
IDNAPI int tld_check_4t(const uint32_t *in, size_t inlen, size_t *errpos, const Tld_table *tld)
Definition: tld.c:280
tld_check_4
IDNAPI int tld_check_4(const uint32_t *in, size_t inlen, size_t *errpos, const Tld_table **overrides)
Definition: tld.c:359
tld_check_4z
IDNAPI int tld_check_4z(const uint32_t *in, size_t *errpos, const Tld_table **overrides)
Definition: tld.c:409
IDNAPI
#define IDNAPI
Definition: tld.h:52
tld_check_4tz
IDNAPI int tld_check_4tz(const uint32_t *in, size_t *errpos, const Tld_table *tld)
Definition: tld.c:322
tld_check_8z
IDNAPI int tld_check_8z(const char *in, size_t *errpos, const Tld_table **overrides)
Definition: tld.c:447
tld_check_lz
IDNAPI int tld_check_lz(const char *in, size_t *errpos, const Tld_table **overrides)
Definition: tld.c:492
tld_get_z
IDNAPI int tld_get_z(const char *in, char **out)
Definition: tld.c:197
tld_get_table
IDNAPI const Tld_table * tld_get_table(const char *tld, const Tld_table **tables)
Definition: tld.c:60
tld_get_4
IDNAPI int tld_get_4(const uint32_t *in, size_t inlen, char **out)
Definition: tld.c:122
tld_default_table
IDNAPI const Tld_table * tld_default_table(const char *tld, const Tld_table **overrides)
Definition: tld.c:89
tld_get_4z
IDNAPI int tld_get_4z(const uint32_t *in, char **out)
Definition: tld.c:171