1 /* $NetBSD: gpos_27.c,v 1.4 2014/12/10 04:37:59 christos Exp $ */
4 * Copyright (C) 2004, 2005, 2007, 2009, 2014 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2002 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: gpos_27.c,v 1.43 2009/12/04 22:06:37 tbox Exp */
22 /* reviewed: Wed Mar 15 16:48:45 PST 2000 by brister */
26 #ifndef RDATA_GENERIC_GPOS_27_C
27 #define RDATA_GENERIC_GPOS_27_C
29 #define RRTYPE_GPOS_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_gpos(ARGS_FROMTEXT
) {
44 for (i
= 0; i
< 3; i
++) {
45 RETERR(isc_lex_getmastertoken(lexer
, &token
,
46 isc_tokentype_qstring
,
48 RETTOK(txt_fromtext(&token
.value
.as_textregion
, target
));
50 return (ISC_R_SUCCESS
);
53 static inline isc_result_t
54 totext_gpos(ARGS_TOTEXT
) {
58 REQUIRE(rdata
->type
== 27);
59 REQUIRE(rdata
->length
!= 0);
63 dns_rdata_toregion(rdata
, ®ion
);
65 for (i
= 0; i
< 3; i
++) {
66 RETERR(txt_totext(®ion
, ISC_TRUE
, target
));
68 RETERR(str_totext(" ", target
));
71 return (ISC_R_SUCCESS
);
74 static inline isc_result_t
75 fromwire_gpos(ARGS_FROMWIRE
) {
85 for (i
= 0; i
< 3; i
++)
86 RETERR(txt_fromwire(source
, target
));
87 return (ISC_R_SUCCESS
);
90 static inline isc_result_t
91 towire_gpos(ARGS_TOWIRE
) {
93 REQUIRE(rdata
->type
== 27);
94 REQUIRE(rdata
->length
!= 0);
98 return (mem_tobuffer(target
, rdata
->data
, rdata
->length
));
102 compare_gpos(ARGS_COMPARE
) {
106 REQUIRE(rdata1
->type
== rdata2
->type
);
107 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
108 REQUIRE(rdata1
->type
== 27);
109 REQUIRE(rdata1
->length
!= 0);
110 REQUIRE(rdata2
->length
!= 0);
112 dns_rdata_toregion(rdata1
, &r1
);
113 dns_rdata_toregion(rdata2
, &r2
);
114 return (isc_region_compare(&r1
, &r2
));
117 static inline isc_result_t
118 fromstruct_gpos(ARGS_FROMSTRUCT
) {
119 dns_rdata_gpos_t
*gpos
= source
;
122 REQUIRE(source
!= NULL
);
123 REQUIRE(gpos
->common
.rdtype
== type
);
124 REQUIRE(gpos
->common
.rdclass
== rdclass
);
129 RETERR(uint8_tobuffer(gpos
->long_len
, target
));
130 RETERR(mem_tobuffer(target
, gpos
->longitude
, gpos
->long_len
));
131 RETERR(uint8_tobuffer(gpos
->lat_len
, target
));
132 RETERR(mem_tobuffer(target
, gpos
->latitude
, gpos
->lat_len
));
133 RETERR(uint8_tobuffer(gpos
->alt_len
, target
));
134 return (mem_tobuffer(target
, gpos
->altitude
, gpos
->alt_len
));
137 static inline isc_result_t
138 tostruct_gpos(ARGS_TOSTRUCT
) {
139 dns_rdata_gpos_t
*gpos
= target
;
142 REQUIRE(rdata
->type
== 27);
143 REQUIRE(target
!= NULL
);
144 REQUIRE(rdata
->length
!= 0);
146 gpos
->common
.rdclass
= rdata
->rdclass
;
147 gpos
->common
.rdtype
= rdata
->type
;
148 ISC_LINK_INIT(&gpos
->common
, link
);
150 dns_rdata_toregion(rdata
, ®ion
);
151 gpos
->long_len
= uint8_fromregion(®ion
);
152 isc_region_consume(®ion
, 1);
153 gpos
->longitude
= mem_maybedup(mctx
, region
.base
, gpos
->long_len
);
154 if (gpos
->longitude
== NULL
)
155 return (ISC_R_NOMEMORY
);
156 isc_region_consume(®ion
, gpos
->long_len
);
158 gpos
->lat_len
= uint8_fromregion(®ion
);
159 isc_region_consume(®ion
, 1);
160 gpos
->latitude
= mem_maybedup(mctx
, region
.base
, gpos
->lat_len
);
161 if (gpos
->latitude
== NULL
)
162 goto cleanup_longitude
;
163 isc_region_consume(®ion
, gpos
->lat_len
);
165 gpos
->alt_len
= uint8_fromregion(®ion
);
166 isc_region_consume(®ion
, 1);
167 if (gpos
->lat_len
> 0) {
169 mem_maybedup(mctx
, region
.base
, gpos
->alt_len
);
170 if (gpos
->altitude
== NULL
)
171 goto cleanup_latitude
;
173 gpos
->altitude
= NULL
;
176 return (ISC_R_SUCCESS
);
179 if (mctx
!= NULL
&& gpos
->longitude
!= NULL
)
180 isc_mem_free(mctx
, gpos
->longitude
);
183 if (mctx
!= NULL
&& gpos
->latitude
!= NULL
)
184 isc_mem_free(mctx
, gpos
->latitude
);
185 return (ISC_R_NOMEMORY
);
189 freestruct_gpos(ARGS_FREESTRUCT
) {
190 dns_rdata_gpos_t
*gpos
= source
;
192 REQUIRE(source
!= NULL
);
193 REQUIRE(gpos
->common
.rdtype
== 27);
195 if (gpos
->mctx
== NULL
)
198 if (gpos
->longitude
!= NULL
)
199 isc_mem_free(gpos
->mctx
, gpos
->longitude
);
200 if (gpos
->latitude
!= NULL
)
201 isc_mem_free(gpos
->mctx
, gpos
->latitude
);
202 if (gpos
->altitude
!= NULL
)
203 isc_mem_free(gpos
->mctx
, gpos
->altitude
);
207 static inline isc_result_t
208 additionaldata_gpos(ARGS_ADDLDATA
) {
209 REQUIRE(rdata
->type
== 27);
215 return (ISC_R_SUCCESS
);
218 static inline isc_result_t
219 digest_gpos(ARGS_DIGEST
) {
222 REQUIRE(rdata
->type
== 27);
224 dns_rdata_toregion(rdata
, &r
);
226 return ((digest
)(arg
, &r
));
229 static inline isc_boolean_t
230 checkowner_gpos(ARGS_CHECKOWNER
) {
242 static inline isc_boolean_t
243 checknames_gpos(ARGS_CHECKNAMES
) {
245 REQUIRE(rdata
->type
== 27);
255 casecompare_gpos(ARGS_COMPARE
) {
256 return (compare_gpos(rdata1
, rdata2
));
259 #endif /* RDATA_GENERIC_GPOS_27_C */