Annotation of src/external/mpl/bind/dist/lib/dns/rdata/generic/uri_256.c, Revision 1.1.1.6
1.1 christos 1: /* $NetBSD$ */
2:
3: /*
4: * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5: *
1.1.1.6 ! christos 6: * SPDX-License-Identifier: MPL-2.0
! 7: *
1.1 christos 8: * This Source Code Form is subject to the terms of the Mozilla Public
9: * License, v. 2.0. If a copy of the MPL was not distributed with this
1.1.1.5 christos 10: * file, you can obtain one at https://mozilla.org/MPL/2.0/.
1.1 christos 11: *
12: * See the COPYRIGHT file distributed with this work for additional
13: * information regarding copyright ownership.
14: */
15:
16: #ifndef GENERIC_URI_256_C
17: #define GENERIC_URI_256_C 1
18:
19: #define RRTYPE_URI_ATTRIBUTES (0)
20:
1.1.1.6 ! christos 21: static isc_result_t
1.1 christos 22: fromtext_uri(ARGS_FROMTEXT) {
23: isc_token_t token;
24:
25: REQUIRE(type == dns_rdatatype_uri);
26:
27: UNUSED(type);
28: UNUSED(rdclass);
29: UNUSED(origin);
30: UNUSED(options);
31: UNUSED(callbacks);
32:
33: /*
34: * Priority
35: */
36: RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
1.1.1.2 christos 37: false));
1.1.1.4 christos 38: if (token.value.as_ulong > 0xffffU) {
1.1 christos 39: RETTOK(ISC_R_RANGE);
1.1.1.4 christos 40: }
1.1 christos 41: RETERR(uint16_tobuffer(token.value.as_ulong, target));
42:
43: /*
44: * Weight
45: */
46: RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
1.1.1.2 christos 47: false));
1.1.1.4 christos 48: if (token.value.as_ulong > 0xffffU) {
1.1 christos 49: RETTOK(ISC_R_RANGE);
1.1.1.4 christos 50: }
1.1 christos 51: RETERR(uint16_tobuffer(token.value.as_ulong, target));
52:
53: /*
54: * Target URI
55: */
1.1.1.4 christos 56: RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
57: false));
58: if (token.type != isc_tokentype_qstring) {
1.1 christos 59: RETTOK(DNS_R_SYNTAX);
1.1.1.4 christos 60: }
1.1 christos 61: RETTOK(multitxt_fromtext(&token.value.as_textregion, target));
62: return (ISC_R_SUCCESS);
63: }
64:
1.1.1.6 ! christos 65: static isc_result_t
1.1 christos 66: totext_uri(ARGS_TOTEXT) {
67: isc_region_t region;
68: unsigned short priority, weight;
69: char buf[sizeof("65000 ")];
70:
71: UNUSED(tctx);
72:
73: REQUIRE(rdata->type == dns_rdatatype_uri);
74: REQUIRE(rdata->length != 0);
75:
76: dns_rdata_toregion(rdata, ®ion);
77:
78: /*
79: * Priority
80: */
81: priority = uint16_fromregion(®ion);
82: isc_region_consume(®ion, 2);
83: snprintf(buf, sizeof(buf), "%u ", priority);
84: RETERR(str_totext(buf, target));
85:
86: /*
87: * Weight
88: */
89: weight = uint16_fromregion(®ion);
90: isc_region_consume(®ion, 2);
91: snprintf(buf, sizeof(buf), "%u ", weight);
92: RETERR(str_totext(buf, target));
93:
94: /*
95: * Target URI
96: */
97: RETERR(multitxt_totext(®ion, target));
98: return (ISC_R_SUCCESS);
99: }
100:
1.1.1.6 ! christos 101: static isc_result_t
1.1 christos 102: fromwire_uri(ARGS_FROMWIRE) {
103: isc_region_t region;
104:
105: REQUIRE(type == dns_rdatatype_uri);
106:
107: UNUSED(type);
108: UNUSED(rdclass);
109: UNUSED(dctx);
110: UNUSED(options);
111:
112: /*
113: * Priority, weight
114: */
115: isc_buffer_activeregion(source, ®ion);
1.1.1.4 christos 116: if (region.length < 4) {
1.1 christos 117: return (ISC_R_UNEXPECTEDEND);
1.1.1.4 christos 118: }
1.1 christos 119:
120: /*
121: * Priority, weight and target URI
122: */
123: isc_buffer_forward(source, region.length);
124: return (mem_tobuffer(target, region.base, region.length));
125: }
126:
1.1.1.6 ! christos 127: static isc_result_t
1.1 christos 128: towire_uri(ARGS_TOWIRE) {
129: isc_region_t region;
130:
131: REQUIRE(rdata->type == dns_rdatatype_uri);
132: REQUIRE(rdata->length != 0);
133:
134: UNUSED(cctx);
135:
136: dns_rdata_toregion(rdata, ®ion);
137: return (mem_tobuffer(target, region.base, region.length));
138: }
139:
1.1.1.6 ! christos 140: static int
1.1 christos 141: compare_uri(ARGS_COMPARE) {
142: isc_region_t r1;
143: isc_region_t r2;
144: int order;
145:
146: REQUIRE(rdata1->type == rdata2->type);
147: REQUIRE(rdata1->rdclass == rdata2->rdclass);
148: REQUIRE(rdata1->type == dns_rdatatype_uri);
149: REQUIRE(rdata1->length != 0);
150: REQUIRE(rdata2->length != 0);
151:
152: dns_rdata_toregion(rdata1, &r1);
153: dns_rdata_toregion(rdata2, &r2);
154:
155: /*
156: * Priority
157: */
158: order = memcmp(r1.base, r2.base, 2);
1.1.1.4 christos 159: if (order != 0) {
1.1 christos 160: return (order < 0 ? -1 : 1);
1.1.1.4 christos 161: }
1.1 christos 162: isc_region_consume(&r1, 2);
163: isc_region_consume(&r2, 2);
164:
165: /*
166: * Weight
167: */
168: order = memcmp(r1.base, r2.base, 2);
1.1.1.4 christos 169: if (order != 0) {
1.1 christos 170: return (order < 0 ? -1 : 1);
1.1.1.4 christos 171: }
1.1 christos 172: isc_region_consume(&r1, 2);
173: isc_region_consume(&r2, 2);
174:
175: return (isc_region_compare(&r1, &r2));
176: }
177:
1.1.1.6 ! christos 178: static isc_result_t
1.1 christos 179: fromstruct_uri(ARGS_FROMSTRUCT) {
180: dns_rdata_uri_t *uri = source;
181:
182: REQUIRE(type == dns_rdatatype_uri);
1.1.1.3 christos 183: REQUIRE(uri != NULL);
1.1 christos 184: REQUIRE(uri->common.rdtype == type);
185: REQUIRE(uri->common.rdclass == rdclass);
186: REQUIRE(uri->target != NULL && uri->tgt_len != 0);
187:
188: UNUSED(type);
189: UNUSED(rdclass);
190:
191: /*
192: * Priority
193: */
194: RETERR(uint16_tobuffer(uri->priority, target));
195:
196: /*
197: * Weight
198: */
199: RETERR(uint16_tobuffer(uri->weight, target));
200:
201: /*
202: * Target URI
203: */
204: return (mem_tobuffer(target, uri->target, uri->tgt_len));
205: }
206:
1.1.1.6 ! christos 207: static isc_result_t
1.1 christos 208: tostruct_uri(ARGS_TOSTRUCT) {
209: dns_rdata_uri_t *uri = target;
210: isc_region_t sr;
211:
212: REQUIRE(rdata->type == dns_rdatatype_uri);
1.1.1.3 christos 213: REQUIRE(uri != NULL);
1.1 christos 214: REQUIRE(rdata->length != 0);
215:
216: uri->common.rdclass = rdata->rdclass;
217: uri->common.rdtype = rdata->type;
218: ISC_LINK_INIT(&uri->common, link);
219:
220: dns_rdata_toregion(rdata, &sr);
221:
222: /*
223: * Priority
224: */
1.1.1.4 christos 225: if (sr.length < 2) {
1.1 christos 226: return (ISC_R_UNEXPECTEDEND);
1.1.1.4 christos 227: }
1.1 christos 228: uri->priority = uint16_fromregion(&sr);
229: isc_region_consume(&sr, 2);
230:
231: /*
232: * Weight
233: */
1.1.1.4 christos 234: if (sr.length < 2) {
1.1 christos 235: return (ISC_R_UNEXPECTEDEND);
1.1.1.4 christos 236: }
1.1 christos 237: uri->weight = uint16_fromregion(&sr);
238: isc_region_consume(&sr, 2);
239:
240: /*
241: * Target URI
242: */
243: uri->tgt_len = sr.length;
244: uri->target = mem_maybedup(mctx, sr.base, sr.length);
1.1.1.4 christos 245: if (uri->target == NULL) {
1.1 christos 246: return (ISC_R_NOMEMORY);
1.1.1.4 christos 247: }
1.1 christos 248:
249: uri->mctx = mctx;
250: return (ISC_R_SUCCESS);
251: }
252:
1.1.1.6 ! christos 253: static void
1.1 christos 254: freestruct_uri(ARGS_FREESTRUCT) {
1.1.1.4 christos 255: dns_rdata_uri_t *uri = (dns_rdata_uri_t *)source;
1.1 christos 256:
1.1.1.3 christos 257: REQUIRE(uri != NULL);
1.1 christos 258: REQUIRE(uri->common.rdtype == dns_rdatatype_uri);
259:
1.1.1.4 christos 260: if (uri->mctx == NULL) {
1.1 christos 261: return;
1.1.1.4 christos 262: }
1.1 christos 263:
1.1.1.4 christos 264: if (uri->target != NULL) {
1.1 christos 265: isc_mem_free(uri->mctx, uri->target);
1.1.1.4 christos 266: }
1.1 christos 267: uri->mctx = NULL;
268: }
269:
1.1.1.6 ! christos 270: static isc_result_t
1.1 christos 271: additionaldata_uri(ARGS_ADDLDATA) {
272: REQUIRE(rdata->type == dns_rdatatype_uri);
273:
274: UNUSED(rdata);
275: UNUSED(add);
276: UNUSED(arg);
277:
278: return (ISC_R_SUCCESS);
279: }
280:
1.1.1.6 ! christos 281: static isc_result_t
1.1 christos 282: digest_uri(ARGS_DIGEST) {
283: isc_region_t r;
284:
285: REQUIRE(rdata->type == dns_rdatatype_uri);
286:
287: dns_rdata_toregion(rdata, &r);
288:
289: return ((digest)(arg, &r));
290: }
291:
1.1.1.6 ! christos 292: static bool
1.1 christos 293: checkowner_uri(ARGS_CHECKOWNER) {
294: REQUIRE(type == dns_rdatatype_uri);
295:
296: UNUSED(name);
297: UNUSED(type);
298: UNUSED(rdclass);
299: UNUSED(wildcard);
300:
1.1.1.2 christos 301: return (true);
1.1 christos 302: }
303:
1.1.1.6 ! christos 304: static bool
1.1 christos 305: checknames_uri(ARGS_CHECKNAMES) {
306: REQUIRE(rdata->type == dns_rdatatype_uri);
307:
308: UNUSED(rdata);
309: UNUSED(owner);
310: UNUSED(bad);
311:
1.1.1.2 christos 312: return (true);
1.1 christos 313: }
314:
1.1.1.6 ! christos 315: static int
1.1 christos 316: casecompare_uri(ARGS_COMPARE) {
317: return (compare_uri(rdata1, rdata2));
318: }
319:
320: #endif /* GENERIC_URI_256_C */
CVSweb <webmaster@jp.NetBSD.org>