gpos_27.c 5.8 KB
Newer Older
Mark Andrews's avatar
Mark Andrews committed
1
/*
Bob Halley's avatar
Bob Halley committed
2
 * Copyright (C) 1999, 2000  Internet Software Consortium.
Michael Graff's avatar
Michael Graff committed
3
 * 
Mark Andrews's avatar
Mark Andrews committed
4
5
6
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
Michael Graff's avatar
Michael Graff committed
7
 * 
Mark Andrews's avatar
Mark Andrews committed
8
9
10
11
12
13
14
15
16
17
 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */

18
/* $Id: gpos_27.c,v 1.20 2000/05/22 12:37:33 marka Exp $ */
Mark Andrews's avatar
Mark Andrews committed
19

James Brister's avatar
James Brister committed
20
21
22
/* reviewed: Wed Mar 15 16:48:45 PST 2000 by brister */

/* RFC 1712 */
Mark Andrews's avatar
Mark Andrews committed
23

24
25
#ifndef RDATA_GENERIC_GPOS_27_C
#define RDATA_GENERIC_GPOS_27_C
Mark Andrews's avatar
Mark Andrews committed
26

27
28
#define RRTYPE_GPOS_ATTRIBUTES (0)

29
static inline isc_result_t
30
fromtext_gpos(dns_rdataclass_t rdclass, dns_rdatatype_t type,
Mark Andrews's avatar
Mark Andrews committed
31
32
33
	      isc_lex_t *lexer, dns_name_t *origin,
	      isc_boolean_t downcase, isc_buffer_t *target)
{
Mark Andrews's avatar
Mark Andrews committed
34
35
36
37
38
	isc_token_t token;
	int i;

	REQUIRE(type == 27);

James Brister's avatar
James Brister committed
39
40
41
	UNUSED(rdclass);
	UNUSED(origin);
	UNUSED(downcase);
Mark Andrews's avatar
Mark Andrews committed
42
43
44
45
46
47

	for (i = 0; i < 3 ; i++) {
		RETERR(gettoken(lexer, &token, isc_tokentype_qstring,
				ISC_FALSE));
		RETERR(txt_fromtext(&token.value.as_textregion, target));
	}
48
	return (ISC_R_SUCCESS);
Mark Andrews's avatar
Mark Andrews committed
49
50
}

51
static inline isc_result_t
52
53
54
totext_gpos(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx, 
	    isc_buffer_t *target) 
{
Mark Andrews's avatar
Mark Andrews committed
55
56
57
58
59
	isc_region_t region;
	int i;

	REQUIRE(rdata->type == 27);

James Brister's avatar
James Brister committed
60
	UNUSED(tctx);
Mark Andrews's avatar
Mark Andrews committed
61
62
63
64
65
66
67
68
69

	dns_rdata_toregion(rdata, &region);

	for (i = 0; i < 3 ; i++) {
		RETERR(txt_totext(&region, target));
		if (i != 2)
			RETERR(str_totext(" ", target));
	}

70
	return (ISC_R_SUCCESS);
Mark Andrews's avatar
Mark Andrews committed
71
72
}

73
static inline isc_result_t
74
fromwire_gpos(dns_rdataclass_t rdclass, dns_rdatatype_t type,
Mark Andrews's avatar
Mark Andrews committed
75
76
77
	      isc_buffer_t *source, dns_decompress_t *dctx,
	      isc_boolean_t downcase, isc_buffer_t *target)
{
Mark Andrews's avatar
Mark Andrews committed
78
79
80
81
	int i;

	REQUIRE(type == 27);

James Brister's avatar
James Brister committed
82
83
84
	UNUSED(dctx);
	UNUSED(rdclass);
	UNUSED(downcase);
Mark Andrews's avatar
Mark Andrews committed
85
86
87

	for (i = 0 ; i < 3; i++)
		RETERR(txt_fromwire(source, target));
88
	return (ISC_R_SUCCESS);
Mark Andrews's avatar
Mark Andrews committed
89
90
}

91
static inline isc_result_t
James Brister's avatar
James Brister committed
92
93
towire_gpos(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target)
{
Mark Andrews's avatar
Mark Andrews committed
94
95
96

	REQUIRE(rdata->type == 27);

James Brister's avatar
James Brister committed
97
	UNUSED(cctx);
Mark Andrews's avatar
Mark Andrews committed
98

James Brister's avatar
James Brister committed
99
	return (mem_tobuffer(target, rdata->data, rdata->length));
Mark Andrews's avatar
Mark Andrews committed
100
101
}

102
static inline int
James Brister's avatar
James Brister committed
103
104
compare_gpos(dns_rdata_t *rdata1, dns_rdata_t *rdata2)
{
Mark Andrews's avatar
Mark Andrews committed
105
106
107
108
	isc_region_t r1;
	isc_region_t r2;
	
	REQUIRE(rdata1->type == rdata2->type);
109
	REQUIRE(rdata1->rdclass == rdata2->rdclass);
Mark Andrews's avatar
Mark Andrews committed
110
111
112
113
	REQUIRE(rdata1->type == 27);

	dns_rdata_toregion(rdata1, &r1);
	dns_rdata_toregion(rdata2, &r2);
James Brister's avatar
James Brister committed
114
	return (compare_region(&r1, &r2));
Mark Andrews's avatar
Mark Andrews committed
115
116
}

