diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/dav/calencoder.rs | 55 | ||||
-rw-r--r-- | src/dav/caltypes.rs | 29 | ||||
-rw-r--r-- | src/dav/encoder.rs | 8 |
3 files changed, 71 insertions, 21 deletions
diff --git a/src/dav/calencoder.rs b/src/dav/calencoder.rs index 73db4fa..a701fe1 100644 --- a/src/dav/calencoder.rs +++ b/src/dav/calencoder.rs @@ -278,8 +278,6 @@ impl<C: CalContext> QuickWritable<C> for Violation { Self::SupportedCalendarData => atom("supported-calendar-data").await, Self::ValidCalendarObjectResource => atom("valid-calendar-object-resource").await, Self::SupportedCalendarComponent => atom("supported-calendar-component").await, - Self::ValidCalendarObjectResource => atom("valid-calendar-object-resource").await, - Self::SupportedCalendarComponent => atom("SupportedCalendarComponent").await, Self::NoUidConflict(href) => { let start = ctx.create_cal_element("no-uid-conflict"); let end = start.to_end(); @@ -391,43 +389,82 @@ impl<C: CalContext> QuickWritable<C> for CalendarDataEmpty { impl<C: CalContext> QuickWritable<C> for Comp { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { - unimplemented!(); + let mut start = ctx.create_cal_element("calendar-data"); + start.push_attribute(("name", self.name.as_str())); + let end = start.to_end(); + xml.write_event_async(Event::Start(start.clone())).await?; + self.prop_kind.write(xml, ctx.child()).await?; + self.comp_kind.write(xml, ctx.child()).await?; + xml.write_event_async(Event::End(end)).await } } impl<C: CalContext> QuickWritable<C> for CompSupport { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { - unimplemented!(); + let mut empty = ctx.create_cal_element("comp"); + empty.push_attribute(("name", self.0.as_str())); + xml.write_event_async(Event::Empty(empty)).await } } impl<C: CalContext> QuickWritable<C> for CompKind { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { - unimplemented!(); + match self { + Self::AllComp => xml.write_event_async(Event::Empty(ctx.create_cal_element("allcomp"))).await, + Self::Comp(many_comp) => { + for comp in many_comp.iter() { + // Required: recursion in an async fn requires boxing + // rustc --explain E0733 + Box::pin(comp.write(xml, ctx.child())).await?; + } + Ok(()) + } + } } } impl<C: CalContext> QuickWritable<C> for PropKind { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { - unimplemented!(); + match self { + Self::AllProp => xml.write_event_async(Event::Empty(ctx.create_cal_element("allprop"))).await, + Self::Prop(many_prop) => { + for prop in many_prop.iter() { + prop.write(xml, ctx.child()).await?; + } + Ok(()) + } + } } } impl<C: CalContext> QuickWritable<C> for CalProp { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { - unimplemented!(); + let mut empty = ctx.create_cal_element("prop"); + empty.push_attribute(("name", self.name.0.as_str())); + match self.novalue { + None => (), + Some(true) => empty.push_attribute(("novalue", "yes")), + Some(false) => empty.push_attribute(("novalue", "no")), + } + xml.write_event_async(Event::Empty(empty)).await } } impl<C: CalContext> QuickWritable<C> for RecurrenceModifier { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { - unimplemented!(); + match self { + Self::Expand(exp) => exp.write(xml, ctx).await, + Self::LimitRecurrenceSet(lrs) => lrs.write(xml, ctx).await, + } } } impl<C: CalContext> QuickWritable<C> for Expand { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { - unimplemented!(); + let mut empty = ctx.create_cal_element("expand"); + empty.push_attribute(("start", format!("{}", self.0.format(ICAL_DATETIME_FMT)).as_str())); + empty.push_attribute(("end", format!("{}", self.1.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 97d75c5..5668201 100644 --- a/src/dav/caltypes.rs +++ b/src/dav/caltypes.rs @@ -846,9 +846,9 @@ pub struct CalendarDataSupport { /// in the "urn:ietf:params:xml:ns:caldav" namespace instead of the /// "DAV:" namespace. pub struct Comp { - name: Component, - prop_kind: PropKind, - comp_kind: CompKind, + pub name: Component, + pub prop_kind: PropKind, + pub comp_kind: CompKind, } /// For SupportedCalendarComponentSet @@ -864,7 +864,7 @@ pub struct Comp { /// <C:comp name="VEVENT"/> /// <C:comp name="VTODO"/> /// </C:supported-calendar-component-set> -pub struct CompSupport(Component); +pub struct CompSupport(pub Component); /// Name: allcomp /// @@ -932,8 +932,8 @@ pub enum PropKind { /// defined in the "urn:ietf:params:xml:ns:caldav" namespace instead /// of the "DAV:" namespace. pub struct CalProp { - name: ComponentProperty, - novalue: bool, + pub name: ComponentProperty, + pub novalue: Option<bool>, } pub enum RecurrenceModifier { @@ -981,7 +981,7 @@ pub enum RecurrenceModifier { /// end CDATA #REQUIRED> /// start value: an iCalendar "date with UTC time" /// end value: an iCalendar "date with UTC time" -pub struct Expand(DateTime<Utc>, DateTime<Utc>); +pub struct Expand(pub DateTime<Utc>, pub DateTime<Utc>); /// CALDAV:limit-recurrence-set XML Element /// @@ -1348,11 +1348,24 @@ pub enum Component { VAlarm, Unknown(String), } +impl Component { + pub fn as_str<'a>(&'a self) -> &'a str { + match self { + Self::VCalendar => "VCALENDAR", + Self::VJournal => "VJOURNAL", + Self::VFreeBusy => "VFREEBUSY", + Self::VEvent => "VEVENT", + Self::VTodo => "VTODO", + Self::VAlarm => "VALARM", + Self::Unknown(c) => c, + } + } +} /// name="VERSION", name="SUMMARY", etc. /// Can be set on different objects: VCalendar, VEvent, etc. /// Might be replaced by an enum later -pub struct ComponentProperty(String); +pub struct ComponentProperty(pub String); /// like PARSTAT pub struct PropertyParameter(String); diff --git a/src/dav/encoder.rs b/src/dav/encoder.rs index f842734..7778d61 100644 --- a/src/dav/encoder.rs +++ b/src/dav/encoder.rs @@ -37,16 +37,16 @@ impl Context for NoExtension { } start } - async fn hook_error(&self, err: &Disabled, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> { + async fn hook_error(&self, _err: &Disabled, _xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> { unreachable!(); } - async fn hook_property(&self, prop: &Disabled, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> { + async fn hook_property(&self, _prop: &Disabled, _xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> { unreachable!(); } - async fn hook_propertyrequest(&self, prop: &Disabled, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> { + async fn hook_propertyrequest(&self, _prop: &Disabled, _xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> { unreachable!(); } - async fn hook_resourcetype(&self, restype: &Disabled, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> { + async fn hook_resourcetype(&self, _restype: &Disabled, _xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> { unreachable!(); } } |