x25_19.c 4.18 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.
Michael Graff's avatar
Michael Graff committed
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.
Michael Graff's avatar
Michael Graff committed
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.22 2000/07/27 09:49:53 tale 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);
Mark Andrews's avatar
Mark Andrews committed
56
57
58
59
60

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

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

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

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

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

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

	REQUIRE(rdata->type == 19);

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

86
static inline int
David Lawrence's avatar
David Lawrence committed
87
compare_x25(ARGS_COMPARE) {
Brian Wellington's avatar
Brian Wellington committed
88
89
	isc_region_t r1;
	isc_region_t r2;
Mark Andrews's avatar
Mark Andrews committed
90
91
	
	REQUIRE(rdata1->type == rdata2->type);
92
	REQUIRE(rdata1->rdclass == rdata2->rdclass);
Mark Andrews's avatar
Mark Andrews committed
93
94
	REQUIRE(rdata1->type == 19);

Brian Wellington's avatar
Brian Wellington committed
95
96
97
	dns_rdata_toregion(rdata1, &r1);
	dns_rdata_toregion(rdata2, &r2);
	return (compare_region(&r1, &r2));
Mark Andrews's avatar
Mark Andrews committed
98
99
}

100
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
101
fromstruct_x25(ARGS_FROMSTRUCT) {
102
103
	dns_rdata_x25_t *x25 = source;
	isc_uint8_t i;
Mark Andrews's avatar
Mark Andrews committed
104
105

	REQUIRE(type == 19);
106
107
108
109
110
111
112
113
114
	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
115

116
117
	RETERR(uint8_tobuffer(x25->x25_len, target));
	return (mem_tobuffer(target, x25->x25, x25->x25_len));
Mark Andrews's avatar
Mark Andrews committed
118
119
}

120
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
121
tostruct_x25(ARGS_TOSTRUCT) {
122
123
	dns_rdata_x25_t *x25 = target;
	isc_region_t r;
Mark Andrews's avatar
Mark Andrews committed
124
125

	REQUIRE(rdata->type == 19);
126
	REQUIRE(target != NULL);
Mark Andrews's avatar
Mark Andrews committed
127

128
129
130
	x25->common.rdclass = rdata->rdclass;
	x25->common.rdtype = rdata->type;
	ISC_LINK_INIT(&x25->common, link);
Mark Andrews's avatar
Mark Andrews committed
131

132
133
134
135
136
137
138
139
140
141
142
143
	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
144
}
145

146
static inline void
David Lawrence's avatar
David Lawrence committed
147
freestruct_x25(ARGS_FREESTRUCT) {
148
	dns_rdata_x25_t *x25 = source;
149
	REQUIRE(source != NULL);
150
	REQUIRE(x25->common.rdtype == 19);
151

152
153
154
155
156
157
	if (x25->mctx == NULL)
		return;

	if (x25->x25 != NULL)
		isc_mem_free(x25->mctx, x25->x25);
	x25->mctx = NULL;
158
}
159

160
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
161
additionaldata_x25(ARGS_ADDLDATA) {
162
163
164
	REQUIRE(rdata->type == 19);

	UNUSED(rdata);
Brian Wellington's avatar
Brian Wellington committed
165
166
	UNUSED(add);
	UNUSED(arg);
167

168
	return (ISC_R_SUCCESS);
169
170
}

171
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
172
digest_x25(ARGS_DIGEST) {
Bob Halley's avatar
Bob Halley committed
173
174
175
176
177
178
179
180
181
	isc_region_t r;

	REQUIRE(rdata->type == 19);

	dns_rdata_toregion(rdata, &r);

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

182
#endif	/* RDATA_GENERIC_X25_19_C */