aboutsummaryrefslogtreecommitdiff
path: root/aero-dav
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2024-05-28 13:59:40 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2024-05-28 13:59:40 +0200
commit171a762768aabd799a1012d2fb939d869ff53f7b (patch)
treef375107c43ea3e57762548c777c5a8b9d15e6f69 /aero-dav
parent410d663a5ecbb6ca46ac049227afdaaaf50ac27f (diff)
downloadaerogramme-171a762768aabd799a1012d2fb939d869ff53f7b.tar.gz
aerogramme-171a762768aabd799a1012d2fb939d869ff53f7b.zip
implement sync multistatus extension
Diffstat (limited to 'aero-dav')
-rw-r--r--aero-dav/src/realization.rs24
-rw-r--r--aero-dav/src/syncdecoder.rs9
-rw-r--r--aero-dav/src/syncencoder.rs26
-rw-r--r--aero-dav/src/synctypes.rs5
4 files changed, 63 insertions, 1 deletions
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<All>;
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<impl xml::IWrite>,
+ ) -> Result<(), quick_xml::Error> {
+ match self {
+ Self::Sync(s) => s.qwrite(xml).await,
+ }
+ }
+}
+
+impl xml::QRead<Multistatus> for Multistatus {
+ async fn qread(xml: &mut xml::Reader<impl xml::IRead>) -> Result<Self, error::ParsingError> {
+ 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<ReportTypeName> for ReportTypeName {
}
}
+impl QRead<Multistatus> for Multistatus {
+ async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
+ SyncToken::qread(xml)
+ .await
+ .map(|sync_token| Multistatus { sync_token })
+ }
+}
+
impl<E: dav::Extension> QRead<SyncCollection<E>> for SyncCollection<E> {
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
xml.open(DAV_URN, "sync-collection").await?;
@@ -80,6 +88,7 @@ impl QRead<SyncTokenRequest> for SyncTokenRequest {
impl QRead<SyncToken> for SyncToken {
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
+ 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<impl IWrite>) -> Result<(), QError> {
+ self.sync_token.qwrite(xml).await
+ }
+}
+
impl<E: Extension> QWrite for SyncCollection<E> {
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> 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::<All> {
+ 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