/src/bind9/lib/dns/rdata/generic/sink_40.c
Line | Count | Source |
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 | 7.27k | #define RRTYPE_SINK_ATTRIBUTES (0) |
20 | | |
21 | | static isc_result_t |
22 | 4.17k | fromtext_sink(ARGS_FROMTEXT) { |
23 | 4.17k | isc_token_t token; |
24 | | |
25 | 4.17k | REQUIRE(type == dns_rdatatype_sink); |
26 | | |
27 | 4.17k | UNUSED(type); |
28 | 4.17k | UNUSED(rdclass); |
29 | 4.17k | UNUSED(origin); |
30 | 4.17k | UNUSED(options); |
31 | 4.17k | UNUSED(callbacks); |
32 | | |
33 | | /* meaning */ |
34 | 4.17k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
35 | 4.17k | false)); |
36 | 4.16k | if (token.value.as_ulong > 0xffU) { |
37 | 44 | RETTOK(ISC_R_RANGE); |
38 | 44 | } |
39 | 4.12k | RETERR(uint8_tobuffer(token.value.as_ulong, target)); |
40 | | |
41 | | /* coding */ |
42 | 4.12k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
43 | 4.12k | false)); |
44 | 4.10k | if (token.value.as_ulong > 0xffU) { |
45 | 33 | RETTOK(ISC_R_RANGE); |
46 | 33 | } |
47 | 4.07k | RETERR(uint8_tobuffer(token.value.as_ulong, target)); |
48 | | |
49 | | /* subcoding */ |
50 | 4.07k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
51 | 4.07k | false)); |
52 | 4.05k | if (token.value.as_ulong > 0xffU) { |
53 | 30 | RETTOK(ISC_R_RANGE); |
54 | 30 | } |
55 | 4.02k | RETERR(uint8_tobuffer(token.value.as_ulong, target)); |
56 | | |
57 | 4.02k | return isc_base64_tobuffer(lexer, target, isc_zero_or_more); |
58 | 4.02k | } |
59 | | |
60 | | static isc_result_t |
61 | 2.97k | totext_sink(ARGS_TOTEXT) { |
62 | 2.97k | isc_region_t sr; |
63 | 2.97k | char buf[sizeof("255 255 255")]; |
64 | 2.97k | uint8_t meaning, coding, subcoding; |
65 | | |
66 | 2.97k | REQUIRE(rdata->type == dns_rdatatype_sink); |
67 | 2.97k | REQUIRE(rdata->length >= 3); |
68 | | |
69 | 2.97k | dns_rdata_toregion(rdata, &sr); |
70 | | |
71 | | /* Meaning, Coding and Subcoding */ |
72 | 2.97k | meaning = uint8_fromregion(&sr); |
73 | 2.97k | isc_region_consume(&sr, 1); |
74 | 2.97k | coding = uint8_fromregion(&sr); |
75 | 2.97k | isc_region_consume(&sr, 1); |
76 | 2.97k | subcoding = uint8_fromregion(&sr); |
77 | 2.97k | isc_region_consume(&sr, 1); |
78 | 2.97k | snprintf(buf, sizeof(buf), "%u %u %u", meaning, coding, subcoding); |
79 | 2.97k | RETERR(str_totext(buf, target)); |
80 | | |
81 | 2.97k | if (sr.length == 0U) { |
82 | 1.73k | return ISC_R_SUCCESS; |
83 | 1.73k | } |
84 | | |
85 | | /* data */ |
86 | 1.23k | if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { |
87 | 22 | RETERR(str_totext(" (", target)); |
88 | 22 | } |
89 | | |
90 | 1.23k | RETERR(str_totext(tctx->linebreak, target)); |
91 | | |
92 | 1.23k | if (tctx->width == 0) { /* No splitting */ |
93 | 0 | RETERR(isc_base64_totext(&sr, 60, "", target)); |
94 | 1.23k | } else { |
95 | 1.23k | RETERR(isc_base64_totext(&sr, tctx->width - 2, tctx->linebreak, |
96 | 1.23k | target)); |
97 | 1.23k | } |
98 | | |
99 | 1.23k | if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { |
100 | 22 | RETERR(str_totext(" )", target)); |
101 | 22 | } |
102 | | |
103 | 1.23k | return ISC_R_SUCCESS; |
104 | 1.23k | } |
105 | | |
106 | | static isc_result_t |
107 | 3.62k | fromwire_sink(ARGS_FROMWIRE) { |
108 | 3.62k | isc_region_t sr; |
109 | | |
110 | 3.62k | REQUIRE(type == dns_rdatatype_sink); |
111 | | |
112 | 3.62k | UNUSED(type); |
113 | 3.62k | UNUSED(rdclass); |
114 | 3.62k | UNUSED(dctx); |
115 | | |
116 | 3.62k | isc_buffer_activeregion(source, &sr); |
117 | 3.62k | if (sr.length < 3) { |
118 | 11 | return ISC_R_UNEXPECTEDEND; |
119 | 11 | } |
120 | | |
121 | 3.61k | RETERR(mem_tobuffer(target, sr.base, sr.length)); |
122 | 3.52k | isc_buffer_forward(source, sr.length); |
123 | 3.52k | return ISC_R_SUCCESS; |
124 | 3.61k | } |
125 | | |
126 | | static int |
127 | 140k | compare_sink(ARGS_COMPARE) { |
128 | 140k | isc_region_t r1; |
129 | 140k | isc_region_t r2; |
130 | | |
131 | 140k | REQUIRE(rdata1->type == rdata2->type); |
132 | 140k | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
133 | 140k | REQUIRE(rdata1->type == dns_rdatatype_sink); |
134 | 140k | REQUIRE(rdata1->length >= 3); |
135 | 140k | REQUIRE(rdata2->length >= 3); |
136 | | |
137 | 140k | dns_rdata_toregion(rdata1, &r1); |
138 | 140k | dns_rdata_toregion(rdata2, &r2); |
139 | 140k | return isc_region_compare(&r1, &r2); |
140 | 140k | } |
141 | | |
142 | | static isc_result_t |
143 | 0 | fromstruct_sink(ARGS_FROMSTRUCT) { |
144 | 0 | dns_rdata_sink_t *sink = source; |
145 | |
|
146 | 0 | REQUIRE(type == dns_rdatatype_sink); |
147 | 0 | REQUIRE(sink != NULL); |
148 | 0 | REQUIRE(sink->common.rdtype == type); |
149 | 0 | REQUIRE(sink->common.rdclass == rdclass); |
150 | |
|
151 | 0 | UNUSED(type); |
152 | 0 | UNUSED(rdclass); |
153 | | |
154 | | /* Meaning */ |
155 | 0 | RETERR(uint8_tobuffer(sink->meaning, target)); |
156 | | |
157 | | /* Coding */ |
158 | 0 | RETERR(uint8_tobuffer(sink->coding, target)); |
159 | | |
160 | | /* Subcoding */ |
161 | 0 | RETERR(uint8_tobuffer(sink->subcoding, target)); |
162 | | |
163 | | /* Data */ |
164 | 0 | return mem_tobuffer(target, sink->data, sink->datalen); |
165 | 0 | } |
166 | | |
167 | | static isc_result_t |
168 | 0 | tostruct_sink(ARGS_TOSTRUCT) { |
169 | 0 | dns_rdata_sink_t *sink = target; |
170 | 0 | isc_region_t sr; |
171 | |
|
172 | 0 | REQUIRE(rdata->type == dns_rdatatype_sink); |
173 | 0 | REQUIRE(sink != NULL); |
174 | 0 | REQUIRE(rdata->length >= 3); |
175 | |
|
176 | 0 | DNS_RDATACOMMON_INIT(sink, rdata->type, rdata->rdclass); |
177 | |
|
178 | 0 | dns_rdata_toregion(rdata, &sr); |
179 | | |
180 | | /* Meaning */ |
181 | 0 | sink->meaning = uint8_fromregion(&sr); |
182 | 0 | isc_region_consume(&sr, 1); |
183 | | |
184 | | /* Coding */ |
185 | 0 | sink->coding = uint8_fromregion(&sr); |
186 | 0 | isc_region_consume(&sr, 1); |
187 | | |
188 | | /* Subcoding */ |
189 | 0 | sink->subcoding = uint8_fromregion(&sr); |
190 | 0 | isc_region_consume(&sr, 1); |
191 | | |
192 | | /* Data */ |
193 | 0 | sink->datalen = sr.length; |
194 | 0 | sink->data = sr.base; |
195 | 0 | return ISC_R_SUCCESS; |
196 | 0 | } |
197 | | |
198 | | static isc_result_t |
199 | 0 | additionaldata_sink(ARGS_ADDLDATA) { |
200 | 0 | REQUIRE(rdata->type == dns_rdatatype_sink); |
201 | |
|
202 | 0 | UNUSED(rdata); |
203 | 0 | UNUSED(owner); |
204 | 0 | UNUSED(add); |
205 | 0 | UNUSED(arg); |
206 | |
|
207 | 0 | return ISC_R_SUCCESS; |
208 | 0 | } |
209 | | |
210 | | static isc_result_t |
211 | 0 | digest_sink(ARGS_DIGEST) { |
212 | 0 | isc_region_t r; |
213 | |
|
214 | 0 | REQUIRE(rdata->type == dns_rdatatype_sink); |
215 | |
|
216 | 0 | dns_rdata_toregion(rdata, &r); |
217 | |
|
218 | 0 | return (digest)(arg, &r); |
219 | 0 | } |
220 | | |
221 | | static bool |
222 | 0 | checkowner_sink(ARGS_CHECKOWNER) { |
223 | 0 | REQUIRE(type == dns_rdatatype_sink); |
224 | |
|
225 | 0 | UNUSED(name); |
226 | 0 | UNUSED(type); |
227 | 0 | UNUSED(rdclass); |
228 | 0 | UNUSED(wildcard); |
229 | |
|
230 | 0 | return true; |
231 | 0 | } |
232 | | |
233 | | static bool |
234 | 0 | checknames_sink(ARGS_CHECKNAMES) { |
235 | 0 | REQUIRE(rdata->type == dns_rdatatype_sink); |
236 | |
|
237 | 0 | UNUSED(rdata); |
238 | 0 | UNUSED(owner); |
239 | 0 | UNUSED(bad); |
240 | |
|
241 | 0 | return true; |
242 | 0 | } |
243 | | |
244 | | static int |
245 | 0 | casecompare_sink(ARGS_COMPARE) { |
246 | 0 | return compare_sink(rdata1, rdata2); |
247 | 0 | } |
248 | | #endif /* RDATA_GENERIC_SINK_40_C */ |