Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / in_1 / nsap_22.c
blob097afd1c954b63fc7deb69b86d6983dd30329bbe
1 /* $NetBSD: nsap_22.c,v 1.5 2014/12/10 04:37:59 christos Exp $ */
3 /*
4 * Copyright (C) 2004, 2005, 2007, 2009, 2013 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2002 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: nsap_22.c,v 1.44 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Fri Mar 17 10:41:07 PST 2000 by gson */
24 /* RFC1706 */
26 #ifndef RDATA_IN_1_NSAP_22_C
27 #define RDATA_IN_1_NSAP_22_C
29 #define RRTYPE_NSAP_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_in_nsap(ARGS_FROMTEXT) {
33 isc_token_t token;
34 isc_textregion_t *sr;
35 int n;
36 int digits;
37 unsigned char c = 0;
39 REQUIRE(type == 22);
40 REQUIRE(rdclass == 1);
42 UNUSED(type);
43 UNUSED(origin);
44 UNUSED(options);
45 UNUSED(rdclass);
46 UNUSED(callbacks);
48 /* 0x<hex.string.with.periods> */
49 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
50 ISC_FALSE));
51 sr = &token.value.as_textregion;
52 if (sr->length < 2)
53 RETTOK(ISC_R_UNEXPECTEDEND);
54 if (sr->base[0] != '0' || (sr->base[1] != 'x' && sr->base[1] != 'X'))
55 RETTOK(DNS_R_SYNTAX);
56 isc_textregion_consume(sr, 2);
57 digits = 0;
58 while (sr->length > 0) {
59 if (sr->base[0] == '.') {
60 isc_textregion_consume(sr, 1);
61 continue;
63 if ((n = hexvalue(sr->base[0])) == -1)
64 RETTOK(DNS_R_SYNTAX);
65 c <<= 4;
66 c += n;
67 if (++digits == 2) {
68 RETERR(mem_tobuffer(target, &c, 1));
69 digits = 0;
71 isc_textregion_consume(sr, 1);
73 if (digits)
74 RETTOK(ISC_R_UNEXPECTEDEND);
75 return (ISC_R_SUCCESS);
78 static inline isc_result_t
79 totext_in_nsap(ARGS_TOTEXT) {
80 isc_region_t region;
81 char buf[sizeof("xx")];
83 REQUIRE(rdata->type == 22);
84 REQUIRE(rdata->rdclass == 1);
85 REQUIRE(rdata->length != 0);
87 UNUSED(tctx);
89 dns_rdata_toregion(rdata, &region);
90 RETERR(str_totext("0x", target));
91 while (region.length != 0) {
92 sprintf(buf, "%02x", region.base[0]);
93 isc_region_consume(&region, 1);
94 RETERR(str_totext(buf, target));
96 return (ISC_R_SUCCESS);
99 static inline isc_result_t
100 fromwire_in_nsap(ARGS_FROMWIRE) {
101 isc_region_t region;
103 REQUIRE(type == 22);
104 REQUIRE(rdclass == 1);
106 UNUSED(type);
107 UNUSED(dctx);
108 UNUSED(options);
109 UNUSED(rdclass);
111 isc_buffer_activeregion(source, &region);
112 if (region.length < 1)
113 return (ISC_R_UNEXPECTEDEND);
115 RETERR(mem_tobuffer(target, region.base, region.length));
116 isc_buffer_forward(source, region.length);
117 return (ISC_R_SUCCESS);
120 static inline isc_result_t
121 towire_in_nsap(ARGS_TOWIRE) {
122 REQUIRE(rdata->type == 22);
123 REQUIRE(rdata->rdclass == 1);
124 REQUIRE(rdata->length != 0);
126 UNUSED(cctx);
128 return (mem_tobuffer(target, rdata->data, rdata->length));
131 static inline int
132 compare_in_nsap(ARGS_COMPARE) {
133 isc_region_t r1;
134 isc_region_t r2;
136 REQUIRE(rdata1->type == rdata2->type);
137 REQUIRE(rdata1->rdclass == rdata2->rdclass);
138 REQUIRE(rdata1->type == 22);
139 REQUIRE(rdata1->rdclass == 1);
140 REQUIRE(rdata1->length != 0);
141 REQUIRE(rdata2->length != 0);
143 dns_rdata_toregion(rdata1, &r1);
144 dns_rdata_toregion(rdata2, &r2);
145 return (isc_region_compare(&r1, &r2));
148 static inline isc_result_t
149 fromstruct_in_nsap(ARGS_FROMSTRUCT) {
150 dns_rdata_in_nsap_t *nsap = source;
152 REQUIRE(type == 22);
153 REQUIRE(rdclass == 1);
154 REQUIRE(source != NULL);
155 REQUIRE(nsap->common.rdtype == type);
156 REQUIRE(nsap->common.rdclass == rdclass);
157 REQUIRE(nsap->nsap != NULL || nsap->nsap_len == 0);
159 UNUSED(type);
160 UNUSED(rdclass);
162 return (mem_tobuffer(target, nsap->nsap, nsap->nsap_len));
165 static inline isc_result_t
166 tostruct_in_nsap(ARGS_TOSTRUCT) {
167 dns_rdata_in_nsap_t *nsap = target;
168 isc_region_t r;
170 REQUIRE(rdata->type == 22);
171 REQUIRE(rdata->rdclass == 1);
172 REQUIRE(target != NULL);
173 REQUIRE(rdata->length != 0);
175 nsap->common.rdclass = rdata->rdclass;
176 nsap->common.rdtype = rdata->type;
177 ISC_LINK_INIT(&nsap->common, link);
179 dns_rdata_toregion(rdata, &r);
180 nsap->nsap_len = r.length;
181 nsap->nsap = mem_maybedup(mctx, r.base, r.length);
182 if (nsap->nsap == NULL)
183 return (ISC_R_NOMEMORY);
185 nsap->mctx = mctx;
186 return (ISC_R_SUCCESS);
189 static inline void
190 freestruct_in_nsap(ARGS_FREESTRUCT) {
191 dns_rdata_in_nsap_t *nsap = source;
193 REQUIRE(source != NULL);
194 REQUIRE(nsap->common.rdclass == 1);
195 REQUIRE(nsap->common.rdtype == 22);
197 if (nsap->mctx == NULL)
198 return;
200 if (nsap->nsap != NULL)
201 isc_mem_free(nsap->mctx, nsap->nsap);
202 nsap->mctx = NULL;
205 static inline isc_result_t
206 additionaldata_in_nsap(ARGS_ADDLDATA) {
207 REQUIRE(rdata->type == 22);
208 REQUIRE(rdata->rdclass == 1);
210 UNUSED(rdata);
211 UNUSED(add);
212 UNUSED(arg);
214 return (ISC_R_SUCCESS);
217 static inline isc_result_t
218 digest_in_nsap(ARGS_DIGEST) {
219 isc_region_t r;
221 REQUIRE(rdata->type == 22);
222 REQUIRE(rdata->rdclass == 1);
224 dns_rdata_toregion(rdata, &r);
226 return ((digest)(arg, &r));
229 static inline isc_boolean_t
230 checkowner_in_nsap(ARGS_CHECKOWNER) {
232 REQUIRE(type == 22);
233 REQUIRE(rdclass == 1);
235 UNUSED(name);
236 UNUSED(type);
237 UNUSED(rdclass);
238 UNUSED(wildcard);
240 return (ISC_TRUE);
243 static inline isc_boolean_t
244 checknames_in_nsap(ARGS_CHECKNAMES) {
246 REQUIRE(rdata->type == 22);
247 REQUIRE(rdata->rdclass == 1);
249 UNUSED(rdata);
250 UNUSED(owner);
251 UNUSED(bad);
253 return (ISC_TRUE);
256 static inline int
257 casecompare_in_nsap(ARGS_COMPARE) {
258 return (compare_in_nsap(rdata1, rdata2));
261 #endif /* RDATA_IN_1_NSAP_22_C */