diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2024-03-01 13:21:19 +0100 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2024-03-01 13:21:19 +0100 |
commit | 8d7c8713b69883632cad84521d604cb9eb9a40d4 (patch) | |
tree | bbc0f71bc7b5ca15ea22d8843ce1aacb1c8f58ba | |
parent | cd48825275a99ccc8ccdadde2169cfd5b7dad15f (diff) | |
download | aerogramme-8d7c8713b69883632cad84521d604cb9eb9a40d4.tar.gz aerogramme-8d7c8713b69883632cad84521d604cb9eb9a40d4.zip |
Finalized encode ActiveLock
-rw-r--r-- | src/dav/encoder.rs | 75 | ||||
-rw-r--r-- | src/dav/types.rs | 30 |
2 files changed, 93 insertions, 12 deletions
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<C: Context> QuickWritable<C> for ActiveLock { impl<C: Context> QuickWritable<C> for LockType { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, 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<C: Context> QuickWritable<C> for LockScope { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, 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<C: Context> QuickWritable<C> for Owner { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, 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<C: Context> QuickWritable<C> for Depth { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, 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<C: Context> QuickWritable<C> for Timeout { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, 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<C: Context> QuickWritable<C> for LockToken { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, 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<C: Context> QuickWritable<C> for LockRoot { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, 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<C: Context> QuickWritable<C> for LockEntry { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, 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); /// /// <!ELEMENT lockentry (lockscope, locktype) > pub struct LockEntry { - pub lokscope: LockScope, + pub lockscope: LockScope, pub locktype: LockType, } @@ -300,7 +300,7 @@ pub enum LockScope { /// refers to the lock. /// /// <!ELEMENT locktoken (href) > -pub struct LockToken(Href); +pub struct LockToken(pub Href); /// 14.15. locktype XML Element /// @@ -363,7 +363,11 @@ pub struct Multistatus<T: Extension> { /// text content or attributes. /// /// <!ELEMENT owner ANY > -pub struct Owner(pub String); +//@FIXME might need support for an extension +pub struct Owner { + pub txt: Option<String>, + pub url: Option<Href>, +} /// 14.18. prop XML Element /// @@ -559,7 +563,25 @@ pub struct Status(pub http::status::StatusCode); /// /// /// <!ELEMENT timeout (#PCDATA) > -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 |