Import bind 9.5.2 vendor sources.
[dragonfly.git] / contrib / bind-9.5.2 / lib / dns / rdata / in_1 / px_26.c
blob1d17f2f0e6ed2b6f270a6d37acbabc7692563d03
1 /*
2 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001, 2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: px_26.c,v 1.43 2007/06/19 23:47:17 tbox Exp $ */
20 /* Reviewed: Mon Mar 20 10:44:27 PST 2000 */
22 /* RFC2163 */
24 #ifndef RDATA_IN_1_PX_26_C
25 #define RDATA_IN_1_PX_26_C
27 #define RRTYPE_PX_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_in_px(ARGS_FROMTEXT) {
31 isc_token_t token;
32 dns_name_t name;
33 isc_buffer_t buffer;
35 REQUIRE(type == 26);
36 REQUIRE(rdclass == 1);
38 UNUSED(type);
39 UNUSED(rdclass);
40 UNUSED(callbacks);
43 * Preference.
45 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
46 ISC_FALSE));
47 if (token.value.as_ulong > 0xffffU)
48 RETTOK(ISC_R_RANGE);
49 RETERR(uint16_tobuffer(token.value.as_ulong, target));
52 * MAP822.
54 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
55 ISC_FALSE));
56 dns_name_init(&name, NULL);
57 buffer_fromregion(&buffer, &token.value.as_region);
58 origin = (origin != NULL) ? origin : dns_rootname;
59 RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
62 * MAPX400.
64 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
65 ISC_FALSE));
66 dns_name_init(&name, NULL);
67 buffer_fromregion(&buffer, &token.value.as_region);
68 origin = (origin != NULL) ? origin : dns_rootname;
69 RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
70 return (ISC_R_SUCCESS);
73 static inline isc_result_t
74 totext_in_px(ARGS_TOTEXT) {
75 isc_region_t region;
76 dns_name_t name;
77 dns_name_t prefix;
78 isc_boolean_t sub;
79 char buf[sizeof("64000")];
80 unsigned short num;
82 REQUIRE(rdata->type == 26);
83 REQUIRE(rdata->rdclass == 1);
84 REQUIRE(rdata->length != 0);
86 dns_name_init(&name, NULL);
87 dns_name_init(&prefix, NULL);
90 * Preference.
92 dns_rdata_toregion(rdata, &region);
93 num = uint16_fromregion(&region);
94 isc_region_consume(&region, 2);
95 sprintf(buf, "%u", num);
96 RETERR(str_totext(buf, target));
97 RETERR(str_totext(" ", target));
100 * MAP822.
102 dns_name_fromregion(&name, &region);
103 sub = name_prefix(&name, tctx->origin, &prefix);
104 isc_region_consume(&region, name_length(&name));
105 RETERR(dns_name_totext(&prefix, sub, target));
106 RETERR(str_totext(" ", target));
109 * MAPX400.
111 dns_name_fromregion(&name, &region);
112 sub = name_prefix(&name, tctx->origin, &prefix);
113 return(dns_name_totext(&prefix, sub, target));
116 static inline isc_result_t
117 fromwire_in_px(ARGS_FROMWIRE) {
118 dns_name_t name;
119 isc_region_t sregion;
121 REQUIRE(type == 26);
122 REQUIRE(rdclass == 1);
124 UNUSED(type);
125 UNUSED(rdclass);
127 dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
129 dns_name_init(&name, NULL);
132 * Preference.
134 isc_buffer_activeregion(source, &sregion);
135 if (sregion.length < 2)
136 return (ISC_R_UNEXPECTEDEND);
137 RETERR(mem_tobuffer(target, sregion.base, 2));
138 isc_buffer_forward(source, 2);
141 * MAP822.
143 RETERR(dns_name_fromwire(&name, source, dctx, options, target));
146 * MAPX400.
148 return (dns_name_fromwire(&name, source, dctx, options, target));
151 static inline isc_result_t
152 towire_in_px(ARGS_TOWIRE) {
153 dns_name_t name;
154 dns_offsets_t offsets;
155 isc_region_t region;
157 REQUIRE(rdata->type == 26);
158 REQUIRE(rdata->rdclass == 1);
159 REQUIRE(rdata->length != 0);
161 dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
163 * Preference.
165 dns_rdata_toregion(rdata, &region);
166 RETERR(mem_tobuffer(target, region.base, 2));
167 isc_region_consume(&region, 2);
170 * MAP822.
172 dns_name_init(&name, offsets);
173 dns_name_fromregion(&name, &region);
174 RETERR(dns_name_towire(&name, cctx, target));
175 isc_region_consume(&region, name_length(&name));
178 * MAPX400.
180 dns_name_init(&name, offsets);
181 dns_name_fromregion(&name, &region);
182 return (dns_name_towire(&name, cctx, target));
185 static inline int
186 compare_in_px(ARGS_COMPARE) {
187 dns_name_t name1;
188 dns_name_t name2;
189 isc_region_t region1;
190 isc_region_t region2;
191 int order;
193 REQUIRE(rdata1->type == rdata2->type);
194 REQUIRE(rdata1->rdclass == rdata2->rdclass);
195 REQUIRE(rdata1->type == 26);
196 REQUIRE(rdata1->rdclass == 1);
197 REQUIRE(rdata1->length != 0);
198 REQUIRE(rdata2->length != 0);
200 order = memcmp(rdata1->data, rdata2->data, 2);
201 if (order != 0)
202 return (order < 0 ? -1 : 1);
204 dns_name_init(&name1, NULL);
205 dns_name_init(&name2, NULL);
207 dns_rdata_toregion(rdata1, &region1);
208 dns_rdata_toregion(rdata2, &region2);
210 isc_region_consume(&region1, 2);
211 isc_region_consume(&region2, 2);
213 dns_name_fromregion(&name1, &region1);
214 dns_name_fromregion(&name2, &region2);
216 order = dns_name_rdatacompare(&name1, &name2);
217 if (order != 0)
218 return (order);
220 isc_region_consume(&region1, name_length(&name1));
221 isc_region_consume(&region2, name_length(&name2));
223 dns_name_fromregion(&name1, &region1);
224 dns_name_fromregion(&name2, &region2);
226 return (dns_name_rdatacompare(&name1, &name2));
229 static inline isc_result_t
230 fromstruct_in_px(ARGS_FROMSTRUCT) {
231 dns_rdata_in_px_t *px = source;
232 isc_region_t region;
234 REQUIRE(type == 26);
235 REQUIRE(rdclass == 1);
236 REQUIRE(source != NULL);
237 REQUIRE(px->common.rdtype == type);
238 REQUIRE(px->common.rdclass == rdclass);
240 UNUSED(type);
241 UNUSED(rdclass);
243 RETERR(uint16_tobuffer(px->preference, target));
244 dns_name_toregion(&px->map822, &region);
245 RETERR(isc_buffer_copyregion(target, &region));
246 dns_name_toregion(&px->mapx400, &region);
247 return (isc_buffer_copyregion(target, &region));
250 static inline isc_result_t
251 tostruct_in_px(ARGS_TOSTRUCT) {
252 dns_rdata_in_px_t *px = target;
253 dns_name_t name;
254 isc_region_t region;
255 isc_result_t result;
257 REQUIRE(rdata->type == 26);
258 REQUIRE(rdata->rdclass == 1);
259 REQUIRE(target != NULL);
260 REQUIRE(rdata->length != 0);
262 px->common.rdclass = rdata->rdclass;
263 px->common.rdtype = rdata->type;
264 ISC_LINK_INIT(&px->common, link);
266 dns_name_init(&name, NULL);
267 dns_rdata_toregion(rdata, &region);
269 px->preference = uint16_fromregion(&region);
270 isc_region_consume(&region, 2);
272 dns_name_fromregion(&name, &region);
274 dns_name_init(&px->map822, NULL);
275 RETERR(name_duporclone(&name, mctx, &px->map822));
276 isc_region_consume(&region, name_length(&px->map822));
278 dns_name_init(&px->mapx400, NULL);
279 result = name_duporclone(&name, mctx, &px->mapx400);
280 if (result != ISC_R_SUCCESS)
281 goto cleanup;
283 px->mctx = mctx;
284 return (result);
286 cleanup:
287 dns_name_free(&px->map822, mctx);
288 return (ISC_R_NOMEMORY);
291 static inline void
292 freestruct_in_px(ARGS_FREESTRUCT) {
293 dns_rdata_in_px_t *px = source;
295 REQUIRE(source != NULL);
296 REQUIRE(px->common.rdclass == 1);
297 REQUIRE(px->common.rdtype == 26);
299 if (px->mctx == NULL)
300 return;
302 dns_name_free(&px->map822, px->mctx);
303 dns_name_free(&px->mapx400, px->mctx);
304 px->mctx = NULL;
307 static inline isc_result_t
308 additionaldata_in_px(ARGS_ADDLDATA) {
309 REQUIRE(rdata->type == 26);
310 REQUIRE(rdata->rdclass == 1);
312 UNUSED(rdata);
313 UNUSED(add);
314 UNUSED(arg);
316 return (ISC_R_SUCCESS);
319 static inline isc_result_t
320 digest_in_px(ARGS_DIGEST) {
321 isc_region_t r1, r2;
322 dns_name_t name;
323 isc_result_t result;
325 REQUIRE(rdata->type == 26);
326 REQUIRE(rdata->rdclass == 1);
328 dns_rdata_toregion(rdata, &r1);
329 r2 = r1;
330 isc_region_consume(&r2, 2);
331 r1.length = 2;
332 result = (digest)(arg, &r1);
333 if (result != ISC_R_SUCCESS)
334 return (result);
335 dns_name_init(&name, NULL);
336 dns_name_fromregion(&name, &r2);
337 result = dns_name_digest(&name, digest, arg);
338 if (result != ISC_R_SUCCESS)
339 return (result);
340 isc_region_consume(&r2, name_length(&name));
341 dns_name_init(&name, NULL);
342 dns_name_fromregion(&name, &r2);
344 return (dns_name_digest(&name, digest, arg));
347 static inline isc_boolean_t
348 checkowner_in_px(ARGS_CHECKOWNER) {
350 REQUIRE(type == 26);
351 REQUIRE(rdclass == 1);
353 UNUSED(name);
354 UNUSED(type);
355 UNUSED(rdclass);
356 UNUSED(wildcard);
358 return (ISC_TRUE);
361 static inline isc_boolean_t
362 checknames_in_px(ARGS_CHECKNAMES) {
364 REQUIRE(rdata->type == 26);
365 REQUIRE(rdata->rdclass == 1);
367 UNUSED(rdata);
368 UNUSED(owner);
369 UNUSED(bad);
371 return (ISC_TRUE);
374 #endif /* RDATA_IN_1_PX_26_C */