PageRenderTime 30ms CodeModel.GetById 14ms app.highlight 14ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/freebsd/freebsd-head/
C | 237 lines | 159 code | 59 blank | 19 comment | 27 complexity | 55e2ac90bed32ff06e00c8b28ed4523a MD5 | raw file
  1/*
  2 * Copyright (C) 2004, 2007, 2009  Internet Systems Consortium, Inc. ("ISC")
  3 * Copyright (C) 1999-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: dname_39.c,v 1.40 2009/12/04 22:06:37 tbox Exp $ */
 19
 20/* Reviewed: Wed Mar 15 16:52:38 PST 2000 by explorer */
 21
 22/* RFC2672 */
 23
 24#ifndef RDATA_GENERIC_DNAME_39_C
 25#define RDATA_GENERIC_DNAME_39_C
 26
 27#define RRTYPE_DNAME_ATTRIBUTES (DNS_RDATATYPEATTR_SINGLETON)
 28
 29static inline isc_result_t
 30fromtext_dname(ARGS_FROMTEXT) {
 31	isc_token_t token;
 32	dns_name_t name;
 33	isc_buffer_t buffer;
 34
 35	REQUIRE(type == 39);
 36
 37	UNUSED(type);
 38	UNUSED(rdclass);
 39	UNUSED(callbacks);
 40
 41	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
 42				      ISC_FALSE));
 43
 44	dns_name_init(&name, NULL);
 45	buffer_fromregion(&buffer, &token.value.as_region);
 46	origin = (origin != NULL) ? origin : dns_rootname;
 47	RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
 48	return (ISC_R_SUCCESS);
 49}
 50
 51static inline isc_result_t
 52totext_dname(ARGS_TOTEXT) {
 53	isc_region_t region;
 54	dns_name_t name;
 55	dns_name_t prefix;
 56	isc_boolean_t sub;
 57
 58	REQUIRE(rdata->type == 39);
 59	REQUIRE(rdata->length != 0);
 60
 61	dns_name_init(&name, NULL);
 62	dns_name_init(&prefix, NULL);
 63
 64	dns_rdata_toregion(rdata, &region);
 65	dns_name_fromregion(&name, &region);
 66
 67	sub = name_prefix(&name, tctx->origin, &prefix);
 68
 69	return (dns_name_totext(&prefix, sub, target));
 70}
 71
 72static inline isc_result_t
 73fromwire_dname(ARGS_FROMWIRE) {
 74	dns_name_t name;
 75
 76	REQUIRE(type == 39);
 77
 78	UNUSED(type);
 79	UNUSED(rdclass);
 80
 81	dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
 82
 83	dns_name_init(&name, NULL);
 84	return(dns_name_fromwire(&name, source, dctx, options, target));
 85}
 86
 87static inline isc_result_t
 88towire_dname(ARGS_TOWIRE) {
 89	dns_name_t name;
 90	dns_offsets_t offsets;
 91	isc_region_t region;
 92
 93	REQUIRE(rdata->type == 39);
 94	REQUIRE(rdata->length != 0);
 95
 96	dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
 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_dname(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 == 39);
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_dname(ARGS_FROMSTRUCT) {
131	dns_rdata_dname_t *dname = source;
132	isc_region_t region;
133
134	REQUIRE(type == 39);
135	REQUIRE(source != NULL);
136	REQUIRE(dname->common.rdtype == type);
137	REQUIRE(dname->common.rdclass == rdclass);
138
139	UNUSED(type);
140	UNUSED(rdclass);
141
142	dns_name_toregion(&dname->dname, &region);
143	return (isc_buffer_copyregion(target, &region));
144}
145
146static inline isc_result_t
147tostruct_dname(ARGS_TOSTRUCT) {
148	isc_region_t region;
149	dns_rdata_dname_t *dname = target;
150	dns_name_t name;
151
152	REQUIRE(rdata->type == 39);
153	REQUIRE(target != NULL);
154	REQUIRE(rdata->length != 0);
155
156	dname->common.rdclass = rdata->rdclass;
157	dname->common.rdtype = rdata->type;
158	ISC_LINK_INIT(&dname->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(&dname->dname, NULL);
164	RETERR(name_duporclone(&name, mctx, &dname->dname));
165	dname->mctx = mctx;
166	return (ISC_R_SUCCESS);
167}
168
169static inline void
170freestruct_dname(ARGS_FREESTRUCT) {
171	dns_rdata_dname_t *dname = source;
172
173	REQUIRE(source != NULL);
174	REQUIRE(dname->common.rdtype == 39);
175
176	if (dname->mctx == NULL)
177		return;
178
179	dns_name_free(&dname->dname, dname->mctx);
180	dname->mctx = NULL;
181}
182
183static inline isc_result_t
184additionaldata_dname(ARGS_ADDLDATA) {
185	UNUSED(rdata);
186	UNUSED(add);
187	UNUSED(arg);
188
189	REQUIRE(rdata->type == 39);
190
191	return (ISC_R_SUCCESS);
192}
193
194static inline isc_result_t
195digest_dname(ARGS_DIGEST) {
196	isc_region_t r;
197	dns_name_t name;
198
199	REQUIRE(rdata->type == 39);
200
201	dns_rdata_toregion(rdata, &r);
202	dns_name_init(&name, NULL);
203	dns_name_fromregion(&name, &r);
204
205	return (dns_name_digest(&name, digest, arg));
206}
207
208static inline isc_boolean_t
209checkowner_dname(ARGS_CHECKOWNER) {
210
211	REQUIRE(type == 39);
212
213	UNUSED(name);
214	UNUSED(type);
215	UNUSED(rdclass);
216	UNUSED(wildcard);
217
218	return (ISC_TRUE);
219}
220
221static inline isc_boolean_t
222checknames_dname(ARGS_CHECKNAMES) {
223
224	REQUIRE(rdata->type == 39);
225
226	UNUSED(rdata);
227	UNUSED(owner);
228	UNUSED(bad);
229
230	return (ISC_TRUE);
231}
232
233static inline int
234casecompare_dname(ARGS_COMPARE) {
235	return (compare_dname(rdata1, rdata2));
236}
237#endif	/* RDATA_GENERIC_DNAME_39_C */