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: uri_256.c,v 1.12 2020/02/26 18:47:59 florian Exp $ */
18
19 #ifndef GENERIC_URI_256_C
20 #define GENERIC_URI_256_C 1
21
22 static inline isc_result_t
totext_uri(ARGS_TOTEXT)23 totext_uri(ARGS_TOTEXT) {
24 isc_region_t region;
25 unsigned short priority, weight;
26 char buf[sizeof("65000 ")];
27
28 UNUSED(tctx);
29
30 REQUIRE(rdata->type == dns_rdatatype_uri);
31 REQUIRE(rdata->length != 0);
32
33 dns_rdata_toregion(rdata, ®ion);
34
35 /*
36 * Priority
37 */
38 priority = uint16_fromregion(®ion);
39 isc_region_consume(®ion, 2);
40 snprintf(buf, sizeof(buf), "%u ", priority);
41 RETERR(isc_str_tobuffer(buf, target));
42
43 /*
44 * Weight
45 */
46 weight = uint16_fromregion(®ion);
47 isc_region_consume(®ion, 2);
48 snprintf(buf, sizeof(buf), "%u ", weight);
49 RETERR(isc_str_tobuffer(buf, target));
50
51 /*
52 * Target URI
53 */
54 RETERR(multitxt_totext(®ion, target));
55 return (ISC_R_SUCCESS);
56 }
57
58 static inline isc_result_t
fromwire_uri(ARGS_FROMWIRE)59 fromwire_uri(ARGS_FROMWIRE) {
60 isc_region_t region;
61
62 REQUIRE(type == dns_rdatatype_uri);
63
64 UNUSED(type);
65 UNUSED(rdclass);
66 UNUSED(dctx);
67 UNUSED(options);
68
69 /*
70 * Priority, weight
71 */
72 isc_buffer_activeregion(source, ®ion);
73 if (region.length < 4)
74 return (ISC_R_UNEXPECTEDEND);
75
76 /*
77 * Priority, weight and target URI
78 */
79 isc_buffer_forward(source, region.length);
80 return (isc_mem_tobuffer(target, region.base, region.length));
81 }
82
83 static inline isc_result_t
towire_uri(ARGS_TOWIRE)84 towire_uri(ARGS_TOWIRE) {
85 isc_region_t region;
86
87 REQUIRE(rdata->type == dns_rdatatype_uri);
88 REQUIRE(rdata->length != 0);
89
90 UNUSED(cctx);
91
92 dns_rdata_toregion(rdata, ®ion);
93 return (isc_mem_tobuffer(target, region.base, region.length));
94 }
95
96 #endif /* GENERIC_URI_256_C */
97