2 * Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1998-2002 Internet Software Consortium.
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.
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.
18 /* $Id: spf_99.c,v 1.1.2.2 2005/07/16 00:40:54 marka Exp $ */
20 /* Reviewed: Thu Mar 16 15:40:00 PST 2000 by bwelling */
22 #ifndef RDATA_GENERIC_SPF_99_C
23 #define RDATA_GENERIC_SPF_99_C
25 #define RRTYPE_SPF_ATTRIBUTES (0)
27 static inline isc_result_t
28 fromtext_spf(ARGS_FROMTEXT) {
42 RETERR(isc_lex_getmastertoken(lexer, &token,
43 isc_tokentype_qstring,
45 if (token.type != isc_tokentype_qstring &&
46 token.type != isc_tokentype_string)
48 RETTOK(txt_fromtext(&token.value.as_textregion, target));
51 /* Let upper layer handle eol/eof. */
52 isc_lex_ungettoken(lexer, &token);
53 return (strings == 0 ? ISC_R_UNEXPECTEDEND : ISC_R_SUCCESS);
56 static inline isc_result_t
57 totext_spf(ARGS_TOTEXT) {
62 REQUIRE(rdata->type == 99);
64 dns_rdata_toregion(rdata, ®ion);
66 while (region.length > 0) {
67 RETERR(txt_totext(®ion, target));
68 if (region.length > 0)
69 RETERR(str_totext(" ", target));
72 return (ISC_R_SUCCESS);
75 static inline isc_result_t
76 fromwire_spf(ARGS_FROMWIRE) {
87 result = txt_fromwire(source, target);
88 if (result != ISC_R_SUCCESS)
90 } while (!buffer_empty(source));
91 return (ISC_R_SUCCESS);
94 static inline isc_result_t
95 towire_spf(ARGS_TOWIRE) {
98 REQUIRE(rdata->type == 99);
102 isc_buffer_availableregion(target, ®ion);
103 if (region.length < rdata->length)
104 return (ISC_R_NOSPACE);
106 memcpy(region.base, rdata->data, rdata->length);
107 isc_buffer_add(target, rdata->length);
108 return (ISC_R_SUCCESS);
112 compare_spf(ARGS_COMPARE) {
116 REQUIRE(rdata1->type == rdata2->type);
117 REQUIRE(rdata1->rdclass == rdata2->rdclass);
118 REQUIRE(rdata1->type == 99);
120 dns_rdata_toregion(rdata1, &r1);
121 dns_rdata_toregion(rdata2, &r2);
122 return (isc_region_compare(&r1, &r2));
125 static inline isc_result_t
126 fromstruct_spf(ARGS_FROMSTRUCT) {
127 dns_rdata_spf_t *txt = source;
132 REQUIRE(source != NULL);
133 REQUIRE(txt->common.rdtype == type);
134 REQUIRE(txt->common.rdclass == rdclass);
135 REQUIRE(txt->txt != NULL && txt->txt_len != 0);
140 region.base = txt->txt;
141 region.length = txt->txt_len;
142 while (region.length > 0) {
143 length = uint8_fromregion(®ion);
144 isc_region_consume(®ion, 1);
145 if (region.length <= length)
146 return (ISC_R_UNEXPECTEDEND);
147 isc_region_consume(®ion, length);
150 return (mem_tobuffer(target, txt->txt, txt->txt_len));
153 static inline isc_result_t
154 tostruct_spf(ARGS_TOSTRUCT) {
155 dns_rdata_spf_t *txt = target;
158 REQUIRE(rdata->type == 99);
159 REQUIRE(target != NULL);
161 txt->common.rdclass = rdata->rdclass;
162 txt->common.rdtype = rdata->type;
163 ISC_LINK_INIT(&txt->common, link);
165 dns_rdata_toregion(rdata, &r);
166 txt->txt_len = r.length;
167 txt->txt = mem_maybedup(mctx, r.base, r.length);
168 if (txt->txt == NULL)
169 return (ISC_R_NOMEMORY);
173 return (ISC_R_SUCCESS);
177 freestruct_spf(ARGS_FREESTRUCT) {
178 dns_rdata_spf_t *txt = source;
180 REQUIRE(source != NULL);
181 REQUIRE(txt->common.rdtype == 99);
183 if (txt->mctx == NULL)
186 if (txt->txt != NULL)
187 isc_mem_free(txt->mctx, txt->txt);
191 static inline isc_result_t
192 additionaldata_spf(ARGS_ADDLDATA) {
193 REQUIRE(rdata->type == 99);
199 return (ISC_R_SUCCESS);
202 static inline isc_result_t
203 digest_spf(ARGS_DIGEST) {
206 REQUIRE(rdata->type == 99);
208 dns_rdata_toregion(rdata, &r);
210 return ((digest)(arg, &r));
213 static inline isc_boolean_t
214 checkowner_spf(ARGS_CHECKOWNER) {
226 static inline isc_boolean_t
227 checknames_spf(ARGS_CHECKNAMES) {
229 REQUIRE(rdata->type == 99);
238 #endif /* RDATA_GENERIC_SPF_99_C */