aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dav/calencoder.rs10
-rw-r--r--src/dav/caltypes.rs4
-rw-r--r--src/dav/encoder.rs74
-rw-r--r--src/dav/types.rs52
-rw-r--r--src/main.rs1
5 files changed, 115 insertions, 26 deletions
diff --git a/src/dav/calencoder.rs b/src/dav/calencoder.rs
index fc380ac..c7708eb 100644
--- a/src/dav/calencoder.rs
+++ b/src/dav/calencoder.rs
@@ -27,6 +27,10 @@ impl Context for CalExtension {
async fn hook_resourcetype(&self, restype: &Self::ResourceType, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> {
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 {
@@ -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 {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: CalExtension) -> Result<(), QError> {
match self {
diff --git a/src/dav/caltypes.rs b/src/dav/caltypes.rs
index 9e4cb47..55f4f93 100644
--- a/src/dav/caltypes.rs
+++ b/src/dav/caltypes.rs
@@ -29,6 +29,10 @@ pub enum Violation {
SupportedFilter,
}
+pub enum PropertyRequest {
+ CalendarDescription,
+ CalendarTimezone,
+}
pub enum Property {
CalendarDescription,
diff --git a/src/dav/encoder.rs b/src/dav/encoder.rs
index 72d9b91..0ad8949 100644
--- a/src/dav/encoder.rs
+++ b/src/dav/encoder.rs
@@ -21,6 +21,7 @@ pub trait Context: Extension {
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_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>;
}
@@ -42,6 +43,9 @@ impl Context for NoExtension {
async fn hook_property(&self, prop: &Disabled, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> {
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> {
unreachable!();
}
@@ -55,7 +59,30 @@ impl Context for NoExtension {
/// PROPFIND REQUEST
impl<C: Context> QuickWritable<C> for PropFind<C> {
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
impl<C: Context> QuickWritable<C> for LockInfo {
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 {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
// <D:activelock>
diff --git a/src/dav/types.rs b/src/dav/types.rs
index 7f22385..95fe749 100644
--- a/src/dav/types.rs
+++ b/src/dav/types.rs
@@ -39,17 +39,6 @@ pub struct ActiveLock {
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
///
/// Name: collection
@@ -219,7 +208,7 @@ pub struct Href(pub String);
/// standards. This element MUST NOT contain text or mixed content.
///
/// <!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
///
@@ -401,6 +390,29 @@ pub enum PropertyUpdateItem<T: Extension> {
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
///
/// Name: propfind
@@ -413,20 +425,12 @@ pub enum PropertyUpdateItem<T: Extension> {
///
/// <!ELEMENT propfind ( propname | (allprop, include?) | prop ) >
pub enum PropFind<T: Extension> {
- PropName(PropName),
- AllProp(AllProp, Option<Include<T>>),
- Prop(Prop<T>),
+ PropName,
+ AllProp(Option<Include<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
///
diff --git a/src/main.rs b/src/main.rs
index 4f874b9..c9ce42d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,5 +1,6 @@
#![feature(type_alias_impl_trait)]
#![feature(async_fn_in_trait)]
+#![feature(async_closure)]
mod auth;
mod bayou;