From 463be750e1b053f7a93eff9e91fc52e962ef3f18 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Sun, 3 Mar 2024 11:08:00 +0100 Subject: CalEncoder should be fully implemented now --- src/dav/calencoder.rs | 41 ++++++++++++++++--------------- src/dav/caltypes.rs | 68 ++++++++++++++++++++++++++------------------------- 2 files changed, 56 insertions(+), 53 deletions(-) diff --git a/src/dav/calencoder.rs b/src/dav/calencoder.rs index 503d48b..05d0454 100644 --- a/src/dav/calencoder.rs +++ b/src/dav/calencoder.rs @@ -638,37 +638,38 @@ impl QuickWritable for ParamFilterMatch { impl QuickWritable for TimeZone { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); - } -} - -impl QuickWritable for Filter { - async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); - } -} + let mut start = ctx.create_cal_element("timezone"); + let end = start.to_end(); -impl QuickWritable for Component { - async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); + xml.write_event_async(Event::Start(start.clone())).await?; + xml.write_event_async(Event::Text(BytesText::new(self.0.as_str()))).await?; + xml.write_event_async(Event::End(end)).await } } -impl QuickWritable for ComponentProperty { +impl QuickWritable for Filter { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); - } -} + let mut start = ctx.create_cal_element("filter"); + let end = start.to_end(); -impl QuickWritable for PropertyParameter { - async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); + 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 TimeRange { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); + let mut empty = ctx.create_cal_element("time-range"); + match self { + Self::OnlyStart(start) => empty.push_attribute(("start", format!("{}", start.format(ICAL_DATETIME_FMT)).as_str())), + Self::OnlyEnd(end) => empty.push_attribute(("end", format!("{}", end.format(ICAL_DATETIME_FMT)).as_str())), + Self::FullRange(start, end) => { + empty.push_attribute(("start", format!("{}", start.format(ICAL_DATETIME_FMT)).as_str())); + empty.push_attribute(("end", format!("{}", end.format(ICAL_DATETIME_FMT)).as_str())); + } + } + xml.write_event_async(Event::Empty(empty)).await } } diff --git a/src/dav/caltypes.rs b/src/dav/caltypes.rs index 5d30600..9f4dfd6 100644 --- a/src/dav/caltypes.rs +++ b/src/dav/caltypes.rs @@ -771,23 +771,6 @@ pub enum Violation { /// server MUST respond with a CALDAV:supported-collation precondition /// error response. pub struct SupportedCollation(pub Collation); -#[derive(Default)] -pub enum Collation { - #[default] - AsciiCaseMap, - Octet, - Unknown(String), -} -impl Collation { - pub fn as_str<'a>(&'a self) -> &'a str { - match self { - Self::AsciiCaseMap => "i;ascii-casemap", - Self::Octet => "i;octet", - Self::Unknown(c) => c.as_str(), - } - } -} - /// /// PCDATA value: iCalendar object @@ -1328,7 +1311,7 @@ pub enum ParamFilterMatch { /// /// /// PCDATA value: an iCalendar object with exactly one VTIMEZONE -pub struct TimeZone(String); +pub struct TimeZone(pub String); /// Name: filter /// @@ -1343,7 +1326,24 @@ pub struct TimeZone(String); /// /// Definition: /// -pub struct Filter(CompFilter); +pub struct Filter(pub CompFilter); + +/// Name: time-range +/// +/// Definition: +/// +/// +/// +/// start value: an iCalendar "date with UTC time" +/// end value: an iCalendar "date with UTC time" +pub enum TimeRange { + OnlyStart(DateTime), + OnlyEnd(DateTime), + FullRange(DateTime, DateTime), +} + +// ----------------------- ENUM ATTRIBUTES --------------------- /// Known components pub enum Component { @@ -1355,7 +1355,7 @@ pub enum Component { VAlarm, Unknown(String), } -impl Component { +impl Component { pub fn as_str<'a>(&'a self) -> &'a str { match self { Self::VCalendar => "VCALENDAR", @@ -1382,17 +1382,19 @@ impl PropertyParameter { } } -/// Name: time-range -/// -/// Definition: -/// -/// -/// -/// start value: an iCalendar "date with UTC time" -/// end value: an iCalendar "date with UTC time" -pub enum TimeRange { - OnlyStart(DateTime), - OnlyEnd(DateTime), - FullRange(DateTime, DateTime), +#[derive(Default)] +pub enum Collation { + #[default] + AsciiCaseMap, + Octet, + Unknown(String), +} +impl Collation { + pub fn as_str<'a>(&'a self) -> &'a str { + match self { + Self::AsciiCaseMap => "i;ascii-casemap", + Self::Octet => "i;octet", + Self::Unknown(c) => c.as_str(), + } + } } -- cgit v1.2.3