From 936f851fdb120dd0b46c4effeabe0dbb508d4d3d Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Sun, 21 Apr 2024 13:47:45 +0200 Subject: Do not silently drop an invalid frame --- aero-proto/src/dav/codec.rs | 8 ++++++-- aero-proto/src/dav/node.rs | 6 ++++-- aero-proto/src/dav/resource.rs | 35 ++++++++++++++++++++++++++++++++--- 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(status_ok: hyper::Stat pub(crate) async fn deserialize>(req: Request) -> Result { 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; +pub(crate) type Content = Box>>; pub(crate) enum PutPolicy { CreateOnly, @@ -28,8 +30,8 @@ pub(crate) trait DavNode: Send { fn supported_properties(&self, user: &ArcUser) -> dav::PropName; /// Get the values for the given properties fn properties(&self, user: &ArcUser, prop: dav::PropName) -> Vec>; - /// Put a child - //fn put(&self, policy: PutPolicy, stream: TryStream) -> BoxFuture>; + /// Put an element (create or update) + fn put(&self, policy: PutPolicy, stream: Content) -> BoxFuture>; /// 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; 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> { + 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> { + 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> { + 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> { + 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> { + todo!() + } } #[derive(Clone)] @@ -383,4 +407,9 @@ impl DavNode for CreateEventNode { fn properties(&self, _user: &ArcUser, prop: dav::PropName) -> Vec> { vec![] } + + fn put(&self, policy: PutPolicy, stream: Content) -> BoxFuture> { + //@TODO write file + todo!() + } } -- cgit v1.2.3