1 /* $NetBSD: isdn_20.c,v 1.5 2014/12/10 04:37:59 christos Exp $ */
4 * Copyright (C) 2004, 2005, 2007, 2009, 2013, 2014 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2002 Internet Software Consortium.
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.
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.
20 /* Id: isdn_20.c,v 1.40 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Wed Mar 15 16:53:11 PST 2000 by bwelling */
26 #ifndef RDATA_GENERIC_ISDN_20_C
27 #define RDATA_GENERIC_ISDN_20_C
29 #define RRTYPE_ISDN_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_isdn(ARGS_FROMTEXT
) {
44 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_qstring
,
46 RETTOK(txt_fromtext(&token
.value
.as_textregion
, target
));
49 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_qstring
,
51 if (token
.type
!= isc_tokentype_string
&&
52 token
.type
!= isc_tokentype_qstring
) {
53 isc_lex_ungettoken(lexer
, &token
);
54 return (ISC_R_SUCCESS
);
56 RETTOK(txt_fromtext(&token
.value
.as_textregion
, target
));
57 return (ISC_R_SUCCESS
);
60 static inline isc_result_t
61 totext_isdn(ARGS_TOTEXT
) {
64 REQUIRE(rdata
->type
== 20);
65 REQUIRE(rdata
->length
!= 0);
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
));
77 static inline isc_result_t
78 fromwire_isdn(ARGS_FROMWIRE
) {
86 RETERR(txt_fromwire(source
, target
));
87 if (buffer_empty(source
))
88 return (ISC_R_SUCCESS
);
89 return (txt_fromwire(source
, target
));
92 static inline isc_result_t
93 towire_isdn(ARGS_TOWIRE
) {
96 REQUIRE(rdata
->type
== 20);
97 REQUIRE(rdata
->length
!= 0);
99 return (mem_tobuffer(target
, rdata
->data
, rdata
->length
));
103 compare_isdn(ARGS_COMPARE
) {
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);
113 dns_rdata_toregion(rdata1
, &r1
);
114 dns_rdata_toregion(rdata2
, &r2
);
115 return (isc_region_compare(&r1
, &r2
));
118 static inline isc_result_t
119 fromstruct_isdn(ARGS_FROMSTRUCT
) {
120 dns_rdata_isdn_t
*isdn
= source
;
123 REQUIRE(source
!= NULL
);
124 REQUIRE(isdn
->common
.rdtype
== type
);
125 REQUIRE(isdn
->common
.rdclass
== rdclass
);
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
));
138 static inline isc_result_t
139 tostruct_isdn(ARGS_TOSTRUCT
) {
140 dns_rdata_isdn_t
*isdn
= target
;
143 REQUIRE(rdata
->type
== 20);
144 REQUIRE(target
!= NULL
);
145 REQUIRE(rdata
->length
!= 0);
147 isdn
->common
.rdclass
= rdata
->rdclass
;
148 isdn
->common
.rdtype
= rdata
->type
;
149 ISC_LINK_INIT(&isdn
->common
, link
);
151 dns_rdata_toregion(rdata
, &r
);
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
);
161 isdn
->subaddress_len
= 0;
162 isdn
->subaddress
= NULL
;
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
)
173 return (ISC_R_SUCCESS
);
176 if (mctx
!= NULL
&& isdn
->isdn
!= NULL
)
177 isc_mem_free(mctx
, isdn
->isdn
);
178 return (ISC_R_NOMEMORY
);
182 freestruct_isdn(ARGS_FREESTRUCT
) {
183 dns_rdata_isdn_t
*isdn
= source
;
185 REQUIRE(source
!= NULL
);
187 if (isdn
->mctx
== NULL
)
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
);
197 static inline isc_result_t
198 additionaldata_isdn(ARGS_ADDLDATA
) {
199 REQUIRE(rdata
->type
== 20);
205 return (ISC_R_SUCCESS
);
208 static inline isc_result_t
209 digest_isdn(ARGS_DIGEST
) {
212 REQUIRE(rdata
->type
== 20);
214 dns_rdata_toregion(rdata
, &r
);
216 return ((digest
)(arg
, &r
));
219 static inline isc_boolean_t
220 checkowner_isdn(ARGS_CHECKOWNER
) {
232 static inline isc_boolean_t
233 checknames_isdn(ARGS_CHECKNAMES
) {
235 REQUIRE(rdata
->type
== 20);
245 casecompare_isdn(ARGS_COMPARE
) {
246 return (compare_isdn(rdata1
, rdata2
));
249 #endif /* RDATA_GENERIC_ISDN_20_C */