From 2b30c97084a63afa53278e35dbbcc620192c8c3f Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 1 Mar 2024 14:28:36 +0100 Subject: fully serialize webdav core? --- src/dav/calencoder.rs | 10 +++++++ src/dav/caltypes.rs | 4 +++ src/dav/encoder.rs | 74 +++++++++++++++++++++++++++++++++++++++++++++++++-- src/dav/types.rs | 52 +++++++++++++++++++----------------- src/main.rs | 1 + 5 files changed, 115 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/dav/calencoder.rs b/src/dav/calencoder.rs index fc380ac..c7708eb 100644 --- a/src/dav/calencoder.rs +++ b/src/dav/calencoder.rs @@ -27,6 +27,10 @@ impl Context for CalExtension { async fn hook_resourcetype(&self, restype: &Self::ResourceType, xml: &mut Writer) -> Result<(), QError> { restype.write(xml, self.child()).await } + + async fn hook_propertyrequest(&self, propreq: &Self::PropertyRequest, xml: &mut Writer) -> Result<(), QError> { + propreq.write(xml, self.child()).await + } } impl CalExtension { @@ -62,6 +66,12 @@ impl QuickWritable for Property { } } +impl QuickWritable for PropertyRequest { + async fn write(&self, xml: &mut Writer, ctx: CalExtension) -> Result<(), QError> { + unimplemented!(); + } +} + impl QuickWritable for ResourceType { async fn write(&self, xml: &mut Writer, ctx: CalExtension) -> Result<(), QError> { match self { diff --git a/src/dav/caltypes.rs b/src/dav/caltypes.rs index 9e4cb47..55f4f93 100644 --- a/src/dav/caltypes.rs +++ b/src/dav/caltypes.rs @@ -29,6 +29,10 @@ pub enum Violation { SupportedFilter, } +pub enum PropertyRequest { + CalendarDescription, + CalendarTimezone, +} pub enum Property { CalendarDescription, diff --git a/src/dav/encoder.rs b/src/dav/encoder.rs index 72d9b91..0ad8949 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_propertyrequest(&self, prop: &Self::PropertyRequest, xml: &mut Writer) -> Result<(), QError>; async fn hook_resourcetype(&self, prop: &Self::ResourceType, xml: &mut Writer) -> Result<(), QError>; } @@ -42,6 +43,9 @@ impl Context for NoExtension { async fn hook_property(&self, prop: &Disabled, xml: &mut Writer) -> Result<(), QError> { unreachable!(); } + async fn hook_propertyrequest(&self, prop: &Disabled, xml: &mut Writer) -> Result<(), QError> { + unreachable!(); + } async fn hook_resourcetype(&self, restype: &Disabled, xml: &mut Writer) -> Result<(), QError> { unreachable!(); } @@ -55,7 +59,30 @@ impl Context for NoExtension { /// PROPFIND REQUEST impl QuickWritable for PropFind { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); + let start = ctx.create_dav_element("propfind"); + let end = start.to_end(); + + xml.write_event_async(Event::Start(start.clone())).await?; + match self { + Self::PropName => xml.write_event_async(Event::Empty(ctx.create_dav_element("propname"))).await?, + Self::AllProp(maybe_include) => { + xml.write_event_async(Event::Empty(ctx.create_dav_element("allprop"))).await?; + if let Some(include) = maybe_include { + include.write(xml, ctx.child()).await?; + } + }, + Self::Prop(many_propreq) => { + let start = ctx.create_dav_element("prop"); + let end = start.to_end(); + + xml.write_event_async(Event::Start(start.clone())).await?; + for propreq in many_propreq.iter() { + propreq.write(xml, ctx.child()).await?; + } + xml.write_event_async(Event::End(end)).await?; + }, + } + xml.write_event_async(Event::End(end)).await } } @@ -82,7 +109,16 @@ impl QuickWritable for Multistatus { /// LOCK REQUEST impl QuickWritable for LockInfo { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); + let start = ctx.create_dav_element("lockinfo"); + let end = start.to_end(); + + xml.write_event_async(Event::Start(start.clone())).await?; + self.lockscope.write(xml, ctx.child()).await?; + self.locktype.write(xml, ctx.child()).await?; + if let Some(owner) = &self.owner { + owner.write(xml, ctx.child()).await?; + } + xml.write_event_async(Event::End(end)).await } } @@ -349,6 +385,40 @@ impl QuickWritable for ResourceType { } } +impl QuickWritable for Include { + async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { + let start = ctx.create_dav_element("include"); + let end = start.to_end(); + + xml.write_event_async(Event::Start(start.clone())).await?; + for prop in self.0.iter() { + prop.write(xml, ctx.child()).await?; + } + xml.write_event_async(Event::End(end)).await + } +} + +impl QuickWritable for PropertyRequest { + async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { + use PropertyRequest::*; + let mut atom = (async |c| xml.write_event_async(Event::Empty(ctx.create_dav_element(c))).await); + + match self { + CreationDate => atom("creationdate").await, + DisplayName => atom("displayname").await, + GetContentLanguage => atom("getcontentlanguage").await, + GetContentLength => atom("getcontentlength").await, + GetContentType => atom("getcontenttype").await, + GetEtag => atom("getetag").await, + GetLastModified => atom("getlastmodified").await, + LockDiscovery => atom("lockdiscovery").await, + ResourceType => atom("resourcetype").await, + SupportedLock => atom("supportedlock").await, + Extension(inner) => ctx.hook_propertyrequest(inner, xml).await, + } + } +} + impl QuickWritable for ActiveLock { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { // diff --git a/src/dav/types.rs b/src/dav/types.rs index 7f22385..95fe749 100644 --- a/src/dav/types.rs +++ b/src/dav/types.rs @@ -39,17 +39,6 @@ pub struct ActiveLock { pub lockroot: LockRoot, } -/// 14.2 allprop XML Element -/// -/// Name: allprop -/// -/// Purpose: Specifies that all names and values of dead properties and -/// the live properties defined by this document existing on the -/// resource are to be returned. -/// -/// -pub struct AllProp{} - /// 14.3 collection XML Element /// /// Name: collection @@ -219,7 +208,7 @@ pub struct Href(pub String); /// standards. This element MUST NOT contain text or mixed content. /// /// -pub struct Include(pub Vec>); +pub struct Include(pub Vec>); /// 14.9. location XML Element /// @@ -401,6 +390,29 @@ pub enum PropertyUpdateItem { Set(Set), } +/// 14.2 allprop XML Element +/// +/// Name: allprop +/// +/// Purpose: Specifies that all names and values of dead properties and +/// the live properties defined by this document existing on the +/// resource are to be returned. +/// +/// +/// +/// --- +/// +/// 14.21. propname XML Element +/// +/// Name: propname +/// +/// Purpose: Specifies that only a list of property names on the +/// resource is to be returned. +/// +/// +/// +/// --- +/// /// 14.20. propfind XML Element /// /// Name: propfind @@ -413,20 +425,12 @@ pub enum PropertyUpdateItem { /// /// pub enum PropFind { - PropName(PropName), - AllProp(AllProp, Option>), - Prop(Prop), + PropName, + AllProp(Option>), + Prop(Vec>), } -/// 14.21. propname XML Element -/// -/// Name: propname -/// -/// Purpose: Specifies that only a list of property names on the -/// resource is to be returned. -/// -/// -pub struct PropName {} + /// 14.22 propstat XML Element /// diff --git a/src/main.rs b/src/main.rs index 4f874b9..c9ce42d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ #![feature(type_alias_impl_trait)] #![feature(async_fn_in_trait)] +#![feature(async_closure)] mod auth; mod bayou; -- cgit v1.2.3