domain/rdata/rfc1035/
name.rs

1//! Record data type from RFC 1035 that consist of a single domain name.
2//!
3//! This is a private module. It’s content is re-exported by the parent.
4
5use crate::base::cmp::CanonicalOrd;
6use crate::base::name::{ParsedName, ToName};
7use crate::base::wire::ParseError;
8use core::{fmt, hash, str};
9use core::cmp::Ordering;
10use core::str::FromStr;
11use octseq::octets::{Octets, OctetsFrom};
12use octseq::parse::Parser;
13
14//------------ Cname --------------------------------------------------------
15
16name_type_well_known! {
17    /// CNAME record data.
18    ///
19    /// The CNAME record specifies the canonical or primary name for domain
20    /// name alias.
21    ///
22    /// The CNAME type is defined in [RFC 1035, section 3.3.1][1].
23    /// 
24    /// [1]: https://tools.ietf.org/html/rfc1035#section-3.3.1
25    (Cname, CNAME, cname, into_cname)
26}
27
28//------------ Mb -----------------------------------------------------------
29
30name_type_well_known! {
31    /// MB record data.
32    ///
33    /// The experimental MB record specifies a host that serves a mailbox.
34    ///
35    /// The MB record type is defined in [RFC 1035, section 3.3.3][1].
36    /// 
37    /// [1]: https://tools.ietf.org/html/rfc1035#section-3.3.3
38    (Mb, MB, madname, into_madname)
39}
40
41//------------ Md -----------------------------------------------------------
42
43name_type_well_known! {
44    /// MD record data.
45    ///
46    /// The MD record specifices a host which has a mail agent for
47    /// the domain which should be able to deliver mail for the domain.
48    ///
49    /// The MD record is obsolete. It is recommended to either reject the record
50    /// or convert them into an Mx record at preference 0.
51    ///
52    /// The MD record type is defined in [RFC 1035, section 3.3.4][1].
53    /// 
54    /// [1]: https://tools.ietf.org/html/rfc1035#section-3.3.4
55    (Md, MD, madname, into_madname)
56}
57
58//------------ Mf -----------------------------------------------------------
59
60name_type_well_known! {
61    /// MF record data.
62    ///
63    /// The MF record specifices a host which has a mail agent for
64    /// the domain which will be accept mail for forwarding to the domain.
65    ///
66    /// The MF record is obsolete. It is recommended to either reject the record
67    /// or convert them into an Mx record at preference 10.
68    ///
69    /// The MF record type is defined in [RFC 1035, section 3.3.5][1].
70    /// 
71    /// [1]: https://tools.ietf.org/html/rfc1035#section-3.3.5
72    (Mf, MF, madname, into_madname)
73}
74
75//------------ Mg -----------------------------------------------------------
76
77name_type_well_known! {
78    /// MG record data.
79    ///
80    /// The MG record specifices a mailbox which is a member of the mail group
81    /// specified by the domain name.
82    ///
83    /// The MG record is experimental.
84    ///
85    /// The MG record type is defined in [RFC 1035, section 3.3.6][1].
86    /// 
87    /// [1]: https://tools.ietf.org/html/rfc1035#section-3.3.6
88    (Mg, MG, madname, into_madname)
89}
90
91//------------ Mr -----------------------------------------------------------
92
93name_type_well_known! {
94    /// MR record data.
95    ///
96    /// The MR record specifices a mailbox which is the proper rename of the
97    /// specified mailbox.
98    ///
99    /// The MR record is experimental.
100    ///
101    /// The MR record type is defined in [RFC 1035, section 3.3.8][1].
102    /// 
103    /// [1]: https://tools.ietf.org/html/rfc1035#section-3.3.8
104    (Mr, MR, newname, into_newname)
105}
106
107//------------ Ns -----------------------------------------------------------
108
109name_type_well_known! {
110    /// NS record data.
111    ///
112    /// NS records specify hosts that are authoritative for a class and domain.
113    ///
114    /// The NS record type is defined in [RFC 1035, section 3.3.11][1].
115    /// 
116    /// [1]: https://tools.ietf.org/html/rfc1035#section-3.3.11
117    (Ns, NS, nsdname, into_nsdname)
118}
119
120//------------ Ptr ----------------------------------------------------------
121
122name_type_well_known! {
123    /// PTR record data.
124    ///
125    /// PRT records are used in special domains to point to some other location
126    /// in the domain space.
127    ///
128    /// The PTR record type is defined in [RFC 1035, section 3.3.12][1].
129    /// 
130    /// [1]: https://tools.ietf.org/html/rfc1035#section-3.3.12
131    (Ptr, PTR, ptrdname, into_ptrdname)
132}
133
134//============ Testing =======================================================
135
136#[cfg(test)]
137#[cfg(all(feature = "std", feature = "bytes"))]
138mod test {
139    use super::*;
140    use crate::base::name::Name;
141    use crate::base::rdata::test::{
142        test_compose_parse, test_rdlen, test_scan,
143    };
144    use std::vec::Vec;
145
146    // We only test Cname since all the other types are exactly the same.
147
148    #[test]
149    #[allow(clippy::redundant_closure)] // lifetimes ...
150    fn cname_compose_parse_scan() {
151        let rdata =
152            Cname::<Name<Vec<u8>>>::from_str("www.example.com").unwrap();
153        test_rdlen(&rdata);
154        test_compose_parse(&rdata, |parser| Cname::parse(parser));
155        test_scan(&["www.example.com"], Cname::scan, &rdata);
156    }
157}
158