2 * Copyright (C) 2004, 2005, 2007, 2009, 2013-2015 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2002 Internet Software Consortium.
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.
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.
18 /* $Id: isdn_20.c,v 1.40 2009/12/04 22:06:37 tbox Exp $ */
20 /* Reviewed: Wed Mar 15 16:53:11 PST 2000 by bwelling */
24 #ifndef RDATA_GENERIC_ISDN_20_C
25 #define RDATA_GENERIC_ISDN_20_C
27 #define RRTYPE_ISDN_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_isdn(ARGS_FROMTEXT) {
33 REQUIRE(type == dns_rdatatype_isdn);
42 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
44 RETTOK(txt_fromtext(&token.value.as_textregion, target));
47 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
49 if (token.type != isc_tokentype_string &&
50 token.type != isc_tokentype_qstring) {
51 isc_lex_ungettoken(lexer, &token);
52 return (ISC_R_SUCCESS);
54 RETTOK(txt_fromtext(&token.value.as_textregion, target));
55 return (ISC_R_SUCCESS);
58 static inline isc_result_t
59 totext_isdn(ARGS_TOTEXT) {
62 REQUIRE(rdata->type == dns_rdatatype_isdn);
63 REQUIRE(rdata->length != 0);
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));
75 static inline isc_result_t
76 fromwire_isdn(ARGS_FROMWIRE) {
77 REQUIRE(type == dns_rdatatype_isdn);
84 RETERR(txt_fromwire(source, target));
85 if (buffer_empty(source))
86 return (ISC_R_SUCCESS);
87 return (txt_fromwire(source, target));
90 static inline isc_result_t
91 towire_isdn(ARGS_TOWIRE) {
94 REQUIRE(rdata->type == dns_rdatatype_isdn);
95 REQUIRE(rdata->length != 0);
97 return (mem_tobuffer(target, rdata->data, rdata->length));
101 compare_isdn(ARGS_COMPARE) {
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);
111 dns_rdata_toregion(rdata1, &r1);
112 dns_rdata_toregion(rdata2, &r2);
113 return (isc_region_compare(&r1, &r2));
116 static inline isc_result_t
117 fromstruct_isdn(ARGS_FROMSTRUCT) {
118 dns_rdata_isdn_t *isdn = source;
120 REQUIRE(type == dns_rdatatype_isdn);
121 REQUIRE(source != NULL);
122 REQUIRE(isdn->common.rdtype == type);
123 REQUIRE(isdn->common.rdclass == rdclass);
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));
136 static inline isc_result_t
137 tostruct_isdn(ARGS_TOSTRUCT) {
138 dns_rdata_isdn_t *isdn = target;
141 REQUIRE(rdata->type == dns_rdatatype_isdn);
142 REQUIRE(target != NULL);
143 REQUIRE(rdata->length != 0);
145 isdn->common.rdclass = rdata->rdclass;
146 isdn->common.rdtype = rdata->type;
147 ISC_LINK_INIT(&isdn->common, link);
149 dns_rdata_toregion(rdata, &r);
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);
159 isdn->subaddress_len = 0;
160 isdn->subaddress = NULL;
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)
171 return (ISC_R_SUCCESS);
174 if (mctx != NULL && isdn->isdn != NULL)
175 isc_mem_free(mctx, isdn->isdn);
176 return (ISC_R_NOMEMORY);
180 freestruct_isdn(ARGS_FREESTRUCT) {
181 dns_rdata_isdn_t *isdn = source;
183 REQUIRE(source != NULL);
185 if (isdn->mctx == NULL)
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);
195 static inline isc_result_t
196 additionaldata_isdn(ARGS_ADDLDATA) {
197 REQUIRE(rdata->type == dns_rdatatype_isdn);
203 return (ISC_R_SUCCESS);
206 static inline isc_result_t
207 digest_isdn(ARGS_DIGEST) {
210 REQUIRE(rdata->type == dns_rdatatype_isdn);
212 dns_rdata_toregion(rdata, &r);
214 return ((digest)(arg, &r));
217 static inline isc_boolean_t
218 checkowner_isdn(ARGS_CHECKOWNER) {
220 REQUIRE(type == dns_rdatatype_isdn);
230 static inline isc_boolean_t
231 checknames_isdn(ARGS_CHECKNAMES) {
233 REQUIRE(rdata->type == dns_rdatatype_isdn);
243 casecompare_isdn(ARGS_COMPARE) {
244 return (compare_isdn(rdata1, rdata2));
247 #endif /* RDATA_GENERIC_ISDN_20_C */