mb_7.c revision 1.1 1 /* $NetBSD: mb_7.c,v 1.1 2018/08/12 12:08:17 christos Exp $ */
2
3 /*
4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 *
10 * See the COPYRIGHT file distributed with this work for additional
11 * information regarding copyright ownership.
12 */
13
14 #ifndef RDATA_GENERIC_MB_7_C
15 #define RDATA_GENERIC_MB_7_C
16
17 #define RRTYPE_MB_ATTRIBUTES (0)
18
19 static inline isc_result_t
20 fromtext_mb(ARGS_FROMTEXT) {
21 isc_token_t token;
22 dns_name_t name;
23 isc_buffer_t buffer;
24
25 REQUIRE(type == dns_rdatatype_mb);
26
27 UNUSED(type);
28 UNUSED(rdclass);
29 UNUSED(callbacks);
30
31 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
32 ISC_FALSE));
33
34 dns_name_init(&name, NULL);
35 buffer_fromregion(&buffer, &token.value.as_region);
36 if (origin == NULL)
37 origin = dns_rootname;
38 RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
39 return (ISC_R_SUCCESS);
40 }
41
42 static inline isc_result_t
43 totext_mb(ARGS_TOTEXT) {
44 isc_region_t region;
45 dns_name_t name;
46 dns_name_t prefix;
47 isc_boolean_t sub;
48
49 REQUIRE(rdata->type == dns_rdatatype_mb);
50 REQUIRE(rdata->length != 0);
51
52 dns_name_init(&name, NULL);
53 dns_name_init(&prefix, NULL);
54
55 dns_rdata_toregion(rdata, ®ion);
56 dns_name_fromregion(&name, ®ion);
57
58 sub = name_prefix(&name, tctx->origin, &prefix);
59
60 return (dns_name_totext(&prefix, sub, target));
61 }
62
63 static inline isc_result_t
64 fromwire_mb(ARGS_FROMWIRE) {
65 dns_name_t name;
66
67 REQUIRE(type == dns_rdatatype_mb);
68
69 UNUSED(type);
70 UNUSED(rdclass);
71
72 dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
73
74 dns_name_init(&name, NULL);
75 return (dns_name_fromwire(&name, source, dctx, options, target));
76 }
77
78 static inline isc_result_t
79 towire_mb(ARGS_TOWIRE) {
80 dns_name_t name;
81 dns_offsets_t offsets;
82 isc_region_t region;
83
84 REQUIRE(rdata->type == dns_rdatatype_mb);
85 REQUIRE(rdata->length != 0);
86
87 dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
88
89 dns_name_init(&name, offsets);
90 dns_rdata_toregion(rdata, ®ion);
91 dns_name_fromregion(&name, ®ion);
92
93 return (dns_name_towire(&name, cctx, target));
94 }
95
96 static inline int
97 compare_mb(ARGS_COMPARE) {
98 dns_name_t name1;
99 dns_name_t name2;
100 isc_region_t region1;
101 isc_region_t region2;
102
103 REQUIRE(rdata1->type == rdata2->type);
104 REQUIRE(rdata1->rdclass == rdata2->rdclass);
105 REQUIRE(rdata1->type == dns_rdatatype_mb);
106 REQUIRE(rdata1->length != 0);
107 REQUIRE(rdata2->length != 0);
108
109 dns_name_init(&name1, NULL);
110 dns_name_init(&name2, NULL);
111
112 dns_rdata_toregion(rdata1, ®ion1);
113 dns_rdata_toregion(rdata2, ®ion2);
114
115 dns_name_fromregion(&name1, ®ion1);
116 dns_name_fromregion(&name2, ®ion2);
117
118 return (dns_name_rdatacompare(&name1, &name2));
119 }
120
121 static inline isc_result_t
122 fromstruct_mb(ARGS_FROMSTRUCT) {
123 dns_rdata_mb_t *mb = source;
124 isc_region_t region;
125
126 REQUIRE(type == dns_rdatatype_mb);
127 REQUIRE(source != NULL);
128 REQUIRE(mb->common.rdtype == type);
129 REQUIRE(mb->common.rdclass == rdclass);
130
131 UNUSED(type);
132 UNUSED(rdclass);
133
134 dns_name_toregion(&mb->mb, ®ion);
135 return (isc_buffer_copyregion(target, ®ion));
136 }
137
138 static inline isc_result_t
139 tostruct_mb(ARGS_TOSTRUCT) {
140 isc_region_t region;
141 dns_rdata_mb_t *mb = target;
142 dns_name_t name;
143
144 REQUIRE(rdata->type == dns_rdatatype_mb);
145 REQUIRE(target != NULL);
146 REQUIRE(rdata->length != 0);
147
148 mb->common.rdclass = rdata->rdclass;
149 mb->common.rdtype = rdata->type;
150 ISC_LINK_INIT(&mb->common, link);
151
152 dns_name_init(&name, NULL);
153 dns_rdata_toregion(rdata, ®ion);
154 dns_name_fromregion(&name, ®ion);
155 dns_name_init(&mb->mb, NULL);
156 RETERR(name_duporclone(&name, mctx, &mb->mb));
157 mb->mctx = mctx;
158 return (ISC_R_SUCCESS);
159 }
160
161 static inline void
162 freestruct_mb(ARGS_FREESTRUCT) {
163 dns_rdata_mb_t *mb = source;
164
165 REQUIRE(source != NULL);
166
167 if (mb->mctx == NULL)
168 return;
169
170 dns_name_free(&mb->mb, mb->mctx);
171 mb->mctx = NULL;
172 }
173
174 static inline isc_result_t
175 additionaldata_mb(ARGS_ADDLDATA) {
176 dns_name_t name;
177 dns_offsets_t offsets;
178 isc_region_t region;
179
180 REQUIRE(rdata->type == dns_rdatatype_mb);
181
182 dns_name_init(&name, offsets);
183 dns_rdata_toregion(rdata, ®ion);
184 dns_name_fromregion(&name, ®ion);
185
186 return ((add)(arg, &name, dns_rdatatype_a));
187 }
188
189 static inline isc_result_t
190 digest_mb(ARGS_DIGEST) {
191 isc_region_t r;
192 dns_name_t name;
193
194 REQUIRE(rdata->type == dns_rdatatype_mb);
195
196 dns_rdata_toregion(rdata, &r);
197 dns_name_init(&name, NULL);
198 dns_name_fromregion(&name, &r);
199
200 return (dns_name_digest(&name, digest, arg));
201 }
202
203 static inline isc_boolean_t
204 checkowner_mb(ARGS_CHECKOWNER) {
205
206 REQUIRE(type == dns_rdatatype_mb);
207
208 UNUSED(type);
209 UNUSED(rdclass);
210 UNUSED(wildcard);
211
212 return (dns_name_ismailbox(name));
213 }
214
215 static inline isc_boolean_t
216 checknames_mb(ARGS_CHECKNAMES) {
217
218 REQUIRE(rdata->type == dns_rdatatype_mb);
219
220 UNUSED(rdata);
221 UNUSED(owner);
222 UNUSED(bad);
223
224 return (ISC_TRUE);
225 }
226
227 static inline int
228 casecompare_mb(ARGS_COMPARE) {
229 return (compare_mb(rdata1, rdata2));
230 }
231
232 #endif /* RDATA_GENERIC_MB_7_C */
233