hinfo_13.c revision 1.3
1/*
2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
15 */
16
17/* $Id: hinfo_13.c,v 1.3 2020/02/23 19:54:26 jung Exp $ */
18
19/*
20 * Reviewed: Wed Mar 15 16:47:10 PST 2000 by halley.
21 */
22
23#ifndef RDATA_GENERIC_HINFO_13_C
24#define RDATA_GENERIC_HINFO_13_C
25
26#define RRTYPE_HINFO_ATTRIBUTES (0)
27
28static inline isc_result_t
29totext_hinfo(ARGS_TOTEXT) {
30	isc_region_t region;
31
32	UNUSED(tctx);
33
34	REQUIRE(rdata->type == dns_rdatatype_hinfo);
35	REQUIRE(rdata->length != 0);
36
37	dns_rdata_toregion(rdata, &region);
38	RETERR(txt_totext(&region, ISC_TRUE, target));
39	RETERR(str_totext(" ", target));
40	return (txt_totext(&region, ISC_TRUE, target));
41}
42
43static inline isc_result_t
44fromwire_hinfo(ARGS_FROMWIRE) {
45
46	REQUIRE(type == dns_rdatatype_hinfo);
47
48	UNUSED(type);
49	UNUSED(dctx);
50	UNUSED(rdclass);
51	UNUSED(options);
52
53	RETERR(txt_fromwire(source, target));
54	return (txt_fromwire(source, target));
55}
56
57static inline isc_result_t
58towire_hinfo(ARGS_TOWIRE) {
59
60	UNUSED(cctx);
61
62	REQUIRE(rdata->type == dns_rdatatype_hinfo);
63	REQUIRE(rdata->length != 0);
64
65	return (mem_tobuffer(target, rdata->data, rdata->length));
66}
67
68static inline int
69compare_hinfo(ARGS_COMPARE) {
70	isc_region_t r1;
71	isc_region_t r2;
72
73	REQUIRE(rdata1->type == rdata2->type);
74	REQUIRE(rdata1->rdclass == rdata2->rdclass);
75	REQUIRE(rdata1->type == dns_rdatatype_hinfo);
76	REQUIRE(rdata1->length != 0);
77	REQUIRE(rdata2->length != 0);
78
79	dns_rdata_toregion(rdata1, &r1);
80	dns_rdata_toregion(rdata2, &r2);
81	return (isc_region_compare(&r1, &r2));
82}
83
84static inline isc_result_t
85fromstruct_hinfo(ARGS_FROMSTRUCT) {
86	dns_rdata_hinfo_t *hinfo = source;
87
88	REQUIRE(type == dns_rdatatype_hinfo);
89	REQUIRE(source != NULL);
90	REQUIRE(hinfo->common.rdtype == type);
91	REQUIRE(hinfo->common.rdclass == rdclass);
92
93	UNUSED(type);
94	UNUSED(rdclass);
95
96	RETERR(uint8_tobuffer(hinfo->cpu_len, target));
97	RETERR(mem_tobuffer(target, hinfo->cpu, hinfo->cpu_len));
98	RETERR(uint8_tobuffer(hinfo->os_len, target));
99	return (mem_tobuffer(target, hinfo->os, hinfo->os_len));
100}
101
102static inline isc_result_t
103tostruct_hinfo(ARGS_TOSTRUCT) {
104	dns_rdata_hinfo_t *hinfo = target;
105	isc_region_t region;
106
107	REQUIRE(rdata->type == dns_rdatatype_hinfo);
108	REQUIRE(target != NULL);
109	REQUIRE(rdata->length != 0);
110
111	hinfo->common.rdclass = rdata->rdclass;
112	hinfo->common.rdtype = rdata->type;
113	ISC_LINK_INIT(&hinfo->common, link);
114
115	dns_rdata_toregion(rdata, &region);
116	hinfo->cpu_len = uint8_fromregion(&region);
117	isc_region_consume(&region, 1);
118	hinfo->cpu = mem_maybedup(region.base, hinfo->cpu_len);
119	if (hinfo->cpu == NULL)
120		return (ISC_R_NOMEMORY);
121	isc_region_consume(&region, hinfo->cpu_len);
122
123	hinfo->os_len = uint8_fromregion(&region);
124	isc_region_consume(&region, 1);
125	hinfo->os = mem_maybedup(region.base, hinfo->os_len);
126	if (hinfo->os == NULL)
127		goto cleanup;
128
129	return (ISC_R_SUCCESS);
130
131 cleanup:
132	free(hinfo->cpu);
133	return (ISC_R_NOMEMORY);
134}
135
136static inline void
137freestruct_hinfo(ARGS_FREESTRUCT) {
138	dns_rdata_hinfo_t *hinfo = source;
139
140	REQUIRE(source != NULL);
141
142	free(hinfo->cpu);
143	free(hinfo->os);
144}
145
146static inline isc_boolean_t
147checkowner_hinfo(ARGS_CHECKOWNER) {
148
149	REQUIRE(type == dns_rdatatype_hinfo);
150
151	UNUSED(name);
152	UNUSED(type);
153	UNUSED(rdclass);
154	UNUSED(wildcard);
155
156	return (ISC_TRUE);
157}
158
159static inline int
160casecompare_hinfo(ARGS_COMPARE) {
161	return (compare_hinfo(rdata1, rdata2));
162}
163#endif	/* RDATA_GENERIC_HINFO_13_C */
164