Skip to main content

contacts_client/
compliance.rs

1
2/// Compliance classes reported in the `DAV` header [RFC 4981 section 10.1]
3///
4/// [RFC 4981 section 10.1]:
5///    https://datatracker.ietf.org/doc/html/rfc4918#section-10.1
6#[derive(Debug)]
7#[derive(Default)]
8pub struct Compliance {
9    /// Compliance Class 1 [RFC 4918 section 18.1]
10    ///
11    /// [RFC 4918 section 18.1]:
12    ///    https://datatracker.ietf.org/doc/html/rfc4918#section-18.1
13    pub class_1: bool,
14
15    /// Compliance Class 2 [RFC 4918 section 18.2]
16    ///
17    /// [RFC 4918 section 18.2]:
18    ///    https://datatracker.ietf.org/doc/html/rfc4918#section-18.2
19    pub class_2: bool,
20
21    /// Compliance Class 3 [RFC 4918 section 18.3]
22    ///
23    /// [RFC 4918 section 18.3]:
24    ///    https://datatracker.ietf.org/doc/html/rfc4918#section-18.3
25    pub class_3: bool,
26
27    /// Access Control (ACL) support [RFC 3744 section 7.2]
28    ///
29    /// [RFC 3744 section 7.2]:
30    ///    https://datatracker.ietf.org/doc/html/rfc3744#section-7.2
31    pub access_control: bool,
32
33    /// Address Book support [RFC 6352 section 6.1]
34    ///
35    /// [RFC 6352 section 6.1]:
36    ///    https://datatracker.ietf.org/doc/html/rfc6352#section-6.1
37    pub address_book: bool,
38
39    pub extensions: Vec<String>,
40}
41
42impl Compliance {
43    fn from_str(dav: &str) -> Self {
44        let mut compliance = Self::default();
45
46        for class in dav.split(',') {
47            let class = class.trim_ascii();
48
49            match class {
50                "1" =>
51                    compliance.class_1 = true,
52                "2" =>
53                    compliance.class_2 = true,
54                "3" =>
55                    compliance.class_3 = true,
56                "access-control" =>
57                    compliance.access_control = true,
58                "addressbook" =>
59                    compliance.address_book = true,
60                _ =>
61                    compliance.extensions.push(class.to_string()),
62            }
63        }
64
65        compliance
66    }
67
68    pub fn has_extension(&self, has: &str) -> bool {
69        self.extensions
70            .iter()
71            .find(|extension| *extension == has)
72            .is_some()
73    }
74}
75