Add BIND 9.2.4rc7.
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / dns / rdata / generic / gpos_27.c
blob2bc266a29f3d42d607bdb69565886ffca06e01c5
1 /*
2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and 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.32.2.1 2004/03/09 06:11:27 marka Exp $ */
20 /* reviewed: Wed Mar 15 16:48:45 PST 2000 by brister */
22 /* RFC 1712 */
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) {
31 isc_token_t token;
32 int i;
34 REQUIRE(type == 27);
36 UNUSED(type);
37 UNUSED(rdclass);
38 UNUSED(origin);
39 UNUSED(downcase);
40 UNUSED(callbacks);
42 for (i = 0; i < 3 ; i++) {
43 RETERR(isc_lex_getmastertoken(lexer, &token,
44 isc_tokentype_qstring,
45 ISC_FALSE));
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) {
53 isc_region_t region;
54 int i;
56 REQUIRE(rdata->type == 27);
57 REQUIRE(rdata->length != 0);
59 UNUSED(tctx);
61 dns_rdata_toregion(rdata, &region);
63 for (i = 0; i < 3 ; i++) {
64 RETERR(txt_totext(&region, target));
65 if (i != 2)
66 RETERR(str_totext(" ", target));
69 return (ISC_R_SUCCESS);
72 static inline isc_result_t
73 fromwire_gpos(ARGS_FROMWIRE) {
74 int i;
76 REQUIRE(type == 27);
78 UNUSED(type);
79 UNUSED(dctx);
80 UNUSED(rdclass);
81 UNUSED(downcase);
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);
94 UNUSED(cctx);
96 return (mem_tobuffer(target, rdata->data, rdata->length));
99 static inline int
100 compare_gpos(ARGS_COMPARE) {
101 isc_region_t r1;
102 isc_region_t r2;
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 (compare_region(&r1, &r2));
115 static inline isc_result_t
116 fromstruct_gpos(ARGS_FROMSTRUCT) {
117 dns_rdata_gpos_t *gpos = source;
119 REQUIRE(type == 27);
120 REQUIRE(source != NULL);
121 REQUIRE(gpos->common.rdtype == type);
122 REQUIRE(gpos->common.rdclass == rdclass);
124 UNUSED(type);
125 UNUSED(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;
138 isc_region_t region;
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, &region);
149 gpos->long_len = uint8_fromregion(&region);
150 isc_region_consume(&region, 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(&region, gpos->long_len);
156 gpos->lat_len = uint8_fromregion(&region);
157 isc_region_consume(&region, 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(&region, gpos->lat_len);
163 gpos->alt_len = uint8_fromregion(&region);
164 isc_region_consume(&region, 1);
165 if (gpos->lat_len > 0) {
166 gpos->altitude =
167 mem_maybedup(mctx, region.base, gpos->alt_len);
168 if (gpos->altitude == NULL)
169 goto cleanup_latitude;
170 } else
171 gpos->altitude = NULL;
173 gpos->mctx = mctx;
174 return (ISC_R_SUCCESS);
176 cleanup_latitude:
177 if (mctx != NULL && gpos->longitude != NULL)
178 isc_mem_free(mctx, gpos->longitude);
180 cleanup_longitude:
181 if (mctx != NULL && gpos->latitude != NULL)
182 isc_mem_free(mctx, gpos->latitude);
183 return (ISC_R_NOMEMORY);
186 static inline void
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)
194 return;
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);
202 gpos->mctx = NULL;
205 static inline isc_result_t
206 additionaldata_gpos(ARGS_ADDLDATA) {
207 REQUIRE(rdata->type == 27);
209 UNUSED(rdata);
210 UNUSED(add);
211 UNUSED(arg);
213 return (ISC_R_SUCCESS);
216 static inline isc_result_t
217 digest_gpos(ARGS_DIGEST) {
218 isc_region_t r;
220 REQUIRE(rdata->type == 27);
222 dns_rdata_toregion(rdata, &r);
224 return ((digest)(arg, &r));
227 #endif /* RDATA_GENERIC_GPOS_27_C */