x25_19.c 4.33 KB
Newer Older
Mark Andrews's avatar
Mark Andrews committed
1
/*
Bob Halley's avatar
Bob Halley committed
2
 * Copyright (C) 1999, 2000  Internet Software Consortium.
3
 *
Mark Andrews's avatar
Mark Andrews committed
4
5
6
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
7
 *
8
9
10
11
12
13
14
15
 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
 * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Mark Andrews's avatar
Mark Andrews committed
16
17
 */

18
/* $Id: x25_19.c,v 1.24 2000/10/25 05:43:57 marka Exp $ */
Mark Andrews's avatar
Mark Andrews committed
19

Brian Wellington's avatar
Brian Wellington committed
20
21
22
/* Reviewed: Thu Mar 16 16:15:57 PST 2000 by bwelling */

/* RFC 1183 */
Mark Andrews's avatar
Mark Andrews committed
23

24
25
#ifndef RDATA_GENERIC_X25_19_C
#define RDATA_GENERIC_X25_19_C
Mark Andrews's avatar
Mark Andrews committed
26

27
28
#define RRTYPE_X25_ATTRIBUTES (0)

29
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
30
fromtext_x25(ARGS_FROMTEXT) {
Mark Andrews's avatar
Mark Andrews committed
31
32
33
	isc_token_t token;
	unsigned int i;

Brian Wellington's avatar
Brian Wellington committed
34
35
36
	UNUSED(rdclass);
	UNUSED(origin);
	UNUSED(downcase);
Mark Andrews's avatar
Mark Andrews committed
37

Brian Wellington's avatar
Brian Wellington committed
38
	REQUIRE(type == 19);
Mark Andrews's avatar
Mark Andrews committed
39

40
	RETERR(gettoken(lexer, &token, isc_tokentype_qstring, ISC_FALSE));
Brian Wellington's avatar
Brian Wellington committed
41
42
	if (token.value.as_textregion.length < 4)
		return (DNS_R_SYNTAX);
Mark Andrews's avatar
Mark Andrews committed
43
	for (i = 0; i < token.value.as_textregion.length; i++)
Brian Wellington's avatar
Brian Wellington committed
44
		if (!isdigit(token.value.as_textregion.base[i] & 0xff))
David Lawrence's avatar
David Lawrence committed
45
			return (ISC_R_RANGE);
Mark Andrews's avatar
Mark Andrews committed
46
47
48
	return (txt_fromtext(&token.value.as_textregion, target));
}

49
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
50
totext_x25(ARGS_TOTEXT) {
Mark Andrews's avatar
Mark Andrews committed
51
52
	isc_region_t region;

Brian Wellington's avatar
Brian Wellington committed
53
	UNUSED(tctx);
Mark Andrews's avatar
Mark Andrews committed
54

Brian Wellington's avatar
Brian Wellington committed
55
	REQUIRE(rdata->type == 19);
56
	REQUIRE(rdata->length != 0);
Mark Andrews's avatar
Mark Andrews committed
57
58
59
60
61

	dns_rdata_toregion(rdata, &region);
	return (txt_totext(&region, target));
}

62
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
63
fromwire_x25(ARGS_FROMWIRE) {
Brian Wellington's avatar
Brian Wellington committed
64
	isc_region_t sr;
Mark Andrews's avatar
Mark Andrews committed
65

Brian Wellington's avatar
Brian Wellington committed
66
67
68
	UNUSED(dctx);
	UNUSED(rdclass);
	UNUSED(downcase);
Mark Andrews's avatar
Mark Andrews committed
69

Brian Wellington's avatar
Brian Wellington committed
70
	REQUIRE(type == 19);
Mark Andrews's avatar
Mark Andrews committed
71

72
	isc_buffer_activeregion(source, &sr);
Brian Wellington's avatar
Brian Wellington committed
73
74
	if (sr.length < 5)
		return (DNS_R_FORMERR);
Mark Andrews's avatar
Mark Andrews committed
75
76
77
	return (txt_fromwire(source, target));
}

78
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
79
towire_x25(ARGS_TOWIRE) {
Brian Wellington's avatar
Brian Wellington committed
80
	UNUSED(cctx);
Mark Andrews's avatar
Mark Andrews committed
81
82

	REQUIRE(rdata->type == 19);
83
	REQUIRE(rdata->length != 0);
Mark Andrews's avatar
Mark Andrews committed
84
85
86
87

	return (mem_tobuffer(target, rdata->data, rdata->length));
}

