Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / generic / caa_257.c
blob19689d9c855af7d2b30e3ddd85d0505c1fd1fddb
1 /* $NetBSD: caa_257.c,v 1.1.1.3 2014/12/10 03:34:42 christos Exp $ */
3 /*
4 * Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
19 #ifndef GENERIC_CAA_257_C
20 #define GENERIC_CAA_257_C 1
22 #define RRTYPE_CAA_ATTRIBUTES (0)
24 static unsigned char const alphanumeric[256] = {
25 /* 0x00-0x0f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
26 /* 0x10-0x1f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
27 /* 0x20-0x2f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
28 /* 0x30-0x3f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
29 /* 0x40-0x4f */ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
30 /* 0x50-0x5f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
31 /* 0x60-0x6f */ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
32 /* 0x70-0x7f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
33 /* 0x80-0x8f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
34 /* 0x90-0x9f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
35 /* 0xa0-0xaf */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
36 /* 0xb0-0xbf */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
37 /* 0xc0-0xcf */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
38 /* 0xd0-0xdf */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
39 /* 0xe0-0xef */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
40 /* 0xf0-0xff */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43 static inline isc_result_t
44 fromtext_caa(ARGS_FROMTEXT) {
45 isc_token_t token;
46 isc_textregion_t tr;
47 isc_uint8_t flags;
48 unsigned int i;
50 REQUIRE(type == 257);
52 UNUSED(type);
53 UNUSED(rdclass);
54 UNUSED(origin);
55 UNUSED(options);
56 UNUSED(callbacks);
58 /* Flags. */
59 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
60 ISC_FALSE));
61 if (token.value.as_ulong > 255U)
62 RETTOK(ISC_R_RANGE);
63 flags = token.value.as_ulong;
64 RETERR(uint8_tobuffer(flags, target));
67 * Tag
69 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
70 ISC_FALSE));
71 tr = token.value.as_textregion;
72 for (i = 0; i < tr.length; i++)
73 if (!alphanumeric[(unsigned int) tr.base[i]])
74 RETTOK(DNS_R_SYNTAX);
75 RETERR(uint8_tobuffer(tr.length, target));
76 RETERR(mem_tobuffer(target, tr.base, tr.length));
79 * Value
81 RETERR(isc_lex_getmastertoken(lexer, &token,
82 isc_tokentype_qstring, ISC_FALSE));
83 if (token.type != isc_tokentype_qstring &&
84 token.type != isc_tokentype_string)
85 RETERR(DNS_R_SYNTAX);
86 RETERR(multitxt_fromtext(&token.value.as_textregion, target));
87 return (ISC_R_SUCCESS);
90 static inline isc_result_t
91 totext_caa(ARGS_TOTEXT) {
92 isc_region_t region;
93 isc_uint8_t flags;
94 char buf[256];
96 UNUSED(tctx);
98 REQUIRE(rdata->type == 257);
99 REQUIRE(rdata->length >= 3U);
100 REQUIRE(rdata->data != NULL);
102 dns_rdata_toregion(rdata, &region);
105 * Flags
107 flags = uint8_consume_fromregion(&region);
108 sprintf(buf, "%u ", flags);
109 RETERR(str_totext(buf, target));
112 * Tag
114 RETERR(txt_totext(&region, ISC_FALSE, target));
115 RETERR(str_totext(" ", target));
118 * Value
120 RETERR(multitxt_totext(&region, target));
121 return (ISC_R_SUCCESS);
124 static inline isc_result_t
125 fromwire_caa(ARGS_FROMWIRE) {
126 isc_region_t sr;
127 unsigned int len, i;
129 REQUIRE(type == 257);
131 UNUSED(type);
132 UNUSED(rdclass);
133 UNUSED(dctx);
134 UNUSED(options);
137 * Flags
139 isc_buffer_activeregion(source, &sr);
140 if (sr.length < 2)
141 return (ISC_R_UNEXPECTEDEND);
144 * Flags, tag length
146 RETERR(mem_tobuffer(target, sr.base, 2));
147 len = sr.base[1];
148 isc_region_consume(&sr, 2);
149 isc_buffer_forward(source, 2);
152 * Zero length tag fields are illegal.
154 if (sr.length < len || len == 0)
155 RETERR(DNS_R_FORMERR);
157 /* Check the Tag's value */
158 for (i = 0; i < len; i++)
159 if (!alphanumeric[sr.base[i]])
160 RETERR(DNS_R_FORMERR);
162 * Tag + Value
164 isc_buffer_forward(source, sr.length);
165 return (mem_tobuffer(target, sr.base, sr.length));
168 static inline isc_result_t
169 towire_caa(ARGS_TOWIRE) {
170 isc_region_t region;
172 REQUIRE(rdata->type == 257);
173 REQUIRE(rdata->length >= 3U);
174 REQUIRE(rdata->data != NULL);
176 UNUSED(cctx);
178 dns_rdata_toregion(rdata, &region);
179 return (mem_tobuffer(target, region.base, region.length));
182 static inline int
183 compare_caa(ARGS_COMPARE) {
184 isc_region_t r1, r2;
186 REQUIRE(rdata1->type == rdata2->type);
187 REQUIRE(rdata1->rdclass == rdata2->rdclass);
188 REQUIRE(rdata1->type == 257);
189 REQUIRE(rdata1->length >= 3U);
190 REQUIRE(rdata2->length >= 3U);
191 REQUIRE(rdata1->data != NULL);
192 REQUIRE(rdata2->data != NULL);
194 dns_rdata_toregion(rdata1, &r1);
195 dns_rdata_toregion(rdata2, &r2);
196 return (isc_region_compare(&r1, &r2));
199 static inline isc_result_t
200 fromstruct_caa(ARGS_FROMSTRUCT) {
201 dns_rdata_caa_t *caa = source;
202 isc_region_t region;
203 unsigned int i;
205 REQUIRE(type == 257);
206 REQUIRE(source != NULL);
207 REQUIRE(caa->common.rdtype == type);
208 REQUIRE(caa->common.rdclass == rdclass);
209 REQUIRE(caa->tag != NULL && caa->tag_len != 0);
210 REQUIRE(caa->value != NULL);
212 UNUSED(type);
213 UNUSED(rdclass);
216 * Flags
218 RETERR(uint8_tobuffer(caa->flags, target));
221 * Tag length
223 RETERR(uint8_tobuffer(caa->tag_len, target));
226 * Tag
228 region.base = caa->tag;
229 region.length = caa->tag_len;
230 for (i = 0; i < region.length; i++)
231 if (!alphanumeric[region.base[i]])
232 RETERR(DNS_R_SYNTAX);
233 RETERR(isc_buffer_copyregion(target, &region));
236 * Value
238 region.base = caa->value;
239 region.length = caa->value_len;
240 return (isc_buffer_copyregion(target, &region));
243 static inline isc_result_t
244 tostruct_caa(ARGS_TOSTRUCT) {
245 dns_rdata_caa_t *caa = target;
246 isc_region_t sr;
248 REQUIRE(rdata->type == 257);
249 REQUIRE(target != NULL);
250 REQUIRE(rdata->length >= 3U);
251 REQUIRE(rdata->data != NULL);
253 caa->common.rdclass = rdata->rdclass;
254 caa->common.rdtype = rdata->type;
255 ISC_LINK_INIT(&caa->common, link);
257 dns_rdata_toregion(rdata, &sr);
260 * Flags
262 if (sr.length < 1)
263 return (ISC_R_UNEXPECTEDEND);
264 caa->flags = uint8_fromregion(&sr);
265 isc_region_consume(&sr, 1);
268 * Tag length
270 if (sr.length < 1)
271 return (ISC_R_UNEXPECTEDEND);
272 caa->tag_len = uint8_fromregion(&sr);
273 isc_region_consume(&sr, 1);
276 * Tag
278 if (sr.length < caa->tag_len)
279 return (ISC_R_UNEXPECTEDEND);
280 caa->tag = mem_maybedup(mctx, sr.base, caa->tag_len);
281 if (caa->tag == NULL)
282 return (ISC_R_NOMEMORY);
283 isc_region_consume(&sr, caa->tag_len);
286 * Value
288 caa->value_len = sr.length;
289 caa->value = mem_maybedup(mctx, sr.base, sr.length);
290 if (caa->value == NULL)
291 return (ISC_R_NOMEMORY);
293 caa->mctx = mctx;
294 return (ISC_R_SUCCESS);
297 static inline void
298 freestruct_caa(ARGS_FREESTRUCT) {
299 dns_rdata_caa_t *caa = (dns_rdata_caa_t *) source;
301 REQUIRE(source != NULL);
302 REQUIRE(caa->common.rdtype == 257);
304 if (caa->mctx == NULL)
305 return;
307 if (caa->tag != NULL)
308 isc_mem_free(caa->mctx, caa->tag);
309 if (caa->value != NULL)
310 isc_mem_free(caa->mctx, caa->value);
311 caa->mctx = NULL;
314 static inline isc_result_t
315 additionaldata_caa(ARGS_ADDLDATA) {
316 REQUIRE(rdata->type == 257);
317 REQUIRE(rdata->data != NULL);
318 REQUIRE(rdata->length >= 3U);
320 UNUSED(rdata);
321 UNUSED(add);
322 UNUSED(arg);
324 return (ISC_R_SUCCESS);
327 static inline isc_result_t
328 digest_caa(ARGS_DIGEST) {
329 isc_region_t r;
331 REQUIRE(rdata->type == 257);
332 REQUIRE(rdata->data != NULL);
333 REQUIRE(rdata->length >= 3U);
335 dns_rdata_toregion(rdata, &r);
337 return ((digest)(arg, &r));
340 static inline isc_boolean_t
341 checkowner_caa(ARGS_CHECKOWNER) {
343 REQUIRE(type == 257);
345 UNUSED(name);
346 UNUSED(type);
347 UNUSED(rdclass);
348 UNUSED(wildcard);
350 return (ISC_TRUE);
353 static inline isc_boolean_t
354 checknames_caa(ARGS_CHECKNAMES) {
356 REQUIRE(rdata->type == 257);
357 REQUIRE(rdata->data != NULL);
358 REQUIRE(rdata->length >= 3U);
360 UNUSED(rdata);
361 UNUSED(owner);
362 UNUSED(bad);
364 return (ISC_TRUE);
367 static inline int
368 casecompare_caa(ARGS_COMPARE) {
369 return (compare_caa(rdata1, rdata2));
372 #endif /* GENERIC_CAA_257_C */