gpos_27.c 5.38 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.18 2000/05/05 05:49:44 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)
{
Mark Andrews's avatar
Mark Andrews committed
121
122
123

	REQUIRE(type == 27);

James Brister's avatar
James Brister committed
124
	UNUSED(rdclass);
Mark Andrews's avatar
Mark Andrews committed
125

James Brister's avatar
James Brister committed
126
127
	UNUSED(source);
	UNUSED(target);
Mark Andrews's avatar
Mark Andrews committed
128

129
	return (ISC_R_NOTIMPLEMENTED);
Mark Andrews's avatar
Mark Andrews committed
130
131
}

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

	REQUIRE(rdata->type == 27);
139
140
141
142
143
144
145
146
147
148
149
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
	REQUIRE(target != NULL);

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

	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
177

178
179
180
 cleanup_latitude:
	if (mctx != NULL && gpos->longitude != NULL)
		isc_mem_free(mctx, gpos->longitude);
Mark Andrews's avatar
Mark Andrews committed
181

182
183
184
185
 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
186
}
187

188
static inline void
James Brister's avatar
James Brister committed
189
190
freestruct_gpos(void *source)
{
191
	dns_rdata_gpos_t *gpos = source;
192

193
194
195
196
197
198
199
200
201
202
203
204
205
	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;
206
}
207

208
static inline isc_result_t
209
210
211
212
213
additionaldata_gpos(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
		    void *arg)
{
	REQUIRE(rdata->type == 27);

214
	UNUSED(rdata);
Andreas Gustafsson's avatar
Andreas Gustafsson committed
215
216
	UNUSED(add);
	UNUSED(arg);
217

218
	return (ISC_R_SUCCESS);
219
220
}

221
static inline isc_result_t
James Brister's avatar
James Brister committed
222
223
digest_gpos(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg)
{
Bob Halley's avatar
Bob Halley committed
224
225
226
227
228
229
	isc_region_t r;

	REQUIRE(rdata->type == 27);

	dns_rdata_toregion(rdata, &r);

James Brister's avatar
James Brister committed
230
	return ((digest)(arg, &r));
Bob Halley's avatar
Bob Halley committed
231
232
}

233
#endif	/* RDATA_GENERIC_GPOS_27_C */