PageRenderTime 99ms CodeModel.GetById 74ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/freebsd/freebsd-head/
C | 313 lines | 222 code | 66 blank | 25 comment | 44 complexity | f7f8aeee4f995e2f2b439410443074ff MD5 | raw file
  1/*
  2 * Copyright (C) 2004, 2005, 2007, 2009  Internet Systems Consortium, Inc. ("ISC")
  3 * Copyright (C) 1999-2001, 2003  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: afsdb_18.c,v 1.49 2009/12/04 22:06:37 tbox Exp $ */
 19
 20/* Reviewed: Wed Mar 15 14:59:00 PST 2000 by explorer */
 21
 22/* RFC1183 */
 23
 24#ifndef RDATA_GENERIC_AFSDB_18_C
 25#define RDATA_GENERIC_AFSDB_18_C
 26
 27#define RRTYPE_AFSDB_ATTRIBUTES (0)
 28
 29static inline isc_result_t
 30fromtext_afsdb(ARGS_FROMTEXT) {
 31	isc_token_t token;
 32	isc_buffer_t buffer;
 33	dns_name_t name;
 34	isc_boolean_t ok;
 35
 36	REQUIRE(type == 18);
 37
 38	UNUSED(type);
 39	UNUSED(rdclass);
 40	UNUSED(callbacks);
 41
 42	/*
 43	 * Subtype.
 44	 */
 45	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
 46				      ISC_FALSE));
 47	if (token.value.as_ulong > 0xffffU)
 48		RETTOK(ISC_R_RANGE);
 49	RETERR(uint16_tobuffer(token.value.as_ulong, target));
 50
 51	/*
 52	 * Hostname.
 53	 */
 54	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
 55				      ISC_FALSE));
 56	dns_name_init(&name, NULL);
 57	buffer_fromregion(&buffer, &token.value.as_region);
 58	origin = (origin != NULL) ? origin : dns_rootname;
 59	RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
 60	ok = ISC_TRUE;
 61	if ((options & DNS_RDATA_CHECKNAMES) != 0)
 62		ok = dns_name_ishostname(&name, ISC_FALSE);
 63	if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
 64		RETTOK(DNS_R_BADNAME);
 65	if (!ok && callbacks != NULL)
 66		warn_badname(&name, lexer, callbacks);
 67	return (ISC_R_SUCCESS);
 68}
 69
 70static inline isc_result_t
 71totext_afsdb(ARGS_TOTEXT) {
 72	dns_name_t name;
 73	dns_name_t prefix;
 74	isc_region_t region;
 75	char buf[sizeof("64000 ")];
 76	isc_boolean_t sub;
 77	unsigned int num;
 78
 79	REQUIRE(rdata->type == 18);
 80	REQUIRE(rdata->length != 0);
 81
 82	dns_name_init(&name, NULL);
 83	dns_name_init(&prefix, NULL);
 84
 85	dns_rdata_toregion(rdata, &region);
 86	num = uint16_fromregion(&region);
 87	isc_region_consume(&region, 2);
 88	sprintf(buf, "%u ", num);
 89	RETERR(str_totext(buf, target));
 90	dns_name_fromregion(&name, &region);
 91	sub = name_prefix(&name, tctx->origin, &prefix);
 92	return (dns_name_totext(&prefix, sub, target));
 93}
 94
 95static inline isc_result_t
 96fromwire_afsdb(ARGS_FROMWIRE) {
 97	dns_name_t name;
 98	isc_region_t sr;
 99	isc_region_t tr;
100
101	REQUIRE(type == 18);
102
103	UNUSED(type);
104	UNUSED(rdclass);
105
106	dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
107
108	dns_name_init(&name, NULL);
109
110	isc_buffer_activeregion(source, &sr);
111	isc_buffer_availableregion(target, &tr);
112	if (tr.length < 2)
113		return (ISC_R_NOSPACE);
114	if (sr.length < 2)
115		return (ISC_R_UNEXPECTEDEND);
116	memcpy(tr.base, sr.base, 2);
117	isc_buffer_forward(source, 2);
118	isc_buffer_add(target, 2);
119	return (dns_name_fromwire(&name, source, dctx, options, target));
120}
121
122static inline isc_result_t
123towire_afsdb(ARGS_TOWIRE) {
124	isc_region_t tr;
125	isc_region_t sr;
126	dns_name_t name;
127	dns_offsets_t offsets;
128
129	REQUIRE(rdata->type == 18);
130	REQUIRE(rdata->length != 0);
131
132	dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
133	isc_buffer_availableregion(target, &tr);
134	dns_rdata_toregion(rdata, &sr);
135	if (tr.length < 2)
136		return (ISC_R_NOSPACE);
137	memcpy(tr.base, sr.base, 2);
138	isc_region_consume(&sr, 2);
139	isc_buffer_add(target, 2);
140
141	dns_name_init(&name, offsets);
142	dns_name_fromregion(&name, &sr);
143
144	return (dns_name_towire(&name, cctx, target));
145}
146
147static inline int
148compare_afsdb(ARGS_COMPARE) {
149	int result;
150	dns_name_t name1;
151	dns_name_t name2;
152	isc_region_t region1;
153	isc_region_t region2;
154
155	REQUIRE(rdata1->type == rdata2->type);
156	REQUIRE(rdata1->rdclass == rdata2->rdclass);
157	REQUIRE(rdata1->type == 18);
158	REQUIRE(rdata1->length != 0);
159	REQUIRE(rdata2->length != 0);
160
161	result = memcmp(rdata1->data, rdata2->data, 2);
162	if (result != 0)
163		return (result < 0 ? -1 : 1);
164
165	dns_name_init(&name1, NULL);
166	dns_name_init(&name2, NULL);
167
168	dns_rdata_toregion(rdata1, &region1);
169	dns_rdata_toregion(rdata2, &region2);
170
171	isc_region_consume(&region1, 2);
172	isc_region_consume(&region2, 2);
173
174	dns_name_fromregion(&name1, &region1);
175	dns_name_fromregion(&name2, &region2);
176
177	return (dns_name_rdatacompare(&name1, &name2));
178}
179
180static inline isc_result_t
181fromstruct_afsdb(ARGS_FROMSTRUCT) {
182	dns_rdata_afsdb_t *afsdb = source;
183	isc_region_t region;
184
185	REQUIRE(type == 18);
186	REQUIRE(source != NULL);
187	REQUIRE(afsdb->common.rdclass == rdclass);
188	REQUIRE(afsdb->common.rdtype == type);
189
190	UNUSED(type);
191	UNUSED(rdclass);
192
193	RETERR(uint16_tobuffer(afsdb->subtype, target));
194	dns_name_toregion(&afsdb->server, &region);
195	return (isc_buffer_copyregion(target, &region));
196}
197
198static inline isc_result_t
199tostruct_afsdb(ARGS_TOSTRUCT) {
200	isc_region_t region;
201	dns_rdata_afsdb_t *afsdb = target;
202	dns_name_t name;
203
204	REQUIRE(rdata->type == 18);
205	REQUIRE(target != NULL);
206	REQUIRE(rdata->length != 0);
207
208	afsdb->common.rdclass = rdata->rdclass;
209	afsdb->common.rdtype = rdata->type;
210	ISC_LINK_INIT(&afsdb->common, link);
211
212	dns_name_init(&afsdb->server, NULL);
213
214	dns_rdata_toregion(rdata, &region);
215
216	afsdb->subtype = uint16_fromregion(&region);
217	isc_region_consume(&region, 2);
218
219	dns_name_init(&name, NULL);
220	dns_name_fromregion(&name, &region);
221
222	RETERR(name_duporclone(&name, mctx, &afsdb->server));
223	afsdb->mctx = mctx;
224	return (ISC_R_SUCCESS);
225}
226
227static inline void
228freestruct_afsdb(ARGS_FREESTRUCT) {
229	dns_rdata_afsdb_t *afsdb = source;
230
231	REQUIRE(source != NULL);
232	REQUIRE(afsdb->common.rdtype == 18);
233
234	if (afsdb->mctx == NULL)
235		return;
236
237	dns_name_free(&afsdb->server, afsdb->mctx);
238	afsdb->mctx = NULL;
239}
240
241static inline isc_result_t
242additionaldata_afsdb(ARGS_ADDLDATA) {
243	dns_name_t name;
244	dns_offsets_t offsets;
245	isc_region_t region;
246
247	REQUIRE(rdata->type == 18);
248
249	dns_name_init(&name, offsets);
250	dns_rdata_toregion(rdata, &region);
251	isc_region_consume(&region, 2);
252	dns_name_fromregion(&name, &region);
253
254	return ((add)(arg, &name, dns_rdatatype_a));
255}
256
257static inline isc_result_t
258digest_afsdb(ARGS_DIGEST) {
259	isc_region_t r1, r2;
260	dns_name_t name;
261
262	REQUIRE(rdata->type == 18);
263
264	dns_rdata_toregion(rdata, &r1);
265	r2 = r1;
266	isc_region_consume(&r2, 2);
267	r1.length = 2;
268	RETERR((digest)(arg, &r1));
269	dns_name_init(&name, NULL);
270	dns_name_fromregion(&name, &r2);
271
272	return (dns_name_digest(&name, digest, arg));
273}
274
275static inline isc_boolean_t
276checkowner_afsdb(ARGS_CHECKOWNER) {
277
278	REQUIRE(type == 18);
279
280	UNUSED(name);
281	UNUSED(type);
282	UNUSED(rdclass);
283	UNUSED(wildcard);
284
285	return (ISC_TRUE);
286}
287
288static inline isc_boolean_t
289checknames_afsdb(ARGS_CHECKNAMES) {
290	isc_region_t region;
291	dns_name_t name;
292
293	REQUIRE(rdata->type == 18);
294
295	UNUSED(owner);
296
297	dns_rdata_toregion(rdata, &region);
298	isc_region_consume(&region, 2);
299	dns_name_init(&name, NULL);
300	dns_name_fromregion(&name, &region);
301	if (!dns_name_ishostname(&name, ISC_FALSE)) {
302		if (bad != NULL)
303			dns_name_clone(&name, bad);
304		return (ISC_FALSE);
305	}
306	return (ISC_TRUE);
307}
308
309static inline int
310casecompare_afsdb(ARGS_COMPARE) {
311	return (compare_afsdb(rdata1, rdata2));
312}
313#endif	/* RDATA_GENERIC_AFSDB_18_C */