1 /* $NetBSD: mg_8.c,v 1.4 2014/12/10 04:37:59 christos Exp $ */
2
3 /*
4 * Copyright (C) 2004, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1998-2001 Internet Software Consortium.
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 */
19
20 /* Id: mg_8.c,v 1.45 2009/12/04 22:06:37 tbox Exp */
21
22 /* reviewed: Wed Mar 15 17:49:21 PST 2000 by brister */
23
24 #ifndef RDATA_GENERIC_MG_8_C
25 #define RDATA_GENERIC_MG_8_C
26
27 #define RRTYPE_MG_ATTRIBUTES (0)
28
29 static inline isc_result_t
fromtext_mg(ARGS_FROMTEXT)30 fromtext_mg(ARGS_FROMTEXT) {
31 isc_token_t token;
32 dns_name_t name;
33 isc_buffer_t buffer;
34
35 REQUIRE(type == 8);
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 origin = (origin != NULL) ? origin : dns_rootname;
47 RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
48 return (ISC_R_SUCCESS);
49 }
50
51 static inline isc_result_t
totext_mg(ARGS_TOTEXT)52 totext_mg(ARGS_TOTEXT) {
53 isc_region_t region;
54 dns_name_t name;
55 dns_name_t prefix;
56 isc_boolean_t sub;
57
58 REQUIRE(rdata->type == 8);
59 REQUIRE(rdata->length != 0);
60
61 dns_name_init(&name, NULL);
62 dns_name_init(&prefix, NULL);
63
64 dns_rdata_toregion(rdata, ®ion);
65 dns_name_fromregion(&name, ®ion);
66
67 sub = name_prefix(&name, tctx->origin, &prefix);
68
69 return (dns_name_totext(&prefix, sub, target));
70 }
71
72 static inline isc_result_t
fromwire_mg(ARGS_FROMWIRE)73 fromwire_mg(ARGS_FROMWIRE) {
74 dns_name_t name;
75
76 REQUIRE(type == 8);
77
78 UNUSED(type);
79 UNUSED(rdclass);
80
81 dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
82
83 dns_name_init(&name, NULL);
84 return (dns_name_fromwire(&name, source, dctx, options, target));
85 }
86
87 static inline isc_result_t
towire_mg(ARGS_TOWIRE)88 towire_mg(ARGS_TOWIRE) {
89 dns_name_t name;
90 dns_offsets_t offsets;
91 isc_region_t region;
92
93 REQUIRE(rdata->type == 8);
94 REQUIRE(rdata->length != 0);
95
96 dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
97
98 dns_name_init(&name, offsets);
99 dns_rdata_toregion(rdata, ®ion);
100 dns_name_fromregion(&name, ®ion);
101
102 return (dns_name_towire(&name, cctx, target));
103 }
104
105 static inline int
compare_mg(ARGS_COMPARE)106 compare_mg(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 == 8);
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, ®ion1);
122 dns_rdata_toregion(rdata2, ®ion2);
123
124 dns_name_fromregion(&name1, ®ion1);
125 dns_name_fromregion(&name2, ®ion2);
126
127 return (dns_name_rdatacompare(&name1, &name2));
128 }
129
130 static inline isc_result_t
fromstruct_mg(ARGS_FROMSTRUCT)131 fromstruct_mg(ARGS_FROMSTRUCT) {
132 dns_rdata_mg_t *mg = source;
133 isc_region_t region;
134
135 REQUIRE(type == 8);
136 REQUIRE(source != NULL);
137 REQUIRE(mg->common.rdtype == type);
138 REQUIRE(mg->common.rdclass == rdclass);
139
140 UNUSED(type);
141 UNUSED(rdclass);
142
143 dns_name_toregion(&mg->mg, ®ion);
144 return (isc_buffer_copyregion(target, ®ion));
145 }
146
147 static inline isc_result_t
tostruct_mg(ARGS_TOSTRUCT)148 tostruct_mg(ARGS_TOSTRUCT) {
149 isc_region_t region;
150 dns_rdata_mg_t *mg = target;
151 dns_name_t name;
152
153 REQUIRE(rdata->type == 8);
154 REQUIRE(target != NULL);
155 REQUIRE(rdata->length != 0);
156
157 mg->common.rdclass = rdata->rdclass;
158 mg->common.rdtype = rdata->type;
159 ISC_LINK_INIT(&mg->common, link);
160
161 dns_name_init(&name, NULL);
162 dns_rdata_toregion(rdata, ®ion);
163 dns_name_fromregion(&name, ®ion);
164 dns_name_init(&mg->mg, NULL);
165 RETERR(name_duporclone(&name, mctx, &mg->mg));
166 mg->mctx = mctx;
167 return (ISC_R_SUCCESS);
168 }
169
170 static inline void
freestruct_mg(ARGS_FREESTRUCT)171 freestruct_mg(ARGS_FREESTRUCT) {
172 dns_rdata_mg_t *mg = source;
173
174 REQUIRE(source != NULL);
175 REQUIRE(mg->common.rdtype == 8);
176
177 if (mg->mctx == NULL)
178 return;
179 dns_name_free(&mg->mg, mg->mctx);
180 mg->mctx = NULL;
181 }
182
183 static inline isc_result_t
additionaldata_mg(ARGS_ADDLDATA)184 additionaldata_mg(ARGS_ADDLDATA) {
185 REQUIRE(rdata->type == 8);
186
187 UNUSED(add);
188 UNUSED(arg);
189 UNUSED(rdata);
190
191 return (ISC_R_SUCCESS);
192 }
193
194 static inline isc_result_t
digest_mg(ARGS_DIGEST)195 digest_mg(ARGS_DIGEST) {
196 isc_region_t r;
197 dns_name_t name;
198
199 REQUIRE(rdata->type == 8);
200
201 dns_rdata_toregion(rdata, &r);
202 dns_name_init(&name, NULL);
203 dns_name_fromregion(&name, &r);
204
205 return (dns_name_digest(&name, digest, arg));
206 }
207
208 static inline isc_boolean_t
checkowner_mg(ARGS_CHECKOWNER)209 checkowner_mg(ARGS_CHECKOWNER) {
210
211 REQUIRE(type == 8);
212
213 UNUSED(type);
214 UNUSED(rdclass);
215 UNUSED(wildcard);
216
217 return (dns_name_ismailbox(name));
218 }
219
220 static inline isc_boolean_t
checknames_mg(ARGS_CHECKNAMES)221 checknames_mg(ARGS_CHECKNAMES) {
222
223 REQUIRE(rdata->type == 8);
224
225 UNUSED(rdata);
226 UNUSED(owner);
227 UNUSED(bad);
228
229 return (ISC_TRUE);
230 }
231
232 static inline int
casecompare_mg(ARGS_COMPARE)233 casecompare_mg(ARGS_COMPARE) {
234 return (compare_mg(rdata1, rdata2));
235 }
236
237 #endif /* RDATA_GENERIC_MG_8_C */
238