Merge from vendor branch LIBARCHIVE:
[dragonfly.git] / contrib / bind-9.3 / lib / dns / rdata / generic / minfo_14.c
1 /*
2  * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1998-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: minfo_14.c,v 1.40.12.4 2004/03/08 09:04:41 marka Exp $ */
19
20 /* reviewed: Wed Mar 15 17:45:32 PST 2000 by brister */
21
22 #ifndef RDATA_GENERIC_MINFO_14_C
23 #define RDATA_GENERIC_MINFO_14_C
24
25 #define RRTYPE_MINFO_ATTRIBUTES (0)
26
27 static inline isc_result_t
28 fromtext_minfo(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 == 14);
36
37         UNUSED(type);
38         UNUSED(rdclass);
39         UNUSED(callbacks);
40
41         for (i = 0; i < 2; i++) {
42                 RETERR(isc_lex_getmastertoken(lexer, &token,
43                                               isc_tokentype_string,
44                                               ISC_FALSE));
45                 dns_name_init(&name, NULL);
46                 buffer_fromregion(&buffer, &token.value.as_region);
47                 origin = (origin != NULL) ? origin : dns_rootname;
48                 RETTOK(dns_name_fromtext(&name, &buffer, origin,
49                                          options, target));
50                 ok = ISC_TRUE;
51                 if ((options & DNS_RDATA_CHECKNAMES) != 0)
52                         ok = dns_name_ismailbox(&name);
53                 if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
54                         RETTOK(DNS_R_BADNAME);
55                 if (!ok && callbacks != NULL)
56                         warn_badname(&name, lexer, callbacks);
57         }
58         return (ISC_R_SUCCESS);
59 }
60
61 static inline isc_result_t
62 totext_minfo(ARGS_TOTEXT) {
63         isc_region_t region;
64         dns_name_t rmail;
65         dns_name_t email;
66         dns_name_t prefix;
67         isc_boolean_t sub;
68
69         REQUIRE(rdata->type == 14);
70         REQUIRE(rdata->length != 0);
71
72         dns_name_init(&rmail, NULL);
73         dns_name_init(&email, NULL);
74         dns_name_init(&prefix, NULL);
75
76         dns_rdata_toregion(rdata, &region);
77
78         dns_name_fromregion(&rmail, &region);
79         isc_region_consume(&region, rmail.length);
80
81         dns_name_fromregion(&email, &region);
82         isc_region_consume(&region, email.length);
83
84         sub = name_prefix(&rmail, tctx->origin, &prefix);
85
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_minfo(ARGS_FROMWIRE) {
96         dns_name_t rmail;
97         dns_name_t email;
98
99         REQUIRE(type == 14);
100
101         UNUSED(type);
102         UNUSED(rdclass);
103
104         dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
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_minfo(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 == 14);
122         REQUIRE(rdata->length != 0);
123
124         dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
125
126         dns_name_init(&rmail, roffsets);
127         dns_name_init(&email, eoffsets);
128
129         dns_rdata_toregion(rdata, &region);
130
131         dns_name_fromregion(&rmail, &region);
132         isc_region_consume(&region, name_length(&rmail));
133
134         RETERR(dns_name_towire(&rmail, cctx, target));
135
136         dns_name_fromregion(&rmail, &region);
137         isc_region_consume(&region, rmail.length);
138
139         return (dns_name_towire(&rmail, cctx, target));
140 }
141
142 static inline int
143 compare_minfo(ARGS_COMPARE) {
144         isc_region_t region1;
145         isc_region_t region2;
146         dns_name_t name1;
147         dns_name_t name2;
148         int order;
149
150         REQUIRE(rdata1->type == rdata2->type);
151         REQUIRE(rdata1->rdclass == rdata2->rdclass);
152         REQUIRE(rdata1->type == 14);
153         REQUIRE(rdata1->length != 0);
154         REQUIRE(rdata2->length != 0);
155
156         dns_name_init(&name1, NULL);
157         dns_name_init(&name2, NULL);
158
159         dns_rdata_toregion(rdata1, &region1);
160         dns_rdata_toregion(rdata2, &region2);
161
162         dns_name_fromregion(&name1, &region1);
163         dns_name_fromregion(&name2, &region2);
164
165         order = dns_name_rdatacompare(&name1, &name2);
166         if (order != 0)
167                 return (order);
168
169         isc_region_consume(&region1, name_length(&name1));
170         isc_region_consume(&region2, name_length(&name2));
171
172         dns_name_init(&name1, NULL);
173         dns_name_init(&name2, NULL);
174
175         dns_name_fromregion(&name1, &region1);
176         dns_name_fromregion(&name2, &region2);
177
178         order = dns_name_rdatacompare(&name1, &name2);
179         return (order);
180 }
181
182 static inline isc_result_t
183 fromstruct_minfo(ARGS_FROMSTRUCT) {
184         dns_rdata_minfo_t *minfo = source;
185         isc_region_t region;
186
187         REQUIRE(type == 14);
188         REQUIRE(source != NULL);
189         REQUIRE(minfo->common.rdtype == type);
190         REQUIRE(minfo->common.rdclass == rdclass);
191
192         UNUSED(type);
193         UNUSED(rdclass);
194
195         dns_name_toregion(&minfo->rmailbox, &region);
196         RETERR(isc_buffer_copyregion(target, &region));
197         dns_name_toregion(&minfo->emailbox, &region);
198         return (isc_buffer_copyregion(target, &region));
199 }
200
201 static inline isc_result_t
202 tostruct_minfo(ARGS_TOSTRUCT) {
203         dns_rdata_minfo_t *minfo = target;
204         isc_region_t region;
205         dns_name_t name;
206         isc_result_t result;
207
208         REQUIRE(rdata->type == 14);
209         REQUIRE(target != NULL);
210         REQUIRE(rdata->length != 0);
211
212         minfo->common.rdclass = rdata->rdclass;
213         minfo->common.rdtype = rdata->type;
214         ISC_LINK_INIT(&minfo->common, link);
215
216         dns_name_init(&name, NULL);
217         dns_rdata_toregion(rdata, &region);
218         dns_name_fromregion(&name, &region);
219         dns_name_init(&minfo->rmailbox, NULL);
220         RETERR(name_duporclone(&name, mctx, &minfo->rmailbox));
221         isc_region_consume(&region, name_length(&name));
222
223         dns_name_fromregion(&name, &region);
224         dns_name_init(&minfo->emailbox, NULL);
225         result = name_duporclone(&name, mctx, &minfo->emailbox);
226         if (result != ISC_R_SUCCESS)
227                 goto cleanup;
228         minfo->mctx = mctx;
229         return (ISC_R_SUCCESS);
230
231  cleanup:
232         if (mctx != NULL)
233                 dns_name_free(&minfo->rmailbox, mctx);
234         return (ISC_R_NOMEMORY);
235 }
236
237 static inline void
238 freestruct_minfo(ARGS_FREESTRUCT) {
239         dns_rdata_minfo_t *minfo = source;
240
241         REQUIRE(source != NULL);
242         REQUIRE(minfo->common.rdtype == 14);
243
244         if (minfo->mctx == NULL)
245                 return;
246
247         dns_name_free(&minfo->rmailbox, minfo->mctx);
248         dns_name_free(&minfo->emailbox, minfo->mctx);
249         minfo->mctx = NULL;
250 }
251
252 static inline isc_result_t
253 additionaldata_minfo(ARGS_ADDLDATA) {
254         REQUIRE(rdata->type == 14);
255
256         UNUSED(rdata);
257         UNUSED(add);
258         UNUSED(arg);
259
260         return (ISC_R_SUCCESS);
261 }
262
263 static inline isc_result_t
264 digest_minfo(ARGS_DIGEST) {
265         isc_region_t r;
266         dns_name_t name;
267         isc_result_t result;
268
269         REQUIRE(rdata->type == 14);
270
271         dns_rdata_toregion(rdata, &r);
272         dns_name_init(&name, NULL);
273         dns_name_fromregion(&name, &r);
274         result = dns_name_digest(&name, digest, arg);
275         if (result != ISC_R_SUCCESS)
276                 return (result);
277         isc_region_consume(&r, name_length(&name));
278         dns_name_init(&name, NULL);
279         dns_name_fromregion(&name, &r);
280
281         return (dns_name_digest(&name, digest, arg));
282 }
283
284 static inline isc_boolean_t
285 checkowner_minfo(ARGS_CHECKOWNER) {
286
287         REQUIRE(type == 14);
288
289         UNUSED(name);
290         UNUSED(type);
291         UNUSED(rdclass);
292         UNUSED(wildcard);
293
294         return (ISC_TRUE);
295 }
296
297 static inline isc_boolean_t
298 checknames_minfo(ARGS_CHECKNAMES) {
299         isc_region_t region;
300         dns_name_t name;
301
302         REQUIRE(rdata->type == 14);
303
304         UNUSED(owner);
305
306         dns_rdata_toregion(rdata, &region);
307         dns_name_init(&name, NULL);
308         dns_name_fromregion(&name, &region);
309         if (!dns_name_ismailbox(&name)) {
310                 if (bad != NULL)
311                         dns_name_clone(&name, bad);
312                 return (ISC_FALSE);
313         }
314         isc_region_consume(&region, name_length(&name));
315         dns_name_fromregion(&name, &region);
316         if (!dns_name_ismailbox(&name)) {
317                 if (bad != NULL)
318                         dns_name_clone(&name, bad);
319                 return (ISC_FALSE);
320         }
321         return (ISC_TRUE);
322 }
323
324 #endif  /* RDATA_GENERIC_MINFO_14_C */