]> CyberLeo.Net >> Repos - FreeBSD/releng/9.3.git/blob - contrib/bind9/lib/dns/rdata/in_1/nsap_22.c
Copy stable/9 to releng/9.3 as part of the 9.3-RELEASE cycle.
[FreeBSD/releng/9.3.git] / contrib / bind9 / lib / dns / rdata / in_1 / nsap_22.c
1 /*
2  * Copyright (C) 2004, 2005, 2007, 2009, 2013  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2002  Internet Software Consortium.
4  *
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.
8  *
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.
16  */
17
18 /* $Id: nsap_22.c,v 1.44 2009/12/04 22:06:37 tbox Exp $ */
19
20 /* Reviewed: Fri Mar 17 10:41:07 PST 2000 by gson */
21
22 /* RFC1706 */
23
24 #ifndef RDATA_IN_1_NSAP_22_C
25 #define RDATA_IN_1_NSAP_22_C
26
27 #define RRTYPE_NSAP_ATTRIBUTES (0)
28
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;
36
37         REQUIRE(type == 22);
38         REQUIRE(rdclass == 1);
39
40         UNUSED(type);
41         UNUSED(origin);
42         UNUSED(options);
43         UNUSED(rdclass);
44         UNUSED(callbacks);
45
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         while (sr->length > 0) {
57                 if (sr->base[0] == '.') {
58                         isc_textregion_consume(sr, 1);
59                         continue;
60                 }
61                 if ((n = hexvalue(sr->base[0])) == -1)
62                         RETTOK(DNS_R_SYNTAX);
63                 c <<= 4;
64                 c += n;
65                 if (++digits == 2) {
66                         RETERR(mem_tobuffer(target, &c, 1));
67                         digits = 0;
68                 }
69                 isc_textregion_consume(sr, 1);
70         }
71         if (digits)
72                 RETTOK(ISC_R_UNEXPECTEDEND);
73         return (ISC_R_SUCCESS);
74 }
75
76 static inline isc_result_t
77 totext_in_nsap(ARGS_TOTEXT) {
78         isc_region_t region;
79         char buf[sizeof("xx")];
80
81         REQUIRE(rdata->type == 22);
82         REQUIRE(rdata->rdclass == 1);
83         REQUIRE(rdata->length != 0);
84
85         UNUSED(tctx);
86
87         dns_rdata_toregion(rdata, &region);
88         RETERR(str_totext("0x", target));
89         while (region.length != 0) {
90                 sprintf(buf, "%02x", region.base[0]);
91                 isc_region_consume(&region, 1);
92                 RETERR(str_totext(buf, target));
93         }
94         return (ISC_R_SUCCESS);
95 }
96
97 static inline isc_result_t
98 fromwire_in_nsap(ARGS_FROMWIRE) {
99         isc_region_t region;
100
101         REQUIRE(type == 22);
102         REQUIRE(rdclass == 1);
103
104         UNUSED(type);
105         UNUSED(dctx);
106         UNUSED(options);
107         UNUSED(rdclass);
108
109         isc_buffer_activeregion(source, &region);
110         if (region.length < 1)
111                 return (ISC_R_UNEXPECTEDEND);
112
113         RETERR(mem_tobuffer(target, region.base, region.length));
114         isc_buffer_forward(source, region.length);
115         return (ISC_R_SUCCESS);
116 }
117
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);
123
124         UNUSED(cctx);
125
126         return (mem_tobuffer(target, rdata->data, rdata->length));
127 }
128
129 static inline int
130 compare_in_nsap(ARGS_COMPARE) {
131         isc_region_t r1;
132         isc_region_t r2;
133
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);
140
141         dns_rdata_toregion(rdata1, &r1);
142         dns_rdata_toregion(rdata2, &r2);
143         return (isc_region_compare(&r1, &r2));
144 }
145
146 static inline isc_result_t
147 fromstruct_in_nsap(ARGS_FROMSTRUCT) {
148         dns_rdata_in_nsap_t *nsap = source;
149
150         REQUIRE(type == 22);
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);
156
157         UNUSED(type);
158         UNUSED(rdclass);
159
160         return (mem_tobuffer(target, nsap->nsap, nsap->nsap_len));
161 }
162
163 static inline isc_result_t
164 tostruct_in_nsap(ARGS_TOSTRUCT) {
165         dns_rdata_in_nsap_t *nsap = target;
166         isc_region_t r;
167
168         REQUIRE(rdata->type == 22);
169         REQUIRE(rdata->rdclass == 1);
170         REQUIRE(target != NULL);
171         REQUIRE(rdata->length != 0);
172
173         nsap->common.rdclass = rdata->rdclass;
174         nsap->common.rdtype = rdata->type;
175         ISC_LINK_INIT(&nsap->common, link);
176
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);
182
183         nsap->mctx = mctx;
184         return (ISC_R_SUCCESS);
185 }
186
187 static inline void
188 freestruct_in_nsap(ARGS_FREESTRUCT) {
189         dns_rdata_in_nsap_t *nsap = source;
190
191         REQUIRE(source != NULL);
192         REQUIRE(nsap->common.rdclass == 1);
193         REQUIRE(nsap->common.rdtype == 22);
194
195         if (nsap->mctx == NULL)
196                 return;
197
198         if (nsap->nsap != NULL)
199                 isc_mem_free(nsap->mctx, nsap->nsap);
200         nsap->mctx = NULL;
201 }
202
203 static inline isc_result_t
204 additionaldata_in_nsap(ARGS_ADDLDATA) {
205         REQUIRE(rdata->type == 22);
206         REQUIRE(rdata->rdclass == 1);
207
208         UNUSED(rdata);
209         UNUSED(add);
210         UNUSED(arg);
211
212         return (ISC_R_SUCCESS);
213 }
214
215 static inline isc_result_t
216 digest_in_nsap(ARGS_DIGEST) {
217         isc_region_t r;
218
219         REQUIRE(rdata->type == 22);
220         REQUIRE(rdata->rdclass == 1);
221
222         dns_rdata_toregion(rdata, &r);
223
224         return ((digest)(arg, &r));
225 }
226
227 static inline isc_boolean_t
228 checkowner_in_nsap(ARGS_CHECKOWNER) {
229
230         REQUIRE(type == 22);
231         REQUIRE(rdclass == 1);
232
233         UNUSED(name);
234         UNUSED(type);
235         UNUSED(rdclass);
236         UNUSED(wildcard);
237
238         return (ISC_TRUE);
239 }
240
241 static inline isc_boolean_t
242 checknames_in_nsap(ARGS_CHECKNAMES) {
243
244         REQUIRE(rdata->type == 22);
245         REQUIRE(rdata->rdclass == 1);
246
247         UNUSED(rdata);
248         UNUSED(owner);
249         UNUSED(bad);
250
251         return (ISC_TRUE);
252 }
253
254 static inline int
255 casecompare_in_nsap(ARGS_COMPARE) {
256         return (compare_in_nsap(rdata1, rdata2));
257 }
258
259 #endif  /* RDATA_IN_1_NSAP_22_C */