xref: /netbsd-src/external/mpl/bind/dist/lib/dns/rdata/generic/hinfo_13.c (revision 5dd36a3bc8bf2a9dec29ceb6349550414570c447)
1 /*	$NetBSD: hinfo_13.c,v 1.4 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 #ifndef RDATA_GENERIC_HINFO_13_C
15 #define RDATA_GENERIC_HINFO_13_C
16 
17 #define RRTYPE_HINFO_ATTRIBUTES (0)
18 
19 static inline isc_result_t
20 fromtext_hinfo(ARGS_FROMTEXT) {
21 	isc_token_t token;
22 	int i;
23 
24 	UNUSED(type);
25 	UNUSED(rdclass);
26 	UNUSED(origin);
27 	UNUSED(options);
28 	UNUSED(callbacks);
29 
30 	REQUIRE(type == dns_rdatatype_hinfo);
31 
32 	for (i = 0; i < 2; i++) {
33 		RETERR(isc_lex_getmastertoken(lexer, &token,
34 					      isc_tokentype_qstring,
35 					      false));
36 		RETTOK(txt_fromtext(&token.value.as_textregion, target));
37 	}
38 	return (ISC_R_SUCCESS);
39 }
40 
41 static inline isc_result_t
42 totext_hinfo(ARGS_TOTEXT) {
43 	isc_region_t region;
44 
45 	UNUSED(tctx);
46 
47 	REQUIRE(rdata->type == dns_rdatatype_hinfo);
48 	REQUIRE(rdata->length != 0);
49 
50 	dns_rdata_toregion(rdata, &region);
51 	RETERR(txt_totext(&region, true, target));
52 	RETERR(str_totext(" ", target));
53 	return (txt_totext(&region, true, target));
54 }
55 
56 static inline isc_result_t
57 fromwire_hinfo(ARGS_FROMWIRE) {
58 
59 	REQUIRE(type == dns_rdatatype_hinfo);
60 
61 	UNUSED(type);
62 	UNUSED(dctx);
63 	UNUSED(rdclass);
64 	UNUSED(options);
65 
66 	RETERR(txt_fromwire(source, target));
67 	return (txt_fromwire(source, target));
68 }
69 
70 static inline isc_result_t
71 towire_hinfo(ARGS_TOWIRE) {
72 
73 	UNUSED(cctx);
74 
75 	REQUIRE(rdata->type == dns_rdatatype_hinfo);
76 	REQUIRE(rdata->length != 0);
77 
78 	return (mem_tobuffer(target, rdata->data, rdata->length));
79 }
80 
81 static inline int
82 compare_hinfo(ARGS_COMPARE) {
83 	isc_region_t r1;
84 	isc_region_t r2;
85 
86 	REQUIRE(rdata1->type == rdata2->type);
87 	REQUIRE(rdata1->rdclass == rdata2->rdclass);
88 	REQUIRE(rdata1->type == dns_rdatatype_hinfo);
89 	REQUIRE(rdata1->length != 0);
90 	REQUIRE(rdata2->length != 0);
91 
92 	dns_rdata_toregion(rdata1, &r1);
93 	dns_rdata_toregion(rdata2, &r2);
94 	return (isc_region_compare(&r1, &r2));
95 }
96 
97 static inline isc_result_t
98 fromstruct_hinfo(ARGS_FROMSTRUCT) {
99 	dns_rdata_hinfo_t *hinfo = source;
100 
101 	REQUIRE(type == dns_rdatatype_hinfo);
102 	REQUIRE(hinfo != NULL);
103 	REQUIRE(hinfo->common.rdtype == type);
104 	REQUIRE(hinfo->common.rdclass == rdclass);
105 
106 	UNUSED(type);
107 	UNUSED(rdclass);
108 
109 	RETERR(uint8_tobuffer(hinfo->cpu_len, target));
110 	RETERR(mem_tobuffer(target, hinfo->cpu, hinfo->cpu_len));
111 	RETERR(uint8_tobuffer(hinfo->os_len, target));
112 	return (mem_tobuffer(target, hinfo->os, hinfo->os_len));
113 }
114 
115 static inline isc_result_t
116 tostruct_hinfo(ARGS_TOSTRUCT) {
117 	dns_rdata_hinfo_t *hinfo = target;
118 	isc_region_t region;
119 
120 	REQUIRE(rdata->type == dns_rdatatype_hinfo);
121 	REQUIRE(hinfo != NULL);
122 	REQUIRE(rdata->length != 0);
123 
124 	hinfo->common.rdclass = rdata->rdclass;
125 	hinfo->common.rdtype = rdata->type;
126 	ISC_LINK_INIT(&hinfo->common, link);
127 
128 	dns_rdata_toregion(rdata, &region);
129 	hinfo->cpu_len = uint8_fromregion(&region);
130 	isc_region_consume(&region, 1);
131 	hinfo->cpu = mem_maybedup(mctx, region.base, hinfo->cpu_len);
132 	if (hinfo->cpu == NULL)
133 		return (ISC_R_NOMEMORY);
134 	isc_region_consume(&region, hinfo->cpu_len);
135 
136 	hinfo->os_len = uint8_fromregion(&region);
137 	isc_region_consume(&region, 1);
138 	hinfo->os = mem_maybedup(mctx, region.base, hinfo->os_len);
139 	if (hinfo->os == NULL)
140 		goto cleanup;
141 
142 	hinfo->mctx = mctx;
143 	return (ISC_R_SUCCESS);
144 
145  cleanup:
146 	if (mctx != NULL && hinfo->cpu != NULL)
147 		isc_mem_free(mctx, hinfo->cpu);
148 	return (ISC_R_NOMEMORY);
149 }
150 
151 static inline void
152 freestruct_hinfo(ARGS_FREESTRUCT) {
153 	dns_rdata_hinfo_t *hinfo = source;
154 
155 	REQUIRE(hinfo != NULL);
156 
157 	if (hinfo->mctx == NULL)
158 		return;
159 
160 	if (hinfo->cpu != NULL)
161 		isc_mem_free(hinfo->mctx, hinfo->cpu);
162 	if (hinfo->os != NULL)
163 		isc_mem_free(hinfo->mctx, hinfo->os);
164 	hinfo->mctx = NULL;
165 }
166 
167 static inline isc_result_t
168 additionaldata_hinfo(ARGS_ADDLDATA) {
169 	REQUIRE(rdata->type == dns_rdatatype_hinfo);
170 
171 	UNUSED(add);
172 	UNUSED(arg);
173 	UNUSED(rdata);
174 
175 	return (ISC_R_SUCCESS);
176 }
177 
178 static inline isc_result_t
179 digest_hinfo(ARGS_DIGEST) {
180 	isc_region_t r;
181 
182 	REQUIRE(rdata->type == dns_rdatatype_hinfo);
183 
184 	dns_rdata_toregion(rdata, &r);
185 
186 	return ((digest)(arg, &r));
187 }
188 
189 static inline bool
190 checkowner_hinfo(ARGS_CHECKOWNER) {
191 
192 	REQUIRE(type == dns_rdatatype_hinfo);
193 
194 	UNUSED(name);
195 	UNUSED(type);
196 	UNUSED(rdclass);
197 	UNUSED(wildcard);
198 
199 	return (true);
200 }
201 
202 static inline bool
203 checknames_hinfo(ARGS_CHECKNAMES) {
204 
205 	REQUIRE(rdata->type == dns_rdatatype_hinfo);
206 
207 	UNUSED(rdata);
208 	UNUSED(owner);
209 	UNUSED(bad);
210 
211 	return (true);
212 }
213 
214 static inline int
215 casecompare_hinfo(ARGS_COMPARE) {
216 	return (compare_hinfo(rdata1, rdata2));
217 }
218 #endif	/* RDATA_GENERIC_HINFO_13_C */
219