]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/bind9/lib/dns/rdata/in_1/dhcid_49.c
MFC r363988:
[FreeBSD/stable/9.git] / contrib / bind9 / lib / dns / rdata / in_1 / dhcid_49.c
1 /*
2  * Copyright (C) 2006, 2007, 2009, 2011, 2012, 2015  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$ */
18
19 /* RFC 4701 */
20
21 #ifndef RDATA_IN_1_DHCID_49_C
22 #define RDATA_IN_1_DHCID_49_C 1
23
24 #define RRTYPE_DHCID_ATTRIBUTES 0
25
26 static inline isc_result_t
27 fromtext_in_dhcid(ARGS_FROMTEXT) {
28
29         REQUIRE(type == dns_rdatatype_dhcid);
30         REQUIRE(rdclass == dns_rdataclass_in);
31
32         UNUSED(type);
33         UNUSED(rdclass);
34         UNUSED(origin);
35         UNUSED(options);
36         UNUSED(callbacks);
37
38         return (isc_base64_tobuffer(lexer, target, -1));
39 }
40
41 static inline isc_result_t
42 totext_in_dhcid(ARGS_TOTEXT) {
43         isc_region_t sr;
44         char buf[sizeof(" ; 64000 255 64000")];
45         size_t n;
46
47         REQUIRE(rdata->type == dns_rdatatype_dhcid);
48         REQUIRE(rdata->rdclass == dns_rdataclass_in);
49         REQUIRE(rdata->length != 0);
50
51         dns_rdata_toregion(rdata, &sr);
52
53         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
54                 RETERR(str_totext("( " /*)*/, target));
55         if (tctx->width == 0)   /* No splitting */
56                 RETERR(isc_base64_totext(&sr, 60, "", target));
57         else
58                 RETERR(isc_base64_totext(&sr, tctx->width - 2,
59                                          tctx->linebreak, target));
60         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
61                 RETERR(str_totext(/* ( */ " )", target));
62                 if (rdata->length > 2) {
63                         n = snprintf(buf, sizeof(buf), " ; %u %u %u",
64                                      sr.base[0] * 256 + sr.base[1],
65                                      sr.base[2], rdata->length - 3);
66                         INSIST(n < sizeof(buf));
67                         RETERR(str_totext(buf, target));
68                 }
69         }
70         return (ISC_R_SUCCESS);
71 }
72
73 static inline isc_result_t
74 fromwire_in_dhcid(ARGS_FROMWIRE) {
75         isc_region_t sr;
76
77         REQUIRE(type == dns_rdatatype_dhcid);
78         REQUIRE(rdclass == dns_rdataclass_in);
79
80         UNUSED(type);
81         UNUSED(rdclass);
82         UNUSED(dctx);
83         UNUSED(options);
84
85         isc_buffer_activeregion(source, &sr);
86         if (sr.length == 0)
87                 return (ISC_R_UNEXPECTEDEND);
88
89         isc_buffer_forward(source, sr.length);
90         return (mem_tobuffer(target, sr.base, sr.length));
91 }
92
93 static inline isc_result_t
94 towire_in_dhcid(ARGS_TOWIRE) {
95         isc_region_t sr;
96
97         REQUIRE(rdata->type == dns_rdatatype_dhcid);
98         REQUIRE(rdata->rdclass == dns_rdataclass_in);
99         REQUIRE(rdata->length != 0);
100
101         UNUSED(cctx);
102
103         dns_rdata_toregion(rdata, &sr);
104         return (mem_tobuffer(target, sr.base, sr.length));
105 }
106
107 static inline int
108 compare_in_dhcid(ARGS_COMPARE) {
109         isc_region_t r1;
110         isc_region_t r2;
111
112         REQUIRE(rdata1->type == rdata2->type);
113         REQUIRE(rdata1->rdclass == rdata2->rdclass);
114         REQUIRE(rdata1->type == dns_rdatatype_dhcid);
115         REQUIRE(rdata1->rdclass == dns_rdataclass_in);
116         REQUIRE(rdata1->length != 0);
117         REQUIRE(rdata2->length != 0);
118
119         dns_rdata_toregion(rdata1, &r1);
120         dns_rdata_toregion(rdata2, &r2);
121         return (isc_region_compare(&r1, &r2));
122 }
123
124 static inline isc_result_t
125 fromstruct_in_dhcid(ARGS_FROMSTRUCT) {
126         dns_rdata_in_dhcid_t *dhcid = source;
127
128         REQUIRE(type == dns_rdatatype_dhcid);
129         REQUIRE(rdclass == dns_rdataclass_in);
130         REQUIRE(source != NULL);
131         REQUIRE(dhcid->common.rdtype == type);
132         REQUIRE(dhcid->common.rdclass == rdclass);
133         REQUIRE(dhcid->length != 0);
134
135         UNUSED(type);
136         UNUSED(rdclass);
137
138         return (mem_tobuffer(target, dhcid->dhcid, dhcid->length));
139 }
140
141 static inline isc_result_t
142 tostruct_in_dhcid(ARGS_TOSTRUCT) {
143         dns_rdata_in_dhcid_t *dhcid = target;
144         isc_region_t region;
145
146         REQUIRE(rdata->type == dns_rdatatype_dhcid);
147         REQUIRE(rdata->rdclass == dns_rdataclass_in);
148         REQUIRE(target != NULL);
149         REQUIRE(rdata->length != 0);
150
151         dhcid->common.rdclass = rdata->rdclass;
152         dhcid->common.rdtype = rdata->type;
153         ISC_LINK_INIT(&dhcid->common, link);
154
155         dns_rdata_toregion(rdata, &region);
156
157         dhcid->dhcid = mem_maybedup(mctx, region.base, region.length);
158         if (dhcid->dhcid == NULL)
159                 return (ISC_R_NOMEMORY);
160
161         dhcid->mctx = mctx;
162         return (ISC_R_SUCCESS);
163 }
164
165 static inline void
166 freestruct_in_dhcid(ARGS_FREESTRUCT) {
167         dns_rdata_in_dhcid_t *dhcid = source;
168
169         REQUIRE(dhcid != NULL);
170         REQUIRE(dhcid->common.rdtype == dns_rdatatype_dhcid);
171         REQUIRE(dhcid->common.rdclass == dns_rdataclass_in);
172
173         if (dhcid->mctx == NULL)
174                 return;
175
176         if (dhcid->dhcid != NULL)
177                 isc_mem_free(dhcid->mctx, dhcid->dhcid);
178         dhcid->mctx = NULL;
179 }
180
181 static inline isc_result_t
182 additionaldata_in_dhcid(ARGS_ADDLDATA) {
183         REQUIRE(rdata->type == dns_rdatatype_dhcid);
184         REQUIRE(rdata->rdclass == dns_rdataclass_in);
185
186         UNUSED(rdata);
187         UNUSED(add);
188         UNUSED(arg);
189
190         return (ISC_R_SUCCESS);
191 }
192
193 static inline isc_result_t
194 digest_in_dhcid(ARGS_DIGEST) {
195         isc_region_t r;
196
197         REQUIRE(rdata->type == dns_rdatatype_dhcid);
198         REQUIRE(rdata->rdclass == dns_rdataclass_in);
199
200         dns_rdata_toregion(rdata, &r);
201
202         return ((digest)(arg, &r));
203 }
204
205 static inline isc_boolean_t
206 checkowner_in_dhcid(ARGS_CHECKOWNER) {
207
208         REQUIRE(type == dns_rdatatype_dhcid);
209         REQUIRE(rdclass == dns_rdataclass_in);
210
211         UNUSED(name);
212         UNUSED(type);
213         UNUSED(rdclass);
214         UNUSED(wildcard);
215
216         return (ISC_TRUE);
217 }
218
219 static inline isc_boolean_t
220 checknames_in_dhcid(ARGS_CHECKNAMES) {
221
222         REQUIRE(rdata->type == dns_rdatatype_dhcid);
223         REQUIRE(rdata->rdclass == dns_rdataclass_in);
224
225         UNUSED(rdata);
226         UNUSED(owner);
227         UNUSED(bad);
228
229         return (ISC_TRUE);
230 }
231
232 static inline int
233 casecompare_in_dhcid(ARGS_COMPARE) {
234         return (compare_in_dhcid(rdata1, rdata2));
235 }
236
237 #endif  /* RDATA_IN_1_DHCID_49_C */