/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 | 142k | #define RRTYPE_SINK_ATTRIBUTES (0) |
20 | | |
21 | | static isc_result_t |
22 | 880 | fromtext_sink(ARGS_FROMTEXT) { |
23 | 880 | isc_token_t token; |
24 | | |
25 | 880 | REQUIRE(type == dns_rdatatype_sink); |
26 | | |
27 | 880 | UNUSED(type); |
28 | 880 | UNUSED(rdclass); |
29 | 880 | UNUSED(origin); |
30 | 880 | UNUSED(options); |
31 | 880 | UNUSED(callbacks); |
32 | | |
33 | | /* meaning */ |
34 | 880 | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
35 | 880 | false)); |
36 | 874 | if (token.value.as_ulong > 0xffU) { |
37 | 25 | RETTOK(ISC_R_RANGE); |
38 | 25 | } |
39 | 849 | RETERR(uint8_tobuffer(token.value.as_ulong, target)); |
40 | | |
41 | | /* coding */ |
42 | 849 | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
43 | 849 | false)); |
44 | 844 | if (token.value.as_ulong > 0xffU) { |
45 | 29 | RETTOK(ISC_R_RANGE); |
46 | 29 | } |
47 | 815 | RETERR(uint8_tobuffer(token.value.as_ulong, target)); |
48 | | |
49 | | /* subcoding */ |
50 | 815 | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
51 | 815 | false)); |
52 | 809 | if (token.value.as_ulong > 0xffU) { |
53 | 15 | RETTOK(ISC_R_RANGE); |
54 | 15 | } |
55 | 794 | RETERR(uint8_tobuffer(token.value.as_ulong, target)); |
56 | | |
57 | 794 | return (isc_base64_tobuffer(lexer, target, -1)); |
58 | 794 | } |
59 | | |
60 | | static isc_result_t |
61 | 1.39k | totext_sink(ARGS_TOTEXT) { |
62 | 1.39k | isc_region_t sr; |
63 | 1.39k | char buf[sizeof("255 255 255")]; |
64 | 1.39k | uint8_t meaning, coding, subcoding; |
65 | | |
66 | 1.39k | REQUIRE(rdata->type == dns_rdatatype_sink); |
67 | 1.39k | REQUIRE(rdata->length >= 3); |
68 | | |
69 | 1.39k | dns_rdata_toregion(rdata, &sr); |
70 | | |
71 | | /* Meaning, Coding and Subcoding */ |
72 | 1.39k | meaning = uint8_fromregion(&sr); |
73 | 1.39k | isc_region_consume(&sr, 1); |
74 | 1.39k | coding = uint8_fromregion(&sr); |
75 | 1.39k | isc_region_consume(&sr, 1); |
76 | 1.39k | subcoding = uint8_fromregion(&sr); |
77 | 1.39k | isc_region_consume(&sr, 1); |
78 | 1.39k | snprintf(buf, sizeof(buf), "%u %u %u", meaning, coding, subcoding); |
79 | 1.39k | RETERR(str_totext(buf, target)); |
80 | | |
81 | 1.39k | if (sr.length == 0U) { |
82 | 787 | return (ISC_R_SUCCESS); |
83 | 787 | } |
84 | | |
85 | | /* data */ |
86 | 608 | if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { |
87 | 23 | RETERR(str_totext(" (", target)); |
88 | 23 | } |
89 | | |
90 | 608 | RETERR(str_totext(tctx->linebreak, target)); |
91 | | |
92 | 608 | if (tctx->width == 0) { /* No splitting */ |
93 | 0 | RETERR(isc_base64_totext(&sr, 60, "", target)); |
94 | 608 | } else { |
95 | 608 | RETERR(isc_base64_totext(&sr, tctx->width - 2, tctx->linebreak, |
96 | 608 | target)); |
97 | 608 | } |
98 | | |
99 | 608 | if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { |
100 | 23 | RETERR(str_totext(" )", target)); |
101 | 23 | } |
102 | | |
103 | 608 | return (ISC_R_SUCCESS); |
104 | 608 | } |
105 | | |
106 | | static isc_result_t |
107 | 67.2k | fromwire_sink(ARGS_FROMWIRE) { |
108 | 67.2k | isc_region_t sr; |
109 | | |
110 | 67.2k | REQUIRE(type == dns_rdatatype_sink); |
111 | | |
112 | 67.2k | UNUSED(type); |
113 | 67.2k | UNUSED(rdclass); |
114 | 67.2k | UNUSED(dctx); |
115 | | |
116 | 67.2k | isc_buffer_activeregion(source, &sr); |
117 | 67.2k | if (sr.length < 3) { |
118 | 11 | return (ISC_R_UNEXPECTEDEND); |
119 | 11 | } |
120 | | |
121 | 67.2k | RETERR(mem_tobuffer(target, sr.base, sr.length)); |
122 | 67.1k | isc_buffer_forward(source, sr.length); |
123 | 67.1k | return (ISC_R_SUCCESS); |
124 | 67.2k | } |
125 | | |
126 | | static isc_result_t |
127 | 709 | towire_sink(ARGS_TOWIRE) { |
128 | 709 | REQUIRE(rdata->type == dns_rdatatype_sink); |
129 | 709 | REQUIRE(rdata->length >= 3); |
130 | | |
131 | 709 | UNUSED(cctx); |
132 | | |
133 | 709 | return (mem_tobuffer(target, rdata->data, rdata->length)); |
134 | 709 | } |
135 | | |
136 | | static int |
137 | 267k | compare_sink(ARGS_COMPARE) { |
138 | 267k | isc_region_t r1; |
139 | 267k | isc_region_t r2; |
140 | | |
141 | 267k | REQUIRE(rdata1->type == rdata2->type); |
142 | 267k | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
143 | 267k | REQUIRE(rdata1->type == dns_rdatatype_sink); |
144 | 267k | REQUIRE(rdata1->length >= 3); |
145 | 267k | REQUIRE(rdata2->length >= 3); |
146 | | |
147 | 267k | dns_rdata_toregion(rdata1, &r1); |
148 | 267k | dns_rdata_toregion(rdata2, &r2); |
149 | 267k | return (isc_region_compare(&r1, &r2)); |
150 | 267k | } |
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 | 0 | ISC_LINK_INIT(&sink->common, link); |
189 | |
|
190 | 0 | dns_rdata_toregion(rdata, &sr); |
191 | | |
192 | | /* Meaning */ |
193 | 0 | sink->meaning = uint8_fromregion(&sr); |
194 | 0 | isc_region_consume(&sr, 1); |
195 | | |
196 | | /* Coding */ |
197 | 0 | sink->coding = uint8_fromregion(&sr); |
198 | 0 | isc_region_consume(&sr, 1); |
199 | | |
200 | | /* Subcoding */ |
201 | 0 | sink->subcoding = uint8_fromregion(&sr); |
202 | 0 | isc_region_consume(&sr, 1); |
203 | | |
204 | | /* Data */ |
205 | 0 | sink->datalen = sr.length; |
206 | 0 | sink->data = mem_maybedup(mctx, sr.base, sink->datalen); |
207 | 0 | sink->mctx = mctx; |
208 | 0 | return (ISC_R_SUCCESS); |
209 | 0 | } |
210 | | |
211 | | static void |
212 | 0 | freestruct_sink(ARGS_FREESTRUCT) { |
213 | 0 | dns_rdata_sink_t *sink = (dns_rdata_sink_t *)source; |
214 | |
|
215 | 0 | REQUIRE(sink != NULL); |
216 | 0 | REQUIRE(sink->common.rdtype == dns_rdatatype_sink); |
217 | |
|
218 | 0 | if (sink->mctx == NULL) { |
219 | 0 | return; |
220 | 0 | } |
221 | | |
222 | 0 | if (sink->data != NULL) { |
223 | 0 | isc_mem_free(sink->mctx, sink->data); |
224 | 0 | } |
225 | 0 | sink->mctx = NULL; |
226 | 0 | } |
227 | | |
228 | | static isc_result_t |
229 | 0 | additionaldata_sink(ARGS_ADDLDATA) { |
230 | 0 | REQUIRE(rdata->type == dns_rdatatype_sink); |
231 | |
|
232 | 0 | UNUSED(rdata); |
233 | 0 | UNUSED(owner); |
234 | 0 | UNUSED(add); |
235 | 0 | UNUSED(arg); |
236 | |
|
237 | 0 | return (ISC_R_SUCCESS); |
238 | 0 | } |
239 | | |
240 | | static isc_result_t |
241 | 0 | digest_sink(ARGS_DIGEST) { |
242 | 0 | isc_region_t r; |
243 | |
|
244 | 0 | REQUIRE(rdata->type == dns_rdatatype_sink); |
245 | |
|
246 | 0 | dns_rdata_toregion(rdata, &r); |
247 | |
|
248 | 0 | return ((digest)(arg, &r)); |
249 | 0 | } |
250 | | |
251 | | static bool |
252 | 0 | checkowner_sink(ARGS_CHECKOWNER) { |
253 | 0 | REQUIRE(type == dns_rdatatype_sink); |
254 | |
|
255 | 0 | UNUSED(name); |
256 | 0 | UNUSED(type); |
257 | 0 | UNUSED(rdclass); |
258 | 0 | UNUSED(wildcard); |
259 | |
|
260 | 0 | return (true); |
261 | 0 | } |
262 | | |
263 | | static bool |
264 | 0 | checknames_sink(ARGS_CHECKNAMES) { |
265 | 0 | REQUIRE(rdata->type == dns_rdatatype_sink); |
266 | |
|
267 | 0 | UNUSED(rdata); |
268 | 0 | UNUSED(owner); |
269 | 0 | UNUSED(bad); |
270 | |
|
271 | 0 | return (true); |
272 | 0 | } |
273 | | |
274 | | static int |
275 | 0 | casecompare_sink(ARGS_COMPARE) { |
276 | 0 | return (compare_sink(rdata1, rdata2)); |
277 | 0 | } |
278 | | #endif /* RDATA_GENERIC_SINK_40_C */ |