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