aboutsummaryrefslogtreecommitdiff
path: root/aero-dav/src/aclencoder.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/aclencoder.rs
parent0dcf69f180f5a7b71b6ad2ac67e4cdd81e5154f1 (diff)
parent5954de6efbb040b8b47daf0c7663a60f3db1da6e (diff)
downloadaerogramme-b9ce5886033677f6c65a4b873e17574fdb8df31d.tar.gz
aerogramme-b9ce5886033677f6c65a4b873e17574fdb8df31d.zip
Merge branch 'caldav'
Diffstat (limited to 'aero-dav/src/aclencoder.rs')
-rw-r--r--aero-dav/src/aclencoder.rs71
1 files changed, 71 insertions, 0 deletions
diff --git a/aero-dav/src/aclencoder.rs b/aero-dav/src/aclencoder.rs
new file mode 100644
index 0000000..28c01a7
--- /dev/null
+++ b/aero-dav/src/aclencoder.rs
@@ -0,0 +1,71 @@
+use quick_xml::events::Event;
+use quick_xml::Error as QError;
+
+use super::acltypes::*;
+use super::error::ParsingError;
+use super::xml::{IWrite, QWrite, Writer};
+
+impl QWrite for Property {
+ async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
+ match self {
+ Self::Owner(href) => {
+ let start = xml.create_dav_element("owner");
+ let end = start.to_end();
+ xml.q.write_event_async(Event::Start(start.clone())).await?;
+ href.qwrite(xml).await?;
+ xml.q.write_event_async(Event::End(end)).await
+ }
+ Self::CurrentUserPrincipal(user) => {
+ let start = xml.create_dav_element("current-user-principal");
+ let end = start.to_end();
+ xml.q.write_event_async(Event::Start(start.clone())).await?;
+ user.qwrite(xml).await?;
+ xml.q.write_event_async(Event::End(end)).await
+ }
+ Self::CurrentUserPrivilegeSet(_) => {
+ let empty_tag = xml.create_dav_element("current-user-privilege-set");
+ xml.q.write_event_async(Event::Empty(empty_tag)).await
+ }
+ }
+ }
+}
+
+impl QWrite for PropertyRequest {
+ async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
+ let mut atom = async |c| {
+ let empty_tag = xml.create_dav_element(c);
+ xml.q.write_event_async(Event::Empty(empty_tag)).await
+ };
+
+ match self {
+ Self::Owner => atom("owner").await,
+ Self::CurrentUserPrincipal => atom("current-user-principal").await,
+ Self::CurrentUserPrivilegeSet => atom("current-user-privilege-set").await,
+ }
+ }
+}
+
+impl QWrite for ResourceType {
+ async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
+ match self {
+ Self::Principal => {
+ let empty_tag = xml.create_dav_element("principal");
+ xml.q.write_event_async(Event::Empty(empty_tag)).await
+ }
+ }
+ }
+}
+
+// -----
+
+impl QWrite for User {
+ async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
+ match self {
+ Self::Unauthenticated => {
+ let tag = xml.create_dav_element("unauthenticated");
+ xml.q.write_event_async(Event::Empty(tag)).await
+ }
+ Self::Authenticated(href) => href.qwrite(xml).await,
+ }
+ }
+}