xref: /minix3/external/bsd/bind/dist/lib/dns/rdata/generic/hinfo_13.c (revision 00b67f09dd46474d133c95011a48590a8e8f94c7)
1 /*	$NetBSD: hinfo_13.c,v 1.4 2014/12/10 04:37:59 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2004, 2007, 2009, 2014  Internet Systems Consortium, Inc. ("ISC")
5  * Copyright (C) 1998-2002  Internet Software Consortium.
6  *
7  * Permission to use, copy, modify, and/or distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /* Id: hinfo_13.c,v 1.46 2009/12/04 22:06:37 tbox Exp  */
21 
22 /*
23  * Reviewed: Wed Mar 15 16:47:10 PST 2000 by halley.
24  */
25 
26 #ifndef RDATA_GENERIC_HINFO_13_C
27 #define RDATA_GENERIC_HINFO_13_C
28 
29 #define RRTYPE_HINFO_ATTRIBUTES (0)
30 
31 static inline isc_result_t
fromtext_hinfo(ARGS_FROMTEXT)32 fromtext_hinfo(ARGS_FROMTEXT) {
33 	isc_token_t token;
34 	int i;
35 
36 	UNUSED(type);
37 	UNUSED(rdclass);
38 	UNUSED(origin);
39 	UNUSED(options);
40 	UNUSED(callbacks);
41 
42 	REQUIRE(type == 13);
43 
44 	for (i = 0; i < 2; i++) {
45 		RETERR(isc_lex_getmastertoken(lexer, &token,
46 					      isc_tokentype_qstring,
47 					      ISC_FALSE));
48 		RETTOK(txt_fromtext(&token.value.as_textregion, target));
49 	}
50 	return (ISC_R_SUCCESS);
51 }
52 
53 static inline isc_result_t
totext_hinfo(ARGS_TOTEXT)54 totext_hinfo(ARGS_TOTEXT) {
55 	isc_region_t region;
56 
57 	UNUSED(tctx);
58 
59 	REQUIRE(rdata->type == 13);
60 	REQUIRE(rdata->length != 0);
61 
62 	dns_rdata_toregion(rdata, &region);
63 	RETERR(txt_totext(&region, ISC_TRUE, target));
64 	RETERR(str_totext(" ", target));
65 	return (txt_totext(&region, ISC_TRUE, target));
66 }
67 
68 static inline isc_result_t
fromwire_hinfo(ARGS_FROMWIRE)69 fromwire_hinfo(ARGS_FROMWIRE) {
70 
71 	REQUIRE(type == 13);
72 
73 	UNUSED(type);
74 	UNUSED(dctx);
75 	UNUSED(rdclass);
76 	UNUSED(options);
77 
78 	RETERR(txt_fromwire(source, target));
79 	return (txt_fromwire(source, target));
80 }
81 
82 static inline isc_result_t
towire_hinfo(ARGS_TOWIRE)83 towire_hinfo(ARGS_TOWIRE) {
84 
85 	UNUSED(cctx);
86 
87 	REQUIRE(rdata->type == 13);
88 	REQUIRE(rdata->length != 0);
89 
90 	return (mem_tobuffer(target, rdata->data, rdata->length));
91 }
92 
93 static inline int
compare_hinfo(ARGS_COMPARE)94 compare_hinfo(ARGS_COMPARE) {
95 	isc_region_t r1;
96 	isc_region_t r2;
97 
98 	REQUIRE(rdata1->type == rdata2->type);
99 	REQUIRE(rdata1->rdclass == rdata2->rdclass);
100 	REQUIRE(rdata1->type == 13);
101 	REQUIRE(rdata1->length != 0);
102 	REQUIRE(rdata2->length != 0);
103 
104 	dns_rdata_toregion(rdata1, &r1);
105 	dns_rdata_toregion(rdata2, &r2);
106 	return (isc_region_compare(&r1, &r2));
107 }
108 
109 static inline isc_result_t
fromstruct_hinfo(ARGS_FROMSTRUCT)110 fromstruct_hinfo(ARGS_FROMSTRUCT) {
111 	dns_rdata_hinfo_t *hinfo = source;
112 
113 	REQUIRE(type == 13);
114 	REQUIRE(source != NULL);
115 	REQUIRE(hinfo->common.rdtype == type);
116 	REQUIRE(hinfo->common.rdclass == rdclass);
117 
118 	UNUSED(type);
119 	UNUSED(rdclass);
120 
121 	RETERR(uint8_tobuffer(hinfo->cpu_len, target));
122 	RETERR(mem_tobuffer(target, hinfo->cpu, hinfo->cpu_len));
123 	RETERR(uint8_tobuffer(hinfo->os_len, target));
124 	return (mem_tobuffer(target, hinfo->os, hinfo->os_len));
125 }
126 
127 static inline isc_result_t
tostruct_hinfo(ARGS_TOSTRUCT)128 tostruct_hinfo(ARGS_TOSTRUCT) {
129 	dns_rdata_hinfo_t *hinfo = target;
130 	isc_region_t region;
131 
132 	REQUIRE(rdata->type == 13);
133 	REQUIRE(target != NULL);
134 	REQUIRE(rdata->length != 0);
135 
136 	hinfo->common.rdclass = rdata->rdclass;
137 	hinfo->common.rdtype = rdata->type;
138 	ISC_LINK_INIT(&hinfo->common, link);
139 
140 	dns_rdata_toregion(rdata, &region);
141 	hinfo->cpu_len = uint8_fromregion(&region);
142 	isc_region_consume(&region, 1);
143 	hinfo->cpu = mem_maybedup(mctx, region.base, hinfo->cpu_len);
144 	if (hinfo->cpu == NULL)
145 		return (ISC_R_NOMEMORY);
146 	isc_region_consume(&region, hinfo->cpu_len);
147 
148 	hinfo->os_len = uint8_fromregion(&region);
149 	isc_region_consume(&region, 1);
150 	hinfo->os = mem_maybedup(mctx, region.base, hinfo->os_len);
151 	if (hinfo->os == NULL)
152 		goto cleanup;
153 
154 	hinfo->mctx = mctx;
155 	return (ISC_R_SUCCESS);
156 
157  cleanup:
158 	if (mctx != NULL && hinfo->cpu != NULL)
159 		isc_mem_free(mctx, hinfo->cpu);
160 	return (ISC_R_NOMEMORY);
161 }
162 
163 static inline void
freestruct_hinfo(ARGS_FREESTRUCT)164 freestruct_hinfo(ARGS_FREESTRUCT) {
165 	dns_rdata_hinfo_t *hinfo = source;
166 
167 	REQUIRE(source != NULL);
168 
169 	if (hinfo->mctx == NULL)
170 		return;
171 
172 	if (hinfo->cpu != NULL)
173 		isc_mem_free(hinfo->mctx, hinfo->cpu);
174 	if (hinfo->os != NULL)
175 		isc_mem_free(hinfo->mctx, hinfo->os);
176 	hinfo->mctx = NULL;
177 }
178 
179 static inline isc_result_t
additionaldata_hinfo(ARGS_ADDLDATA)180 additionaldata_hinfo(ARGS_ADDLDATA) {
181 	REQUIRE(rdata->type == 13);
182 
183 	UNUSED(add);
184 	UNUSED(arg);
185 	UNUSED(rdata);
186 
187 	return (ISC_R_SUCCESS);
188 }
189 
190 static inline isc_result_t
digest_hinfo(ARGS_DIGEST)191 digest_hinfo(ARGS_DIGEST) {
192 	isc_region_t r;
193 
194 	REQUIRE(rdata->type == 13);
195 
196 	dns_rdata_toregion(rdata, &r);
197 
198 	return ((digest)(arg, &r));
199 }
200 
201 static inline isc_boolean_t
checkowner_hinfo(ARGS_CHECKOWNER)202 checkowner_hinfo(ARGS_CHECKOWNER) {
203 
204 	REQUIRE(type == 13);
205 
206 	UNUSED(name);
207 	UNUSED(type);
208 	UNUSED(rdclass);
209 	UNUSED(wildcard);
210 
211 	return (ISC_TRUE);
212 }
213 
214 static inline isc_boolean_t
checknames_hinfo(ARGS_CHECKNAMES)215 checknames_hinfo(ARGS_CHECKNAMES) {
216 
217 	REQUIRE(rdata->type == 13);
218 
219 	UNUSED(rdata);
220 	UNUSED(owner);
221 	UNUSED(bad);
222 
223 	return (ISC_TRUE);
224 }
225 
226 static inline int
casecompare_hinfo(ARGS_COMPARE)227 casecompare_hinfo(ARGS_COMPARE) {
228 	return (compare_hinfo(rdata1, rdata2));
229 }
230 #endif	/* RDATA_GENERIC_HINFO_13_C */
231