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: md_3.c,v 1.11 2020/09/14 08:40:43 florian Exp $ */
18
19 /* Reviewed: Wed Mar 15 17:48:20 PST 2000 by bwelling */
20
21 #ifndef RDATA_GENERIC_MD_3_C
22 #define RDATA_GENERIC_MD_3_C
23
24 static inline isc_result_t
totext_md(ARGS_TOTEXT)25 totext_md(ARGS_TOTEXT) {
26 isc_region_t region;
27 dns_name_t name;
28 dns_name_t prefix;
29 int sub;
30
31 REQUIRE(rdata->type == dns_rdatatype_md);
32 REQUIRE(rdata->length != 0);
33
34 dns_name_init(&name, NULL);
35 dns_name_init(&prefix, NULL);
36
37 dns_rdata_toregion(rdata, ®ion);
38 dns_name_fromregion(&name, ®ion);
39
40 sub = name_prefix(&name, tctx->origin, &prefix);
41
42 return (dns_name_totext(&prefix, sub, target));
43 }
44
45 static inline isc_result_t
fromwire_md(ARGS_FROMWIRE)46 fromwire_md(ARGS_FROMWIRE) {
47 dns_name_t name;
48
49 REQUIRE(type == dns_rdatatype_md);
50
51 UNUSED(type);
52 UNUSED(rdclass);
53
54 dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
55
56 dns_name_init(&name, NULL);
57 return (dns_name_fromwire(&name, source, dctx, options, target));
58 }
59
60 static inline isc_result_t
towire_md(ARGS_TOWIRE)61 towire_md(ARGS_TOWIRE) {
62 dns_name_t name;
63 dns_offsets_t offsets;
64 isc_region_t region;
65
66 REQUIRE(rdata->type == dns_rdatatype_md);
67 REQUIRE(rdata->length != 0);
68
69 dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
70
71 dns_name_init(&name, offsets);
72 dns_rdata_toregion(rdata, ®ion);
73 dns_name_fromregion(&name, ®ion);
74
75 return (dns_name_towire(&name, cctx, target));
76 }
77
78 #endif /* RDATA_GENERIC_MD_3_C */
79