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