gpos_27.c revision 1.1
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.1 2020/02/07 09:58:53 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
29fromtext_gpos(ARGS_FROMTEXT) {
30	isc_token_t token;
31	int i;
32
33	REQUIRE(type == dns_rdatatype_gpos);
34
35	UNUSED(type);
36	UNUSED(rdclass);
37	UNUSED(origin);
38	UNUSED(options);
39	UNUSED(callbacks);
40
41	for (i = 0; i < 3; i++) {
42		RETERR(isc_lex_getmastertoken(lexer, &token,
43					      isc_tokentype_qstring,
44					      ISC_FALSE));
45		RETTOK(txt_fromtext(&token.value.as_textregion, target));
46	}
47	return (ISC_R_SUCCESS);
48}
49
50static inline isc_result_t
51totext_gpos(ARGS_TOTEXT) {
52	isc_region_t region;
53	int i;
54
55	REQUIRE(rdata->type == dns_rdatatype_gpos);
56	REQUIRE(rdata->length != 0);
57
58	UNUSED(tctx);
59
60	dns_rdata_toregion(rdata, &region);
61
62	for (i = 0; i < 3; i++) {
63		RETERR(txt_totext(&region, ISC_TRUE, target));
64		if (i != 2)
65			RETERR(str_totext(" ", target));
66	}
67
68	return (ISC_R_SUCCESS);
69}
70
71static inline isc_result_t
72fromwire_gpos(ARGS_FROMWIRE) {
73	int i;
74
75	REQUIRE(type == dns_rdatatype_gpos);
76
77	UNUSED(type);
78	UNUSED(dctx);
79	UNUSED(rdclass);
80	UNUSED(options);
81
82	for (i = 0; i < 3; i++)
83		RETERR(txt_fromwire(source, target));
84	return (ISC_R_SUCCESS);
85}
86
87static inline isc_result_t
88towire_gpos(ARGS_TOWIRE) {
89
90	REQUIRE(rdata->type == dns_rdatatype_gpos);
91	REQUIRE(rdata->length != 0);
92
93	UNUSED(cctx);
94
95	return (mem_tobuffer(target, rdata->data, rdata->length));
96}
97
98static inline int
99compare_gpos(ARGS_COMPARE) {
100	isc_region_t r1;
101	isc_region_t r2;
102
103	REQUIRE(rdata1->type == rdata2->type);
104	REQUIRE(rdata1->rdclass == rdata2->rdclass);
105	REQUIRE(rdata1->type == dns_rdatatype_gpos);
106	REQUIRE(rdata1->length != 0);
107	REQUIRE(rdata2->length != 0);
108
109	dns_rdata_toregion(rdata1, &r1);
110	dns_rdata_toregion(rdata2, &r2);
111	return (isc_region_compare(&r1, &r2));
112}
113
114static inline isc_result_t
115fromstruct_gpos(ARGS_FROMSTRUCT) {
116	dns_rdata_gpos_t *gpos = source;
117
118	REQUIRE(type == dns_rdatatype_gpos);
119	REQUIRE(source != NULL);
120	REQUIRE(gpos->common.rdtype == type);
121	REQUIRE(gpos->common.rdclass == rdclass);
122
123	UNUSED(type);
124	UNUSED(rdclass);
125
126	RETERR(uint8_tobuffer(gpos->long_len, target));
127	RETERR(mem_tobuffer(target, gpos->longitude, gpos->long_len));
128	RETERR(uint8_tobuffer(gpos->lat_len, target));
129	RETERR(mem_tobuffer(target, gpos->latitude, gpos->lat_len));
130	RETERR(uint8_tobuffer(gpos->alt_len, target));
131	return (mem_tobuffer(target, gpos->altitude, gpos->alt_len));
132}
133
134static inline isc_result_t
135tostruct_gpos(ARGS_TOSTRUCT) {
136	dns_rdata_gpos_t *gpos = target;
137	isc_region_t region;
138
139	REQUIRE(rdata->type == dns_rdatatype_gpos);
140	REQUIRE(target != NULL);
141	REQUIRE(rdata->length != 0);
142
143	gpos->common.rdclass = rdata->rdclass;
144	gpos->common.rdtype = rdata->type;
145	ISC_LINK_INIT(&gpos->common, link);
146
147	dns_rdata_toregion(rdata, &region);
148	gpos->long_len = uint8_fromregion(&region);
149	isc_region_consume(&region, 1);
150	gpos->longitude = mem_maybedup(region.base, gpos->long_len);
151	if (gpos->longitude == NULL)
152		return (ISC_R_NOMEMORY);
153	isc_region_consume(&region, gpos->long_len);
154
155	gpos->lat_len = uint8_fromregion(&region);
156	isc_region_consume(&region, 1);
157	gpos->latitude = mem_maybedup(region.base, gpos->lat_len);
158	if (gpos->latitude == NULL)
159		goto cleanup_longitude;
160	isc_region_consume(&region, gpos->lat_len);
161
162	gpos->alt_len = uint8_fromregion(&region);
163	isc_region_consume(&region, 1);
164	if (gpos->lat_len > 0) {
165		gpos->altitude =
166			mem_maybedup(region.base, gpos->alt_len);
167		if (gpos->altitude == NULL)
168			goto cleanup_latitude;
169	} else
170		gpos->altitude = NULL;
171
172	return (ISC_R_SUCCESS);
173
174 cleanup_latitude:
175	free(gpos->longitude);
176
177 cleanup_longitude:
178	free(gpos->latitude);
179	return (ISC_R_NOMEMORY);
180}
181
182static inline void
183freestruct_gpos(ARGS_FREESTRUCT) {
184	dns_rdata_gpos_t *gpos = source;
185
186	REQUIRE(source != NULL);
187	REQUIRE(gpos->common.rdtype == dns_rdatatype_gpos);
188
189
190	free(gpos->longitude);
191	free(gpos->latitude);
192	free(gpos->altitude);
193}
194
195static inline isc_result_t
196additionaldata_gpos(ARGS_ADDLDATA) {
197	REQUIRE(rdata->type == dns_rdatatype_gpos);
198
199	UNUSED(rdata);
200	UNUSED(add);
201	UNUSED(arg);
202
203	return (ISC_R_SUCCESS);
204}
205
206static inline isc_result_t
207digest_gpos(ARGS_DIGEST) {
208	isc_region_t r;
209
210	REQUIRE(rdata->type == dns_rdatatype_gpos);
211
212	dns_rdata_toregion(rdata, &r);
213
214	return ((digest)(arg, &r));
215}
216
217static inline isc_boolean_t
218checkowner_gpos(ARGS_CHECKOWNER) {
219
220	REQUIRE(type == dns_rdatatype_gpos);
221
222	UNUSED(name);
223	UNUSED(type);
224	UNUSED(rdclass);
225	UNUSED(wildcard);
226
227	return (ISC_TRUE);
228}
229
230static inline isc_boolean_t
231checknames_gpos(ARGS_CHECKNAMES) {
232
233	REQUIRE(rdata->type == dns_rdatatype_gpos);
234
235	UNUSED(rdata);
236	UNUSED(owner);
237	UNUSED(bad);
238
239	return (ISC_TRUE);
240}
241
242static inline int
243casecompare_gpos(ARGS_COMPARE) {
244	return (compare_gpos(rdata1, rdata2));
245}
246
247#endif	/* RDATA_GENERIC_GPOS_27_C */
248