Detect FPU by checking CPUID features.
[dragonfly.git] / contrib / bind-9.5.2 / lib / dns / rdata / generic / afsdb_18.c
blob2230efb1499add23d62bf80fb1600b743c44a3fd
1 /*
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 */
22 /* RFC1183 */
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) {
31 isc_token_t token;
32 isc_buffer_t buffer;
33 dns_name_t name;
34 isc_boolean_t ok;
36 REQUIRE(type == 18);
38 UNUSED(type);
39 UNUSED(rdclass);
40 UNUSED(callbacks);
43 * Subtype.
45 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
46 ISC_FALSE));
47 if (token.value.as_ulong > 0xffffU)
48 RETTOK(ISC_R_RANGE);
49 RETERR(uint16_tobuffer(token.value.as_ulong, target));
52 * Hostname.
54 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
55 ISC_FALSE));
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));
60 ok = ISC_TRUE;
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) {
72 dns_name_t name;
73 dns_name_t prefix;
74 isc_region_t region;
75 char buf[sizeof("64000 ")];
76 isc_boolean_t sub;
77 unsigned int num;
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, &region);
86 num = uint16_fromregion(&region);
87 isc_region_consume(&region, 2);
88 sprintf(buf, "%u ", num);
89 RETERR(str_totext(buf, target));
90 dns_name_fromregion(&name, &region);
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) {
97 dns_name_t name;
98 isc_region_t sr;
99 isc_region_t tr;
101 REQUIRE(type == 18);
103 UNUSED(type);
104 UNUSED(rdclass);
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);
112 if (tr.length < 2)
113 return (ISC_R_NOSPACE);
114 if (sr.length < 2)
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) {
124 isc_region_t tr;
125 isc_region_t sr;
126 dns_name_t name;
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);
135 if (tr.length < 2)
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));
147 static inline int
148 compare_afsdb(ARGS_COMPARE) {
149 int result;
150 dns_name_t name1;
151 dns_name_t name2;
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);
162 if (result != 0)
163 return (result < 0 ? -1 : 1);
165 dns_name_init(&name1, NULL);
166 dns_name_init(&name2, NULL);
168 dns_rdata_toregion(rdata1, &region1);
169 dns_rdata_toregion(rdata2, &region2);
171 isc_region_consume(&region1, 2);
172 isc_region_consume(&region2, 2);
174 dns_name_fromregion(&name1, &region1);
175 dns_name_fromregion(&name2, &region2);
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;
183 isc_region_t region;
185 REQUIRE(type == 18);
186 REQUIRE(source != NULL);
187 REQUIRE(afsdb->common.rdclass == rdclass);
188 REQUIRE(afsdb->common.rdtype == type);
190 UNUSED(type);
191 UNUSED(rdclass);
193 RETERR(uint16_tobuffer(afsdb->subtype, target));
194 dns_name_toregion(&afsdb->server, &region);
195 return (isc_buffer_copyregion(target, &region));
198 static inline isc_result_t
199 tostruct_afsdb(ARGS_TOSTRUCT) {
200 isc_region_t region;
201 dns_rdata_afsdb_t *afsdb = target;
202 dns_name_t name;
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, &region);
216 afsdb->subtype = uint16_fromregion(&region);
217 isc_region_consume(&region, 2);
219 dns_name_init(&name, NULL);
220 dns_name_fromregion(&name, &region);
222 RETERR(name_duporclone(&name, mctx, &afsdb->server));
223 afsdb->mctx = mctx;
224 return (ISC_R_SUCCESS);
227 static inline void
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)
235 return;
237 dns_name_free(&afsdb->server, afsdb->mctx);
238 afsdb->mctx = NULL;
241 static inline isc_result_t
242 additionaldata_afsdb(ARGS_ADDLDATA) {
243 dns_name_t name;
244 dns_offsets_t offsets;
245 isc_region_t region;
247 REQUIRE(rdata->type == 18);
249 dns_name_init(&name, offsets);
250 dns_rdata_toregion(rdata, &region);
251 isc_region_consume(&region, 2);
252 dns_name_fromregion(&name, &region);
254 return ((add)(arg, &name, dns_rdatatype_a));
257 static inline isc_result_t
258 digest_afsdb(ARGS_DIGEST) {
259 isc_region_t r1, r2;
260 dns_name_t name;
262 REQUIRE(rdata->type == 18);
264 dns_rdata_toregion(rdata, &r1);
265 r2 = r1;
266 isc_region_consume(&r2, 2);
267 r1.length = 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) {
278 REQUIRE(type == 18);
280 UNUSED(name);
281 UNUSED(type);
282 UNUSED(rdclass);
283 UNUSED(wildcard);
285 return (ISC_TRUE);
288 static inline isc_boolean_t
289 checknames_afsdb(ARGS_CHECKNAMES) {
290 isc_region_t region;
291 dns_name_t name;
293 REQUIRE(rdata->type == 18);
295 UNUSED(owner);
297 dns_rdata_toregion(rdata, &region);
298 isc_region_consume(&region, 2);
299 dns_name_init(&name, NULL);
300 dns_name_fromregion(&name, &region);
301 if (!dns_name_ishostname(&name, ISC_FALSE)) {
302 if (bad != NULL)
303 dns_name_clone(&name, bad);
304 return (ISC_FALSE);
306 return (ISC_TRUE);
309 #endif /* RDATA_GENERIC_AFSDB_18_C */