nimloc_32.c revision 1.5
1/*	$NetBSD: nimloc_32.c,v 1.5 2019/11/27 05:48:42 christos Exp $	*/
2
3/*
4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 *
10 * See the COPYRIGHT file distributed with this work for additional
11 * information regarding copyright ownership.
12 */
13
14/* http://ana-3.lcs.mit.edu/~jnc/nimrod/dns.txt */
15
16#ifndef RDATA_IN_1_NIMLOC_32_C
17#define RDATA_IN_1_NIMLOC_32_C
18
19#define RRTYPE_NIMLOC_ATTRIBUTES (0)
20
21static inline isc_result_t
22fromtext_in_nimloc(ARGS_FROMTEXT) {
23
24	REQUIRE(type == dns_rdatatype_nimloc);
25	REQUIRE(rdclass == dns_rdataclass_in);
26
27	UNUSED(type);
28	UNUSED(origin);
29	UNUSED(options);
30	UNUSED(rdclass);
31	UNUSED(callbacks);
32
33	return (isc_hex_tobuffer(lexer, target, -2));
34}
35
36static inline isc_result_t
37totext_in_nimloc(ARGS_TOTEXT) {
38	isc_region_t region;
39
40	REQUIRE(rdata->type == dns_rdatatype_nimloc);
41	REQUIRE(rdata->rdclass == dns_rdataclass_in);
42	REQUIRE(rdata->length != 0);
43
44	dns_rdata_toregion(rdata, &region);
45
46	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
47		RETERR(str_totext("( ", target));
48	}
49	if (tctx->width == 0) {
50		RETERR(isc_hex_totext(&region, 60, "", target));
51	} else {
52		RETERR(isc_hex_totext(&region, tctx->width - 2,
53				      tctx->linebreak, target));
54	}
55	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
56		RETERR(str_totext(" )", target));
57	}
58	return (ISC_R_SUCCESS);
59}
60
61static inline isc_result_t
62fromwire_in_nimloc(ARGS_FROMWIRE) {
63	isc_region_t region;
64
65	REQUIRE(type == dns_rdatatype_nimloc);
66	REQUIRE(rdclass == dns_rdataclass_in);
67
68	UNUSED(type);
69	UNUSED(dctx);
70	UNUSED(options);
71	UNUSED(rdclass);
72
73	isc_buffer_activeregion(source, &region);
74	if (region.length < 1) {
75		return (ISC_R_UNEXPECTEDEND);
76	}
77
78	RETERR(mem_tobuffer(target, region.base, region.length));
79	isc_buffer_forward(source, region.length);
80	return (ISC_R_SUCCESS);
81}
82
83static inline isc_result_t
84towire_in_nimloc(ARGS_TOWIRE) {
85	REQUIRE(rdata->type == dns_rdatatype_nimloc);
86	REQUIRE(rdata->rdclass == dns_rdataclass_in);
87	REQUIRE(rdata->length != 0);
88
89	UNUSED(cctx);
90
91	return (mem_tobuffer(target, rdata->data, rdata->length));
92}
93
94static inline int
95compare_in_nimloc(ARGS_COMPARE) {
96	isc_region_t r1;
97	isc_region_t r2;
98
99	REQUIRE(rdata1->type == rdata2->type);
100	REQUIRE(rdata1->rdclass == rdata2->rdclass);
101	REQUIRE(rdata1->type == dns_rdatatype_nimloc);
102	REQUIRE(rdata1->rdclass == dns_rdataclass_in);
103	REQUIRE(rdata1->length != 0);
104	REQUIRE(rdata2->length != 0);
105
106	dns_rdata_toregion(rdata1, &r1);
107	dns_rdata_toregion(rdata2, &r2);
108	return (isc_region_compare(&r1, &r2));
109}
110
111static inline isc_result_t
112fromstruct_in_nimloc(ARGS_FROMSTRUCT) {
113	dns_rdata_in_nimloc_t *nimloc = source;
114
115	REQUIRE(type == dns_rdatatype_nimloc);
116	REQUIRE(rdclass == dns_rdataclass_in);
117	REQUIRE(nimloc != NULL);
118	REQUIRE(nimloc->common.rdtype == type);
119	REQUIRE(nimloc->common.rdclass == rdclass);
120	REQUIRE(nimloc->nimloc != NULL || nimloc->nimloc_len == 0);
121
122	UNUSED(type);
123	UNUSED(rdclass);
124
125	return (mem_tobuffer(target, nimloc->nimloc, nimloc->nimloc_len));
126}
127
128static inline isc_result_t
129tostruct_in_nimloc(ARGS_TOSTRUCT) {
130	dns_rdata_in_nimloc_t *nimloc = target;
131	isc_region_t r;
132
133	REQUIRE(rdata->type == dns_rdatatype_nimloc);
134	REQUIRE(rdata->rdclass == dns_rdataclass_in);
135	REQUIRE(nimloc != NULL);
136	REQUIRE(rdata->length != 0);
137
138	nimloc->common.rdclass = rdata->rdclass;
139	nimloc->common.rdtype = rdata->type;
140	ISC_LINK_INIT(&nimloc->common, link);
141
142	dns_rdata_toregion(rdata, &r);
143	nimloc->nimloc_len = r.length;
144	nimloc->nimloc = mem_maybedup(mctx, r.base, r.length);
145	if (nimloc->nimloc == NULL) {
146		return (ISC_R_NOMEMORY);
147	}
148
149	nimloc->mctx = mctx;
150	return (ISC_R_SUCCESS);
151}
152
153static inline void
154freestruct_in_nimloc(ARGS_FREESTRUCT) {
155	dns_rdata_in_nimloc_t *nimloc = source;
156
157	REQUIRE(nimloc != NULL);
158	REQUIRE(nimloc->common.rdclass == dns_rdataclass_in);
159	REQUIRE(nimloc->common.rdtype == dns_rdatatype_nimloc);
160
161	if (nimloc->mctx == NULL) {
162		return;
163	}
164
165	if (nimloc->nimloc != NULL) {
166		isc_mem_free(nimloc->mctx, nimloc->nimloc);
167	}
168	nimloc->mctx = NULL;
169}
170
171static inline isc_result_t
172additionaldata_in_nimloc(ARGS_ADDLDATA) {
173	REQUIRE(rdata->type == dns_rdatatype_nimloc);
174	REQUIRE(rdata->rdclass == dns_rdataclass_in);
175
176	UNUSED(rdata);
177	UNUSED(add);
178	UNUSED(arg);
179
180	return (ISC_R_SUCCESS);
181}
182
183static inline isc_result_t
184digest_in_nimloc(ARGS_DIGEST) {
185	isc_region_t r;
186
187	REQUIRE(rdata->type == dns_rdatatype_nimloc);
188	REQUIRE(rdata->rdclass == dns_rdataclass_in);
189
190	dns_rdata_toregion(rdata, &r);
191
192	return ((digest)(arg, &r));
193}
194
195static inline bool
196checkowner_in_nimloc(ARGS_CHECKOWNER) {
197
198	REQUIRE(type == dns_rdatatype_nimloc);
199	REQUIRE(rdclass == dns_rdataclass_in);
200
201	UNUSED(name);
202	UNUSED(type);
203	UNUSED(rdclass);
204	UNUSED(wildcard);
205
206	return (true);
207}
208
209static inline bool
210checknames_in_nimloc(ARGS_CHECKNAMES) {
211
212	REQUIRE(rdata->type == dns_rdatatype_nimloc);
213	REQUIRE(rdata->rdclass == dns_rdataclass_in);
214
215	UNUSED(rdata);
216	UNUSED(owner);
217	UNUSED(bad);
218
219	return (true);
220}
221
222static inline int
223casecompare_in_nimloc(ARGS_COMPARE) {
224	return (compare_in_nimloc(rdata1, rdata2));
225}
226
227#endif	/* RDATA_IN_1_NIMLOC_32_C */
228