1 /* $NetBSD: rp_17.c,v 1.4 2014/12/10 04:37:59 christos Exp $ */
4 * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-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: rp_17.c,v 1.44 2009/12/04 22:06:37 tbox Exp */
24 #ifndef RDATA_GENERIC_RP_17_C
25 #define RDATA_GENERIC_RP_17_C
27 #define RRTYPE_RP_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_rp(ARGS_FROMTEXT
) {
43 origin
= (origin
!= NULL
) ? origin
: dns_rootname
;
45 for (i
= 0; i
< 2; i
++) {
46 RETERR(isc_lex_getmastertoken(lexer
, &token
,
49 dns_name_init(&name
, NULL
);
50 buffer_fromregion(&buffer
, &token
.value
.as_region
);
51 RETTOK(dns_name_fromtext(&name
, &buffer
, origin
,
54 if ((options
& DNS_RDATA_CHECKNAMES
) != 0 && i
== 0)
55 ok
= dns_name_ismailbox(&name
);
56 if (!ok
&& (options
& DNS_RDATA_CHECKNAMESFAIL
) != 0)
57 RETTOK(DNS_R_BADNAME
);
58 if (!ok
&& callbacks
!= NULL
)
59 warn_badname(&name
, lexer
, callbacks
);
61 return (ISC_R_SUCCESS
);
64 static inline isc_result_t
65 totext_rp(ARGS_TOTEXT
) {
72 REQUIRE(rdata
->type
== 17);
73 REQUIRE(rdata
->length
!= 0);
75 dns_name_init(&rmail
, NULL
);
76 dns_name_init(&email
, NULL
);
77 dns_name_init(&prefix
, NULL
);
79 dns_rdata_toregion(rdata
, ®ion
);
81 dns_name_fromregion(&rmail
, ®ion
);
82 isc_region_consume(®ion
, rmail
.length
);
84 dns_name_fromregion(&email
, ®ion
);
85 isc_region_consume(®ion
, email
.length
);
87 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_rp(ARGS_FROMWIRE
) {
106 dns_decompress_setmethods(dctx
, DNS_COMPRESS_NONE
);
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_rp(ARGS_TOWIRE
) {
120 dns_offsets_t roffsets
;
121 dns_offsets_t eoffsets
;
123 REQUIRE(rdata
->type
== 17);
124 REQUIRE(rdata
->length
!= 0);
126 dns_compress_setmethods(cctx
, DNS_COMPRESS_NONE
);
127 dns_name_init(&rmail
, roffsets
);
128 dns_name_init(&email
, eoffsets
);
130 dns_rdata_toregion(rdata
, ®ion
);
132 dns_name_fromregion(&rmail
, ®ion
);
133 isc_region_consume(®ion
, rmail
.length
);
135 RETERR(dns_name_towire(&rmail
, cctx
, target
));
137 dns_name_fromregion(&rmail
, ®ion
);
138 isc_region_consume(®ion
, rmail
.length
);
140 return (dns_name_towire(&rmail
, cctx
, target
));
144 compare_rp(ARGS_COMPARE
) {
145 isc_region_t region1
;
146 isc_region_t region2
;
151 REQUIRE(rdata1
->type
== rdata2
->type
);
152 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
153 REQUIRE(rdata1
->type
== 17);
154 REQUIRE(rdata1
->length
!= 0);
155 REQUIRE(rdata2
->length
!= 0);
157 dns_name_init(&name1
, NULL
);
158 dns_name_init(&name2
, NULL
);
160 dns_rdata_toregion(rdata1
, ®ion1
);
161 dns_rdata_toregion(rdata2
, ®ion2
);
163 dns_name_fromregion(&name1
, ®ion1
);
164 dns_name_fromregion(&name2
, ®ion2
);
166 order
= dns_name_rdatacompare(&name1
, &name2
);
170 isc_region_consume(®ion1
, name_length(&name1
));
171 isc_region_consume(®ion2
, name_length(&name2
));
173 dns_name_init(&name1
, NULL
);
174 dns_name_init(&name2
, NULL
);
176 dns_name_fromregion(&name1
, ®ion1
);
177 dns_name_fromregion(&name2
, ®ion2
);
179 return (dns_name_rdatacompare(&name1
, &name2
));
182 static inline isc_result_t
183 fromstruct_rp(ARGS_FROMSTRUCT
) {
184 dns_rdata_rp_t
*rp
= source
;
188 REQUIRE(source
!= NULL
);
189 REQUIRE(rp
->common
.rdtype
== type
);
190 REQUIRE(rp
->common
.rdclass
== rdclass
);
195 dns_name_toregion(&rp
->mail
, ®ion
);
196 RETERR(isc_buffer_copyregion(target
, ®ion
));
197 dns_name_toregion(&rp
->text
, ®ion
);
198 return (isc_buffer_copyregion(target
, ®ion
));
201 static inline isc_result_t
202 tostruct_rp(ARGS_TOSTRUCT
) {
205 dns_rdata_rp_t
*rp
= target
;
208 REQUIRE(rdata
->type
== 17);
209 REQUIRE(target
!= NULL
);
210 REQUIRE(rdata
->length
!= 0);
212 rp
->common
.rdclass
= rdata
->rdclass
;
213 rp
->common
.rdtype
= rdata
->type
;
214 ISC_LINK_INIT(&rp
->common
, link
);
216 dns_name_init(&name
, NULL
);
217 dns_rdata_toregion(rdata
, ®ion
);
218 dns_name_fromregion(&name
, ®ion
);
219 dns_name_init(&rp
->mail
, NULL
);
220 RETERR(name_duporclone(&name
, mctx
, &rp
->mail
));
221 isc_region_consume(®ion
, name_length(&name
));
222 dns_name_fromregion(&name
, ®ion
);
223 dns_name_init(&rp
->text
, NULL
);
224 result
= name_duporclone(&name
, mctx
, &rp
->text
);
225 if (result
!= ISC_R_SUCCESS
)
229 return (ISC_R_SUCCESS
);
233 dns_name_free(&rp
->mail
, mctx
);
234 return (ISC_R_NOMEMORY
);
238 freestruct_rp(ARGS_FREESTRUCT
) {
239 dns_rdata_rp_t
*rp
= source
;
241 REQUIRE(source
!= NULL
);
242 REQUIRE(rp
->common
.rdtype
== 17);
244 if (rp
->mctx
== NULL
)
247 dns_name_free(&rp
->mail
, rp
->mctx
);
248 dns_name_free(&rp
->text
, rp
->mctx
);
252 static inline isc_result_t
253 additionaldata_rp(ARGS_ADDLDATA
) {
254 REQUIRE(rdata
->type
== 17);
260 return (ISC_R_SUCCESS
);
263 static inline isc_result_t
264 digest_rp(ARGS_DIGEST
) {
268 REQUIRE(rdata
->type
== 17);
270 dns_rdata_toregion(rdata
, &r
);
271 dns_name_init(&name
, NULL
);
273 dns_name_fromregion(&name
, &r
);
274 RETERR(dns_name_digest(&name
, digest
, arg
));
275 isc_region_consume(&r
, name_length(&name
));
277 dns_name_init(&name
, NULL
);
278 dns_name_fromregion(&name
, &r
);
280 return (dns_name_digest(&name
, digest
, arg
));
283 static inline isc_boolean_t
284 checkowner_rp(ARGS_CHECKOWNER
) {
296 static inline isc_boolean_t
297 checknames_rp(ARGS_CHECKNAMES
) {
301 REQUIRE(rdata
->type
== 17);
305 dns_rdata_toregion(rdata
, ®ion
);
306 dns_name_init(&name
, NULL
);
307 dns_name_fromregion(&name
, ®ion
);
308 if (!dns_name_ismailbox(&name
)) {
310 dns_name_clone(&name
, bad
);
317 casecompare_rp(ARGS_COMPARE
) {
318 return (compare_rp(rdata1
, rdata2
));
320 #endif /* RDATA_GENERIC_RP_17_C */