Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / bind / dist / lib / dns / rdata / in_1 / nsap_22.c
blob1a10dcc245d273dc4fd68cf694964cd44b1b8acd
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2004, 2005, 2007, 2009 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 n = 0;
59 while (sr->length > 0) {
60 if (sr->base[0] == '.') {
61 isc_textregion_consume(sr, 1);
62 continue;
64 if ((n = hexvalue(sr->base[0])) == -1)
65 RETTOK(DNS_R_SYNTAX);
66 c <<= 4;
67 c += n;
68 if (++digits == 2) {
69 RETERR(mem_tobuffer(target, &c, 1));
70 digits = 0;
72 isc_textregion_consume(sr, 1);
74 if (digits)
75 RETTOK(ISC_R_UNEXPECTEDEND);
76 return (ISC_R_SUCCESS);
79 static inline isc_result_t
80 totext_in_nsap(ARGS_TOTEXT) {
81 isc_region_t region;
82 char buf[sizeof("xx")];
84 REQUIRE(rdata->type == 22);
85 REQUIRE(rdata->rdclass == 1);
86 REQUIRE(rdata->length != 0);
88 UNUSED(tctx);
90 dns_rdata_toregion(rdata, &region);
91 RETERR(str_totext("0x", target));
92 while (region.length != 0) {
93 sprintf(buf, "%02x", region.base[0]);
94 isc_region_consume(&region, 1);
95 RETERR(str_totext(buf, target));
97 return (ISC_R_SUCCESS);
100 static inline isc_result_t
101 fromwire_in_nsap(ARGS_FROMWIRE) {
102 isc_region_t region;
104 REQUIRE(type == 22);
105 REQUIRE(rdclass == 1);
107 UNUSED(type);
108 UNUSED(dctx);
109 UNUSED(options);
110 UNUSED(rdclass);
112 isc_buffer_activeregion(source, &region);
113 if (region.length < 1)
114 return (ISC_R_UNEXPECTEDEND);
116 RETERR(mem_tobuffer(target, region.base, region.length));
117 isc_buffer_forward(source, region.length);
118 return (ISC_R_SUCCESS);
121 static inline isc_result_t
122 towire_in_nsap(ARGS_TOWIRE) {
123 REQUIRE(rdata->type == 22);
124 REQUIRE(rdata->rdclass == 1);
125 REQUIRE(rdata->length != 0);
127 UNUSED(cctx);
129 return (mem_tobuffer(target, rdata->data, rdata->length));
132 static inline int
133 compare_in_nsap(ARGS_COMPARE) {
134 isc_region_t r1;
135 isc_region_t r2;
137 REQUIRE(rdata1->type == rdata2->type);
138 REQUIRE(rdata1->rdclass == rdata2->rdclass);
139 REQUIRE(rdata1->type == 22);
140 REQUIRE(rdata1->rdclass == 1);
141 REQUIRE(rdata1->length != 0);
142 REQUIRE(rdata2->length != 0);
144 dns_rdata_toregion(rdata1, &r1);
145 dns_rdata_toregion(rdata2, &r2);
146 return (isc_region_compare(&r1, &r2));
149 static inline isc_result_t
150 fromstruct_in_nsap(ARGS_FROMSTRUCT) {
151 dns_rdata_in_nsap_t *nsap = source;
153 REQUIRE(type == 22);
154 REQUIRE(rdclass == 1);
155 REQUIRE(source != NULL);
156 REQUIRE(nsap->common.rdtype == type);
157 REQUIRE(nsap->common.rdclass == rdclass);
158 REQUIRE(nsap->nsap != NULL || nsap->nsap_len == 0);
160 UNUSED(type);
161 UNUSED(rdclass);
163 return (mem_tobuffer(target, nsap->nsap, nsap->nsap_len));
166 static inline isc_result_t
167 tostruct_in_nsap(ARGS_TOSTRUCT) {
168 dns_rdata_in_nsap_t *nsap = target;
169 isc_region_t r;
171 REQUIRE(rdata->type == 22);
172 REQUIRE(rdata->rdclass == 1);
173 REQUIRE(target != NULL);
174 REQUIRE(rdata->length != 0);
176 nsap->common.rdclass = rdata->rdclass;
177 nsap->common.rdtype = rdata->type;
178 ISC_LINK_INIT(&nsap->common, link);
180 dns_rdata_toregion(rdata, &r);
181 nsap->nsap_len = r.length;
182 nsap->nsap = mem_maybedup(mctx, r.base, r.length);
183 if (nsap->nsap == NULL)
184 return (ISC_R_NOMEMORY);
186 nsap->mctx = mctx;
187 return (ISC_R_SUCCESS);
190 static inline void
191 freestruct_in_nsap(ARGS_FREESTRUCT) {
192 dns_rdata_in_nsap_t *nsap = source;
194 REQUIRE(source != NULL);
195 REQUIRE(nsap->common.rdclass == 1);
196 REQUIRE(nsap->common.rdtype == 22);
198 if (nsap->mctx == NULL)
199 return;
201 if (nsap->nsap != NULL)
202 isc_mem_free(nsap->mctx, nsap->nsap);
203 nsap->mctx = NULL;
206 static inline isc_result_t
207 additionaldata_in_nsap(ARGS_ADDLDATA) {
208 REQUIRE(rdata->type == 22);
209 REQUIRE(rdata->rdclass == 1);
211 UNUSED(rdata);
212 UNUSED(add);
213 UNUSED(arg);
215 return (ISC_R_SUCCESS);
218 static inline isc_result_t
219 digest_in_nsap(ARGS_DIGEST) {
220 isc_region_t r;
222 REQUIRE(rdata->type == 22);
223 REQUIRE(rdata->rdclass == 1);
225 dns_rdata_toregion(rdata, &r);
227 return ((digest)(arg, &r));
230 static inline isc_boolean_t
231 checkowner_in_nsap(ARGS_CHECKOWNER) {
233 REQUIRE(type == 22);
234 REQUIRE(rdclass == 1);
236 UNUSED(name);
237 UNUSED(type);
238 UNUSED(rdclass);
239 UNUSED(wildcard);
241 return (ISC_TRUE);
244 static inline isc_boolean_t
245 checknames_in_nsap(ARGS_CHECKNAMES) {
247 REQUIRE(rdata->type == 22);
248 REQUIRE(rdata->rdclass == 1);
250 UNUSED(rdata);
251 UNUSED(owner);
252 UNUSED(bad);
254 return (ISC_TRUE);
257 static inline int
258 casecompare_in_nsap(ARGS_COMPARE) {
259 return (compare_in_nsap(rdata1, rdata2));
262 #endif /* RDATA_IN_1_NSAP_22_C */