Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / generic / ns_2.c
blobdbcd032fc3347f958a9974380d6b7a93e2d731db
1 /* $NetBSD: ns_2.c,v 1.4 2014/12/10 04:37:59 christos Exp $ */
3 /*
4 * Copyright (C) 2004, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1998-2001 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: ns_2.c,v 1.48 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Wed Mar 15 18:15:00 PST 2000 by bwelling */
24 #ifndef RDATA_GENERIC_NS_2_C
25 #define RDATA_GENERIC_NS_2_C
27 #define RRTYPE_NS_ATTRIBUTES (DNS_RDATATYPEATTR_ZONECUTAUTH)
29 static inline isc_result_t
30 fromtext_ns(ARGS_FROMTEXT) {
31 isc_token_t token;
32 dns_name_t name;
33 isc_buffer_t buffer;
34 isc_boolean_t ok;
36 REQUIRE(type == 2);
38 UNUSED(type);
39 UNUSED(rdclass);
40 UNUSED(callbacks);
42 RETERR(isc_lex_getmastertoken(lexer, &token,isc_tokentype_string,
43 ISC_FALSE));
45 dns_name_init(&name, NULL);
46 buffer_fromregion(&buffer, &token.value.as_region);
47 origin = (origin != NULL) ? origin : dns_rootname;
48 RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
49 ok = ISC_TRUE;
50 if ((options & DNS_RDATA_CHECKNAMES) != 0)
51 ok = dns_name_ishostname(&name, ISC_FALSE);
52 if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
53 RETTOK(DNS_R_BADNAME);
54 if (!ok && callbacks != NULL)
55 warn_badname(&name, lexer, callbacks);
56 return (ISC_R_SUCCESS);
59 static inline isc_result_t
60 totext_ns(ARGS_TOTEXT) {
61 isc_region_t region;
62 dns_name_t name;
63 dns_name_t prefix;
64 isc_boolean_t sub;
66 REQUIRE(rdata->type == 2);
67 REQUIRE(rdata->length != 0);
69 dns_name_init(&name, NULL);
70 dns_name_init(&prefix, NULL);
72 dns_rdata_toregion(rdata, &region);
73 dns_name_fromregion(&name, &region);
75 sub = name_prefix(&name, tctx->origin, &prefix);
77 return (dns_name_totext(&prefix, sub, target));
80 static inline isc_result_t
81 fromwire_ns(ARGS_FROMWIRE) {
82 dns_name_t name;
84 REQUIRE(type == 2);
86 UNUSED(type);
87 UNUSED(rdclass);
89 dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
91 dns_name_init(&name, NULL);
92 return (dns_name_fromwire(&name, source, dctx, options, target));
95 static inline isc_result_t
96 towire_ns(ARGS_TOWIRE) {
97 dns_name_t name;
98 dns_offsets_t offsets;
99 isc_region_t region;
101 REQUIRE(rdata->type == 2);
102 REQUIRE(rdata->length != 0);
104 dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
106 dns_name_init(&name, offsets);
107 dns_rdata_toregion(rdata, &region);
108 dns_name_fromregion(&name, &region);
110 return (dns_name_towire(&name, cctx, target));
113 static inline int
114 compare_ns(ARGS_COMPARE) {
115 dns_name_t name1;
116 dns_name_t name2;
117 isc_region_t region1;
118 isc_region_t region2;
120 REQUIRE(rdata1->type == rdata2->type);
121 REQUIRE(rdata1->rdclass == rdata2->rdclass);
122 REQUIRE(rdata1->type == 2);
123 REQUIRE(rdata1->length != 0);
124 REQUIRE(rdata2->length != 0);
126 dns_name_init(&name1, NULL);
127 dns_name_init(&name2, NULL);
129 dns_rdata_toregion(rdata1, &region1);
130 dns_rdata_toregion(rdata2, &region2);
132 dns_name_fromregion(&name1, &region1);
133 dns_name_fromregion(&name2, &region2);
135 return (dns_name_rdatacompare(&name1, &name2));
138 static inline isc_result_t
139 fromstruct_ns(ARGS_FROMSTRUCT) {
140 dns_rdata_ns_t *ns = source;
141 isc_region_t region;
143 REQUIRE(type == 2);
144 REQUIRE(source != NULL);
145 REQUIRE(ns->common.rdtype == type);
146 REQUIRE(ns->common.rdclass == rdclass);
148 UNUSED(type);
149 UNUSED(rdclass);
151 dns_name_toregion(&ns->name, &region);
152 return (isc_buffer_copyregion(target, &region));
155 static inline isc_result_t
156 tostruct_ns(ARGS_TOSTRUCT) {
157 isc_region_t region;
158 dns_rdata_ns_t *ns = target;
159 dns_name_t name;
161 REQUIRE(rdata->type == 2);
162 REQUIRE(target != NULL);
163 REQUIRE(rdata->length != 0);
165 ns->common.rdclass = rdata->rdclass;
166 ns->common.rdtype = rdata->type;
167 ISC_LINK_INIT(&ns->common, link);
169 dns_name_init(&name, NULL);
170 dns_rdata_toregion(rdata, &region);
171 dns_name_fromregion(&name, &region);
172 dns_name_init(&ns->name, NULL);
173 RETERR(name_duporclone(&name, mctx, &ns->name));
174 ns->mctx = mctx;
175 return (ISC_R_SUCCESS);
178 static inline void
179 freestruct_ns(ARGS_FREESTRUCT) {
180 dns_rdata_ns_t *ns = source;
182 REQUIRE(source != NULL);
184 if (ns->mctx == NULL)
185 return;
187 dns_name_free(&ns->name, ns->mctx);
188 ns->mctx = NULL;
191 static inline isc_result_t
192 additionaldata_ns(ARGS_ADDLDATA) {
193 dns_name_t name;
194 dns_offsets_t offsets;
195 isc_region_t region;
197 REQUIRE(rdata->type == 2);
199 dns_name_init(&name, offsets);
200 dns_rdata_toregion(rdata, &region);
201 dns_name_fromregion(&name, &region);
203 return ((add)(arg, &name, dns_rdatatype_a));
206 static inline isc_result_t
207 digest_ns(ARGS_DIGEST) {
208 isc_region_t r;
209 dns_name_t name;
211 REQUIRE(rdata->type == 2);
213 dns_rdata_toregion(rdata, &r);
214 dns_name_init(&name, NULL);
215 dns_name_fromregion(&name, &r);
217 return (dns_name_digest(&name, digest, arg));
220 static inline isc_boolean_t
221 checkowner_ns(ARGS_CHECKOWNER) {
223 REQUIRE(type == 2);
225 UNUSED(name);
226 UNUSED(type);
227 UNUSED(rdclass);
228 UNUSED(wildcard);
230 return (ISC_TRUE);
233 static inline isc_boolean_t
234 checknames_ns(ARGS_CHECKNAMES) {
235 isc_region_t region;
236 dns_name_t name;
238 REQUIRE(rdata->type == 2);
240 UNUSED(owner);
242 dns_rdata_toregion(rdata, &region);
243 dns_name_init(&name, NULL);
244 dns_name_fromregion(&name, &region);
245 if (!dns_name_ishostname(&name, ISC_FALSE)) {
246 if (bad != NULL)
247 dns_name_clone(&name, bad);
248 return (ISC_FALSE);
250 return (ISC_TRUE);
253 static inline int
254 casecompare_ns(ARGS_COMPARE) {
255 return (compare_ns(rdata1, rdata2));
258 #endif /* RDATA_GENERIC_NS_2_C */