x25_19.c 3.82 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
 * 
Mark Andrews's avatar
Mark Andrews committed
8
9
10
11
12
13
14
15
16
17
 * 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.
 */

Brian Wellington's avatar
Brian Wellington committed
18
/* $Id: x25_19.c,v 1.12 2000/03/17 00:15:30 bwelling 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

#include <ctype.h>

29
static inline isc_result_t
30
fromtext_x25(dns_rdataclass_t rdclass, dns_rdatatype_t type,
Mark Andrews's avatar
Mark Andrews committed
31
32
33
	     isc_lex_t *lexer, dns_name_t *origin,
	     isc_boolean_t downcase, isc_buffer_t *target)
{
Mark Andrews's avatar
Mark Andrews committed
34
35
36
	isc_token_t token;
	unsigned int i;

Brian Wellington's avatar
Brian Wellington committed
37
38
39
	UNUSED(rdclass);
	UNUSED(origin);
	UNUSED(downcase);
Mark Andrews's avatar
Mark Andrews committed
40

Brian Wellington's avatar
Brian Wellington committed
41
	REQUIRE(type == 19);
Mark Andrews's avatar
Mark Andrews committed
42

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

52
static inline isc_result_t
53
54
55
totext_x25(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx, 
	   isc_buffer_t *target) 
{
Mark Andrews's avatar
Mark Andrews committed
56
57
	isc_region_t region;

Brian Wellington's avatar
Brian Wellington committed
58
	UNUSED(tctx);
Mark Andrews's avatar
Mark Andrews committed
59

Brian Wellington's avatar
Brian Wellington committed
60
	REQUIRE(rdata->type == 19);
Mark Andrews's avatar
Mark Andrews committed
61
62
63
64
65

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

66
static inline isc_result_t
67
fromwire_x25(dns_rdataclass_t rdclass, dns_rdatatype_t type,
Mark Andrews's avatar
Mark Andrews committed
68
69
70
	     isc_buffer_t *source, dns_decompress_t *dctx,
	     isc_boolean_t downcase, isc_buffer_t *target)
{
Brian Wellington's avatar
Brian Wellington committed
71
	isc_region_t sr;
Mark Andrews's avatar
Mark Andrews committed
72

Brian Wellington's avatar
Brian Wellington committed
73
74
75
	UNUSED(dctx);
	UNUSED(rdclass);
	UNUSED(downcase);
Mark Andrews's avatar
Mark Andrews committed
76

Brian Wellington's avatar
Brian Wellington committed
77
	REQUIRE(type == 19);
Mark Andrews's avatar
Mark Andrews committed
78

Brian Wellington's avatar
Brian Wellington committed
79
80
81
	isc_buffer_active(source, &sr);
	if (sr.length < 5)
		return (DNS_R_FORMERR);
Mark Andrews's avatar
Mark Andrews committed
82
83
84
	return (txt_fromwire(source, target));
}

85
static inline isc_result_t
Mark Andrews's avatar
Mark Andrews committed
86
towire_x25(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target) {
Brian Wellington's avatar
Brian Wellington committed
87
	UNUSED(cctx);
Mark Andrews's avatar
Mark Andrews committed
88
89
90
91
92
93

	REQUIRE(rdata->type == 19);

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

94
static inline int
Mark Andrews's avatar
Mark Andrews committed
95
compare_x25(dns_rdata_t *rdata1, dns_rdata_t *rdata2) {
Brian Wellington's avatar
Brian Wellington committed
96
97
	isc_region_t r1;
	isc_region_t r2;
Mark Andrews's avatar
Mark Andrews committed
98
99
	
	REQUIRE(rdata1->type == rdata2->type);
100
	REQUIRE(rdata1->rdclass == rdata2->rdclass);
Mark Andrews's avatar
Mark Andrews committed
101
102
	REQUIRE(rdata1->type == 19);

Brian Wellington's avatar
Brian Wellington committed
103
104
105
	dns_rdata_toregion(rdata1, &r1);
	dns_rdata_toregion(rdata2, &r2);
	return (compare_region(&r1, &r2));
Mark Andrews's avatar
Mark Andrews committed
106
107
}

108
static inline isc_result_t
109
fromstruct_x25(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
Mark Andrews's avatar
Mark Andrews committed
110
111
	       isc_buffer_t *target)
{
Brian Wellington's avatar
Brian Wellington committed
112
113
114
	UNUSED(rdclass);
	UNUSED(source);
	UNUSED(target);
Mark Andrews's avatar
Mark Andrews committed
115
116
117
118
119
120

	REQUIRE(type == 19);

	return (DNS_R_NOTIMPLEMENTED);
}

121
static inline isc_result_t
122
tostruct_x25(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
Mark Andrews's avatar
Mark Andrews committed
123
124
125

	REQUIRE(rdata->type == 19);

Brian Wellington's avatar
Brian Wellington committed
126
127
	UNUSED(target);
	UNUSED(mctx);
Mark Andrews's avatar
Mark Andrews committed
128
129
130

	return (DNS_R_NOTIMPLEMENTED);
}
131

132
static inline void
133
134
135
136
freestruct_x25(void *source) {
	REQUIRE(source != NULL);
	REQUIRE(ISC_FALSE);	/*XXX*/
}
137

138
static inline isc_result_t
139
140
141
additionaldata_x25(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
		   void *arg)
{
Brian Wellington's avatar
Brian Wellington committed
142
143
	UNUSED(add);
	UNUSED(arg);
144

Brian Wellington's avatar
Brian Wellington committed
145
	REQUIRE(rdata->type == 19);
146
147
148
149

	return (DNS_R_SUCCESS);
}

150
static inline isc_result_t
Bob Halley's avatar
Bob Halley committed
151
152
153
154
155
156
157
158
159
160
digest_x25(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) {
	isc_region_t r;

	REQUIRE(rdata->type == 19);

	dns_rdata_toregion(rdata, &r);

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

161
#endif	/* RDATA_GENERIC_X25_19_C */