Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / generic / isdn_20.c
blob615dad0cdc2fdcf97c10e8f988ffa8ccbbefcbad
1 /* $NetBSD: isdn_20.c,v 1.5 2014/12/10 04:37:59 christos Exp $ */
3 /*
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 */
24 /* RFC1183 */
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) {
33 isc_token_t token;
35 REQUIRE(type == 20);
37 UNUSED(type);
38 UNUSED(rdclass);
39 UNUSED(origin);
40 UNUSED(options);
41 UNUSED(callbacks);
43 /* ISDN-address */
44 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
45 ISC_FALSE));
46 RETTOK(txt_fromtext(&token.value.as_textregion, target));
48 /* sa: optional */
49 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
50 ISC_TRUE));
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) {
62 isc_region_t region;
64 REQUIRE(rdata->type == 20);
65 REQUIRE(rdata->length != 0);
67 UNUSED(tctx);
69 dns_rdata_toregion(rdata, &region);
70 RETERR(txt_totext(&region, ISC_TRUE, target));
71 if (region.length == 0)
72 return (ISC_R_SUCCESS);
73 RETERR(str_totext(" ", target));
74 return (txt_totext(&region, ISC_TRUE, target));
77 static inline isc_result_t
78 fromwire_isdn(ARGS_FROMWIRE) {
79 REQUIRE(type == 20);
81 UNUSED(type);
82 UNUSED(dctx);
83 UNUSED(rdclass);
84 UNUSED(options);
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) {
94 UNUSED(cctx);
96 REQUIRE(rdata->type == 20);
97 REQUIRE(rdata->length != 0);
99 return (mem_tobuffer(target, rdata->data, rdata->length));
102 static inline int
103 compare_isdn(ARGS_COMPARE) {
104 isc_region_t r1;
105 isc_region_t r2;
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;
122 REQUIRE(type == 20);
123 REQUIRE(source != NULL);
124 REQUIRE(isdn->common.rdtype == type);
125 REQUIRE(isdn->common.rdclass == rdclass);
127 UNUSED(type);
128 UNUSED(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;
141 isc_region_t r;
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);
160 if (r.length == 0) {
161 isdn->subaddress_len = 0;
162 isdn->subaddress = NULL;
163 } else {
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)
169 goto cleanup;
172 isdn->mctx = mctx;
173 return (ISC_R_SUCCESS);
175 cleanup:
176 if (mctx != NULL && isdn->isdn != NULL)
177 isc_mem_free(mctx, isdn->isdn);
178 return (ISC_R_NOMEMORY);
181 static inline void
182 freestruct_isdn(ARGS_FREESTRUCT) {
183 dns_rdata_isdn_t *isdn = source;
185 REQUIRE(source != NULL);
187 if (isdn->mctx == NULL)
188 return;
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);
194 isdn->mctx = NULL;
197 static inline isc_result_t
198 additionaldata_isdn(ARGS_ADDLDATA) {
199 REQUIRE(rdata->type == 20);
201 UNUSED(rdata);
202 UNUSED(add);
203 UNUSED(arg);
205 return (ISC_R_SUCCESS);
208 static inline isc_result_t
209 digest_isdn(ARGS_DIGEST) {
210 isc_region_t r;
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) {
222 REQUIRE(type == 20);
224 UNUSED(name);
225 UNUSED(type);
226 UNUSED(rdclass);
227 UNUSED(wildcard);
229 return (ISC_TRUE);
232 static inline isc_boolean_t
233 checknames_isdn(ARGS_CHECKNAMES) {
235 REQUIRE(rdata->type == 20);
237 UNUSED(rdata);
238 UNUSED(owner);
239 UNUSED(bad);
241 return (ISC_TRUE);
244 static inline int
245 casecompare_isdn(ARGS_COMPARE) {
246 return (compare_isdn(rdata1, rdata2));
249 #endif /* RDATA_GENERIC_ISDN_20_C */