Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / ch_3 / a_1.c
blob08197096930e0003e4ba215b7f8885808e1527d7
1 /* $NetBSD: a_1.c,v 1.5 2014/12/10 04:37:58 christos Exp $ */
3 /*
4 * Copyright (C) 2005, 2007, 2009, 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: a_1.c,v 1.8 2009/12/04 22:06:37 tbox Exp */
21 /* by Bjorn.Victor@it.uu.se, 2005-05-07 */
22 /* Based on generic/soa_6.c and generic/mx_15.c */
24 #ifndef RDATA_CH_3_A_1_C
25 #define RDATA_CH_3_A_1_C
27 #include <isc/net.h>
29 #define RRTYPE_A_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_ch_a(ARGS_FROMTEXT) {
33 isc_token_t token;
34 dns_name_t name;
35 isc_buffer_t buffer;
37 REQUIRE(type == 1);
38 REQUIRE(rdclass == dns_rdataclass_ch); /* 3 */
40 UNUSED(type);
41 UNUSED(callbacks);
43 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
44 ISC_FALSE));
46 /* get domain name */
47 dns_name_init(&name, NULL);
48 buffer_fromregion(&buffer, &token.value.as_region);
49 origin = (origin != NULL) ? origin : dns_rootname;
50 RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
51 if ((options & DNS_RDATA_CHECKNAMES) != 0 &&
52 (options & DNS_RDATA_CHECKREVERSE) != 0) {
53 isc_boolean_t ok;
54 ok = dns_name_ishostname(&name, ISC_FALSE);
55 if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
56 RETTOK(DNS_R_BADNAME);
57 if (!ok && callbacks != NULL)
58 warn_badname(&name, lexer, callbacks);
61 /* 16-bit octal address */
62 RETERR(isc_lex_getoctaltoken(lexer, &token, ISC_FALSE));
63 if (token.value.as_ulong > 0xffffU)
64 RETTOK(ISC_R_RANGE);
65 return (uint16_tobuffer(token.value.as_ulong, target));
68 static inline isc_result_t
69 totext_ch_a(ARGS_TOTEXT) {
70 isc_region_t region;
71 dns_name_t name;
72 dns_name_t prefix;
73 isc_boolean_t sub;
74 char buf[sizeof("0177777")];
75 isc_uint16_t addr;
77 REQUIRE(rdata->type == 1);
78 REQUIRE(rdata->rdclass == dns_rdataclass_ch); /* 3 */
79 REQUIRE(rdata->length != 0);
81 dns_name_init(&name, NULL);
82 dns_name_init(&prefix, NULL);
84 dns_rdata_toregion(rdata, &region);
85 dns_name_fromregion(&name, &region);
86 isc_region_consume(&region, name_length(&name));
87 addr = uint16_fromregion(&region);
89 sub = name_prefix(&name, tctx->origin, &prefix);
90 RETERR(dns_name_totext(&prefix, sub, target));
92 sprintf(buf, "%o", addr); /* note octal */
93 RETERR(str_totext(" ", target));
94 return (str_totext(buf, target));
97 static inline isc_result_t
98 fromwire_ch_a(ARGS_FROMWIRE) {
99 isc_region_t sregion;
100 isc_region_t tregion;
101 dns_name_t name;
103 REQUIRE(type == 1);
104 REQUIRE(rdclass == dns_rdataclass_ch);
106 UNUSED(type);
107 UNUSED(rdclass);
109 dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
111 dns_name_init(&name, NULL);
113 RETERR(dns_name_fromwire(&name, source, dctx, options, target));
115 isc_buffer_activeregion(source, &sregion);
116 isc_buffer_availableregion(target, &tregion);
117 if (sregion.length < 2)
118 return (ISC_R_UNEXPECTEDEND);
119 if (tregion.length < 2)
120 return (ISC_R_NOSPACE);
122 memmove(tregion.base, sregion.base, 2);
123 isc_buffer_forward(source, 2);
124 isc_buffer_add(target, 2);
126 return (ISC_R_SUCCESS);
129 static inline isc_result_t
130 towire_ch_a(ARGS_TOWIRE) {
131 dns_name_t name;
132 dns_offsets_t offsets;
133 isc_region_t sregion;
134 isc_region_t tregion;
136 REQUIRE(rdata->type == 1);
137 REQUIRE(rdata->rdclass == dns_rdataclass_ch);
138 REQUIRE(rdata->length != 0);
140 dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
142 dns_name_init(&name, offsets);
144 dns_rdata_toregion(rdata, &sregion);
146 dns_name_fromregion(&name, &sregion);
147 isc_region_consume(&sregion, name_length(&name));
148 RETERR(dns_name_towire(&name, cctx, target));
150 isc_buffer_availableregion(target, &tregion);
151 if (tregion.length < 2)
152 return (ISC_R_NOSPACE);
154 memmove(tregion.base, sregion.base, 2);
155 isc_buffer_add(target, 2);
156 return (ISC_R_SUCCESS);
159 static inline int
160 compare_ch_a(ARGS_COMPARE) {
161 dns_name_t name1;
162 dns_name_t name2;
163 isc_region_t region1;
164 isc_region_t region2;
165 int order;
167 REQUIRE(rdata1->type == rdata2->type);
168 REQUIRE(rdata1->rdclass == rdata2->rdclass);
169 REQUIRE(rdata1->type == 1);
170 REQUIRE(rdata1->rdclass == dns_rdataclass_ch);
171 REQUIRE(rdata1->length != 0);
172 REQUIRE(rdata2->length != 0);
174 dns_name_init(&name1, NULL);
175 dns_name_init(&name2, NULL);
177 dns_rdata_toregion(rdata1, &region1);
178 dns_rdata_toregion(rdata2, &region2);
180 dns_name_fromregion(&name1, &region1);
181 dns_name_fromregion(&name2, &region2);
182 isc_region_consume(&region1, name_length(&name1));
183 isc_region_consume(&region2, name_length(&name2));
185 order = dns_name_rdatacompare(&name1, &name2);
186 if (order != 0)
187 return (order);
189 order = memcmp(rdata1->data, rdata2->data, 2);
190 if (order != 0)
191 order = (order < 0) ? -1 : 1;
192 return (order);
195 static inline isc_result_t
196 fromstruct_ch_a(ARGS_FROMSTRUCT) {
197 dns_rdata_ch_a_t *a = source;
198 isc_region_t region;
200 REQUIRE(type == 1);
201 REQUIRE(source != NULL);
202 REQUIRE(a->common.rdtype == type);
203 REQUIRE(a->common.rdclass == rdclass);
205 UNUSED(type);
206 UNUSED(rdclass);
208 dns_name_toregion(&a->ch_addr_dom, &region);
209 RETERR(isc_buffer_copyregion(target, &region));
211 return (uint16_tobuffer(ntohs(a->ch_addr), target));
214 static inline isc_result_t
215 tostruct_ch_a(ARGS_TOSTRUCT) {
216 dns_rdata_ch_a_t *a = target;
217 isc_region_t region;
218 dns_name_t name;
220 REQUIRE(rdata->type == 1);
221 REQUIRE(rdata->rdclass == dns_rdataclass_ch);
222 REQUIRE(rdata->length != 0);
224 a->common.rdclass = rdata->rdclass;
225 a->common.rdtype = rdata->type;
226 ISC_LINK_INIT(&a->common, link);
228 dns_rdata_toregion(rdata, &region);
230 dns_name_init(&name, NULL);
231 dns_name_fromregion(&name, &region);
232 isc_region_consume(&region, name_length(&name));
234 dns_name_init(&a->ch_addr_dom, NULL);
235 RETERR(name_duporclone(&name, mctx, &a->ch_addr_dom));
236 a->ch_addr = htons(uint16_fromregion(&region));
237 a->mctx = mctx;
238 return (ISC_R_SUCCESS);
241 static inline void
242 freestruct_ch_a(ARGS_FREESTRUCT) {
243 dns_rdata_ch_a_t *a = source;
245 REQUIRE(source != NULL);
246 REQUIRE(a->common.rdtype == 1);
248 if (a->mctx == NULL)
249 return;
251 dns_name_free(&a->ch_addr_dom, a->mctx);
252 a->mctx = NULL;
255 static inline isc_result_t
256 additionaldata_ch_a(ARGS_ADDLDATA) {
258 REQUIRE(rdata->type == 1);
259 REQUIRE(rdata->rdclass == dns_rdataclass_ch);
261 UNUSED(rdata);
262 UNUSED(add);
263 UNUSED(arg);
265 return (ISC_R_SUCCESS);
268 static inline isc_result_t
269 digest_ch_a(ARGS_DIGEST) {
270 isc_region_t r;
272 dns_name_t name;
274 REQUIRE(rdata->type == 1);
275 REQUIRE(rdata->rdclass == dns_rdataclass_ch);
277 dns_rdata_toregion(rdata, &r);
278 dns_name_init(&name, NULL);
279 dns_name_fromregion(&name, &r);
280 isc_region_consume(&r, name_length(&name));
281 RETERR(dns_name_digest(&name, digest, arg));
282 return ((digest)(arg, &r));
285 static inline isc_boolean_t
286 checkowner_ch_a(ARGS_CHECKOWNER) {
288 REQUIRE(type == 1);
289 REQUIRE(rdclass == dns_rdataclass_ch);
291 UNUSED(type);
293 return (dns_name_ishostname(name, wildcard));
296 static inline isc_boolean_t
297 checknames_ch_a(ARGS_CHECKNAMES) {
298 isc_region_t region;
299 dns_name_t name;
301 REQUIRE(rdata->type == 1);
302 REQUIRE(rdata->rdclass == dns_rdataclass_ch);
304 UNUSED(owner);
306 dns_rdata_toregion(rdata, &region);
307 dns_name_init(&name, NULL);
308 dns_name_fromregion(&name, &region);
309 if (!dns_name_ishostname(&name, ISC_FALSE)) {
310 if (bad != NULL)
311 dns_name_clone(&name, bad);
312 return (ISC_FALSE);
315 return (ISC_TRUE);
318 static inline int
319 casecompare_ch_a(ARGS_COMPARE) {
320 return (compare_ch_a(rdata1, rdata2));
322 #endif /* RDATA_CH_3_A_1_C */