From dba0dcdc4122ff73c94d733376a77e98cabd7478 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Sat, 2 Mar 2024 18:35:11 +0100 Subject: Serialize CalDAV errors --- src/dav/calencoder.rs | 56 ++++++++++++++++++++++++++++++++++++++++++++------- src/dav/caltypes.rs | 8 +++++--- 2 files changed, 54 insertions(+), 10 deletions(-) (limited to 'src/dav') diff --git a/src/dav/calencoder.rs b/src/dav/calencoder.rs index 5cd40ef..1016a20 100644 --- a/src/dav/calencoder.rs +++ b/src/dav/calencoder.rs @@ -262,14 +262,56 @@ impl QuickWritable for ResourceType { // --------------------------- DAV::error ------------------------------------ impl QuickWritable for Violation { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { + let mut atom = async |c| xml.write_event_async(Event::Empty(ctx.create_cal_element(c))).await; + match self { - Self::ResourceMustBeNull => { - let start = ctx.create_cal_element("resource-must-be-null"); - xml.write_event_async(Event::Empty(start)).await?; - }, - _ => unimplemented!(), - }; - Ok(()) + //@FIXME + // DAV elements, should not be here but in RFC3744 on ACLs + // (we do not use atom as this error is in the DAV namespace, not the caldav one) + Self::NeedPrivileges => xml.write_event_async(Event::Empty(ctx.create_dav_element("need-privileges"))).await, + + // Regular CalDAV errors + Self::ResourceMustBeNull => atom("resource-must-be-null").await, + Self::CalendarCollectionLocationOk => atom("calendar-collection-location-ok").await, + Self::ValidCalendarData => atom("valid-calendar-data").await, + Self::InitializeCalendarCollection => atom("initialize-calendar-collection").await, + 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(); + + xml.write_event_async(Event::Start(start.clone())).await?; + href.write(xml, ctx.child()).await?; + xml.write_event_async(Event::End(end)).await + }, + Self::MaxResourceSize => atom("max-resource-size").await, + Self::MinDateTime => atom("min-date-time").await, + Self::MaxDateTime => atom("max-date-time").await, + Self::MaxInstances => atom("max-instances").await, + Self::MaxAttendeesPerInstance => atom("max-attendees-per-instance").await, + Self::ValidFilter => atom("valid-filter").await, + Self::SupportedFilter { comp, prop, param } => { + let start = ctx.create_cal_element("supported-filter"); + let end = start.to_end(); + + xml.write_event_async(Event::Start(start.clone())).await?; + for comp_item in comp.iter() { + comp_item.write(xml, ctx.child()).await?; + } + for prop_item in prop.iter() { + prop_item.write(xml, ctx.child()).await?; + } + for param_item in param.iter() { + param_item.write(xml, ctx.child()).await?; + } + xml.write_event_async(Event::End(end)).await + }, + Self::NumberOfMatchesWithinLimits => atom("number-of-matches-within-limits").await, + } } } diff --git a/src/dav/caltypes.rs b/src/dav/caltypes.rs index c803c0c..29dc02f 100644 --- a/src/dav/caltypes.rs +++ b/src/dav/caltypes.rs @@ -614,9 +614,11 @@ pub enum Violation { /// containing a single valid VTIMEZONE component. ValidCalendarData, - /// (DAV:needs-privilege): The DAV:bind privilege MUST be granted to + ///@FIXME should not be here but in RFC3744 + /// !!! ERRATA 1002 !!! + /// (DAV:need-privileges): The DAV:bind privilege MUST be granted to /// the current user on the parent collection of the Request-URI. - NeedsPrivilege, + NeedPrivileges, /// (CALDAV:initialize-calendar-collection): A new calendar collection /// exists at the Request-URI. The DAV:resourcetype of the calendar @@ -693,7 +695,7 @@ pub enum Violation { /// the resource will be stored; MaxAttendeesPerInstance, - /// The CALDAV:filter XML element (see + /// (CALDAV:valid-filter): The CALDAV:filter XML element (see /// Section 9.7) specified in the REPORT request MUST be valid. For /// instance, a CALDAV:filter cannot nest a /// element in a element, and a CALDAV:filter -- cgit v1.2.3