From cd48825275a99ccc8ccdadde2169cfd5b7dad15f Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 1 Mar 2024 10:56:05 +0100 Subject: [PATCH] WIP DAV encoder --- src/dav/encoder.rs | 133 ++++++++++++++++++++++++++++++++++++++------- src/dav/types.rs | 2 + 2 files changed, 115 insertions(+), 20 deletions(-) diff --git a/src/dav/encoder.rs b/src/dav/encoder.rs index 72d815b..8534db1 100644 --- a/src/dav/encoder.rs +++ b/src/dav/encoder.rs @@ -51,6 +51,16 @@ impl Context for NoExtension { //--------------------- ENCODING -------------------- // --- XML ROOTS + +/// PROPFIND REQUEST +impl QuickWritable for PropFind { + async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { + unimplemented!(); + } +} + +/// PROPFIND RESPONSE, PROPPATCH RESPONSE, COPY RESPONSE, MOVE RESPONSE +/// DELETE RESPONSE, impl QuickWritable for Multistatus { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { let start = ctx.create_dav_element("multistatus"); @@ -69,6 +79,28 @@ impl QuickWritable for Multistatus { } } +/// LOCK REQUEST +impl QuickWritable for LockInfo { + async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { + unimplemented!(); + } +} + +/// SOME LOCK RESPONSES +impl QuickWritable for Prop { + async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { + let start = ctx.create_dav_element("prop"); + let end = start.to_end(); + + xml.write_event_async(Event::Start(start.clone())).await?; + for property in &self.0 { + property.write(xml, ctx.child()).await?; + } + xml.write_event_async(Event::End(end)).await?; + + Ok(()) + } +} // --- XML inner elements impl QuickWritable for Href { @@ -184,22 +216,6 @@ impl QuickWritable for PropStat { } } -impl QuickWritable for Prop { - async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - let start = ctx.create_dav_element("prop"); - let end = start.to_end(); - - xml.write_event_async(Event::Start(start.clone())).await?; - for property in &self.0 { - property.write(xml, ctx.child()).await?; - } - xml.write_event_async(Event::End(end)).await?; - - Ok(()) - } -} - - impl QuickWritable for Property { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { use Property::*; @@ -327,14 +343,89 @@ impl QuickWritable for Property { impl QuickWritable for ResourceType { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { 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(()) + Self::Collection => xml.write_event_async(Event::Empty(ctx.create_dav_element("collection"))).await, + Self::Extension(inner) => ctx.hook_resourcetype(inner, xml).await, + } } } impl QuickWritable for ActiveLock { + async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { + // + // + // + // infinity + // + // http://example.org/~ejw/contact.html + // + // Second-604800 + // + // urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4 + // + // + // http://example.com/workspace/webdav/proposal.doc + // + // + let start = ctx.create_dav_element("activelock"); + let end = start.to_end(); + + xml.write_event_async(Event::Start(start.clone())).await?; + self.locktype.write(xml, ctx.child()).await?; + self.lockscope.write(xml, ctx.child()).await?; + self.depth.write(xml, ctx.child()).await?; + if let Some(owner) = &self.owner { + owner.write(xml, ctx.child()).await?; + } + if let Some(timeout) = &self.timeout { + timeout.write(xml, ctx.child()).await?; + } + if let Some(locktoken) = &self.locktoken { + locktoken.write(xml, ctx.child()).await?; + } + self.lockroot.write(xml, ctx.child()).await?; + xml.write_event_async(Event::End(end)).await?; + + Ok(()) + } +} + +impl QuickWritable for LockType { + async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { + unimplemented!(); + } +} + +impl QuickWritable for LockScope { + async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { + unimplemented!(); + } +} + +impl QuickWritable for Owner { + async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { + unimplemented!(); + } +} + +impl QuickWritable for Depth { + async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { + unimplemented!(); + } +} + +impl QuickWritable for Timeout { + async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { + unimplemented!(); + } +} + +impl QuickWritable for LockToken { + async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { + unimplemented!(); + } +} + +impl QuickWritable for LockRoot { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { unimplemented!(); } @@ -342,6 +433,8 @@ impl QuickWritable for ActiveLock { impl QuickWritable for LockEntry { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { + let start = ctx.create_dav_element("lockentry"); + let end = start.to_end(); unimplemented!(); } } diff --git a/src/dav/types.rs b/src/dav/types.rs index 59cfcd6..50f88e3 100644 --- a/src/dav/types.rs +++ b/src/dav/types.rs @@ -35,6 +35,8 @@ pub struct ActiveLock { pub depth: Depth, pub owner: Option, pub timeout: Option, + pub locktoken: Option, + pub lockroot: LockRoot, } /// 14.2 allprop XML Element