1 /* $NetBSD: gpos_27.c,v 1.10 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 /* RFC1712 */ 17 18 #ifndef RDATA_GENERIC_GPOS_27_C 19 #define RDATA_GENERIC_GPOS_27_C 20 21 #define RRTYPE_GPOS_ATTRIBUTES (0) 22 23 static isc_result_t 24 fromtext_gpos(ARGS_FROMTEXT) { 25 isc_token_t token; 26 int i; 27 28 REQUIRE(type == dns_rdatatype_gpos); 29 30 UNUSED(type); 31 UNUSED(rdclass); 32 UNUSED(origin); 33 UNUSED(options); 34 UNUSED(callbacks); 35 36 for (i = 0; i < 3; i++) { 37 RETERR(isc_lex_getmastertoken(lexer, &token, 38 isc_tokentype_qstring, false)); 39 RETTOK(txt_fromtext(&token.value.as_textregion, target)); 40 } 41 return ISC_R_SUCCESS; 42 } 43 44 static isc_result_t 45 totext_gpos(ARGS_TOTEXT) { 46 isc_region_t region; 47 int i; 48 49 REQUIRE(rdata->type == dns_rdatatype_gpos); 50 REQUIRE(rdata->length != 0); 51 52 UNUSED(tctx); 53 54 dns_rdata_toregion(rdata, ®ion); 55 56 for (i = 0; i < 3; i++) { 57 RETERR(txt_totext(®ion, true, target)); 58 if (i != 2) { 59 RETERR(str_totext(" ", target)); 60 } 61 } 62 63 return ISC_R_SUCCESS; 64 } 65 66 static isc_result_t 67 fromwire_gpos(ARGS_FROMWIRE) { 68 int i; 69 70 REQUIRE(type == dns_rdatatype_gpos); 71 72 UNUSED(type); 73 UNUSED(dctx); 74 UNUSED(rdclass); 75 76 for (i = 0; i < 3; i++) { 77 RETERR(txt_fromwire(source, target)); 78 } 79 return ISC_R_SUCCESS; 80 } 81 82 static isc_result_t 83 towire_gpos(ARGS_TOWIRE) { 84 REQUIRE(rdata->type == dns_rdatatype_gpos); 85 REQUIRE(rdata->length != 0); 86 87 UNUSED(cctx); 88 89 return mem_tobuffer(target, rdata->data, rdata->length); 90 } 91 92 static int 93 compare_gpos(ARGS_COMPARE) { 94 isc_region_t r1; 95 isc_region_t r2; 96 97 REQUIRE(rdata1->type == rdata2->type); 98 REQUIRE(rdata1->rdclass == rdata2->rdclass); 99 REQUIRE(rdata1->type == dns_rdatatype_gpos); 100 REQUIRE(rdata1->length != 0); 101 REQUIRE(rdata2->length != 0); 102 103 dns_rdata_toregion(rdata1, &r1); 104 dns_rdata_toregion(rdata2, &r2); 105 return isc_region_compare(&r1, &r2); 106 } 107 108 static isc_result_t 109 fromstruct_gpos(ARGS_FROMSTRUCT) { 110 dns_rdata_gpos_t *gpos = source; 111 112 REQUIRE(type == dns_rdatatype_gpos); 113 REQUIRE(gpos != NULL); 114 REQUIRE(gpos->common.rdtype == type); 115 REQUIRE(gpos->common.rdclass == rdclass); 116 117 UNUSED(type); 118 UNUSED(rdclass); 119 120 RETERR(uint8_tobuffer(gpos->long_len, target)); 121 RETERR(mem_tobuffer(target, gpos->longitude, gpos->long_len)); 122 RETERR(uint8_tobuffer(gpos->lat_len, target)); 123 RETERR(mem_tobuffer(target, gpos->latitude, gpos->lat_len)); 124 RETERR(uint8_tobuffer(gpos->alt_len, target)); 125 return mem_tobuffer(target, gpos->altitude, gpos->alt_len); 126 } 127 128 static isc_result_t 129 tostruct_gpos(ARGS_TOSTRUCT) { 130 dns_rdata_gpos_t *gpos = target; 131 isc_region_t region; 132 133 REQUIRE(rdata->type == dns_rdatatype_gpos); 134 REQUIRE(gpos != NULL); 135 REQUIRE(rdata->length != 0); 136 137 DNS_RDATACOMMON_INIT(gpos, rdata->type, rdata->rdclass); 138 139 dns_rdata_toregion(rdata, ®ion); 140 gpos->long_len = uint8_fromregion(®ion); 141 isc_region_consume(®ion, 1); 142 gpos->longitude = mem_maybedup(mctx, region.base, gpos->long_len); 143 isc_region_consume(®ion, gpos->long_len); 144 145 gpos->lat_len = uint8_fromregion(®ion); 146 isc_region_consume(®ion, 1); 147 gpos->latitude = mem_maybedup(mctx, region.base, gpos->lat_len); 148 isc_region_consume(®ion, gpos->lat_len); 149 150 gpos->alt_len = uint8_fromregion(®ion); 151 isc_region_consume(®ion, 1); 152 if (gpos->lat_len > 0) { 153 gpos->altitude = mem_maybedup(mctx, region.base, gpos->alt_len); 154 } else { 155 gpos->altitude = NULL; 156 } 157 158 gpos->mctx = mctx; 159 return ISC_R_SUCCESS; 160 } 161 162 static void 163 freestruct_gpos(ARGS_FREESTRUCT) { 164 dns_rdata_gpos_t *gpos = source; 165 166 REQUIRE(gpos != NULL); 167 REQUIRE(gpos->common.rdtype == dns_rdatatype_gpos); 168 169 if (gpos->mctx == NULL) { 170 return; 171 } 172 173 if (gpos->longitude != NULL) { 174 isc_mem_free(gpos->mctx, gpos->longitude); 175 } 176 if (gpos->latitude != NULL) { 177 isc_mem_free(gpos->mctx, gpos->latitude); 178 } 179 if (gpos->altitude != NULL) { 180 isc_mem_free(gpos->mctx, gpos->altitude); 181 } 182 gpos->mctx = NULL; 183 } 184 185 static isc_result_t 186 additionaldata_gpos(ARGS_ADDLDATA) { 187 REQUIRE(rdata->type == dns_rdatatype_gpos); 188 189 UNUSED(rdata); 190 UNUSED(owner); 191 UNUSED(add); 192 UNUSED(arg); 193 194 return ISC_R_SUCCESS; 195 } 196 197 static isc_result_t 198 digest_gpos(ARGS_DIGEST) { 199 isc_region_t r; 200 201 REQUIRE(rdata->type == dns_rdatatype_gpos); 202 203 dns_rdata_toregion(rdata, &r); 204 205 return (digest)(arg, &r); 206 } 207 208 static bool 209 checkowner_gpos(ARGS_CHECKOWNER) { 210 REQUIRE(type == dns_rdatatype_gpos); 211 212 UNUSED(name); 213 UNUSED(type); 214 UNUSED(rdclass); 215 UNUSED(wildcard); 216 217 return true; 218 } 219 220 static bool 221 checknames_gpos(ARGS_CHECKNAMES) { 222 REQUIRE(rdata->type == dns_rdatatype_gpos); 223 224 UNUSED(rdata); 225 UNUSED(owner); 226 UNUSED(bad); 227 228 return true; 229 } 230 231 static int 232 casecompare_gpos(ARGS_COMPARE) { 233 return compare_gpos(rdata1, rdata2); 234 } 235 236 #endif /* RDATA_GENERIC_GPOS_27_C */ 237