2 * Copyright (C) 2004, 2005, 2007, 2009, 2013 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.44 2009/12/04 22:06:37 tbox Exp $ */
20 /* Reviewed: Fri Mar 17 10:41:07 PST 2000 by gson */
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) {
38 REQUIRE(rdclass == 1);
46 /* 0x<hex.string.with.periods> */
47 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
49 sr = &token.value.as_textregion;
51 RETTOK(ISC_R_UNEXPECTEDEND);
52 if (sr->base[0] != '0' || (sr->base[1] != 'x' && sr->base[1] != 'X'))
54 isc_textregion_consume(sr, 2);
56 while (sr->length > 0) {
57 if (sr->base[0] == '.') {
58 isc_textregion_consume(sr, 1);
61 if ((n = hexvalue(sr->base[0])) == -1)
66 RETERR(mem_tobuffer(target, &c, 1));
69 isc_textregion_consume(sr, 1);
72 RETTOK(ISC_R_UNEXPECTEDEND);
73 return (ISC_R_SUCCESS);
76 static inline isc_result_t
77 totext_in_nsap(ARGS_TOTEXT) {
79 char buf[sizeof("xx")];
81 REQUIRE(rdata->type == 22);
82 REQUIRE(rdata->rdclass == 1);
83 REQUIRE(rdata->length != 0);
87 dns_rdata_toregion(rdata, ®ion);
88 RETERR(str_totext("0x", target));
89 while (region.length != 0) {
90 sprintf(buf, "%02x", region.base[0]);
91 isc_region_consume(®ion, 1);
92 RETERR(str_totext(buf, target));
94 return (ISC_R_SUCCESS);
97 static inline isc_result_t
98 fromwire_in_nsap(ARGS_FROMWIRE) {
102 REQUIRE(rdclass == 1);
109 isc_buffer_activeregion(source, ®ion);
110 if (region.length < 1)
111 return (ISC_R_UNEXPECTEDEND);
113 RETERR(mem_tobuffer(target, region.base, region.length));
114 isc_buffer_forward(source, region.length);
115 return (ISC_R_SUCCESS);
118 static inline isc_result_t
119 towire_in_nsap(ARGS_TOWIRE) {
120 REQUIRE(rdata->type == 22);
121 REQUIRE(rdata->rdclass == 1);
122 REQUIRE(rdata->length != 0);
126 return (mem_tobuffer(target, rdata->data, rdata->length));
130 compare_in_nsap(ARGS_COMPARE) {
134 REQUIRE(rdata1->type == rdata2->type);
135 REQUIRE(rdata1->rdclass == rdata2->rdclass);
136 REQUIRE(rdata1->type == 22);
137 REQUIRE(rdata1->rdclass == 1);
138 REQUIRE(rdata1->length != 0);
139 REQUIRE(rdata2->length != 0);
141 dns_rdata_toregion(rdata1, &r1);
142 dns_rdata_toregion(rdata2, &r2);
143 return (isc_region_compare(&r1, &r2));
146 static inline isc_result_t
147 fromstruct_in_nsap(ARGS_FROMSTRUCT) {
148 dns_rdata_in_nsap_t *nsap = source;
151 REQUIRE(rdclass == 1);
152 REQUIRE(source != NULL);
153 REQUIRE(nsap->common.rdtype == type);
154 REQUIRE(nsap->common.rdclass == rdclass);
155 REQUIRE(nsap->nsap != NULL || nsap->nsap_len == 0);
160 return (mem_tobuffer(target, nsap->nsap, nsap->nsap_len));
163 static inline isc_result_t
164 tostruct_in_nsap(ARGS_TOSTRUCT) {
165 dns_rdata_in_nsap_t *nsap = target;
168 REQUIRE(rdata->type == 22);
169 REQUIRE(rdata->rdclass == 1);
170 REQUIRE(target != NULL);
171 REQUIRE(rdata->length != 0);
173 nsap->common.rdclass = rdata->rdclass;
174 nsap->common.rdtype = rdata->type;
175 ISC_LINK_INIT(&nsap->common, link);
177 dns_rdata_toregion(rdata, &r);
178 nsap->nsap_len = r.length;
179 nsap->nsap = mem_maybedup(mctx, r.base, r.length);
180 if (nsap->nsap == NULL)
181 return (ISC_R_NOMEMORY);
184 return (ISC_R_SUCCESS);
188 freestruct_in_nsap(ARGS_FREESTRUCT) {
189 dns_rdata_in_nsap_t *nsap = source;
191 REQUIRE(source != NULL);
192 REQUIRE(nsap->common.rdclass == 1);
193 REQUIRE(nsap->common.rdtype == 22);
195 if (nsap->mctx == NULL)
198 if (nsap->nsap != NULL)
199 isc_mem_free(nsap->mctx, nsap->nsap);
203 static inline isc_result_t
204 additionaldata_in_nsap(ARGS_ADDLDATA) {
205 REQUIRE(rdata->type == 22);
206 REQUIRE(rdata->rdclass == 1);
212 return (ISC_R_SUCCESS);
215 static inline isc_result_t
216 digest_in_nsap(ARGS_DIGEST) {
219 REQUIRE(rdata->type == 22);
220 REQUIRE(rdata->rdclass == 1);
222 dns_rdata_toregion(rdata, &r);
224 return ((digest)(arg, &r));
227 static inline isc_boolean_t
228 checkowner_in_nsap(ARGS_CHECKOWNER) {
231 REQUIRE(rdclass == 1);
241 static inline isc_boolean_t
242 checknames_in_nsap(ARGS_CHECKNAMES) {
244 REQUIRE(rdata->type == 22);
245 REQUIRE(rdata->rdclass == 1);
255 casecompare_in_nsap(ARGS_COMPARE) {
256 return (compare_in_nsap(rdata1, rdata2));
259 #endif /* RDATA_IN_1_NSAP_22_C */