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: minfo_14.c,v 1.45 2007/06/19 23:47:17 tbox Exp $ */
20 /* reviewed: Wed Mar 15 17:45:32 PST 2000 by brister */
22 #ifndef RDATA_GENERIC_MINFO_14_C
23 #define RDATA_GENERIC_MINFO_14_C
25 #define RRTYPE_MINFO_ATTRIBUTES (0)
27 static inline isc_result_t
28 fromtext_minfo(ARGS_FROMTEXT
) {
41 for (i
= 0; i
< 2; i
++) {
42 RETERR(isc_lex_getmastertoken(lexer
, &token
,
45 dns_name_init(&name
, NULL
);
46 buffer_fromregion(&buffer
, &token
.value
.as_region
);
47 origin
= (origin
!= NULL
) ? origin
: dns_rootname
;
48 RETTOK(dns_name_fromtext(&name
, &buffer
, origin
,
51 if ((options
& DNS_RDATA_CHECKNAMES
) != 0)
52 ok
= dns_name_ismailbox(&name
);
53 if (!ok
&& (options
& DNS_RDATA_CHECKNAMESFAIL
) != 0)
54 RETTOK(DNS_R_BADNAME
);
55 if (!ok
&& callbacks
!= NULL
)
56 warn_badname(&name
, lexer
, callbacks
);
58 return (ISC_R_SUCCESS
);
61 static inline isc_result_t
62 totext_minfo(ARGS_TOTEXT
) {
69 REQUIRE(rdata
->type
== 14);
70 REQUIRE(rdata
->length
!= 0);
72 dns_name_init(&rmail
, NULL
);
73 dns_name_init(&email
, NULL
);
74 dns_name_init(&prefix
, NULL
);
76 dns_rdata_toregion(rdata
, ®ion
);
78 dns_name_fromregion(&rmail
, ®ion
);
79 isc_region_consume(®ion
, rmail
.length
);
81 dns_name_fromregion(&email
, ®ion
);
82 isc_region_consume(®ion
, email
.length
);
84 sub
= name_prefix(&rmail
, tctx
->origin
, &prefix
);
86 RETERR(dns_name_totext(&prefix
, sub
, target
));
88 RETERR(str_totext(" ", target
));
90 sub
= name_prefix(&email
, tctx
->origin
, &prefix
);
91 return (dns_name_totext(&prefix
, sub
, target
));
94 static inline isc_result_t
95 fromwire_minfo(ARGS_FROMWIRE
) {
104 dns_decompress_setmethods(dctx
, DNS_COMPRESS_GLOBAL14
);
106 dns_name_init(&rmail
, NULL
);
107 dns_name_init(&email
, NULL
);
109 RETERR(dns_name_fromwire(&rmail
, source
, dctx
, options
, target
));
110 return (dns_name_fromwire(&email
, source
, dctx
, options
, target
));
113 static inline isc_result_t
114 towire_minfo(ARGS_TOWIRE
) {
118 dns_offsets_t roffsets
;
119 dns_offsets_t eoffsets
;
121 REQUIRE(rdata
->type
== 14);
122 REQUIRE(rdata
->length
!= 0);
124 dns_compress_setmethods(cctx
, DNS_COMPRESS_GLOBAL14
);
126 dns_name_init(&rmail
, roffsets
);
127 dns_name_init(&email
, eoffsets
);
129 dns_rdata_toregion(rdata
, ®ion
);
131 dns_name_fromregion(&rmail
, ®ion
);
132 isc_region_consume(®ion
, name_length(&rmail
));
134 RETERR(dns_name_towire(&rmail
, cctx
, target
));
136 dns_name_fromregion(&rmail
, ®ion
);
137 isc_region_consume(®ion
, rmail
.length
);
139 return (dns_name_towire(&rmail
, cctx
, target
));
143 compare_minfo(ARGS_COMPARE
) {
144 isc_region_t region1
;
145 isc_region_t region2
;
150 REQUIRE(rdata1
->type
== rdata2
->type
);
151 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
152 REQUIRE(rdata1
->type
== 14);
153 REQUIRE(rdata1
->length
!= 0);
154 REQUIRE(rdata2
->length
!= 0);
156 dns_name_init(&name1
, NULL
);
157 dns_name_init(&name2
, NULL
);
159 dns_rdata_toregion(rdata1
, ®ion1
);
160 dns_rdata_toregion(rdata2
, ®ion2
);
162 dns_name_fromregion(&name1
, ®ion1
);
163 dns_name_fromregion(&name2
, ®ion2
);
165 order
= dns_name_rdatacompare(&name1
, &name2
);
169 isc_region_consume(®ion1
, name_length(&name1
));
170 isc_region_consume(®ion2
, name_length(&name2
));
172 dns_name_init(&name1
, NULL
);
173 dns_name_init(&name2
, NULL
);
175 dns_name_fromregion(&name1
, ®ion1
);
176 dns_name_fromregion(&name2
, ®ion2
);
178 order
= dns_name_rdatacompare(&name1
, &name2
);
182 static inline isc_result_t
183 fromstruct_minfo(ARGS_FROMSTRUCT
) {
184 dns_rdata_minfo_t
*minfo
= source
;
188 REQUIRE(source
!= NULL
);
189 REQUIRE(minfo
->common
.rdtype
== type
);
190 REQUIRE(minfo
->common
.rdclass
== rdclass
);
195 dns_name_toregion(&minfo
->rmailbox
, ®ion
);
196 RETERR(isc_buffer_copyregion(target
, ®ion
));
197 dns_name_toregion(&minfo
->emailbox
, ®ion
);
198 return (isc_buffer_copyregion(target
, ®ion
));
201 static inline isc_result_t
202 tostruct_minfo(ARGS_TOSTRUCT
) {
203 dns_rdata_minfo_t
*minfo
= target
;
208 REQUIRE(rdata
->type
== 14);
209 REQUIRE(target
!= NULL
);
210 REQUIRE(rdata
->length
!= 0);
212 minfo
->common
.rdclass
= rdata
->rdclass
;
213 minfo
->common
.rdtype
= rdata
->type
;
214 ISC_LINK_INIT(&minfo
->common
, link
);
216 dns_name_init(&name
, NULL
);
217 dns_rdata_toregion(rdata
, ®ion
);
218 dns_name_fromregion(&name
, ®ion
);
219 dns_name_init(&minfo
->rmailbox
, NULL
);
220 RETERR(name_duporclone(&name
, mctx
, &minfo
->rmailbox
));
221 isc_region_consume(®ion
, name_length(&name
));
223 dns_name_fromregion(&name
, ®ion
);
224 dns_name_init(&minfo
->emailbox
, NULL
);
225 result
= name_duporclone(&name
, mctx
, &minfo
->emailbox
);
226 if (result
!= ISC_R_SUCCESS
)
229 return (ISC_R_SUCCESS
);
233 dns_name_free(&minfo
->rmailbox
, mctx
);
234 return (ISC_R_NOMEMORY
);
238 freestruct_minfo(ARGS_FREESTRUCT
) {
239 dns_rdata_minfo_t
*minfo
= source
;
241 REQUIRE(source
!= NULL
);
242 REQUIRE(minfo
->common
.rdtype
== 14);
244 if (minfo
->mctx
== NULL
)
247 dns_name_free(&minfo
->rmailbox
, minfo
->mctx
);
248 dns_name_free(&minfo
->emailbox
, minfo
->mctx
);
252 static inline isc_result_t
253 additionaldata_minfo(ARGS_ADDLDATA
) {
254 REQUIRE(rdata
->type
== 14);
260 return (ISC_R_SUCCESS
);
263 static inline isc_result_t
264 digest_minfo(ARGS_DIGEST
) {
269 REQUIRE(rdata
->type
== 14);
271 dns_rdata_toregion(rdata
, &r
);
272 dns_name_init(&name
, NULL
);
273 dns_name_fromregion(&name
, &r
);
274 result
= dns_name_digest(&name
, digest
, arg
);
275 if (result
!= ISC_R_SUCCESS
)
277 isc_region_consume(&r
, name_length(&name
));
278 dns_name_init(&name
, NULL
);
279 dns_name_fromregion(&name
, &r
);
281 return (dns_name_digest(&name
, digest
, arg
));
284 static inline isc_boolean_t
285 checkowner_minfo(ARGS_CHECKOWNER
) {
297 static inline isc_boolean_t
298 checknames_minfo(ARGS_CHECKNAMES
) {
302 REQUIRE(rdata
->type
== 14);
306 dns_rdata_toregion(rdata
, ®ion
);
307 dns_name_init(&name
, NULL
);
308 dns_name_fromregion(&name
, ®ion
);
309 if (!dns_name_ismailbox(&name
)) {
311 dns_name_clone(&name
, bad
);
314 isc_region_consume(®ion
, name_length(&name
));
315 dns_name_fromregion(&name
, ®ion
);
316 if (!dns_name_ismailbox(&name
)) {
318 dns_name_clone(&name
, bad
);
324 #endif /* RDATA_GENERIC_MINFO_14_C */