117
static inline isc_result_t
118
fromstruct_gpos(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
Mark Andrews's avatar
Mark Andrews committed
119
120
		isc_buffer_t *target)
{
121
	dns_rdata_gpos_t *gpos = source;
Mark Andrews's avatar
Mark Andrews committed
122
123

	REQUIRE(type == 27);
124
125
126
127
128
129
130
131
132
133
	REQUIRE(source != NULL);
	REQUIRE(gpos->common.rdtype == type);
	REQUIRE(gpos->common.rdclass == rdclass);

	RETERR(uint8_tobuffer(gpos->long_len, target));
	RETERR(mem_tobuffer(target, gpos->longitude, gpos->long_len));
	RETERR(uint8_tobuffer(gpos->lat_len, target));
	RETERR(mem_tobuffer(target, gpos->latitude, gpos->lat_len));
	RETERR(uint8_tobuffer(gpos->alt_len, target));
	return (mem_tobuffer(target, gpos->altitude, gpos->alt_len));
Mark Andrews's avatar
Mark Andrews committed
134
135
}

136
static inline isc_result_t
James Brister's avatar
James Brister committed
137
138
tostruct_gpos(dns_rdata_t *rdata, void *target, isc_mem_t *mctx)
{
139
140
	dns_rdata_gpos_t *gpos = target;
	isc_region_t region;
Mark Andrews's avatar
Mark Andrews committed
141
142

	REQUIRE(rdata->type == 27);
143
144
145
146
147
148
	REQUIRE(target != NULL);

	gpos->common.rdclass = rdata->rdclass;
	gpos->common.rdtype = rdata->type;
	ISC_LINK_INIT(&gpos->common, link);

149
	dns_rdata_toregion(rdata, &region);
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
	gpos->long_len = uint8_fromregion(&region);
	isc_region_consume(&region, 1);
	if (gpos->long_len != 0) {
		gpos->longitude = mem_maybedup(mctx, region.base,
					       gpos->long_len);
		if (gpos->longitude == NULL)
			return (ISC_R_NOMEMORY);
		isc_region_consume(&region, gpos->long_len);
	} else
		gpos->longitude = NULL;

	gpos->lat_len = uint8_fromregion(&region);
	isc_region_consume(&region, 1);
	if (gpos->lat_len > 0) {
		gpos->latitude = mem_maybedup(mctx, region.base, gpos->lat_len);
		if (gpos->latitude == NULL)
			goto cleanup_longitude;
		isc_region_consume(&region, gpos->lat_len);
	} else
		gpos->latitude = NULL;

	gpos->alt_len = uint8_fromregion(&region);
	isc_region_consume(&region, 1);
	if (gpos->lat_len > 0) {
		gpos->altitude = mem_maybedup(mctx, region.base, gpos->alt_len);
		if (gpos->altitude == NULL)
			goto cleanup_latitude;
	} else 
		gpos->altitude = NULL;

	gpos->mctx = mctx;
	return (ISC_R_SUCCESS);
Mark Andrews's avatar
Mark Andrews committed
182

183
184
185
 cleanup_latitude:
	if (mctx != NULL && gpos->longitude != NULL)
		isc_mem_free(mctx, gpos->longitude);
Mark Andrews's avatar
Mark Andrews committed
186

187
188
189
190
 cleanup_longitude:
	if (mctx != NULL && gpos->latitude != NULL)
		isc_mem_free(mctx, gpos->latitude);
	return (ISC_R_NOMEMORY);
Mark Andrews's avatar
Mark Andrews committed
191
}
192

193
static inline void
James Brister's avatar
James Brister committed
194
195
freestruct_gpos(void *source)
{
196
	dns_rdata_gpos_t *gpos = source;
197

198
199
200
201
202
203
204
205
206
207
208
209
210
	REQUIRE(source != NULL);
	REQUIRE(gpos->common.rdtype == 27);

	if (gpos->mctx == NULL)
		return;

	if (gpos->longitude != NULL)
		isc_mem_free(gpos->mctx, gpos->longitude);
	if (gpos->latitude != NULL)
		isc_mem_free(gpos->mctx, gpos->latitude);
	if (gpos->altitude != NULL)
		isc_mem_free(gpos->mctx, gpos->altitude);
	gpos->mctx = NULL;
211
}
212

213
static inline isc_result_t
214
215
216
217
218
additionaldata_gpos(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
		    void *arg)
{
	REQUIRE(rdata->type == 27);

219
	UNUSED(rdata);
Andreas Gustafsson's avatar
Andreas Gustafsson committed
220
221
	UNUSED(add);
	UNUSED(arg);
222

223
	return (ISC_R_SUCCESS);
224
225
}

226
static inline isc_result_t
James Brister's avatar
James Brister committed
227
228
digest_gpos(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg)
{
Bob Halley's avatar
Bob Halley committed
229
230
231
232
233
234
	isc_region_t r;

	REQUIRE(rdata->type == 27);

	dns_rdata_toregion(rdata, &r);

James Brister's avatar
James Brister committed
235
	return ((digest)(arg, &r));
Bob Halley's avatar
Bob Halley committed
236
237
}

238
#endif	/* RDATA_GENERIC_GPOS_27_C */