rp_17.c 5.83 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.
Mark Andrews's avatar
Mark Andrews committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 * 
 * 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.
 * 
 * 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.
 */

18
/* $Id: rp_17.c,v 1.18 2000/04/06 22:03:09 explorer Exp $ */
Mark Andrews's avatar
Mark Andrews committed
19

20
/* RFC 1183 */
Mark Andrews's avatar
Mark Andrews committed
21

22
23
#ifndef RDATA_GENERIC_RP_17_C
#define RDATA_GENERIC_RP_17_C
Mark Andrews's avatar
Mark Andrews committed
24

25
static inline isc_result_t
26
fromtext_rp(dns_rdataclass_t rdclass, dns_rdatatype_t type,
Mark Andrews's avatar
Mark Andrews committed
27
28
29
	    isc_lex_t *lexer, dns_name_t *origin,
	    isc_boolean_t downcase, isc_buffer_t *target)
{
Mark Andrews's avatar
Mark Andrews committed
30
31
32
33
34
	isc_token_t token;
	dns_name_t name;
	isc_buffer_t buffer;
	int i;

Michael Graff's avatar
Michael Graff committed
35
36
	UNUSED(rdclass);

Mark Andrews's avatar
Mark Andrews committed
37
38
	REQUIRE(type == 17);

Michael Graff's avatar
Michael Graff committed
39
40
	origin = (origin != NULL) ? origin : dns_rootname;

Mark Andrews's avatar
Mark Andrews committed
41
42
43
44
45
46
47
48
49
	for (i = 0; i < 2 ; i++) {
		RETERR(gettoken(lexer, &token, isc_tokentype_string,
				ISC_FALSE));
		dns_name_init(&name, NULL);
		buffer_fromregion(&buffer, &token.value.as_region,
				  ISC_BUFFERTYPE_TEXT);
		RETERR(dns_name_fromtext(&name, &buffer, origin,
					 downcase, target));
	}
50
	return (ISC_R_SUCCESS);
Mark Andrews's avatar
Mark Andrews committed
51
52
}

53
static inline isc_result_t
54
55
56
totext_rp(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx, 
	  isc_buffer_t *target) 
{
Mark Andrews's avatar
Mark Andrews committed
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
	isc_region_t region;
	dns_name_t rmail;
	dns_name_t email;
	dns_name_t prefix;
	isc_boolean_t sub;

	REQUIRE(rdata->type == 17);

	dns_name_init(&rmail, NULL);
	dns_name_init(&email, NULL);
	dns_name_init(&prefix, NULL);

	dns_rdata_toregion(rdata, &region);

	dns_name_fromregion(&rmail, &region);
	isc_region_consume(&region, rmail.length);

	dns_name_fromregion(&email, &region);
	isc_region_consume(&region, email.length);

77
	sub = name_prefix(&rmail, tctx->origin, &prefix);
Mark Andrews's avatar
Mark Andrews committed
78
79
80
81
	RETERR(dns_name_totext(&prefix, sub, target));

	RETERR(str_totext(" ", target));

82
	sub = name_prefix(&email, tctx->origin, &prefix);
Mark Andrews's avatar
Mark Andrews committed
83
84
85
	return (dns_name_totext(&prefix, sub, target));
}

86
static inline isc_result_t
87
fromwire_rp(dns_rdataclass_t rdclass, dns_rdatatype_t type,
Mark Andrews's avatar
Mark Andrews committed
88
89
90
	    isc_buffer_t *source, dns_decompress_t *dctx,
	    isc_boolean_t downcase, isc_buffer_t *target)
{
Mark Andrews's avatar
Mark Andrews committed
91
92
        dns_name_t rmail;
        dns_name_t email;
Michael Graff's avatar
Michael Graff committed
93
94

	UNUSED(rdclass);
Mark Andrews's avatar
Mark Andrews committed
95
96
97
        
	REQUIRE(type == 17);

Mark Andrews's avatar
Mark Andrews committed
98
99
100
101
102
	if (dns_decompress_edns(dctx) >= 1 || !dns_decompress_strict(dctx))
		dns_decompress_setmethods(dctx, DNS_COMPRESS_ALL);
	else
		dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);

Mark Andrews's avatar
Mark Andrews committed
103
104
105
106
107
108
109
        dns_name_init(&rmail, NULL);
        dns_name_init(&email, NULL);

        RETERR(dns_name_fromwire(&rmail, source, dctx, downcase, target));
        return (dns_name_fromwire(&email, source, dctx, downcase, target));
}

110
static inline isc_result_t
Michael Graff's avatar
Michael Graff committed
111
112
towire_rp(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target)
{
Mark Andrews's avatar
Mark Andrews committed
113
114
115
116
117
118
	isc_region_t region;
	dns_name_t rmail;
	dns_name_t email;

	REQUIRE(rdata->type == 17);

Mark Andrews's avatar
Mark Andrews committed
119
120
121
122
123
	if (dns_compress_getedns(cctx) >= 1)
		dns_compress_setmethods(cctx, DNS_COMPRESS_ALL);
	else
		dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);

