1 /* $NetBSD: minfo_14.c,v 1.4 2014/12/10 04:37:59 christos Exp $ */
4 * Copyright (C) 2004, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1998-2001 Internet Software Consortium.
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.
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.
20 /* Id: minfo_14.c,v 1.47 2009/12/04 22:06:37 tbox Exp */
22 /* reviewed: Wed Mar 15 17:45:32 PST 2000 by brister */
24 #ifndef RDATA_GENERIC_MINFO_14_C
25 #define RDATA_GENERIC_MINFO_14_C
27 #define RRTYPE_MINFO_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_minfo(ARGS_FROMTEXT
) {
43 for (i
= 0; i
< 2; i
++) {
44 RETERR(isc_lex_getmastertoken(lexer
, &token
,
47 dns_name_init(&name
, NULL
);
48 buffer_fromregion(&buffer
, &token
.value
.as_region
);
49 origin
= (origin
!= NULL
) ? origin
: dns_rootname
;
50 RETTOK(dns_name_fromtext(&name
, &buffer
, origin
,
53 if ((options
& DNS_RDATA_CHECKNAMES
) != 0)
54 ok
= dns_name_ismailbox(&name
);
55 if (!ok
&& (options
& DNS_RDATA_CHECKNAMESFAIL
) != 0)
56 RETTOK(DNS_R_BADNAME
);
57 if (!ok
&& callbacks
!= NULL
)
58 warn_badname(&name
, lexer
, callbacks
);
60 return (ISC_R_SUCCESS
);
63 static inline isc_result_t
64 totext_minfo(ARGS_TOTEXT
) {
71 REQUIRE(rdata
->type
== 14);
72 REQUIRE(rdata
->length
!= 0);
74 dns_name_init(&rmail
, NULL
);
75 dns_name_init(&email
, NULL
);
76 dns_name_init(&prefix
, NULL
);
78 dns_rdata_toregion(rdata
, ®ion
);
80 dns_name_fromregion(&rmail
, ®ion
);
81 isc_region_consume(®ion
, rmail
.length
);
83 dns_name_fromregion(&email
, ®ion
);
84 isc_region_consume(®ion
, email
.length
);
86 sub
= name_prefix(&rmail
, tctx
->origin
, &prefix
);
88 RETERR(dns_name_totext(&prefix
, sub
, target
));
90 RETERR(str_totext(" ", target
));
92 sub
= name_prefix(&email
, tctx
->origin
, &prefix
);
93 return (dns_name_totext(&prefix
, sub
, target
));
96 static inline isc_result_t
97 fromwire_minfo(ARGS_FROMWIRE
) {
106 dns_decompress_setmethods(dctx
, DNS_COMPRESS_GLOBAL14
);
108 dns_name_init(&rmail
, NULL
);
109 dns_name_init(&email
, NULL
);
111 RETERR(dns_name_fromwire(&rmail
, source
, dctx
, options
, target
));
112 return (dns_name_fromwire(&email
, source
, dctx
, options
, target
));
115 static inline isc_result_t
116 towire_minfo(ARGS_TOWIRE
) {
120 dns_offsets_t roffsets
;
121 dns_offsets_t eoffsets
;
123 REQUIRE(rdata
->type
== 14);
124 REQUIRE(rdata
->length
!= 0);
126 dns_compress_setmethods(cctx
, DNS_COMPRESS_GLOBAL14
);
128 dns_name_init(&rmail
, roffsets
);
129 dns_name_init(&email
, eoffsets
);
131 dns_rdata_toregion(rdata
, ®ion
);
133 dns_name_fromregion(&rmail
, ®ion
);
134 isc_region_consume(®ion
, name_length(&rmail
));
136 RETERR(dns_name_towire(&rmail
, cctx
, target
));
138 dns_name_fromregion(&rmail
, ®ion
);
139 isc_region_consume(®ion
, rmail
.length
);
141 return (dns_name_towire(&rmail
, cctx
, target
));
145 compare_minfo(ARGS_COMPARE
) {
146 isc_region_t region1
;
147 isc_region_t region2
;
152 REQUIRE(rdata1
->type
== rdata2
->type
);
153 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
154 REQUIRE(rdata1
->type
== 14);
155 REQUIRE(rdata1
->length
!= 0);
156 REQUIRE(rdata2
->length
!= 0);
158 dns_name_init(&name1
, NULL
);
159 dns_name_init(&name2
, NULL
);
161 dns_rdata_toregion(rdata1
, ®ion1
);
162 dns_rdata_toregion(rdata2
, ®ion2
);
164 dns_name_fromregion(&name1
, ®ion1
);
165 dns_name_fromregion(&name2
, ®ion2
);
167 order
= dns_name_rdatacompare(&name1
, &name2
);
171 isc_region_consume(®ion1
, name_length(&name1
));
172 isc_region_consume(®ion2
, name_length(&name2
));
174 dns_name_init(&name1
, NULL
);
175 dns_name_init(&name2
, NULL
);
177 dns_name_fromregion(&name1
, ®ion1
);
178 dns_name_fromregion(&name2
, ®ion2
);
180 order
= dns_name_rdatacompare(&name1
, &name2
);
184 static inline isc_result_t
185 fromstruct_minfo(ARGS_FROMSTRUCT
) {
186 dns_rdata_minfo_t
*minfo
= source
;
190 REQUIRE(source
!= NULL
);
191 REQUIRE(minfo
->common
.rdtype
== type
);
192 REQUIRE(minfo
->common
.rdclass
== rdclass
);
197 dns_name_toregion(&minfo
->rmailbox
, ®ion
);
198 RETERR(isc_buffer_copyregion(target
, ®ion
));
199 dns_name_toregion(&minfo
->emailbox
, ®ion
);
200 return (isc_buffer_copyregion(target
, ®ion
));
203 static inline isc_result_t
204 tostruct_minfo(ARGS_TOSTRUCT
) {
205 dns_rdata_minfo_t
*minfo
= target
;
210 REQUIRE(rdata
->type
== 14);
211 REQUIRE(target
!= NULL
);
212 REQUIRE(rdata
->length
!= 0);
214 minfo
->common
.rdclass
= rdata
->rdclass
;
215 minfo
->common
.rdtype
= rdata
->type
;
216 ISC_LINK_INIT(&minfo
->common
, link
);
218 dns_name_init(&name
, NULL
);
219 dns_rdata_toregion(rdata
, ®ion
);
220 dns_name_fromregion(&name
, ®ion
);
221 dns_name_init(&minfo
->rmailbox
, NULL
);
222 RETERR(name_duporclone(&name
, mctx
, &minfo
->rmailbox
));
223 isc_region_consume(®ion
, name_length(&name
));
225 dns_name_fromregion(&name
, ®ion
);
226 dns_name_init(&minfo
->emailbox
, NULL
);
227 result
= name_duporclone(&name
, mctx
, &minfo
->emailbox
);
228 if (result
!= ISC_R_SUCCESS
)
231 return (ISC_R_SUCCESS
);
235 dns_name_free(&minfo
->rmailbox
, mctx
);
236 return (ISC_R_NOMEMORY
);
240 freestruct_minfo(ARGS_FREESTRUCT
) {
241 dns_rdata_minfo_t
*minfo
= source
;
243 REQUIRE(source
!= NULL
);
244 REQUIRE(minfo
->common
.rdtype
== 14);
246 if (minfo
->mctx
== NULL
)
249 dns_name_free(&minfo
->rmailbox
, minfo
->mctx
);
250 dns_name_free(&minfo
->emailbox
, minfo
->mctx
);
254 static inline isc_result_t
255 additionaldata_minfo(ARGS_ADDLDATA
) {
256 REQUIRE(rdata
->type
== 14);
262 return (ISC_R_SUCCESS
);
265 static inline isc_result_t
266 digest_minfo(ARGS_DIGEST
) {
271 REQUIRE(rdata
->type
== 14);
273 dns_rdata_toregion(rdata
, &r
);
274 dns_name_init(&name
, NULL
);
275 dns_name_fromregion(&name
, &r
);
276 result
= dns_name_digest(&name
, digest
, arg
);
277 if (result
!= ISC_R_SUCCESS
)
279 isc_region_consume(&r
, name_length(&name
));
280 dns_name_init(&name
, NULL
);
281 dns_name_fromregion(&name
, &r
);
283 return (dns_name_digest(&name
, digest
, arg
));
286 static inline isc_boolean_t
287 checkowner_minfo(ARGS_CHECKOWNER
) {
299 static inline isc_boolean_t
300 checknames_minfo(ARGS_CHECKNAMES
) {
304 REQUIRE(rdata
->type
== 14);
308 dns_rdata_toregion(rdata
, ®ion
);
309 dns_name_init(&name
, NULL
);
310 dns_name_fromregion(&name
, ®ion
);
311 if (!dns_name_ismailbox(&name
)) {
313 dns_name_clone(&name
, bad
);
316 isc_region_consume(®ion
, name_length(&name
));
317 dns_name_fromregion(&name
, ®ion
);
318 if (!dns_name_ismailbox(&name
)) {
320 dns_name_clone(&name
, bad
);
327 casecompare_minfo(ARGS_COMPARE
) {
328 return (compare_minfo(rdata1
, rdata2
));
331 #endif /* RDATA_GENERIC_MINFO_14_C */