From 18f2154151b2cf81e03bdda28fa2ea5d685e33d1 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 28 May 2024 16:03:25 +0200 Subject: implement propfind sync-token --- aero-dav/src/syncdecoder.rs | 14 ++++++-------- aero-dav/src/syncencoder.rs | 7 +++++-- aero-dav/src/synctypes.rs | 2 +- aero-dav/src/versioningdecoder.rs | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) (limited to 'aero-dav/src') diff --git a/aero-dav/src/syncdecoder.rs b/aero-dav/src/syncdecoder.rs index be25b79..2a61dea 100644 --- a/aero-dav/src/syncdecoder.rs +++ b/aero-dav/src/syncdecoder.rs @@ -7,10 +7,11 @@ use super::xml::{IRead, QRead, Reader, DAV_URN}; impl QRead for PropertyRequest { async fn qread(xml: &mut Reader) -> Result { - let mut dirty = false; - let mut m_cdr = None; - xml.maybe_read(&mut m_cdr, &mut dirty).await?; - m_cdr.ok_or(ParsingError::Recoverable).map(Self::SyncToken) + if xml.maybe_open(DAV_URN, "sync-token").await?.is_some() { + xml.close().await?; + return Ok(Self::SyncToken); + } + return Err(ParsingError::Recoverable); } } @@ -88,7 +89,6 @@ 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?; @@ -213,9 +213,7 @@ mod tests { #[tokio::test] async fn prop_req() { let expected = dav::PropName::(vec![dav::PropertyRequest::Extension( - realization::PropertyRequest::Sync(PropertyRequest::SyncToken( - SyncTokenRequest::InitialSync, - )), + realization::PropertyRequest::Sync(PropertyRequest::SyncToken), )]); let src = r#""#; let got = deserialize::>(src).await; diff --git a/aero-dav/src/syncencoder.rs b/aero-dav/src/syncencoder.rs index 8badc92..2dd50eb 100644 --- a/aero-dav/src/syncencoder.rs +++ b/aero-dav/src/syncencoder.rs @@ -16,7 +16,10 @@ impl QWrite for Property { impl QWrite for PropertyRequest { async fn qwrite(&self, xml: &mut Writer) -> Result<(), QError> { match self { - Self::SyncToken(token) => token.qwrite(xml).await, + Self::SyncToken => { + let start = xml.create_dav_element("sync-token"); + xml.q.write_event_async(Event::Empty(start)).await + } } } } @@ -180,7 +183,7 @@ mod tests { async fn prop_req() { serialize_deserialize(&dav::PropName::(vec![ dav::PropertyRequest::Extension(realization::PropertyRequest::Sync( - PropertyRequest::SyncToken(SyncTokenRequest::InitialSync), + PropertyRequest::SyncToken, )), ])) .await; diff --git a/aero-dav/src/synctypes.rs b/aero-dav/src/synctypes.rs index cbd86b8..2a14221 100644 --- a/aero-dav/src/synctypes.rs +++ b/aero-dav/src/synctypes.rs @@ -6,7 +6,7 @@ use super::versioningtypes as vers; #[derive(Debug, PartialEq, Clone)] pub enum PropertyRequest { - SyncToken(SyncTokenRequest), + SyncToken, } #[derive(Debug, PartialEq, Clone)] diff --git a/aero-dav/src/versioningdecoder.rs b/aero-dav/src/versioningdecoder.rs index c28c0d5..a0a3ddf 100644 --- a/aero-dav/src/versioningdecoder.rs +++ b/aero-dav/src/versioningdecoder.rs @@ -21,7 +21,7 @@ impl QRead for PropertyRequest { impl QRead> for Property { async fn qread(xml: &mut Reader) -> Result { if xml - .maybe_open(DAV_URN, "supported-report-set") + .maybe_open_start(DAV_URN, "supported-report-set") .await? .is_some() { -- cgit v1.2.3