aboutsummaryrefslogtreecommitdiff
path: root/aero-proto
diff options
context:
space:
mode:
Diffstat (limited to 'aero-proto')
-rw-r--r--aero-proto/src/dav/codec.rs8
-rw-r--r--aero-proto/src/dav/node.rs6
-rw-r--r--aero-proto/src/dav/resource.rs35
3 files changed, 42 insertions, 7 deletions
diff --git a/aero-proto/src/dav/codec.rs b/aero-proto/src/dav/codec.rs
index 08af2fe..e317a03 100644
--- a/aero-proto/src/dav/codec.rs
+++ b/aero-proto/src/dav/codec.rs
@@ -70,8 +70,12 @@ pub(crate) fn serialize<T: dxml::QWrite + Send + 'static>(status_ok: hyper::Stat
pub(crate) async fn deserialize<T: dxml::Node<T>>(req: Request<Incoming>) -> Result<T> {
let stream_of_frames = BodyStream::new(req.into_body());
let stream_of_bytes = stream_of_frames
- .try_filter_map(|frame| async move { Ok(frame.into_data().ok()) })
- .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err));
+ .map_ok(|frame| frame.into_data())
+ .map(|obj| match obj {
+ Ok(Ok(v)) => Ok(v),
+ Ok(Err(_)) => Err(std::io::Error::new(std::io::ErrorKind::Other, "conversion error")),
+ Err(err) => Err(std::io::Error::new(std::io::ErrorKind::Other, err)),
+ });
let async_read = tokio_util::io::StreamReader::new(stream_of_bytes);
let async_read = std::pin::pin!(async_read);
let mut rdr = dxml::Reader::new(quick_xml::reader::NsReader::from_reader(async_read)).await?;
diff --git a/aero-proto/src/dav/node.rs b/aero-proto/src/dav/node.rs
index b0f97a5..96bd52b 100644
--- a/aero-proto/src/dav/node.rs
+++ b/aero-proto/src/dav/node.rs
@@ -1,4 +1,5 @@
use anyhow::Result;
+use futures::Stream;
use futures::future::BoxFuture;
use aero_dav::types as dav;
@@ -6,6 +7,7 @@ use aero_dav::realization::All;
use aero_collections::user::User;
type ArcUser = std::sync::Arc<User>;
+pub(crate) type Content = Box<dyn Stream<Item=Result<u64>>>;
pub(crate) enum PutPolicy {
CreateOnly,
@@ -28,8 +30,8 @@ pub(crate) trait DavNode: Send {
fn supported_properties(&self, user: &ArcUser) -> dav::PropName<All>;
/// Get the values for the given properties
fn properties(&self, user: &ArcUser, prop: dav::PropName<All>) -> Vec<dav::AnyProperty<All>>;
- /// Put a child
- //fn put(&self, policy: PutPolicy, stream: TryStream) -> BoxFuture<Result<dyn DavNode>>;
+ /// Put an element (create or update)
+ fn put(&self, policy: PutPolicy, stream: Content) -> BoxFuture<Result<()>>;
/// Get content
//fn content(&self) -> TryStream;
diff --git a/aero-proto/src/dav/resource.rs b/aero-proto/src/dav/resource.rs
index fec8bcb..2269de2 100644
--- a/aero-proto/src/dav/resource.rs
+++ b/aero-proto/src/dav/resource.rs
@@ -2,7 +2,7 @@ use std::sync::Arc;
type ArcUser = std::sync::Arc<User>;
use anyhow::{anyhow, Result};
-use futures::stream::StreamExt;
+use futures::stream::{TryStream, StreamExt};
use futures::{future::BoxFuture, future::FutureExt};
use aero_collections::{user::User, calendar::Calendar, davdag::BlobId};
@@ -12,7 +12,7 @@ use aero_dav::acltypes as acl;
use aero_dav::realization::{All, self as all};
-use crate::dav::node::DavNode;
+use crate::dav::node::{DavNode, PutPolicy, Content};
#[derive(Clone)]
pub(crate) struct RootNode {}
@@ -60,6 +60,10 @@ impl DavNode for RootNode {
v => dav::AnyProperty::Request(v),
}).collect()
}
+
+ fn put(&self, policy: PutPolicy, stream: Content) -> BoxFuture<Result<()>> {
+ todo!()
+ }
}
#[derive(Clone)]
@@ -111,10 +115,18 @@ impl DavNode for HomeNode {
])),
dav::PropertyRequest::GetContentType => dav::AnyProperty::Value(dav::Property::GetContentType("httpd/unix-directory".into())),
dav::PropertyRequest::Extension(all::PropertyRequest::Cal(cal::PropertyRequest::CalendarHomeSet)) =>
- dav::AnyProperty::Value(dav::Property::Extension(all::Property::Cal(cal::Property::CalendarHomeSet(dav::Href(/*CalendarListNode{}.path(user)*/ todo!()))))),
+ dav::AnyProperty::Value(dav::Property::Extension(all::Property::Cal(cal::Property::CalendarHomeSet(dav::Href(
+ //@FIXME we are hardcoding the calendar path, instead we would want to use
+ //objects
+ format!("/{}/calendar/", user.username)
+ ))))),
v => dav::AnyProperty::Request(v),
}).collect()
}
+
+ fn put(&self, policy: PutPolicy, stream: Content) -> BoxFuture<Result<()>> {
+ todo!()
+ }
}
#[derive(Clone)]
@@ -184,6 +196,10 @@ impl DavNode for CalendarListNode {
v => dav::AnyProperty::Request(v),
}).collect()
}
+
+ fn put(&self, policy: PutPolicy, stream: Content) -> BoxFuture<Result<()>> {
+ todo!()
+ }
}
#[derive(Clone)]
@@ -270,6 +286,10 @@ impl DavNode for CalendarNode {
v => dav::AnyProperty::Request(v),
}).collect()
}
+
+ fn put(&self, policy: PutPolicy, stream: Content) -> BoxFuture<Result<()>> {
+ todo!()
+ }
}
const FAKE_ICS: &str = r#"BEGIN:VCALENDAR
@@ -350,6 +370,10 @@ impl DavNode for EventNode {
v => dav::AnyProperty::Request(v),
}).collect()
}
+
+ fn put(&self, policy: PutPolicy, stream: Content) -> BoxFuture<Result<()>> {
+ todo!()
+ }
}
#[derive(Clone)]
@@ -383,4 +407,9 @@ impl DavNode for CreateEventNode {
fn properties(&self, _user: &ArcUser, prop: dav::PropName<All>) -> Vec<dav::AnyProperty<All>> {
vec![]
}
+
+ fn put(&self, policy: PutPolicy, stream: Content) -> BoxFuture<Result<()>> {
+ //@TODO write file
+ todo!()
+ }
}