]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/bind9/lib/dns/rdata/generic/sink_40.c
MFV r306384:
[FreeBSD/stable/9.git] / contrib / bind9 / lib / dns / rdata / generic / sink_40.c
1 /*
2  * Copyright (C) 2015  Internet Systems Consortium, Inc. ("ISC")
3  *
4  * Permission to use, copy, modify, and/or 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 #ifndef RDATA_GENERIC_SINK_40_C
18 #define RDATA_GENERIC_SINK_40_C
19
20 #include <dst/dst.h>
21
22 #define RRTYPE_SINK_ATTRIBUTES (0)
23
24 static inline isc_result_t
25 fromtext_sink(ARGS_FROMTEXT) {
26         isc_token_t token;
27
28         REQUIRE(type == dns_rdatatype_sink);
29
30         UNUSED(type);
31         UNUSED(rdclass);
32         UNUSED(origin);
33         UNUSED(options);
34         UNUSED(callbacks);
35
36         /* meaning */
37         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
38                                       ISC_FALSE));
39         if (token.value.as_ulong > 0xffU)
40                 RETTOK(ISC_R_RANGE);
41         RETERR(uint8_tobuffer(token.value.as_ulong, target));
42
43         /* coding */
44         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
45                                       ISC_FALSE));
46         if (token.value.as_ulong > 0xffU)
47                 RETTOK(ISC_R_RANGE);
48         RETERR(uint8_tobuffer(token.value.as_ulong, target));
49
50         /* subcoding */
51         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
52                                       ISC_FALSE));
53         if (token.value.as_ulong > 0xffU)
54                 RETTOK(ISC_R_RANGE);
55         RETERR(uint8_tobuffer(token.value.as_ulong, target));
56
57         return(isc_base64_tobuffer(lexer, target, -1));
58 }
59
60 static inline isc_result_t
61 totext_sink(ARGS_TOTEXT) {
62         isc_region_t sr;
63         char buf[sizeof("255 255 255")];
64         isc_uint8_t meaning, coding, subcoding;
65
66         REQUIRE(rdata->type == dns_rdatatype_sink);
67         REQUIRE(rdata->length >= 3);
68
69         dns_rdata_toregion(rdata, &sr);
70
71         /* Meaning, Coding and Subcoding */
72         meaning = uint8_fromregion(&sr);
73         isc_region_consume(&sr, 1);
74         coding = uint8_fromregion(&sr);
75         isc_region_consume(&sr, 1);
76         subcoding = uint8_fromregion(&sr);
77         isc_region_consume(&sr, 1);
78         sprintf(buf, "%u %u %u", meaning, coding, subcoding);
79         RETERR(str_totext(buf, target));
80
81         if (sr.length == 0U)
82                 return (ISC_R_SUCCESS);
83
84         /* data */
85         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
86                 RETERR(str_totext(" (", target));
87
88         RETERR(str_totext(tctx->linebreak, target));
89
90         if (tctx->width == 0)   /* No splitting */
91                 RETERR(isc_base64_totext(&sr, 60, "", target));
92         else
93                 RETERR(isc_base64_totext(&sr, tctx->width - 2,
94                                          tctx->linebreak, target));
95
96         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
97                 RETERR(str_totext(" )", target));
98
99         return (ISC_R_SUCCESS);
100 }
101
102 static inline isc_result_t
103 fromwire_sink(ARGS_FROMWIRE) {
104         isc_region_t sr;
105
106         REQUIRE(type == dns_rdatatype_sink);
107
108         UNUSED(type);
109         UNUSED(rdclass);
110         UNUSED(dctx);
111         UNUSED(options);
112
113         isc_buffer_activeregion(source, &sr);
114         if (sr.length < 3)
115                 return (ISC_R_UNEXPECTEDEND);
116
117         RETERR(mem_tobuffer(target, sr.base, sr.length));
118         isc_buffer_forward(source, sr.length);
119         return (ISC_R_SUCCESS);
120 }
121
122 static inline isc_result_t
123 towire_sink(ARGS_TOWIRE) {
124
125         REQUIRE(rdata->type == dns_rdatatype_sink);
126         REQUIRE(rdata->length >= 3);
127
128         UNUSED(cctx);
129
130         return (mem_tobuffer(target, rdata->data, rdata->length));
131 }
132
133 static inline int
134 compare_sink(ARGS_COMPARE) {
135         isc_region_t r1;
136         isc_region_t r2;
137
138         REQUIRE(rdata1->type == rdata2->type);
139         REQUIRE(rdata1->rdclass == rdata2->rdclass);
140         REQUIRE(rdata1->type == dns_rdatatype_sink);
141         REQUIRE(rdata1->length >= 3);
142         REQUIRE(rdata2->length >= 3);
143
144         dns_rdata_toregion(rdata1, &r1);
145         dns_rdata_toregion(rdata2, &r2);
146         return (isc_region_compare(&r1, &r2));
147 }
148
149 static inline isc_result_t
150 fromstruct_sink(ARGS_FROMSTRUCT) {
151         dns_rdata_sink_t *sink = source;
152
153         REQUIRE(type == dns_rdatatype_sink);
154         REQUIRE(source != NULL);
155         REQUIRE(sink->common.rdtype == type);
156         REQUIRE(sink->common.rdclass == rdclass);
157
158         UNUSED(type);
159         UNUSED(rdclass);
160
161         /* Meaning */
162         RETERR(uint8_tobuffer(sink->meaning, target));
163
164         /* Coding */
165         RETERR(uint8_tobuffer(sink->coding, target));
166
167         /* Subcoding */
168         RETERR(uint8_tobuffer(sink->subcoding, target));
169
170         /* Data */
171         return (mem_tobuffer(target, sink->data, sink->datalen));
172 }
173
174 static inline isc_result_t
175 tostruct_sink(ARGS_TOSTRUCT) {
176         dns_rdata_sink_t *sink = target;
177         isc_region_t sr;
178
179         REQUIRE(rdata->type == dns_rdatatype_sink);
180         REQUIRE(target != NULL);
181         REQUIRE(rdata->length >= 3);
182
183         sink->common.rdclass = rdata->rdclass;
184         sink->common.rdtype = rdata->type;
185         ISC_LINK_INIT(&sink->common, link);
186
187         dns_rdata_toregion(rdata, &sr);
188
189         /* Meaning */
190         if (sr.length < 1)
191                 return (ISC_R_UNEXPECTEDEND);
192         sink->meaning = uint8_fromregion(&sr);
193         isc_region_consume(&sr, 1);
194
195         /* Coding */
196         if (sr.length < 1)
197                 return (ISC_R_UNEXPECTEDEND);
198         sink->coding = uint8_fromregion(&sr);
199         isc_region_consume(&sr, 1);
200
201         /* Subcoding */
202         if (sr.length < 1)
203                 return (ISC_R_UNEXPECTEDEND);
204         sink->subcoding = uint8_fromregion(&sr);
205         isc_region_consume(&sr, 1);
206
207         /* Data */
208         sink->datalen = sr.length;
209         sink->data = mem_maybedup(mctx, sr.base, sink->datalen);
210         if (sink->data == NULL)
211                 return (ISC_R_NOMEMORY);
212
213         sink->mctx = mctx;
214         return (ISC_R_SUCCESS);
215 }
216
217 static inline void
218 freestruct_sink(ARGS_FREESTRUCT) {
219         dns_rdata_sink_t *sink = (dns_rdata_sink_t *) source;
220
221         REQUIRE(source != NULL);
222         REQUIRE(sink->common.rdtype == dns_rdatatype_sink);
223
224         if (sink->mctx == NULL)
225                 return;
226
227         if (sink->data != NULL)
228                 isc_mem_free(sink->mctx, sink->data);
229         sink->mctx = NULL;
230 }
231
232 static inline isc_result_t
233 additionaldata_sink(ARGS_ADDLDATA) {
234         REQUIRE(rdata->type == dns_rdatatype_sink);
235
236         UNUSED(rdata);
237         UNUSED(add);
238         UNUSED(arg);
239
240         return (ISC_R_SUCCESS);
241 }
242
243 static inline isc_result_t
244 digest_sink(ARGS_DIGEST) {
245         isc_region_t r;
246
247         REQUIRE(rdata->type == dns_rdatatype_sink);
248
249         dns_rdata_toregion(rdata, &r);
250
251         return ((digest)(arg, &r));
252 }
253
254 static inline isc_boolean_t
255 checkowner_sink(ARGS_CHECKOWNER) {
256
257         REQUIRE(type == dns_rdatatype_sink);
258
259         UNUSED(name);
260         UNUSED(type);
261         UNUSED(rdclass);
262         UNUSED(wildcard);
263
264         return (ISC_TRUE);
265 }
266
267 static inline isc_boolean_t
268 checknames_sink(ARGS_CHECKNAMES) {
269
270         REQUIRE(rdata->type == dns_rdatatype_sink);
271
272         UNUSED(rdata);
273         UNUSED(owner);
274         UNUSED(bad);
275
276         return (ISC_TRUE);
277 }
278
279 static inline int
280 casecompare_sink(ARGS_COMPARE) {
281         return (compare_sink(rdata1, rdata2));
282 }
283 #endif  /* RDATA_GENERIC_SINK_40_C */