From c52a6591512825d297b0636cc228ee0915974404 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 1 Mar 2024 10:29:16 +0100 Subject: [PATCH] hook resource type --- src/dav/calencoder.rs | 12 +++++++++++- src/dav/caltypes.rs | 6 +++++- src/dav/encoder.rs | 14 +++++++++++--- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/dav/calencoder.rs b/src/dav/calencoder.rs index 14b7903..fc380ac 100644 --- a/src/dav/calencoder.rs +++ b/src/dav/calencoder.rs @@ -23,6 +23,10 @@ impl Context for CalExtension { async fn hook_property(&self, prop: &Self::Property, xml: &mut Writer) -> Result<(), QError> { prop.write(xml, self.child()).await } + + async fn hook_resourcetype(&self, restype: &Self::ResourceType, xml: &mut Writer) -> Result<(), QError> { + restype.write(xml, self.child()).await + } } impl CalExtension { @@ -58,7 +62,13 @@ impl QuickWritable for Property { } } - +impl QuickWritable for ResourceType { + async fn write(&self, xml: &mut Writer, ctx: CalExtension) -> Result<(), QError> { + match self { + Self::Calendar => xml.write_event_async(Event::Empty(ctx.create_dav_element("calendar"))).await, + } + } +} #[cfg(test)] mod tests { diff --git a/src/dav/caltypes.rs b/src/dav/caltypes.rs index a68936c..9e4cb47 100644 --- a/src/dav/caltypes.rs +++ b/src/dav/caltypes.rs @@ -8,7 +8,7 @@ impl Extension for CalExtension { type Error = Violation; type Property = Property; type PropertyRequest = Property; //@FIXME - type ResourceType = Property; //@FIXME + type ResourceType = ResourceType; } pub enum Violation { @@ -34,3 +34,7 @@ pub enum Property { CalendarDescription, CalendarTimezone, } + +pub enum ResourceType { + Calendar, +} diff --git a/src/dav/encoder.rs b/src/dav/encoder.rs index 332c13a..72d815b 100644 --- a/src/dav/encoder.rs +++ b/src/dav/encoder.rs @@ -21,6 +21,7 @@ pub trait Context: Extension { fn create_dav_element(&self, name: &str) -> BytesStart; async fn hook_error(&self, err: &Self::Error, xml: &mut Writer) -> Result<(), QError>; async fn hook_property(&self, prop: &Self::Property, xml: &mut Writer) -> Result<(), QError>; + async fn hook_resourcetype(&self, prop: &Self::ResourceType, xml: &mut Writer) -> Result<(), QError>; } /// -------------- NoExtension Encoding Context @@ -41,6 +42,9 @@ impl Context for NoExtension { async fn hook_property(&self, prop: &Disabled, xml: &mut Writer) -> Result<(), QError> { unreachable!(); } + async fn hook_resourcetype(&self, restype: &Disabled, xml: &mut Writer) -> Result<(), QError> { + unreachable!(); + } } @@ -320,13 +324,17 @@ impl QuickWritable for Property { } } -impl QuickWritable for ActiveLock { +impl QuickWritable for ResourceType { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); + match self { + Self::Collection => xml.write_event_async(Event::Empty(ctx.create_dav_element("collection"))).await?, + Self::Extension(inner) => ctx.hook_resourcetype(inner, xml).await?, + }; + Ok(()) } } -impl QuickWritable for ResourceType { +impl QuickWritable for ActiveLock { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { unimplemented!(); }