Import bind 9.5.2 vendor sources.
[dragonfly.git] / contrib / bind-9.5.2 / lib / dns / rdata / generic / mr_9.c
blob289d7395c0249d98dda3ccef73aae481875c2f81
1 /*
2 * Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1998-2001 Internet Software Consortium.
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.
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: mr_9.c,v 1.42 2007/06/19 23:47:17 tbox Exp $ */
20 /* Reviewed: Wed Mar 15 21:30:35 EST 2000 by tale */
22 #ifndef RDATA_GENERIC_MR_9_C
23 #define RDATA_GENERIC_MR_9_C
25 #define RRTYPE_MR_ATTRIBUTES (0)
27 static inline isc_result_t
28 fromtext_mr(ARGS_FROMTEXT) {
29 isc_token_t token;
30 dns_name_t name;
31 isc_buffer_t buffer;
33 REQUIRE(type == 9);
35 UNUSED(type);
36 UNUSED(rdclass);
37 UNUSED(callbacks);
39 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
40 ISC_FALSE));
42 dns_name_init(&name, NULL);
43 buffer_fromregion(&buffer, &token.value.as_region);
44 origin = (origin != NULL) ? origin : dns_rootname;
45 RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
46 return (ISC_R_SUCCESS);
49 static inline isc_result_t
50 totext_mr(ARGS_TOTEXT) {
51 isc_region_t region;
52 dns_name_t name;
53 dns_name_t prefix;
54 isc_boolean_t sub;
56 REQUIRE(rdata->type == 9);
57 REQUIRE(rdata->length != 0);
59 dns_name_init(&name, NULL);
60 dns_name_init(&prefix, NULL);
62 dns_rdata_toregion(rdata, &region);
63 dns_name_fromregion(&name, &region);
65 sub = name_prefix(&name, tctx->origin, &prefix);
67 return (dns_name_totext(&prefix, sub, target));
70 static inline isc_result_t
71 fromwire_mr(ARGS_FROMWIRE) {
72 dns_name_t name;
74 REQUIRE(type == 9);
76 UNUSED(type);
77 UNUSED(rdclass);
79 dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
81 dns_name_init(&name, NULL);
82 return (dns_name_fromwire(&name, source, dctx, options, target));
85 static inline isc_result_t
86 towire_mr(ARGS_TOWIRE) {
87 dns_name_t name;
88 dns_offsets_t offsets;
89 isc_region_t region;
91 REQUIRE(rdata->type == 9);
92 REQUIRE(rdata->length != 0);
94 dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
96 dns_name_init(&name, offsets);
97 dns_rdata_toregion(rdata, &region);
98 dns_name_fromregion(&name, &region);
100 return (dns_name_towire(&name, cctx, target));
103 static inline int
104 compare_mr(ARGS_COMPARE) {
105 dns_name_t name1;
106 dns_name_t name2;
107 isc_region_t region1;
108 isc_region_t region2;
110 REQUIRE(rdata1->type == rdata2->type);
111 REQUIRE(rdata1->rdclass == rdata2->rdclass);
112 REQUIRE(rdata1->type == 9);
113 REQUIRE(rdata1->length != 0);
114 REQUIRE(rdata2->length != 0);
116 dns_name_init(&name1, NULL);
117 dns_name_init(&name2, NULL);
119 dns_rdata_toregion(rdata1, &region1);
120 dns_rdata_toregion(rdata2, &region2);
122 dns_name_fromregion(&name1, &region1);
123 dns_name_fromregion(&name2, &region2);
125 return (dns_name_rdatacompare(&name1, &name2));
128 static inline isc_result_t
129 fromstruct_mr(ARGS_FROMSTRUCT) {
130 dns_rdata_mr_t *mr = source;
131 isc_region_t region;
133 REQUIRE(type == 9);
134 REQUIRE(source != NULL);
135 REQUIRE(mr->common.rdtype == type);
136 REQUIRE(mr->common.rdclass == rdclass);
138 UNUSED(type);
139 UNUSED(rdclass);
141 dns_name_toregion(&mr->mr, &region);
142 return (isc_buffer_copyregion(target, &region));
145 static inline isc_result_t
146 tostruct_mr(ARGS_TOSTRUCT) {
147 isc_region_t region;
148 dns_rdata_mr_t *mr = target;
149 dns_name_t name;
151 REQUIRE(rdata->type == 9);
152 REQUIRE(target != NULL);
153 REQUIRE(rdata->length != 0);
155 mr->common.rdclass = rdata->rdclass;
156 mr->common.rdtype = rdata->type;
157 ISC_LINK_INIT(&mr->common, link);
159 dns_name_init(&name, NULL);
160 dns_rdata_toregion(rdata, &region);
161 dns_name_fromregion(&name, &region);
162 dns_name_init(&mr->mr, NULL);
163 RETERR(name_duporclone(&name, mctx, &mr->mr));
164 mr->mctx = mctx;
165 return (ISC_R_SUCCESS);
168 static inline void
169 freestruct_mr(ARGS_FREESTRUCT) {
170 dns_rdata_mr_t *mr = source;
172 REQUIRE(source != NULL);
173 REQUIRE(mr->common.rdtype == 9);
175 if (mr->mctx == NULL)
176 return;
177 dns_name_free(&mr->mr, mr->mctx);
178 mr->mctx = NULL;
181 static inline isc_result_t
182 additionaldata_mr(ARGS_ADDLDATA) {
183 REQUIRE(rdata->type == 9);
185 UNUSED(rdata);
186 UNUSED(add);
187 UNUSED(arg);
189 return (ISC_R_SUCCESS);
192 static inline isc_result_t
193 digest_mr(ARGS_DIGEST) {
194 isc_region_t r;
195 dns_name_t name;
197 REQUIRE(rdata->type == 9);
199 dns_rdata_toregion(rdata, &r);
200 dns_name_init(&name, NULL);
201 dns_name_fromregion(&name, &r);
203 return (dns_name_digest(&name, digest, arg));
206 static inline isc_boolean_t
207 checkowner_mr(ARGS_CHECKOWNER) {
209 REQUIRE(type == 9);
211 UNUSED(name);
212 UNUSED(type);
213 UNUSED(rdclass);
214 UNUSED(wildcard);
216 return (ISC_TRUE);
219 static inline isc_boolean_t
220 checknames_mr(ARGS_CHECKNAMES) {
222 REQUIRE(rdata->type == 9);
224 UNUSED(rdata);
225 UNUSED(owner);
226 UNUSED(bad);
228 return (ISC_TRUE);
231 #endif /* RDATA_GENERIC_MR_9_C */