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