1 /* $NetBSD: hinfo_13.c,v 1.4 2014/12/10 04:37:59 christos Exp $ */
4 * Copyright (C) 2004, 2007, 2009, 2014 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1998-2002 Internet Software Consortium.
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.
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.
20 /* Id: hinfo_13.c,v 1.46 2009/12/04 22:06:37 tbox Exp */
23 * Reviewed: Wed Mar 15 16:47:10 PST 2000 by halley.
26 #ifndef RDATA_GENERIC_HINFO_13_C
27 #define RDATA_GENERIC_HINFO_13_C
29 #define RRTYPE_HINFO_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_hinfo(ARGS_FROMTEXT
) {
44 for (i
= 0; i
< 2; i
++) {
45 RETERR(isc_lex_getmastertoken(lexer
, &token
,
46 isc_tokentype_qstring
,
48 RETTOK(txt_fromtext(&token
.value
.as_textregion
, target
));
50 return (ISC_R_SUCCESS
);
53 static inline isc_result_t
54 totext_hinfo(ARGS_TOTEXT
) {
59 REQUIRE(rdata
->type
== 13);
60 REQUIRE(rdata
->length
!= 0);
62 dns_rdata_toregion(rdata
, ®ion
);
63 RETERR(txt_totext(®ion
, ISC_TRUE
, target
));
64 RETERR(str_totext(" ", target
));
65 return (txt_totext(®ion
, ISC_TRUE
, target
));
68 static inline isc_result_t
69 fromwire_hinfo(ARGS_FROMWIRE
) {
78 RETERR(txt_fromwire(source
, target
));
79 return (txt_fromwire(source
, target
));
82 static inline isc_result_t
83 towire_hinfo(ARGS_TOWIRE
) {
87 REQUIRE(rdata
->type
== 13);
88 REQUIRE(rdata
->length
!= 0);
90 return (mem_tobuffer(target
, rdata
->data
, rdata
->length
));
94 compare_hinfo(ARGS_COMPARE
) {
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);
104 dns_rdata_toregion(rdata1
, &r1
);
105 dns_rdata_toregion(rdata2
, &r2
);
106 return (isc_region_compare(&r1
, &r2
));
109 static inline isc_result_t
110 fromstruct_hinfo(ARGS_FROMSTRUCT
) {
111 dns_rdata_hinfo_t
*hinfo
= source
;
114 REQUIRE(source
!= NULL
);
115 REQUIRE(hinfo
->common
.rdtype
== type
);
116 REQUIRE(hinfo
->common
.rdclass
== rdclass
);
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
));
127 static inline isc_result_t
128 tostruct_hinfo(ARGS_TOSTRUCT
) {
129 dns_rdata_hinfo_t
*hinfo
= target
;
132 REQUIRE(rdata
->type
== 13);
133 REQUIRE(target
!= NULL
);
134 REQUIRE(rdata
->length
!= 0);
136 hinfo
->common
.rdclass
= rdata
->rdclass
;
137 hinfo
->common
.rdtype
= rdata
->type
;
138 ISC_LINK_INIT(&hinfo
->common
, link
);
140 dns_rdata_toregion(rdata
, ®ion
);
141 hinfo
->cpu_len
= uint8_fromregion(®ion
);
142 isc_region_consume(®ion
, 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(®ion
, hinfo
->cpu_len
);
148 hinfo
->os_len
= uint8_fromregion(®ion
);
149 isc_region_consume(®ion
, 1);
150 hinfo
->os
= mem_maybedup(mctx
, region
.base
, hinfo
->os_len
);
151 if (hinfo
->os
== NULL
)
155 return (ISC_R_SUCCESS
);
158 if (mctx
!= NULL
&& hinfo
->cpu
!= NULL
)
159 isc_mem_free(mctx
, hinfo
->cpu
);
160 return (ISC_R_NOMEMORY
);
164 freestruct_hinfo(ARGS_FREESTRUCT
) {
165 dns_rdata_hinfo_t
*hinfo
= source
;
167 REQUIRE(source
!= NULL
);
169 if (hinfo
->mctx
== NULL
)
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
);
179 static inline isc_result_t
180 additionaldata_hinfo(ARGS_ADDLDATA
) {
181 REQUIRE(rdata
->type
== 13);
187 return (ISC_R_SUCCESS
);
190 static inline isc_result_t
191 digest_hinfo(ARGS_DIGEST
) {
194 REQUIRE(rdata
->type
== 13);
196 dns_rdata_toregion(rdata
, &r
);
198 return ((digest
)(arg
, &r
));
201 static inline isc_boolean_t
202 checkowner_hinfo(ARGS_CHECKOWNER
) {
214 static inline isc_boolean_t
215 checknames_hinfo(ARGS_CHECKNAMES
) {
217 REQUIRE(rdata
->type
== 13);
227 casecompare_hinfo(ARGS_COMPARE
) {
228 return (compare_hinfo(rdata1
, rdata2
));
230 #endif /* RDATA_GENERIC_HINFO_13_C */