1 /* $NetBSD: mb_7.c,v 1.5 2020/05/24 19:46:24 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 http://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 #ifndef RDATA_GENERIC_MB_7_C 15 #define RDATA_GENERIC_MB_7_C 16 17 #define RRTYPE_MB_ATTRIBUTES (0) 18 19 static inline isc_result_t 20 fromtext_mb(ARGS_FROMTEXT) { 21 isc_token_t token; 22 dns_name_t name; 23 isc_buffer_t buffer; 24 25 REQUIRE(type == dns_rdatatype_mb); 26 27 UNUSED(type); 28 UNUSED(rdclass); 29 UNUSED(callbacks); 30 31 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, 32 false)); 33 34 dns_name_init(&name, NULL); 35 buffer_fromregion(&buffer, &token.value.as_region); 36 if (origin == NULL) { 37 origin = dns_rootname; 38 } 39 RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); 40 return (ISC_R_SUCCESS); 41 } 42 43 static inline isc_result_t 44 totext_mb(ARGS_TOTEXT) { 45 isc_region_t region; 46 dns_name_t name; 47 dns_name_t prefix; 48 bool sub; 49 50 REQUIRE(rdata->type == dns_rdatatype_mb); 51 REQUIRE(rdata->length != 0); 52 53 dns_name_init(&name, NULL); 54 dns_name_init(&prefix, NULL); 55 56 dns_rdata_toregion(rdata, ®ion); 57 dns_name_fromregion(&name, ®ion); 58 59 sub = name_prefix(&name, tctx->origin, &prefix); 60 61 return (dns_name_totext(&prefix, sub, target)); 62 } 63 64 static inline isc_result_t 65 fromwire_mb(ARGS_FROMWIRE) { 66 dns_name_t name; 67 68 REQUIRE(type == dns_rdatatype_mb); 69 70 UNUSED(type); 71 UNUSED(rdclass); 72 73 dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14); 74 75 dns_name_init(&name, NULL); 76 return (dns_name_fromwire(&name, source, dctx, options, target)); 77 } 78 79 static inline isc_result_t 80 towire_mb(ARGS_TOWIRE) { 81 dns_name_t name; 82 dns_offsets_t offsets; 83 isc_region_t region; 84 85 REQUIRE(rdata->type == dns_rdatatype_mb); 86 REQUIRE(rdata->length != 0); 87 88 dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); 89 90 dns_name_init(&name, offsets); 91 dns_rdata_toregion(rdata, ®ion); 92 dns_name_fromregion(&name, ®ion); 93 94 return (dns_name_towire(&name, cctx, target)); 95 } 96 97 static inline int 98 compare_mb(ARGS_COMPARE) { 99 dns_name_t name1; 100 dns_name_t name2; 101 isc_region_t region1; 102 isc_region_t region2; 103 104 REQUIRE(rdata1->type == rdata2->type); 105 REQUIRE(rdata1->rdclass == rdata2->rdclass); 106 REQUIRE(rdata1->type == dns_rdatatype_mb); 107 REQUIRE(rdata1->length != 0); 108 REQUIRE(rdata2->length != 0); 109 110 dns_name_init(&name1, NULL); 111 dns_name_init(&name2, NULL); 112 113 dns_rdata_toregion(rdata1, ®ion1); 114 dns_rdata_toregion(rdata2, ®ion2); 115 116 dns_name_fromregion(&name1, ®ion1); 117 dns_name_fromregion(&name2, ®ion2); 118 119 return (dns_name_rdatacompare(&name1, &name2)); 120 } 121 122 static inline isc_result_t 123 fromstruct_mb(ARGS_FROMSTRUCT) { 124 dns_rdata_mb_t *mb = source; 125 isc_region_t region; 126 127 REQUIRE(type == dns_rdatatype_mb); 128 REQUIRE(mb != NULL); 129 REQUIRE(mb->common.rdtype == type); 130 REQUIRE(mb->common.rdclass == rdclass); 131 132 UNUSED(type); 133 UNUSED(rdclass); 134 135 dns_name_toregion(&mb->mb, ®ion); 136 return (isc_buffer_copyregion(target, ®ion)); 137 } 138 139 static inline isc_result_t 140 tostruct_mb(ARGS_TOSTRUCT) { 141 isc_region_t region; 142 dns_rdata_mb_t *mb = target; 143 dns_name_t name; 144 145 REQUIRE(rdata->type == dns_rdatatype_mb); 146 REQUIRE(mb != NULL); 147 REQUIRE(rdata->length != 0); 148 149 mb->common.rdclass = rdata->rdclass; 150 mb->common.rdtype = rdata->type; 151 ISC_LINK_INIT(&mb->common, link); 152 153 dns_name_init(&name, NULL); 154 dns_rdata_toregion(rdata, ®ion); 155 dns_name_fromregion(&name, ®ion); 156 dns_name_init(&mb->mb, NULL); 157 RETERR(name_duporclone(&name, mctx, &mb->mb)); 158 mb->mctx = mctx; 159 return (ISC_R_SUCCESS); 160 } 161 162 static inline void 163 freestruct_mb(ARGS_FREESTRUCT) { 164 dns_rdata_mb_t *mb = source; 165 166 REQUIRE(mb != NULL); 167 168 if (mb->mctx == NULL) { 169 return; 170 } 171 172 dns_name_free(&mb->mb, mb->mctx); 173 mb->mctx = NULL; 174 } 175 176 static inline isc_result_t 177 additionaldata_mb(ARGS_ADDLDATA) { 178 dns_name_t name; 179 dns_offsets_t offsets; 180 isc_region_t region; 181 182 REQUIRE(rdata->type == dns_rdatatype_mb); 183 184 dns_name_init(&name, offsets); 185 dns_rdata_toregion(rdata, ®ion); 186 dns_name_fromregion(&name, ®ion); 187 188 return ((add)(arg, &name, dns_rdatatype_a)); 189 } 190 191 static inline isc_result_t 192 digest_mb(ARGS_DIGEST) { 193 isc_region_t r; 194 dns_name_t name; 195 196 REQUIRE(rdata->type == dns_rdatatype_mb); 197 198 dns_rdata_toregion(rdata, &r); 199 dns_name_init(&name, NULL); 200 dns_name_fromregion(&name, &r); 201 202 return (dns_name_digest(&name, digest, arg)); 203 } 204 205 static inline bool 206 checkowner_mb(ARGS_CHECKOWNER) { 207 REQUIRE(type == dns_rdatatype_mb); 208 209 UNUSED(type); 210 UNUSED(rdclass); 211 UNUSED(wildcard); 212 213 return (dns_name_ismailbox(name)); 214 } 215 216 static inline bool 217 checknames_mb(ARGS_CHECKNAMES) { 218 REQUIRE(rdata->type == dns_rdatatype_mb); 219 220 UNUSED(rdata); 221 UNUSED(owner); 222 UNUSED(bad); 223 224 return (true); 225 } 226 227 static inline int 228 casecompare_mb(ARGS_COMPARE) { 229 return (compare_mb(rdata1, rdata2)); 230 } 231 232 #endif /* RDATA_GENERIC_MB_7_C */ 233