Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / generic / uri_256.c
blobb4527b6d8014e01d69ab956e466632cbc2d1a480
1 /* $NetBSD: uri_256.c,v 1.1.1.5 2014/12/10 03:34:42 christos Exp $ */
3 /*
4 * Copyright (C) 2011, 2012, 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 /* Id */
21 #ifndef GENERIC_URI_256_C
22 #define GENERIC_URI_256_C 1
24 #define RRTYPE_URI_ATTRIBUTES (0)
26 static inline isc_result_t
27 fromtext_uri(ARGS_FROMTEXT) {
28 isc_token_t token;
30 REQUIRE(type == 256);
32 UNUSED(type);
33 UNUSED(rdclass);
34 UNUSED(origin);
35 UNUSED(options);
36 UNUSED(callbacks);
39 * Priority
41 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
42 ISC_FALSE));
43 if (token.value.as_ulong > 0xffffU)
44 RETTOK(ISC_R_RANGE);
45 RETERR(uint16_tobuffer(token.value.as_ulong, target));
48 * Weight
50 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
51 ISC_FALSE));
52 if (token.value.as_ulong > 0xffffU)
53 RETTOK(ISC_R_RANGE);
54 RETERR(uint16_tobuffer(token.value.as_ulong, target));
57 * Target URI
59 RETERR(isc_lex_getmastertoken(lexer, &token,
60 isc_tokentype_qstring, ISC_FALSE));
61 if (token.type != isc_tokentype_qstring)
62 RETTOK(DNS_R_SYNTAX);
63 RETTOK(multitxt_fromtext(&token.value.as_textregion, target));
64 return (ISC_R_SUCCESS);
67 static inline isc_result_t
68 totext_uri(ARGS_TOTEXT) {
69 isc_region_t region;
70 unsigned short priority, weight;
71 char buf[sizeof("65000 ")];
73 UNUSED(tctx);
75 REQUIRE(rdata->type == 256);
76 REQUIRE(rdata->length != 0);
78 dns_rdata_toregion(rdata, &region);
81 * Priority
83 priority = uint16_fromregion(&region);
84 isc_region_consume(&region, 2);
85 sprintf(buf, "%u ", priority);
86 RETERR(str_totext(buf, target));
89 * Weight
91 weight = uint16_fromregion(&region);
92 isc_region_consume(&region, 2);
93 sprintf(buf, "%u ", weight);
94 RETERR(str_totext(buf, target));
97 * Target URI
99 RETERR(multitxt_totext(&region, target));
100 return (ISC_R_SUCCESS);
103 static inline isc_result_t
104 fromwire_uri(ARGS_FROMWIRE) {
105 isc_region_t region;
107 REQUIRE(type == 256);
109 UNUSED(type);
110 UNUSED(rdclass);
111 UNUSED(dctx);
112 UNUSED(options);
115 * Priority, weight
117 isc_buffer_activeregion(source, &region);
118 if (region.length < 4)
119 return (ISC_R_UNEXPECTEDEND);
122 * Priority, weight and target URI
124 isc_buffer_forward(source, region.length);
125 return (mem_tobuffer(target, region.base, region.length));
128 static inline isc_result_t
129 towire_uri(ARGS_TOWIRE) {
130 isc_region_t region;
132 REQUIRE(rdata->type == 256);
133 REQUIRE(rdata->length != 0);
135 UNUSED(cctx);
137 dns_rdata_toregion(rdata, &region);
138 return (mem_tobuffer(target, region.base, region.length));
141 static inline int
142 compare_uri(ARGS_COMPARE) {
143 isc_region_t r1;
144 isc_region_t r2;
145 int order;
147 REQUIRE(rdata1->type == rdata2->type);
148 REQUIRE(rdata1->rdclass == rdata2->rdclass);
149 REQUIRE(rdata1->type == 256);
150 REQUIRE(rdata1->length != 0);
151 REQUIRE(rdata2->length != 0);
153 dns_rdata_toregion(rdata1, &r1);
154 dns_rdata_toregion(rdata2, &r2);
157 * Priority
159 order = memcmp(r1.base, r2.base, 2);
160 if (order != 0)
161 return (order < 0 ? -1 : 1);
162 isc_region_consume(&r1, 2);
163 isc_region_consume(&r2, 2);
166 * Weight
168 order = memcmp(r1.base, r2.base, 2);
169 if (order != 0)
170 return (order < 0 ? -1 : 1);
171 isc_region_consume(&r1, 2);
172 isc_region_consume(&r2, 2);
174 return (isc_region_compare(&r1, &r2));
177 static inline isc_result_t
178 fromstruct_uri(ARGS_FROMSTRUCT) {
179 dns_rdata_uri_t *uri = source;
181 REQUIRE(type == 256);
182 REQUIRE(source != NULL);
183 REQUIRE(uri->common.rdtype == type);
184 REQUIRE(uri->common.rdclass == rdclass);
185 REQUIRE(uri->target != NULL && uri->tgt_len != 0);
187 UNUSED(type);
188 UNUSED(rdclass);
191 * Priority
193 RETERR(uint16_tobuffer(uri->priority, target));
196 * Weight
198 RETERR(uint16_tobuffer(uri->weight, target));
201 * Target URI
203 return (mem_tobuffer(target, uri->target, uri->tgt_len));
206 static inline isc_result_t
207 tostruct_uri(ARGS_TOSTRUCT) {
208 dns_rdata_uri_t *uri = target;
209 isc_region_t sr;
211 REQUIRE(rdata->type == 256);
212 REQUIRE(target != NULL);
213 REQUIRE(rdata->length != 0);
215 uri->common.rdclass = rdata->rdclass;
216 uri->common.rdtype = rdata->type;
217 ISC_LINK_INIT(&uri->common, link);
219 dns_rdata_toregion(rdata, &sr);
222 * Priority
224 if (sr.length < 2)
225 return (ISC_R_UNEXPECTEDEND);
226 uri->priority = uint16_fromregion(&sr);
227 isc_region_consume(&sr, 2);
230 * Weight
232 if (sr.length < 2)
233 return (ISC_R_UNEXPECTEDEND);
234 uri->weight = uint16_fromregion(&sr);
235 isc_region_consume(&sr, 2);
238 * Target URI
240 uri->tgt_len = sr.length;
241 uri->target = mem_maybedup(mctx, sr.base, sr.length);
242 if (uri->target == NULL)
243 return (ISC_R_NOMEMORY);
245 uri->mctx = mctx;
246 return (ISC_R_SUCCESS);
249 static inline void
250 freestruct_uri(ARGS_FREESTRUCT) {
251 dns_rdata_uri_t *uri = (dns_rdata_uri_t *) source;
253 REQUIRE(source != NULL);
254 REQUIRE(uri->common.rdtype == 256);
256 if (uri->mctx == NULL)
257 return;
259 if (uri->target != NULL)
260 isc_mem_free(uri->mctx, uri->target);
261 uri->mctx = NULL;
264 static inline isc_result_t
265 additionaldata_uri(ARGS_ADDLDATA) {
266 REQUIRE(rdata->type == 256);
268 UNUSED(rdata);
269 UNUSED(add);
270 UNUSED(arg);
272 return (ISC_R_SUCCESS);
275 static inline isc_result_t
276 digest_uri(ARGS_DIGEST) {
277 isc_region_t r;
279 REQUIRE(rdata->type == 256);
281 dns_rdata_toregion(rdata, &r);
283 return ((digest)(arg, &r));
286 static inline isc_boolean_t
287 checkowner_uri(ARGS_CHECKOWNER) {
289 REQUIRE(type == 256);
291 UNUSED(name);
292 UNUSED(type);
293 UNUSED(rdclass);
294 UNUSED(wildcard);
296 return (ISC_TRUE);
299 static inline isc_boolean_t
300 checknames_uri(ARGS_CHECKNAMES) {
302 REQUIRE(rdata->type == 256);
304 UNUSED(rdata);
305 UNUSED(owner);
306 UNUSED(bad);
308 return (ISC_TRUE);
311 static inline int
312 casecompare_uri(ARGS_COMPARE) {
313 return (compare_uri(rdata1, rdata2));
316 #endif /* GENERIC_URI_256_C */