PageRenderTime 29ms CodeModel.GetById 1ms app.highlight 23ms RepoModel.GetById 1ms app.codeStats 1ms

/contrib/bind9/lib/dns/rdata/in_1/dhcid_49.c

https://bitbucket.org/freebsd/freebsd-head/
C | 234 lines | 162 code | 55 blank | 17 comment | 50 complexity | e2e06517e2b105aae94cfbeea13c416c MD5 | raw file
  1/*
  2 * Copyright (C) 2006, 2007, 2009, 2012  Internet Systems Consortium, Inc. ("ISC")
  3 *
  4 * Permission to use, copy, modify, and/or distribute this software for any
  5 * purpose with or without fee is hereby granted, provided that the above
  6 * copyright notice and this permission notice appear in all copies.
  7 *
  8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 10 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 14 * PERFORMANCE OF THIS SOFTWARE.
 15 */
 16
 17/* $Id$ */
 18
 19/* RFC 4701 */
 20
 21#ifndef RDATA_IN_1_DHCID_49_C
 22#define RDATA_IN_1_DHCID_49_C 1
 23
 24#define RRTYPE_DHCID_ATTRIBUTES 0
 25
 26static inline isc_result_t
 27fromtext_in_dhcid(ARGS_FROMTEXT) {
 28
 29	REQUIRE(type == 49);
 30	REQUIRE(rdclass == 1);
 31
 32	UNUSED(type);
 33	UNUSED(rdclass);
 34	UNUSED(origin);
 35	UNUSED(options);
 36	UNUSED(callbacks);
 37
 38	return (isc_base64_tobuffer(lexer, target, -1));
 39}
 40
 41static inline isc_result_t
 42totext_in_dhcid(ARGS_TOTEXT) {
 43	isc_region_t sr;
 44	char buf[sizeof(" ; 64000 255 64000")];
 45	size_t n;
 46
 47	REQUIRE(rdata->type == 49);
 48	REQUIRE(rdata->rdclass == 1);
 49	REQUIRE(rdata->length != 0);
 50
 51	dns_rdata_toregion(rdata, &sr);
 52
 53	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
 54		RETERR(str_totext("( " /*)*/, target));
 55	RETERR(isc_base64_totext(&sr, tctx->width - 2, tctx->linebreak,
 56				 target));
 57	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
 58		RETERR(str_totext(/* ( */ " )", target));
 59		if (rdata->length > 2) {
 60			n = snprintf(buf, sizeof(buf), " ; %u %u %u",
 61				     sr.base[0] * 256 + sr.base[1],
 62				     sr.base[2], rdata->length - 3);
 63			INSIST(n < sizeof(buf));
 64			RETERR(str_totext(buf, target));
 65		}
 66	}
 67	return (ISC_R_SUCCESS);
 68}
 69
 70static inline isc_result_t
 71fromwire_in_dhcid(ARGS_FROMWIRE) {
 72	isc_region_t sr;
 73
 74	REQUIRE(type == 49);
 75	REQUIRE(rdclass == 1);
 76
 77	UNUSED(type);
 78	UNUSED(rdclass);
 79	UNUSED(dctx);
 80	UNUSED(options);
 81
 82	isc_buffer_activeregion(source, &sr);
 83	if (sr.length == 0)
 84		return (ISC_R_UNEXPECTEDEND);
 85
 86	isc_buffer_forward(source, sr.length);
 87	return (mem_tobuffer(target, sr.base, sr.length));
 88}
 89
 90static inline isc_result_t
 91towire_in_dhcid(ARGS_TOWIRE) {
 92	isc_region_t sr;
 93
 94	REQUIRE(rdata->type == 49);
 95	REQUIRE(rdata->rdclass == 1);
 96	REQUIRE(rdata->length != 0);
 97
 98	UNUSED(cctx);
 99
100	dns_rdata_toregion(rdata, &sr);
101	return (mem_tobuffer(target, sr.base, sr.length));
102}
103
104static inline int
105compare_in_dhcid(ARGS_COMPARE) {
106	isc_region_t r1;
107	isc_region_t r2;
108
109	REQUIRE(rdata1->type == rdata2->type);
110	REQUIRE(rdata1->rdclass == rdata2->rdclass);
111	REQUIRE(rdata1->type == 49);
112	REQUIRE(rdata1->rdclass == 1);
113	REQUIRE(rdata1->length != 0);
114	REQUIRE(rdata2->length != 0);
115
116	dns_rdata_toregion(rdata1, &r1);
117	dns_rdata_toregion(rdata2, &r2);
118	return (isc_region_compare(&r1, &r2));
119}
120
121static inline isc_result_t
122fromstruct_in_dhcid(ARGS_FROMSTRUCT) {
123	dns_rdata_in_dhcid_t *dhcid = source;
124
125	REQUIRE(type == 49);
126	REQUIRE(rdclass == 1);
127	REQUIRE(source != NULL);
128	REQUIRE(dhcid->common.rdtype == type);
129	REQUIRE(dhcid->common.rdclass == rdclass);
130	REQUIRE(dhcid->length != 0);
131
132	UNUSED(type);
133	UNUSED(rdclass);
134
135	return (mem_tobuffer(target, dhcid->dhcid, dhcid->length));
136}
137
138static inline isc_result_t
139tostruct_in_dhcid(ARGS_TOSTRUCT) {
140	dns_rdata_in_dhcid_t *dhcid = target;
141	isc_region_t region;
142
143	REQUIRE(rdata->type == 49);
144	REQUIRE(rdata->rdclass == 1);
145	REQUIRE(target != NULL);
146	REQUIRE(rdata->length != 0);
147
148	dhcid->common.rdclass = rdata->rdclass;
149	dhcid->common.rdtype = rdata->type;
150	ISC_LINK_INIT(&dhcid->common, link);
151
152	dns_rdata_toregion(rdata, &region);
153
154	dhcid->dhcid = mem_maybedup(mctx, region.base, region.length);
155	if (dhcid->dhcid == NULL)
156		return (ISC_R_NOMEMORY);
157
158	dhcid->mctx = mctx;
159	return (ISC_R_SUCCESS);
160}
161
162static inline void
163freestruct_in_dhcid(ARGS_FREESTRUCT) {
164	dns_rdata_in_dhcid_t *dhcid = source;
165
166	REQUIRE(dhcid != NULL);
167	REQUIRE(dhcid->common.rdtype == 49);
168	REQUIRE(dhcid->common.rdclass == 1);
169
170	if (dhcid->mctx == NULL)
171		return;
172
173	if (dhcid->dhcid != NULL)
174		isc_mem_free(dhcid->mctx, dhcid->dhcid);
175	dhcid->mctx = NULL;
176}
177
178static inline isc_result_t
179additionaldata_in_dhcid(ARGS_ADDLDATA) {
180	REQUIRE(rdata->type == 49);
181	REQUIRE(rdata->rdclass == 1);
182
183	UNUSED(rdata);
184	UNUSED(add);
185	UNUSED(arg);
186
187	return (ISC_R_SUCCESS);
188}
189
190static inline isc_result_t
191digest_in_dhcid(ARGS_DIGEST) {
192	isc_region_t r;
193
194	REQUIRE(rdata->type == 49);
195	REQUIRE(rdata->rdclass == 1);
196
197	dns_rdata_toregion(rdata, &r);
198
199	return ((digest)(arg, &r));
200}
201
202static inline isc_boolean_t
203checkowner_in_dhcid(ARGS_CHECKOWNER) {
204
205	REQUIRE(type == 49);
206	REQUIRE(rdclass == 1);
207
208	UNUSED(name);
209	UNUSED(type);
210	UNUSED(rdclass);
211	UNUSED(wildcard);
212
213	return (ISC_TRUE);
214}
215
216static inline isc_boolean_t
217checknames_in_dhcid(ARGS_CHECKNAMES) {
218
219	REQUIRE(rdata->type == 49);
220	REQUIRE(rdata->rdclass == 1);
221
222	UNUSED(rdata);
223	UNUSED(owner);
224	UNUSED(bad);
225
226	return (ISC_TRUE);
227}
228
229static inline int
230casecompare_in_dhcid(ARGS_COMPARE) {
231	return (compare_in_dhcid(rdata1, rdata2));
232}
233
234#endif	/* RDATA_IN_1_DHCID_49_C */