fully serialize webdav core?

This commit is contained in:
Quentin 2024-03-01 14:28:36 +01:00
parent 8d7c8713b6
commit 2b30c97084
Signed by: quentin
GPG key ID: E9602264D639FF68
5 changed files with 115 additions and 26 deletions

View file

@ -27,6 +27,10 @@ impl Context for CalExtension {
async fn hook_resourcetype(&self, restype: &Self::ResourceType, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> { async fn hook_resourcetype(&self, restype: &Self::ResourceType, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> {
restype.write(xml, self.child()).await restype.write(xml, self.child()).await
} }
async fn hook_propertyrequest(&self, propreq: &Self::PropertyRequest, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> {
propreq.write(xml, self.child()).await
}
} }
impl CalExtension { impl CalExtension {
@ -62,6 +66,12 @@ impl QuickWritable<CalExtension> for Property {
} }
} }
impl QuickWritable<CalExtension> for PropertyRequest {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: CalExtension) -> Result<(), QError> {
unimplemented!();
}
}
impl QuickWritable<CalExtension> for ResourceType { impl QuickWritable<CalExtension> for ResourceType {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: CalExtension) -> Result<(), QError> { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: CalExtension) -> Result<(), QError> {
match self { match self {

View file

@ -29,6 +29,10 @@ pub enum Violation {
SupportedFilter, SupportedFilter,
} }
pub enum PropertyRequest {
CalendarDescription,
CalendarTimezone,
}
pub enum Property { pub enum Property {
CalendarDescription, CalendarDescription,

View file

@ -21,6 +21,7 @@ pub trait Context: Extension {
fn create_dav_element(&self, name: &str) -> BytesStart; fn create_dav_element(&self, name: &str) -> BytesStart;
async fn hook_error(&self, err: &Self::Error, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError>; async fn hook_error(&self, err: &Self::Error, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError>;
async fn hook_property(&self, prop: &Self::Property, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError>; async fn hook_property(&self, prop: &Self::Property, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError>;
async fn hook_propertyrequest(&self, prop: &Self::PropertyRequest, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError>;
async fn hook_resourcetype(&self, prop: &Self::ResourceType, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError>; async fn hook_resourcetype(&self, prop: &Self::ResourceType, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError>;
} }
@ -42,6 +43,9 @@ impl Context for NoExtension {
async fn hook_property(&self, prop: &Disabled, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> { async fn hook_property(&self, prop: &Disabled, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> {
unreachable!(); unreachable!();
} }
async fn hook_propertyrequest(&self, prop: &Disabled, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> {
unreachable!();
}
async fn hook_resourcetype(&self, restype: &Disabled, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> { async fn hook_resourcetype(&self, restype: &Disabled, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> {
unreachable!(); unreachable!();
} }
@ -55,7 +59,30 @@ impl Context for NoExtension {
/// PROPFIND REQUEST /// PROPFIND REQUEST
impl<C: Context> QuickWritable<C> for PropFind<C> { impl<C: Context> QuickWritable<C> for PropFind<C> {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, 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<C: Context> QuickWritable<C> for Multistatus<C> {
/// LOCK REQUEST /// LOCK REQUEST
impl<C: Context> QuickWritable<C> for LockInfo { impl<C: Context> QuickWritable<C> for LockInfo {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, 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<C: Context> QuickWritable<C> for ResourceType<C> {
} }
} }
impl<C: Context> QuickWritable<C> for Include<C> {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, 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<C: Context> QuickWritable<C> for PropertyRequest<C> {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, 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<C: Context> QuickWritable<C> for ActiveLock { impl<C: Context> QuickWritable<C> for ActiveLock {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
// <D:activelock> // <D:activelock>

View file

@ -39,17 +39,6 @@ pub struct ActiveLock {
pub lockroot: LockRoot, 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.
///
/// <!ELEMENT allprop EMPTY >
pub struct AllProp{}
/// 14.3 collection XML Element /// 14.3 collection XML Element
/// ///
/// Name: collection /// Name: collection
@ -219,7 +208,7 @@ pub struct Href(pub String);
/// standards. This element MUST NOT contain text or mixed content. /// standards. This element MUST NOT contain text or mixed content.
/// ///
/// <!ELEMENT include ANY > /// <!ELEMENT include ANY >
pub struct Include<T: Extension>(pub Vec<Property<T>>); pub struct Include<T: Extension>(pub Vec<PropertyRequest<T>>);
/// 14.9. location XML Element /// 14.9. location XML Element
/// ///
@ -401,6 +390,29 @@ pub enum PropertyUpdateItem<T: Extension> {
Set(Set<T>), Set(Set<T>),
} }
/// 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.
///
/// <!ELEMENT allprop EMPTY >
///
/// ---
///
/// 14.21. propname XML Element
///
/// Name: propname
///
/// Purpose: Specifies that only a list of property names on the
/// resource is to be returned.
///
/// <!ELEMENT propname EMPTY >
///
/// ---
///
/// 14.20. propfind XML Element /// 14.20. propfind XML Element
/// ///
/// Name: propfind /// Name: propfind
@ -413,20 +425,12 @@ pub enum PropertyUpdateItem<T: Extension> {
/// ///
/// <!ELEMENT propfind ( propname | (allprop, include?) | prop ) > /// <!ELEMENT propfind ( propname | (allprop, include?) | prop ) >
pub enum PropFind<T: Extension> { pub enum PropFind<T: Extension> {
PropName(PropName), PropName,
AllProp(AllProp, Option<Include<T>>), AllProp(Option<Include<T>>),
Prop(Prop<T>), Prop(Vec<PropertyRequest<T>>),
} }
/// 14.21. propname XML Element
///
/// Name: propname
///
/// Purpose: Specifies that only a list of property names on the
/// resource is to be returned.
///
/// <!ELEMENT propname EMPTY >
pub struct PropName {}
/// 14.22 propstat XML Element /// 14.22 propstat XML Element
/// ///

View file

@ -1,5 +1,6 @@
#![feature(type_alias_impl_trait)] #![feature(type_alias_impl_trait)]
#![feature(async_fn_in_trait)] #![feature(async_fn_in_trait)]
#![feature(async_closure)]
mod auth; mod auth;
mod bayou; mod bayou;