gpos_27.c revision 1.5
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.5 2020/02/24 12:06:51 florian 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 76 77static inline isc_result_t 78fromstruct_gpos(ARGS_FROMSTRUCT) { 79 dns_rdata_gpos_t *gpos = source; 80 81 REQUIRE(type == dns_rdatatype_gpos); 82 REQUIRE(source != NULL); 83 REQUIRE(gpos->common.rdtype == type); 84 REQUIRE(gpos->common.rdclass == rdclass); 85 86 UNUSED(type); 87 UNUSED(rdclass); 88 89 RETERR(uint8_tobuffer(gpos->long_len, target)); 90 RETERR(mem_tobuffer(target, gpos->longitude, gpos->long_len)); 91 RETERR(uint8_tobuffer(gpos->lat_len, target)); 92 RETERR(mem_tobuffer(target, gpos->latitude, gpos->lat_len)); 93 RETERR(uint8_tobuffer(gpos->alt_len, target)); 94 return (mem_tobuffer(target, gpos->altitude, gpos->alt_len)); 95} 96 97static inline isc_result_t 98tostruct_gpos(ARGS_TOSTRUCT) { 99 dns_rdata_gpos_t *gpos = target; 100 isc_region_t region; 101 102 REQUIRE(rdata->type == dns_rdatatype_gpos); 103 REQUIRE(target != NULL); 104 REQUIRE(rdata->length != 0); 105 106 gpos->common.rdclass = rdata->rdclass; 107 gpos->common.rdtype = rdata->type; 108 ISC_LINK_INIT(&gpos->common, link); 109 110 dns_rdata_toregion(rdata, ®ion); 111 gpos->long_len = uint8_fromregion(®ion); 112 isc_region_consume(®ion, 1); 113 gpos->longitude = mem_maybedup(region.base, gpos->long_len); 114 if (gpos->longitude == NULL) 115 return (ISC_R_NOMEMORY); 116 isc_region_consume(®ion, gpos->long_len); 117 118 gpos->lat_len = uint8_fromregion(®ion); 119 isc_region_consume(®ion, 1); 120 gpos->latitude = mem_maybedup(region.base, gpos->lat_len); 121 if (gpos->latitude == NULL) 122 goto cleanup_longitude; 123 isc_region_consume(®ion, gpos->lat_len); 124 125 gpos->alt_len = uint8_fromregion(®ion); 126 isc_region_consume(®ion, 1); 127 if (gpos->lat_len > 0) { 128 gpos->altitude = 129 mem_maybedup(region.base, gpos->alt_len); 130 if (gpos->altitude == NULL) 131 goto cleanup_latitude; 132 } else 133 gpos->altitude = NULL; 134 135 return (ISC_R_SUCCESS); 136 137 cleanup_latitude: 138 free(gpos->longitude); 139 140 cleanup_longitude: 141 free(gpos->latitude); 142 return (ISC_R_NOMEMORY); 143} 144 145static inline void 146freestruct_gpos(ARGS_FREESTRUCT) { 147 dns_rdata_gpos_t *gpos = source; 148 149 REQUIRE(source != NULL); 150 REQUIRE(gpos->common.rdtype == dns_rdatatype_gpos); 151 152 153 free(gpos->longitude); 154 free(gpos->latitude); 155 free(gpos->altitude); 156} 157 158 159 160#endif /* RDATA_GENERIC_GPOS_27_C */ 161