Home | History | Annotate | Line # | Download | only in generic
      1 /*	$NetBSD: isdn_20.c,v 1.11 2026/01/29 18:37:52 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, &region);
     63 	RETERR(txt_totext(&region, true, target));
     64 	if (region.length == 0) {
     65 		return ISC_R_SUCCESS;
     66 	}
     67 	RETERR(str_totext(" ", target));
     68 	return txt_totext(&region, 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 
     79 	RETERR(txt_fromwire(source, target));
     80 	if (buffer_empty(source)) {
     81 		return ISC_R_SUCCESS;
     82 	}
     83 	return txt_fromwire(source, target);
     84 }
     85 
     86 static isc_result_t
     87 towire_isdn(ARGS_TOWIRE) {
     88 	UNUSED(cctx);
     89 
     90 	REQUIRE(rdata->type == dns_rdatatype_isdn);
     91 	REQUIRE(rdata->length != 0);
     92 
     93 	return mem_tobuffer(target, rdata->data, rdata->length);
     94 }
     95 
     96 static int
     97 compare_isdn(ARGS_COMPARE) {
     98 	isc_region_t r1;
     99 	isc_region_t r2;
    100 
    101 	REQUIRE(rdata1->type == rdata2->type);
    102 	REQUIRE(rdata1->rdclass == rdata2->rdclass);
    103 	REQUIRE(rdata1->type == dns_rdatatype_isdn);
    104 	REQUIRE(rdata1->length != 0);
    105 	REQUIRE(rdata2->length != 0);
    106 
    107 	dns_rdata_toregion(rdata1, &r1);
    108 	dns_rdata_toregion(rdata2, &r2);
    109 	return isc_region_compare(&r1, &r2);
    110 }
    111 
    112 static isc_result_t
    113 fromstruct_isdn(ARGS_FROMSTRUCT) {
    114 	dns_rdata_isdn_t *isdn = source;
    115 
    116 	REQUIRE(type == dns_rdatatype_isdn);
    117 	REQUIRE(isdn != NULL);
    118 	REQUIRE(isdn->common.rdtype == type);
    119 	REQUIRE(isdn->common.rdclass == rdclass);
    120 
    121 	UNUSED(type);
    122 	UNUSED(rdclass);
    123 
    124 	RETERR(uint8_tobuffer(isdn->isdn_len, target));
    125 	RETERR(mem_tobuffer(target, isdn->isdn, isdn->isdn_len));
    126 	if (isdn->subaddress == NULL) {
    127 		return ISC_R_SUCCESS;
    128 	}
    129 	RETERR(uint8_tobuffer(isdn->subaddress_len, target));
    130 	return mem_tobuffer(target, isdn->subaddress, isdn->subaddress_len);
    131 }
    132 
    133 static isc_result_t
    134 tostruct_isdn(ARGS_TOSTRUCT) {
    135 	dns_rdata_isdn_t *isdn = target;
    136 	isc_region_t r;
    137 
    138 	REQUIRE(rdata->type == dns_rdatatype_isdn);
    139 	REQUIRE(isdn != NULL);
    140 	REQUIRE(rdata->length != 0);
    141 
    142 	DNS_RDATACOMMON_INIT(isdn, rdata->type, rdata->rdclass);
    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 	isc_region_consume(&r, isdn->isdn_len);
    150 
    151 	if (r.length == 0) {
    152 		isdn->subaddress_len = 0;
    153 		isdn->subaddress = NULL;
    154 	} else {
    155 		isdn->subaddress_len = uint8_fromregion(&r);
    156 		isc_region_consume(&r, 1);
    157 		isdn->subaddress = mem_maybedup(mctx, r.base,
    158 						isdn->subaddress_len);
    159 	}
    160 
    161 	isdn->mctx = mctx;
    162 	return ISC_R_SUCCESS;
    163 }
    164 
    165 static void
    166 freestruct_isdn(ARGS_FREESTRUCT) {
    167 	dns_rdata_isdn_t *isdn = source;
    168 
    169 	REQUIRE(isdn != NULL);
    170 
    171 	if (isdn->mctx == NULL) {
    172 		return;
    173 	}
    174 
    175 	if (isdn->isdn != NULL) {
    176 		isc_mem_free(isdn->mctx, isdn->isdn);
    177 	}
    178 	if (isdn->subaddress != NULL) {
    179 		isc_mem_free(isdn->mctx, isdn->subaddress);
    180 	}
    181 	isdn->mctx = NULL;
    182 }
    183 
    184 static isc_result_t
    185 additionaldata_isdn(ARGS_ADDLDATA) {
    186 	REQUIRE(rdata->type == dns_rdatatype_isdn);
    187 
    188 	UNUSED(rdata);
    189 	UNUSED(owner);
    190 	UNUSED(add);
    191 	UNUSED(arg);
    192 
    193 	return ISC_R_SUCCESS;
    194 }
    195 
    196 static isc_result_t
    197 digest_isdn(ARGS_DIGEST) {
    198 	isc_region_t r;
    199 
    200 	REQUIRE(rdata->type == dns_rdatatype_isdn);
    201 
    202 	dns_rdata_toregion(rdata, &r);
    203 
    204 	return (digest)(arg, &r);
    205 }
    206 
    207 static bool
    208 checkowner_isdn(ARGS_CHECKOWNER) {
    209 	REQUIRE(type == dns_rdatatype_isdn);
    210 
    211 	UNUSED(name);
    212 	UNUSED(type);
    213 	UNUSED(rdclass);
    214 	UNUSED(wildcard);
    215 
    216 	return true;
    217 }
    218 
    219 static bool
    220 checknames_isdn(ARGS_CHECKNAMES) {
    221 	REQUIRE(rdata->type == dns_rdatatype_isdn);
    222 
    223 	UNUSED(rdata);
    224 	UNUSED(owner);
    225 	UNUSED(bad);
    226 
    227 	return true;
    228 }
    229 
    230 static int
    231 casecompare_isdn(ARGS_COMPARE) {
    232 	return compare_isdn(rdata1, rdata2);
    233 }
    234 
    235 #endif /* RDATA_GENERIC_ISDN_20_C */
    236