2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1998-2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and 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: cname_5.c,v 1.43.2.1 2004/03/09 06:11:27 marka Exp $ */
20 /* reviewed: Wed Mar 15 16:48:45 PST 2000 by brister */
22 #ifndef RDATA_GENERIC_CNAME_5_C
23 #define RDATA_GENERIC_CNAME_5_C
25 #define RRTYPE_CNAME_ATTRIBUTES \
26 (DNS_RDATATYPEATTR_EXCLUSIVE | DNS_RDATATYPEATTR_SINGLETON)
28 static inline isc_result_t
29 fromtext_cname(ARGS_FROMTEXT
) {
40 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
43 dns_name_init(&name
, NULL
);
44 buffer_fromregion(&buffer
, &token
.value
.as_region
);
45 origin
= (origin
!= NULL
) ? origin
: dns_rootname
;
46 RETTOK(dns_name_fromtext(&name
, &buffer
, origin
, downcase
, target
));
47 return (ISC_R_SUCCESS
);
50 static inline isc_result_t
51 totext_cname(ARGS_TOTEXT
) {
57 REQUIRE(rdata
->type
== 5);
58 REQUIRE(rdata
->length
!= 0);
60 dns_name_init(&name
, NULL
);
61 dns_name_init(&prefix
, NULL
);
63 dns_rdata_toregion(rdata
, ®ion
);
64 dns_name_fromregion(&name
, ®ion
);
66 sub
= name_prefix(&name
, tctx
->origin
, &prefix
);
68 return (dns_name_totext(&prefix
, sub
, target
));
71 static inline isc_result_t
72 fromwire_cname(ARGS_FROMWIRE
) {
80 dns_decompress_setmethods(dctx
, DNS_COMPRESS_GLOBAL14
);
82 dns_name_init(&name
, NULL
);
83 return (dns_name_fromwire(&name
, source
, dctx
, downcase
, target
));
86 static inline isc_result_t
87 towire_cname(ARGS_TOWIRE
) {
89 dns_offsets_t offsets
;
92 REQUIRE(rdata
->type
== 5);
93 REQUIRE(rdata
->length
!= 0);
95 dns_compress_setmethods(cctx
, DNS_COMPRESS_GLOBAL14
);
97 dns_name_init(&name
, offsets
);
98 dns_rdata_toregion(rdata
, ®ion
);
99 dns_name_fromregion(&name
, ®ion
);
101 return (dns_name_towire(&name
, cctx
, target
));
105 compare_cname(ARGS_COMPARE
) {
108 isc_region_t region1
;
109 isc_region_t region2
;
111 REQUIRE(rdata1
->type
== rdata2
->type
);
112 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
113 REQUIRE(rdata1
->type
== 5);
114 REQUIRE(rdata1
->length
!= 0);
115 REQUIRE(rdata2
->length
!= 0);
117 dns_name_init(&name1
, NULL
);
118 dns_name_init(&name2
, NULL
);
120 dns_rdata_toregion(rdata1
, ®ion1
);
121 dns_rdata_toregion(rdata2
, ®ion2
);
123 dns_name_fromregion(&name1
, ®ion1
);
124 dns_name_fromregion(&name2
, ®ion2
);
126 return (dns_name_rdatacompare(&name1
, &name2
));
129 static inline isc_result_t
130 fromstruct_cname(ARGS_FROMSTRUCT
) {
131 dns_rdata_cname_t
*cname
= source
;
135 REQUIRE(source
!= NULL
);
136 REQUIRE(cname
->common
.rdtype
== type
);
137 REQUIRE(cname
->common
.rdclass
== rdclass
);
142 dns_name_toregion(&cname
->cname
, ®ion
);
143 return (isc_buffer_copyregion(target
, ®ion
));
146 static inline isc_result_t
147 tostruct_cname(ARGS_TOSTRUCT
) {
149 dns_rdata_cname_t
*cname
= target
;
152 REQUIRE(rdata
->type
== 5);
153 REQUIRE(target
!= NULL
);
154 REQUIRE(rdata
->length
!= 0);
156 cname
->common
.rdclass
= rdata
->rdclass
;
157 cname
->common
.rdtype
= rdata
->type
;
158 ISC_LINK_INIT(&cname
->common
, link
);
160 dns_name_init(&name
, NULL
);
161 dns_rdata_toregion(rdata
, ®ion
);
162 dns_name_fromregion(&name
, ®ion
);
163 dns_name_init(&cname
->cname
, NULL
);
164 RETERR(name_duporclone(&name
, mctx
, &cname
->cname
));
166 return (ISC_R_SUCCESS
);
170 freestruct_cname(ARGS_FREESTRUCT
) {
171 dns_rdata_cname_t
*cname
= source
;
173 REQUIRE(source
!= NULL
);
175 if (cname
->mctx
== NULL
)
178 dns_name_free(&cname
->cname
, cname
->mctx
);
182 static inline isc_result_t
183 additionaldata_cname(ARGS_ADDLDATA
) {
188 REQUIRE(rdata
->type
== 5);
190 return (ISC_R_SUCCESS
);
193 static inline isc_result_t
194 digest_cname(ARGS_DIGEST
) {
198 REQUIRE(rdata
->type
== 5);
200 dns_rdata_toregion(rdata
, &r
);
201 dns_name_init(&name
, NULL
);
202 dns_name_fromregion(&name
, &r
);
204 return (dns_name_digest(&name
, digest
, arg
));
207 #endif /* RDATA_GENERIC_CNAME_5_C */