From 3c2d4e69876f4e8af0e3fbf5efa774a2084be67e Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 20 Mar 2024 13:15:56 +0100 Subject: Refactor Multistatus builder to better integrate with REPORT --- aero-dav/src/caldecoder.rs | 16 ++++++++++++++++ aero-dav/src/calencoder.rs | 15 +++++++++++++++ aero-dav/src/caltypes.rs | 8 +++++++- 3 files changed, 38 insertions(+), 1 deletion(-) (limited to 'aero-dav/src') diff --git a/aero-dav/src/caldecoder.rs b/aero-dav/src/caldecoder.rs index b124154..f92cf09 100644 --- a/aero-dav/src/caldecoder.rs +++ b/aero-dav/src/caldecoder.rs @@ -25,6 +25,22 @@ impl QRead> for MkCalendarResponse { } } +impl QRead> for Report { + async fn qread(xml: &mut Reader) -> Result { + match CalendarQuery::::qread(xml).await { + Err(ParsingError::Recoverable) => (), + otherwise => return otherwise.map(Self::Query) + } + + match CalendarMultiget::::qread(xml).await { + Err(ParsingError::Recoverable) => (), + otherwise => return otherwise.map(Self::Multiget), + } + + FreeBusyQuery::qread(xml).await.map(Self::FreeBusy) + } +} + impl QRead> for CalendarQuery { async fn qread(xml: &mut Reader) -> Result { xml.open(CAL_URN, "calendar-query").await?; diff --git a/aero-dav/src/calencoder.rs b/aero-dav/src/calencoder.rs index d4e79dc..d324c7f 100644 --- a/aero-dav/src/calencoder.rs +++ b/aero-dav/src/calencoder.rs @@ -34,6 +34,15 @@ impl QWrite for MkCalendarResponse { } // ----------------------- REPORT METHOD ------------------------------------- +impl QWrite for Report { + async fn qwrite(&self, xml: &mut Writer) -> Result<(), QError> { + match self { + Self::Query(v) => v.qwrite(xml).await, + Self::Multiget(v) => v.qwrite(xml).await, + Self::FreeBusy(v) => v.qwrite(xml).await, + } + } +} impl QWrite for CalendarQuery { async fn qwrite(&self, xml: &mut Writer) -> Result<(), QError> { @@ -335,6 +344,12 @@ impl QWrite for CalendarDataRequest { start.push_attribute(("content-type", mime.content_type.as_str())); start.push_attribute(("version", mime.version.as_str())); } + + // Empty tag + if self.comp.is_none() && self.recurrence.is_none() && self.limit_freebusy_set.is_none() { + return xml.q.write_event_async(Event::Empty(start.clone())).await + } + let end = start.to_end(); xml.q.write_event_async(Event::Start(start.clone())).await?; if let Some(comp) = &self.comp { diff --git a/aero-dav/src/caltypes.rs b/aero-dav/src/caltypes.rs index 602498c..08991a0 100644 --- a/aero-dav/src/caltypes.rs +++ b/aero-dav/src/caltypes.rs @@ -51,6 +51,12 @@ pub struct MkCalendar(pub dav::Set); pub struct MkCalendarResponse(pub Vec>); // --- (REPORT PART) --- +#[derive(Debug, PartialEq, Clone)] +pub enum Report { + Query(CalendarQuery), + Multiget(CalendarMultiget), + FreeBusy(FreeBusyQuery), +} /// Name: calendar-query /// @@ -827,7 +833,7 @@ pub struct CalendarDataPayload { /// when nested in the DAV:prop XML element in a calendaring /// REPORT request to specify which parts of calendar object /// resources should be returned in the response; -#[derive(Debug, PartialEq, Clone)] +#[derive(Debug, PartialEq, Clone, Default)] pub struct CalendarDataRequest { pub mime: Option, pub comp: Option, -- cgit v1.2.3