1 /*
2 * Copyright (C) 2004, 2007, 2009, 2015 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-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: unspec_103.c,v 1.37 2009/12/04 22:06:37 tbox Exp $ */
19
20 #ifndef RDATA_GENERIC_UNSPEC_103_C
21 #define RDATA_GENERIC_UNSPEC_103_C
22
23 #define RRTYPE_UNSPEC_ATTRIBUTES (0)
24
25 static inline isc_result_t
fromtext_unspec(ARGS_FROMTEXT)26 fromtext_unspec(ARGS_FROMTEXT) {
27
28 REQUIRE(type == dns_rdatatype_unspec);
29
30 UNUSED(type);
31 UNUSED(rdclass);
32 UNUSED(origin);
33 UNUSED(options);
34 UNUSED(callbacks);
35
36 return (atob_tobuffer(lexer, target));
37 }
38
39 static inline isc_result_t
totext_unspec(ARGS_TOTEXT)40 totext_unspec(ARGS_TOTEXT) {
41
42 REQUIRE(rdata->type == dns_rdatatype_unspec);
43
44 UNUSED(tctx);
45
46 return (btoa_totext(rdata->data, rdata->length, target));
47 }
48
49 static inline isc_result_t
fromwire_unspec(ARGS_FROMWIRE)50 fromwire_unspec(ARGS_FROMWIRE) {
51 isc_region_t sr;
52
53 REQUIRE(type == dns_rdatatype_unspec);
54
55 UNUSED(type);
56 UNUSED(rdclass);
57 UNUSED(dctx);
58 UNUSED(options);
59
60 isc_buffer_activeregion(source, &sr);
61 isc_buffer_forward(source, sr.length);
62 return (mem_tobuffer(target, sr.base, sr.length));
63 }
64
65 static inline isc_result_t
towire_unspec(ARGS_TOWIRE)66 towire_unspec(ARGS_TOWIRE) {
67
68 REQUIRE(rdata->type == dns_rdatatype_unspec);
69
70 UNUSED(cctx);
71
72 return (mem_tobuffer(target, rdata->data, rdata->length));
73 }
74
75 static inline int
compare_unspec(ARGS_COMPARE)76 compare_unspec(ARGS_COMPARE) {
77 isc_region_t r1;
78 isc_region_t r2;
79
80 REQUIRE(rdata1->type == rdata2->type);
81 REQUIRE(rdata1->rdclass == rdata2->rdclass);
82 REQUIRE(rdata1->type == dns_rdatatype_unspec);
83
84 dns_rdata_toregion(rdata1, &r1);
85 dns_rdata_toregion(rdata2, &r2);
86 return (isc_region_compare(&r1, &r2));
87 }
88
89 static inline isc_result_t
fromstruct_unspec(ARGS_FROMSTRUCT)90 fromstruct_unspec(ARGS_FROMSTRUCT) {
91 dns_rdata_unspec_t *unspec = source;
92
93 REQUIRE(type == dns_rdatatype_unspec);
94 REQUIRE(source != NULL);
95 REQUIRE(unspec->common.rdtype == type);
96 REQUIRE(unspec->common.rdclass == rdclass);
97 REQUIRE(unspec->data != NULL || unspec->datalen == 0);
98
99 UNUSED(type);
100 UNUSED(rdclass);
101
102 return (mem_tobuffer(target, unspec->data, unspec->datalen));
103 }
104
105 static inline isc_result_t
tostruct_unspec(ARGS_TOSTRUCT)106 tostruct_unspec(ARGS_TOSTRUCT) {
107 dns_rdata_unspec_t *unspec = target;
108 isc_region_t r;
109
110 REQUIRE(rdata->type == dns_rdatatype_unspec);
111 REQUIRE(target != NULL);
112
113 unspec->common.rdclass = rdata->rdclass;
114 unspec->common.rdtype = rdata->type;
115 ISC_LINK_INIT(&unspec->common, link);
116
117 dns_rdata_toregion(rdata, &r);
118 unspec->datalen = r.length;
119 unspec->data = mem_maybedup(mctx, r.base, r.length);
120 if (unspec->data == NULL)
121 return (ISC_R_NOMEMORY);
122
123 unspec->mctx = mctx;
124 return (ISC_R_SUCCESS);
125 }
126
127 static inline void
freestruct_unspec(ARGS_FREESTRUCT)128 freestruct_unspec(ARGS_FREESTRUCT) {
129 dns_rdata_unspec_t *unspec = source;
130
131 REQUIRE(source != NULL);
132 REQUIRE(unspec->common.rdtype == dns_rdatatype_unspec);
133
134 if (unspec->mctx == NULL)
135 return;
136
137 if (unspec->data != NULL)
138 isc_mem_free(unspec->mctx, unspec->data);
139 unspec->mctx = NULL;
140 }
141
142 static inline isc_result_t
additionaldata_unspec(ARGS_ADDLDATA)143 additionaldata_unspec(ARGS_ADDLDATA) {
144 REQUIRE(rdata->type == dns_rdatatype_unspec);
145
146 UNUSED(rdata);
147 UNUSED(add);
148 UNUSED(arg);
149
150 return (ISC_R_SUCCESS);
151 }
152
153 static inline isc_result_t
digest_unspec(ARGS_DIGEST)154 digest_unspec(ARGS_DIGEST) {
155 isc_region_t r;
156
157 REQUIRE(rdata->type == dns_rdatatype_unspec);
158
159 dns_rdata_toregion(rdata, &r);
160
161 return ((digest)(arg, &r));
162 }
163
164 static inline isc_boolean_t
checkowner_unspec(ARGS_CHECKOWNER)165 checkowner_unspec(ARGS_CHECKOWNER) {
166
167 REQUIRE(type == dns_rdatatype_unspec);
168
169 UNUSED(name);
170 UNUSED(type);
171 UNUSED(rdclass);
172 UNUSED(wildcard);
173
174 return (ISC_TRUE);
175 }
176
177 static inline isc_boolean_t
checknames_unspec(ARGS_CHECKNAMES)178 checknames_unspec(ARGS_CHECKNAMES) {
179
180 REQUIRE(rdata->type == dns_rdatatype_unspec);
181
182 UNUSED(rdata);
183 UNUSED(owner);
184 UNUSED(bad);
185
186 return (ISC_TRUE);
187 }
188
189 static inline int
casecompare_unspec(ARGS_COMPARE)190 casecompare_unspec(ARGS_COMPARE) {
191 return (compare_unspec(rdata1, rdata2));
192 }
193
194 #endif /* RDATA_GENERIC_UNSPEC_103_C */
195