1/*
2 * Copyright (C) 2004, 2005, 2007, 2009  Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2002  Internet Software Consortium.
4 *
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.
8 *
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.
16 */
17
18/* $Id: x25_19.c,v 1.41 2009/12/04 22:06:37 tbox Exp $ */
19
20/* Reviewed: Thu Mar 16 16:15:57 PST 2000 by bwelling */
21
22/* RFC1183 */
23
24#ifndef RDATA_GENERIC_X25_19_C
25#define RDATA_GENERIC_X25_19_C
26
27#define RRTYPE_X25_ATTRIBUTES (0)
28
29static inline isc_result_t
30fromtext_x25(ARGS_FROMTEXT) {
31	isc_token_t token;
32	unsigned int i;
33
34	REQUIRE(type == 19);
35
36	UNUSED(type);
37	UNUSED(rdclass);
38	UNUSED(origin);
39	UNUSED(options);
40	UNUSED(callbacks);
41
42	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
43				      ISC_FALSE));
44	if (token.value.as_textregion.length < 4)
45		RETTOK(DNS_R_SYNTAX);
46	for (i = 0; i < token.value.as_textregion.length; i++)
47		if (!isdigit(token.value.as_textregion.base[i] & 0xff))
48			RETTOK(ISC_R_RANGE);
49	RETTOK(txt_fromtext(&token.value.as_textregion, target));
50	return (ISC_R_SUCCESS);
51}
52
53static inline isc_result_t
54totext_x25(ARGS_TOTEXT) {
55	isc_region_t region;
56
57	UNUSED(tctx);
58
59	REQUIRE(rdata->type == 19);
60	REQUIRE(rdata->length != 0);
61
62	dns_rdata_toregion(rdata, &region);
63	return (txt_totext(&region, target));
64}
65
66static inline isc_result_t
67fromwire_x25(ARGS_FROMWIRE) {
68	isc_region_t sr;
69
70	REQUIRE(type == 19);
71
72	UNUSED(type);
73	UNUSED(dctx);
74	UNUSED(rdclass);
75	UNUSED(options);
76
77	isc_buffer_activeregion(source, &sr);
78	if (sr.length < 5)
79		return (DNS_R_FORMERR);
80	return (txt_fromwire(source, target));
81}
82
83static inline isc_result_t
84towire_x25(ARGS_TOWIRE) {
85	UNUSED(cctx);
86
87	REQUIRE(rdata->type == 19);
88	REQUIRE(rdata->length != 0);
89
90	return (mem_tobuffer(target, rdata->data, rdata->length));
91}
92
93static inline int
94compare_x25(ARGS_COMPARE) {
95	isc_region_t r1;
96	isc_region_t r2;
97
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);
103
104	dns_rdata_toregion(rdata1, &r1);
105	dns_rdata_toregion(rdata2, &r2);
106	return (isc_region_compare(&r1, &r2));
107}
108
109static inline isc_result_t
110fromstruct_x25(ARGS_FROMSTRUCT) {
111	dns_rdata_x25_t *x25 = source;
112	isc_uint8_t i;
113
114	REQUIRE(type == 19);
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);
119
120	UNUSED(type);
121	UNUSED(rdclass);
122
123	if (x25->x25_len < 4)
124		return (ISC_R_RANGE);
125
126	for (i = 0; i < x25->x25_len; i++)
127		if (!isdigit(x25->x25[i] & 0xff))
128			return (ISC_R_RANGE);
129
130	RETERR(uint8_tobuffer(x25->x25_len, target));
131	return (mem_tobuffer(target, x25->x25, x25->x25_len));
132}
133
134static inline isc_result_t
135tostruct_x25(ARGS_TOSTRUCT) {
136	dns_rdata_x25_t *x25 = target;
137	isc_region_t r;
138
139	REQUIRE(rdata->type == 19);
140	REQUIRE(target != NULL);
141	REQUIRE(rdata->length != 0);
142
143	x25->common.rdclass = rdata->rdclass;
144	x25->common.rdtype = rdata->type;
145	ISC_LINK_INIT(&x25->common, link);
146
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);
153
154	x25->mctx = mctx;
155	return (ISC_R_SUCCESS);
156}
157
158static inline void
159freestruct_x25(ARGS_FREESTRUCT) {
160	dns_rdata_x25_t *x25 = source;
161	REQUIRE(source != NULL);
162	REQUIRE(x25->common.rdtype == 19);
163
164	if (x25->mctx == NULL)
165		return;
166
167	if (x25->x25 != NULL)
168		isc_mem_free(x25->mctx, x25->x25);
169	x25->mctx = NULL;
170}
171
172static inline isc_result_t
173additionaldata_x25(ARGS_ADDLDATA) {
174	REQUIRE(rdata->type == 19);
175
176	UNUSED(rdata);
177	UNUSED(add);
178	UNUSED(arg);
179
180	return (ISC_R_SUCCESS);
181}
182
183static inline isc_result_t
184digest_x25(ARGS_DIGEST) {
185	isc_region_t r;
186
187	REQUIRE(rdata->type == 19);
188
189	dns_rdata_toregion(rdata, &r);
190
191	return ((digest)(arg, &r));
192}
193
194static inline isc_boolean_t
195checkowner_x25(ARGS_CHECKOWNER) {
196
197	REQUIRE(type == 19);
198
199	UNUSED(name);
200	UNUSED(type);
201	UNUSED(rdclass);
202	UNUSED(wildcard);
203
204	return (ISC_TRUE);
205}
206
207static inline isc_boolean_t
208checknames_x25(ARGS_CHECKNAMES) {
209
210	REQUIRE(rdata->type == 19);
211
212	UNUSED(rdata);
213	UNUSED(owner);
214	UNUSED(bad);
215
216	return (ISC_TRUE);
217}
218
219static inline int
220casecompare_x25(ARGS_COMPARE) {
221	return (compare_x25(rdata1, rdata2));
222}
223
224#endif	/* RDATA_GENERIC_X25_19_C */
225