Finalized encode ActiveLock

This commit is contained in:
Quentin 2024-03-01 13:21:19 +01:00
parent cd48825275
commit 8d7c8713b6
Signed by: quentin
GPG key ID: E9602264D639FF68
2 changed files with 93 additions and 12 deletions

View file

@ -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
}
}

View file

@ -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