Merge from vendor branch LESS:
[dragonfly.git] / contrib / bind-9.3 / lib / dns / rdata / generic / dlv_65323.c
1 /*
2  * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14  * PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 /* $Id: dlv_65323.c,v 1.2.2.4 2004/03/16 12:38:14 marka Exp $ */
18
19 /* draft-ietf-dnsext-delegation-signer-05.txt */
20
21 #ifndef RDATA_GENERIC_DLV_65323_C
22 #define RDATA_GENERIC_DLV_65323_C
23
24 #define RRTYPE_DLV_ATTRIBUTES 0
25
26 static inline isc_result_t
27 fromtext_dlv(ARGS_FROMTEXT) {
28         isc_token_t token;
29
30         REQUIRE(type == 65323);
31
32         UNUSED(type);
33         UNUSED(rdclass);
34         UNUSED(origin);
35         UNUSED(options);
36         UNUSED(callbacks);
37
38         /*
39          * Key tag.
40          */
41         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
42                                       ISC_FALSE));
43         if (token.value.as_ulong > 0xffffU)
44                 RETTOK(ISC_R_RANGE);
45         RETERR(uint16_tobuffer(token.value.as_ulong, target));
46
47         /*
48          * Algorithm.
49          */
50         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
51                                       ISC_FALSE));
52         if (token.value.as_ulong > 0xffU)
53                 RETTOK(ISC_R_RANGE);
54         RETERR(uint8_tobuffer(token.value.as_ulong, target));
55
56         /*
57          * Digest type.
58          */
59         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
60                                       ISC_FALSE));
61         if (token.value.as_ulong > 0xffU)
62                 RETTOK(ISC_R_RANGE);
63         RETERR(uint8_tobuffer(token.value.as_ulong, target));
64         type = (isc_uint16_t) token.value.as_ulong;
65
66         /*
67          * Digest.
68          */
69         return (isc_hex_tobuffer(lexer, target, -1));
70 }
71
72 static inline isc_result_t
73 totext_dlv(ARGS_TOTEXT) {
74         isc_region_t sr;
75         char buf[sizeof("64000 ")];
76         unsigned int n;
77
78         REQUIRE(rdata->type == 65323);
79         REQUIRE(rdata->length != 0);
80
81         UNUSED(tctx);
82
83         dns_rdata_toregion(rdata, &sr);
84
85         /*
86          * Key tag.
87          */
88         n = uint16_fromregion(&sr);
89         isc_region_consume(&sr, 2);
90         sprintf(buf, "%u ", n);
91         RETERR(str_totext(buf, target));
92
93         /*
94          * Algorithm.
95          */
96         n = uint8_fromregion(&sr);
97         isc_region_consume(&sr, 1);
98         sprintf(buf, "%u ", n);
99         RETERR(str_totext(buf, target));
100
101         /*
102          * Digest type.
103          */
104         n = uint8_fromregion(&sr);
105         isc_region_consume(&sr, 1);
106         sprintf(buf, "%u", n);
107         RETERR(str_totext(buf, target));
108
109         /*
110          * Digest.
111          */
112         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
113                 RETERR(str_totext(" (", target));
114         RETERR(str_totext(tctx->linebreak, target));
115         RETERR(isc_hex_totext(&sr, tctx->width - 2, tctx->linebreak, target));
116         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
117                 RETERR(str_totext(" )", target));
118         return (ISC_R_SUCCESS);
119 }
120
121 static inline isc_result_t
122 fromwire_dlv(ARGS_FROMWIRE) {
123         isc_region_t sr;
124
125         REQUIRE(type == 65323);
126
127         UNUSED(type);
128         UNUSED(rdclass);
129         UNUSED(dctx);
130         UNUSED(options);
131
132         isc_buffer_activeregion(source, &sr);
133         if (sr.length < 4)
134                 return (ISC_R_UNEXPECTEDEND);
135
136         isc_buffer_forward(source, sr.length);
137         return (mem_tobuffer(target, sr.base, sr.length));
138 }
139
140 static inline isc_result_t
141 towire_dlv(ARGS_TOWIRE) {
142         isc_region_t sr;
143
144         REQUIRE(rdata->type == 65323);
145         REQUIRE(rdata->length != 0);
146
147         UNUSED(cctx);
148
149         dns_rdata_toregion(rdata, &sr);
150         return (mem_tobuffer(target, sr.base, sr.length));
151 }
152
153 static inline int
154 compare_dlv(ARGS_COMPARE) {
155         isc_region_t r1;
156         isc_region_t r2;
157
158         REQUIRE(rdata1->type == rdata2->type);
159         REQUIRE(rdata1->rdclass == rdata2->rdclass);
160         REQUIRE(rdata1->type == 65323);
161         REQUIRE(rdata1->length != 0);
162         REQUIRE(rdata2->length != 0);
163
164         dns_rdata_toregion(rdata1, &r1);
165         dns_rdata_toregion(rdata2, &r2);
166         return (isc_region_compare(&r1, &r2));
167 }
168
169 static inline isc_result_t
170 fromstruct_dlv(ARGS_FROMSTRUCT) {
171         dns_rdata_dlv_t *dlv = source;
172
173         REQUIRE(type == 65323);
174         REQUIRE(source != NULL);
175         REQUIRE(dlv->common.rdtype == type);
176         REQUIRE(dlv->common.rdclass == rdclass);
177
178         UNUSED(type);
179         UNUSED(rdclass);
180
181         RETERR(uint16_tobuffer(dlv->key_tag, target));
182         RETERR(uint8_tobuffer(dlv->algorithm, target));
183         RETERR(uint8_tobuffer(dlv->digest_type, target));
184
185         return (mem_tobuffer(target, dlv->digest, dlv->length));
186 }
187
188 static inline isc_result_t
189 tostruct_dlv(ARGS_TOSTRUCT) {
190         dns_rdata_dlv_t *dlv = target;
191         isc_region_t region;
192
193         REQUIRE(rdata->type == 65323);
194         REQUIRE(target != NULL);
195         REQUIRE(rdata->length != 0);
196
197         dlv->common.rdclass = rdata->rdclass;
198         dlv->common.rdtype = rdata->type;
199         ISC_LINK_INIT(&dlv->common, link);
200
201         dns_rdata_toregion(rdata, &region);
202
203         dlv->key_tag = uint16_fromregion(&region);
204         isc_region_consume(&region, 2);
205         dlv->algorithm = uint8_fromregion(&region);
206         isc_region_consume(&region, 1);
207         dlv->digest_type = uint8_fromregion(&region);
208         isc_region_consume(&region, 1);
209         dlv->length = region.length;
210
211         dlv->digest = mem_maybedup(mctx, region.base, region.length);
212         if (dlv->digest == NULL)
213                 return (ISC_R_NOMEMORY);
214
215         dlv->mctx = mctx;
216         return (ISC_R_SUCCESS);
217 }
218
219 static inline void
220 freestruct_dlv(ARGS_FREESTRUCT) {
221         dns_rdata_dlv_t *dlv = source;
222
223         REQUIRE(dlv != NULL);
224         REQUIRE(dlv->common.rdtype == 65323);
225
226         if (dlv->mctx == NULL)
227                 return;
228
229         if (dlv->digest != NULL)
230                 isc_mem_free(dlv->mctx, dlv->digest);
231         dlv->mctx = NULL;
232 }
233
234 static inline isc_result_t
235 additionaldata_dlv(ARGS_ADDLDATA) {
236         REQUIRE(rdata->type == 65323);
237
238         UNUSED(rdata);
239         UNUSED(add);
240         UNUSED(arg);
241
242         return (ISC_R_SUCCESS);
243 }
244
245 static inline isc_result_t
246 digest_dlv(ARGS_DIGEST) {
247         isc_region_t r;
248
249         REQUIRE(rdata->type == 65323);
250
251         dns_rdata_toregion(rdata, &r);
252
253         return ((digest)(arg, &r));
254 }
255
256 static inline isc_boolean_t
257 checkowner_dlv(ARGS_CHECKOWNER) {
258
259         REQUIRE(type == 65323);
260
261         UNUSED(name);
262         UNUSED(type);
263         UNUSED(rdclass);
264         UNUSED(wildcard);
265
266         return (ISC_TRUE);
267 }
268
269 static inline isc_boolean_t
270 checknames_dlv(ARGS_CHECKNAMES) {
271
272         REQUIRE(rdata->type == 65323);
273
274         UNUSED(rdata);
275         UNUSED(owner);
276         UNUSED(bad);
277
278         return (ISC_TRUE);
279 }
280
281 #endif  /* RDATA_GENERIC_DLV_65323_C */