PageRenderTime 23ms CodeModel.GetById 1ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/freebsd/freebsd-head/
C | 237 lines | 159 code | 60 blank | 18 comment | 26 complexity | ff5a5c9cb12fe8b31e9174655ab063be 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: cname_5.c,v 1.49 2009/12/04 22:06:37 tbox Exp $ */
 19
 20/* reviewed: Wed Mar 15 16:48:45 PST 2000 by brister */
 21
 22#ifndef RDATA_GENERIC_CNAME_5_C
 23#define RDATA_GENERIC_CNAME_5_C
 24
 25#define RRTYPE_CNAME_ATTRIBUTES \
 26	(DNS_RDATATYPEATTR_EXCLUSIVE | DNS_RDATATYPEATTR_SINGLETON)
 27
 28static inline isc_result_t
 29fromtext_cname(ARGS_FROMTEXT) {
 30	isc_token_t token;
 31	dns_name_t name;
 32	isc_buffer_t buffer;
 33
 34	REQUIRE(type == 5);
 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	return (ISC_R_SUCCESS);
 48}
 49
 50static inline isc_result_t
 51totext_cname(ARGS_TOTEXT) {
 52	isc_region_t region;
 53	dns_name_t name;
 54	dns_name_t prefix;
 55	isc_boolean_t sub;
 56
 57	REQUIRE(rdata->type == 5);
 58	REQUIRE(rdata->length != 0);
 59
 60	dns_name_init(&name, NULL);
 61	dns_name_init(&prefix, NULL);
 62
 63	dns_rdata_toregion(rdata, &region);
 64	dns_name_fromregion(&name, &region);
 65
 66	sub = name_prefix(&name, tctx->origin, &prefix);
 67
 68	return (dns_name_totext(&prefix, sub, target));
 69}
 70
 71static inline isc_result_t
 72fromwire_cname(ARGS_FROMWIRE) {
 73	dns_name_t name;
 74
 75	REQUIRE(type == 5);
 76
 77	UNUSED(type);
 78	UNUSED(rdclass);
 79
 80	dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
 81
 82	dns_name_init(&name, NULL);
 83	return (dns_name_fromwire(&name, source, dctx, options, target));
 84}
 85
 86static inline isc_result_t
 87towire_cname(ARGS_TOWIRE) {
 88	dns_name_t name;
 89	dns_offsets_t offsets;
 90	isc_region_t region;
 91
 92	REQUIRE(rdata->type == 5);
 93	REQUIRE(rdata->length != 0);
 94
 95	dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
 96
 97	dns_name_init(&name, offsets);
 98	dns_rdata_toregion(rdata, &region);
 99	dns_name_fromregion(&name, &region);
100
101	return (dns_name_towire(&name, cctx, target));
102}
103
104static inline int
105compare_cname(ARGS_COMPARE) {
106	dns_name_t name1;
107	dns_name_t name2;
108	isc_region_t region1;
109	isc_region_t region2;
110
111	REQUIRE(rdata1->type == rdata2->type);
112	REQUIRE(rdata1->rdclass == rdata2->rdclass);
113	REQUIRE(rdata1->type == 5);
114	REQUIRE(rdata1->length != 0);
115	REQUIRE(rdata2->length != 0);
116
117	dns_name_init(&name1, NULL);
118	dns_name_init(&name2, NULL);
119
120	dns_rdata_toregion(rdata1, &region1);
121	dns_rdata_toregion(rdata2, &region2);
122
123	dns_name_fromregion(&name1, &region1);
124	dns_name_fromregion(&name2, &region2);
125
126	return (dns_name_rdatacompare(&name1, &name2));
127}
128
129static inline isc_result_t
130fromstruct_cname(ARGS_FROMSTRUCT) {
131	dns_rdata_cname_t *cname = source;
132	isc_region_t region;
133
134	REQUIRE(type == 5);
135	REQUIRE(source != NULL);
136	REQUIRE(cname->common.rdtype == type);
137	REQUIRE(cname->common.rdclass == rdclass);
138
139	UNUSED(type);
140	UNUSED(rdclass);
141
142	dns_name_toregion(&cname->cname, &region);
143	return (isc_buffer_copyregion(target, &region));
144}
145
146static inline isc_result_t
147tostruct_cname(ARGS_TOSTRUCT) {
148	isc_region_t region;
149	dns_rdata_cname_t *cname = target;
150	dns_name_t name;
151
152	REQUIRE(rdata->type == 5);
153	REQUIRE(target != NULL);
154	REQUIRE(rdata->length != 0);
155
156	cname->common.rdclass = rdata->rdclass;
157	cname->common.rdtype = rdata->type;
158	ISC_LINK_INIT(&cname->common, link);
159
160	dns_name_init(&name, NULL);
161	dns_rdata_toregion(rdata, &region);
162	dns_name_fromregion(&name, &region);
163	dns_name_init(&cname->cname, NULL);
164	RETERR(name_duporclone(&name, mctx, &cname->cname));
165	cname->mctx = mctx;
166	return (ISC_R_SUCCESS);
167}
168
169static inline void
170freestruct_cname(ARGS_FREESTRUCT) {
171	dns_rdata_cname_t *cname = source;
172
173	REQUIRE(source != NULL);
174
175	if (cname->mctx == NULL)
176		return;
177
178	dns_name_free(&cname->cname, cname->mctx);
179	cname->mctx = NULL;
180}
181
182static inline isc_result_t
183additionaldata_cname(ARGS_ADDLDATA) {
184	UNUSED(rdata);
185	UNUSED(add);
186	UNUSED(arg);
187
188	REQUIRE(rdata->type == 5);
189
190	return (ISC_R_SUCCESS);
191}
192
193static inline isc_result_t
194digest_cname(ARGS_DIGEST) {
195	isc_region_t r;
196	dns_name_t name;
197
198	REQUIRE(rdata->type == 5);
199
200	dns_rdata_toregion(rdata, &r);
201	dns_name_init(&name, NULL);
202	dns_name_fromregion(&name, &r);
203
204	return (dns_name_digest(&name, digest, arg));
205}
206
207static inline isc_boolean_t
208checkowner_cname(ARGS_CHECKOWNER) {
209
210	REQUIRE(type == 5);
211
212	UNUSED(name);
213	UNUSED(type);
214	UNUSED(rdclass);
215	UNUSED(wildcard);
216
217	return (ISC_TRUE);
218}
219
220static inline isc_boolean_t
221checknames_cname(ARGS_CHECKNAMES) {
222
223	REQUIRE(rdata->type == 5);
224
225	UNUSED(rdata);
226	UNUSED(owner);
227	UNUSED(bad);
228
229	return (ISC_TRUE);
230}
231
232static inline int
233casecompare_cname(ARGS_COMPARE) {
234	return (compare_cname(rdata1, rdata2));
235}
236
237#endif	/* RDATA_GENERIC_CNAME_5_C */