Detect FPU by checking CPUID features.
[dragonfly.git] / contrib / bind-9.5.2 / lib / dns / rdata / in_1 / nsap_22.c
blobc25f5608884c4fa5a346ae4fe4ebd2010feb9d5b
1 /*
2 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2002 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: nsap_22.c,v 1.42 2007/06/19 23:47:17 tbox Exp $ */
20 /* Reviewed: Fri Mar 17 10:41:07 PST 2000 by gson */
22 /* RFC1706 */
24 #ifndef RDATA_IN_1_NSAP_22_C
25 #define RDATA_IN_1_NSAP_22_C
27 #define RRTYPE_NSAP_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_in_nsap(ARGS_FROMTEXT) {
31 isc_token_t token;
32 isc_textregion_t *sr;
33 int n;
34 int digits;
35 unsigned char c = 0;
37 REQUIRE(type == 22);
38 REQUIRE(rdclass == 1);
40 UNUSED(type);
41 UNUSED(origin);
42 UNUSED(options);
43 UNUSED(rdclass);
44 UNUSED(callbacks);
46 /* 0x<hex.string.with.periods> */
47 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
48 ISC_FALSE));
49 sr = &token.value.as_textregion;
50 if (sr->length < 2)
51 RETTOK(ISC_R_UNEXPECTEDEND);
52 if (sr->base[0] != '0' || (sr->base[1] != 'x' && sr->base[1] != 'X'))
53 RETTOK(DNS_R_SYNTAX);
54 isc_textregion_consume(sr, 2);
55 digits = 0;
56 n = 0;
57 while (sr->length > 0) {
58 if (sr->base[0] == '.') {
59 isc_textregion_consume(sr, 1);
60 continue;
62 if ((n = hexvalue(sr->base[0])) == -1)
63 RETTOK(DNS_R_SYNTAX);
64 c <<= 4;
65 c += n;
66 if (++digits == 2) {
67 RETERR(mem_tobuffer(target, &c, 1));
68 digits = 0;
70 isc_textregion_consume(sr, 1);
72 if (digits)
73 RETTOK(ISC_R_UNEXPECTEDEND);
74 return (ISC_R_SUCCESS);
77 static inline isc_result_t
78 totext_in_nsap(ARGS_TOTEXT) {
79 isc_region_t region;
80 char buf[sizeof("xx")];
82 REQUIRE(rdata->type == 22);
83 REQUIRE(rdata->rdclass == 1);
84 REQUIRE(rdata->length != 0);
86 UNUSED(tctx);
88 dns_rdata_toregion(rdata, &region);
89 RETERR(str_totext("0x", target));
90 while (region.length != 0) {
91 sprintf(buf, "%02x", region.base[0]);
92 isc_region_consume(&region, 1);
93 RETERR(str_totext(buf, target));
95 return (ISC_R_SUCCESS);
98 static inline isc_result_t
99 fromwire_in_nsap(ARGS_FROMWIRE) {
100 isc_region_t region;
102 REQUIRE(type == 22);
103 REQUIRE(rdclass == 1);
105 UNUSED(type);
106 UNUSED(dctx);
107 UNUSED(options);
108 UNUSED(rdclass);
110 isc_buffer_activeregion(source, &region);
111 if (region.length < 1)
112 return (ISC_R_UNEXPECTEDEND);
114 RETERR(mem_tobuffer(target, region.base, region.length));
115 isc_buffer_forward(source, region.length);
116 return (ISC_R_SUCCESS);
119 static inline isc_result_t
120 towire_in_nsap(ARGS_TOWIRE) {
121 REQUIRE(rdata->type == 22);
122 REQUIRE(rdata->rdclass == 1);
123 REQUIRE(rdata->length != 0);
125 UNUSED(cctx);
127 return (mem_tobuffer(target, rdata->data, rdata->length));
130 static inline int
131 compare_in_nsap(ARGS_COMPARE) {
132 isc_region_t r1;
133 isc_region_t r2;
135 REQUIRE(rdata1->type == rdata2->type);
136 REQUIRE(rdata1->rdclass == rdata2->rdclass);
137 REQUIRE(rdata1->type == 22);
138 REQUIRE(rdata1->rdclass == 1);
139 REQUIRE(rdata1->length != 0);
140 REQUIRE(rdata2->length != 0);
142 dns_rdata_toregion(rdata1, &r1);
143 dns_rdata_toregion(rdata2, &r2);
144 return (isc_region_compare(&r1, &r2));
147 static inline isc_result_t
148 fromstruct_in_nsap(ARGS_FROMSTRUCT) {
149 dns_rdata_in_nsap_t *nsap = source;
151 REQUIRE(type == 22);
152 REQUIRE(rdclass == 1);
153 REQUIRE(source != NULL);
154 REQUIRE(nsap->common.rdtype == type);
155 REQUIRE(nsap->common.rdclass == rdclass);
156 REQUIRE(nsap->nsap != NULL || nsap->nsap_len == 0);
158 UNUSED(type);
159 UNUSED(rdclass);
161 return (mem_tobuffer(target, nsap->nsap, nsap->nsap_len));
164 static inline isc_result_t
165 tostruct_in_nsap(ARGS_TOSTRUCT) {
166 dns_rdata_in_nsap_t *nsap = target;
167 isc_region_t r;
169 REQUIRE(rdata->type == 22);
170 REQUIRE(rdata->rdclass == 1);
171 REQUIRE(target != NULL);
172 REQUIRE(rdata->length != 0);
174 nsap->common.rdclass = rdata->rdclass;
175 nsap->common.rdtype = rdata->type;
176 ISC_LINK_INIT(&nsap->common, link);
178 dns_rdata_toregion(rdata, &r);
179 nsap->nsap_len = r.length;
180 nsap->nsap = mem_maybedup(mctx, r.base, r.length);
181 if (nsap->nsap == NULL)
182 return (ISC_R_NOMEMORY);
184 nsap->mctx = mctx;
185 return (ISC_R_SUCCESS);
188 static inline void
189 freestruct_in_nsap(ARGS_FREESTRUCT) {
190 dns_rdata_in_nsap_t *nsap = source;
192 REQUIRE(source != NULL);
193 REQUIRE(nsap->common.rdclass == 1);
194 REQUIRE(nsap->common.rdtype == 22);
196 if (nsap->mctx == NULL)
197 return;
199 if (nsap->nsap != NULL)
200 isc_mem_free(nsap->mctx, nsap->nsap);
201 nsap->mctx = NULL;
204 static inline isc_result_t
205 additionaldata_in_nsap(ARGS_ADDLDATA) {
206 REQUIRE(rdata->type == 22);
207 REQUIRE(rdata->rdclass == 1);
209 UNUSED(rdata);
210 UNUSED(add);
211 UNUSED(arg);
213 return (ISC_R_SUCCESS);
216 static inline isc_result_t
217 digest_in_nsap(ARGS_DIGEST) {
218 isc_region_t r;
220 REQUIRE(rdata->type == 22);
221 REQUIRE(rdata->rdclass == 1);
223 dns_rdata_toregion(rdata, &r);
225 return ((digest)(arg, &r));
228 static inline isc_boolean_t
229 checkowner_in_nsap(ARGS_CHECKOWNER) {
231 REQUIRE(type == 22);
232 REQUIRE(rdclass == 1);
234 UNUSED(name);
235 UNUSED(type);
236 UNUSED(rdclass);
237 UNUSED(wildcard);
239 return (ISC_TRUE);
242 static inline isc_boolean_t
243 checknames_in_nsap(ARGS_CHECKNAMES) {
245 REQUIRE(rdata->type == 22);
246 REQUIRE(rdata->rdclass == 1);
248 UNUSED(rdata);
249 UNUSED(owner);
250 UNUSED(bad);
252 return (ISC_TRUE);
255 #endif /* RDATA_IN_1_NSAP_22_C */