1 /*
2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3  *
4  * SPDX-License-Identifier: MPL-2.0
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 https://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
fromtext_hinfo(ARGS_FROMTEXT)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, false));
35 		RETTOK(txt_fromtext(&token.value.as_textregion, target));
36 	}
37 	return (ISC_R_SUCCESS);
38 }
39 
40 static inline isc_result_t
totext_hinfo(ARGS_TOTEXT)41 totext_hinfo(ARGS_TOTEXT) {
42 	isc_region_t region;
43 
44 	UNUSED(tctx);
45 
46 	REQUIRE(rdata->type == dns_rdatatype_hinfo);
47 	REQUIRE(rdata->length != 0);
48 
49 	dns_rdata_toregion(rdata, &region);
50 	RETERR(txt_totext(&region, true, target));
51 	RETERR(str_totext(" ", target));
52 	return (txt_totext(&region, true, target));
53 }
54 
55 static inline isc_result_t
fromwire_hinfo(ARGS_FROMWIRE)56 fromwire_hinfo(ARGS_FROMWIRE) {
57 	REQUIRE(type == dns_rdatatype_hinfo);
58 
59 	UNUSED(type);
60 	UNUSED(dctx);
61 	UNUSED(rdclass);
62 	UNUSED(options);
63 
64 	RETERR(txt_fromwire(source, target));
65 	return (txt_fromwire(source, target));
66 }
67 
68 static inline isc_result_t
towire_hinfo(ARGS_TOWIRE)69 towire_hinfo(ARGS_TOWIRE) {
70 	UNUSED(cctx);
71 
72 	REQUIRE(rdata->type == dns_rdatatype_hinfo);
73 	REQUIRE(rdata->length != 0);
74 
75 	return (mem_tobuffer(target, rdata->data, rdata->length));
76 }
77 
78 static inline int
compare_hinfo(ARGS_COMPARE)79 compare_hinfo(ARGS_COMPARE) {
80 	isc_region_t r1;
81 	isc_region_t r2;
82 
83 	REQUIRE(rdata1->type == rdata2->type);
84 	REQUIRE(rdata1->rdclass == rdata2->rdclass);
85 	REQUIRE(rdata1->type == dns_rdatatype_hinfo);
86 	REQUIRE(rdata1->length != 0);
87 	REQUIRE(rdata2->length != 0);
88 
89 	dns_rdata_toregion(rdata1, &r1);
90 	dns_rdata_toregion(rdata2, &r2);
91 	return (isc_region_compare(&r1, &r2));
92 }
93 
94 static inline isc_result_t
fromstruct_hinfo(ARGS_FROMSTRUCT)95 fromstruct_hinfo(ARGS_FROMSTRUCT) {
96 	dns_rdata_hinfo_t *hinfo = source;
97 
98 	REQUIRE(type == dns_rdatatype_hinfo);
99 	REQUIRE(hinfo != NULL);
100 	REQUIRE(hinfo->common.rdtype == type);
101 	REQUIRE(hinfo->common.rdclass == rdclass);
102 
103 	UNUSED(type);
104 	UNUSED(rdclass);
105 
106 	RETERR(uint8_tobuffer(hinfo->cpu_len, target));
107 	RETERR(mem_tobuffer(target, hinfo->cpu, hinfo->cpu_len));
108 	RETERR(uint8_tobuffer(hinfo->os_len, target));
109 	return (mem_tobuffer(target, hinfo->os, hinfo->os_len));
110 }
111 
112 static inline isc_result_t
tostruct_hinfo(ARGS_TOSTRUCT)113 tostruct_hinfo(ARGS_TOSTRUCT) {
114 	dns_rdata_hinfo_t *hinfo = target;
115 	isc_region_t region;
116 
117 	REQUIRE(rdata->type == dns_rdatatype_hinfo);
118 	REQUIRE(hinfo != NULL);
119 	REQUIRE(rdata->length != 0);
120 
121 	hinfo->common.rdclass = rdata->rdclass;
122 	hinfo->common.rdtype = rdata->type;
123 	ISC_LINK_INIT(&hinfo->common, link);
124 
125 	dns_rdata_toregion(rdata, &region);
126 	hinfo->cpu_len = uint8_fromregion(&region);
127 	isc_region_consume(&region, 1);
128 	hinfo->cpu = mem_maybedup(mctx, region.base, hinfo->cpu_len);
129 	if (hinfo->cpu == NULL) {
130 		return (ISC_R_NOMEMORY);
131 	}
132 	isc_region_consume(&region, hinfo->cpu_len);
133 
134 	hinfo->os_len = uint8_fromregion(&region);
135 	isc_region_consume(&region, 1);
136 	hinfo->os = mem_maybedup(mctx, region.base, hinfo->os_len);
137 	if (hinfo->os == NULL) {
138 		goto cleanup;
139 	}
140 
141 	hinfo->mctx = mctx;
142 	return (ISC_R_SUCCESS);
143 
144 cleanup:
145 	if (mctx != NULL && hinfo->cpu != NULL) {
146 		isc_mem_free(mctx, hinfo->cpu);
147 	}
148 	return (ISC_R_NOMEMORY);
149 }
150 
151 static inline void
freestruct_hinfo(ARGS_FREESTRUCT)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 
161 	if (hinfo->cpu != NULL) {
162 		isc_mem_free(hinfo->mctx, hinfo->cpu);
163 	}
164 	if (hinfo->os != NULL) {
165 		isc_mem_free(hinfo->mctx, hinfo->os);
166 	}
167 	hinfo->mctx = NULL;
168 }
169 
170 static inline isc_result_t
additionaldata_hinfo(ARGS_ADDLDATA)171 additionaldata_hinfo(ARGS_ADDLDATA) {
172 	REQUIRE(rdata->type == dns_rdatatype_hinfo);
173 
174 	UNUSED(add);
175 	UNUSED(arg);
176 	UNUSED(rdata);
177 
178 	return (ISC_R_SUCCESS);
179 }
180 
181 static inline isc_result_t
digest_hinfo(ARGS_DIGEST)182 digest_hinfo(ARGS_DIGEST) {
183 	isc_region_t r;
184 
185 	REQUIRE(rdata->type == dns_rdatatype_hinfo);
186 
187 	dns_rdata_toregion(rdata, &r);
188 
189 	return ((digest)(arg, &r));
190 }
191 
192 static inline bool
checkowner_hinfo(ARGS_CHECKOWNER)193 checkowner_hinfo(ARGS_CHECKOWNER) {
194 	REQUIRE(type == dns_rdatatype_hinfo);
195 
196 	UNUSED(name);
197 	UNUSED(type);
198 	UNUSED(rdclass);
199 	UNUSED(wildcard);
200 
201 	return (true);
202 }
203 
204 static inline bool
checknames_hinfo(ARGS_CHECKNAMES)205 checknames_hinfo(ARGS_CHECKNAMES) {
206 	REQUIRE(rdata->type == dns_rdatatype_hinfo);
207 
208 	UNUSED(rdata);
209 	UNUSED(owner);
210 	UNUSED(bad);
211 
212 	return (true);
213 }
214 
215 static inline int
casecompare_hinfo(ARGS_COMPARE)216 casecompare_hinfo(ARGS_COMPARE) {
217 	return (compare_hinfo(rdata1, rdata2));
218 }
219 #endif /* RDATA_GENERIC_HINFO_13_C */
220