Merge from vendor branch SENDMAIL:
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / dns / rdata / generic / rp_17.c
1 /*
2  * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2001  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and 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: rp_17.c,v 1.35.2.1 2004/03/09 06:11:33 marka Exp $ */
19
20 /* RFC 1183 */
21
22 #ifndef RDATA_GENERIC_RP_17_C
23 #define RDATA_GENERIC_RP_17_C
24
25 #define RRTYPE_RP_ATTRIBUTES (0)
26
27 static inline isc_result_t
28 fromtext_rp(ARGS_FROMTEXT) {
29         isc_token_t token;
30         dns_name_t name;
31         isc_buffer_t buffer;
32         int i;
33
34         REQUIRE(type == 17);
35
36         UNUSED(type);
37         UNUSED(rdclass);
38         UNUSED(callbacks);
39
40         origin = (origin != NULL) ? origin : dns_rootname;
41
42         for (i = 0; i < 2 ; i++) {
43                 RETERR(isc_lex_getmastertoken(lexer, &token,
44                                               isc_tokentype_string,
45                                               ISC_FALSE));
46                 dns_name_init(&name, NULL);
47                 buffer_fromregion(&buffer, &token.value.as_region);
48                 RETTOK(dns_name_fromtext(&name, &buffer, origin,
49                                          downcase, target));
50         }
51         return (ISC_R_SUCCESS);
52 }
53
54 static inline isc_result_t
55 totext_rp(ARGS_TOTEXT) {
56         isc_region_t region;
57         dns_name_t rmail;
58         dns_name_t email;
59         dns_name_t prefix;
60         isc_boolean_t sub;
61
62         REQUIRE(rdata->type == 17);
63         REQUIRE(rdata->length != 0);
64
65         dns_name_init(&rmail, NULL);
66         dns_name_init(&email, NULL);
67         dns_name_init(&prefix, NULL);
68
69         dns_rdata_toregion(rdata, &region);
70
71         dns_name_fromregion(&rmail, &region);
72         isc_region_consume(&region, rmail.length);
73
74         dns_name_fromregion(&email, &region);
75         isc_region_consume(&region, email.length);
76
77         sub = name_prefix(&rmail, tctx->origin, &prefix);
78         RETERR(dns_name_totext(&prefix, sub, target));
79
80         RETERR(str_totext(" ", target));
81
82         sub = name_prefix(&email, tctx->origin, &prefix);
83         return (dns_name_totext(&prefix, sub, target));
84 }
85
86 static inline isc_result_t
87 fromwire_rp(ARGS_FROMWIRE) {
88         dns_name_t rmail;
89         dns_name_t email;
90
91         REQUIRE(type == 17);
92
93         UNUSED(type);
94         UNUSED(rdclass);
95
96         dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
97
98         dns_name_init(&rmail, NULL);
99         dns_name_init(&email, NULL);
100
101         RETERR(dns_name_fromwire(&rmail, source, dctx, downcase, target));
102         return (dns_name_fromwire(&email, source, dctx, downcase, target));
103 }
104
105 static inline isc_result_t
106 towire_rp(ARGS_TOWIRE) {
107         isc_region_t region;
108         dns_name_t rmail;
109         dns_name_t email;
110         dns_offsets_t roffsets;
111         dns_offsets_t eoffsets;
112
113         REQUIRE(rdata->type == 17);
114         REQUIRE(rdata->length != 0);
115
116         dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
117         dns_name_init(&rmail, roffsets);
118         dns_name_init(&email, eoffsets);
119
120         dns_rdata_toregion(rdata, &region);
121
122         dns_name_fromregion(&rmail, &region);
123         isc_region_consume(&region, rmail.length);
124
125         RETERR(dns_name_towire(&rmail, cctx, target));
126
127         dns_name_fromregion(&rmail, &region);
128         isc_region_consume(&region, rmail.length);
129
130         return (dns_name_towire(&rmail, cctx, target));
131 }
132
133 static inline int
134 compare_rp(ARGS_COMPARE) {
135         isc_region_t region1;
136         isc_region_t region2;
137         dns_name_t name1;
138         dns_name_t name2;
139         int order;
140
141         REQUIRE(rdata1->type == rdata2->type);
142         REQUIRE(rdata1->rdclass == rdata2->rdclass);
143         REQUIRE(rdata1->type == 17);
144         REQUIRE(rdata1->length != 0);
145         REQUIRE(rdata2->length != 0);
146
147         dns_name_init(&name1, NULL);
148         dns_name_init(&name2, NULL);
149
150         dns_rdata_toregion(rdata1, &region1);
151         dns_rdata_toregion(rdata2, &region2);
152
153         dns_name_fromregion(&name1, &region1);
154         dns_name_fromregion(&name2, &region2);
155
156         order = dns_name_rdatacompare(&name1, &name2);
157         if (order != 0)
158                 return (order);
159
160         isc_region_consume(&region1, name_length(&name1));
161         isc_region_consume(&region2, name_length(&name2));
162
163         dns_name_init(&name1, NULL);
164         dns_name_init(&name2, NULL);
165
166         dns_name_fromregion(&name1, &region1);
167         dns_name_fromregion(&name2, &region2);
168
169         return (dns_name_rdatacompare(&name1, &name2));
170 }
171
172 static inline isc_result_t
173 fromstruct_rp(ARGS_FROMSTRUCT) {
174         dns_rdata_rp_t *rp = source;
175         isc_region_t region;
176
177         REQUIRE(type == 17);
178         REQUIRE(source != NULL);
179         REQUIRE(rp->common.rdtype == type);
180         REQUIRE(rp->common.rdclass == rdclass);
181
182         UNUSED(type);
183         UNUSED(rdclass);
184
185         dns_name_toregion(&rp->mail, &region);
186         RETERR(isc_buffer_copyregion(target, &region));
187         dns_name_toregion(&rp->text, &region);
188         return (isc_buffer_copyregion(target, &region));
189 }
190
191 static inline isc_result_t
192 tostruct_rp(ARGS_TOSTRUCT) {
193         isc_result_t result;
194         isc_region_t region;
195         dns_rdata_rp_t *rp = target;
196         dns_name_t name;
197
198         REQUIRE(rdata->type == 17);
199         REQUIRE(target != NULL);
200         REQUIRE(rdata->length != 0);
201
202         rp->common.rdclass = rdata->rdclass;
203         rp->common.rdtype = rdata->type;
204         ISC_LINK_INIT(&rp->common, link);
205
206         dns_name_init(&name, NULL);
207         dns_rdata_toregion(rdata, &region);
208         dns_name_fromregion(&name, &region);
209         dns_name_init(&rp->mail, NULL);
210         RETERR(name_duporclone(&name, mctx, &rp->mail));
211         isc_region_consume(&region, name_length(&name));
212         dns_name_fromregion(&name, &region);
213         dns_name_init(&rp->text, NULL);
214         result = name_duporclone(&name, mctx, &rp->text);
215         if (result != ISC_R_SUCCESS)
216                 goto cleanup;
217
218         rp->mctx = mctx;
219         return (ISC_R_SUCCESS);
220
221  cleanup:
222         if (mctx != NULL)
223                 dns_name_free(&rp->mail, mctx);
224         return (ISC_R_NOMEMORY);
225 }
226
227 static inline void
228 freestruct_rp(ARGS_FREESTRUCT) {
229         dns_rdata_rp_t *rp = source;
230
231         REQUIRE(source != NULL);
232         REQUIRE(rp->common.rdtype == 17);
233
234         if (rp->mctx == NULL)
235                 return;
236
237         dns_name_free(&rp->mail, rp->mctx);
238         dns_name_free(&rp->text, rp->mctx);
239         rp->mctx = NULL;
240 }
241
242 static inline isc_result_t
243 additionaldata_rp(ARGS_ADDLDATA) {
244         REQUIRE(rdata->type == 17);
245
246         UNUSED(rdata);
247         UNUSED(add);
248         UNUSED(arg);
249
250         return (ISC_R_SUCCESS);
251 }
252
253 static inline isc_result_t
254 digest_rp(ARGS_DIGEST) {
255         isc_region_t r;
256         dns_name_t name;
257
258         REQUIRE(rdata->type == 17);
259
260         dns_rdata_toregion(rdata, &r);
261         dns_name_init(&name, NULL);
262
263         dns_name_fromregion(&name, &r);
264         RETERR(dns_name_digest(&name, digest, arg));
265         isc_region_consume(&r, name_length(&name));
266
267         dns_name_init(&name, NULL);
268         dns_name_fromregion(&name, &r);
269
270         return (dns_name_digest(&name, digest, arg));
271 }
272
273 #endif  /* RDATA_GENERIC_RP_17_C */