gpos_27.c revision 1.3
1/* 2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 * PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17/* $Id: gpos_27.c,v 1.3 2020/02/23 19:54:26 jung Exp $ */ 18 19/* reviewed: Wed Mar 15 16:48:45 PST 2000 by brister */ 20 21/* RFC1712 */ 22 23#ifndef RDATA_GENERIC_GPOS_27_C 24#define RDATA_GENERIC_GPOS_27_C 25 26#define RRTYPE_GPOS_ATTRIBUTES (0) 27 28static inline isc_result_t 29totext_gpos(ARGS_TOTEXT) { 30 isc_region_t region; 31 int i; 32 33 REQUIRE(rdata->type == dns_rdatatype_gpos); 34 REQUIRE(rdata->length != 0); 35 36 UNUSED(tctx); 37 38 dns_rdata_toregion(rdata, ®ion); 39 40 for (i = 0; i < 3; i++) { 41 RETERR(txt_totext(®ion, ISC_TRUE, target)); 42 if (i != 2) 43 RETERR(str_totext(" ", target)); 44 } 45 46 return (ISC_R_SUCCESS); 47} 48 49static inline isc_result_t 50fromwire_gpos(ARGS_FROMWIRE) { 51 int i; 52 53 REQUIRE(type == dns_rdatatype_gpos); 54 55 UNUSED(type); 56 UNUSED(dctx); 57 UNUSED(rdclass); 58 UNUSED(options); 59 60 for (i = 0; i < 3; i++) 61 RETERR(txt_fromwire(source, target)); 62 return (ISC_R_SUCCESS); 63} 64 65static inline isc_result_t 66towire_gpos(ARGS_TOWIRE) { 67 68 REQUIRE(rdata->type == dns_rdatatype_gpos); 69 REQUIRE(rdata->length != 0); 70 71 UNUSED(cctx); 72 73 return (mem_tobuffer(target, rdata->data, rdata->length)); 74} 75 76static inline int 77compare_gpos(ARGS_COMPARE) { 78 isc_region_t r1; 79 isc_region_t r2; 80 81 REQUIRE(rdata1->type == rdata2->type); 82 REQUIRE(rdata1->rdclass == rdata2->rdclass); 83 REQUIRE(rdata1->type == dns_rdatatype_gpos); 84 REQUIRE(rdata1->length != 0); 85 REQUIRE(rdata2->length != 0); 86 87 dns_rdata_toregion(rdata1, &r1); 88 dns_rdata_toregion(rdata2, &r2); 89 return (isc_region_compare(&r1, &r2)); 90} 91 92static inline isc_result_t 93fromstruct_gpos(ARGS_FROMSTRUCT) { 94 dns_rdata_gpos_t *gpos = source; 95 96 REQUIRE(type == dns_rdatatype_gpos); 97 REQUIRE(source != NULL); 98 REQUIRE(gpos->common.rdtype == type); 99 REQUIRE(gpos->common.rdclass == rdclass); 100 101 UNUSED(type); 102 UNUSED(rdclass); 103 104 RETERR(uint8_tobuffer(gpos->long_len, target)); 105 RETERR(mem_tobuffer(target, gpos->longitude, gpos->long_len)); 106 RETERR(uint8_tobuffer(gpos->lat_len, target)); 107 RETERR(mem_tobuffer(target, gpos->latitude, gpos->lat_len)); 108 RETERR(uint8_tobuffer(gpos->alt_len, target)); 109 return (mem_tobuffer(target, gpos->altitude, gpos->alt_len)); 110} 111 112static inline isc_result_t 113tostruct_gpos(ARGS_TOSTRUCT) { 114 dns_rdata_gpos_t *gpos = target; 115 isc_region_t region; 116 117 REQUIRE(rdata->type == dns_rdatatype_gpos); 118 REQUIRE(target != NULL); 119 REQUIRE(rdata->length != 0); 120 121 gpos->common.rdclass = rdata->rdclass; 122 gpos->common.rdtype = rdata->type; 123 ISC_LINK_INIT(&gpos->common, link); 124 125 dns_rdata_toregion(rdata, ®ion); 126 gpos->long_len = uint8_fromregion(®ion); 127 isc_region_consume(®ion, 1); 128 gpos->longitude = mem_maybedup(region.base, gpos->long_len); 129 if (gpos->longitude == NULL) 130 return (ISC_R_NOMEMORY); 131 isc_region_consume(®ion, gpos->long_len); 132 133 gpos->lat_len = uint8_fromregion(®ion); 134 isc_region_consume(®ion, 1); 135 gpos->latitude = mem_maybedup(region.base, gpos->lat_len); 136 if (gpos->latitude == NULL) 137 goto cleanup_longitude; 138 isc_region_consume(®ion, gpos->lat_len); 139 140 gpos->alt_len = uint8_fromregion(®ion); 141 isc_region_consume(®ion, 1); 142 if (gpos->lat_len > 0) { 143 gpos->altitude = 144 mem_maybedup(region.base, gpos->alt_len); 145 if (gpos->altitude == NULL) 146 goto cleanup_latitude; 147 } else 148 gpos->altitude = NULL; 149 150 return (ISC_R_SUCCESS); 151 152 cleanup_latitude: 153 free(gpos->longitude); 154 155 cleanup_longitude: 156 free(gpos->latitude); 157 return (ISC_R_NOMEMORY); 158} 159 160static inline void 161freestruct_gpos(ARGS_FREESTRUCT) { 162 dns_rdata_gpos_t *gpos = source; 163 164 REQUIRE(source != NULL); 165 REQUIRE(gpos->common.rdtype == dns_rdatatype_gpos); 166 167 168 free(gpos->longitude); 169 free(gpos->latitude); 170 free(gpos->altitude); 171} 172 173static inline isc_boolean_t 174checkowner_gpos(ARGS_CHECKOWNER) { 175 176 REQUIRE(type == dns_rdatatype_gpos); 177 178 UNUSED(name); 179 UNUSED(type); 180 UNUSED(rdclass); 181 UNUSED(wildcard); 182 183 return (ISC_TRUE); 184} 185 186static inline int 187casecompare_gpos(ARGS_COMPARE) { 188 return (compare_gpos(rdata1, rdata2)); 189} 190 191#endif /* RDATA_GENERIC_GPOS_27_C */ 192