1 /* $NetBSD: dhcid_49.c,v 1.5 2014/12/10 04:37:59 christos Exp $ */
4 * Copyright (C) 2006, 2007, 2009, 2011, 2012 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
23 #ifndef RDATA_IN_1_DHCID_49_C
24 #define RDATA_IN_1_DHCID_49_C 1
26 #define RRTYPE_DHCID_ATTRIBUTES 0
28 static inline isc_result_t
29 fromtext_in_dhcid(ARGS_FROMTEXT
) {
32 REQUIRE(rdclass
== 1);
40 return (isc_base64_tobuffer(lexer
, target
, -1));
43 static inline isc_result_t
44 totext_in_dhcid(ARGS_TOTEXT
) {
46 char buf
[sizeof(" ; 64000 255 64000")];
49 REQUIRE(rdata
->type
== 49);
50 REQUIRE(rdata
->rdclass
== 1);
51 REQUIRE(rdata
->length
!= 0);
53 dns_rdata_toregion(rdata
, &sr
);
55 if ((tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
56 RETERR(str_totext("( " /*)*/, target
));
57 if (tctx
->width
== 0) /* No splitting */
58 RETERR(isc_base64_totext(&sr
, 60, "", target
));
60 RETERR(isc_base64_totext(&sr
, tctx
->width
- 2,
61 tctx
->linebreak
, target
));
62 if ((tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0) {
63 RETERR(str_totext(/* ( */ " )", target
));
64 if (rdata
->length
> 2) {
65 n
= snprintf(buf
, sizeof(buf
), " ; %u %u %u",
66 sr
.base
[0] * 256 + sr
.base
[1],
67 sr
.base
[2], rdata
->length
- 3);
68 INSIST(n
< sizeof(buf
));
69 RETERR(str_totext(buf
, target
));
72 return (ISC_R_SUCCESS
);
75 static inline isc_result_t
76 fromwire_in_dhcid(ARGS_FROMWIRE
) {
80 REQUIRE(rdclass
== 1);
87 isc_buffer_activeregion(source
, &sr
);
89 return (ISC_R_UNEXPECTEDEND
);
91 isc_buffer_forward(source
, sr
.length
);
92 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
95 static inline isc_result_t
96 towire_in_dhcid(ARGS_TOWIRE
) {
99 REQUIRE(rdata
->type
== 49);
100 REQUIRE(rdata
->rdclass
== 1);
101 REQUIRE(rdata
->length
!= 0);
105 dns_rdata_toregion(rdata
, &sr
);
106 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
110 compare_in_dhcid(ARGS_COMPARE
) {
114 REQUIRE(rdata1
->type
== rdata2
->type
);
115 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
116 REQUIRE(rdata1
->type
== 49);
117 REQUIRE(rdata1
->rdclass
== 1);
118 REQUIRE(rdata1
->length
!= 0);
119 REQUIRE(rdata2
->length
!= 0);
121 dns_rdata_toregion(rdata1
, &r1
);
122 dns_rdata_toregion(rdata2
, &r2
);
123 return (isc_region_compare(&r1
, &r2
));
126 static inline isc_result_t
127 fromstruct_in_dhcid(ARGS_FROMSTRUCT
) {
128 dns_rdata_in_dhcid_t
*dhcid
= source
;
131 REQUIRE(rdclass
== 1);
132 REQUIRE(source
!= NULL
);
133 REQUIRE(dhcid
->common
.rdtype
== type
);
134 REQUIRE(dhcid
->common
.rdclass
== rdclass
);
135 REQUIRE(dhcid
->length
!= 0);
140 return (mem_tobuffer(target
, dhcid
->dhcid
, dhcid
->length
));
143 static inline isc_result_t
144 tostruct_in_dhcid(ARGS_TOSTRUCT
) {
145 dns_rdata_in_dhcid_t
*dhcid
= target
;
148 REQUIRE(rdata
->type
== 49);
149 REQUIRE(rdata
->rdclass
== 1);
150 REQUIRE(target
!= NULL
);
151 REQUIRE(rdata
->length
!= 0);
153 dhcid
->common
.rdclass
= rdata
->rdclass
;
154 dhcid
->common
.rdtype
= rdata
->type
;
155 ISC_LINK_INIT(&dhcid
->common
, link
);
157 dns_rdata_toregion(rdata
, ®ion
);
159 dhcid
->dhcid
= mem_maybedup(mctx
, region
.base
, region
.length
);
160 if (dhcid
->dhcid
== NULL
)
161 return (ISC_R_NOMEMORY
);
164 return (ISC_R_SUCCESS
);
168 freestruct_in_dhcid(ARGS_FREESTRUCT
) {
169 dns_rdata_in_dhcid_t
*dhcid
= source
;
171 REQUIRE(dhcid
!= NULL
);
172 REQUIRE(dhcid
->common
.rdtype
== 49);
173 REQUIRE(dhcid
->common
.rdclass
== 1);
175 if (dhcid
->mctx
== NULL
)
178 if (dhcid
->dhcid
!= NULL
)
179 isc_mem_free(dhcid
->mctx
, dhcid
->dhcid
);
183 static inline isc_result_t
184 additionaldata_in_dhcid(ARGS_ADDLDATA
) {
185 REQUIRE(rdata
->type
== 49);
186 REQUIRE(rdata
->rdclass
== 1);
192 return (ISC_R_SUCCESS
);
195 static inline isc_result_t
196 digest_in_dhcid(ARGS_DIGEST
) {
199 REQUIRE(rdata
->type
== 49);
200 REQUIRE(rdata
->rdclass
== 1);
202 dns_rdata_toregion(rdata
, &r
);
204 return ((digest
)(arg
, &r
));
207 static inline isc_boolean_t
208 checkowner_in_dhcid(ARGS_CHECKOWNER
) {
211 REQUIRE(rdclass
== 1);
221 static inline isc_boolean_t
222 checknames_in_dhcid(ARGS_CHECKNAMES
) {
224 REQUIRE(rdata
->type
== 49);
225 REQUIRE(rdata
->rdclass
== 1);
235 casecompare_in_dhcid(ARGS_COMPARE
) {
236 return (compare_in_dhcid(rdata1
, rdata2
));
239 #endif /* RDATA_IN_1_DHCID_49_C */