From 61ee5f153b01c8a0927f0e4547c8c655ede912ed Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Sat, 2 Mar 2024 19:01:20 +0100 Subject: [PATCH] Serialize calendar-data --- src/dav/calencoder.rs | 58 +++++++++++++++++++++++++++++++++++-------- src/dav/caltypes.rs | 16 ++++++------ 2 files changed, 55 insertions(+), 19 deletions(-) diff --git a/src/dav/calencoder.rs b/src/dav/calencoder.rs index 1016a20..73db4fa 100644 --- a/src/dav/calencoder.rs +++ b/src/dav/calencoder.rs @@ -319,37 +319,73 @@ impl QuickWritable for Violation { // ---------------------------- Inner XML ------------------------------------ impl QuickWritable for SupportedCollation { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); + let start = ctx.create_cal_element("supported-collation"); + let end = start.to_end(); + + xml.write_event_async(Event::Start(start.clone())).await?; + self.0.write(xml, ctx.child()).await?; + xml.write_event_async(Event::End(end)).await + } } impl QuickWritable for Collation { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); + let col = match self { + Self::AsciiCaseMap => "i;ascii-casemap", + Self::Octet => "i;octet", + Self::Unknown(v) => v.as_str(), + }; + + xml.write_event_async(Event::Text(BytesText::new(col))).await } } impl QuickWritable for CalendarDataPayload { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); + let mut start = ctx.create_cal_element("calendar-data"); + if let Some(mime) = &self.mime { + start.push_attribute(("content-type", mime.content_type.as_str())); + start.push_attribute(("version", mime.version.as_str())); + } + let end = start.to_end(); + + xml.write_event_async(Event::Start(start.clone())).await?; + xml.write_event_async(Event::Text(BytesText::new(self.payload.as_str()))).await?; + xml.write_event_async(Event::End(end)).await } } impl QuickWritable for CalendarDataRequest { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); + let mut start = ctx.create_cal_element("calendar-data"); + if let Some(mime) = &self.mime { + start.push_attribute(("content-type", mime.content_type.as_str())); + start.push_attribute(("version", mime.version.as_str())); + } + let end = start.to_end(); + xml.write_event_async(Event::Start(start.clone())).await?; + if let Some(comp) = &self.comp { + comp.write(xml, ctx.child()).await?; + } + if let Some(recurrence) = &self.recurrence { + recurrence.write(xml, ctx.child()).await?; + } + if let Some(freebusy) = &self.limit_freebusy_set { + freebusy.write(xml, ctx.child()).await?; + } + xml.write_event_async(Event::End(end)).await } } impl QuickWritable for CalendarDataEmpty { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); - } -} - -impl QuickWritable for CalendarDataSupport { - async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); + let mut empty = ctx.create_cal_element("calendar-data"); + if let Some(mime) = &self.0 { + empty.push_attribute(("content-type", mime.content_type.as_str())); + empty.push_attribute(("version", mime.version.as_str())); + } + xml.write_event_async(Event::Empty(empty)).await } } diff --git a/src/dav/caltypes.rs b/src/dav/caltypes.rs index 29dc02f..97d75c5 100644 --- a/src/dav/caltypes.rs +++ b/src/dav/caltypes.rs @@ -770,7 +770,7 @@ pub enum Violation { /// If the client chooses a collation not supported by the server, the /// server MUST respond with a CALDAV:supported-collation precondition /// error response. -pub struct SupportedCollation(Collation); +pub struct SupportedCollation(pub Collation); #[derive(Default)] pub enum Collation { #[default] @@ -799,10 +799,10 @@ pub struct CalendarDataPayload { /// REPORT request to specify which parts of calendar object /// resources should be returned in the response; pub struct CalendarDataRequest { - mime: Option, - comp: Option, - reccurence: Option, - limit_freebusy_set: Option, + pub mime: Option, + pub comp: Option, + pub recurrence: Option, + pub limit_freebusy_set: Option, } /// calendar-data specialization for Property @@ -812,7 +812,7 @@ pub struct CalendarDataRequest { /// when nested in the CALDAV:supported-calendar-data property /// to specify a supported media type for calendar object /// resources; -pub struct CalendarDataEmpty(Option); +pub struct CalendarDataEmpty(pub Option); /// @@ -821,8 +821,8 @@ pub struct CalendarDataEmpty(Option); /// attributes can be used on all three variants of the /// CALDAV:calendar-data XML element. pub struct CalendarDataSupport { - content_type: String, - version: String, + pub content_type: String, + pub version: String, } /// Name: comp