aboutsummaryrefslogtreecommitdiff
path: root/aero-dav/src/acldecoder.rs
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2024-05-29 10:14:51 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2024-05-29 10:14:51 +0200
commitb9ce5886033677f6c65a4b873e17574fdb8df31d (patch)
tree9ed1d721361027d7d6fef0ecad65d7e1b74a7ddb /aero-dav/src/acldecoder.rs
parent0dcf69f180f5a7b71b6ad2ac67e4cdd81e5154f1 (diff)
parent5954de6efbb040b8b47daf0c7663a60f3db1da6e (diff)
downloadaerogramme-b9ce5886033677f6c65a4b873e17574fdb8df31d.tar.gz
aerogramme-b9ce5886033677f6c65a4b873e17574fdb8df31d.zip
Merge branch 'caldav'
Diffstat (limited to 'aero-dav/src/acldecoder.rs')
-rw-r--r--aero-dav/src/acldecoder.rs84
1 files changed, 84 insertions, 0 deletions
diff --git a/aero-dav/src/acldecoder.rs b/aero-dav/src/acldecoder.rs
new file mode 100644
index 0000000..405286e
--- /dev/null
+++ b/aero-dav/src/acldecoder.rs
@@ -0,0 +1,84 @@
+use super::acltypes::*;
+use super::error::ParsingError;
+use super::types as dav;
+use super::xml::{IRead, QRead, Reader, DAV_URN};
+
+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)
+ }
+}