From 171a762768aabd799a1012d2fb939d869ff53f7b Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 28 May 2024 13:59:40 +0200 Subject: implement sync multistatus extension --- aero-dav/src/realization.rs | 24 +++++++++++++++++++++++- aero-dav/src/syncdecoder.rs | 9 +++++++++ aero-dav/src/syncencoder.rs | 26 ++++++++++++++++++++++++++ aero-dav/src/synctypes.rs | 5 +++++ 4 files changed, 63 insertions(+), 1 deletion(-) (limited to 'aero-dav/src') diff --git a/aero-dav/src/realization.rs b/aero-dav/src/realization.rs index 1e6f25e..76170f8 100644 --- a/aero-dav/src/realization.rs +++ b/aero-dav/src/realization.rs @@ -74,7 +74,7 @@ impl dav::Extension for All { type ResourceType = ResourceType; type ReportType = ReportType; type ReportTypeName = ReportTypeName; - type Multistatus = Disabled; + type Multistatus = Multistatus; } #[derive(Debug, PartialEq, Clone)] @@ -236,3 +236,25 @@ impl xml::QWrite for ReportTypeName { } } } + +#[derive(Debug, PartialEq, Clone)] +pub enum Multistatus { + Sync(sync::Multistatus), +} + +impl xml::QWrite for Multistatus { + async fn qwrite( + &self, + xml: &mut xml::Writer, + ) -> Result<(), quick_xml::Error> { + match self { + Self::Sync(s) => s.qwrite(xml).await, + } + } +} + +impl xml::QRead for Multistatus { + async fn qread(xml: &mut xml::Reader) -> Result { + sync::Multistatus::qread(xml).await.map(Self::Sync) + } +} diff --git a/aero-dav/src/syncdecoder.rs b/aero-dav/src/syncdecoder.rs index d81f8d4..be25b79 100644 --- a/aero-dav/src/syncdecoder.rs +++ b/aero-dav/src/syncdecoder.rs @@ -33,6 +33,14 @@ impl QRead for ReportTypeName { } } +impl QRead for Multistatus { + async fn qread(xml: &mut Reader) -> Result { + SyncToken::qread(xml) + .await + .map(|sync_token| Multistatus { sync_token }) + } +} + impl QRead> for SyncCollection { async fn qread(xml: &mut Reader) -> Result { xml.open(DAV_URN, "sync-collection").await?; @@ -80,6 +88,7 @@ impl QRead for SyncTokenRequest { impl QRead for SyncToken { async fn qread(xml: &mut Reader) -> Result { + println!("sync_token {:?}", xml.peek()); xml.open(DAV_URN, "sync-token").await?; let token = xml.tag_string().await?; xml.close().await?; diff --git a/aero-dav/src/syncencoder.rs b/aero-dav/src/syncencoder.rs index 59ad6cc..8badc92 100644 --- a/aero-dav/src/syncencoder.rs +++ b/aero-dav/src/syncencoder.rs @@ -32,6 +32,12 @@ impl QWrite for ReportTypeName { } } +impl QWrite for Multistatus { + async fn qwrite(&self, xml: &mut Writer) -> Result<(), QError> { + self.sync_token.qwrite(xml).await + } +} + impl QWrite for SyncCollection { async fn qwrite(&self, xml: &mut Writer) -> Result<(), QError> { let start = xml.create_dav_element("sync-collection"); @@ -196,4 +202,24 @@ mod tests { ])) .await; } + + #[tokio::test] + async fn multistatus_ext() { + serialize_deserialize(&dav::Multistatus:: { + responses: vec![dav::Response { + status_or_propstat: dav::StatusOrPropstat::Status( + vec![dav::Href("/".into())], + dav::Status(http::status::StatusCode::OK), + ), + error: None, + location: None, + responsedescription: None, + }], + responsedescription: None, + extension: Some(realization::Multistatus::Sync(Multistatus { + sync_token: SyncToken("http://example.com/ns/sync/1232".into()), + })), + }) + .await; + } } diff --git a/aero-dav/src/synctypes.rs b/aero-dav/src/synctypes.rs index c127962..cbd86b8 100644 --- a/aero-dav/src/synctypes.rs +++ b/aero-dav/src/synctypes.rs @@ -19,6 +19,11 @@ pub enum ReportTypeName { SyncCollection, } +#[derive(Debug, PartialEq, Clone)] +pub struct Multistatus { + pub sync_token: SyncToken, +} + //@FIXME add SyncToken to Multistatus /// Name: sync-collection -- cgit v1.2.3