Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / in_1 / kx_36.c
blob71d772b2debb4cdb33df9019d21395abd6b391d0
1 /* $NetBSD: kx_36.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: kx_36.c,v 1.47 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Thu Mar 16 17:24:54 PST 2000 by explorer */
24 /* RFC2230 */
26 #ifndef RDATA_IN_1_KX_36_C
27 #define RDATA_IN_1_KX_36_C
29 #define RRTYPE_KX_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_in_kx(ARGS_FROMTEXT) {
33 isc_token_t token;
34 dns_name_t name;
35 isc_buffer_t buffer;
37 REQUIRE(type == 36);
38 REQUIRE(rdclass == 1);
40 UNUSED(type);
41 UNUSED(rdclass);
42 UNUSED(callbacks);
44 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
45 ISC_FALSE));
46 if (token.value.as_ulong > 0xffffU)
47 RETTOK(ISC_R_RANGE);
48 RETERR(uint16_tobuffer(token.value.as_ulong, target));
50 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
51 ISC_FALSE));
52 dns_name_init(&name, NULL);
53 buffer_fromregion(&buffer, &token.value.as_region);
54 origin = (origin != NULL) ? origin : dns_rootname;
55 RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
56 return (ISC_R_SUCCESS);
59 static inline isc_result_t
60 totext_in_kx(ARGS_TOTEXT) {
61 isc_region_t region;
62 dns_name_t name;
63 dns_name_t prefix;
64 isc_boolean_t sub;
65 char buf[sizeof("64000")];
66 unsigned short num;
68 REQUIRE(rdata->type == 36);
69 REQUIRE(rdata->rdclass == 1);
70 REQUIRE(rdata->length != 0);
72 dns_name_init(&name, NULL);
73 dns_name_init(&prefix, NULL);
75 dns_rdata_toregion(rdata, &region);
76 num = uint16_fromregion(&region);
77 isc_region_consume(&region, 2);
78 sprintf(buf, "%u", num);
79 RETERR(str_totext(buf, target));
81 RETERR(str_totext(" ", target));
83 dns_name_fromregion(&name, &region);
84 sub = name_prefix(&name, tctx->origin, &prefix);
85 return (dns_name_totext(&prefix, sub, target));
88 static inline isc_result_t
89 fromwire_in_kx(ARGS_FROMWIRE) {
90 dns_name_t name;
91 isc_region_t sregion;
93 REQUIRE(type == 36);
94 REQUIRE(rdclass == 1);
96 UNUSED(type);
97 UNUSED(rdclass);
99 dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
101 dns_name_init(&name, NULL);
103 isc_buffer_activeregion(source, &sregion);
104 if (sregion.length < 2)
105 return (ISC_R_UNEXPECTEDEND);
106 RETERR(mem_tobuffer(target, sregion.base, 2));
107 isc_buffer_forward(source, 2);
108 return (dns_name_fromwire(&name, source, dctx, options, target));
111 static inline isc_result_t
112 towire_in_kx(ARGS_TOWIRE) {
113 dns_name_t name;
114 dns_offsets_t offsets;
115 isc_region_t region;
117 REQUIRE(rdata->type == 36);
118 REQUIRE(rdata->rdclass == 1);
119 REQUIRE(rdata->length != 0);
121 dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
122 dns_rdata_toregion(rdata, &region);
123 RETERR(mem_tobuffer(target, region.base, 2));
124 isc_region_consume(&region, 2);
126 dns_name_init(&name, offsets);
127 dns_name_fromregion(&name, &region);
129 return (dns_name_towire(&name, cctx, target));
132 static inline int
133 compare_in_kx(ARGS_COMPARE) {
134 dns_name_t name1;
135 dns_name_t name2;
136 isc_region_t region1;
137 isc_region_t region2;
138 int order;
140 REQUIRE(rdata1->type == rdata2->type);
141 REQUIRE(rdata1->rdclass == rdata2->rdclass);
142 REQUIRE(rdata1->type == 36);
143 REQUIRE(rdata1->rdclass == 1);
144 REQUIRE(rdata1->length != 0);
145 REQUIRE(rdata2->length != 0);
147 order = memcmp(rdata1->data, rdata2->data, 2);
148 if (order != 0)
149 return (order < 0 ? -1 : 1);
151 dns_name_init(&name1, NULL);
152 dns_name_init(&name2, NULL);
154 dns_rdata_toregion(rdata1, &region1);
155 dns_rdata_toregion(rdata2, &region2);
157 isc_region_consume(&region1, 2);
158 isc_region_consume(&region2, 2);
160 dns_name_fromregion(&name1, &region1);
161 dns_name_fromregion(&name2, &region2);
163 return (dns_name_rdatacompare(&name1, &name2));
166 static inline isc_result_t
167 fromstruct_in_kx(ARGS_FROMSTRUCT) {
168 dns_rdata_in_kx_t *kx = source;
169 isc_region_t region;
171 REQUIRE(type == 36);
172 REQUIRE(rdclass == 1);
173 REQUIRE(source != NULL);
174 REQUIRE(kx->common.rdtype == type);
175 REQUIRE(kx->common.rdclass == rdclass);
177 UNUSED(type);
178 UNUSED(rdclass);
180 RETERR(uint16_tobuffer(kx->preference, target));
181 dns_name_toregion(&kx->exchange, &region);
182 return (isc_buffer_copyregion(target, &region));
185 static inline isc_result_t
186 tostruct_in_kx(ARGS_TOSTRUCT) {
187 isc_region_t region;
188 dns_rdata_in_kx_t *kx = target;
189 dns_name_t name;
191 REQUIRE(rdata->type == 36);
192 REQUIRE(rdata->rdclass == 1);
193 REQUIRE(target != NULL);
194 REQUIRE(rdata->length != 0);
196 kx->common.rdclass = rdata->rdclass;
197 kx->common.rdtype = rdata->type;
198 ISC_LINK_INIT(&kx->common, link);
200 dns_name_init(&name, NULL);
201 dns_rdata_toregion(rdata, &region);
203 kx->preference = uint16_fromregion(&region);
204 isc_region_consume(&region, 2);
206 dns_name_fromregion(&name, &region);
207 dns_name_init(&kx->exchange, NULL);
208 RETERR(name_duporclone(&name, mctx, &kx->exchange));
209 kx->mctx = mctx;
210 return (ISC_R_SUCCESS);
213 static inline void
214 freestruct_in_kx(ARGS_FREESTRUCT) {
215 dns_rdata_in_kx_t *kx = source;
217 REQUIRE(source != NULL);
218 REQUIRE(kx->common.rdclass == 1);
219 REQUIRE(kx->common.rdtype == 36);
221 if (kx->mctx == NULL)
222 return;
224 dns_name_free(&kx->exchange, kx->mctx);
225 kx->mctx = NULL;
228 static inline isc_result_t
229 additionaldata_in_kx(ARGS_ADDLDATA) {
230 dns_name_t name;
231 dns_offsets_t offsets;
232 isc_region_t region;
234 REQUIRE(rdata->type == 36);
235 REQUIRE(rdata->rdclass == 1);
237 dns_name_init(&name, offsets);
238 dns_rdata_toregion(rdata, &region);
239 isc_region_consume(&region, 2);
240 dns_name_fromregion(&name, &region);
242 return ((add)(arg, &name, dns_rdatatype_a));
245 static inline isc_result_t
246 digest_in_kx(ARGS_DIGEST) {
247 isc_region_t r1, r2;
248 dns_name_t name;
250 REQUIRE(rdata->type == 36);
251 REQUIRE(rdata->rdclass == 1);
253 dns_rdata_toregion(rdata, &r1);
254 r2 = r1;
255 isc_region_consume(&r2, 2);
256 r1.length = 2;
257 RETERR((digest)(arg, &r1));
258 dns_name_init(&name, NULL);
259 dns_name_fromregion(&name, &r2);
260 return (dns_name_digest(&name, digest, arg));
263 static inline isc_boolean_t
264 checkowner_in_kx(ARGS_CHECKOWNER) {
266 REQUIRE(type == 36);
267 REQUIRE(rdclass == 1);
269 UNUSED(name);
270 UNUSED(type);
271 UNUSED(rdclass);
272 UNUSED(wildcard);
274 return (ISC_TRUE);
277 static inline isc_boolean_t
278 checknames_in_kx(ARGS_CHECKNAMES) {
280 REQUIRE(rdata->type == 36);
281 REQUIRE(rdata->rdclass == 1);
283 UNUSED(rdata);
284 UNUSED(owner);
285 UNUSED(bad);
287 return (ISC_TRUE);
290 static inline int
291 casecompare_in_kx(ARGS_COMPARE) {
292 return (compare_in_kx(rdata1, rdata2));
295 #endif /* RDATA_IN_1_KX_36_C */