1 /* $NetBSD: x25_19.c,v 1.4 2014/12/10 04:37:59 christos Exp $ */
4 * Copyright (C) 2004, 2005, 2007, 2009, 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: x25_19.c,v 1.41 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Thu Mar 16 16:15:57 PST 2000 by bwelling */
26 #ifndef RDATA_GENERIC_X25_19_C
27 #define RDATA_GENERIC_X25_19_C
29 #define RRTYPE_X25_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_x25(ARGS_FROMTEXT
) {
44 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_qstring
,
46 if (token
.value
.as_textregion
.length
< 4)
48 for (i
= 0; i
< token
.value
.as_textregion
.length
; i
++)
49 if (!isdigit(token
.value
.as_textregion
.base
[i
] & 0xff))
51 RETTOK(txt_fromtext(&token
.value
.as_textregion
, target
));
52 return (ISC_R_SUCCESS
);
55 static inline isc_result_t
56 totext_x25(ARGS_TOTEXT
) {
61 REQUIRE(rdata
->type
== 19);
62 REQUIRE(rdata
->length
!= 0);
64 dns_rdata_toregion(rdata
, ®ion
);
65 return (txt_totext(®ion
, ISC_TRUE
, target
));
68 static inline isc_result_t
69 fromwire_x25(ARGS_FROMWIRE
) {
79 isc_buffer_activeregion(source
, &sr
);
81 return (DNS_R_FORMERR
);
82 return (txt_fromwire(source
, target
));
85 static inline isc_result_t
86 towire_x25(ARGS_TOWIRE
) {
89 REQUIRE(rdata
->type
== 19);
90 REQUIRE(rdata
->length
!= 0);
92 return (mem_tobuffer(target
, rdata
->data
, rdata
->length
));
96 compare_x25(ARGS_COMPARE
) {
100 REQUIRE(rdata1
->type
== rdata2
->type
);
101 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
102 REQUIRE(rdata1
->type
== 19);
103 REQUIRE(rdata1
->length
!= 0);
104 REQUIRE(rdata2
->length
!= 0);
106 dns_rdata_toregion(rdata1
, &r1
);
107 dns_rdata_toregion(rdata2
, &r2
);
108 return (isc_region_compare(&r1
, &r2
));
111 static inline isc_result_t
112 fromstruct_x25(ARGS_FROMSTRUCT
) {
113 dns_rdata_x25_t
*x25
= source
;
117 REQUIRE(source
!= NULL
);
118 REQUIRE(x25
->common
.rdtype
== type
);
119 REQUIRE(x25
->common
.rdclass
== rdclass
);
120 REQUIRE(x25
->x25
!= NULL
&& x25
->x25_len
!= 0);
125 if (x25
->x25_len
< 4)
126 return (ISC_R_RANGE
);
128 for (i
= 0; i
< x25
->x25_len
; i
++)
129 if (!isdigit(x25
->x25
[i
] & 0xff))
130 return (ISC_R_RANGE
);
132 RETERR(uint8_tobuffer(x25
->x25_len
, target
));
133 return (mem_tobuffer(target
, x25
->x25
, x25
->x25_len
));
136 static inline isc_result_t
137 tostruct_x25(ARGS_TOSTRUCT
) {
138 dns_rdata_x25_t
*x25
= target
;
141 REQUIRE(rdata
->type
== 19);
142 REQUIRE(target
!= NULL
);
143 REQUIRE(rdata
->length
!= 0);
145 x25
->common
.rdclass
= rdata
->rdclass
;
146 x25
->common
.rdtype
= rdata
->type
;
147 ISC_LINK_INIT(&x25
->common
, link
);
149 dns_rdata_toregion(rdata
, &r
);
150 x25
->x25_len
= uint8_fromregion(&r
);
151 isc_region_consume(&r
, 1);
152 x25
->x25
= mem_maybedup(mctx
, r
.base
, x25
->x25_len
);
153 if (x25
->x25
== NULL
)
154 return (ISC_R_NOMEMORY
);
157 return (ISC_R_SUCCESS
);
161 freestruct_x25(ARGS_FREESTRUCT
) {
162 dns_rdata_x25_t
*x25
= source
;
163 REQUIRE(source
!= NULL
);
164 REQUIRE(x25
->common
.rdtype
== 19);
166 if (x25
->mctx
== NULL
)
169 if (x25
->x25
!= NULL
)
170 isc_mem_free(x25
->mctx
, x25
->x25
);
174 static inline isc_result_t
175 additionaldata_x25(ARGS_ADDLDATA
) {
176 REQUIRE(rdata
->type
== 19);
182 return (ISC_R_SUCCESS
);
185 static inline isc_result_t
186 digest_x25(ARGS_DIGEST
) {
189 REQUIRE(rdata
->type
== 19);
191 dns_rdata_toregion(rdata
, &r
);
193 return ((digest
)(arg
, &r
));
196 static inline isc_boolean_t
197 checkowner_x25(ARGS_CHECKOWNER
) {
209 static inline isc_boolean_t
210 checknames_x25(ARGS_CHECKNAMES
) {
212 REQUIRE(rdata
->type
== 19);
222 casecompare_x25(ARGS_COMPARE
) {
223 return (compare_x25(rdata1
, rdata2
));
226 #endif /* RDATA_GENERIC_X25_19_C */