2 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001, 2003 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: afsdb_18.c,v 1.47 2007/06/19 23:47:17 tbox Exp $ */
20 /* Reviewed: Wed Mar 15 14:59:00 PST 2000 by explorer */
24 #ifndef RDATA_GENERIC_AFSDB_18_C
25 #define RDATA_GENERIC_AFSDB_18_C
27 #define RRTYPE_AFSDB_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_afsdb(ARGS_FROMTEXT
) {
45 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
47 if (token
.value
.as_ulong
> 0xffffU
)
49 RETERR(uint16_tobuffer(token
.value
.as_ulong
, target
));
54 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
56 dns_name_init(&name
, NULL
);
57 buffer_fromregion(&buffer
, &token
.value
.as_region
);
58 origin
= (origin
!= NULL
) ? origin
: dns_rootname
;
59 RETTOK(dns_name_fromtext(&name
, &buffer
, origin
, options
, target
));
61 if ((options
& DNS_RDATA_CHECKNAMES
) != 0)
62 ok
= dns_name_ishostname(&name
, ISC_FALSE
);
63 if (!ok
&& (options
& DNS_RDATA_CHECKNAMESFAIL
) != 0)
64 RETTOK(DNS_R_BADNAME
);
65 if (!ok
&& callbacks
!= NULL
)
66 warn_badname(&name
, lexer
, callbacks
);
67 return (ISC_R_SUCCESS
);
70 static inline isc_result_t
71 totext_afsdb(ARGS_TOTEXT
) {
75 char buf
[sizeof("64000 ")];
79 REQUIRE(rdata
->type
== 18);
80 REQUIRE(rdata
->length
!= 0);
82 dns_name_init(&name
, NULL
);
83 dns_name_init(&prefix
, NULL
);
85 dns_rdata_toregion(rdata
, ®ion
);
86 num
= uint16_fromregion(®ion
);
87 isc_region_consume(®ion
, 2);
88 sprintf(buf
, "%u ", num
);
89 RETERR(str_totext(buf
, target
));
90 dns_name_fromregion(&name
, ®ion
);
91 sub
= name_prefix(&name
, tctx
->origin
, &prefix
);
92 return (dns_name_totext(&prefix
, sub
, target
));
95 static inline isc_result_t
96 fromwire_afsdb(ARGS_FROMWIRE
) {
106 dns_decompress_setmethods(dctx
, DNS_COMPRESS_NONE
);
108 dns_name_init(&name
, NULL
);
110 isc_buffer_activeregion(source
, &sr
);
111 isc_buffer_availableregion(target
, &tr
);
113 return (ISC_R_NOSPACE
);
115 return (ISC_R_UNEXPECTEDEND
);
116 memcpy(tr
.base
, sr
.base
, 2);
117 isc_buffer_forward(source
, 2);
118 isc_buffer_add(target
, 2);
119 return (dns_name_fromwire(&name
, source
, dctx
, options
, target
));
122 static inline isc_result_t
123 towire_afsdb(ARGS_TOWIRE
) {
127 dns_offsets_t offsets
;
129 REQUIRE(rdata
->type
== 18);
130 REQUIRE(rdata
->length
!= 0);
132 dns_compress_setmethods(cctx
, DNS_COMPRESS_NONE
);
133 isc_buffer_availableregion(target
, &tr
);
134 dns_rdata_toregion(rdata
, &sr
);
136 return (ISC_R_NOSPACE
);
137 memcpy(tr
.base
, sr
.base
, 2);
138 isc_region_consume(&sr
, 2);
139 isc_buffer_add(target
, 2);
141 dns_name_init(&name
, offsets
);
142 dns_name_fromregion(&name
, &sr
);
144 return (dns_name_towire(&name
, cctx
, target
));
148 compare_afsdb(ARGS_COMPARE
) {
152 isc_region_t region1
;
153 isc_region_t region2
;
155 REQUIRE(rdata1
->type
== rdata2
->type
);
156 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
157 REQUIRE(rdata1
->type
== 18);
158 REQUIRE(rdata1
->length
!= 0);
159 REQUIRE(rdata2
->length
!= 0);
161 result
= memcmp(rdata1
->data
, rdata2
->data
, 2);
163 return (result
< 0 ? -1 : 1);
165 dns_name_init(&name1
, NULL
);
166 dns_name_init(&name2
, NULL
);
168 dns_rdata_toregion(rdata1
, ®ion1
);
169 dns_rdata_toregion(rdata2
, ®ion2
);
171 isc_region_consume(®ion1
, 2);
172 isc_region_consume(®ion2
, 2);
174 dns_name_fromregion(&name1
, ®ion1
);
175 dns_name_fromregion(&name2
, ®ion2
);
177 return (dns_name_rdatacompare(&name1
, &name2
));
180 static inline isc_result_t
181 fromstruct_afsdb(ARGS_FROMSTRUCT
) {
182 dns_rdata_afsdb_t
*afsdb
= source
;
186 REQUIRE(source
!= NULL
);
187 REQUIRE(afsdb
->common
.rdclass
== rdclass
);
188 REQUIRE(afsdb
->common
.rdtype
== type
);
193 RETERR(uint16_tobuffer(afsdb
->subtype
, target
));
194 dns_name_toregion(&afsdb
->server
, ®ion
);
195 return (isc_buffer_copyregion(target
, ®ion
));
198 static inline isc_result_t
199 tostruct_afsdb(ARGS_TOSTRUCT
) {
201 dns_rdata_afsdb_t
*afsdb
= target
;
204 REQUIRE(rdata
->type
== 18);
205 REQUIRE(target
!= NULL
);
206 REQUIRE(rdata
->length
!= 0);
208 afsdb
->common
.rdclass
= rdata
->rdclass
;
209 afsdb
->common
.rdtype
= rdata
->type
;
210 ISC_LINK_INIT(&afsdb
->common
, link
);
212 dns_name_init(&afsdb
->server
, NULL
);
214 dns_rdata_toregion(rdata
, ®ion
);
216 afsdb
->subtype
= uint16_fromregion(®ion
);
217 isc_region_consume(®ion
, 2);
219 dns_name_init(&name
, NULL
);
220 dns_name_fromregion(&name
, ®ion
);
222 RETERR(name_duporclone(&name
, mctx
, &afsdb
->server
));
224 return (ISC_R_SUCCESS
);
228 freestruct_afsdb(ARGS_FREESTRUCT
) {
229 dns_rdata_afsdb_t
*afsdb
= source
;
231 REQUIRE(source
!= NULL
);
232 REQUIRE(afsdb
->common
.rdtype
== 18);
234 if (afsdb
->mctx
== NULL
)
237 dns_name_free(&afsdb
->server
, afsdb
->mctx
);
241 static inline isc_result_t
242 additionaldata_afsdb(ARGS_ADDLDATA
) {
244 dns_offsets_t offsets
;
247 REQUIRE(rdata
->type
== 18);
249 dns_name_init(&name
, offsets
);
250 dns_rdata_toregion(rdata
, ®ion
);
251 isc_region_consume(®ion
, 2);
252 dns_name_fromregion(&name
, ®ion
);
254 return ((add
)(arg
, &name
, dns_rdatatype_a
));
257 static inline isc_result_t
258 digest_afsdb(ARGS_DIGEST
) {
262 REQUIRE(rdata
->type
== 18);
264 dns_rdata_toregion(rdata
, &r1
);
266 isc_region_consume(&r2
, 2);
268 RETERR((digest
)(arg
, &r1
));
269 dns_name_init(&name
, NULL
);
270 dns_name_fromregion(&name
, &r2
);
272 return (dns_name_digest(&name
, digest
, arg
));
275 static inline isc_boolean_t
276 checkowner_afsdb(ARGS_CHECKOWNER
) {
288 static inline isc_boolean_t
289 checknames_afsdb(ARGS_CHECKNAMES
) {
293 REQUIRE(rdata
->type
== 18);
297 dns_rdata_toregion(rdata
, ®ion
);
298 isc_region_consume(®ion
, 2);
299 dns_name_init(&name
, NULL
);
300 dns_name_fromregion(&name
, ®ion
);
301 if (!dns_name_ishostname(&name
, ISC_FALSE
)) {
303 dns_name_clone(&name
, bad
);
309 #endif /* RDATA_GENERIC_AFSDB_18_C */