isdn_20.c revision 1.7
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.7 2020/02/24 17:44:44 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
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
70
71
72static inline isc_result_t
73tostruct_isdn(ARGS_TOSTRUCT) {
74	dns_rdata_isdn_t *isdn = target;
75	isc_region_t r;
76
77	REQUIRE(rdata->type == dns_rdatatype_isdn);
78	REQUIRE(target != NULL);
79	REQUIRE(rdata->length != 0);
80
81	isdn->common.rdclass = rdata->rdclass;
82	isdn->common.rdtype = rdata->type;
83	ISC_LINK_INIT(&isdn->common, link);
84
85	dns_rdata_toregion(rdata, &r);
86
87	isdn->isdn_len = uint8_fromregion(&r);
88	isc_region_consume(&r, 1);
89	isdn->isdn = mem_maybedup(r.base, isdn->isdn_len);
90	if (isdn->isdn == NULL)
91		return (ISC_R_NOMEMORY);
92	isc_region_consume(&r, isdn->isdn_len);
93
94	if (r.length == 0) {
95		isdn->subaddress_len = 0;
96		isdn->subaddress = NULL;
97	} else {
98		isdn->subaddress_len = uint8_fromregion(&r);
99		isc_region_consume(&r, 1);
100		isdn->subaddress = mem_maybedup(r.base,
101						isdn->subaddress_len);
102		if (isdn->subaddress == NULL)
103			goto cleanup;
104	}
105
106	return (ISC_R_SUCCESS);
107
108 cleanup:
109	free(isdn->isdn);
110	return (ISC_R_NOMEMORY);
111}
112
113
114
115
116#endif	/* RDATA_GENERIC_ISDN_20_C */
117