1 /* $NetBSD: uri_256.c,v 1.1.1.5 2014/12/10 03:34:42 christos Exp $ */
4 * Copyright (C) 2011, 2012, 2014 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
21 #ifndef GENERIC_URI_256_C
22 #define GENERIC_URI_256_C 1
24 #define RRTYPE_URI_ATTRIBUTES (0)
26 static inline isc_result_t
27 fromtext_uri(ARGS_FROMTEXT
) {
41 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
43 if (token
.value
.as_ulong
> 0xffffU
)
45 RETERR(uint16_tobuffer(token
.value
.as_ulong
, target
));
50 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
52 if (token
.value
.as_ulong
> 0xffffU
)
54 RETERR(uint16_tobuffer(token
.value
.as_ulong
, target
));
59 RETERR(isc_lex_getmastertoken(lexer
, &token
,
60 isc_tokentype_qstring
, ISC_FALSE
));
61 if (token
.type
!= isc_tokentype_qstring
)
63 RETTOK(multitxt_fromtext(&token
.value
.as_textregion
, target
));
64 return (ISC_R_SUCCESS
);
67 static inline isc_result_t
68 totext_uri(ARGS_TOTEXT
) {
70 unsigned short priority
, weight
;
71 char buf
[sizeof("65000 ")];
75 REQUIRE(rdata
->type
== 256);
76 REQUIRE(rdata
->length
!= 0);
78 dns_rdata_toregion(rdata
, ®ion
);
83 priority
= uint16_fromregion(®ion
);
84 isc_region_consume(®ion
, 2);
85 sprintf(buf
, "%u ", priority
);
86 RETERR(str_totext(buf
, target
));
91 weight
= uint16_fromregion(®ion
);
92 isc_region_consume(®ion
, 2);
93 sprintf(buf
, "%u ", weight
);
94 RETERR(str_totext(buf
, target
));
99 RETERR(multitxt_totext(®ion
, target
));
100 return (ISC_R_SUCCESS
);
103 static inline isc_result_t
104 fromwire_uri(ARGS_FROMWIRE
) {
107 REQUIRE(type
== 256);
117 isc_buffer_activeregion(source
, ®ion
);
118 if (region
.length
< 4)
119 return (ISC_R_UNEXPECTEDEND
);
122 * Priority, weight and target URI
124 isc_buffer_forward(source
, region
.length
);
125 return (mem_tobuffer(target
, region
.base
, region
.length
));
128 static inline isc_result_t
129 towire_uri(ARGS_TOWIRE
) {
132 REQUIRE(rdata
->type
== 256);
133 REQUIRE(rdata
->length
!= 0);
137 dns_rdata_toregion(rdata
, ®ion
);
138 return (mem_tobuffer(target
, region
.base
, region
.length
));
142 compare_uri(ARGS_COMPARE
) {
147 REQUIRE(rdata1
->type
== rdata2
->type
);
148 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
149 REQUIRE(rdata1
->type
== 256);
150 REQUIRE(rdata1
->length
!= 0);
151 REQUIRE(rdata2
->length
!= 0);
153 dns_rdata_toregion(rdata1
, &r1
);
154 dns_rdata_toregion(rdata2
, &r2
);
159 order
= memcmp(r1
.base
, r2
.base
, 2);
161 return (order
< 0 ? -1 : 1);
162 isc_region_consume(&r1
, 2);
163 isc_region_consume(&r2
, 2);
168 order
= memcmp(r1
.base
, r2
.base
, 2);
170 return (order
< 0 ? -1 : 1);
171 isc_region_consume(&r1
, 2);
172 isc_region_consume(&r2
, 2);
174 return (isc_region_compare(&r1
, &r2
));
177 static inline isc_result_t
178 fromstruct_uri(ARGS_FROMSTRUCT
) {
179 dns_rdata_uri_t
*uri
= source
;
181 REQUIRE(type
== 256);
182 REQUIRE(source
!= NULL
);
183 REQUIRE(uri
->common
.rdtype
== type
);
184 REQUIRE(uri
->common
.rdclass
== rdclass
);
185 REQUIRE(uri
->target
!= NULL
&& uri
->tgt_len
!= 0);
193 RETERR(uint16_tobuffer(uri
->priority
, target
));
198 RETERR(uint16_tobuffer(uri
->weight
, target
));
203 return (mem_tobuffer(target
, uri
->target
, uri
->tgt_len
));
206 static inline isc_result_t
207 tostruct_uri(ARGS_TOSTRUCT
) {
208 dns_rdata_uri_t
*uri
= target
;
211 REQUIRE(rdata
->type
== 256);
212 REQUIRE(target
!= NULL
);
213 REQUIRE(rdata
->length
!= 0);
215 uri
->common
.rdclass
= rdata
->rdclass
;
216 uri
->common
.rdtype
= rdata
->type
;
217 ISC_LINK_INIT(&uri
->common
, link
);
219 dns_rdata_toregion(rdata
, &sr
);
225 return (ISC_R_UNEXPECTEDEND
);
226 uri
->priority
= uint16_fromregion(&sr
);
227 isc_region_consume(&sr
, 2);
233 return (ISC_R_UNEXPECTEDEND
);
234 uri
->weight
= uint16_fromregion(&sr
);
235 isc_region_consume(&sr
, 2);
240 uri
->tgt_len
= sr
.length
;
241 uri
->target
= mem_maybedup(mctx
, sr
.base
, sr
.length
);
242 if (uri
->target
== NULL
)
243 return (ISC_R_NOMEMORY
);
246 return (ISC_R_SUCCESS
);
250 freestruct_uri(ARGS_FREESTRUCT
) {
251 dns_rdata_uri_t
*uri
= (dns_rdata_uri_t
*) source
;
253 REQUIRE(source
!= NULL
);
254 REQUIRE(uri
->common
.rdtype
== 256);
256 if (uri
->mctx
== NULL
)
259 if (uri
->target
!= NULL
)
260 isc_mem_free(uri
->mctx
, uri
->target
);
264 static inline isc_result_t
265 additionaldata_uri(ARGS_ADDLDATA
) {
266 REQUIRE(rdata
->type
== 256);
272 return (ISC_R_SUCCESS
);
275 static inline isc_result_t
276 digest_uri(ARGS_DIGEST
) {
279 REQUIRE(rdata
->type
== 256);
281 dns_rdata_toregion(rdata
, &r
);
283 return ((digest
)(arg
, &r
));
286 static inline isc_boolean_t
287 checkowner_uri(ARGS_CHECKOWNER
) {
289 REQUIRE(type
== 256);
299 static inline isc_boolean_t
300 checknames_uri(ARGS_CHECKNAMES
) {
302 REQUIRE(rdata
->type
== 256);
312 casecompare_uri(ARGS_COMPARE
) {
313 return (compare_uri(rdata1
, rdata2
));
316 #endif /* GENERIC_URI_256_C */