2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and 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.30.2.1 2004/03/09 06:11:28 marka 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
) {
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
== 20);
63 REQUIRE(rdata
->length
!= 0);
67 dns_rdata_toregion(rdata
, ®ion
);
68 RETERR(txt_totext(®ion
, target
));
69 if (region
.length
== 0)
70 return (ISC_R_SUCCESS
);
71 RETERR(str_totext(" ", target
));
72 return (txt_totext(®ion
, target
));
75 static inline isc_result_t
76 fromwire_isdn(ARGS_FROMWIRE
) {
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
== 20);
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
== 20);
108 REQUIRE(rdata1
->length
!= 0);
109 REQUIRE(rdata2
->length
!= 0);
111 dns_rdata_toregion(rdata1
, &r1
);
112 dns_rdata_toregion(rdata2
, &r2
);
113 return (compare_region(&r1
, &r2
));
116 static inline isc_result_t
117 fromstruct_isdn(ARGS_FROMSTRUCT
) {
118 dns_rdata_isdn_t
*isdn
= source
;
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 RETERR(uint8_tobuffer(isdn
->subaddress_len
, target
));
131 return (mem_tobuffer(target
, isdn
->subaddress
, isdn
->subaddress_len
));
134 static inline isc_result_t
135 tostruct_isdn(ARGS_TOSTRUCT
) {
136 dns_rdata_isdn_t
*isdn
= target
;
139 REQUIRE(rdata
->type
== 20);
140 REQUIRE(target
!= NULL
);
141 REQUIRE(rdata
->length
!= 0);
143 isdn
->common
.rdclass
= rdata
->rdclass
;
144 isdn
->common
.rdtype
= rdata
->type
;
145 ISC_LINK_INIT(&isdn
->common
, link
);
147 dns_rdata_toregion(rdata
, &r
);
149 isdn
->isdn_len
= uint8_fromregion(&r
);
150 isc_region_consume(&r
, 1);
151 isdn
->isdn
= mem_maybedup(mctx
, r
.base
, isdn
->isdn_len
);
152 if (isdn
->isdn
== NULL
)
153 return (ISC_R_NOMEMORY
);
154 isc_region_consume(&r
, isdn
->isdn_len
);
156 isdn
->subaddress_len
= uint8_fromregion(&r
);
157 isc_region_consume(&r
, 1);
158 isdn
->subaddress
= mem_maybedup(mctx
, r
.base
, isdn
->subaddress_len
);
159 if (isdn
->subaddress
== NULL
)
163 return (ISC_R_SUCCESS
);
166 if (mctx
!= NULL
&& isdn
->isdn
!= NULL
)
167 isc_mem_free(mctx
, isdn
->isdn
);
168 return (ISC_R_NOMEMORY
);
172 freestruct_isdn(ARGS_FREESTRUCT
) {
173 dns_rdata_isdn_t
*isdn
= source
;
175 REQUIRE(source
!= NULL
);
177 if (isdn
->mctx
== NULL
)
180 if (isdn
->isdn
!= NULL
)
181 isc_mem_free(isdn
->mctx
, isdn
->isdn
);
182 if (isdn
->subaddress
!= NULL
)
183 isc_mem_free(isdn
->mctx
, isdn
->subaddress
);
187 static inline isc_result_t
188 additionaldata_isdn(ARGS_ADDLDATA
) {
189 REQUIRE(rdata
->type
== 20);
195 return (ISC_R_SUCCESS
);
198 static inline isc_result_t
199 digest_isdn(ARGS_DIGEST
) {
202 REQUIRE(rdata
->type
== 20);
204 dns_rdata_toregion(rdata
, &r
);
206 return ((digest
)(arg
, &r
));
209 #endif /* RDATA_GENERIC_ISDN_20_C */