Mark Andrews's avatar
Mark Andrews committed
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
	dns_name_init(&rmail, NULL);
	dns_name_init(&email, NULL);

	dns_rdata_toregion(rdata, &region);

	dns_name_fromregion(&rmail, &region);
	isc_region_consume(&region, rmail.length);

	RETERR(dns_name_towire(&rmail, cctx, target));

	dns_name_fromregion(&rmail, &region);
	isc_region_consume(&region, rmail.length);

	return (dns_name_towire(&rmail, cctx, target));
}

140
static inline int
Michael Graff's avatar
Michael Graff committed
141
142
compare_rp(dns_rdata_t *rdata1, dns_rdata_t *rdata2)
{
Mark Andrews's avatar
Mark Andrews committed
143
144
145
146
	isc_region_t region1;
	isc_region_t region2;
	dns_name_t name1;
	dns_name_t name2;
147
	int order;
Mark Andrews's avatar
Mark Andrews committed
148
149

	REQUIRE(rdata1->type == rdata2->type);
150
	REQUIRE(rdata1->rdclass == rdata2->rdclass);
Mark Andrews's avatar
Mark Andrews committed
151
152
153
154
155
156
157
158
159
160
161
	REQUIRE(rdata1->type == 17);

	dns_name_init(&name1, NULL);
	dns_name_init(&name2, NULL);

	dns_rdata_toregion(rdata1, &region1);
	dns_rdata_toregion(rdata2, &region2);

	dns_name_fromregion(&name1, &region1);
	dns_name_fromregion(&name2, &region2);

162
163
164
	order = dns_name_rdatacompare(&name1, &name2);
	if (order != 0)
		return (order);
Mark Andrews's avatar
Mark Andrews committed
165
166
167
168
169
170
171
172
173
174

	isc_region_consume(&region1, name_length(&name1));
	isc_region_consume(&region2, name_length(&name2));

	dns_name_init(&name1, NULL);
	dns_name_init(&name2, NULL);

	dns_name_fromregion(&name1, &region1);
	dns_name_fromregion(&name2, &region2);

175
	return (dns_name_rdatacompare(&name1, &name2));
Mark Andrews's avatar
Mark Andrews committed
176
177
}

178
static inline isc_result_t
179
fromstruct_rp(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
Mark Andrews's avatar
Mark Andrews committed
180
181
	      isc_buffer_t *target)
{
Michael Graff's avatar
Michael Graff committed
182
183
184
	UNUSED(rdclass);
	UNUSED(source);
	UNUSED(target);
Mark Andrews's avatar
Mark Andrews committed
185
186
187

	REQUIRE(type == 17);

188
	return (ISC_R_NOTIMPLEMENTED);
Mark Andrews's avatar
Mark Andrews committed
189
190
}

191
static inline isc_result_t
Michael Graff's avatar
Michael Graff committed
192
193
194
195
tostruct_rp(dns_rdata_t *rdata, void *target, isc_mem_t *mctx)
{
	UNUSED(target);
	UNUSED(mctx);
Mark Andrews's avatar
Mark Andrews committed
196

Michael Graff's avatar
Michael Graff committed
197
	REQUIRE(rdata->type == 17);
Mark Andrews's avatar
Mark Andrews committed
198

199
	return (ISC_R_NOTIMPLEMENTED);
Mark Andrews's avatar
Mark Andrews committed
200
}
201

202
static inline void
Michael Graff's avatar
Michael Graff committed
203
204
freestruct_rp(void *source)
{
205
206
207
	REQUIRE(source != NULL);
	REQUIRE(ISC_FALSE);	/*XXX*/
}
208

209
static inline isc_result_t
210
211
212
additionaldata_rp(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
		  void *arg)
{
Michael Graff's avatar
Michael Graff committed
213
214
	UNUSED(add);
	UNUSED(arg);
215

Michael Graff's avatar
Michael Graff committed
216
	REQUIRE(rdata->type == 17);
217

218
	return (ISC_R_SUCCESS);
219
220
}

221
static inline isc_result_t
Michael Graff's avatar
Michael Graff committed
222
223
digest_rp(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg)
{
Bob Halley's avatar
Bob Halley committed
224
225
226
227
228
229
230
	isc_region_t r;
	dns_name_t name;

	REQUIRE(rdata->type == 17);

	dns_rdata_toregion(rdata, &r);
	dns_name_init(&name, NULL);
Michael Graff's avatar
Michael Graff committed
231

Bob Halley's avatar
Bob Halley committed
232
	dns_name_fromregion(&name, &r);
Michael Graff's avatar
Michael Graff committed
233
	RETERR(dns_name_digest(&name, digest, arg));
Bob Halley's avatar
Bob Halley committed
234
	isc_region_consume(&r, name_length(&name));
Michael Graff's avatar
Michael Graff committed
235

Bob Halley's avatar
Bob Halley committed
236
237
238
239
240
241
	dns_name_init(&name, NULL);
	dns_name_fromregion(&name, &r);

	return (dns_name_digest(&name, digest, arg));
}

242
#endif	/* RDATA_GENERIC_RP_17_C */