Home | History | Annotate | Line # | Download | only in generic
      1 /*	$NetBSD: hhit_67.c,v 1.3 2026/04/08 00:16:15 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 #ifndef RDATA_GENERIC_HHIT_67_C
     17 #define RDATA_GENERIC_HHIT_67_C
     18 
     19 #include <dst/dst.h>
     20 
     21 #define RRTYPE_HHIT_ATTRIBUTES (0)
     22 
     23 static isc_result_t
     24 fromtext_hhit(ARGS_FROMTEXT) {
     25 	REQUIRE(type == dns_rdatatype_hhit);
     26 
     27 	UNUSED(type);
     28 	UNUSED(rdclass);
     29 	UNUSED(origin);
     30 	UNUSED(options);
     31 	UNUSED(callbacks);
     32 
     33 	return isc_base64_tobuffer(lexer, target, isc_one_or_more);
     34 }
     35 
     36 static isc_result_t
     37 totext_hhit(ARGS_TOTEXT) {
     38 	isc_region_t sr;
     39 
     40 	REQUIRE(rdata->type == dns_rdatatype_hhit);
     41 	REQUIRE(rdata->length > 0);
     42 
     43 	dns_rdata_toregion(rdata, &sr);
     44 
     45 	/* data */
     46 	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
     47 		RETERR(str_totext(" (", target));
     48 	}
     49 
     50 	if (tctx->width == 0) { /* No splitting */
     51 		RETERR(isc_base64_totext(&sr, 60, "", target));
     52 	} else {
     53 		RETERR(isc_base64_totext(&sr, tctx->width - 2, tctx->linebreak,
     54 					 target));
     55 	}
     56 
     57 	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
     58 		RETERR(str_totext(" )", target));
     59 	}
     60 
     61 	return ISC_R_SUCCESS;
     62 }
     63 
     64 static isc_result_t
     65 fromwire_hhit(ARGS_FROMWIRE) {
     66 	isc_region_t sr;
     67 
     68 	REQUIRE(type == dns_rdatatype_hhit);
     69 
     70 	UNUSED(type);
     71 	UNUSED(rdclass);
     72 	UNUSED(dctx);
     73 
     74 	isc_buffer_activeregion(source, &sr);
     75 	if (sr.length == 0) {
     76 		return ISC_R_UNEXPECTEDEND;
     77 	}
     78 
     79 	RETERR(mem_tobuffer(target, sr.base, sr.length));
     80 	isc_buffer_forward(source, sr.length);
     81 	return ISC_R_SUCCESS;
     82 }
     83 
     84 static isc_result_t
     85 towire_hhit(ARGS_TOWIRE) {
     86 	REQUIRE(rdata->type == dns_rdatatype_hhit);
     87 	REQUIRE(rdata->length > 0);
     88 
     89 	UNUSED(cctx);
     90 
     91 	return mem_tobuffer(target, rdata->data, rdata->length);
     92 }
     93 
     94 static int
     95 compare_hhit(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_hhit);
    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 isc_result_t
    111 fromstruct_hhit(ARGS_FROMSTRUCT) {
    112 	dns_rdata_hhit_t *hhit = source;
    113 
    114 	REQUIRE(type == dns_rdatatype_hhit);
    115 	REQUIRE(hhit != NULL);
    116 	REQUIRE(hhit->common.rdtype == type);
    117 	REQUIRE(hhit->common.rdclass == rdclass);
    118 
    119 	UNUSED(type);
    120 	UNUSED(rdclass);
    121 
    122 	/* Data */
    123 	return mem_tobuffer(target, hhit->data, hhit->datalen);
    124 }
    125 
    126 static isc_result_t
    127 tostruct_hhit(ARGS_TOSTRUCT) {
    128 	dns_rdata_hhit_t *hhit = target;
    129 	isc_region_t sr;
    130 
    131 	REQUIRE(rdata->type == dns_rdatatype_hhit);
    132 	REQUIRE(hhit != NULL);
    133 	REQUIRE(rdata->length > 0);
    134 
    135 	DNS_RDATACOMMON_INIT(hhit, rdata->type, rdata->rdclass);
    136 
    137 	dns_rdata_toregion(rdata, &sr);
    138 
    139 	/* Data */
    140 	hhit->datalen = sr.length;
    141 	hhit->data = mem_maybedup(mctx, sr.base, hhit->datalen);
    142 	hhit->mctx = mctx;
    143 	return ISC_R_SUCCESS;
    144 }
    145 
    146 static void
    147 freestruct_hhit(ARGS_FREESTRUCT) {
    148 	dns_rdata_hhit_t *hhit = (dns_rdata_hhit_t *)source;
    149 
    150 	REQUIRE(hhit != NULL);
    151 	REQUIRE(hhit->common.rdtype == dns_rdatatype_hhit);
    152 
    153 	if (hhit->mctx == NULL) {
    154 		return;
    155 	}
    156 
    157 	if (hhit->data != NULL) {
    158 		isc_mem_free(hhit->mctx, hhit->data);
    159 	}
    160 	hhit->mctx = NULL;
    161 }
    162 
    163 static isc_result_t
    164 additionaldata_hhit(ARGS_ADDLDATA) {
    165 	REQUIRE(rdata->type == dns_rdatatype_hhit);
    166 
    167 	UNUSED(rdata);
    168 	UNUSED(owner);
    169 	UNUSED(add);
    170 	UNUSED(arg);
    171 
    172 	return ISC_R_SUCCESS;
    173 }
    174 
    175 static isc_result_t
    176 digest_hhit(ARGS_DIGEST) {
    177 	isc_region_t r;
    178 
    179 	REQUIRE(rdata->type == dns_rdatatype_hhit);
    180 
    181 	dns_rdata_toregion(rdata, &r);
    182 
    183 	return (digest)(arg, &r);
    184 }
    185 
    186 static bool
    187 checkowner_hhit(ARGS_CHECKOWNER) {
    188 	REQUIRE(type == dns_rdatatype_hhit);
    189 
    190 	UNUSED(name);
    191 	UNUSED(type);
    192 	UNUSED(rdclass);
    193 	UNUSED(wildcard);
    194 
    195 	return true;
    196 }
    197 
    198 static bool
    199 checknames_hhit(ARGS_CHECKNAMES) {
    200 	REQUIRE(rdata->type == dns_rdatatype_hhit);
    201 
    202 	UNUSED(rdata);
    203 	UNUSED(owner);
    204 	UNUSED(bad);
    205 
    206 	return true;
    207 }
    208 
    209 static int
    210 casecompare_hhit(ARGS_COMPARE) {
    211 	return compare_hhit(rdata1, rdata2);
    212 }
    213 #endif /* RDATA_GENERIC_HHIT_67_C */
    214