88
static inline int
David Lawrence's avatar
David Lawrence committed
89
compare_x25(ARGS_COMPARE) {
Brian Wellington's avatar
Brian Wellington committed
90
91
	isc_region_t r1;
	isc_region_t r2;
92

Mark Andrews's avatar
Mark Andrews committed
93
	REQUIRE(rdata1->type == rdata2->type);
94
	REQUIRE(rdata1->rdclass == rdata2->rdclass);
Mark Andrews's avatar
Mark Andrews committed
95
	REQUIRE(rdata1->type == 19);
96
97
	REQUIRE(rdata1->length != 0);
	REQUIRE(rdata2->length != 0);
Mark Andrews's avatar
Mark Andrews committed
98

Brian Wellington's avatar
Brian Wellington committed
99
100
101
	dns_rdata_toregion(rdata1, &r1);
	dns_rdata_toregion(rdata2, &r2);
	return (compare_region(&r1, &r2));
Mark Andrews's avatar
Mark Andrews committed
102
103
}

104
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
105
fromstruct_x25(ARGS_FROMSTRUCT) {
106
107
	dns_rdata_x25_t *x25 = source;
	isc_uint8_t i;
Mark Andrews's avatar
Mark Andrews committed
108
109

	REQUIRE(type == 19);
110
111
112
113
114
115
116
117
118
	REQUIRE(source != NULL);
	REQUIRE(x25->common.rdtype == type);
	REQUIRE(x25->common.rdclass == rdclass);
	REQUIRE((x25->x25 == NULL && x25->x25_len == 0) ||
		(x25->x25 != NULL && x25->x25_len != 0));

	for (i = 0; i < x25->x25_len; i++)
		if (!isdigit(x25->x25[i] & 0xff))
			return (ISC_R_RANGE);
Mark Andrews's avatar
Mark Andrews committed
119

120
121
	RETERR(uint8_tobuffer(x25->x25_len, target));
	return (mem_tobuffer(target, x25->x25, x25->x25_len));
Mark Andrews's avatar
Mark Andrews committed
122
123
}

124
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
125
tostruct_x25(ARGS_TOSTRUCT) {
126
127
	dns_rdata_x25_t *x25 = target;
	isc_region_t r;
Mark Andrews's avatar
Mark Andrews committed
128
129

	REQUIRE(rdata->type == 19);
130
	REQUIRE(target != NULL);
131
	REQUIRE(rdata->length != 0);
Mark Andrews's avatar
Mark Andrews committed
132

133
134
135
	x25->common.rdclass = rdata->rdclass;
	x25->common.rdtype = rdata->type;
	ISC_LINK_INIT(&x25->common, link);
Mark Andrews's avatar
Mark Andrews committed
136

137
138
139
140
141
142
143
144
145
146
147
148
	dns_rdata_toregion(rdata, &r);
	x25->x25_len = uint8_fromregion(&r);
	isc_region_consume(&r, 1);
	if (x25->x25_len != 0) {
		x25->x25 = mem_maybedup(mctx, r.base, x25->x25_len);
		if (x25->x25 == NULL)
			return (ISC_R_NOMEMORY);
	} else
		x25->x25 = NULL;

	x25->mctx = mctx;
	return (ISC_R_SUCCESS);
Mark Andrews's avatar
Mark Andrews committed
149
}
150

151
static inline void
David Lawrence's avatar
David Lawrence committed
152
freestruct_x25(ARGS_FREESTRUCT) {
153
	dns_rdata_x25_t *x25 = source;
154
	REQUIRE(source != NULL);
155
	REQUIRE(x25->common.rdtype == 19);
156

157
158
159
160
161
162
	if (x25->mctx == NULL)
		return;

	if (x25->x25 != NULL)
		isc_mem_free(x25->mctx, x25->x25);
	x25->mctx = NULL;
163
}
164

165
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
166
additionaldata_x25(ARGS_ADDLDATA) {
167
168
169
	REQUIRE(rdata->type == 19);

	UNUSED(rdata);
Brian Wellington's avatar
Brian Wellington committed
170
171
	UNUSED(add);
	UNUSED(arg);
172

173
	return (ISC_R_SUCCESS);
174
175
}

176
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
177
digest_x25(ARGS_DIGEST) {
Bob Halley's avatar
Bob Halley committed
178
179
180
181
182
183
184
185
186
	isc_region_t r;

	REQUIRE(rdata->type == 19);

	dns_rdata_toregion(rdata, &r);

	return ((digest)(arg, &r));
}

187
#endif	/* RDATA_GENERIC_X25_19_C */