1 /*
2 * Copyright (C) 2004, 2005, 2007, 2009, 2013-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: isdn_20.c,v 1.40 2009/12/04 22:06:37 tbox Exp $ */
19
20 /* Reviewed: Wed Mar 15 16:53:11 PST 2000 by bwelling */
21
22 /* RFC1183 */
23
24 #ifndef RDATA_GENERIC_ISDN_20_C
25 #define RDATA_GENERIC_ISDN_20_C
26
27 #define RRTYPE_ISDN_ATTRIBUTES (0)
28
29 static inline isc_result_t
fromtext_isdn(ARGS_FROMTEXT)30 fromtext_isdn(ARGS_FROMTEXT) {
31 isc_token_t token;
32
33 REQUIRE(type == dns_rdatatype_isdn);
34
35 UNUSED(type);
36 UNUSED(rdclass);
37 UNUSED(origin);
38 UNUSED(options);
39 UNUSED(callbacks);
40
41 /* ISDN-address */
42 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
43 ISC_FALSE));
44 RETTOK(txt_fromtext(&token.value.as_textregion, target));
45
46 /* sa: optional */
47 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
48 ISC_TRUE));
49 if (token.type != isc_tokentype_string &&
50 token.type != isc_tokentype_qstring) {
51 isc_lex_ungettoken(lexer, &token);
52 return (ISC_R_SUCCESS);
53 }
54 RETTOK(txt_fromtext(&token.value.as_textregion, target));
55 return (ISC_R_SUCCESS);
56 }
57
58 static inline isc_result_t
totext_isdn(ARGS_TOTEXT)59 totext_isdn(ARGS_TOTEXT) {
60 isc_region_t region;
61
62 REQUIRE(rdata->type == dns_rdatatype_isdn);
63 REQUIRE(rdata->length != 0);
64
65 UNUSED(tctx);
66
67 dns_rdata_toregion(rdata, ®ion);
68 RETERR(txt_totext(®ion, ISC_TRUE, target));
69 if (region.length == 0)
70 return (ISC_R_SUCCESS);
71 RETERR(str_totext(" ", target));
72 return (txt_totext(®ion, ISC_TRUE, target));
73 }
74
75 static inline isc_result_t
fromwire_isdn(ARGS_FROMWIRE)76 fromwire_isdn(ARGS_FROMWIRE) {
77 REQUIRE(type == dns_rdatatype_isdn);
78
79 UNUSED(type);
80 UNUSED(dctx);
81 UNUSED(rdclass);
82 UNUSED(options);
83
84 RETERR(txt_fromwire(source, target));
85 if (buffer_empty(source))
86 return (ISC_R_SUCCESS);
87 return (txt_fromwire(source, target));
88 }
89
90 static inline isc_result_t
towire_isdn(ARGS_TOWIRE)91 towire_isdn(ARGS_TOWIRE) {
92 UNUSED(cctx);
93
94 REQUIRE(rdata->type == dns_rdatatype_isdn);
95 REQUIRE(rdata->length != 0);
96
97 return (mem_tobuffer(target, rdata->data, rdata->length));
98 }
99
100 static inline int
compare_isdn(ARGS_COMPARE)101 compare_isdn(ARGS_COMPARE) {
102 isc_region_t r1;
103 isc_region_t r2;
104
105 REQUIRE(rdata1->type == rdata2->type);
106 REQUIRE(rdata1->rdclass == rdata2->rdclass);
107 REQUIRE(rdata1->type == dns_rdatatype_isdn);
108 REQUIRE(rdata1->length != 0);
109 REQUIRE(rdata2->length != 0);
110
111 dns_rdata_toregion(rdata1, &r1);
112 dns_rdata_toregion(rdata2, &r2);
113 return (isc_region_compare(&r1, &r2));
114 }
115
116 static inline isc_result_t
fromstruct_isdn(ARGS_FROMSTRUCT)117 fromstruct_isdn(ARGS_FROMSTRUCT) {
118 dns_rdata_isdn_t *isdn = source;
119
120 REQUIRE(type == dns_rdatatype_isdn);
121 REQUIRE(source != NULL);
122 REQUIRE(isdn->common.rdtype == type);
123 REQUIRE(isdn->common.rdclass == rdclass);
124
125 UNUSED(type);
126 UNUSED(rdclass);
127
128 RETERR(uint8_tobuffer(isdn->isdn_len, target));
129 RETERR(mem_tobuffer(target, isdn->isdn, isdn->isdn_len));
130 if (isdn->subaddress == NULL)
131 return (ISC_R_SUCCESS);
132 RETERR(uint8_tobuffer(isdn->subaddress_len, target));
133 return (mem_tobuffer(target, isdn->subaddress, isdn->subaddress_len));
134 }
135
136 static inline isc_result_t
tostruct_isdn(ARGS_TOSTRUCT)137 tostruct_isdn(ARGS_TOSTRUCT) {
138 dns_rdata_isdn_t *isdn = target;
139 isc_region_t r;
140
141 REQUIRE(rdata->type == dns_rdatatype_isdn);
142 REQUIRE(target != NULL);
143 REQUIRE(rdata->length != 0);
144
145 isdn->common.rdclass = rdata->rdclass;
146 isdn->common.rdtype = rdata->type;
147 ISC_LINK_INIT(&isdn->common, link);
148
149 dns_rdata_toregion(rdata, &r);
150
151 isdn->isdn_len = uint8_fromregion(&r);
152 isc_region_consume(&r, 1);
153 isdn->isdn = mem_maybedup(mctx, r.base, isdn->isdn_len);
154 if (isdn->isdn == NULL)
155 return (ISC_R_NOMEMORY);
156 isc_region_consume(&r, isdn->isdn_len);
157
158 if (r.length == 0) {
159 isdn->subaddress_len = 0;
160 isdn->subaddress = NULL;
161 } else {
162 isdn->subaddress_len = uint8_fromregion(&r);
163 isc_region_consume(&r, 1);
164 isdn->subaddress = mem_maybedup(mctx, r.base,
165 isdn->subaddress_len);
166 if (isdn->subaddress == NULL)
167 goto cleanup;
168 }
169
170 isdn->mctx = mctx;
171 return (ISC_R_SUCCESS);
172
173 cleanup:
174 if (mctx != NULL && isdn->isdn != NULL)
175 isc_mem_free(mctx, isdn->isdn);
176 return (ISC_R_NOMEMORY);
177 }
178
179 static inline void
freestruct_isdn(ARGS_FREESTRUCT)180 freestruct_isdn(ARGS_FREESTRUCT) {
181 dns_rdata_isdn_t *isdn = source;
182
183 REQUIRE(source != NULL);
184
185 if (isdn->mctx == NULL)
186 return;
187
188 if (isdn->isdn != NULL)
189 isc_mem_free(isdn->mctx, isdn->isdn);
190 if (isdn->subaddress != NULL)
191 isc_mem_free(isdn->mctx, isdn->subaddress);
192 isdn->mctx = NULL;
193 }
194
195 static inline isc_result_t
additionaldata_isdn(ARGS_ADDLDATA)196 additionaldata_isdn(ARGS_ADDLDATA) {
197 REQUIRE(rdata->type == dns_rdatatype_isdn);
198
199 UNUSED(rdata);
200 UNUSED(add);
201 UNUSED(arg);
202
203 return (ISC_R_SUCCESS);
204 }
205
206 static inline isc_result_t
digest_isdn(ARGS_DIGEST)207 digest_isdn(ARGS_DIGEST) {
208 isc_region_t r;
209
210 REQUIRE(rdata->type == dns_rdatatype_isdn);
211
212 dns_rdata_toregion(rdata, &r);
213
214 return ((digest)(arg, &r));
215 }
216
217 static inline isc_boolean_t
checkowner_isdn(ARGS_CHECKOWNER)218 checkowner_isdn(ARGS_CHECKOWNER) {
219
220 REQUIRE(type == dns_rdatatype_isdn);
221
222 UNUSED(name);
223 UNUSED(type);
224 UNUSED(rdclass);
225 UNUSED(wildcard);
226
227 return (ISC_TRUE);
228 }
229
230 static inline isc_boolean_t
checknames_isdn(ARGS_CHECKNAMES)231 checknames_isdn(ARGS_CHECKNAMES) {
232
233 REQUIRE(rdata->type == dns_rdatatype_isdn);
234
235 UNUSED(rdata);
236 UNUSED(owner);
237 UNUSED(bad);
238
239 return (ISC_TRUE);
240 }
241
242 static inline int
casecompare_isdn(ARGS_COMPARE)243 casecompare_isdn(ARGS_COMPARE) {
244 return (compare_isdn(rdata1, rdata2));
245 }
246
247 #endif /* RDATA_GENERIC_ISDN_20_C */
248