"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.11.23/lib/dns/rdata/generic/isdn_20.c" (7 Sep 2020, 5413 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 "isdn_20.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 /* RFC1183 */
   13 
   14 #ifndef RDATA_GENERIC_ISDN_20_C
   15 #define RDATA_GENERIC_ISDN_20_C
   16 
   17 #define RRTYPE_ISDN_ATTRIBUTES (0)
   18 
   19 static inline isc_result_t
   20 fromtext_isdn(ARGS_FROMTEXT) {
   21     isc_token_t token;
   22 
   23     REQUIRE(type == dns_rdatatype_isdn);
   24 
   25     UNUSED(type);
   26     UNUSED(rdclass);
   27     UNUSED(origin);
   28     UNUSED(options);
   29     UNUSED(callbacks);
   30 
   31     /* ISDN-address */
   32     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
   33                       false));
   34     RETTOK(txt_fromtext(&token.value.as_textregion, target));
   35 
   36     /* sa: optional */
   37     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
   38                       true));
   39     if (token.type != isc_tokentype_string &&
   40         token.type != isc_tokentype_qstring) {
   41         isc_lex_ungettoken(lexer, &token);
   42         return (ISC_R_SUCCESS);
   43     }
   44     RETTOK(txt_fromtext(&token.value.as_textregion, target));
   45     return (ISC_R_SUCCESS);
   46 }
   47 
   48 static inline isc_result_t
   49 totext_isdn(ARGS_TOTEXT) {
   50     isc_region_t region;
   51 
   52     REQUIRE(rdata->type == dns_rdatatype_isdn);
   53     REQUIRE(rdata->length != 0);
   54 
   55     UNUSED(tctx);
   56 
   57     dns_rdata_toregion(rdata, &region);
   58     RETERR(txt_totext(&region, true, target));
   59     if (region.length == 0)
   60         return (ISC_R_SUCCESS);
   61     RETERR(str_totext(" ", target));
   62     return (txt_totext(&region, true, target));
   63 }
   64 
   65 static inline isc_result_t
   66 fromwire_isdn(ARGS_FROMWIRE) {
   67     REQUIRE(type == dns_rdatatype_isdn);
   68 
   69     UNUSED(type);
   70     UNUSED(dctx);
   71     UNUSED(rdclass);
   72     UNUSED(options);
   73 
   74     RETERR(txt_fromwire(source, target));
   75     if (buffer_empty(source))
   76         return (ISC_R_SUCCESS);
   77     return (txt_fromwire(source, target));
   78 }
   79 
   80 static inline isc_result_t
   81 towire_isdn(ARGS_TOWIRE) {
   82     UNUSED(cctx);
   83 
   84     REQUIRE(rdata->type == dns_rdatatype_isdn);
   85     REQUIRE(rdata->length != 0);
   86 
   87     return (mem_tobuffer(target, rdata->data, rdata->length));
   88 }
   89 
   90 static inline int
   91 compare_isdn(ARGS_COMPARE) {
   92     isc_region_t r1;
   93     isc_region_t r2;
   94 
   95     REQUIRE(rdata1->type == rdata2->type);
   96     REQUIRE(rdata1->rdclass == rdata2->rdclass);
   97     REQUIRE(rdata1->type == dns_rdatatype_isdn);
   98     REQUIRE(rdata1->length != 0);
   99     REQUIRE(rdata2->length != 0);
  100 
  101     dns_rdata_toregion(rdata1, &r1);
  102     dns_rdata_toregion(rdata2, &r2);
  103     return (isc_region_compare(&r1, &r2));
  104 }
  105 
  106 static inline isc_result_t
  107 fromstruct_isdn(ARGS_FROMSTRUCT) {
  108     dns_rdata_isdn_t *isdn;
  109 
  110     REQUIRE(type == dns_rdatatype_isdn);
  111     REQUIRE(((dns_rdata_isdn_t *)source) != NULL);
  112     REQUIRE(((dns_rdata_isdn_t *)source)->common.rdtype == type);
  113     REQUIRE(((dns_rdata_isdn_t *)source)->common.rdclass == rdclass);
  114 
  115     isdn = source;
  116 
  117     UNUSED(type);
  118     UNUSED(rdclass);
  119 
  120     RETERR(uint8_tobuffer(isdn->isdn_len, target));
  121     RETERR(mem_tobuffer(target, isdn->isdn, isdn->isdn_len));
  122     if (isdn->subaddress == NULL)
  123         return (ISC_R_SUCCESS);
  124     RETERR(uint8_tobuffer(isdn->subaddress_len, target));
  125     return (mem_tobuffer(target, isdn->subaddress, isdn->subaddress_len));
  126 }
  127 
  128 static inline isc_result_t
  129 tostruct_isdn(ARGS_TOSTRUCT) {
  130     dns_rdata_isdn_t *isdn;
  131     isc_region_t r;
  132 
  133     REQUIRE(((dns_rdata_isdn_t *)target) != NULL);
  134     REQUIRE(rdata->type == dns_rdatatype_isdn);
  135     REQUIRE(rdata->length != 0);
  136 
  137     isdn = target;
  138 
  139     isdn->common.rdclass = rdata->rdclass;
  140     isdn->common.rdtype = rdata->type;
  141     ISC_LINK_INIT(&isdn->common, link);
  142 
  143     dns_rdata_toregion(rdata, &r);
  144 
  145     isdn->isdn_len = uint8_fromregion(&r);
  146     isc_region_consume(&r, 1);
  147     isdn->isdn = mem_maybedup(mctx, r.base, isdn->isdn_len);
  148     if (isdn->isdn == NULL)
  149         return (ISC_R_NOMEMORY);
  150     isc_region_consume(&r, isdn->isdn_len);
  151 
  152     if (r.length == 0) {
  153         isdn->subaddress_len = 0;
  154         isdn->subaddress = NULL;
  155     } else {
  156         isdn->subaddress_len = uint8_fromregion(&r);
  157         isc_region_consume(&r, 1);
  158         isdn->subaddress = mem_maybedup(mctx, r.base,
  159                         isdn->subaddress_len);
  160         if (isdn->subaddress == NULL)
  161             goto cleanup;
  162     }
  163 
  164     isdn->mctx = mctx;
  165     return (ISC_R_SUCCESS);
  166 
  167  cleanup:
  168     if (mctx != NULL && isdn->isdn != NULL)
  169         isc_mem_free(mctx, isdn->isdn);
  170     return (ISC_R_NOMEMORY);
  171 }
  172 
  173 static inline void
  174 freestruct_isdn(ARGS_FREESTRUCT) {
  175     dns_rdata_isdn_t *isdn;
  176 
  177     REQUIRE(((dns_rdata_isdn_t *)source) != NULL);
  178 
  179     isdn = source;
  180 
  181     if (isdn->mctx == NULL)
  182         return;
  183 
  184     if (isdn->isdn != NULL)
  185         isc_mem_free(isdn->mctx, isdn->isdn);
  186     if (isdn->subaddress != NULL)
  187         isc_mem_free(isdn->mctx, isdn->subaddress);
  188     isdn->mctx = NULL;
  189 }
  190 
  191 static inline isc_result_t
  192 additionaldata_isdn(ARGS_ADDLDATA) {
  193     REQUIRE(rdata->type == dns_rdatatype_isdn);
  194 
  195     UNUSED(rdata);
  196     UNUSED(add);
  197     UNUSED(arg);
  198 
  199     return (ISC_R_SUCCESS);
  200 }
  201 
  202 static inline isc_result_t
  203 digest_isdn(ARGS_DIGEST) {
  204     isc_region_t r;
  205 
  206     REQUIRE(rdata->type == dns_rdatatype_isdn);
  207 
  208     dns_rdata_toregion(rdata, &r);
  209 
  210     return ((digest)(arg, &r));
  211 }
  212 
  213 static inline bool
  214 checkowner_isdn(ARGS_CHECKOWNER) {
  215 
  216     REQUIRE(type == dns_rdatatype_isdn);
  217 
  218     UNUSED(name);
  219     UNUSED(type);
  220     UNUSED(rdclass);
  221     UNUSED(wildcard);
  222 
  223     return (true);
  224 }
  225 
  226 static inline bool
  227 checknames_isdn(ARGS_CHECKNAMES) {
  228 
  229     REQUIRE(rdata->type == dns_rdatatype_isdn);
  230 
  231     UNUSED(rdata);
  232     UNUSED(owner);
  233     UNUSED(bad);
  234 
  235     return (true);
  236 }
  237 
  238 static inline int
  239 casecompare_isdn(ARGS_COMPARE) {
  240     return (compare_isdn(rdata1, rdata2));
  241 }
  242 
  243 #endif  /* RDATA_GENERIC_ISDN_20_C */