"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.17.5/lib/dns/rdata/generic/minfo_14.c" (4 Sep 2020, 7598 Bytes) of package /linux/misc/dns/bind9/9.17.5/bind-9.17.5.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 "minfo_14.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_MINFO_14_C
   13 #define RDATA_GENERIC_MINFO_14_C
   14 
   15 #define RRTYPE_MINFO_ATTRIBUTES (0)
   16 
   17 static inline isc_result_t
   18 fromtext_minfo(ARGS_FROMTEXT) {
   19     isc_token_t token;
   20     dns_name_t name;
   21     isc_buffer_t buffer;
   22     int i;
   23     bool ok;
   24 
   25     REQUIRE(type == dns_rdatatype_minfo);
   26 
   27     UNUSED(type);
   28     UNUSED(rdclass);
   29     UNUSED(callbacks);
   30 
   31     if (origin == NULL) {
   32         origin = dns_rootname;
   33     }
   34 
   35     for (i = 0; i < 2; i++) {
   36         RETERR(isc_lex_getmastertoken(lexer, &token,
   37                           isc_tokentype_string, false));
   38         dns_name_init(&name, NULL);
   39         buffer_fromregion(&buffer, &token.value.as_region);
   40         RETTOK(dns_name_fromtext(&name, &buffer, origin, options,
   41                      target));
   42         ok = true;
   43         if ((options & DNS_RDATA_CHECKNAMES) != 0) {
   44             ok = dns_name_ismailbox(&name);
   45         }
   46         if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) {
   47             RETTOK(DNS_R_BADNAME);
   48         }
   49         if (!ok && callbacks != NULL) {
   50             warn_badname(&name, lexer, callbacks);
   51         }
   52     }
   53     return (ISC_R_SUCCESS);
   54 }
   55 
   56 static inline isc_result_t
   57 totext_minfo(ARGS_TOTEXT) {
   58     isc_region_t region;
   59     dns_name_t rmail;
   60     dns_name_t email;
   61     dns_name_t prefix;
   62     bool sub;
   63 
   64     REQUIRE(rdata->type == dns_rdatatype_minfo);
   65     REQUIRE(rdata->length != 0);
   66 
   67     dns_name_init(&rmail, NULL);
   68     dns_name_init(&email, NULL);
   69     dns_name_init(&prefix, NULL);
   70 
   71     dns_rdata_toregion(rdata, &region);
   72 
   73     dns_name_fromregion(&rmail, &region);
   74     isc_region_consume(&region, rmail.length);
   75 
   76     dns_name_fromregion(&email, &region);
   77     isc_region_consume(&region, email.length);
   78 
   79     sub = name_prefix(&rmail, tctx->origin, &prefix);
   80 
   81     RETERR(dns_name_totext(&prefix, sub, target));
   82 
   83     RETERR(str_totext(" ", target));
   84 
   85     sub = name_prefix(&email, tctx->origin, &prefix);
   86     return (dns_name_totext(&prefix, sub, target));
   87 }
   88 
   89 static inline isc_result_t
   90 fromwire_minfo(ARGS_FROMWIRE) {
   91     dns_name_t rmail;
   92     dns_name_t email;
   93 
   94     REQUIRE(type == dns_rdatatype_minfo);
   95 
   96     UNUSED(type);
   97     UNUSED(rdclass);
   98 
   99     dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
  100 
  101     dns_name_init(&rmail, NULL);
  102     dns_name_init(&email, NULL);
  103 
  104     RETERR(dns_name_fromwire(&rmail, source, dctx, options, target));
  105     return (dns_name_fromwire(&email, source, dctx, options, target));
  106 }
  107 
  108 static inline isc_result_t
  109 towire_minfo(ARGS_TOWIRE) {
  110     isc_region_t region;
  111     dns_name_t rmail;
  112     dns_name_t email;
  113     dns_offsets_t roffsets;
  114     dns_offsets_t eoffsets;
  115 
  116     REQUIRE(rdata->type == dns_rdatatype_minfo);
  117     REQUIRE(rdata->length != 0);
  118 
  119     dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
  120 
  121     dns_name_init(&rmail, roffsets);
  122     dns_name_init(&email, eoffsets);
  123 
  124     dns_rdata_toregion(rdata, &region);
  125 
  126     dns_name_fromregion(&rmail, &region);
  127     isc_region_consume(&region, name_length(&rmail));
  128 
  129     RETERR(dns_name_towire(&rmail, cctx, target));
  130 
  131     dns_name_fromregion(&rmail, &region);
  132     isc_region_consume(&region, rmail.length);
  133 
  134     return (dns_name_towire(&rmail, cctx, target));
  135 }
  136 
  137 static inline int
  138 compare_minfo(ARGS_COMPARE) {
  139     isc_region_t region1;
  140     isc_region_t region2;
  141     dns_name_t name1;
  142     dns_name_t name2;
  143     int order;
  144 
  145     REQUIRE(rdata1->type == rdata2->type);
  146     REQUIRE(rdata1->rdclass == rdata2->rdclass);
  147     REQUIRE(rdata1->type == dns_rdatatype_minfo);
  148     REQUIRE(rdata1->length != 0);
  149     REQUIRE(rdata2->length != 0);
  150 
  151     dns_name_init(&name1, NULL);
  152     dns_name_init(&name2, NULL);
  153 
  154     dns_rdata_toregion(rdata1, &region1);
  155     dns_rdata_toregion(rdata2, &region2);
  156 
  157     dns_name_fromregion(&name1, &region1);
  158     dns_name_fromregion(&name2, &region2);
  159 
  160     order = dns_name_rdatacompare(&name1, &name2);
  161     if (order != 0) {
  162         return (order);
  163     }
  164 
  165     isc_region_consume(&region1, name_length(&name1));
  166     isc_region_consume(&region2, name_length(&name2));
  167 
  168     dns_name_init(&name1, NULL);
  169     dns_name_init(&name2, NULL);
  170 
  171     dns_name_fromregion(&name1, &region1);
  172     dns_name_fromregion(&name2, &region2);
  173 
  174     order = dns_name_rdatacompare(&name1, &name2);
  175     return (order);
  176 }
  177 
  178 static inline isc_result_t
  179 fromstruct_minfo(ARGS_FROMSTRUCT) {
  180     dns_rdata_minfo_t *minfo = source;
  181     isc_region_t region;
  182 
  183     REQUIRE(type == dns_rdatatype_minfo);
  184     REQUIRE(minfo != NULL);
  185     REQUIRE(minfo->common.rdtype == type);
  186     REQUIRE(minfo->common.rdclass == rdclass);
  187 
  188     UNUSED(type);
  189     UNUSED(rdclass);
  190 
  191     dns_name_toregion(&minfo->rmailbox, &region);
  192     RETERR(isc_buffer_copyregion(target, &region));
  193     dns_name_toregion(&minfo->emailbox, &region);
  194     return (isc_buffer_copyregion(target, &region));
  195 }
  196 
  197 static inline isc_result_t
  198 tostruct_minfo(ARGS_TOSTRUCT) {
  199     dns_rdata_minfo_t *minfo = target;
  200     isc_region_t region;
  201     dns_name_t name;
  202     isc_result_t result;
  203 
  204     REQUIRE(rdata->type == dns_rdatatype_minfo);
  205     REQUIRE(minfo != NULL);
  206     REQUIRE(rdata->length != 0);
  207 
  208     minfo->common.rdclass = rdata->rdclass;
  209     minfo->common.rdtype = rdata->type;
  210     ISC_LINK_INIT(&minfo->common, link);
  211 
  212     dns_name_init(&name, NULL);
  213     dns_rdata_toregion(rdata, &region);
  214     dns_name_fromregion(&name, &region);
  215     dns_name_init(&minfo->rmailbox, NULL);
  216     RETERR(name_duporclone(&name, mctx, &minfo->rmailbox));
  217     isc_region_consume(&region, name_length(&name));
  218 
  219     dns_name_fromregion(&name, &region);
  220     dns_name_init(&minfo->emailbox, NULL);
  221     result = name_duporclone(&name, mctx, &minfo->emailbox);
  222     if (result != ISC_R_SUCCESS) {
  223         goto cleanup;
  224     }
  225     minfo->mctx = mctx;
  226     return (ISC_R_SUCCESS);
  227 
  228 cleanup:
  229     if (mctx != NULL) {
  230         dns_name_free(&minfo->rmailbox, mctx);
  231     }
  232     return (ISC_R_NOMEMORY);
  233 }
  234 
  235 static inline void
  236 freestruct_minfo(ARGS_FREESTRUCT) {
  237     dns_rdata_minfo_t *minfo = source;
  238 
  239     REQUIRE(minfo != NULL);
  240     REQUIRE(minfo->common.rdtype == dns_rdatatype_minfo);
  241 
  242     if (minfo->mctx == NULL) {
  243         return;
  244     }
  245 
  246     dns_name_free(&minfo->rmailbox, minfo->mctx);
  247     dns_name_free(&minfo->emailbox, minfo->mctx);
  248     minfo->mctx = NULL;
  249 }
  250 
  251 static inline isc_result_t
  252 additionaldata_minfo(ARGS_ADDLDATA) {
  253     REQUIRE(rdata->type == dns_rdatatype_minfo);
  254 
  255     UNUSED(rdata);
  256     UNUSED(add);
  257     UNUSED(arg);
  258 
  259     return (ISC_R_SUCCESS);
  260 }
  261 
  262 static inline isc_result_t
  263 digest_minfo(ARGS_DIGEST) {
  264     isc_region_t r;
  265     dns_name_t name;
  266     isc_result_t result;
  267 
  268     REQUIRE(rdata->type == dns_rdatatype_minfo);
  269 
  270     dns_rdata_toregion(rdata, &r);
  271     dns_name_init(&name, NULL);
  272     dns_name_fromregion(&name, &r);
  273     result = dns_name_digest(&name, digest, arg);
  274     if (result != ISC_R_SUCCESS) {
  275         return (result);
  276     }
  277     isc_region_consume(&r, name_length(&name));
  278     dns_name_init(&name, NULL);
  279     dns_name_fromregion(&name, &r);
  280 
  281     return (dns_name_digest(&name, digest, arg));
  282 }
  283 
  284 static inline bool
  285 checkowner_minfo(ARGS_CHECKOWNER) {
  286     REQUIRE(type == dns_rdatatype_minfo);
  287 
  288     UNUSED(name);
  289     UNUSED(type);
  290     UNUSED(rdclass);
  291     UNUSED(wildcard);
  292 
  293     return (true);
  294 }
  295 
  296 static inline bool
  297 checknames_minfo(ARGS_CHECKNAMES) {
  298     isc_region_t region;
  299     dns_name_t name;
  300 
  301     REQUIRE(rdata->type == dns_rdatatype_minfo);
  302 
  303     UNUSED(owner);
  304 
  305     dns_rdata_toregion(rdata, &region);
  306     dns_name_init(&name, NULL);
  307     dns_name_fromregion(&name, &region);
  308     if (!dns_name_ismailbox(&name)) {
  309         if (bad != NULL) {
  310             dns_name_clone(&name, bad);
  311         }
  312         return (false);
  313     }
  314     isc_region_consume(&region, name_length(&name));
  315     dns_name_fromregion(&name, &region);
  316     if (!dns_name_ismailbox(&name)) {
  317         if (bad != NULL) {
  318             dns_name_clone(&name, bad);
  319         }
  320         return (false);
  321     }
  322     return (true);
  323 }
  324 
  325 static inline int
  326 casecompare_minfo(ARGS_COMPARE) {
  327     return (compare_minfo(rdata1, rdata2));
  328 }
  329 
  330 #endif /* RDATA_GENERIC_MINFO_14_C */