Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / in_1 / px_26.c
blob8878967821fc64bef23a54afa27db9f50736fec6
1 /* $NetBSD: px_26.c,v 1.4 2014/12/10 04:37:59 christos Exp $ */
3 /*
4 * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2001, 2003 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: px_26.c,v 1.45 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Mon Mar 20 10:44:27 PST 2000 */
24 /* RFC2163 */
26 #ifndef RDATA_IN_1_PX_26_C
27 #define RDATA_IN_1_PX_26_C
29 #define RRTYPE_PX_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_in_px(ARGS_FROMTEXT) {
33 isc_token_t token;
34 dns_name_t name;
35 isc_buffer_t buffer;
37 REQUIRE(type == 26);
38 REQUIRE(rdclass == 1);
40 UNUSED(type);
41 UNUSED(rdclass);
42 UNUSED(callbacks);
45 * Preference.
47 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
48 ISC_FALSE));
49 if (token.value.as_ulong > 0xffffU)
50 RETTOK(ISC_R_RANGE);
51 RETERR(uint16_tobuffer(token.value.as_ulong, target));
54 * MAP822.
56 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
57 ISC_FALSE));
58 dns_name_init(&name, NULL);
59 buffer_fromregion(&buffer, &token.value.as_region);
60 origin = (origin != NULL) ? origin : dns_rootname;
61 RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
64 * MAPX400.
66 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
67 ISC_FALSE));
68 dns_name_init(&name, NULL);
69 buffer_fromregion(&buffer, &token.value.as_region);
70 origin = (origin != NULL) ? origin : dns_rootname;
71 RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
72 return (ISC_R_SUCCESS);
75 static inline isc_result_t
76 totext_in_px(ARGS_TOTEXT) {
77 isc_region_t region;
78 dns_name_t name;
79 dns_name_t prefix;
80 isc_boolean_t sub;
81 char buf[sizeof("64000")];
82 unsigned short num;
84 REQUIRE(rdata->type == 26);
85 REQUIRE(rdata->rdclass == 1);
86 REQUIRE(rdata->length != 0);
88 dns_name_init(&name, NULL);
89 dns_name_init(&prefix, NULL);
92 * Preference.
94 dns_rdata_toregion(rdata, &region);
95 num = uint16_fromregion(&region);
96 isc_region_consume(&region, 2);
97 sprintf(buf, "%u", num);
98 RETERR(str_totext(buf, target));
99 RETERR(str_totext(" ", target));
102 * MAP822.
104 dns_name_fromregion(&name, &region);
105 sub = name_prefix(&name, tctx->origin, &prefix);
106 isc_region_consume(&region, name_length(&name));
107 RETERR(dns_name_totext(&prefix, sub, target));
108 RETERR(str_totext(" ", target));
111 * MAPX400.
113 dns_name_fromregion(&name, &region);
114 sub = name_prefix(&name, tctx->origin, &prefix);
115 return(dns_name_totext(&prefix, sub, target));
118 static inline isc_result_t
119 fromwire_in_px(ARGS_FROMWIRE) {
120 dns_name_t name;
121 isc_region_t sregion;
123 REQUIRE(type == 26);
124 REQUIRE(rdclass == 1);
126 UNUSED(type);
127 UNUSED(rdclass);
129 dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
131 dns_name_init(&name, NULL);
134 * Preference.
136 isc_buffer_activeregion(source, &sregion);
137 if (sregion.length < 2)
138 return (ISC_R_UNEXPECTEDEND);
139 RETERR(mem_tobuffer(target, sregion.base, 2));
140 isc_buffer_forward(source, 2);
143 * MAP822.
145 RETERR(dns_name_fromwire(&name, source, dctx, options, target));
148 * MAPX400.
150 return (dns_name_fromwire(&name, source, dctx, options, target));
153 static inline isc_result_t
154 towire_in_px(ARGS_TOWIRE) {
155 dns_name_t name;
156 dns_offsets_t offsets;
157 isc_region_t region;
159 REQUIRE(rdata->type == 26);
160 REQUIRE(rdata->rdclass == 1);
161 REQUIRE(rdata->length != 0);
163 dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
165 * Preference.
167 dns_rdata_toregion(rdata, &region);
168 RETERR(mem_tobuffer(target, region.base, 2));
169 isc_region_consume(&region, 2);
172 * MAP822.
174 dns_name_init(&name, offsets);
175 dns_name_fromregion(&name, &region);
176 RETERR(dns_name_towire(&name, cctx, target));
177 isc_region_consume(&region, name_length(&name));
180 * MAPX400.
182 dns_name_init(&name, offsets);
183 dns_name_fromregion(&name, &region);
184 return (dns_name_towire(&name, cctx, target));
187 static inline int
188 compare_in_px(ARGS_COMPARE) {
189 dns_name_t name1;
190 dns_name_t name2;
191 isc_region_t region1;
192 isc_region_t region2;
193 int order;
195 REQUIRE(rdata1->type == rdata2->type);
196 REQUIRE(rdata1->rdclass == rdata2->rdclass);
197 REQUIRE(rdata1->type == 26);
198 REQUIRE(rdata1->rdclass == 1);
199 REQUIRE(rdata1->length != 0);
200 REQUIRE(rdata2->length != 0);
202 order = memcmp(rdata1->data, rdata2->data, 2);
203 if (order != 0)
204 return (order < 0 ? -1 : 1);
206 dns_name_init(&name1, NULL);
207 dns_name_init(&name2, NULL);
209 dns_rdata_toregion(rdata1, &region1);
210 dns_rdata_toregion(rdata2, &region2);
212 isc_region_consume(&region1, 2);
213 isc_region_consume(&region2, 2);
215 dns_name_fromregion(&name1, &region1);
216 dns_name_fromregion(&name2, &region2);
218 order = dns_name_rdatacompare(&name1, &name2);
219 if (order != 0)
220 return (order);
222 isc_region_consume(&region1, name_length(&name1));
223 isc_region_consume(&region2, name_length(&name2));
225 dns_name_fromregion(&name1, &region1);
226 dns_name_fromregion(&name2, &region2);
228 return (dns_name_rdatacompare(&name1, &name2));
231 static inline isc_result_t
232 fromstruct_in_px(ARGS_FROMSTRUCT) {
233 dns_rdata_in_px_t *px = source;
234 isc_region_t region;
236 REQUIRE(type == 26);
237 REQUIRE(rdclass == 1);
238 REQUIRE(source != NULL);
239 REQUIRE(px->common.rdtype == type);
240 REQUIRE(px->common.rdclass == rdclass);
242 UNUSED(type);
243 UNUSED(rdclass);
245 RETERR(uint16_tobuffer(px->preference, target));
246 dns_name_toregion(&px->map822, &region);
247 RETERR(isc_buffer_copyregion(target, &region));
248 dns_name_toregion(&px->mapx400, &region);
249 return (isc_buffer_copyregion(target, &region));
252 static inline isc_result_t
253 tostruct_in_px(ARGS_TOSTRUCT) {
254 dns_rdata_in_px_t *px = target;
255 dns_name_t name;
256 isc_region_t region;
257 isc_result_t result;
259 REQUIRE(rdata->type == 26);
260 REQUIRE(rdata->rdclass == 1);
261 REQUIRE(target != NULL);
262 REQUIRE(rdata->length != 0);
264 px->common.rdclass = rdata->rdclass;
265 px->common.rdtype = rdata->type;
266 ISC_LINK_INIT(&px->common, link);
268 dns_name_init(&name, NULL);
269 dns_rdata_toregion(rdata, &region);
271 px->preference = uint16_fromregion(&region);
272 isc_region_consume(&region, 2);
274 dns_name_fromregion(&name, &region);
276 dns_name_init(&px->map822, NULL);
277 RETERR(name_duporclone(&name, mctx, &px->map822));
278 isc_region_consume(&region, name_length(&px->map822));
280 dns_name_init(&px->mapx400, NULL);
281 result = name_duporclone(&name, mctx, &px->mapx400);
282 if (result != ISC_R_SUCCESS)
283 goto cleanup;
285 px->mctx = mctx;
286 return (result);
288 cleanup:
289 dns_name_free(&px->map822, mctx);
290 return (ISC_R_NOMEMORY);
293 static inline void
294 freestruct_in_px(ARGS_FREESTRUCT) {
295 dns_rdata_in_px_t *px = source;
297 REQUIRE(source != NULL);
298 REQUIRE(px->common.rdclass == 1);
299 REQUIRE(px->common.rdtype == 26);
301 if (px->mctx == NULL)
302 return;
304 dns_name_free(&px->map822, px->mctx);
305 dns_name_free(&px->mapx400, px->mctx);
306 px->mctx = NULL;
309 static inline isc_result_t
310 additionaldata_in_px(ARGS_ADDLDATA) {
311 REQUIRE(rdata->type == 26);
312 REQUIRE(rdata->rdclass == 1);
314 UNUSED(rdata);
315 UNUSED(add);
316 UNUSED(arg);
318 return (ISC_R_SUCCESS);
321 static inline isc_result_t
322 digest_in_px(ARGS_DIGEST) {
323 isc_region_t r1, r2;
324 dns_name_t name;
325 isc_result_t result;
327 REQUIRE(rdata->type == 26);
328 REQUIRE(rdata->rdclass == 1);
330 dns_rdata_toregion(rdata, &r1);
331 r2 = r1;
332 isc_region_consume(&r2, 2);
333 r1.length = 2;
334 result = (digest)(arg, &r1);
335 if (result != ISC_R_SUCCESS)
336 return (result);
337 dns_name_init(&name, NULL);
338 dns_name_fromregion(&name, &r2);
339 result = dns_name_digest(&name, digest, arg);
340 if (result != ISC_R_SUCCESS)
341 return (result);
342 isc_region_consume(&r2, name_length(&name));
343 dns_name_init(&name, NULL);
344 dns_name_fromregion(&name, &r2);
346 return (dns_name_digest(&name, digest, arg));
349 static inline isc_boolean_t
350 checkowner_in_px(ARGS_CHECKOWNER) {
352 REQUIRE(type == 26);
353 REQUIRE(rdclass == 1);
355 UNUSED(name);
356 UNUSED(type);
357 UNUSED(rdclass);
358 UNUSED(wildcard);
360 return (ISC_TRUE);
363 static inline isc_boolean_t
364 checknames_in_px(ARGS_CHECKNAMES) {
366 REQUIRE(rdata->type == 26);
367 REQUIRE(rdata->rdclass == 1);
369 UNUSED(rdata);
370 UNUSED(owner);
371 UNUSED(bad);
373 return (ISC_TRUE);
376 static inline int
377 casecompare_in_px(ARGS_COMPARE) {
378 return (compare_in_px(rdata1, rdata2));
381 #endif /* RDATA_IN_1_PX_26_C */