Merge from vendor branch CVS:
[dragonfly.git] / contrib / bind-9.2.4rc7 / 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.2.1 2004/03/09 06:11:31 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
34         REQUIRE(type == 14);
35
36         UNUSED(type);
37         UNUSED(rdclass);
38         UNUSED(callbacks);
39
40         for (i = 0; i < 2 ; i++) {
41                 RETERR(isc_lex_getmastertoken(lexer, &token,
42                                               isc_tokentype_string,
43                                               ISC_FALSE));
44                 dns_name_init(&name, NULL);
45                 buffer_fromregion(&buffer, &token.value.as_region);
46                 origin = (origin != NULL) ? origin : dns_rootname;
47                 RETTOK(dns_name_fromtext(&name, &buffer, origin,
48                                          downcase, target));
49         }
50         return (ISC_R_SUCCESS);
51 }
52
53 static inline isc_result_t
54 totext_minfo(ARGS_TOTEXT) {
55         isc_region_t region;
56         dns_name_t rmail;
57         dns_name_t email;
58         dns_name_t prefix;
59         isc_boolean_t sub;
60
61         REQUIRE(rdata->type == 14);
62         REQUIRE(rdata->length != 0);
63
64         dns_name_init(&rmail, NULL);
65         dns_name_init(&email, NULL);
66         dns_name_init(&prefix, NULL);
67
68         dns_rdata_toregion(rdata, &region);
69
70         dns_name_fromregion(&rmail, &region);
71         isc_region_consume(&region, rmail.length);
72
73         dns_name_fromregion(&email, &region);
74         isc_region_consume(&region, email.length);
75
76         sub = name_prefix(&rmail, tctx->origin, &prefix);
77
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_minfo(ARGS_FROMWIRE) {
88         dns_name_t rmail;
89         dns_name_t email;
90
91         REQUIRE(type == 14);
92
93         UNUSED(type);
94         UNUSED(rdclass);
95
96         dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
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_minfo(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 == 14);
114         REQUIRE(rdata->length != 0);
115
116         dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
117
118         dns_name_init(&rmail, roffsets);
119         dns_name_init(&email, eoffsets);
120
121         dns_rdata_toregion(rdata, &region);
122
123         dns_name_fromregion(&rmail, &region);
124         isc_region_consume(&region, name_length(&rmail));
125
126         RETERR(dns_name_towire(&rmail, cctx, target));
127
128         dns_name_fromregion(&rmail, &region);
129         isc_region_consume(&region, rmail.length);
130
131         return (dns_name_towire(&rmail, cctx, target));
132 }
133
134 static inline int
135 compare_minfo(ARGS_COMPARE) {
136         isc_region_t region1;
137         isc_region_t region2;
138         dns_name_t name1;
139         dns_name_t name2;
140         int order;
141
142         REQUIRE(rdata1->type == rdata2->type);
143         REQUIRE(rdata1->rdclass == rdata2->rdclass);
144         REQUIRE(rdata1->type == 14);
145         REQUIRE(rdata1->length != 0);
146         REQUIRE(rdata2->length != 0);
147
148         dns_name_init(&name1, NULL);
149         dns_name_init(&name2, NULL);
150
151         dns_rdata_toregion(rdata1, &region1);
152         dns_rdata_toregion(rdata2, &region2);
153
154         dns_name_fromregion(&name1, &region1);
155         dns_name_fromregion(&name2, &region2);
156
157         order = dns_name_rdatacompare(&name1, &name2);
158         if (order != 0)
159                 return (order);
160
161         isc_region_consume(&region1, name_length(&name1));
162         isc_region_consume(&region2, name_length(&name2));
163
164         dns_name_init(&name1, NULL);
165         dns_name_init(&name2, NULL);
166
167         dns_name_fromregion(&name1, &region1);
168         dns_name_fromregion(&name2, &region2);
169
170         order = dns_name_rdatacompare(&name1, &name2);
171         return (order);
172 }
173
174 static inline isc_result_t
175 fromstruct_minfo(ARGS_FROMSTRUCT) {
176         dns_rdata_minfo_t *minfo = source;
177         isc_region_t region;
178
179         REQUIRE(type == 14);
180         REQUIRE(source != NULL);
181         REQUIRE(minfo->common.rdtype == type);
182         REQUIRE(minfo->common.rdclass == rdclass);
183
184         UNUSED(type);
185         UNUSED(rdclass);
186
187         dns_name_toregion(&minfo->rmailbox, &region);
188         RETERR(isc_buffer_copyregion(target, &region));
189         dns_name_toregion(&minfo->emailbox, &region);
190         return (isc_buffer_copyregion(target, &region));
191 }
192
193 static inline isc_result_t
194 tostruct_minfo(ARGS_TOSTRUCT) {
195         dns_rdata_minfo_t *minfo = target;
196         isc_region_t region;
197         dns_name_t name;
198         isc_result_t result;
199
200         REQUIRE(rdata->type == 14);
201         REQUIRE(target != NULL);
202         REQUIRE(rdata->length != 0);
203
204         minfo->common.rdclass = rdata->rdclass;
205         minfo->common.rdtype = rdata->type;
206         ISC_LINK_INIT(&minfo->common, link);
207
208         dns_name_init(&name, NULL);
209         dns_rdata_toregion(rdata, &region);
210         dns_name_fromregion(&name, &region);
211         dns_name_init(&minfo->rmailbox, NULL);
212         RETERR(name_duporclone(&name, mctx, &minfo->rmailbox));
213         isc_region_consume(&region, name_length(&name));
214
215         dns_name_fromregion(&name, &region);
216         dns_name_init(&minfo->emailbox, NULL);
217         result = name_duporclone(&name, mctx, &minfo->emailbox);
218         if (result != ISC_R_SUCCESS)
219                 goto cleanup;
220         minfo->mctx = mctx;
221         return (ISC_R_SUCCESS);
222
223  cleanup:
224         if (mctx != NULL)
225                 dns_name_free(&minfo->rmailbox, mctx);
226         return (ISC_R_NOMEMORY);
227 }
228
229 static inline void
230 freestruct_minfo(ARGS_FREESTRUCT) {
231         dns_rdata_minfo_t *minfo = source;
232
233         REQUIRE(source != NULL);
234         REQUIRE(minfo->common.rdtype == 14);
235
236         if (minfo->mctx == NULL)
237                 return;
238
239         dns_name_free(&minfo->rmailbox, minfo->mctx);
240         dns_name_free(&minfo->emailbox, minfo->mctx);
241         minfo->mctx = NULL;
242 }
243
244 static inline isc_result_t
245 additionaldata_minfo(ARGS_ADDLDATA) {
246         REQUIRE(rdata->type == 14);
247
248         UNUSED(rdata);
249         UNUSED(add);
250         UNUSED(arg);
251
252         return (ISC_R_SUCCESS);
253 }
254
255 static inline isc_result_t
256 digest_minfo(ARGS_DIGEST) {
257         isc_region_t r;
258         dns_name_t name;
259         isc_result_t result;
260
261         REQUIRE(rdata->type == 14);
262
263         dns_rdata_toregion(rdata, &r);
264         dns_name_init(&name, NULL);
265         dns_name_fromregion(&name, &r);
266         result = dns_name_digest(&name, digest, arg);
267         if (result != ISC_R_SUCCESS)
268                 return (result);
269         isc_region_consume(&r, name_length(&name));
270         dns_name_init(&name, NULL);
271         dns_name_fromregion(&name, &r);
272
273         return (dns_name_digest(&name, digest, arg));
274 }
275
276 #endif  /* RDATA_GENERIC_MINFO_14_C */