Merge branch 'vendor/TCPDUMP' (early part)
[dragonfly.git] / contrib / bind-9.3 / 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.12.4 2004/03/08 09:04:42 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         isc_boolean_t ok;
34
35         REQUIRE(type == 17);
36
37         UNUSED(type);
38         UNUSED(rdclass);
39         UNUSED(callbacks);
40
41         origin = (origin != NULL) ? origin : dns_rootname;
42
43         for (i = 0; i < 2; i++) {
44                 RETERR(isc_lex_getmastertoken(lexer, &token,
45                                               isc_tokentype_string,
46                                               ISC_FALSE));
47                 dns_name_init(&name, NULL);
48                 buffer_fromregion(&buffer, &token.value.as_region);
49                 RETTOK(dns_name_fromtext(&name, &buffer, origin,
50                                          options, target));
51                 ok = ISC_TRUE;
52                 if ((options & DNS_RDATA_CHECKNAMES) != 0 && i == 0)
53                         ok = dns_name_ismailbox(&name);
54                 if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
55                         RETTOK(DNS_R_BADNAME);
56                 if (!ok && callbacks != NULL)
57                         warn_badname(&name, lexer, callbacks);
58         }
59         return (ISC_R_SUCCESS);
60 }
61
62 static inline isc_result_t
63 totext_rp(ARGS_TOTEXT) {
64         isc_region_t region;
65         dns_name_t rmail;
66         dns_name_t email;
67         dns_name_t prefix;
68         isc_boolean_t sub;
69
70         REQUIRE(rdata->type == 17);
71         REQUIRE(rdata->length != 0);
72
73         dns_name_init(&rmail, NULL);
74         dns_name_init(&email, NULL);
75         dns_name_init(&prefix, NULL);
76
77         dns_rdata_toregion(rdata, &region);
78
79         dns_name_fromregion(&rmail, &region);
80         isc_region_consume(&region, rmail.length);
81
82         dns_name_fromregion(&email, &region);
83         isc_region_consume(&region, email.length);
84
85         sub = name_prefix(&rmail, tctx->origin, &prefix);
86         RETERR(dns_name_totext(&prefix, sub, target));
87
88         RETERR(str_totext(" ", target));
89
90         sub = name_prefix(&email, tctx->origin, &prefix);
91         return (dns_name_totext(&prefix, sub, target));
92 }
93
94 static inline isc_result_t
95 fromwire_rp(ARGS_FROMWIRE) {
96         dns_name_t rmail;
97         dns_name_t email;
98
99         REQUIRE(type == 17);
100
101         UNUSED(type);
102         UNUSED(rdclass);
103
104         dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
105
106         dns_name_init(&rmail, NULL);
107         dns_name_init(&email, NULL);
108
109         RETERR(dns_name_fromwire(&rmail, source, dctx, options, target));
110         return (dns_name_fromwire(&email, source, dctx, options, target));
111 }
112
113 static inline isc_result_t
114 towire_rp(ARGS_TOWIRE) {
115         isc_region_t region;
116         dns_name_t rmail;
117         dns_name_t email;
118         dns_offsets_t roffsets;
119         dns_offsets_t eoffsets;
120
121         REQUIRE(rdata->type == 17);
122         REQUIRE(rdata->length != 0);
123
124         dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
125         dns_name_init(&rmail, roffsets);
126         dns_name_init(&email, eoffsets);
127
128         dns_rdata_toregion(rdata, &region);
129
130         dns_name_fromregion(&rmail, &region);
131         isc_region_consume(&region, rmail.length);
132
133         RETERR(dns_name_towire(&rmail, cctx, target));
134
135         dns_name_fromregion(&rmail, &region);
136         isc_region_consume(&region, rmail.length);
137
138         return (dns_name_towire(&rmail, cctx, target));
139 }
140
141 static inline int
142 compare_rp(ARGS_COMPARE) {
143         isc_region_t region1;
144         isc_region_t region2;
145         dns_name_t name1;
146         dns_name_t name2;
147         int order;
148
149         REQUIRE(rdata1->type == rdata2->type);
150         REQUIRE(rdata1->rdclass == rdata2->rdclass);
151         REQUIRE(rdata1->type == 17);
152         REQUIRE(rdata1->length != 0);
153         REQUIRE(rdata2->length != 0);
154
155         dns_name_init(&name1, NULL);
156         dns_name_init(&name2, NULL);
157
158         dns_rdata_toregion(rdata1, &region1);
159         dns_rdata_toregion(rdata2, &region2);
160
161         dns_name_fromregion(&name1, &region1);
162         dns_name_fromregion(&name2, &region2);
163
164         order = dns_name_rdatacompare(&name1, &name2);
165         if (order != 0)
166                 return (order);
167
168         isc_region_consume(&region1, name_length(&name1));
169         isc_region_consume(&region2, name_length(&name2));
170
171         dns_name_init(&name1, NULL);
172         dns_name_init(&name2, NULL);
173
174         dns_name_fromregion(&name1, &region1);
175         dns_name_fromregion(&name2, &region2);
176
177         return (dns_name_rdatacompare(&name1, &name2));
178 }
179
180 static inline isc_result_t
181 fromstruct_rp(ARGS_FROMSTRUCT) {
182         dns_rdata_rp_t *rp = source;
183         isc_region_t region;
184
185         REQUIRE(type == 17);
186         REQUIRE(source != NULL);
187         REQUIRE(rp->common.rdtype == type);
188         REQUIRE(rp->common.rdclass == rdclass);
189
190         UNUSED(type);
191         UNUSED(rdclass);
192
193         dns_name_toregion(&rp->mail, &region);
194         RETERR(isc_buffer_copyregion(target, &region));
195         dns_name_toregion(&rp->text, &region);
196         return (isc_buffer_copyregion(target, &region));
197 }
198
199 static inline isc_result_t
200 tostruct_rp(ARGS_TOSTRUCT) {
201         isc_result_t result;
202         isc_region_t region;
203         dns_rdata_rp_t *rp = target;
204         dns_name_t name;
205
206         REQUIRE(rdata->type == 17);
207         REQUIRE(target != NULL);
208         REQUIRE(rdata->length != 0);
209
210         rp->common.rdclass = rdata->rdclass;
211         rp->common.rdtype = rdata->type;
212         ISC_LINK_INIT(&rp->common, link);
213
214         dns_name_init(&name, NULL);
215         dns_rdata_toregion(rdata, &region);
216         dns_name_fromregion(&name, &region);
217         dns_name_init(&rp->mail, NULL);
218         RETERR(name_duporclone(&name, mctx, &rp->mail));
219         isc_region_consume(&region, name_length(&name));
220         dns_name_fromregion(&name, &region);
221         dns_name_init(&rp->text, NULL);
222         result = name_duporclone(&name, mctx, &rp->text);
223         if (result != ISC_R_SUCCESS)
224                 goto cleanup;
225
226         rp->mctx = mctx;
227         return (ISC_R_SUCCESS);
228
229  cleanup:
230         if (mctx != NULL)
231                 dns_name_free(&rp->mail, mctx);
232         return (ISC_R_NOMEMORY);
233 }
234
235 static inline void
236 freestruct_rp(ARGS_FREESTRUCT) {
237         dns_rdata_rp_t *rp = source;
238
239         REQUIRE(source != NULL);
240         REQUIRE(rp->common.rdtype == 17);
241
242         if (rp->mctx == NULL)
243                 return;
244
245         dns_name_free(&rp->mail, rp->mctx);
246         dns_name_free(&rp->text, rp->mctx);
247         rp->mctx = NULL;
248 }
249
250 static inline isc_result_t
251 additionaldata_rp(ARGS_ADDLDATA) {
252         REQUIRE(rdata->type == 17);
253
254         UNUSED(rdata);
255         UNUSED(add);
256         UNUSED(arg);
257
258         return (ISC_R_SUCCESS);
259 }
260
261 static inline isc_result_t
262 digest_rp(ARGS_DIGEST) {
263         isc_region_t r;
264         dns_name_t name;
265
266         REQUIRE(rdata->type == 17);
267
268         dns_rdata_toregion(rdata, &r);
269         dns_name_init(&name, NULL);
270
271         dns_name_fromregion(&name, &r);
272         RETERR(dns_name_digest(&name, digest, arg));
273         isc_region_consume(&r, name_length(&name));
274
275         dns_name_init(&name, NULL);
276         dns_name_fromregion(&name, &r);
277
278         return (dns_name_digest(&name, digest, arg));
279 }
280
281 static inline isc_boolean_t
282 checkowner_rp(ARGS_CHECKOWNER) {
283
284         REQUIRE(type == 17);
285
286         UNUSED(name);
287         UNUSED(type);
288         UNUSED(rdclass);
289         UNUSED(wildcard);
290
291         return (ISC_TRUE);
292 }
293
294 static inline isc_boolean_t
295 checknames_rp(ARGS_CHECKNAMES) {
296         isc_region_t region;
297         dns_name_t name;
298
299         REQUIRE(rdata->type == 17);
300
301         UNUSED(owner);
302
303         dns_rdata_toregion(rdata, &region);
304         dns_name_init(&name, NULL);
305         dns_name_fromregion(&name, &region);
306         if (!dns_name_ismailbox(&name)) {
307                 if (bad != NULL)
308                                 dns_name_clone(&name, bad);
309                 return (ISC_FALSE);
310         }
311         return (ISC_TRUE);
312 }
313
314 #endif  /* RDATA_GENERIC_RP_17_C */