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