PageRenderTime 54ms CodeModel.GetById 16ms app.highlight 34ms RepoModel.GetById 2ms app.codeStats 0ms

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

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