gpos_27.c revision 1.7
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.7 2020/02/24 17:44:44 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
29totext_gpos(ARGS_TOTEXT) {
30	isc_region_t region;
31	int i;
32
33	REQUIRE(rdata->type == dns_rdatatype_gpos);
34	REQUIRE(rdata->length != 0);
35
36	UNUSED(tctx);
37
38	dns_rdata_toregion(rdata, &region);
39
40	for (i = 0; i < 3; i++) {
41		RETERR(txt_totext(&region, ISC_TRUE, target));
42		if (i != 2)
43			RETERR(str_totext(" ", target));
44	}
45
46	return (ISC_R_SUCCESS);
47}
48
49static inline isc_result_t
50fromwire_gpos(ARGS_FROMWIRE) {
51	int i;
52
53	REQUIRE(type == dns_rdatatype_gpos);
54
55	UNUSED(type);
56	UNUSED(dctx);
57	UNUSED(rdclass);
58	UNUSED(options);
59
60	for (i = 0; i < 3; i++)
61		RETERR(txt_fromwire(source, target));
62	return (ISC_R_SUCCESS);
63}
64
65static inline isc_result_t
66towire_gpos(ARGS_TOWIRE) {
67
68	REQUIRE(rdata->type == dns_rdatatype_gpos);
69	REQUIRE(rdata->length != 0);
70
71	UNUSED(cctx);
72
73	return (mem_tobuffer(target, rdata->data, rdata->length));
74}
75
76
77
78static inline isc_result_t
79tostruct_gpos(ARGS_TOSTRUCT) {
80	dns_rdata_gpos_t *gpos = target;
81	isc_region_t region;
82
83	REQUIRE(rdata->type == dns_rdatatype_gpos);
84	REQUIRE(target != NULL);
85	REQUIRE(rdata->length != 0);
86
87	gpos->common.rdclass = rdata->rdclass;
88	gpos->common.rdtype = rdata->type;
89	ISC_LINK_INIT(&gpos->common, link);
90
91	dns_rdata_toregion(rdata, &region);
92	gpos->long_len = uint8_fromregion(&region);
93	isc_region_consume(&region, 1);
94	gpos->longitude = mem_maybedup(region.base, gpos->long_len);
95	if (gpos->longitude == NULL)
96		return (ISC_R_NOMEMORY);
97	isc_region_consume(&region, gpos->long_len);
98
99	gpos->lat_len = uint8_fromregion(&region);
100	isc_region_consume(&region, 1);
101	gpos->latitude = mem_maybedup(region.base, gpos->lat_len);
102	if (gpos->latitude == NULL)
103		goto cleanup_longitude;
104	isc_region_consume(&region, gpos->lat_len);
105
106	gpos->alt_len = uint8_fromregion(&region);
107	isc_region_consume(&region, 1);
108	if (gpos->lat_len > 0) {
109		gpos->altitude =
110			mem_maybedup(region.base, gpos->alt_len);
111		if (gpos->altitude == NULL)
112			goto cleanup_latitude;
113	} else
114		gpos->altitude = NULL;
115
116	return (ISC_R_SUCCESS);
117
118 cleanup_latitude:
119	free(gpos->longitude);
120
121 cleanup_longitude:
122	free(gpos->latitude);
123	return (ISC_R_NOMEMORY);
124}
125
126
127
128
129#endif	/* RDATA_GENERIC_GPOS_27_C */
130