1 /* $NetBSD: md_3.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: md_3.c,v 1.49 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Wed Mar 15 17:48:20 PST 2000 by bwelling */
24 #ifndef RDATA_GENERIC_MD_3_C
25 #define RDATA_GENERIC_MD_3_C
27 #define RRTYPE_MD_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_md(ARGS_FROMTEXT
) {
41 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
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
);
51 static inline isc_result_t
52 totext_md(ARGS_TOTEXT
) {
58 REQUIRE(rdata
->type
== 3);
59 REQUIRE(rdata
->length
!= 0);
61 dns_name_init(&name
, NULL
);
62 dns_name_init(&prefix
, NULL
);
64 dns_rdata_toregion(rdata
, ®ion
);
65 dns_name_fromregion(&name
, ®ion
);
67 sub
= name_prefix(&name
, tctx
->origin
, &prefix
);
69 return (dns_name_totext(&prefix
, sub
, target
));
72 static inline isc_result_t
73 fromwire_md(ARGS_FROMWIRE
) {
81 dns_decompress_setmethods(dctx
, DNS_COMPRESS_GLOBAL14
);
83 dns_name_init(&name
, NULL
);
84 return (dns_name_fromwire(&name
, source
, dctx
, options
, target
));
87 static inline isc_result_t
88 towire_md(ARGS_TOWIRE
) {
90 dns_offsets_t offsets
;
93 REQUIRE(rdata
->type
== 3);
94 REQUIRE(rdata
->length
!= 0);
96 dns_compress_setmethods(cctx
, DNS_COMPRESS_GLOBAL14
);
98 dns_name_init(&name
, offsets
);
99 dns_rdata_toregion(rdata
, ®ion
);
100 dns_name_fromregion(&name
, ®ion
);
102 return (dns_name_towire(&name
, cctx
, target
));
106 compare_md(ARGS_COMPARE
) {
109 isc_region_t region1
;
110 isc_region_t region2
;
112 REQUIRE(rdata1
->type
== rdata2
->type
);
113 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
114 REQUIRE(rdata1
->type
== 3);
115 REQUIRE(rdata1
->length
!= 0);
116 REQUIRE(rdata2
->length
!= 0);
118 dns_name_init(&name1
, NULL
);
119 dns_name_init(&name2
, NULL
);
121 dns_rdata_toregion(rdata1
, ®ion1
);
122 dns_rdata_toregion(rdata2
, ®ion2
);
124 dns_name_fromregion(&name1
, ®ion1
);
125 dns_name_fromregion(&name2
, ®ion2
);
127 return (dns_name_rdatacompare(&name1
, &name2
));
130 static inline isc_result_t
131 fromstruct_md(ARGS_FROMSTRUCT
) {
132 dns_rdata_md_t
*md
= source
;
136 REQUIRE(source
!= NULL
);
137 REQUIRE(md
->common
.rdtype
== type
);
138 REQUIRE(md
->common
.rdclass
== rdclass
);
143 dns_name_toregion(&md
->md
, ®ion
);
144 return (isc_buffer_copyregion(target
, ®ion
));
147 static inline isc_result_t
148 tostruct_md(ARGS_TOSTRUCT
) {
149 dns_rdata_md_t
*md
= target
;
153 REQUIRE(rdata
->type
== 3);
154 REQUIRE(target
!= NULL
);
155 REQUIRE(rdata
->length
!= 0);
157 md
->common
.rdclass
= rdata
->rdclass
;
158 md
->common
.rdtype
= rdata
->type
;
159 ISC_LINK_INIT(&md
->common
, link
);
161 dns_name_init(&name
, NULL
);
162 dns_rdata_toregion(rdata
, &r
);
163 dns_name_fromregion(&name
, &r
);
164 dns_name_init(&md
->md
, NULL
);
165 RETERR(name_duporclone(&name
, mctx
, &md
->md
));
167 return (ISC_R_SUCCESS
);
171 freestruct_md(ARGS_FREESTRUCT
) {
172 dns_rdata_md_t
*md
= source
;
174 REQUIRE(source
!= NULL
);
175 REQUIRE(md
->common
.rdtype
== 3);
177 if (md
->mctx
== NULL
)
180 dns_name_free(&md
->md
, md
->mctx
);
184 static inline isc_result_t
185 additionaldata_md(ARGS_ADDLDATA
) {
187 dns_offsets_t offsets
;
190 REQUIRE(rdata
->type
== 3);
192 dns_name_init(&name
, offsets
);
193 dns_rdata_toregion(rdata
, ®ion
);
194 dns_name_fromregion(&name
, ®ion
);
196 return ((add
)(arg
, &name
, dns_rdatatype_a
));
199 static inline isc_result_t
200 digest_md(ARGS_DIGEST
) {
204 REQUIRE(rdata
->type
== 3);
206 dns_rdata_toregion(rdata
, &r
);
207 dns_name_init(&name
, NULL
);
208 dns_name_fromregion(&name
, &r
);
210 return (dns_name_digest(&name
, digest
, arg
));
213 static inline isc_boolean_t
214 checkowner_md(ARGS_CHECKOWNER
) {
226 static inline isc_boolean_t
227 checknames_md(ARGS_CHECKNAMES
) {
229 REQUIRE(rdata
->type
== 3);
239 casecompare_md(ARGS_COMPARE
) {
240 return (compare_md(rdata1
, rdata2
));
243 #endif /* RDATA_GENERIC_MD_3_C */