Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / generic / rp_17.c
blob6590424e7116fac5dbd698468c6893f7a2723b71
1 /* $NetBSD: rp_17.c,v 1.4 2014/12/10 04:37:59 christos Exp $ */
3 /*
4 * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-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: rp_17.c,v 1.44 2009/12/04 22:06:37 tbox Exp */
22 /* RFC1183 */
24 #ifndef RDATA_GENERIC_RP_17_C
25 #define RDATA_GENERIC_RP_17_C
27 #define RRTYPE_RP_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_rp(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 == 17);
39 UNUSED(type);
40 UNUSED(rdclass);
41 UNUSED(callbacks);
43 origin = (origin != NULL) ? origin : dns_rootname;
45 for (i = 0; i < 2; i++) {
46 RETERR(isc_lex_getmastertoken(lexer, &token,
47 isc_tokentype_string,
48 ISC_FALSE));
49 dns_name_init(&name, NULL);
50 buffer_fromregion(&buffer, &token.value.as_region);
51 RETTOK(dns_name_fromtext(&name, &buffer, origin,
52 options, target));
53 ok = ISC_TRUE;
54 if ((options & DNS_RDATA_CHECKNAMES) != 0 && i == 0)
55 ok = dns_name_ismailbox(&name);
56 if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
57 RETTOK(DNS_R_BADNAME);
58 if (!ok && callbacks != NULL)
59 warn_badname(&name, lexer, callbacks);
61 return (ISC_R_SUCCESS);
64 static inline isc_result_t
65 totext_rp(ARGS_TOTEXT) {
66 isc_region_t region;
67 dns_name_t rmail;
68 dns_name_t email;
69 dns_name_t prefix;
70 isc_boolean_t sub;
72 REQUIRE(rdata->type == 17);
73 REQUIRE(rdata->length != 0);
75 dns_name_init(&rmail, NULL);
76 dns_name_init(&email, NULL);
77 dns_name_init(&prefix, NULL);
79 dns_rdata_toregion(rdata, &region);
81 dns_name_fromregion(&rmail, &region);
82 isc_region_consume(&region, rmail.length);
84 dns_name_fromregion(&email, &region);
85 isc_region_consume(&region, email.length);
87 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_rp(ARGS_FROMWIRE) {
98 dns_name_t rmail;
99 dns_name_t email;
101 REQUIRE(type == 17);
103 UNUSED(type);
104 UNUSED(rdclass);
106 dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
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_rp(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 == 17);
124 REQUIRE(rdata->length != 0);
126 dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
127 dns_name_init(&rmail, roffsets);
128 dns_name_init(&email, eoffsets);
130 dns_rdata_toregion(rdata, &region);
132 dns_name_fromregion(&rmail, &region);
133 isc_region_consume(&region, rmail.length);
135 RETERR(dns_name_towire(&rmail, cctx, target));
137 dns_name_fromregion(&rmail, &region);
138 isc_region_consume(&region, rmail.length);
140 return (dns_name_towire(&rmail, cctx, target));
143 static inline int
144 compare_rp(ARGS_COMPARE) {
145 isc_region_t region1;
146 isc_region_t region2;
147 dns_name_t name1;
148 dns_name_t name2;
149 int order;
151 REQUIRE(rdata1->type == rdata2->type);
152 REQUIRE(rdata1->rdclass == rdata2->rdclass);
153 REQUIRE(rdata1->type == 17);
154 REQUIRE(rdata1->length != 0);
155 REQUIRE(rdata2->length != 0);
157 dns_name_init(&name1, NULL);
158 dns_name_init(&name2, NULL);
160 dns_rdata_toregion(rdata1, &region1);
161 dns_rdata_toregion(rdata2, &region2);
163 dns_name_fromregion(&name1, &region1);
164 dns_name_fromregion(&name2, &region2);
166 order = dns_name_rdatacompare(&name1, &name2);
167 if (order != 0)
168 return (order);
170 isc_region_consume(&region1, name_length(&name1));
171 isc_region_consume(&region2, name_length(&name2));
173 dns_name_init(&name1, NULL);
174 dns_name_init(&name2, NULL);
176 dns_name_fromregion(&name1, &region1);
177 dns_name_fromregion(&name2, &region2);
179 return (dns_name_rdatacompare(&name1, &name2));
182 static inline isc_result_t
183 fromstruct_rp(ARGS_FROMSTRUCT) {
184 dns_rdata_rp_t *rp = source;
185 isc_region_t region;
187 REQUIRE(type == 17);
188 REQUIRE(source != NULL);
189 REQUIRE(rp->common.rdtype == type);
190 REQUIRE(rp->common.rdclass == rdclass);
192 UNUSED(type);
193 UNUSED(rdclass);
195 dns_name_toregion(&rp->mail, &region);
196 RETERR(isc_buffer_copyregion(target, &region));
197 dns_name_toregion(&rp->text, &region);
198 return (isc_buffer_copyregion(target, &region));
201 static inline isc_result_t
202 tostruct_rp(ARGS_TOSTRUCT) {
203 isc_result_t result;
204 isc_region_t region;
205 dns_rdata_rp_t *rp = target;
206 dns_name_t name;
208 REQUIRE(rdata->type == 17);
209 REQUIRE(target != NULL);
210 REQUIRE(rdata->length != 0);
212 rp->common.rdclass = rdata->rdclass;
213 rp->common.rdtype = rdata->type;
214 ISC_LINK_INIT(&rp->common, link);
216 dns_name_init(&name, NULL);
217 dns_rdata_toregion(rdata, &region);
218 dns_name_fromregion(&name, &region);
219 dns_name_init(&rp->mail, NULL);
220 RETERR(name_duporclone(&name, mctx, &rp->mail));
221 isc_region_consume(&region, name_length(&name));
222 dns_name_fromregion(&name, &region);
223 dns_name_init(&rp->text, NULL);
224 result = name_duporclone(&name, mctx, &rp->text);
225 if (result != ISC_R_SUCCESS)
226 goto cleanup;
228 rp->mctx = mctx;
229 return (ISC_R_SUCCESS);
231 cleanup:
232 if (mctx != NULL)
233 dns_name_free(&rp->mail, mctx);
234 return (ISC_R_NOMEMORY);
237 static inline void
238 freestruct_rp(ARGS_FREESTRUCT) {
239 dns_rdata_rp_t *rp = source;
241 REQUIRE(source != NULL);
242 REQUIRE(rp->common.rdtype == 17);
244 if (rp->mctx == NULL)
245 return;
247 dns_name_free(&rp->mail, rp->mctx);
248 dns_name_free(&rp->text, rp->mctx);
249 rp->mctx = NULL;
252 static inline isc_result_t
253 additionaldata_rp(ARGS_ADDLDATA) {
254 REQUIRE(rdata->type == 17);
256 UNUSED(rdata);
257 UNUSED(add);
258 UNUSED(arg);
260 return (ISC_R_SUCCESS);
263 static inline isc_result_t
264 digest_rp(ARGS_DIGEST) {
265 isc_region_t r;
266 dns_name_t name;
268 REQUIRE(rdata->type == 17);
270 dns_rdata_toregion(rdata, &r);
271 dns_name_init(&name, NULL);
273 dns_name_fromregion(&name, &r);
274 RETERR(dns_name_digest(&name, digest, arg));
275 isc_region_consume(&r, name_length(&name));
277 dns_name_init(&name, NULL);
278 dns_name_fromregion(&name, &r);
280 return (dns_name_digest(&name, digest, arg));
283 static inline isc_boolean_t
284 checkowner_rp(ARGS_CHECKOWNER) {
286 REQUIRE(type == 17);
288 UNUSED(name);
289 UNUSED(type);
290 UNUSED(rdclass);
291 UNUSED(wildcard);
293 return (ISC_TRUE);
296 static inline isc_boolean_t
297 checknames_rp(ARGS_CHECKNAMES) {
298 isc_region_t region;
299 dns_name_t name;
301 REQUIRE(rdata->type == 17);
303 UNUSED(owner);
305 dns_rdata_toregion(rdata, &region);
306 dns_name_init(&name, NULL);
307 dns_name_fromregion(&name, &region);
308 if (!dns_name_ismailbox(&name)) {
309 if (bad != NULL)
310 dns_name_clone(&name, bad);
311 return (ISC_FALSE);
313 return (ISC_TRUE);
316 static inline int
317 casecompare_rp(ARGS_COMPARE) {
318 return (compare_rp(rdata1, rdata2));
320 #endif /* RDATA_GENERIC_RP_17_C */