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