aboutsummaryrefslogtreecommitdiff
path: root/aero-dav/src/acldecoder.rs
blob: 67dfb0ba9b5a44d43348dced61629df01f72c2ed (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use super::acltypes::*;
use super::types as dav;
use super::xml::{QRead, Reader, IRead, DAV_URN};
use super::error::ParsingError;

impl QRead<Property> for Property {
    async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
        if xml.maybe_open_start(DAV_URN, "owner").await?.is_some() {
            let href = xml.find().await?;
            xml.close().await?;
            return Ok(Self::Owner(href))
        }
        if xml.maybe_open_start(DAV_URN, "current-user-principal").await?.is_some() {
            let user = xml.find().await?;
            xml.close().await?;
            return Ok(Self::CurrentUserPrincipal(user))
        }
        if xml.maybe_open_start(DAV_URN, "current-user-privilege-set").await?.is_some() {
            xml.close().await?;
            return Ok(Self::CurrentUserPrivilegeSet(vec![]))
        }

        Err(ParsingError::Recoverable)
    }
}

impl QRead<PropertyRequest> for PropertyRequest {
    async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
        if xml.maybe_open(DAV_URN, "owner").await?.is_some() {
            xml.close().await?;
            return Ok(Self::Owner)
        }

        if xml.maybe_open(DAV_URN, "current-user-principal").await?.is_some() {
            xml.close().await?;
            return Ok(Self::CurrentUserPrincipal)
        }

        if xml.maybe_open(DAV_URN, "current-user-privilege-set").await?.is_some() {
            xml.close().await?;
            return Ok(Self::CurrentUserPrivilegeSet)
        }

        Err(ParsingError::Recoverable)
    }
}

impl QRead<ResourceType> for ResourceType {
    async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
        if xml.maybe_open(DAV_URN, "principal").await?.is_some() {
            xml.close().await?;
            return Ok(Self::Principal)
        }
        Err(ParsingError::Recoverable)
    }
}

// -----
impl QRead<User> for User {
    async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
        if xml.maybe_open(DAV_URN, "unauthenticated").await?.is_some() {
            xml.close().await?;
            return Ok(Self::Unauthenticated)
        }

        dav::Href::qread(xml).await.map(Self::Authenticated)
    }
}