1 /* $NetBSD: gpos_27.c,v 1.4 2014/12/10 04:37:59 christos Exp $ */
2
3 /*
4 * Copyright (C) 2004, 2005, 2007, 2009, 2014 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2002 Internet Software Consortium.
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 */
19
20 /* Id: gpos_27.c,v 1.43 2009/12/04 22:06:37 tbox Exp */
21
22 /* reviewed: Wed Mar 15 16:48:45 PST 2000 by brister */
23
24 /* RFC1712 */
25
26 #ifndef RDATA_GENERIC_GPOS_27_C
27 #define RDATA_GENERIC_GPOS_27_C
28
29 #define RRTYPE_GPOS_ATTRIBUTES (0)
30
31 static inline isc_result_t
fromtext_gpos(ARGS_FROMTEXT)32 fromtext_gpos(ARGS_FROMTEXT) {
33 isc_token_t token;
34 int i;
35
36 REQUIRE(type == 27);
37
38 UNUSED(type);
39 UNUSED(rdclass);
40 UNUSED(origin);
41 UNUSED(options);
42 UNUSED(callbacks);
43
44 for (i = 0; i < 3; i++) {
45 RETERR(isc_lex_getmastertoken(lexer, &token,
46 isc_tokentype_qstring,
47 ISC_FALSE));
48 RETTOK(txt_fromtext(&token.value.as_textregion, target));
49 }
50 return (ISC_R_SUCCESS);
51 }
52
53 static inline isc_result_t
totext_gpos(ARGS_TOTEXT)54 totext_gpos(ARGS_TOTEXT) {
55 isc_region_t region;
56 int i;
57
58 REQUIRE(rdata->type == 27);
59 REQUIRE(rdata->length != 0);
60
61 UNUSED(tctx);
62
63 dns_rdata_toregion(rdata, ®ion);
64
65 for (i = 0; i < 3; i++) {
66 RETERR(txt_totext(®ion, ISC_TRUE, target));
67 if (i != 2)
68 RETERR(str_totext(" ", target));
69 }
70
71 return (ISC_R_SUCCESS);
72 }
73
74 static inline isc_result_t
fromwire_gpos(ARGS_FROMWIRE)75 fromwire_gpos(ARGS_FROMWIRE) {
76 int i;
77
78 REQUIRE(type == 27);
79
80 UNUSED(type);
81 UNUSED(dctx);
82 UNUSED(rdclass);
83 UNUSED(options);
84
85 for (i = 0; i < 3; i++)
86 RETERR(txt_fromwire(source, target));
87 return (ISC_R_SUCCESS);
88 }
89
90 static inline isc_result_t
towire_gpos(ARGS_TOWIRE)91 towire_gpos(ARGS_TOWIRE) {
92
93 REQUIRE(rdata->type == 27);
94 REQUIRE(rdata->length != 0);
95
96 UNUSED(cctx);
97
98 return (mem_tobuffer(target, rdata->data, rdata->length));
99 }
100
101 static inline int
compare_gpos(ARGS_COMPARE)102 compare_gpos(ARGS_COMPARE) {
103 isc_region_t r1;
104 isc_region_t r2;
105
106 REQUIRE(rdata1->type == rdata2->type);
107 REQUIRE(rdata1->rdclass == rdata2->rdclass);
108 REQUIRE(rdata1->type == 27);
109 REQUIRE(rdata1->length != 0);
110 REQUIRE(rdata2->length != 0);
111
112 dns_rdata_toregion(rdata1, &r1);
113 dns_rdata_toregion(rdata2, &r2);
114 return (isc_region_compare(&r1, &r2));
115 }
116
117 static inline isc_result_t
fromstruct_gpos(ARGS_FROMSTRUCT)118 fromstruct_gpos(ARGS_FROMSTRUCT) {
119 dns_rdata_gpos_t *gpos = source;
120
121 REQUIRE(type == 27);
122 REQUIRE(source != NULL);
123 REQUIRE(gpos->common.rdtype == type);
124 REQUIRE(gpos->common.rdclass == rdclass);
125
126 UNUSED(type);
127 UNUSED(rdclass);
128
129 RETERR(uint8_tobuffer(gpos->long_len, target));
130 RETERR(mem_tobuffer(target, gpos->longitude, gpos->long_len));
131 RETERR(uint8_tobuffer(gpos->lat_len, target));
132 RETERR(mem_tobuffer(target, gpos->latitude, gpos->lat_len));
133 RETERR(uint8_tobuffer(gpos->alt_len, target));
134 return (mem_tobuffer(target, gpos->altitude, gpos->alt_len));
135 }
136
137 static inline isc_result_t
tostruct_gpos(ARGS_TOSTRUCT)138 tostruct_gpos(ARGS_TOSTRUCT) {
139 dns_rdata_gpos_t *gpos = target;
140 isc_region_t region;
141
142 REQUIRE(rdata->type == 27);
143 REQUIRE(target != NULL);
144 REQUIRE(rdata->length != 0);
145
146 gpos->common.rdclass = rdata->rdclass;
147 gpos->common.rdtype = rdata->type;
148 ISC_LINK_INIT(&gpos->common, link);
149
150 dns_rdata_toregion(rdata, ®ion);
151 gpos->long_len = uint8_fromregion(®ion);
152 isc_region_consume(®ion, 1);
153 gpos->longitude = mem_maybedup(mctx, region.base, gpos->long_len);
154 if (gpos->longitude == NULL)
155 return (ISC_R_NOMEMORY);
156 isc_region_consume(®ion, gpos->long_len);
157
158 gpos->lat_len = uint8_fromregion(®ion);
159 isc_region_consume(®ion, 1);
160 gpos->latitude = mem_maybedup(mctx, region.base, gpos->lat_len);
161 if (gpos->latitude == NULL)
162 goto cleanup_longitude;
163 isc_region_consume(®ion, gpos->lat_len);
164
165 gpos->alt_len = uint8_fromregion(®ion);
166 isc_region_consume(®ion, 1);
167 if (gpos->lat_len > 0) {
168 gpos->altitude =
169 mem_maybedup(mctx, region.base, gpos->alt_len);
170 if (gpos->altitude == NULL)
171 goto cleanup_latitude;
172 } else
173 gpos->altitude = NULL;
174
175 gpos->mctx = mctx;
176 return (ISC_R_SUCCESS);
177
178 cleanup_latitude:
179 if (mctx != NULL && gpos->longitude != NULL)
180 isc_mem_free(mctx, gpos->longitude);
181
182 cleanup_longitude:
183 if (mctx != NULL && gpos->latitude != NULL)
184 isc_mem_free(mctx, gpos->latitude);
185 return (ISC_R_NOMEMORY);
186 }
187
188 static inline void
freestruct_gpos(ARGS_FREESTRUCT)189 freestruct_gpos(ARGS_FREESTRUCT) {
190 dns_rdata_gpos_t *gpos = source;
191
192 REQUIRE(source != NULL);
193 REQUIRE(gpos->common.rdtype == 27);
194
195 if (gpos->mctx == NULL)
196 return;
197
198 if (gpos->longitude != NULL)
199 isc_mem_free(gpos->mctx, gpos->longitude);
200 if (gpos->latitude != NULL)
201 isc_mem_free(gpos->mctx, gpos->latitude);
202 if (gpos->altitude != NULL)
203 isc_mem_free(gpos->mctx, gpos->altitude);
204 gpos->mctx = NULL;
205 }
206
207 static inline isc_result_t
additionaldata_gpos(ARGS_ADDLDATA)208 additionaldata_gpos(ARGS_ADDLDATA) {
209 REQUIRE(rdata->type == 27);
210
211 UNUSED(rdata);
212 UNUSED(add);
213 UNUSED(arg);
214
215 return (ISC_R_SUCCESS);
216 }
217
218 static inline isc_result_t
digest_gpos(ARGS_DIGEST)219 digest_gpos(ARGS_DIGEST) {
220 isc_region_t r;
221
222 REQUIRE(rdata->type == 27);
223
224 dns_rdata_toregion(rdata, &r);
225
226 return ((digest)(arg, &r));
227 }
228
229 static inline isc_boolean_t
checkowner_gpos(ARGS_CHECKOWNER)230 checkowner_gpos(ARGS_CHECKOWNER) {
231
232 REQUIRE(type == 27);
233
234 UNUSED(name);
235 UNUSED(type);
236 UNUSED(rdclass);
237 UNUSED(wildcard);
238
239 return (ISC_TRUE);
240 }
241
242 static inline isc_boolean_t
checknames_gpos(ARGS_CHECKNAMES)243 checknames_gpos(ARGS_CHECKNAMES) {
244
245 REQUIRE(rdata->type == 27);
246
247 UNUSED(rdata);
248 UNUSED(owner);
249 UNUSED(bad);
250
251 return (ISC_TRUE);
252 }
253
254 static inline int
casecompare_gpos(ARGS_COMPARE)255 casecompare_gpos(ARGS_COMPARE) {
256 return (compare_gpos(rdata1, rdata2));
257 }
258
259 #endif /* RDATA_GENERIC_GPOS_27_C */
260