2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2002 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: x25_19.c,v 1.31.12.4 2004/03/08 09:04:43 marka Exp $ */
20 /* Reviewed: Thu Mar 16 16:15:57 PST 2000 by bwelling */
24 #ifndef RDATA_GENERIC_X25_19_C
25 #define RDATA_GENERIC_X25_19_C
27 #define RRTYPE_X25_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_x25(ARGS_FROMTEXT) {
42 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
44 if (token.value.as_textregion.length < 4)
46 for (i = 0; i < token.value.as_textregion.length; i++)
47 if (!isdigit(token.value.as_textregion.base[i] & 0xff))
49 RETTOK(txt_fromtext(&token.value.as_textregion, target));
50 return (ISC_R_SUCCESS);
53 static inline isc_result_t
54 totext_x25(ARGS_TOTEXT) {
59 REQUIRE(rdata->type == 19);
60 REQUIRE(rdata->length != 0);
62 dns_rdata_toregion(rdata, ®ion);
63 return (txt_totext(®ion, target));
66 static inline isc_result_t
67 fromwire_x25(ARGS_FROMWIRE) {
77 isc_buffer_activeregion(source, &sr);
79 return (DNS_R_FORMERR);
80 return (txt_fromwire(source, target));
83 static inline isc_result_t
84 towire_x25(ARGS_TOWIRE) {
87 REQUIRE(rdata->type == 19);
88 REQUIRE(rdata->length != 0);
90 return (mem_tobuffer(target, rdata->data, rdata->length));
94 compare_x25(ARGS_COMPARE) {
98 REQUIRE(rdata1->type == rdata2->type);
99 REQUIRE(rdata1->rdclass == rdata2->rdclass);
100 REQUIRE(rdata1->type == 19);
101 REQUIRE(rdata1->length != 0);
102 REQUIRE(rdata2->length != 0);
104 dns_rdata_toregion(rdata1, &r1);
105 dns_rdata_toregion(rdata2, &r2);
106 return (isc_region_compare(&r1, &r2));
109 static inline isc_result_t
110 fromstruct_x25(ARGS_FROMSTRUCT) {
111 dns_rdata_x25_t *x25 = source;
115 REQUIRE(source != NULL);
116 REQUIRE(x25->common.rdtype == type);
117 REQUIRE(x25->common.rdclass == rdclass);
118 REQUIRE(x25->x25 != NULL && x25->x25_len != 0);
123 if (x25->x25_len < 4)
124 return (ISC_R_RANGE);
126 for (i = 0; i < x25->x25_len; i++)
127 if (!isdigit(x25->x25[i] & 0xff))
128 return (ISC_R_RANGE);
130 RETERR(uint8_tobuffer(x25->x25_len, target));
131 return (mem_tobuffer(target, x25->x25, x25->x25_len));
134 static inline isc_result_t
135 tostruct_x25(ARGS_TOSTRUCT) {
136 dns_rdata_x25_t *x25 = target;
139 REQUIRE(rdata->type == 19);
140 REQUIRE(target != NULL);
141 REQUIRE(rdata->length != 0);
143 x25->common.rdclass = rdata->rdclass;
144 x25->common.rdtype = rdata->type;
145 ISC_LINK_INIT(&x25->common, link);
147 dns_rdata_toregion(rdata, &r);
148 x25->x25_len = uint8_fromregion(&r);
149 isc_region_consume(&r, 1);
150 x25->x25 = mem_maybedup(mctx, r.base, x25->x25_len);
151 if (x25->x25 == NULL)
152 return (ISC_R_NOMEMORY);
155 return (ISC_R_SUCCESS);
159 freestruct_x25(ARGS_FREESTRUCT) {
160 dns_rdata_x25_t *x25 = source;
161 REQUIRE(source != NULL);
162 REQUIRE(x25->common.rdtype == 19);
164 if (x25->mctx == NULL)
167 if (x25->x25 != NULL)
168 isc_mem_free(x25->mctx, x25->x25);
172 static inline isc_result_t
173 additionaldata_x25(ARGS_ADDLDATA) {
174 REQUIRE(rdata->type == 19);
180 return (ISC_R_SUCCESS);
183 static inline isc_result_t
184 digest_x25(ARGS_DIGEST) {
187 REQUIRE(rdata->type == 19);
189 dns_rdata_toregion(rdata, &r);
191 return ((digest)(arg, &r));
194 static inline isc_boolean_t
195 checkowner_x25(ARGS_CHECKOWNER) {
207 static inline isc_boolean_t
208 checknames_x25(ARGS_CHECKNAMES) {
210 REQUIRE(rdata->type == 19);
219 #endif /* RDATA_GENERIC_X25_19_C */