/src/bind9/lib/dns/rdata/generic/sink_40.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) Internet Systems Consortium, Inc. ("ISC") |
3 | | * |
4 | | * SPDX-License-Identifier: MPL-2.0 |
5 | | * |
6 | | * This Source Code Form is subject to the terms of the Mozilla Public |
7 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
8 | | * file, you can obtain one at https://mozilla.org/MPL/2.0/. |
9 | | * |
10 | | * See the COPYRIGHT file distributed with this work for additional |
11 | | * information regarding copyright ownership. |
12 | | */ |
13 | | |
14 | | #ifndef RDATA_GENERIC_SINK_40_C |
15 | | #define RDATA_GENERIC_SINK_40_C |
16 | | |
17 | | #include <dst/dst.h> |
18 | | |
19 | 12.2k | #define RRTYPE_SINK_ATTRIBUTES (0) |
20 | | |
21 | | static isc_result_t |
22 | 514 | fromtext_sink(ARGS_FROMTEXT) { |
23 | 514 | isc_token_t token; |
24 | | |
25 | 514 | REQUIRE(type == dns_rdatatype_sink); |
26 | | |
27 | 514 | UNUSED(type); |
28 | 514 | UNUSED(rdclass); |
29 | 514 | UNUSED(origin); |
30 | 514 | UNUSED(options); |
31 | 514 | UNUSED(callbacks); |
32 | | |
33 | | /* meaning */ |
34 | 514 | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
35 | 514 | false)); |
36 | 509 | if (token.value.as_ulong > 0xffU) { |
37 | 48 | RETTOK(ISC_R_RANGE); |
38 | 48 | } |
39 | 461 | RETERR(uint8_tobuffer(token.value.as_ulong, target)); |
40 | | |
41 | | /* coding */ |
42 | 461 | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
43 | 461 | false)); |
44 | 443 | if (token.value.as_ulong > 0xffU) { |
45 | 46 | RETTOK(ISC_R_RANGE); |
46 | 46 | } |
47 | 397 | RETERR(uint8_tobuffer(token.value.as_ulong, target)); |
48 | | |
49 | | /* subcoding */ |
50 | 397 | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
51 | 397 | false)); |
52 | 380 | if (token.value.as_ulong > 0xffU) { |
53 | 32 | RETTOK(ISC_R_RANGE); |
54 | 32 | } |
55 | 348 | RETERR(uint8_tobuffer(token.value.as_ulong, target)); |
56 | | |
57 | 348 | return isc_base64_tobuffer(lexer, target, -1); |
58 | 348 | } |
59 | | |
60 | | static isc_result_t |
61 | 1.46k | totext_sink(ARGS_TOTEXT) { |
62 | 1.46k | isc_region_t sr; |
63 | 1.46k | char buf[sizeof("255 255 255")]; |
64 | 1.46k | uint8_t meaning, coding, subcoding; |
65 | | |
66 | 1.46k | REQUIRE(rdata->type == dns_rdatatype_sink); |
67 | 1.46k | REQUIRE(rdata->length >= 3); |
68 | | |
69 | 1.46k | dns_rdata_toregion(rdata, &sr); |
70 | | |
71 | | /* Meaning, Coding and Subcoding */ |
72 | 1.46k | meaning = uint8_fromregion(&sr); |
73 | 1.46k | isc_region_consume(&sr, 1); |
74 | 1.46k | coding = uint8_fromregion(&sr); |
75 | 1.46k | isc_region_consume(&sr, 1); |
76 | 1.46k | subcoding = uint8_fromregion(&sr); |
77 | 1.46k | isc_region_consume(&sr, 1); |
78 | 1.46k | snprintf(buf, sizeof(buf), "%u %u %u", meaning, coding, subcoding); |
79 | 1.46k | RETERR(str_totext(buf, target)); |
80 | | |
81 | 1.46k | if (sr.length == 0U) { |
82 | 501 | return ISC_R_SUCCESS; |
83 | 501 | } |
84 | | |
85 | | /* data */ |
86 | 964 | if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { |
87 | 9 | RETERR(str_totext(" (", target)); |
88 | 9 | } |
89 | | |
90 | 964 | RETERR(str_totext(tctx->linebreak, target)); |
91 | | |
92 | 964 | if (tctx->width == 0) { /* No splitting */ |
93 | 0 | RETERR(isc_base64_totext(&sr, 60, "", target)); |
94 | 964 | } else { |
95 | 964 | RETERR(isc_base64_totext(&sr, tctx->width - 2, tctx->linebreak, |
96 | 964 | target)); |
97 | 964 | } |
98 | | |
99 | 964 | if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { |
100 | 9 | RETERR(str_totext(" )", target)); |
101 | 9 | } |
102 | | |
103 | 964 | return ISC_R_SUCCESS; |
104 | 964 | } |
105 | | |
106 | | static isc_result_t |
107 | 2.27k | fromwire_sink(ARGS_FROMWIRE) { |
108 | 2.27k | isc_region_t sr; |
109 | | |
110 | 2.27k | REQUIRE(type == dns_rdatatype_sink); |
111 | | |
112 | 2.27k | UNUSED(type); |
113 | 2.27k | UNUSED(rdclass); |
114 | 2.27k | UNUSED(dctx); |
115 | | |
116 | 2.27k | isc_buffer_activeregion(source, &sr); |
117 | 2.27k | if (sr.length < 3) { |
118 | 11 | return ISC_R_UNEXPECTEDEND; |
119 | 11 | } |
120 | | |
121 | 2.26k | RETERR(mem_tobuffer(target, sr.base, sr.length)); |
122 | 2.04k | isc_buffer_forward(source, sr.length); |
123 | 2.04k | return ISC_R_SUCCESS; |
124 | 2.26k | } |
125 | | |
126 | | static isc_result_t |
127 | 767 | towire_sink(ARGS_TOWIRE) { |
128 | 767 | REQUIRE(rdata->type == dns_rdatatype_sink); |
129 | 767 | REQUIRE(rdata->length >= 3); |
130 | | |
131 | 767 | UNUSED(cctx); |
132 | | |
133 | 767 | return mem_tobuffer(target, rdata->data, rdata->length); |
134 | 767 | } |
135 | | |
136 | | static int |
137 | 1.64k | compare_sink(ARGS_COMPARE) { |
138 | 1.64k | isc_region_t r1; |
139 | 1.64k | isc_region_t r2; |
140 | | |
141 | 1.64k | REQUIRE(rdata1->type == rdata2->type); |
142 | 1.64k | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
143 | 1.64k | REQUIRE(rdata1->type == dns_rdatatype_sink); |
144 | 1.64k | REQUIRE(rdata1->length >= 3); |
145 | 1.64k | REQUIRE(rdata2->length >= 3); |
146 | | |
147 | 1.64k | dns_rdata_toregion(rdata1, &r1); |
148 | 1.64k | dns_rdata_toregion(rdata2, &r2); |
149 | 1.64k | return isc_region_compare(&r1, &r2); |
150 | 1.64k | } |
151 | | |
152 | | static isc_result_t |
153 | 0 | fromstruct_sink(ARGS_FROMSTRUCT) { |
154 | 0 | dns_rdata_sink_t *sink = source; |
155 | |
|
156 | 0 | REQUIRE(type == dns_rdatatype_sink); |
157 | 0 | REQUIRE(sink != NULL); |
158 | 0 | REQUIRE(sink->common.rdtype == type); |
159 | 0 | REQUIRE(sink->common.rdclass == rdclass); |
160 | |
|
161 | 0 | UNUSED(type); |
162 | 0 | UNUSED(rdclass); |
163 | | |
164 | | /* Meaning */ |
165 | 0 | RETERR(uint8_tobuffer(sink->meaning, target)); |
166 | | |
167 | | /* Coding */ |
168 | 0 | RETERR(uint8_tobuffer(sink->coding, target)); |
169 | | |
170 | | /* Subcoding */ |
171 | 0 | RETERR(uint8_tobuffer(sink->subcoding, target)); |
172 | | |
173 | | /* Data */ |
174 | 0 | return mem_tobuffer(target, sink->data, sink->datalen); |
175 | 0 | } |
176 | | |
177 | | static isc_result_t |
178 | 0 | tostruct_sink(ARGS_TOSTRUCT) { |
179 | 0 | dns_rdata_sink_t *sink = target; |
180 | 0 | isc_region_t sr; |
181 | |
|
182 | 0 | REQUIRE(rdata->type == dns_rdatatype_sink); |
183 | 0 | REQUIRE(sink != NULL); |
184 | 0 | REQUIRE(rdata->length >= 3); |
185 | |
|
186 | 0 | sink->common.rdclass = rdata->rdclass; |
187 | 0 | sink->common.rdtype = rdata->type; |
188 | |
|
189 | 0 | dns_rdata_toregion(rdata, &sr); |
190 | | |
191 | | /* Meaning */ |
192 | 0 | sink->meaning = uint8_fromregion(&sr); |
193 | 0 | isc_region_consume(&sr, 1); |
194 | | |
195 | | /* Coding */ |
196 | 0 | sink->coding = uint8_fromregion(&sr); |
197 | 0 | isc_region_consume(&sr, 1); |
198 | | |
199 | | /* Subcoding */ |
200 | 0 | sink->subcoding = uint8_fromregion(&sr); |
201 | 0 | isc_region_consume(&sr, 1); |
202 | | |
203 | | /* Data */ |
204 | 0 | sink->datalen = sr.length; |
205 | 0 | sink->data = mem_maybedup(mctx, sr.base, sink->datalen); |
206 | 0 | sink->mctx = mctx; |
207 | 0 | return ISC_R_SUCCESS; |
208 | 0 | } |
209 | | |
210 | | static void |
211 | 0 | freestruct_sink(ARGS_FREESTRUCT) { |
212 | 0 | dns_rdata_sink_t *sink = (dns_rdata_sink_t *)source; |
213 | |
|
214 | 0 | REQUIRE(sink != NULL); |
215 | 0 | REQUIRE(sink->common.rdtype == dns_rdatatype_sink); |
216 | |
|
217 | 0 | if (sink->mctx == NULL) { |
218 | 0 | return; |
219 | 0 | } |
220 | | |
221 | 0 | if (sink->data != NULL) { |
222 | 0 | isc_mem_free(sink->mctx, sink->data); |
223 | 0 | } |
224 | 0 | sink->mctx = NULL; |
225 | 0 | } |
226 | | |
227 | | static isc_result_t |
228 | 0 | additionaldata_sink(ARGS_ADDLDATA) { |
229 | 0 | REQUIRE(rdata->type == dns_rdatatype_sink); |
230 | |
|
231 | 0 | UNUSED(rdata); |
232 | 0 | UNUSED(owner); |
233 | 0 | UNUSED(add); |
234 | 0 | UNUSED(arg); |
235 | |
|
236 | 0 | return ISC_R_SUCCESS; |
237 | 0 | } |
238 | | |
239 | | static isc_result_t |
240 | 0 | digest_sink(ARGS_DIGEST) { |
241 | 0 | isc_region_t r; |
242 | |
|
243 | 0 | REQUIRE(rdata->type == dns_rdatatype_sink); |
244 | |
|
245 | 0 | dns_rdata_toregion(rdata, &r); |
246 | |
|
247 | 0 | return (digest)(arg, &r); |
248 | 0 | } |
249 | | |
250 | | static bool |
251 | 0 | checkowner_sink(ARGS_CHECKOWNER) { |
252 | 0 | REQUIRE(type == dns_rdatatype_sink); |
253 | |
|
254 | 0 | UNUSED(name); |
255 | 0 | UNUSED(type); |
256 | 0 | UNUSED(rdclass); |
257 | 0 | UNUSED(wildcard); |
258 | |
|
259 | 0 | return true; |
260 | 0 | } |
261 | | |
262 | | static bool |
263 | 0 | checknames_sink(ARGS_CHECKNAMES) { |
264 | 0 | REQUIRE(rdata->type == dns_rdatatype_sink); |
265 | |
|
266 | 0 | UNUSED(rdata); |
267 | 0 | UNUSED(owner); |
268 | 0 | UNUSED(bad); |
269 | |
|
270 | 0 | return true; |
271 | 0 | } |
272 | | |
273 | | static int |
274 | 0 | casecompare_sink(ARGS_COMPARE) { |
275 | 0 | return compare_sink(rdata1, rdata2); |
276 | 0 | } |
277 | | #endif /* RDATA_GENERIC_SINK_40_C */ |