"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.16.7/lib/dns/rdata/generic/txt_16.c" (4 Sep 2020, 7687 Bytes) of package /linux/misc/dns/bind9/9.16.7/bind-9.16.7.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "txt_16.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 #ifndef RDATA_GENERIC_TXT_16_C
   13 #define RDATA_GENERIC_TXT_16_C
   14 
   15 #define RRTYPE_TXT_ATTRIBUTES (0)
   16 
   17 static inline isc_result_t
   18 generic_fromtext_txt(ARGS_FROMTEXT) {
   19     isc_token_t token;
   20     int strings;
   21 
   22     UNUSED(type);
   23     UNUSED(rdclass);
   24     UNUSED(origin);
   25     UNUSED(options);
   26     UNUSED(callbacks);
   27 
   28     strings = 0;
   29     if ((options & DNS_RDATA_UNKNOWNESCAPE) != 0) {
   30         isc_textregion_t r;
   31         DE_CONST("#", r.base);
   32         r.length = 1;
   33         RETERR(txt_fromtext(&r, target));
   34         strings++;
   35     }
   36     for (;;) {
   37         RETERR(isc_lex_getmastertoken(lexer, &token,
   38                           isc_tokentype_qstring, true));
   39         if (token.type != isc_tokentype_qstring &&
   40             token.type != isc_tokentype_string) {
   41             break;
   42         }
   43         RETTOK(txt_fromtext(&token.value.as_textregion, target));
   44         strings++;
   45     }
   46     /* Let upper layer handle eol/eof. */
   47     isc_lex_ungettoken(lexer, &token);
   48     return (strings == 0 ? ISC_R_UNEXPECTEDEND : ISC_R_SUCCESS);
   49 }
   50 
   51 static inline isc_result_t
   52 generic_totext_txt(ARGS_TOTEXT) {
   53     isc_region_t region;
   54 
   55     UNUSED(tctx);
   56 
   57     dns_rdata_toregion(rdata, &region);
   58 
   59     while (region.length > 0) {
   60         RETERR(txt_totext(&region, true, target));
   61         if (region.length > 0) {
   62             RETERR(str_totext(" ", target));
   63         }
   64     }
   65 
   66     return (ISC_R_SUCCESS);
   67 }
   68 
   69 static inline isc_result_t
   70 generic_fromwire_txt(ARGS_FROMWIRE) {
   71     isc_result_t result;
   72 
   73     UNUSED(type);
   74     UNUSED(dctx);
   75     UNUSED(rdclass);
   76     UNUSED(options);
   77 
   78     do {
   79         result = txt_fromwire(source, target);
   80         if (result != ISC_R_SUCCESS) {
   81             return (result);
   82         }
   83     } while (!buffer_empty(source));
   84     return (ISC_R_SUCCESS);
   85 }
   86 
   87 static inline isc_result_t
   88 fromtext_txt(ARGS_FROMTEXT) {
   89     REQUIRE(type == dns_rdatatype_txt);
   90 
   91     return (generic_fromtext_txt(rdclass, type, lexer, origin, options,
   92                      target, callbacks));
   93 }
   94 
   95 static inline isc_result_t
   96 totext_txt(ARGS_TOTEXT) {
   97     REQUIRE(rdata->type == dns_rdatatype_txt);
   98 
   99     return (generic_totext_txt(rdata, tctx, target));
  100 }
  101 
  102 static inline isc_result_t
  103 fromwire_txt(ARGS_FROMWIRE) {
  104     REQUIRE(type == dns_rdatatype_txt);
  105 
  106     return (generic_fromwire_txt(rdclass, type, source, dctx, options,
  107                      target));
  108 }
  109 
  110 static inline isc_result_t
  111 towire_txt(ARGS_TOWIRE) {
  112     REQUIRE(rdata->type == dns_rdatatype_txt);
  113 
  114     UNUSED(cctx);
  115 
  116     return (mem_tobuffer(target, rdata->data, rdata->length));
  117 }
  118 
  119 static inline int
  120 compare_txt(ARGS_COMPARE) {
  121     isc_region_t r1;
  122     isc_region_t r2;
  123 
  124     REQUIRE(rdata1->type == rdata2->type);
  125     REQUIRE(rdata1->rdclass == rdata2->rdclass);
  126     REQUIRE(rdata1->type == dns_rdatatype_txt);
  127 
  128     dns_rdata_toregion(rdata1, &r1);
  129     dns_rdata_toregion(rdata2, &r2);
  130     return (isc_region_compare(&r1, &r2));
  131 }
  132 
  133 static inline isc_result_t
  134 generic_fromstruct_txt(ARGS_FROMSTRUCT) {
  135     dns_rdata_txt_t *txt = source;
  136     isc_region_t region;
  137     uint8_t length;
  138 
  139     REQUIRE(txt != NULL);
  140     REQUIRE(txt->common.rdtype == type);
  141     REQUIRE(txt->common.rdclass == rdclass);
  142     REQUIRE(txt->txt != NULL && txt->txt_len != 0);
  143 
  144     UNUSED(type);
  145     UNUSED(rdclass);
  146 
  147     region.base = txt->txt;
  148     region.length = txt->txt_len;
  149     while (region.length > 0) {
  150         length = uint8_fromregion(&region);
  151         isc_region_consume(&region, 1);
  152         if (region.length < length) {
  153             return (ISC_R_UNEXPECTEDEND);
  154         }
  155         isc_region_consume(&region, length);
  156     }
  157 
  158     return (mem_tobuffer(target, txt->txt, txt->txt_len));
  159 }
  160 
  161 static inline isc_result_t
  162 generic_tostruct_txt(ARGS_TOSTRUCT) {
  163     dns_rdata_txt_t *txt = target;
  164     isc_region_t r;
  165 
  166     REQUIRE(txt != NULL);
  167     REQUIRE(txt->common.rdclass == rdata->rdclass);
  168     REQUIRE(txt->common.rdtype == rdata->type);
  169     REQUIRE(!ISC_LINK_LINKED(&txt->common, link));
  170 
  171     dns_rdata_toregion(rdata, &r);
  172     txt->txt_len = r.length;
  173     txt->txt = mem_maybedup(mctx, r.base, r.length);
  174     if (txt->txt == NULL) {
  175         return (ISC_R_NOMEMORY);
  176     }
  177 
  178     txt->offset = 0;
  179     txt->mctx = mctx;
  180     return (ISC_R_SUCCESS);
  181 }
  182 
  183 static inline void
  184 generic_freestruct_txt(ARGS_FREESTRUCT) {
  185     dns_rdata_txt_t *txt = source;
  186 
  187     REQUIRE(txt != NULL);
  188 
  189     if (txt->mctx == NULL) {
  190         return;
  191     }
  192 
  193     if (txt->txt != NULL) {
  194         isc_mem_free(txt->mctx, txt->txt);
  195     }
  196     txt->mctx = NULL;
  197 }
  198 
  199 static inline isc_result_t
  200 fromstruct_txt(ARGS_FROMSTRUCT) {
  201     REQUIRE(type == dns_rdatatype_txt);
  202 
  203     return (generic_fromstruct_txt(rdclass, type, source, target));
  204 }
  205 
  206 static inline isc_result_t
  207 tostruct_txt(ARGS_TOSTRUCT) {
  208     dns_rdata_txt_t *txt = target;
  209 
  210     REQUIRE(rdata->type == dns_rdatatype_txt);
  211     REQUIRE(txt != NULL);
  212 
  213     txt->common.rdclass = rdata->rdclass;
  214     txt->common.rdtype = rdata->type;
  215     ISC_LINK_INIT(&txt->common, link);
  216 
  217     return (generic_tostruct_txt(rdata, target, mctx));
  218 }
  219 
  220 static inline void
  221 freestruct_txt(ARGS_FREESTRUCT) {
  222     dns_rdata_txt_t *txt = source;
  223 
  224     REQUIRE(txt != NULL);
  225     REQUIRE(txt->common.rdtype == dns_rdatatype_txt);
  226 
  227     generic_freestruct_txt(source);
  228 }
  229 
  230 static inline isc_result_t
  231 additionaldata_txt(ARGS_ADDLDATA) {
  232     REQUIRE(rdata->type == dns_rdatatype_txt);
  233 
  234     UNUSED(rdata);
  235     UNUSED(add);
  236     UNUSED(arg);
  237 
  238     return (ISC_R_SUCCESS);
  239 }
  240 
  241 static inline isc_result_t
  242 digest_txt(ARGS_DIGEST) {
  243     isc_region_t r;
  244 
  245     REQUIRE(rdata->type == dns_rdatatype_txt);
  246 
  247     dns_rdata_toregion(rdata, &r);
  248 
  249     return ((digest)(arg, &r));
  250 }
  251 
  252 static inline bool
  253 checkowner_txt(ARGS_CHECKOWNER) {
  254     REQUIRE(type == dns_rdatatype_txt);
  255 
  256     UNUSED(name);
  257     UNUSED(type);
  258     UNUSED(rdclass);
  259     UNUSED(wildcard);
  260 
  261     return (true);
  262 }
  263 
  264 static inline bool
  265 checknames_txt(ARGS_CHECKNAMES) {
  266     REQUIRE(rdata->type == dns_rdatatype_txt);
  267 
  268     UNUSED(rdata);
  269     UNUSED(owner);
  270     UNUSED(bad);
  271 
  272     return (true);
  273 }
  274 
  275 static inline int
  276 casecompare_txt(ARGS_COMPARE) {
  277     return (compare_txt(rdata1, rdata2));
  278 }
  279 
  280 static isc_result_t
  281 generic_txt_first(dns_rdata_txt_t *txt) {
  282     REQUIRE(txt != NULL);
  283     REQUIRE(txt->txt != NULL || txt->txt_len == 0);
  284 
  285     if (txt->txt_len == 0) {
  286         return (ISC_R_NOMORE);
  287     }
  288 
  289     txt->offset = 0;
  290     return (ISC_R_SUCCESS);
  291 }
  292 
  293 static isc_result_t
  294 generic_txt_next(dns_rdata_txt_t *txt) {
  295     isc_region_t r;
  296     uint8_t length;
  297 
  298     REQUIRE(txt != NULL);
  299     REQUIRE(txt->txt != NULL && txt->txt_len != 0);
  300 
  301     INSIST(txt->offset + 1 <= txt->txt_len);
  302     r.base = txt->txt + txt->offset;
  303     r.length = txt->txt_len - txt->offset;
  304     length = uint8_fromregion(&r);
  305     INSIST(txt->offset + 1 + length <= txt->txt_len);
  306     txt->offset = txt->offset + 1 + length;
  307     if (txt->offset == txt->txt_len) {
  308         return (ISC_R_NOMORE);
  309     }
  310     return (ISC_R_SUCCESS);
  311 }
  312 
  313 static isc_result_t
  314 generic_txt_current(dns_rdata_txt_t *txt, dns_rdata_txt_string_t *string) {
  315     isc_region_t r;
  316 
  317     REQUIRE(txt != NULL);
  318     REQUIRE(string != NULL);
  319     REQUIRE(txt->txt != NULL);
  320     REQUIRE(txt->offset < txt->txt_len);
  321 
  322     INSIST(txt->offset + 1 <= txt->txt_len);
  323     r.base = txt->txt + txt->offset;
  324     r.length = txt->txt_len - txt->offset;
  325 
  326     string->length = uint8_fromregion(&r);
  327     isc_region_consume(&r, 1);
  328     string->data = r.base;
  329     INSIST(txt->offset + 1 + string->length <= txt->txt_len);
  330 
  331     return (ISC_R_SUCCESS);
  332 }
  333 
  334 isc_result_t
  335 dns_rdata_txt_first(dns_rdata_txt_t *txt) {
  336     REQUIRE(txt != NULL);
  337     REQUIRE(txt->common.rdtype == dns_rdatatype_txt);
  338 
  339     return (generic_txt_first(txt));
  340 }
  341 
  342 isc_result_t
  343 dns_rdata_txt_next(dns_rdata_txt_t *txt) {
  344     REQUIRE(txt != NULL);
  345     REQUIRE(txt->common.rdtype == dns_rdatatype_txt);
  346 
  347     return (generic_txt_next(txt));
  348 }
  349 
  350 isc_result_t
  351 dns_rdata_txt_current(dns_rdata_txt_t *txt, dns_rdata_txt_string_t *string) {
  352     REQUIRE(txt != NULL);
  353     REQUIRE(txt->common.rdtype == dns_rdatatype_txt);
  354 
  355     return (generic_txt_current(txt, string));
  356 }
  357 #endif /* RDATA_GENERIC_TXT_16_C */