isdn_20.c revision 1.6
1/* 2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 * PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17/* $Id: isdn_20.c,v 1.6 2020/02/24 17:43:52 florian Exp $ */ 18 19/* Reviewed: Wed Mar 15 16:53:11 PST 2000 by bwelling */ 20 21/* RFC1183 */ 22 23#ifndef RDATA_GENERIC_ISDN_20_C 24#define RDATA_GENERIC_ISDN_20_C 25 26#define RRTYPE_ISDN_ATTRIBUTES (0) 27 28static inline isc_result_t 29totext_isdn(ARGS_TOTEXT) { 30 isc_region_t region; 31 32 REQUIRE(rdata->type == dns_rdatatype_isdn); 33 REQUIRE(rdata->length != 0); 34 35 UNUSED(tctx); 36 37 dns_rdata_toregion(rdata, ®ion); 38 RETERR(txt_totext(®ion, ISC_TRUE, target)); 39 if (region.length == 0) 40 return (ISC_R_SUCCESS); 41 RETERR(str_totext(" ", target)); 42 return (txt_totext(®ion, ISC_TRUE, target)); 43} 44 45static inline isc_result_t 46fromwire_isdn(ARGS_FROMWIRE) { 47 REQUIRE(type == dns_rdatatype_isdn); 48 49 UNUSED(type); 50 UNUSED(dctx); 51 UNUSED(rdclass); 52 UNUSED(options); 53 54 RETERR(txt_fromwire(source, target)); 55 if (buffer_empty(source)) 56 return (ISC_R_SUCCESS); 57 return (txt_fromwire(source, target)); 58} 59 60static inline isc_result_t 61towire_isdn(ARGS_TOWIRE) { 62 UNUSED(cctx); 63 64 REQUIRE(rdata->type == dns_rdatatype_isdn); 65 REQUIRE(rdata->length != 0); 66 67 return (mem_tobuffer(target, rdata->data, rdata->length)); 68} 69 70 71static inline isc_result_t 72fromstruct_isdn(ARGS_FROMSTRUCT) { 73 dns_rdata_isdn_t *isdn = source; 74 75 REQUIRE(type == dns_rdatatype_isdn); 76 REQUIRE(source != NULL); 77 REQUIRE(isdn->common.rdtype == type); 78 REQUIRE(isdn->common.rdclass == rdclass); 79 80 UNUSED(type); 81 UNUSED(rdclass); 82 83 RETERR(uint8_tobuffer(isdn->isdn_len, target)); 84 RETERR(mem_tobuffer(target, isdn->isdn, isdn->isdn_len)); 85 if (isdn->subaddress == NULL) 86 return (ISC_R_SUCCESS); 87 RETERR(uint8_tobuffer(isdn->subaddress_len, target)); 88 return (mem_tobuffer(target, isdn->subaddress, isdn->subaddress_len)); 89} 90 91static inline isc_result_t 92tostruct_isdn(ARGS_TOSTRUCT) { 93 dns_rdata_isdn_t *isdn = target; 94 isc_region_t r; 95 96 REQUIRE(rdata->type == dns_rdatatype_isdn); 97 REQUIRE(target != NULL); 98 REQUIRE(rdata->length != 0); 99 100 isdn->common.rdclass = rdata->rdclass; 101 isdn->common.rdtype = rdata->type; 102 ISC_LINK_INIT(&isdn->common, link); 103 104 dns_rdata_toregion(rdata, &r); 105 106 isdn->isdn_len = uint8_fromregion(&r); 107 isc_region_consume(&r, 1); 108 isdn->isdn = mem_maybedup(r.base, isdn->isdn_len); 109 if (isdn->isdn == NULL) 110 return (ISC_R_NOMEMORY); 111 isc_region_consume(&r, isdn->isdn_len); 112 113 if (r.length == 0) { 114 isdn->subaddress_len = 0; 115 isdn->subaddress = NULL; 116 } else { 117 isdn->subaddress_len = uint8_fromregion(&r); 118 isc_region_consume(&r, 1); 119 isdn->subaddress = mem_maybedup(r.base, 120 isdn->subaddress_len); 121 if (isdn->subaddress == NULL) 122 goto cleanup; 123 } 124 125 return (ISC_R_SUCCESS); 126 127 cleanup: 128 free(isdn->isdn); 129 return (ISC_R_NOMEMORY); 130} 131 132 133 134 135#endif /* RDATA_GENERIC_ISDN_20_C */ 136