diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2024-03-03 11:08:00 +0100 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2024-03-03 11:08:00 +0100 |
commit | 463be750e1b053f7a93eff9e91fc52e962ef3f18 (patch) | |
tree | adf46e55fd981d578f7d338c4333b8e841f8364e | |
parent | 433e1f97f6d83bc11134df36de03e47b9393582b (diff) | |
download | aerogramme-463be750e1b053f7a93eff9e91fc52e962ef3f18.tar.gz aerogramme-463be750e1b053f7a93eff9e91fc52e962ef3f18.zip |
CalEncoder should be fully implemented now
-rw-r--r-- | src/dav/calencoder.rs | 41 | ||||
-rw-r--r-- | 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<C: CalContext> QuickWritable<C> for ParamFilterMatch { impl<C: CalContext> QuickWritable<C> for TimeZone { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { - unimplemented!(); - } -} - -impl<C: CalContext> QuickWritable<C> for Filter { - async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { - unimplemented!(); - } -} + let mut start = ctx.create_cal_element("timezone"); + let end = start.to_end(); -impl<C: CalContext> QuickWritable<C> for Component { - async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, 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<C: CalContext> QuickWritable<C> for ComponentProperty { +impl<C: CalContext> QuickWritable<C> for Filter { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { - unimplemented!(); - } -} + let mut start = ctx.create_cal_element("filter"); + let end = start.to_end(); -impl<C: CalContext> QuickWritable<C> for PropertyParameter { - async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, 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<C: CalContext> QuickWritable<C> for TimeRange { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, 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(), - } - } -} - /// <!ELEMENT calendar-data (#PCDATA)> /// PCDATA value: iCalendar object @@ -1328,7 +1311,7 @@ pub enum ParamFilterMatch { /// /// <!ELEMENT timezone (#PCDATA)> /// 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: /// <!ELEMENT filter (comp-filter)> -pub struct Filter(CompFilter); +pub struct Filter(pub CompFilter); + +/// Name: time-range +/// +/// Definition: +/// +/// <!ELEMENT time-range EMPTY> +/// <!ATTLIST time-range start CDATA #IMPLIED +/// end CDATA #IMPLIED> +/// start value: an iCalendar "date with UTC time" +/// end value: an iCalendar "date with UTC time" +pub enum TimeRange { + OnlyStart(DateTime<Utc>), + OnlyEnd(DateTime<Utc>), + FullRange(DateTime<Utc>, DateTime<Utc>), +} + +// ----------------------- 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: -/// -/// <!ELEMENT time-range EMPTY> -/// <!ATTLIST time-range start CDATA #IMPLIED -/// end CDATA #IMPLIED> -/// start value: an iCalendar "date with UTC time" -/// end value: an iCalendar "date with UTC time" -pub enum TimeRange { - OnlyStart(DateTime<Utc>), - OnlyEnd(DateTime<Utc>), - FullRange(DateTime<Utc>, DateTime<Utc>), +#[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(), + } + } } |