xref: /netbsd-src/external/mpl/bind/dist/lib/dns/rdata/generic/null_10.c (revision cef8759bd76c1b621f8eab8faa6f208faabc2e15)
1 /*	$NetBSD: null_10.c,v 1.5 2020/05/24 19:46:24 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 #ifndef RDATA_GENERIC_NULL_10_C
15 #define RDATA_GENERIC_NULL_10_C
16 
17 #define RRTYPE_NULL_ATTRIBUTES (0)
18 
19 static inline isc_result_t
20 fromtext_null(ARGS_FROMTEXT) {
21 	REQUIRE(type == dns_rdatatype_null);
22 
23 	UNUSED(rdclass);
24 	UNUSED(type);
25 	UNUSED(lexer);
26 	UNUSED(origin);
27 	UNUSED(options);
28 	UNUSED(target);
29 	UNUSED(callbacks);
30 
31 	return (DNS_R_SYNTAX);
32 }
33 
34 static inline isc_result_t
35 totext_null(ARGS_TOTEXT) {
36 	REQUIRE(rdata->type == dns_rdatatype_null);
37 
38 	return (unknown_totext(rdata, tctx, target));
39 }
40 
41 static inline isc_result_t
42 fromwire_null(ARGS_FROMWIRE) {
43 	isc_region_t sr;
44 
45 	REQUIRE(type == dns_rdatatype_null);
46 
47 	UNUSED(type);
48 	UNUSED(rdclass);
49 	UNUSED(dctx);
50 	UNUSED(options);
51 
52 	isc_buffer_activeregion(source, &sr);
53 	isc_buffer_forward(source, sr.length);
54 	return (mem_tobuffer(target, sr.base, sr.length));
55 }
56 
57 static inline isc_result_t
58 towire_null(ARGS_TOWIRE) {
59 	REQUIRE(rdata->type == dns_rdatatype_null);
60 
61 	UNUSED(cctx);
62 
63 	return (mem_tobuffer(target, rdata->data, rdata->length));
64 }
65 
66 static inline int
67 compare_null(ARGS_COMPARE) {
68 	isc_region_t r1;
69 	isc_region_t r2;
70 
71 	REQUIRE(rdata1->type == rdata2->type);
72 	REQUIRE(rdata1->rdclass == rdata2->rdclass);
73 	REQUIRE(rdata1->type == dns_rdatatype_null);
74 
75 	dns_rdata_toregion(rdata1, &r1);
76 	dns_rdata_toregion(rdata2, &r2);
77 	return (isc_region_compare(&r1, &r2));
78 }
79 
80 static inline isc_result_t
81 fromstruct_null(ARGS_FROMSTRUCT) {
82 	dns_rdata_null_t *null = source;
83 
84 	REQUIRE(type == dns_rdatatype_null);
85 	REQUIRE(null != NULL);
86 	REQUIRE(null->common.rdtype == type);
87 	REQUIRE(null->common.rdclass == rdclass);
88 	REQUIRE(null->data != NULL || null->length == 0);
89 
90 	UNUSED(type);
91 	UNUSED(rdclass);
92 
93 	return (mem_tobuffer(target, null->data, null->length));
94 }
95 
96 static inline isc_result_t
97 tostruct_null(ARGS_TOSTRUCT) {
98 	dns_rdata_null_t *null = target;
99 	isc_region_t r;
100 
101 	REQUIRE(rdata->type == dns_rdatatype_null);
102 	REQUIRE(null != NULL);
103 
104 	null->common.rdclass = rdata->rdclass;
105 	null->common.rdtype = rdata->type;
106 	ISC_LINK_INIT(&null->common, link);
107 
108 	dns_rdata_toregion(rdata, &r);
109 	null->length = r.length;
110 	null->data = mem_maybedup(mctx, r.base, r.length);
111 	if (null->data == NULL) {
112 		return (ISC_R_NOMEMORY);
113 	}
114 
115 	null->mctx = mctx;
116 	return (ISC_R_SUCCESS);
117 }
118 
119 static inline void
120 freestruct_null(ARGS_FREESTRUCT) {
121 	dns_rdata_null_t *null = source;
122 
123 	REQUIRE(null != NULL);
124 	REQUIRE(null->common.rdtype == dns_rdatatype_null);
125 
126 	if (null->mctx == NULL) {
127 		return;
128 	}
129 
130 	if (null->data != NULL) {
131 		isc_mem_free(null->mctx, null->data);
132 	}
133 	null->mctx = NULL;
134 }
135 
136 static inline isc_result_t
137 additionaldata_null(ARGS_ADDLDATA) {
138 	UNUSED(rdata);
139 	UNUSED(add);
140 	UNUSED(arg);
141 
142 	REQUIRE(rdata->type == dns_rdatatype_null);
143 
144 	return (ISC_R_SUCCESS);
145 }
146 
147 static inline isc_result_t
148 digest_null(ARGS_DIGEST) {
149 	isc_region_t r;
150 
151 	REQUIRE(rdata->type == dns_rdatatype_null);
152 
153 	dns_rdata_toregion(rdata, &r);
154 
155 	return ((digest)(arg, &r));
156 }
157 
158 static inline bool
159 checkowner_null(ARGS_CHECKOWNER) {
160 	REQUIRE(type == dns_rdatatype_null);
161 
162 	UNUSED(name);
163 	UNUSED(type);
164 	UNUSED(rdclass);
165 	UNUSED(wildcard);
166 
167 	return (true);
168 }
169 
170 static inline bool
171 checknames_null(ARGS_CHECKNAMES) {
172 	REQUIRE(rdata->type == dns_rdatatype_null);
173 
174 	UNUSED(rdata);
175 	UNUSED(owner);
176 	UNUSED(bad);
177 
178 	return (true);
179 }
180 
181 static inline int
182 casecompare_null(ARGS_COMPARE) {
183 	return (compare_null(rdata1, rdata2));
184 }
185 
186 #endif /* RDATA_GENERIC_NULL_10_C */
187