PageRenderTime 67ms CodeModel.GetById 37ms app.highlight 25ms RepoModel.GetById 1ms app.codeStats 0ms

/contrib/bind9/lib/dns/rdata/generic/ns_2.c

https://bitbucket.org/freebsd/freebsd-head/
C | 256 lines | 177 code | 61 blank | 18 comment | 37 complexity | 51a84af013a1f6659f30a3c3964e87b4 MD5 | raw file
  1/*
  2 * Copyright (C) 2004, 2007, 2009  Internet Systems Consortium, Inc. ("ISC")
  3 * Copyright (C) 1998-2001  Internet Software Consortium.
  4 *
  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.
  8 *
  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.
 16 */
 17
 18/* $Id: ns_2.c,v 1.48 2009/12/04 22:06:37 tbox Exp $ */
 19
 20/* Reviewed: Wed Mar 15 18:15:00 PST 2000 by bwelling */
 21
 22#ifndef RDATA_GENERIC_NS_2_C
 23#define RDATA_GENERIC_NS_2_C
 24
 25#define RRTYPE_NS_ATTRIBUTES (DNS_RDATATYPEATTR_ZONECUTAUTH)
 26
 27static inline isc_result_t
 28fromtext_ns(ARGS_FROMTEXT) {
 29	isc_token_t token;
 30	dns_name_t name;
 31	isc_buffer_t buffer;
 32	isc_boolean_t ok;
 33
 34	REQUIRE(type == 2);
 35
 36	UNUSED(type);
 37	UNUSED(rdclass);
 38	UNUSED(callbacks);
 39
 40	RETERR(isc_lex_getmastertoken(lexer, &token,isc_tokentype_string,
 41				      ISC_FALSE));
 42
 43	dns_name_init(&name, NULL);
 44	buffer_fromregion(&buffer, &token.value.as_region);
 45	origin = (origin != NULL) ? origin : dns_rootname;
 46	RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
 47	ok = ISC_TRUE;
 48	if ((options & DNS_RDATA_CHECKNAMES) != 0)
 49		ok = dns_name_ishostname(&name, ISC_FALSE);
 50	if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
 51		RETTOK(DNS_R_BADNAME);
 52	if (!ok && callbacks != NULL)
 53		warn_badname(&name, lexer, callbacks);
 54	return (ISC_R_SUCCESS);
 55}
 56
 57static inline isc_result_t
 58totext_ns(ARGS_TOTEXT) {
 59	isc_region_t region;
 60	dns_name_t name;
 61	dns_name_t prefix;
 62	isc_boolean_t sub;
 63
 64	REQUIRE(rdata->type == 2);
 65	REQUIRE(rdata->length != 0);
 66
 67	dns_name_init(&name, NULL);
 68	dns_name_init(&prefix, NULL);
 69
 70	dns_rdata_toregion(rdata, &region);
 71	dns_name_fromregion(&name, &region);
 72
 73	sub = name_prefix(&name, tctx->origin, &prefix);
 74
 75	return (dns_name_totext(&prefix, sub, target));
 76}
 77
 78static inline isc_result_t
 79fromwire_ns(ARGS_FROMWIRE) {
 80	dns_name_t name;
 81
 82	REQUIRE(type == 2);
 83
 84	UNUSED(type);
 85	UNUSED(rdclass);
 86
 87	dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
 88
 89	dns_name_init(&name, NULL);
 90	return (dns_name_fromwire(&name, source, dctx, options, target));
 91}
 92
 93static inline isc_result_t
 94towire_ns(ARGS_TOWIRE) {
 95	dns_name_t name;
 96	dns_offsets_t offsets;
 97	isc_region_t region;
 98
 99	REQUIRE(rdata->type == 2);
100	REQUIRE(rdata->length != 0);
101
102	dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
103
104	dns_name_init(&name, offsets);
105	dns_rdata_toregion(rdata, &region);
106	dns_name_fromregion(&name, &region);
107
108	return (dns_name_towire(&name, cctx, target));
109}
110
111static inline int
112compare_ns(ARGS_COMPARE) {
113	dns_name_t name1;
114	dns_name_t name2;
115	isc_region_t region1;
116	isc_region_t region2;
117
118	REQUIRE(rdata1->type == rdata2->type);
119	REQUIRE(rdata1->rdclass == rdata2->rdclass);
120	REQUIRE(rdata1->type == 2);
121	REQUIRE(rdata1->length != 0);
122	REQUIRE(rdata2->length != 0);
123
124	dns_name_init(&name1, NULL);
125	dns_name_init(&name2, NULL);
126
127	dns_rdata_toregion(rdata1, &region1);
128	dns_rdata_toregion(rdata2, &region2);
129
130	dns_name_fromregion(&name1, &region1);
131	dns_name_fromregion(&name2, &region2);
132
133	return (dns_name_rdatacompare(&name1, &name2));
134}
135
136static inline isc_result_t
137fromstruct_ns(ARGS_FROMSTRUCT) {
138	dns_rdata_ns_t *ns = source;
139	isc_region_t region;
140
141	REQUIRE(type == 2);
142	REQUIRE(source != NULL);
143	REQUIRE(ns->common.rdtype == type);
144	REQUIRE(ns->common.rdclass == rdclass);
145
146	UNUSED(type);
147	UNUSED(rdclass);
148
149	dns_name_toregion(&ns->name, &region);
150	return (isc_buffer_copyregion(target, &region));
151}
152
153static inline isc_result_t
154tostruct_ns(ARGS_TOSTRUCT) {
155	isc_region_t region;
156	dns_rdata_ns_t *ns = target;
157	dns_name_t name;
158
159	REQUIRE(rdata->type == 2);
160	REQUIRE(target != NULL);
161	REQUIRE(rdata->length != 0);
162
163	ns->common.rdclass = rdata->rdclass;
164	ns->common.rdtype = rdata->type;
165	ISC_LINK_INIT(&ns->common, link);
166
167	dns_name_init(&name, NULL);
168	dns_rdata_toregion(rdata, &region);
169	dns_name_fromregion(&name, &region);
170	dns_name_init(&ns->name, NULL);
171	RETERR(name_duporclone(&name, mctx, &ns->name));
172	ns->mctx = mctx;
173	return (ISC_R_SUCCESS);
174}
175
176static inline void
177freestruct_ns(ARGS_FREESTRUCT) {
178	dns_rdata_ns_t *ns = source;
179
180	REQUIRE(source != NULL);
181
182	if (ns->mctx == NULL)
183		return;
184
185	dns_name_free(&ns->name, ns->mctx);
186	ns->mctx = NULL;
187}
188
189static inline isc_result_t
190additionaldata_ns(ARGS_ADDLDATA) {
191	dns_name_t name;
192	dns_offsets_t offsets;
193	isc_region_t region;
194
195	REQUIRE(rdata->type == 2);
196
197	dns_name_init(&name, offsets);
198	dns_rdata_toregion(rdata, &region);
199	dns_name_fromregion(&name, &region);
200
201	return ((add)(arg, &name, dns_rdatatype_a));
202}
203
204static inline isc_result_t
205digest_ns(ARGS_DIGEST) {
206	isc_region_t r;
207	dns_name_t name;
208
209	REQUIRE(rdata->type == 2);
210
211	dns_rdata_toregion(rdata, &r);
212	dns_name_init(&name, NULL);
213	dns_name_fromregion(&name, &r);
214
215	return (dns_name_digest(&name, digest, arg));
216}
217
218static inline isc_boolean_t
219checkowner_ns(ARGS_CHECKOWNER) {
220
221	REQUIRE(type == 2);
222
223	UNUSED(name);
224	UNUSED(type);
225	UNUSED(rdclass);
226	UNUSED(wildcard);
227
228	return (ISC_TRUE);
229}
230
231static inline isc_boolean_t
232checknames_ns(ARGS_CHECKNAMES) {
233	isc_region_t region;
234	dns_name_t name;
235
236	REQUIRE(rdata->type == 2);
237
238	UNUSED(owner);
239
240	dns_rdata_toregion(rdata, &region);
241	dns_name_init(&name, NULL);
242	dns_name_fromregion(&name, &region);
243	if (!dns_name_ishostname(&name, ISC_FALSE)) {
244		if (bad != NULL)
245			dns_name_clone(&name, bad);
246		return (ISC_FALSE);
247	}
248	return (ISC_TRUE);
249}
250
251static inline int
252casecompare_ns(ARGS_COMPARE) {
253	return (compare_ns(rdata1, rdata2));
254}
255
256#endif	/* RDATA_GENERIC_NS_2_C */