1 /* $NetBSD: spf_99.c,v 1.5 2014/12/10 04:37:59 christos Exp $ */
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
) {
44 RETERR(isc_lex_getmastertoken(lexer
, &token
,
45 isc_tokentype_qstring
,
47 if (token
.type
!= isc_tokentype_qstring
&&
48 token
.type
!= isc_tokentype_string
)
50 RETTOK(txt_fromtext(&token
.value
.as_textregion
, target
));
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
) {
64 REQUIRE(rdata
->type
== 99);
66 dns_rdata_toregion(rdata
, ®ion
);
68 while (region
.length
> 0) {
69 RETERR(txt_totext(®ion
, 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
) {
89 result
= txt_fromwire(source
, target
);
90 if (result
!= ISC_R_SUCCESS
)
92 } while (!buffer_empty(source
));
93 return (ISC_R_SUCCESS
);
96 static inline isc_result_t
97 towire_spf(ARGS_TOWIRE
) {
100 REQUIRE(rdata
->type
== 99);
104 isc_buffer_availableregion(target
, ®ion
);
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
);
114 compare_spf(ARGS_COMPARE
) {
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
;
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);
142 region
.base
= txt
->txt
;
143 region
.length
= txt
->txt_len
;
144 while (region
.length
> 0) {
145 length
= uint8_fromregion(®ion
);
146 isc_region_consume(®ion
, 1);
147 if (region
.length
<= length
)
148 return (ISC_R_UNEXPECTEDEND
);
149 isc_region_consume(®ion
, 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
;
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
);
175 return (ISC_R_SUCCESS
);
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
)
188 if (txt
->txt
!= NULL
)
189 isc_mem_free(txt
->mctx
, txt
->txt
);
193 static inline isc_result_t
194 additionaldata_spf(ARGS_ADDLDATA
) {
195 REQUIRE(rdata
->type
== 99);
201 return (ISC_R_SUCCESS
);
204 static inline isc_result_t
205 digest_spf(ARGS_DIGEST
) {
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
) {
228 static inline isc_boolean_t
229 checknames_spf(ARGS_CHECKNAMES
) {
231 REQUIRE(rdata
->type
== 99);
241 casecompare_spf(ARGS_COMPARE
) {
242 return (compare_spf(rdata1
, rdata2
));
244 #endif /* RDATA_GENERIC_SPF_99_C */