Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / generic / minfo_14.c
blobfefd87e81df5d4870bd9c0d027c593b8cde27261
1 /* $NetBSD: minfo_14.c,v 1.4 2014/12/10 04:37:59 christos Exp $ */
3 /*
4 * Copyright (C) 2004, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1998-2001 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: minfo_14.c,v 1.47 2009/12/04 22:06:37 tbox Exp */
22 /* reviewed: Wed Mar 15 17:45:32 PST 2000 by brister */
24 #ifndef RDATA_GENERIC_MINFO_14_C
25 #define RDATA_GENERIC_MINFO_14_C
27 #define RRTYPE_MINFO_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_minfo(ARGS_FROMTEXT) {
31 isc_token_t token;
32 dns_name_t name;
33 isc_buffer_t buffer;
34 int i;
35 isc_boolean_t ok;
37 REQUIRE(type == 14);
39 UNUSED(type);
40 UNUSED(rdclass);
41 UNUSED(callbacks);
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 origin = (origin != NULL) ? origin : dns_rootname;
50 RETTOK(dns_name_fromtext(&name, &buffer, origin,
51 options, target));
52 ok = ISC_TRUE;
53 if ((options & DNS_RDATA_CHECKNAMES) != 0)
54 ok = dns_name_ismailbox(&name);
55 if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
56 RETTOK(DNS_R_BADNAME);
57 if (!ok && callbacks != NULL)
58 warn_badname(&name, lexer, callbacks);
60 return (ISC_R_SUCCESS);
63 static inline isc_result_t
64 totext_minfo(ARGS_TOTEXT) {
65 isc_region_t region;
66 dns_name_t rmail;
67 dns_name_t email;
68 dns_name_t prefix;
69 isc_boolean_t sub;
71 REQUIRE(rdata->type == 14);
72 REQUIRE(rdata->length != 0);
74 dns_name_init(&rmail, NULL);
75 dns_name_init(&email, NULL);
76 dns_name_init(&prefix, NULL);
78 dns_rdata_toregion(rdata, &region);
80 dns_name_fromregion(&rmail, &region);
81 isc_region_consume(&region, rmail.length);
83 dns_name_fromregion(&email, &region);
84 isc_region_consume(&region, email.length);
86 sub = name_prefix(&rmail, tctx->origin, &prefix);
88 RETERR(dns_name_totext(&prefix, sub, target));
90 RETERR(str_totext(" ", target));
92 sub = name_prefix(&email, tctx->origin, &prefix);
93 return (dns_name_totext(&prefix, sub, target));
96 static inline isc_result_t
97 fromwire_minfo(ARGS_FROMWIRE) {
98 dns_name_t rmail;
99 dns_name_t email;
101 REQUIRE(type == 14);
103 UNUSED(type);
104 UNUSED(rdclass);
106 dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
108 dns_name_init(&rmail, NULL);
109 dns_name_init(&email, NULL);
111 RETERR(dns_name_fromwire(&rmail, source, dctx, options, target));
112 return (dns_name_fromwire(&email, source, dctx, options, target));
115 static inline isc_result_t
116 towire_minfo(ARGS_TOWIRE) {
117 isc_region_t region;
118 dns_name_t rmail;
119 dns_name_t email;
120 dns_offsets_t roffsets;
121 dns_offsets_t eoffsets;
123 REQUIRE(rdata->type == 14);
124 REQUIRE(rdata->length != 0);
126 dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
128 dns_name_init(&rmail, roffsets);
129 dns_name_init(&email, eoffsets);
131 dns_rdata_toregion(rdata, &region);
133 dns_name_fromregion(&rmail, &region);
134 isc_region_consume(&region, name_length(&rmail));
136 RETERR(dns_name_towire(&rmail, cctx, target));
138 dns_name_fromregion(&rmail, &region);
139 isc_region_consume(&region, rmail.length);
141 return (dns_name_towire(&rmail, cctx, target));
144 static inline int
145 compare_minfo(ARGS_COMPARE) {
146 isc_region_t region1;
147 isc_region_t region2;
148 dns_name_t name1;
149 dns_name_t name2;
150 int order;
152 REQUIRE(rdata1->type == rdata2->type);
153 REQUIRE(rdata1->rdclass == rdata2->rdclass);
154 REQUIRE(rdata1->type == 14);
155 REQUIRE(rdata1->length != 0);
156 REQUIRE(rdata2->length != 0);
158 dns_name_init(&name1, NULL);
159 dns_name_init(&name2, NULL);
161 dns_rdata_toregion(rdata1, &region1);
162 dns_rdata_toregion(rdata2, &region2);
164 dns_name_fromregion(&name1, &region1);
165 dns_name_fromregion(&name2, &region2);
167 order = dns_name_rdatacompare(&name1, &name2);
168 if (order != 0)
169 return (order);
171 isc_region_consume(&region1, name_length(&name1));
172 isc_region_consume(&region2, name_length(&name2));
174 dns_name_init(&name1, NULL);
175 dns_name_init(&name2, NULL);
177 dns_name_fromregion(&name1, &region1);
178 dns_name_fromregion(&name2, &region2);
180 order = dns_name_rdatacompare(&name1, &name2);
181 return (order);
184 static inline isc_result_t
185 fromstruct_minfo(ARGS_FROMSTRUCT) {
186 dns_rdata_minfo_t *minfo = source;
187 isc_region_t region;
189 REQUIRE(type == 14);
190 REQUIRE(source != NULL);
191 REQUIRE(minfo->common.rdtype == type);
192 REQUIRE(minfo->common.rdclass == rdclass);
194 UNUSED(type);
195 UNUSED(rdclass);
197 dns_name_toregion(&minfo->rmailbox, &region);
198 RETERR(isc_buffer_copyregion(target, &region));
199 dns_name_toregion(&minfo->emailbox, &region);
200 return (isc_buffer_copyregion(target, &region));
203 static inline isc_result_t
204 tostruct_minfo(ARGS_TOSTRUCT) {
205 dns_rdata_minfo_t *minfo = target;
206 isc_region_t region;
207 dns_name_t name;
208 isc_result_t result;
210 REQUIRE(rdata->type == 14);
211 REQUIRE(target != NULL);
212 REQUIRE(rdata->length != 0);
214 minfo->common.rdclass = rdata->rdclass;
215 minfo->common.rdtype = rdata->type;
216 ISC_LINK_INIT(&minfo->common, link);
218 dns_name_init(&name, NULL);
219 dns_rdata_toregion(rdata, &region);
220 dns_name_fromregion(&name, &region);
221 dns_name_init(&minfo->rmailbox, NULL);
222 RETERR(name_duporclone(&name, mctx, &minfo->rmailbox));
223 isc_region_consume(&region, name_length(&name));
225 dns_name_fromregion(&name, &region);
226 dns_name_init(&minfo->emailbox, NULL);
227 result = name_duporclone(&name, mctx, &minfo->emailbox);
228 if (result != ISC_R_SUCCESS)
229 goto cleanup;
230 minfo->mctx = mctx;
231 return (ISC_R_SUCCESS);
233 cleanup:
234 if (mctx != NULL)
235 dns_name_free(&minfo->rmailbox, mctx);
236 return (ISC_R_NOMEMORY);
239 static inline void
240 freestruct_minfo(ARGS_FREESTRUCT) {
241 dns_rdata_minfo_t *minfo = source;
243 REQUIRE(source != NULL);
244 REQUIRE(minfo->common.rdtype == 14);
246 if (minfo->mctx == NULL)
247 return;
249 dns_name_free(&minfo->rmailbox, minfo->mctx);
250 dns_name_free(&minfo->emailbox, minfo->mctx);
251 minfo->mctx = NULL;
254 static inline isc_result_t
255 additionaldata_minfo(ARGS_ADDLDATA) {
256 REQUIRE(rdata->type == 14);
258 UNUSED(rdata);
259 UNUSED(add);
260 UNUSED(arg);
262 return (ISC_R_SUCCESS);
265 static inline isc_result_t
266 digest_minfo(ARGS_DIGEST) {
267 isc_region_t r;
268 dns_name_t name;
269 isc_result_t result;
271 REQUIRE(rdata->type == 14);
273 dns_rdata_toregion(rdata, &r);
274 dns_name_init(&name, NULL);
275 dns_name_fromregion(&name, &r);
276 result = dns_name_digest(&name, digest, arg);
277 if (result != ISC_R_SUCCESS)
278 return (result);
279 isc_region_consume(&r, name_length(&name));
280 dns_name_init(&name, NULL);
281 dns_name_fromregion(&name, &r);
283 return (dns_name_digest(&name, digest, arg));
286 static inline isc_boolean_t
287 checkowner_minfo(ARGS_CHECKOWNER) {
289 REQUIRE(type == 14);
291 UNUSED(name);
292 UNUSED(type);
293 UNUSED(rdclass);
294 UNUSED(wildcard);
296 return (ISC_TRUE);
299 static inline isc_boolean_t
300 checknames_minfo(ARGS_CHECKNAMES) {
301 isc_region_t region;
302 dns_name_t name;
304 REQUIRE(rdata->type == 14);
306 UNUSED(owner);
308 dns_rdata_toregion(rdata, &region);
309 dns_name_init(&name, NULL);
310 dns_name_fromregion(&name, &region);
311 if (!dns_name_ismailbox(&name)) {
312 if (bad != NULL)
313 dns_name_clone(&name, bad);
314 return (ISC_FALSE);
316 isc_region_consume(&region, name_length(&name));
317 dns_name_fromregion(&name, &region);
318 if (!dns_name_ismailbox(&name)) {
319 if (bad != NULL)
320 dns_name_clone(&name, bad);
321 return (ISC_FALSE);
323 return (ISC_TRUE);
326 static inline int
327 casecompare_minfo(ARGS_COMPARE) {
328 return (compare_minfo(rdata1, rdata2));
331 #endif /* RDATA_GENERIC_MINFO_14_C */