diff options
Diffstat (limited to 'lib/dns/rdata/generic/spf_99.c')
| -rw-r--r-- | lib/dns/rdata/generic/spf_99.c | 95 |
1 files changed, 13 insertions, 82 deletions
diff --git a/lib/dns/rdata/generic/spf_99.c b/lib/dns/rdata/generic/spf_99.c index 8ad4f02b9af4..2fa1174d4237 100644 --- a/lib/dns/rdata/generic/spf_99.c +++ b/lib/dns/rdata/generic/spf_99.c @@ -26,8 +26,6 @@ static inline isc_result_t fromtext_spf(ARGS_FROMTEXT) { - isc_token_t token; - int strings; REQUIRE(type == dns_rdatatype_spf); @@ -37,44 +35,22 @@ fromtext_spf(ARGS_FROMTEXT) { UNUSED(options); UNUSED(callbacks); - strings = 0; - for (;;) { - RETERR(isc_lex_getmastertoken(lexer, &token, - isc_tokentype_qstring, - ISC_TRUE)); - if (token.type != isc_tokentype_qstring && - token.type != isc_tokentype_string) - break; - RETTOK(txt_fromtext(&token.value.as_textregion, target)); - strings++; - } - /* Let upper layer handle eol/eof. */ - isc_lex_ungettoken(lexer, &token); - return (strings == 0 ? ISC_R_UNEXPECTEDEND : ISC_R_SUCCESS); + return (generic_fromtext_txt(rdclass, type, lexer, origin, options, + target, callbacks)); } static inline isc_result_t totext_spf(ARGS_TOTEXT) { - isc_region_t region; UNUSED(tctx); REQUIRE(rdata->type == dns_rdatatype_spf); - dns_rdata_toregion(rdata, ®ion); - - while (region.length > 0) { - RETERR(txt_totext(®ion, ISC_TRUE, target)); - if (region.length > 0) - RETERR(str_totext(" ", target)); - } - - return (ISC_R_SUCCESS); + return (generic_totext_txt(rdata, tctx, target)); } static inline isc_result_t fromwire_spf(ARGS_FROMWIRE) { - isc_result_t result; REQUIRE(type == dns_rdatatype_spf); @@ -83,29 +59,18 @@ fromwire_spf(ARGS_FROMWIRE) { UNUSED(rdclass); UNUSED(options); - do { - result = txt_fromwire(source, target); - if (result != ISC_R_SUCCESS) - return (result); - } while (!buffer_empty(source)); - return (ISC_R_SUCCESS); + return (generic_fromwire_txt(rdclass, type, source, dctx, options, + target)); } static inline isc_result_t towire_spf(ARGS_TOWIRE) { - isc_region_t region; REQUIRE(rdata->type == dns_rdatatype_spf); UNUSED(cctx); - isc_buffer_availableregion(target, ®ion); - if (region.length < rdata->length) - return (ISC_R_NOSPACE); - - memmove(region.base, rdata->data, rdata->length); - isc_buffer_add(target, rdata->length); - return (ISC_R_SUCCESS); + return (mem_tobuffer(target, rdata->data, rdata->length)); } static inline int @@ -124,53 +89,24 @@ compare_spf(ARGS_COMPARE) { static inline isc_result_t fromstruct_spf(ARGS_FROMSTRUCT) { - dns_rdata_spf_t *txt = source; - isc_region_t region; - isc_uint8_t length; REQUIRE(type == dns_rdatatype_spf); - REQUIRE(source != NULL); - REQUIRE(txt->common.rdtype == type); - REQUIRE(txt->common.rdclass == rdclass); - REQUIRE(txt->txt != NULL && txt->txt_len != 0); - UNUSED(type); - UNUSED(rdclass); - - region.base = txt->txt; - region.length = txt->txt_len; - while (region.length > 0) { - length = uint8_fromregion(®ion); - isc_region_consume(®ion, 1); - if (region.length <= length) - return (ISC_R_UNEXPECTEDEND); - isc_region_consume(®ion, length); - } - - return (mem_tobuffer(target, txt->txt, txt->txt_len)); + return (generic_fromstruct_txt(rdclass, type, source, target)); } static inline isc_result_t tostruct_spf(ARGS_TOSTRUCT) { - dns_rdata_spf_t *txt = target; - isc_region_t r; + dns_rdata_spf_t *spf = target; REQUIRE(rdata->type == dns_rdatatype_spf); REQUIRE(target != NULL); - txt->common.rdclass = rdata->rdclass; - txt->common.rdtype = rdata->type; - ISC_LINK_INIT(&txt->common, link); + spf->common.rdclass = rdata->rdclass; + spf->common.rdtype = rdata->type; + ISC_LINK_INIT(&spf->common, link); - dns_rdata_toregion(rdata, &r); - txt->txt_len = r.length; - txt->txt = mem_maybedup(mctx, r.base, r.length); - if (txt->txt == NULL) - return (ISC_R_NOMEMORY); - - txt->offset = 0; - txt->mctx = mctx; - return (ISC_R_SUCCESS); + return (generic_tostruct_txt(rdata, target, mctx)); } static inline void @@ -180,12 +116,7 @@ freestruct_spf(ARGS_FREESTRUCT) { REQUIRE(source != NULL); REQUIRE(txt->common.rdtype == dns_rdatatype_spf); - if (txt->mctx == NULL) - return; - - if (txt->txt != NULL) - isc_mem_free(txt->mctx, txt->txt); - txt->mctx = NULL; + generic_freestruct_txt(source); } static inline isc_result_t |
