diff --git a/src/dav/encoder.rs b/src/dav/encoder.rs index 8534db1..72d9b91 100644 --- a/src/dav/encoder.rs +++ b/src/dav/encoder.rs @@ -391,43 +391,98 @@ impl QuickWritable for ActiveLock { impl QuickWritable for LockType { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); + let start = ctx.create_dav_element("locktype"); + let end = start.to_end(); + + xml.write_event_async(Event::Start(start.clone())).await?; + match self { + Self::Write => xml.write_event_async(Event::Empty(ctx.create_dav_element("write"))).await?, + }; + xml.write_event_async(Event::End(end)).await } } impl QuickWritable for LockScope { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); + let start = ctx.create_dav_element("lockscope"); + let end = start.to_end(); + + xml.write_event_async(Event::Start(start.clone())).await?; + match self { + Self::Exclusive => xml.write_event_async(Event::Empty(ctx.create_dav_element("exclusive"))).await?, + Self::Shared => xml.write_event_async(Event::Empty(ctx.create_dav_element("shared"))).await?, + }; + xml.write_event_async(Event::End(end)).await } } impl QuickWritable for Owner { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); + let start = ctx.create_dav_element("owner"); + let end = start.to_end(); + + xml.write_event_async(Event::Start(start.clone())).await?; + if let Some(txt) = &self.txt { + xml.write_event_async(Event::Text(BytesText::new(&txt))).await?; + } + if let Some(href) = &self.url { + href.write(xml, ctx.child()).await?; + } + xml.write_event_async(Event::End(end)).await } } impl QuickWritable for Depth { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); + let start = ctx.create_dav_element("depth"); + let end = start.to_end(); + + xml.write_event_async(Event::Start(start.clone())).await?; + match self { + Self::Zero => xml.write_event_async(Event::Text(BytesText::new("0"))).await?, + Self::One => xml.write_event_async(Event::Text(BytesText::new("1"))).await?, + Self::Infinity => xml.write_event_async(Event::Text(BytesText::new("infinity"))).await?, + }; + xml.write_event_async(Event::End(end)).await } } impl QuickWritable for Timeout { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); + let start = ctx.create_dav_element("timeout"); + let end = start.to_end(); + + xml.write_event_async(Event::Start(start.clone())).await?; + match self { + Self::Seconds(count) => { + let txt = format!("Second-{}", count); + xml.write_event_async(Event::Text(BytesText::new(&txt))).await? + }, + Self::Infinite => xml.write_event_async(Event::Text(BytesText::new("Infinite"))).await? + }; + xml.write_event_async(Event::End(end)).await } } impl QuickWritable for LockToken { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); + let start = ctx.create_dav_element("locktoken"); + let end = start.to_end(); + + xml.write_event_async(Event::Start(start.clone())).await?; + self.0.write(xml, ctx.child()).await?; + xml.write_event_async(Event::End(end)).await } } impl QuickWritable for LockRoot { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); + let start = ctx.create_dav_element("lockroot"); + let end = start.to_end(); + + xml.write_event_async(Event::Start(start.clone())).await?; + self.0.write(xml, ctx.child()).await?; + xml.write_event_async(Event::End(end)).await } } @@ -435,7 +490,11 @@ 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!(); + + xml.write_event_async(Event::Start(start.clone())).await?; + self.lockscope.write(xml, ctx.child()).await?; + self.locktype.write(xml, ctx.child()).await?; + xml.write_event_async(Event::End(end)).await } } diff --git a/src/dav/types.rs b/src/dav/types.rs index 50f88e3..7f22385 100644 --- a/src/dav/types.rs +++ b/src/dav/types.rs @@ -246,7 +246,7 @@ pub struct Location(pub Href); /// /// pub struct LockEntry { - pub lokscope: LockScope, + pub lockscope: LockScope, pub locktype: LockType, } @@ -300,7 +300,7 @@ pub enum LockScope { /// refers to the lock. /// /// -pub struct LockToken(Href); +pub struct LockToken(pub Href); /// 14.15. locktype XML Element /// @@ -363,7 +363,11 @@ pub struct Multistatus { /// text content or attributes. /// /// -pub struct Owner(pub String); +//@FIXME might need support for an extension +pub struct Owner { + pub txt: Option, + pub url: Option, +} /// 14.18. prop XML Element /// @@ -559,7 +563,25 @@ pub struct Status(pub http::status::StatusCode); /// /// /// -pub struct Timeout(u64); +/// +/// TimeOut = "Timeout" ":" 1#TimeType +/// TimeType = ("Second-" DAVTimeOutVal | "Infinite") +/// ; No LWS allowed within TimeType +/// DAVTimeOutVal = 1*DIGIT +/// +/// Clients MAY include Timeout request headers in their LOCK requests. +/// However, the server is not required to honor or even consider these +/// requests. Clients MUST NOT submit a Timeout request header with any +/// method other than a LOCK method. +/// +/// The "Second" TimeType specifies the number of seconds that will +/// elapse between granting of the lock at the server, and the automatic +/// removal of the lock. The timeout value for TimeType "Second" MUST +/// NOT be greater than 2^32-1. +pub enum Timeout { + Seconds(u32), + Infinite, +} /// 15. DAV Properties