isdn_20.c revision 1.3
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.3 2020/02/23 19:54:26 jung 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
29totext_isdn(ARGS_TOTEXT) {
30	isc_region_t region;
31
32	REQUIRE(rdata->type == dns_rdatatype_isdn);
33	REQUIRE(rdata->length != 0);
34
35	UNUSED(tctx);
36
37	dns_rdata_toregion(rdata, &region);
38	RETERR(txt_totext(&region, ISC_TRUE, target));
39	if (region.length == 0)
40		return (ISC_R_SUCCESS);
41	RETERR(str_totext(" ", target));
42	return (txt_totext(&region, ISC_TRUE, target));
43}
44
45static inline isc_result_t
46fromwire_isdn(ARGS_FROMWIRE) {
47	REQUIRE(type == dns_rdatatype_isdn);
48
49	UNUSED(type);
50	UNUSED(dctx);
51	UNUSED(rdclass);
52	UNUSED(options);
53
54	RETERR(txt_fromwire(source, target));
55	if (buffer_empty(source))
56		return (ISC_R_SUCCESS);
57	return (txt_fromwire(source, target));
58}
59
60static inline isc_result_t
61towire_isdn(ARGS_TOWIRE) {
62	UNUSED(cctx);
63
64	REQUIRE(rdata->type == dns_rdatatype_isdn);
65	REQUIRE(rdata->length != 0);
66
67	return (mem_tobuffer(target, rdata->data, rdata->length));
68}
69
70static inline int
71compare_isdn(ARGS_COMPARE) {
72	isc_region_t r1;
73	isc_region_t r2;
74
75	REQUIRE(rdata1->type == rdata2->type);
76	REQUIRE(rdata1->rdclass == rdata2->rdclass);
77	REQUIRE(rdata1->type == dns_rdatatype_isdn);
78	REQUIRE(rdata1->length != 0);
79	REQUIRE(rdata2->length != 0);
80
81	dns_rdata_toregion(rdata1, &r1);
82	dns_rdata_toregion(rdata2, &r2);
83	return (isc_region_compare(&r1, &r2));
84}
85
86static inline isc_result_t
87fromstruct_isdn(ARGS_FROMSTRUCT) {
88	dns_rdata_isdn_t *isdn = source;
89
90	REQUIRE(type == dns_rdatatype_isdn);
91	REQUIRE(source != NULL);
92	REQUIRE(isdn->common.rdtype == type);
93	REQUIRE(isdn->common.rdclass == rdclass);
94
95	UNUSED(type);
96	UNUSED(rdclass);
97
98	RETERR(uint8_tobuffer(isdn->isdn_len, target));
99	RETERR(mem_tobuffer(target, isdn->isdn, isdn->isdn_len));
100	if (isdn->subaddress == NULL)
101		return (ISC_R_SUCCESS);
102	RETERR(uint8_tobuffer(isdn->subaddress_len, target));
103	return (mem_tobuffer(target, isdn->subaddress, isdn->subaddress_len));
104}
105
106static inline isc_result_t
107tostruct_isdn(ARGS_TOSTRUCT) {
108	dns_rdata_isdn_t *isdn = target;
109	isc_region_t r;
110
111	REQUIRE(rdata->type == dns_rdatatype_isdn);
112	REQUIRE(target != NULL);
113	REQUIRE(rdata->length != 0);
114
115	isdn->common.rdclass = rdata->rdclass;
116	isdn->common.rdtype = rdata->type;
117	ISC_LINK_INIT(&isdn->common, link);
118
119	dns_rdata_toregion(rdata, &r);
120
121	isdn->isdn_len = uint8_fromregion(&r);
122	isc_region_consume(&r, 1);
123	isdn->isdn = mem_maybedup(r.base, isdn->isdn_len);
124	if (isdn->isdn == NULL)
125		return (ISC_R_NOMEMORY);
126	isc_region_consume(&r, isdn->isdn_len);
127
128	if (r.length == 0) {
129		isdn->subaddress_len = 0;
130		isdn->subaddress = NULL;
131	} else {
132		isdn->subaddress_len = uint8_fromregion(&r);
133		isc_region_consume(&r, 1);
134		isdn->subaddress = mem_maybedup(r.base,
135						isdn->subaddress_len);
136		if (isdn->subaddress == NULL)
137			goto cleanup;
138	}
139
140	return (ISC_R_SUCCESS);
141
142 cleanup:
143	free(isdn->isdn);
144	return (ISC_R_NOMEMORY);
145}
146
147static inline void
148freestruct_isdn(ARGS_FREESTRUCT) {
149	dns_rdata_isdn_t *isdn = source;
150
151	REQUIRE(source != NULL);
152
153	free(isdn->isdn);
154	free(isdn->subaddress);
155}
156
157static inline isc_boolean_t
158checkowner_isdn(ARGS_CHECKOWNER) {
159
160	REQUIRE(type == dns_rdatatype_isdn);
161
162	UNUSED(name);
163	UNUSED(type);
164	UNUSED(rdclass);
165	UNUSED(wildcard);
166
167	return (ISC_TRUE);
168}
169
170static inline int
171casecompare_isdn(ARGS_COMPARE) {
172	return (compare_isdn(rdata1, rdata2));
173}
174
175#endif	/* RDATA_GENERIC_ISDN_20_C */
176