"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.17.5/lib/dns/rdata/in_1/atma_34.c" (4 Sep 2020, 7150 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 "atma_34.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 /* http://www.broadband-forum.org/ftp/pub/approved-specs/af-dans-0152.000.pdf */
   13 
   14 #ifndef RDATA_IN_1_ATMA_22_C
   15 #define RDATA_IN_1_ATMA_22_C
   16 
   17 #define RRTYPE_ATMA_ATTRIBUTES (0)
   18 
   19 static inline isc_result_t
   20 fromtext_in_atma(ARGS_FROMTEXT) {
   21     isc_token_t token;
   22     isc_textregion_t *sr;
   23     int n;
   24     bool valid = false;
   25     bool lastwasperiod = true; /* leading periods not allowed */
   26     int digits = 0;
   27     unsigned char c = 0;
   28 
   29     REQUIRE(type == dns_rdatatype_atma);
   30     REQUIRE(rdclass == dns_rdataclass_in);
   31 
   32     UNUSED(type);
   33     UNUSED(origin);
   34     UNUSED(options);
   35     UNUSED(rdclass);
   36     UNUSED(callbacks);
   37 
   38     /* ATM End System Address (AESA) format or E.164 */
   39     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
   40                       false));
   41     sr = &token.value.as_textregion;
   42     if (sr->length < 1) {
   43         RETTOK(ISC_R_UNEXPECTEDEND);
   44     }
   45 
   46     if (sr->base[0] != '+') {
   47         /*
   48          * Format 0: ATM End System Address (AESA) format.
   49          */
   50         c = 0;
   51         RETERR(mem_tobuffer(target, &c, 1));
   52         while (sr->length > 0) {
   53             if (sr->base[0] == '.') {
   54                 if (lastwasperiod) {
   55                     RETTOK(DNS_R_SYNTAX);
   56                 }
   57                 isc_textregion_consume(sr, 1);
   58                 lastwasperiod = true;
   59                 continue;
   60             }
   61             if ((n = hexvalue(sr->base[0])) == -1) {
   62                 RETTOK(DNS_R_SYNTAX);
   63             }
   64             c <<= 4;
   65             c += n;
   66             if (++digits == 2) {
   67                 RETERR(mem_tobuffer(target, &c, 1));
   68                 valid = true;
   69                 digits = 0;
   70                 c = 0;
   71             }
   72             isc_textregion_consume(sr, 1);
   73             lastwasperiod = false;
   74         }
   75         if (digits != 0 || !valid || lastwasperiod) {
   76             RETTOK(ISC_R_UNEXPECTEDEND);
   77         }
   78     } else {
   79         /*
   80          * Format 1:  E.164.
   81          */
   82         c = 1;
   83         RETERR(mem_tobuffer(target, &c, 1));
   84         isc_textregion_consume(sr, 1);
   85         while (sr->length > 0) {
   86             if (sr->base[0] == '.') {
   87                 if (lastwasperiod) {
   88                     RETTOK(DNS_R_SYNTAX);
   89                 }
   90                 isc_textregion_consume(sr, 1);
   91                 lastwasperiod = true;
   92                 continue;
   93             }
   94             if ((sr->base[0] < '0') || (sr->base[0] > '9')) {
   95                 RETTOK(DNS_R_SYNTAX);
   96             }
   97             RETERR(mem_tobuffer(target, sr->base, 1));
   98             isc_textregion_consume(sr, 1);
   99             lastwasperiod = false;
  100         }
  101         if (lastwasperiod) {
  102             RETTOK(ISC_R_UNEXPECTEDEND);
  103         }
  104     }
  105     return (ISC_R_SUCCESS);
  106 }
  107 
  108 static inline isc_result_t
  109 totext_in_atma(ARGS_TOTEXT) {
  110     isc_region_t region;
  111     char buf[sizeof("xx")];
  112 
  113     REQUIRE(rdata->type == dns_rdatatype_atma);
  114     REQUIRE(rdata->rdclass == dns_rdataclass_in);
  115     REQUIRE(rdata->length != 0);
  116 
  117     UNUSED(tctx);
  118 
  119     dns_rdata_toregion(rdata, &region);
  120     INSIST(region.length > 1);
  121     switch (region.base[0]) {
  122     case 0:
  123         isc_region_consume(&region, 1);
  124         while (region.length != 0) {
  125             snprintf(buf, sizeof(buf), "%02x", region.base[0]);
  126             isc_region_consume(&region, 1);
  127             RETERR(str_totext(buf, target));
  128         }
  129         break;
  130     case 1:
  131         RETERR(str_totext("+", target));
  132         isc_region_consume(&region, 1);
  133         RETERR(mem_tobuffer(target, region.base, region.length));
  134         break;
  135     default:
  136         return (ISC_R_NOTIMPLEMENTED);
  137     }
  138     return (ISC_R_SUCCESS);
  139 }
  140 
  141 static inline isc_result_t
  142 fromwire_in_atma(ARGS_FROMWIRE) {
  143     isc_region_t region;
  144 
  145     REQUIRE(type == dns_rdatatype_atma);
  146     REQUIRE(rdclass == dns_rdataclass_in);
  147 
  148     UNUSED(type);
  149     UNUSED(dctx);
  150     UNUSED(options);
  151     UNUSED(rdclass);
  152 
  153     isc_buffer_activeregion(source, &region);
  154     if (region.length < 2) {
  155         return (ISC_R_UNEXPECTEDEND);
  156     }
  157     if (region.base[0] == 1) {
  158         unsigned int i;
  159         for (i = 1; i < region.length; i++) {
  160             if (region.base[i] < '0' || region.base[i] > '9') {
  161                 return (DNS_R_FORMERR);
  162             }
  163         }
  164     }
  165     RETERR(mem_tobuffer(target, region.base, region.length));
  166     isc_buffer_forward(source, region.length);
  167     return (ISC_R_SUCCESS);
  168 }
  169 
  170 static inline isc_result_t
  171 towire_in_atma(ARGS_TOWIRE) {
  172     REQUIRE(rdata->type == dns_rdatatype_atma);
  173     REQUIRE(rdata->rdclass == dns_rdataclass_in);
  174     REQUIRE(rdata->length != 0);
  175 
  176     UNUSED(cctx);
  177 
  178     return (mem_tobuffer(target, rdata->data, rdata->length));
  179 }
  180 
  181 static inline int
  182 compare_in_atma(ARGS_COMPARE) {
  183     isc_region_t r1;
  184     isc_region_t r2;
  185 
  186     REQUIRE(rdata1->type == rdata2->type);
  187     REQUIRE(rdata1->rdclass == rdata2->rdclass);
  188     REQUIRE(rdata1->type == dns_rdatatype_atma);
  189     REQUIRE(rdata1->rdclass == dns_rdataclass_in);
  190     REQUIRE(rdata1->length != 0);
  191     REQUIRE(rdata2->length != 0);
  192 
  193     dns_rdata_toregion(rdata1, &r1);
  194     dns_rdata_toregion(rdata2, &r2);
  195     return (isc_region_compare(&r1, &r2));
  196 }
  197 
  198 static inline isc_result_t
  199 fromstruct_in_atma(ARGS_FROMSTRUCT) {
  200     dns_rdata_in_atma_t *atma = source;
  201 
  202     REQUIRE(type == dns_rdatatype_atma);
  203     REQUIRE(rdclass == dns_rdataclass_in);
  204     REQUIRE(atma != NULL);
  205     REQUIRE(atma->common.rdtype == type);
  206     REQUIRE(atma->common.rdclass == rdclass);
  207     REQUIRE(atma->atma != NULL || atma->atma_len == 0);
  208 
  209     UNUSED(type);
  210     UNUSED(rdclass);
  211 
  212     RETERR(mem_tobuffer(target, &atma->format, 1));
  213     return (mem_tobuffer(target, atma->atma, atma->atma_len));
  214 }
  215 
  216 static inline isc_result_t
  217 tostruct_in_atma(ARGS_TOSTRUCT) {
  218     dns_rdata_in_atma_t *atma = target;
  219     isc_region_t r;
  220 
  221     REQUIRE(rdata->type == dns_rdatatype_atma);
  222     REQUIRE(rdata->rdclass == dns_rdataclass_in);
  223     REQUIRE(atma != NULL);
  224     REQUIRE(rdata->length != 0);
  225 
  226     atma->common.rdclass = rdata->rdclass;
  227     atma->common.rdtype = rdata->type;
  228     ISC_LINK_INIT(&atma->common, link);
  229 
  230     dns_rdata_toregion(rdata, &r);
  231     atma->format = r.base[0];
  232     isc_region_consume(&r, 1);
  233     atma->atma_len = r.length;
  234     atma->atma = mem_maybedup(mctx, r.base, r.length);
  235     if (atma->atma == NULL) {
  236         return (ISC_R_NOMEMORY);
  237     }
  238 
  239     atma->mctx = mctx;
  240     return (ISC_R_SUCCESS);
  241 }
  242 
  243 static inline void
  244 freestruct_in_atma(ARGS_FREESTRUCT) {
  245     dns_rdata_in_atma_t *atma = source;
  246 
  247     REQUIRE(atma != NULL);
  248     REQUIRE(atma->common.rdclass == dns_rdataclass_in);
  249     REQUIRE(atma->common.rdtype == dns_rdatatype_atma);
  250 
  251     if (atma->mctx == NULL) {
  252         return;
  253     }
  254 
  255     if (atma->atma != NULL) {
  256         isc_mem_free(atma->mctx, atma->atma);
  257     }
  258     atma->mctx = NULL;
  259 }
  260 
  261 static inline isc_result_t
  262 additionaldata_in_atma(ARGS_ADDLDATA) {
  263     REQUIRE(rdata->type == dns_rdatatype_atma);
  264     REQUIRE(rdata->rdclass == dns_rdataclass_in);
  265 
  266     UNUSED(rdata);
  267     UNUSED(add);
  268     UNUSED(arg);
  269 
  270     return (ISC_R_SUCCESS);
  271 }
  272 
  273 static inline isc_result_t
  274 digest_in_atma(ARGS_DIGEST) {
  275     isc_region_t r;
  276 
  277     REQUIRE(rdata->type == dns_rdatatype_atma);
  278     REQUIRE(rdata->rdclass == dns_rdataclass_in);
  279 
  280     dns_rdata_toregion(rdata, &r);
  281 
  282     return ((digest)(arg, &r));
  283 }
  284 
  285 static inline bool
  286 checkowner_in_atma(ARGS_CHECKOWNER) {
  287     REQUIRE(type == dns_rdatatype_atma);
  288     REQUIRE(rdclass == dns_rdataclass_in);
  289 
  290     UNUSED(name);
  291     UNUSED(type);
  292     UNUSED(rdclass);
  293     UNUSED(wildcard);
  294 
  295     return (true);
  296 }
  297 
  298 static inline bool
  299 checknames_in_atma(ARGS_CHECKNAMES) {
  300     REQUIRE(rdata->type == dns_rdatatype_atma);
  301     REQUIRE(rdata->rdclass == dns_rdataclass_in);
  302 
  303     UNUSED(rdata);
  304     UNUSED(owner);
  305     UNUSED(bad);
  306 
  307     return (true);
  308 }
  309 
  310 static inline int
  311 casecompare_in_atma(ARGS_COMPARE) {
  312     return (compare_in_atma(rdata1, rdata2));
  313 }
  314 
  315 #endif /* RDATA_IN_1_atma_22_C */