gpos_27.c 5.21 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
 * 
8
9
10
11
12
13
14
15
 * 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.
Mark Andrews's avatar
Mark Andrews committed
16
17
 */

18
/* $Id: gpos_27.c,v 1.23 2000/07/27 09:48:58 tale 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
David Lawrence's avatar
David Lawrence committed
30
fromtext_gpos(ARGS_FROMTEXT) {
Mark Andrews's avatar
Mark Andrews committed
31
32
33
34
35
	isc_token_t token;
	int i;

	REQUIRE(type == 27);

James Brister's avatar
James Brister committed
36
37
38
	UNUSED(rdclass);
	UNUSED(origin);
	UNUSED(downcase);
Mark Andrews's avatar
Mark Andrews committed
39
40
41
42
43
44

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

48
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
49
totext_gpos(ARGS_TOTEXT) {
Mark Andrews's avatar
Mark Andrews committed
50
51
52
53
54
	isc_region_t region;
	int i;

	REQUIRE(rdata->type == 27);

James Brister's avatar
James Brister committed
55
	UNUSED(tctx);
Mark Andrews's avatar
Mark Andrews committed
56
57
58
59
60
61
62
63
64

	dns_rdata_toregion(rdata, &region);

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

65
	return (ISC_R_SUCCESS);
Mark Andrews's avatar
Mark Andrews committed
66
67
}

68
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
69
fromwire_gpos(ARGS_FROMWIRE) {
Mark Andrews's avatar
Mark Andrews committed
70
71
72
73
	int i;

	REQUIRE(type == 27);

James Brister's avatar
James Brister committed
74
75
76
	UNUSED(dctx);
	UNUSED(rdclass);
	UNUSED(downcase);
Mark Andrews's avatar
Mark Andrews committed
77
78
79

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

83
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
84
towire_gpos(ARGS_TOWIRE) {
Mark Andrews's avatar
Mark Andrews committed
85
86
87

	REQUIRE(rdata->type == 27);

James Brister's avatar
James Brister committed
88
	UNUSED(cctx);
Mark Andrews's avatar
Mark Andrews committed
89

James Brister's avatar
James Brister committed
90
	return (mem_tobuffer(target, rdata->data, rdata->length));
Mark Andrews's avatar
Mark Andrews committed
91
92
}

93
static inline int
David Lawrence's avatar
David Lawrence committed
94
compare_gpos(ARGS_COMPARE) {
Mark Andrews's avatar
Mark Andrews committed
95
96
97
98
	isc_region_t r1;
	isc_region_t r2;
	
	REQUIRE(rdata1->type == rdata2->type);
99
	REQUIRE(rdata1->rdclass == rdata2->rdclass);
Mark Andrews's avatar
Mark Andrews committed
100
101
102
103
	REQUIRE(rdata1->type == 27);

	dns_rdata_toregion(rdata1, &r1);
	dns_rdata_toregion(rdata2, &r2);
James Brister's avatar
James Brister committed
104
	return (compare_region(&r1, &r2));
Mark Andrews's avatar
Mark Andrews committed
105
106
}

107
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
108
fromstruct_gpos(ARGS_FROMSTRUCT) {
109
	dns_rdata_gpos_t *gpos = source;
Mark Andrews's avatar
Mark Andrews committed
110
111

	REQUIRE(type == 27);
112
113
114
115
116
117
118
119
120
121
	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
122
123
}

124
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
125
tostruct_gpos(ARGS_TOSTRUCT) {
126
127
	dns_rdata_gpos_t *gpos = target;
	isc_region_t region;
Mark Andrews's avatar
Mark Andrews committed
128
129

	REQUIRE(rdata->type == 27);
130
131
132
133
134
135
	REQUIRE(target != NULL);

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

136
	dns_rdata_toregion(rdata, &region);
137
138
139
140
141
142
143
144
145
146
147
148
149
150
	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) {
David Lawrence's avatar
David Lawrence committed
151
152
		gpos->latitude =
			mem_maybedup(mctx, region.base, gpos->lat_len);
153
154
155
156
157
158
159
160
161
		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) {
David Lawrence's avatar
David Lawrence committed
162
163
		gpos->altitude =
			mem_maybedup(mctx, region.base, gpos->alt_len);
164
165
166
167
168
169
170
		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
171

172
173
174
 cleanup_latitude:
	if (mctx != NULL && gpos->longitude != NULL)
		isc_mem_free(mctx, gpos->longitude);
Mark Andrews's avatar
Mark Andrews committed
175

176
177
178
179
 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
180
}
181

182
static inline void
David Lawrence's avatar
David Lawrence committed
183
freestruct_gpos(ARGS_FREESTRUCT) {
184
	dns_rdata_gpos_t *gpos = source;
185

186
187
188
189
190
191
192
193
194
195
196
197
198
	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;
199
}
200

201
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
202
additionaldata_gpos(ARGS_ADDLDATA) {
203
204
	REQUIRE(rdata->type == 27);

205
	UNUSED(rdata);
Andreas Gustafsson's avatar
Andreas Gustafsson committed
206
207
	UNUSED(add);
	UNUSED(arg);
208

209
	return (ISC_R_SUCCESS);
210
211
}

212
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
213
digest_gpos(ARGS_DIGEST) {
Bob Halley's avatar
Bob Halley committed
214
215
216
217
218
219
	isc_region_t r;

	REQUIRE(rdata->type == 27);

	dns_rdata_toregion(rdata, &r);

James Brister's avatar
James Brister committed
220
	return ((digest)(arg, &r));
Bob Halley's avatar
Bob Halley committed
221
222
}

223
#endif	/* RDATA_GENERIC_GPOS_27_C */