"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.16.7/lib/dns/rdata/generic/x25_19.c" (4 Sep 2020, 4737 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 "x25_19.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 9.16.6_vs_9.16.7.

    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 /* RFC1183 */
   13 
   14 #ifndef RDATA_GENERIC_X25_19_C
   15 #define RDATA_GENERIC_X25_19_C
   16 
   17 #define RRTYPE_X25_ATTRIBUTES (0)
   18 
   19 static inline isc_result_t
   20 fromtext_x25(ARGS_FROMTEXT) {
   21     isc_token_t token;
   22     unsigned int i;
   23 
   24     REQUIRE(type == dns_rdatatype_x25);
   25 
   26     UNUSED(type);
   27     UNUSED(rdclass);
   28     UNUSED(origin);
   29     UNUSED(options);
   30     UNUSED(callbacks);
   31 
   32     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
   33                       false));
   34     if (token.value.as_textregion.length < 4) {
   35         RETTOK(DNS_R_SYNTAX);
   36     }
   37     for (i = 0; i < token.value.as_textregion.length; i++) {
   38         if (!isdigit(token.value.as_textregion.base[i] & 0xff)) {
   39             RETTOK(ISC_R_RANGE);
   40         }
   41     }
   42     RETTOK(txt_fromtext(&token.value.as_textregion, target));
   43     return (ISC_R_SUCCESS);
   44 }
   45 
   46 static inline isc_result_t
   47 totext_x25(ARGS_TOTEXT) {
   48     isc_region_t region;
   49 
   50     UNUSED(tctx);
   51 
   52     REQUIRE(rdata->type == dns_rdatatype_x25);
   53     REQUIRE(rdata->length != 0);
   54 
   55     dns_rdata_toregion(rdata, &region);
   56     return (txt_totext(&region, true, target));
   57 }
   58 
   59 static inline isc_result_t
   60 fromwire_x25(ARGS_FROMWIRE) {
   61     isc_region_t sr;
   62     unsigned int i;
   63 
   64     REQUIRE(type == dns_rdatatype_x25);
   65 
   66     UNUSED(type);
   67     UNUSED(dctx);
   68     UNUSED(rdclass);
   69     UNUSED(options);
   70 
   71     isc_buffer_activeregion(source, &sr);
   72     if (sr.length < 5 || sr.base[0] != (sr.length - 1)) {
   73         return (DNS_R_FORMERR);
   74     }
   75     for (i = 1; i < sr.length; i++) {
   76         if (sr.base[i] < 0x30 || sr.base[i] > 0x39) {
   77             return (DNS_R_FORMERR);
   78         }
   79     }
   80     return (txt_fromwire(source, target));
   81 }
   82 
   83 static inline isc_result_t
   84 towire_x25(ARGS_TOWIRE) {
   85     UNUSED(cctx);
   86 
   87     REQUIRE(rdata->type == dns_rdatatype_x25);
   88     REQUIRE(rdata->length != 0);
   89 
   90     return (mem_tobuffer(target, rdata->data, rdata->length));
   91 }
   92 
   93 static inline int
   94 compare_x25(ARGS_COMPARE) {
   95     isc_region_t r1;
   96     isc_region_t r2;
   97 
   98     REQUIRE(rdata1->type == rdata2->type);
   99     REQUIRE(rdata1->rdclass == rdata2->rdclass);
  100     REQUIRE(rdata1->type == dns_rdatatype_x25);
  101     REQUIRE(rdata1->length != 0);
  102     REQUIRE(rdata2->length != 0);
  103 
  104     dns_rdata_toregion(rdata1, &r1);
  105     dns_rdata_toregion(rdata2, &r2);
  106     return (isc_region_compare(&r1, &r2));
  107 }
  108 
  109 static inline isc_result_t
  110 fromstruct_x25(ARGS_FROMSTRUCT) {
  111     dns_rdata_x25_t *x25 = source;
  112     uint8_t i;
  113 
  114     REQUIRE(type == dns_rdatatype_x25);
  115     REQUIRE(x25 != NULL);
  116     REQUIRE(x25->common.rdtype == type);
  117     REQUIRE(x25->common.rdclass == rdclass);
  118     REQUIRE(x25->x25 != NULL && x25->x25_len != 0);
  119 
  120     UNUSED(type);
  121     UNUSED(rdclass);
  122 
  123     if (x25->x25_len < 4) {
  124         return (ISC_R_RANGE);
  125     }
  126 
  127     for (i = 0; i < x25->x25_len; i++) {
  128         if (!isdigit(x25->x25[i] & 0xff)) {
  129             return (ISC_R_RANGE);
  130         }
  131     }
  132 
  133     RETERR(uint8_tobuffer(x25->x25_len, target));
  134     return (mem_tobuffer(target, x25->x25, x25->x25_len));
  135 }
  136 
  137 static inline isc_result_t
  138 tostruct_x25(ARGS_TOSTRUCT) {
  139     dns_rdata_x25_t *x25 = target;
  140     isc_region_t r;
  141 
  142     REQUIRE(rdata->type == dns_rdatatype_x25);
  143     REQUIRE(x25 != NULL);
  144     REQUIRE(rdata->length != 0);
  145 
  146     x25->common.rdclass = rdata->rdclass;
  147     x25->common.rdtype = rdata->type;
  148     ISC_LINK_INIT(&x25->common, link);
  149 
  150     dns_rdata_toregion(rdata, &r);
  151     x25->x25_len = uint8_fromregion(&r);
  152     isc_region_consume(&r, 1);
  153     x25->x25 = mem_maybedup(mctx, r.base, x25->x25_len);
  154     if (x25->x25 == NULL) {
  155         return (ISC_R_NOMEMORY);
  156     }
  157 
  158     x25->mctx = mctx;
  159     return (ISC_R_SUCCESS);
  160 }
  161 
  162 static inline void
  163 freestruct_x25(ARGS_FREESTRUCT) {
  164     dns_rdata_x25_t *x25 = source;
  165 
  166     REQUIRE(x25 != NULL);
  167     REQUIRE(x25->common.rdtype == dns_rdatatype_x25);
  168 
  169     if (x25->mctx == NULL) {
  170         return;
  171     }
  172 
  173     if (x25->x25 != NULL) {
  174         isc_mem_free(x25->mctx, x25->x25);
  175     }
  176     x25->mctx = NULL;
  177 }
  178 
  179 static inline isc_result_t
  180 additionaldata_x25(ARGS_ADDLDATA) {
  181     REQUIRE(rdata->type == dns_rdatatype_x25);
  182 
  183     UNUSED(rdata);
  184     UNUSED(add);
  185     UNUSED(arg);
  186 
  187     return (ISC_R_SUCCESS);
  188 }
  189 
  190 static inline isc_result_t
  191 digest_x25(ARGS_DIGEST) {
  192     isc_region_t r;
  193 
  194     REQUIRE(rdata->type == dns_rdatatype_x25);
  195 
  196     dns_rdata_toregion(rdata, &r);
  197 
  198     return ((digest)(arg, &r));
  199 }
  200 
  201 static inline bool
  202 checkowner_x25(ARGS_CHECKOWNER) {
  203     REQUIRE(type == dns_rdatatype_x25);
  204 
  205     UNUSED(name);
  206     UNUSED(type);
  207     UNUSED(rdclass);
  208     UNUSED(wildcard);
  209 
  210     return (true);
  211 }
  212 
  213 static inline bool
  214 checknames_x25(ARGS_CHECKNAMES) {
  215     REQUIRE(rdata->type == dns_rdatatype_x25);
  216 
  217     UNUSED(rdata);
  218     UNUSED(owner);
  219     UNUSED(bad);
  220 
  221     return (true);
  222 }
  223 
  224 static inline int
  225 casecompare_x25(ARGS_COMPARE) {
  226     return (compare_x25(rdata1, rdata2));
  227 }
  228 
  229 #endif /* RDATA_GENERIC_X25_19_C */