"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.11.23/lib/dns/rdata/in_1/nsap_22.c" (7 Sep 2020, 5952 Bytes) of package /linux/misc/dns/bind9/9.11.23/bind-9.11.23.tar.gz:


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 "nsap_22.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 /* RFC1706 */
   13 
   14 #ifndef RDATA_IN_1_NSAP_22_C
   15 #define RDATA_IN_1_NSAP_22_C
   16 
   17 #define RRTYPE_NSAP_ATTRIBUTES (0)
   18 
   19 static inline isc_result_t
   20 fromtext_in_nsap(ARGS_FROMTEXT) {
   21     isc_token_t token;
   22     isc_textregion_t *sr;
   23     int n;
   24     bool valid = false;
   25     int digits = 0;
   26     unsigned char c = 0;
   27 
   28     REQUIRE(type == dns_rdatatype_nsap);
   29     REQUIRE(rdclass == dns_rdataclass_in);
   30 
   31     UNUSED(type);
   32     UNUSED(origin);
   33     UNUSED(options);
   34     UNUSED(rdclass);
   35     UNUSED(callbacks);
   36 
   37     /* 0x<hex.string.with.periods> */
   38     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
   39                       false));
   40     sr = &token.value.as_textregion;
   41     if (sr->length < 2)
   42         RETTOK(ISC_R_UNEXPECTEDEND);
   43     if (sr->base[0] != '0' || (sr->base[1] != 'x' && sr->base[1] != 'X'))
   44         RETTOK(DNS_R_SYNTAX);
   45     isc_textregion_consume(sr, 2);
   46     while (sr->length > 0) {
   47         if (sr->base[0] == '.') {
   48             isc_textregion_consume(sr, 1);
   49             continue;
   50         }
   51         if ((n = hexvalue(sr->base[0])) == -1)
   52             RETTOK(DNS_R_SYNTAX);
   53         c <<= 4;
   54         c += n;
   55         if (++digits == 2) {
   56             RETERR(mem_tobuffer(target, &c, 1));
   57             valid = true;
   58             digits = 0;
   59             c = 0;
   60         }
   61         isc_textregion_consume(sr, 1);
   62     }
   63     if (digits != 0 || !valid)
   64         RETTOK(ISC_R_UNEXPECTEDEND);
   65     return (ISC_R_SUCCESS);
   66 }
   67 
   68 static inline isc_result_t
   69 totext_in_nsap(ARGS_TOTEXT) {
   70     isc_region_t region;
   71     char buf[sizeof("xx")];
   72 
   73     REQUIRE(rdata->type == dns_rdatatype_nsap);
   74     REQUIRE(rdata->rdclass == dns_rdataclass_in);
   75     REQUIRE(rdata->length != 0);
   76 
   77     UNUSED(tctx);
   78 
   79     dns_rdata_toregion(rdata, &region);
   80     RETERR(str_totext("0x", target));
   81     while (region.length != 0) {
   82         snprintf(buf, sizeof(buf), "%02x", region.base[0]);
   83         isc_region_consume(&region, 1);
   84         RETERR(str_totext(buf, target));
   85     }
   86     return (ISC_R_SUCCESS);
   87 }
   88 
   89 static inline isc_result_t
   90 fromwire_in_nsap(ARGS_FROMWIRE) {
   91     isc_region_t region;
   92 
   93     REQUIRE(type == dns_rdatatype_nsap);
   94     REQUIRE(rdclass == dns_rdataclass_in);
   95 
   96     UNUSED(type);
   97     UNUSED(dctx);
   98     UNUSED(options);
   99     UNUSED(rdclass);
  100 
  101     isc_buffer_activeregion(source, &region);
  102     if (region.length < 1)
  103         return (ISC_R_UNEXPECTEDEND);
  104 
  105     RETERR(mem_tobuffer(target, region.base, region.length));
  106     isc_buffer_forward(source, region.length);
  107     return (ISC_R_SUCCESS);
  108 }
  109 
  110 static inline isc_result_t
  111 towire_in_nsap(ARGS_TOWIRE) {
  112     REQUIRE(rdata->type == dns_rdatatype_nsap);
  113     REQUIRE(rdata->rdclass == dns_rdataclass_in);
  114     REQUIRE(rdata->length != 0);
  115 
  116     UNUSED(cctx);
  117 
  118     return (mem_tobuffer(target, rdata->data, rdata->length));
  119 }
  120 
  121 static inline int
  122 compare_in_nsap(ARGS_COMPARE) {
  123     isc_region_t r1;
  124     isc_region_t r2;
  125 
  126     REQUIRE(rdata1->type == rdata2->type);
  127     REQUIRE(rdata1->rdclass == rdata2->rdclass);
  128     REQUIRE(rdata1->type == dns_rdatatype_nsap);
  129     REQUIRE(rdata1->rdclass == dns_rdataclass_in);
  130     REQUIRE(rdata1->length != 0);
  131     REQUIRE(rdata2->length != 0);
  132 
  133     dns_rdata_toregion(rdata1, &r1);
  134     dns_rdata_toregion(rdata2, &r2);
  135     return (isc_region_compare(&r1, &r2));
  136 }
  137 
  138 static inline isc_result_t
  139 fromstruct_in_nsap(ARGS_FROMSTRUCT) {
  140     dns_rdata_in_nsap_t *nsap;
  141 
  142     REQUIRE(type == dns_rdatatype_nsap);
  143     REQUIRE(rdclass == dns_rdataclass_in);
  144     REQUIRE(((dns_rdata_in_nsap_t *)source) != NULL);
  145     REQUIRE(((dns_rdata_in_nsap_t *)source)->common.rdtype == type);
  146     REQUIRE(((dns_rdata_in_nsap_t *)source)->common.rdclass == rdclass);
  147     REQUIRE(((dns_rdata_in_nsap_t *)source)->nsap != NULL ||
  148         ((dns_rdata_in_nsap_t *)source)->nsap_len == 0);
  149 
  150     nsap = source;
  151 
  152     UNUSED(type);
  153     UNUSED(rdclass);
  154 
  155     return (mem_tobuffer(target, nsap->nsap, nsap->nsap_len));
  156 }
  157 
  158 static inline isc_result_t
  159 tostruct_in_nsap(ARGS_TOSTRUCT) {
  160     dns_rdata_in_nsap_t *nsap;
  161     isc_region_t r;
  162 
  163     REQUIRE(((dns_rdata_in_nsap_t *)target) != NULL);
  164     REQUIRE(rdata->type == dns_rdatatype_nsap);
  165     REQUIRE(rdata->rdclass == dns_rdataclass_in);
  166     REQUIRE(rdata->length != 0);
  167 
  168     nsap = target;
  169 
  170     nsap->common.rdclass = rdata->rdclass;
  171     nsap->common.rdtype = rdata->type;
  172     ISC_LINK_INIT(&nsap->common, link);
  173 
  174     dns_rdata_toregion(rdata, &r);
  175     nsap->nsap_len = r.length;
  176     nsap->nsap = mem_maybedup(mctx, r.base, r.length);
  177     if (nsap->nsap == NULL)
  178         return (ISC_R_NOMEMORY);
  179 
  180     nsap->mctx = mctx;
  181     return (ISC_R_SUCCESS);
  182 }
  183 
  184 static inline void
  185 freestruct_in_nsap(ARGS_FREESTRUCT) {
  186     dns_rdata_in_nsap_t *nsap;
  187 
  188     REQUIRE(((dns_rdata_in_nsap_t *)source) != NULL);
  189     REQUIRE(((dns_rdata_in_nsap_t *)source)->common.rdclass ==
  190         dns_rdataclass_in);
  191     REQUIRE(((dns_rdata_in_nsap_t *)source)->common.rdtype ==
  192         dns_rdatatype_nsap);
  193 
  194     nsap = source;
  195 
  196     if (nsap->mctx == NULL)
  197         return;
  198 
  199     if (nsap->nsap != NULL)
  200         isc_mem_free(nsap->mctx, nsap->nsap);
  201     nsap->mctx = NULL;
  202 }
  203 
  204 static inline isc_result_t
  205 additionaldata_in_nsap(ARGS_ADDLDATA) {
  206     REQUIRE(rdata->type == dns_rdatatype_nsap);
  207     REQUIRE(rdata->rdclass == dns_rdataclass_in);
  208 
  209     UNUSED(rdata);
  210     UNUSED(add);
  211     UNUSED(arg);
  212 
  213     return (ISC_R_SUCCESS);
  214 }
  215 
  216 static inline isc_result_t
  217 digest_in_nsap(ARGS_DIGEST) {
  218     isc_region_t r;
  219 
  220     REQUIRE(rdata->type == dns_rdatatype_nsap);
  221     REQUIRE(rdata->rdclass == dns_rdataclass_in);
  222 
  223     dns_rdata_toregion(rdata, &r);
  224 
  225     return ((digest)(arg, &r));
  226 }
  227 
  228 static inline bool
  229 checkowner_in_nsap(ARGS_CHECKOWNER) {
  230 
  231     REQUIRE(type == dns_rdatatype_nsap);
  232     REQUIRE(rdclass == dns_rdataclass_in);
  233 
  234     UNUSED(name);
  235     UNUSED(type);
  236     UNUSED(rdclass);
  237     UNUSED(wildcard);
  238 
  239     return (true);
  240 }
  241 
  242 static inline bool
  243 checknames_in_nsap(ARGS_CHECKNAMES) {
  244 
  245     REQUIRE(rdata->type == dns_rdatatype_nsap);
  246     REQUIRE(rdata->rdclass == dns_rdataclass_in);
  247 
  248     UNUSED(rdata);
  249     UNUSED(owner);
  250     UNUSED(bad);
  251 
  252     return (true);
  253 }
  254 
  255 static inline int
  256 casecompare_in_nsap(ARGS_COMPARE) {
  257     return (compare_in_nsap(rdata1, rdata2));
  258 }
  259 
  260 #endif  /* RDATA_IN_1_NSAP_22_C */