Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / generic / spf_99.c
blob1bd31b42d933e73af97e99d1936587fe918ba0d3
1 /* $NetBSD: spf_99.c,v 1.5 2014/12/10 04:37:59 christos Exp $ */
3 /*
4 * Copyright (C) 2004, 2005, 2007, 2009, 2014 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1998-2002 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: spf_99.c,v 1.6 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Thu Mar 16 15:40:00 PST 2000 by bwelling */
24 #ifndef RDATA_GENERIC_SPF_99_C
25 #define RDATA_GENERIC_SPF_99_C
27 #define RRTYPE_SPF_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_spf(ARGS_FROMTEXT) {
31 isc_token_t token;
32 int strings;
34 REQUIRE(type == 99);
36 UNUSED(type);
37 UNUSED(rdclass);
38 UNUSED(origin);
39 UNUSED(options);
40 UNUSED(callbacks);
42 strings = 0;
43 for (;;) {
44 RETERR(isc_lex_getmastertoken(lexer, &token,
45 isc_tokentype_qstring,
46 ISC_TRUE));
47 if (token.type != isc_tokentype_qstring &&
48 token.type != isc_tokentype_string)
49 break;
50 RETTOK(txt_fromtext(&token.value.as_textregion, target));
51 strings++;
53 /* Let upper layer handle eol/eof. */
54 isc_lex_ungettoken(lexer, &token);
55 return (strings == 0 ? ISC_R_UNEXPECTEDEND : ISC_R_SUCCESS);
58 static inline isc_result_t
59 totext_spf(ARGS_TOTEXT) {
60 isc_region_t region;
62 UNUSED(tctx);
64 REQUIRE(rdata->type == 99);
66 dns_rdata_toregion(rdata, &region);
68 while (region.length > 0) {
69 RETERR(txt_totext(&region, ISC_TRUE, target));
70 if (region.length > 0)
71 RETERR(str_totext(" ", target));
74 return (ISC_R_SUCCESS);
77 static inline isc_result_t
78 fromwire_spf(ARGS_FROMWIRE) {
79 isc_result_t result;
81 REQUIRE(type == 99);
83 UNUSED(type);
84 UNUSED(dctx);
85 UNUSED(rdclass);
86 UNUSED(options);
88 do {
89 result = txt_fromwire(source, target);
90 if (result != ISC_R_SUCCESS)
91 return (result);
92 } while (!buffer_empty(source));
93 return (ISC_R_SUCCESS);
96 static inline isc_result_t
97 towire_spf(ARGS_TOWIRE) {
98 isc_region_t region;
100 REQUIRE(rdata->type == 99);
102 UNUSED(cctx);
104 isc_buffer_availableregion(target, &region);
105 if (region.length < rdata->length)
106 return (ISC_R_NOSPACE);
108 memmove(region.base, rdata->data, rdata->length);
109 isc_buffer_add(target, rdata->length);
110 return (ISC_R_SUCCESS);
113 static inline int
114 compare_spf(ARGS_COMPARE) {
115 isc_region_t r1;
116 isc_region_t r2;
118 REQUIRE(rdata1->type == rdata2->type);
119 REQUIRE(rdata1->rdclass == rdata2->rdclass);
120 REQUIRE(rdata1->type == 99);
122 dns_rdata_toregion(rdata1, &r1);
123 dns_rdata_toregion(rdata2, &r2);
124 return (isc_region_compare(&r1, &r2));
127 static inline isc_result_t
128 fromstruct_spf(ARGS_FROMSTRUCT) {
129 dns_rdata_spf_t *txt = source;
130 isc_region_t region;
131 isc_uint8_t length;
133 REQUIRE(type == 99);
134 REQUIRE(source != NULL);
135 REQUIRE(txt->common.rdtype == type);
136 REQUIRE(txt->common.rdclass == rdclass);
137 REQUIRE(txt->txt != NULL && txt->txt_len != 0);
139 UNUSED(type);
140 UNUSED(rdclass);
142 region.base = txt->txt;
143 region.length = txt->txt_len;
144 while (region.length > 0) {
145 length = uint8_fromregion(&region);
146 isc_region_consume(&region, 1);
147 if (region.length <= length)
148 return (ISC_R_UNEXPECTEDEND);
149 isc_region_consume(&region, length);
152 return (mem_tobuffer(target, txt->txt, txt->txt_len));
155 static inline isc_result_t
156 tostruct_spf(ARGS_TOSTRUCT) {
157 dns_rdata_spf_t *txt = target;
158 isc_region_t r;
160 REQUIRE(rdata->type == 99);
161 REQUIRE(target != NULL);
163 txt->common.rdclass = rdata->rdclass;
164 txt->common.rdtype = rdata->type;
165 ISC_LINK_INIT(&txt->common, link);
167 dns_rdata_toregion(rdata, &r);
168 txt->txt_len = r.length;
169 txt->txt = mem_maybedup(mctx, r.base, r.length);
170 if (txt->txt == NULL)
171 return (ISC_R_NOMEMORY);
173 txt->offset = 0;
174 txt->mctx = mctx;
175 return (ISC_R_SUCCESS);
178 static inline void
179 freestruct_spf(ARGS_FREESTRUCT) {
180 dns_rdata_spf_t *txt = source;
182 REQUIRE(source != NULL);
183 REQUIRE(txt->common.rdtype == 99);
185 if (txt->mctx == NULL)
186 return;
188 if (txt->txt != NULL)
189 isc_mem_free(txt->mctx, txt->txt);
190 txt->mctx = NULL;
193 static inline isc_result_t
194 additionaldata_spf(ARGS_ADDLDATA) {
195 REQUIRE(rdata->type == 99);
197 UNUSED(rdata);
198 UNUSED(add);
199 UNUSED(arg);
201 return (ISC_R_SUCCESS);
204 static inline isc_result_t
205 digest_spf(ARGS_DIGEST) {
206 isc_region_t r;
208 REQUIRE(rdata->type == 99);
210 dns_rdata_toregion(rdata, &r);
212 return ((digest)(arg, &r));
215 static inline isc_boolean_t
216 checkowner_spf(ARGS_CHECKOWNER) {
218 REQUIRE(type == 99);
220 UNUSED(name);
221 UNUSED(type);
222 UNUSED(rdclass);
223 UNUSED(wildcard);
225 return (ISC_TRUE);
228 static inline isc_boolean_t
229 checknames_spf(ARGS_CHECKNAMES) {
231 REQUIRE(rdata->type == 99);
233 UNUSED(rdata);
234 UNUSED(owner);
235 UNUSED(bad);
237 return (ISC_TRUE);
240 static inline int
241 casecompare_spf(ARGS_COMPARE) {
242 return (compare_spf(rdata1, rdata2));
244 #endif /* RDATA_GENERIC_SPF_99_C */