gpos_27.c 5.35 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.
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.
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.25 2000/10/25 05:43:31 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
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
	isc_region_t region;
	int i;

	REQUIRE(rdata->type == 27);
54
	REQUIRE(rdata->length != 0);
Mark Andrews's avatar
Mark Andrews committed
55

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

	dns_rdata_toregion(rdata, &region);

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

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

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

	REQUIRE(type == 27);

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

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

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

	REQUIRE(rdata->type == 27);
88
	REQUIRE(rdata->length != 0);
Mark Andrews's avatar
Mark Andrews committed
89

James Brister's avatar
James Brister committed
90
	UNUSED(cctx);
Mark Andrews's avatar
Mark Andrews committed
91

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

95
static inline int
David Lawrence's avatar
David Lawrence committed
96
compare_gpos(ARGS_COMPARE) {
Mark Andrews's avatar
Mark Andrews committed
97 98
	isc_region_t r1;
	isc_region_t r2;
99

Mark Andrews's avatar
Mark Andrews committed
100
	REQUIRE(rdata1->type == rdata2->type);
101
	REQUIRE(rdata1->rdclass == rdata2->rdclass);
Mark Andrews's avatar
Mark Andrews committed
102
	REQUIRE(rdata1->type == 27);
103 104
	REQUIRE(rdata1->length != 0);
	REQUIRE(rdata2->length != 0);
Mark Andrews's avatar
Mark Andrews committed
105 106 107

	dns_rdata_toregion(rdata1, &r1);
	dns_rdata_toregion(rdata2, &r2);
James Brister's avatar
James Brister committed
108
	return (compare_region(&r1, &r2));
Mark Andrews's avatar
Mark Andrews committed
109 110
}

111
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
112
fromstruct_gpos(ARGS_FROMSTRUCT) {
113
	dns_rdata_gpos_t *gpos = source;
Mark Andrews's avatar
Mark Andrews committed
114 115

	REQUIRE(type == 27);
116 117 118 119 120 121 122 123 124 125
	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
126 127
}

128
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
129
tostruct_gpos(ARGS_TOSTRUCT) {
130 131
	dns_rdata_gpos_t *gpos = target;
	isc_region_t region;
Mark Andrews's avatar
Mark Andrews committed
132 133

	REQUIRE(rdata->type == 27);
134
	REQUIRE(target != NULL);
135
	REQUIRE(rdata->length != 0);
136 137 138 139 140

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

141
	dns_rdata_toregion(rdata, &region);
142 143 144 145 146 147 148 149 150 151 152 153 154 155
	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
156 157
		gpos->latitude =
			mem_maybedup(mctx, region.base, gpos->lat_len);
158 159 160 161 162 163 164 165 166
		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
167 168
		gpos->altitude =
			mem_maybedup(mctx, region.base, gpos->alt_len);
169 170
		if (gpos->altitude == NULL)
			goto cleanup_latitude;
171
	} else
172 173 174 175
		gpos->altitude = NULL;

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

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

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

187
static inline void
David Lawrence's avatar
David Lawrence committed
188
freestruct_gpos(ARGS_FREESTRUCT) {
189
	dns_rdata_gpos_t *gpos = source;
190

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

206
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
207
additionaldata_gpos(ARGS_ADDLDATA) {
208 209
	REQUIRE(rdata->type == 27);

210
	UNUSED(rdata);
Andreas Gustafsson's avatar
Andreas Gustafsson committed
211 212
	UNUSED(add);
	UNUSED(arg);
213

214
	return (ISC_R_SUCCESS);
215 216
}

217
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
218
digest_gpos(ARGS_DIGEST) {
Bob Halley's avatar
Bob Halley committed
219 220 221 222 223 224
	isc_region_t r;

	REQUIRE(rdata->type == 27);

	dns_rdata_toregion(rdata, &r);

James Brister's avatar
James Brister committed
225
	return ((digest)(arg, &r));
Bob Halley's avatar
Bob Halley committed
226 227
}

228
#endif	/* RDATA_GENERIC_GPOS_27_C */