Add BIND 9.2.4rc7.
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / dns / rdata / generic / cname_5.c
blob345b38ae776fafdca0d3977fc8fe4adb1c0d4d35
1 /*
2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1998-2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and 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.
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.
18 /* $Id: cname_5.c,v 1.43.2.1 2004/03/09 06:11:27 marka Exp $ */
20 /* reviewed: Wed Mar 15 16:48:45 PST 2000 by brister */
22 #ifndef RDATA_GENERIC_CNAME_5_C
23 #define RDATA_GENERIC_CNAME_5_C
25 #define RRTYPE_CNAME_ATTRIBUTES \
26 (DNS_RDATATYPEATTR_EXCLUSIVE | DNS_RDATATYPEATTR_SINGLETON)
28 static inline isc_result_t
29 fromtext_cname(ARGS_FROMTEXT) {
30 isc_token_t token;
31 dns_name_t name;
32 isc_buffer_t buffer;
34 REQUIRE(type == 5);
36 UNUSED(type);
37 UNUSED(rdclass);
38 UNUSED(callbacks);
40 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
41 ISC_FALSE));
43 dns_name_init(&name, NULL);
44 buffer_fromregion(&buffer, &token.value.as_region);
45 origin = (origin != NULL) ? origin : dns_rootname;
46 RETTOK(dns_name_fromtext(&name, &buffer, origin, downcase, target));
47 return (ISC_R_SUCCESS);
50 static inline isc_result_t
51 totext_cname(ARGS_TOTEXT) {
52 isc_region_t region;
53 dns_name_t name;
54 dns_name_t prefix;
55 isc_boolean_t sub;
57 REQUIRE(rdata->type == 5);
58 REQUIRE(rdata->length != 0);
60 dns_name_init(&name, NULL);
61 dns_name_init(&prefix, NULL);
63 dns_rdata_toregion(rdata, &region);
64 dns_name_fromregion(&name, &region);
66 sub = name_prefix(&name, tctx->origin, &prefix);
68 return (dns_name_totext(&prefix, sub, target));
71 static inline isc_result_t
72 fromwire_cname(ARGS_FROMWIRE) {
73 dns_name_t name;
75 REQUIRE(type == 5);
77 UNUSED(type);
78 UNUSED(rdclass);
80 dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
82 dns_name_init(&name, NULL);
83 return (dns_name_fromwire(&name, source, dctx, downcase, target));
86 static inline isc_result_t
87 towire_cname(ARGS_TOWIRE) {
88 dns_name_t name;
89 dns_offsets_t offsets;
90 isc_region_t region;
92 REQUIRE(rdata->type == 5);
93 REQUIRE(rdata->length != 0);
95 dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
97 dns_name_init(&name, offsets);
98 dns_rdata_toregion(rdata, &region);
99 dns_name_fromregion(&name, &region);
101 return (dns_name_towire(&name, cctx, target));
104 static inline int
105 compare_cname(ARGS_COMPARE) {
106 dns_name_t name1;
107 dns_name_t name2;
108 isc_region_t region1;
109 isc_region_t region2;
111 REQUIRE(rdata1->type == rdata2->type);
112 REQUIRE(rdata1->rdclass == rdata2->rdclass);
113 REQUIRE(rdata1->type == 5);
114 REQUIRE(rdata1->length != 0);
115 REQUIRE(rdata2->length != 0);
117 dns_name_init(&name1, NULL);
118 dns_name_init(&name2, NULL);
120 dns_rdata_toregion(rdata1, &region1);
121 dns_rdata_toregion(rdata2, &region2);
123 dns_name_fromregion(&name1, &region1);
124 dns_name_fromregion(&name2, &region2);
126 return (dns_name_rdatacompare(&name1, &name2));
129 static inline isc_result_t
130 fromstruct_cname(ARGS_FROMSTRUCT) {
131 dns_rdata_cname_t *cname = source;
132 isc_region_t region;
134 REQUIRE(type == 5);
135 REQUIRE(source != NULL);
136 REQUIRE(cname->common.rdtype == type);
137 REQUIRE(cname->common.rdclass == rdclass);
139 UNUSED(type);
140 UNUSED(rdclass);
142 dns_name_toregion(&cname->cname, &region);
143 return (isc_buffer_copyregion(target, &region));
146 static inline isc_result_t
147 tostruct_cname(ARGS_TOSTRUCT) {
148 isc_region_t region;
149 dns_rdata_cname_t *cname = target;
150 dns_name_t name;
152 REQUIRE(rdata->type == 5);
153 REQUIRE(target != NULL);
154 REQUIRE(rdata->length != 0);
156 cname->common.rdclass = rdata->rdclass;
157 cname->common.rdtype = rdata->type;
158 ISC_LINK_INIT(&cname->common, link);
160 dns_name_init(&name, NULL);
161 dns_rdata_toregion(rdata, &region);
162 dns_name_fromregion(&name, &region);
163 dns_name_init(&cname->cname, NULL);
164 RETERR(name_duporclone(&name, mctx, &cname->cname));
165 cname->mctx = mctx;
166 return (ISC_R_SUCCESS);
169 static inline void
170 freestruct_cname(ARGS_FREESTRUCT) {
171 dns_rdata_cname_t *cname = source;
173 REQUIRE(source != NULL);
175 if (cname->mctx == NULL)
176 return;
178 dns_name_free(&cname->cname, cname->mctx);
179 cname->mctx = NULL;
182 static inline isc_result_t
183 additionaldata_cname(ARGS_ADDLDATA) {
184 UNUSED(rdata);
185 UNUSED(add);
186 UNUSED(arg);
188 REQUIRE(rdata->type == 5);
190 return (ISC_R_SUCCESS);
193 static inline isc_result_t
194 digest_cname(ARGS_DIGEST) {
195 isc_region_t r;
196 dns_name_t name;
198 REQUIRE(rdata->type == 5);
200 dns_rdata_toregion(rdata, &r);
201 dns_name_init(&name, NULL);
202 dns_name_fromregion(&name, &r);
204 return (dns_name_digest(&name, digest, arg));
207 #endif /* RDATA_GENERIC_CNAME_5_C */