]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/bind9/lib/dns/rdata/generic/dname_39.c
MFC r363988:
[FreeBSD/stable/9.git] / contrib / bind9 / lib / dns / rdata / generic / dname_39.c
1 /*
2  * Copyright (C) 2004, 2007, 2009, 2015  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2001  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id: dname_39.c,v 1.40 2009/12/04 22:06:37 tbox Exp $ */
19
20 /* Reviewed: Wed Mar 15 16:52:38 PST 2000 by explorer */
21
22 /* RFC2672 */
23
24 #ifndef RDATA_GENERIC_DNAME_39_C
25 #define RDATA_GENERIC_DNAME_39_C
26
27 #define RRTYPE_DNAME_ATTRIBUTES (DNS_RDATATYPEATTR_SINGLETON)
28
29 static inline isc_result_t
30 fromtext_dname(ARGS_FROMTEXT) {
31         isc_token_t token;
32         dns_name_t name;
33         isc_buffer_t buffer;
34
35         REQUIRE(type == dns_rdatatype_dname);
36
37         UNUSED(type);
38         UNUSED(rdclass);
39         UNUSED(callbacks);
40
41         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
42                                       ISC_FALSE));
43
44         dns_name_init(&name, NULL);
45         buffer_fromregion(&buffer, &token.value.as_region);
46         if (origin == NULL)
47                 origin = dns_rootname;
48         RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
49         return (ISC_R_SUCCESS);
50 }
51
52 static inline isc_result_t
53 totext_dname(ARGS_TOTEXT) {
54         isc_region_t region;
55         dns_name_t name;
56         dns_name_t prefix;
57         isc_boolean_t sub;
58
59         REQUIRE(rdata->type == dns_rdatatype_dname);
60         REQUIRE(rdata->length != 0);
61
62         dns_name_init(&name, NULL);
63         dns_name_init(&prefix, NULL);
64
65         dns_rdata_toregion(rdata, &region);
66         dns_name_fromregion(&name, &region);
67
68         sub = name_prefix(&name, tctx->origin, &prefix);
69
70         return (dns_name_totext(&prefix, sub, target));
71 }
72
73 static inline isc_result_t
74 fromwire_dname(ARGS_FROMWIRE) {
75         dns_name_t name;
76
77         REQUIRE(type == dns_rdatatype_dname);
78
79         UNUSED(type);
80         UNUSED(rdclass);
81
82         dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
83
84         dns_name_init(&name, NULL);
85         return(dns_name_fromwire(&name, source, dctx, options, target));
86 }
87
88 static inline isc_result_t
89 towire_dname(ARGS_TOWIRE) {
90         dns_name_t name;
91         dns_offsets_t offsets;
92         isc_region_t region;
93
94         REQUIRE(rdata->type == dns_rdatatype_dname);
95         REQUIRE(rdata->length != 0);
96
97         dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
98         dns_name_init(&name, offsets);
99         dns_rdata_toregion(rdata, &region);
100         dns_name_fromregion(&name, &region);
101
102         return (dns_name_towire(&name, cctx, target));
103 }
104
105 static inline int
106 compare_dname(ARGS_COMPARE) {
107         dns_name_t name1;
108         dns_name_t name2;
109         isc_region_t region1;
110         isc_region_t region2;
111
112         REQUIRE(rdata1->type == rdata2->type);
113         REQUIRE(rdata1->rdclass == rdata2->rdclass);
114         REQUIRE(rdata1->type == dns_rdatatype_dname);
115         REQUIRE(rdata1->length != 0);
116         REQUIRE(rdata2->length != 0);
117
118         dns_name_init(&name1, NULL);
119         dns_name_init(&name2, NULL);
120
121         dns_rdata_toregion(rdata1, &region1);
122         dns_rdata_toregion(rdata2, &region2);
123
124         dns_name_fromregion(&name1, &region1);
125         dns_name_fromregion(&name2, &region2);
126
127         return (dns_name_rdatacompare(&name1, &name2));
128 }
129
130 static inline isc_result_t
131 fromstruct_dname(ARGS_FROMSTRUCT) {
132         dns_rdata_dname_t *dname = source;
133         isc_region_t region;
134
135         REQUIRE(type == dns_rdatatype_dname);
136         REQUIRE(source != NULL);
137         REQUIRE(dname->common.rdtype == type);
138         REQUIRE(dname->common.rdclass == rdclass);
139
140         UNUSED(type);
141         UNUSED(rdclass);
142
143         dns_name_toregion(&dname->dname, &region);
144         return (isc_buffer_copyregion(target, &region));
145 }
146
147 static inline isc_result_t
148 tostruct_dname(ARGS_TOSTRUCT) {
149         isc_region_t region;
150         dns_rdata_dname_t *dname = target;
151         dns_name_t name;
152
153         REQUIRE(rdata->type == dns_rdatatype_dname);
154         REQUIRE(target != NULL);
155         REQUIRE(rdata->length != 0);
156
157         dname->common.rdclass = rdata->rdclass;
158         dname->common.rdtype = rdata->type;
159         ISC_LINK_INIT(&dname->common, link);
160
161         dns_name_init(&name, NULL);
162         dns_rdata_toregion(rdata, &region);
163         dns_name_fromregion(&name, &region);
164         dns_name_init(&dname->dname, NULL);
165         RETERR(name_duporclone(&name, mctx, &dname->dname));
166         dname->mctx = mctx;
167         return (ISC_R_SUCCESS);
168 }
169
170 static inline void
171 freestruct_dname(ARGS_FREESTRUCT) {
172         dns_rdata_dname_t *dname = source;
173
174         REQUIRE(source != NULL);
175         REQUIRE(dname->common.rdtype == dns_rdatatype_dname);
176
177         if (dname->mctx == NULL)
178                 return;
179
180         dns_name_free(&dname->dname, dname->mctx);
181         dname->mctx = NULL;
182 }
183
184 static inline isc_result_t
185 additionaldata_dname(ARGS_ADDLDATA) {
186         UNUSED(rdata);
187         UNUSED(add);
188         UNUSED(arg);
189
190         REQUIRE(rdata->type == dns_rdatatype_dname);
191
192         return (ISC_R_SUCCESS);
193 }
194
195 static inline isc_result_t
196 digest_dname(ARGS_DIGEST) {
197         isc_region_t r;
198         dns_name_t name;
199
200         REQUIRE(rdata->type == dns_rdatatype_dname);
201
202         dns_rdata_toregion(rdata, &r);
203         dns_name_init(&name, NULL);
204         dns_name_fromregion(&name, &r);
205
206         return (dns_name_digest(&name, digest, arg));
207 }
208
209 static inline isc_boolean_t
210 checkowner_dname(ARGS_CHECKOWNER) {
211
212         REQUIRE(type == dns_rdatatype_dname);
213
214         UNUSED(name);
215         UNUSED(type);
216         UNUSED(rdclass);
217         UNUSED(wildcard);
218
219         return (ISC_TRUE);
220 }
221
222 static inline isc_boolean_t
223 checknames_dname(ARGS_CHECKNAMES) {
224
225         REQUIRE(rdata->type == dns_rdatatype_dname);
226
227         UNUSED(rdata);
228         UNUSED(owner);
229         UNUSED(bad);
230
231         return (ISC_TRUE);
232 }
233
234 static inline int
235 casecompare_dname(ARGS_COMPARE) {
236         return (compare_dname(rdata1, rdata2));
237 }
238 #endif  /* RDATA_GENERIC_DNAME_39_C */