spf_99.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2005, 2007, 2009, 2014  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1998-2002  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id: spf_99.c,v 1.6 2009/12/04 22:06:37 tbox Exp $ */
00019 
00020 /* Reviewed: Thu Mar 16 15:40:00 PST 2000 by bwelling */
00021 
00022 #ifndef RDATA_GENERIC_SPF_99_C
00023 #define RDATA_GENERIC_SPF_99_C
00024 
00025 #define RRTYPE_SPF_ATTRIBUTES (0)
00026 
00027 static inline isc_result_t
00028 fromtext_spf(ARGS_FROMTEXT) {
00029         isc_token_t token;
00030         int strings;
00031 
00032         REQUIRE(type == 99);
00033 
00034         UNUSED(type);
00035         UNUSED(rdclass);
00036         UNUSED(origin);
00037         UNUSED(options);
00038         UNUSED(callbacks);
00039 
00040         strings = 0;
00041         for (;;) {
00042                 RETERR(isc_lex_getmastertoken(lexer, &token,
00043                                               isc_tokentype_qstring,
00044                                               ISC_TRUE));
00045                 if (token.type != isc_tokentype_qstring &&
00046                     token.type != isc_tokentype_string)
00047                         break;
00048                 RETTOK(txt_fromtext(&token.value.as_textregion, target));
00049                 strings++;
00050         }
00051         /* Let upper layer handle eol/eof. */
00052         isc_lex_ungettoken(lexer, &token);
00053         return (strings == 0 ? ISC_R_UNEXPECTEDEND : ISC_R_SUCCESS);
00054 }
00055 
00056 static inline isc_result_t
00057 totext_spf(ARGS_TOTEXT) {
00058         isc_region_t region;
00059 
00060         UNUSED(tctx);
00061 
00062         REQUIRE(rdata->type == 99);
00063 
00064         dns_rdata_toregion(rdata, &region);
00065 
00066         while (region.length > 0) {
00067                 RETERR(txt_totext(&region, ISC_TRUE, target));
00068                 if (region.length > 0)
00069                         RETERR(str_totext(" ", target));
00070         }
00071 
00072         return (ISC_R_SUCCESS);
00073 }
00074 
00075 static inline isc_result_t
00076 fromwire_spf(ARGS_FROMWIRE) {
00077         isc_result_t result;
00078 
00079         REQUIRE(type == 99);
00080 
00081         UNUSED(type);
00082         UNUSED(dctx);
00083         UNUSED(rdclass);
00084         UNUSED(options);
00085 
00086         do {
00087                 result = txt_fromwire(source, target);
00088                 if (result != ISC_R_SUCCESS)
00089                         return (result);
00090         } while (!buffer_empty(source));
00091         return (ISC_R_SUCCESS);
00092 }
00093 
00094 static inline isc_result_t
00095 towire_spf(ARGS_TOWIRE) {
00096         isc_region_t region;
00097 
00098         REQUIRE(rdata->type == 99);
00099 
00100         UNUSED(cctx);
00101 
00102         isc_buffer_availableregion(target, &region);
00103         if (region.length < rdata->length)
00104                 return (ISC_R_NOSPACE);
00105 
00106         memmove(region.base, rdata->data, rdata->length);
00107         isc_buffer_add(target, rdata->length);
00108         return (ISC_R_SUCCESS);
00109 }
00110 
00111 static inline int
00112 compare_spf(ARGS_COMPARE) {
00113         isc_region_t r1;
00114         isc_region_t r2;
00115 
00116         REQUIRE(rdata1->type == rdata2->type);
00117         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00118         REQUIRE(rdata1->type == 99);
00119 
00120         dns_rdata_toregion(rdata1, &r1);
00121         dns_rdata_toregion(rdata2, &r2);
00122         return (isc_region_compare(&r1, &r2));
00123 }
00124 
00125 static inline isc_result_t
00126 fromstruct_spf(ARGS_FROMSTRUCT) {
00127         dns_rdata_spf_t *txt = source;
00128         isc_region_t region;
00129         isc_uint8_t length;
00130 
00131         REQUIRE(type == 99);
00132         REQUIRE(source != NULL);
00133         REQUIRE(txt->common.rdtype == type);
00134         REQUIRE(txt->common.rdclass == rdclass);
00135         REQUIRE(txt->txt != NULL && txt->txt_len != 0);
00136 
00137         UNUSED(type);
00138         UNUSED(rdclass);
00139 
00140         region.base = txt->txt;
00141         region.length = txt->txt_len;
00142         while (region.length > 0) {
00143                 length = uint8_fromregion(&region);
00144                 isc_region_consume(&region, 1);
00145                 if (region.length <= length)
00146                         return (ISC_R_UNEXPECTEDEND);
00147                 isc_region_consume(&region, length);
00148         }
00149 
00150         return (mem_tobuffer(target, txt->txt, txt->txt_len));
00151 }
00152 
00153 static inline isc_result_t
00154 tostruct_spf(ARGS_TOSTRUCT) {
00155         dns_rdata_spf_t *txt = target;
00156         isc_region_t r;
00157 
00158         REQUIRE(rdata->type == 99);
00159         REQUIRE(target != NULL);
00160 
00161         txt->common.rdclass = rdata->rdclass;
00162         txt->common.rdtype = rdata->type;
00163         ISC_LINK_INIT(&txt->common, link);
00164 
00165         dns_rdata_toregion(rdata, &r);
00166         txt->txt_len = r.length;
00167         txt->txt = mem_maybedup(mctx, r.base, r.length);
00168         if (txt->txt == NULL)
00169                 return (ISC_R_NOMEMORY);
00170 
00171         txt->offset = 0;
00172         txt->mctx = mctx;
00173         return (ISC_R_SUCCESS);
00174 }
00175 
00176 static inline void
00177 freestruct_spf(ARGS_FREESTRUCT) {
00178         dns_rdata_spf_t *txt = source;
00179 
00180         REQUIRE(source != NULL);
00181         REQUIRE(txt->common.rdtype == 99);
00182 
00183         if (txt->mctx == NULL)
00184                 return;
00185 
00186         if (txt->txt != NULL)
00187                 isc_mem_free(txt->mctx, txt->txt);
00188         txt->mctx = NULL;
00189 }
00190 
00191 static inline isc_result_t
00192 additionaldata_spf(ARGS_ADDLDATA) {
00193         REQUIRE(rdata->type == 99);
00194 
00195         UNUSED(rdata);
00196         UNUSED(add);
00197         UNUSED(arg);
00198 
00199         return (ISC_R_SUCCESS);
00200 }
00201 
00202 static inline isc_result_t
00203 digest_spf(ARGS_DIGEST) {
00204         isc_region_t r;
00205 
00206         REQUIRE(rdata->type == 99);
00207 
00208         dns_rdata_toregion(rdata, &r);
00209 
00210         return ((digest)(arg, &r));
00211 }
00212 
00213 static inline isc_boolean_t
00214 checkowner_spf(ARGS_CHECKOWNER) {
00215 
00216         REQUIRE(type == 99);
00217 
00218         UNUSED(name);
00219         UNUSED(type);
00220         UNUSED(rdclass);
00221         UNUSED(wildcard);
00222 
00223         return (ISC_TRUE);
00224 }
00225 
00226 static inline isc_boolean_t
00227 checknames_spf(ARGS_CHECKNAMES) {
00228 
00229         REQUIRE(rdata->type == 99);
00230 
00231         UNUSED(rdata);
00232         UNUSED(owner);
00233         UNUSED(bad);
00234 
00235         return (ISC_TRUE);
00236 }
00237 
00238 static inline int
00239 casecompare_spf(ARGS_COMPARE) {
00240         return (compare_spf(rdata1, rdata2));
00241 }
00242 #endif  /* RDATA_GENERIC_SPF_99_C */

Generated on Tue Apr 28 17:41:00 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha