Import bind 9.5.2 vendor sources.
[dragonfly.git] / contrib / bind-9.5.2 / lib / dns / rdata / generic / isdn_20.c
blobd7333d14c4301684c74d792578a9ae793de3f6ed
1 /*
2 * Copyright (C) 2004, 2005, 2007 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.38 2007/06/19 23:47:17 tbox Exp $ */
20 /* Reviewed: Wed Mar 15 16:53:11 PST 2000 by bwelling */
22 /* RFC1183 */
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) {
31 isc_token_t token;
33 REQUIRE(type == 20);
35 UNUSED(type);
36 UNUSED(rdclass);
37 UNUSED(origin);
38 UNUSED(options);
39 UNUSED(callbacks);
41 /* ISDN-address */
42 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
43 ISC_FALSE));
44 RETTOK(txt_fromtext(&token.value.as_textregion, target));
46 /* sa: optional */
47 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
48 ISC_TRUE));
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) {
60 isc_region_t region;
62 REQUIRE(rdata->type == 20);
63 REQUIRE(rdata->length != 0);
65 UNUSED(tctx);
67 dns_rdata_toregion(rdata, &region);
68 RETERR(txt_totext(&region, target));
69 if (region.length == 0)
70 return (ISC_R_SUCCESS);
71 RETERR(str_totext(" ", target));
72 return (txt_totext(&region, target));
75 static inline isc_result_t
76 fromwire_isdn(ARGS_FROMWIRE) {
77 REQUIRE(type == 20);
79 UNUSED(type);
80 UNUSED(dctx);
81 UNUSED(rdclass);
82 UNUSED(options);
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) {
92 UNUSED(cctx);
94 REQUIRE(rdata->type == 20);
95 REQUIRE(rdata->length != 0);
97 return (mem_tobuffer(target, rdata->data, rdata->length));
100 static inline int
101 compare_isdn(ARGS_COMPARE) {
102 isc_region_t r1;
103 isc_region_t r2;
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 (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 == 20);
121 REQUIRE(source != NULL);
122 REQUIRE(isdn->common.rdtype == type);
123 REQUIRE(isdn->common.rdclass == rdclass);
125 UNUSED(type);
126 UNUSED(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;
137 isc_region_t r;
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)
160 goto cleanup;
162 isdn->mctx = mctx;
163 return (ISC_R_SUCCESS);
165 cleanup:
166 if (mctx != NULL && isdn->isdn != NULL)
167 isc_mem_free(mctx, isdn->isdn);
168 return (ISC_R_NOMEMORY);
171 static inline void
172 freestruct_isdn(ARGS_FREESTRUCT) {
173 dns_rdata_isdn_t *isdn = source;
175 REQUIRE(source != NULL);
177 if (isdn->mctx == NULL)
178 return;
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);
184 isdn->mctx = NULL;
187 static inline isc_result_t
188 additionaldata_isdn(ARGS_ADDLDATA) {
189 REQUIRE(rdata->type == 20);
191 UNUSED(rdata);
192 UNUSED(add);
193 UNUSED(arg);
195 return (ISC_R_SUCCESS);
198 static inline isc_result_t
199 digest_isdn(ARGS_DIGEST) {
200 isc_region_t r;
202 REQUIRE(rdata->type == 20);
204 dns_rdata_toregion(rdata, &r);
206 return ((digest)(arg, &r));
209 static inline isc_boolean_t
210 checkowner_isdn(ARGS_CHECKOWNER) {
212 REQUIRE(type == 20);
214 UNUSED(name);
215 UNUSED(type);
216 UNUSED(rdclass);
217 UNUSED(wildcard);
219 return (ISC_TRUE);
222 static inline isc_boolean_t
223 checknames_isdn(ARGS_CHECKNAMES) {
225 REQUIRE(rdata->type == 20);
227 UNUSED(rdata);
228 UNUSED(owner);
229 UNUSED(bad);
231 return (ISC_TRUE);
234 #endif /* RDATA_GENERIC_ISDN_20_C */