Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / bind / dist / lib / dns / rdata / generic / isdn_20.c
blobc819f3383acbb41d4b6abfde1488988e942cf8b3
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2004, 2005, 2007, 2009 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, target));
71 if (region.length == 0)
72 return (ISC_R_SUCCESS);
73 RETERR(str_totext(" ", target));
74 return (txt_totext(&region, 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 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;
139 isc_region_t r;
141 REQUIRE(rdata->type == 20);
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);
158 isdn->subaddress_len = uint8_fromregion(&r);
159 isc_region_consume(&r, 1);
160 isdn->subaddress = mem_maybedup(mctx, r.base, isdn->subaddress_len);
161 if (isdn->subaddress == NULL)
162 goto cleanup;
164 isdn->mctx = mctx;
165 return (ISC_R_SUCCESS);
167 cleanup:
168 if (mctx != NULL && isdn->isdn != NULL)
169 isc_mem_free(mctx, isdn->isdn);
170 return (ISC_R_NOMEMORY);
173 static inline void
174 freestruct_isdn(ARGS_FREESTRUCT) {
175 dns_rdata_isdn_t *isdn = source;
177 REQUIRE(source != NULL);
179 if (isdn->mctx == NULL)
180 return;
182 if (isdn->isdn != NULL)
183 isc_mem_free(isdn->mctx, isdn->isdn);
184 if (isdn->subaddress != NULL)
185 isc_mem_free(isdn->mctx, isdn->subaddress);
186 isdn->mctx = NULL;
189 static inline isc_result_t
190 additionaldata_isdn(ARGS_ADDLDATA) {
191 REQUIRE(rdata->type == 20);
193 UNUSED(rdata);
194 UNUSED(add);
195 UNUSED(arg);
197 return (ISC_R_SUCCESS);
200 static inline isc_result_t
201 digest_isdn(ARGS_DIGEST) {
202 isc_region_t r;
204 REQUIRE(rdata->type == 20);
206 dns_rdata_toregion(rdata, &r);
208 return ((digest)(arg, &r));
211 static inline isc_boolean_t
212 checkowner_isdn(ARGS_CHECKOWNER) {
214 REQUIRE(type == 20);
216 UNUSED(name);
217 UNUSED(type);
218 UNUSED(rdclass);
219 UNUSED(wildcard);
221 return (ISC_TRUE);
224 static inline isc_boolean_t
225 checknames_isdn(ARGS_CHECKNAMES) {
227 REQUIRE(rdata->type == 20);
229 UNUSED(rdata);
230 UNUSED(owner);
231 UNUSED(bad);
233 return (ISC_TRUE);
236 static inline int
237 casecompare_isdn(ARGS_COMPARE) {
238 return (compare_isdn(rdata1, rdata2));
241 #endif /* RDATA_GENERIC_ISDN_20_C */