2 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2002 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: gpos_27.c,v 1.41 2007/06/19 23:47:17 tbox Exp $ */
20 /* reviewed: Wed Mar 15 16:48:45 PST 2000 by brister */
24 #ifndef RDATA_GENERIC_GPOS_27_C
25 #define RDATA_GENERIC_GPOS_27_C
27 #define RRTYPE_GPOS_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_gpos(ARGS_FROMTEXT) {
42 for (i = 0; i < 3; i++) {
43 RETERR(isc_lex_getmastertoken(lexer, &token,
44 isc_tokentype_qstring,
46 RETTOK(txt_fromtext(&token.value.as_textregion, target));
48 return (ISC_R_SUCCESS);
51 static inline isc_result_t
52 totext_gpos(ARGS_TOTEXT) {
56 REQUIRE(rdata->type == 27);
57 REQUIRE(rdata->length != 0);
61 dns_rdata_toregion(rdata, ®ion);
63 for (i = 0; i < 3; i++) {
64 RETERR(txt_totext(®ion, target));
66 RETERR(str_totext(" ", target));
69 return (ISC_R_SUCCESS);
72 static inline isc_result_t
73 fromwire_gpos(ARGS_FROMWIRE) {
83 for (i = 0; i < 3; i++)
84 RETERR(txt_fromwire(source, target));
85 return (ISC_R_SUCCESS);
88 static inline isc_result_t
89 towire_gpos(ARGS_TOWIRE) {
91 REQUIRE(rdata->type == 27);
92 REQUIRE(rdata->length != 0);
96 return (mem_tobuffer(target, rdata->data, rdata->length));
100 compare_gpos(ARGS_COMPARE) {
104 REQUIRE(rdata1->type == rdata2->type);
105 REQUIRE(rdata1->rdclass == rdata2->rdclass);
106 REQUIRE(rdata1->type == 27);
107 REQUIRE(rdata1->length != 0);
108 REQUIRE(rdata2->length != 0);
110 dns_rdata_toregion(rdata1, &r1);
111 dns_rdata_toregion(rdata2, &r2);
112 return (isc_region_compare(&r1, &r2));
115 static inline isc_result_t
116 fromstruct_gpos(ARGS_FROMSTRUCT) {
117 dns_rdata_gpos_t *gpos = source;
120 REQUIRE(source != NULL);
121 REQUIRE(gpos->common.rdtype == type);
122 REQUIRE(gpos->common.rdclass == rdclass);
127 RETERR(uint8_tobuffer(gpos->long_len, target));
128 RETERR(mem_tobuffer(target, gpos->longitude, gpos->long_len));
129 RETERR(uint8_tobuffer(gpos->lat_len, target));
130 RETERR(mem_tobuffer(target, gpos->latitude, gpos->lat_len));
131 RETERR(uint8_tobuffer(gpos->alt_len, target));
132 return (mem_tobuffer(target, gpos->altitude, gpos->alt_len));
135 static inline isc_result_t
136 tostruct_gpos(ARGS_TOSTRUCT) {
137 dns_rdata_gpos_t *gpos = target;
140 REQUIRE(rdata->type == 27);
141 REQUIRE(target != NULL);
142 REQUIRE(rdata->length != 0);
144 gpos->common.rdclass = rdata->rdclass;
145 gpos->common.rdtype = rdata->type;
146 ISC_LINK_INIT(&gpos->common, link);
148 dns_rdata_toregion(rdata, ®ion);
149 gpos->long_len = uint8_fromregion(®ion);
150 isc_region_consume(®ion, 1);
151 gpos->longitude = mem_maybedup(mctx, region.base, gpos->long_len);
152 if (gpos->longitude == NULL)
153 return (ISC_R_NOMEMORY);
154 isc_region_consume(®ion, gpos->long_len);
156 gpos->lat_len = uint8_fromregion(®ion);
157 isc_region_consume(®ion, 1);
158 gpos->latitude = mem_maybedup(mctx, region.base, gpos->lat_len);
159 if (gpos->latitude == NULL)
160 goto cleanup_longitude;
161 isc_region_consume(®ion, gpos->lat_len);
163 gpos->alt_len = uint8_fromregion(®ion);
164 isc_region_consume(®ion, 1);
165 if (gpos->lat_len > 0) {
167 mem_maybedup(mctx, region.base, gpos->alt_len);
168 if (gpos->altitude == NULL)
169 goto cleanup_latitude;
171 gpos->altitude = NULL;
174 return (ISC_R_SUCCESS);
177 if (mctx != NULL && gpos->longitude != NULL)
178 isc_mem_free(mctx, gpos->longitude);
181 if (mctx != NULL && gpos->latitude != NULL)
182 isc_mem_free(mctx, gpos->latitude);
183 return (ISC_R_NOMEMORY);
187 freestruct_gpos(ARGS_FREESTRUCT) {
188 dns_rdata_gpos_t *gpos = source;
190 REQUIRE(source != NULL);
191 REQUIRE(gpos->common.rdtype == 27);
193 if (gpos->mctx == NULL)
196 if (gpos->longitude != NULL)
197 isc_mem_free(gpos->mctx, gpos->longitude);
198 if (gpos->latitude != NULL)
199 isc_mem_free(gpos->mctx, gpos->latitude);
200 if (gpos->altitude != NULL)
201 isc_mem_free(gpos->mctx, gpos->altitude);
205 static inline isc_result_t
206 additionaldata_gpos(ARGS_ADDLDATA) {
207 REQUIRE(rdata->type == 27);
213 return (ISC_R_SUCCESS);
216 static inline isc_result_t
217 digest_gpos(ARGS_DIGEST) {
220 REQUIRE(rdata->type == 27);
222 dns_rdata_toregion(rdata, &r);
224 return ((digest)(arg, &r));
227 static inline isc_boolean_t
228 checkowner_gpos(ARGS_CHECKOWNER) {
240 static inline isc_boolean_t
241 checknames_gpos(ARGS_CHECKNAMES) {
243 REQUIRE(rdata->type == 27);
252 #endif /* RDATA_GENERIC_GPOS_27_C */