Do not silently drop an invalid frame

This commit is contained in:
Quentin 2024-04-21 13:47:45 +02:00
parent b6c656de8f
commit 936f851fdb
Signed by: quentin
GPG key ID: E9602264D639FF68
3 changed files with 42 additions and 7 deletions

View file

@ -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> { 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_frames = BodyStream::new(req.into_body());
let stream_of_bytes = stream_of_frames let stream_of_bytes = stream_of_frames
.try_filter_map(|frame| async move { Ok(frame.into_data().ok()) }) .map_ok(|frame| frame.into_data())
.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err)); .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 = tokio_util::io::StreamReader::new(stream_of_bytes);
let async_read = std::pin::pin!(async_read); let async_read = std::pin::pin!(async_read);
let mut rdr = dxml::Reader::new(quick_xml::reader::NsReader::from_reader(async_read)).await?; let mut rdr = dxml::Reader::new(quick_xml::reader::NsReader::from_reader(async_read)).await?;

View file

@ -1,4 +1,5 @@
use anyhow::Result; use anyhow::Result;
use futures::Stream;
use futures::future::BoxFuture; use futures::future::BoxFuture;
use aero_dav::types as dav; use aero_dav::types as dav;
@ -6,6 +7,7 @@ use aero_dav::realization::All;
use aero_collections::user::User; use aero_collections::user::User;
type ArcUser = std::sync::Arc<User>; type ArcUser = std::sync::Arc<User>;
pub(crate) type Content = Box<dyn Stream<Item=Result<u64>>>;
pub(crate) enum PutPolicy { pub(crate) enum PutPolicy {
CreateOnly, CreateOnly,
@ -28,8 +30,8 @@ pub(crate) trait DavNode: Send {
fn supported_properties(&self, user: &ArcUser) -> dav::PropName<All>; fn supported_properties(&self, user: &ArcUser) -> dav::PropName<All>;
/// Get the values for the given properties /// Get the values for the given properties
fn properties(&self, user: &ArcUser, prop: dav::PropName<All>) -> Vec<dav::AnyProperty<All>>; fn properties(&self, user: &ArcUser, prop: dav::PropName<All>) -> Vec<dav::AnyProperty<All>>;
/// Put a child /// Put an element (create or update)
//fn put(&self, policy: PutPolicy, stream: TryStream) -> BoxFuture<Result<dyn DavNode>>; fn put(&self, policy: PutPolicy, stream: Content) -> BoxFuture<Result<()>>;
/// Get content /// Get content
//fn content(&self) -> TryStream; //fn content(&self) -> TryStream;

View file

@ -2,7 +2,7 @@ use std::sync::Arc;
type ArcUser = std::sync::Arc<User>; type ArcUser = std::sync::Arc<User>;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use futures::stream::StreamExt; use futures::stream::{TryStream, StreamExt};
use futures::{future::BoxFuture, future::FutureExt}; use futures::{future::BoxFuture, future::FutureExt};
use aero_collections::{user::User, calendar::Calendar, davdag::BlobId}; 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 aero_dav::realization::{All, self as all};
use crate::dav::node::DavNode; use crate::dav::node::{DavNode, PutPolicy, Content};
#[derive(Clone)] #[derive(Clone)]
pub(crate) struct RootNode {} pub(crate) struct RootNode {}
@ -60,6 +60,10 @@ impl DavNode for RootNode {
v => dav::AnyProperty::Request(v), v => dav::AnyProperty::Request(v),
}).collect() }).collect()
} }
fn put(&self, policy: PutPolicy, stream: Content) -> BoxFuture<Result<()>> {
todo!()
}
} }
#[derive(Clone)] #[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::GetContentType => dav::AnyProperty::Value(dav::Property::GetContentType("httpd/unix-directory".into())),
dav::PropertyRequest::Extension(all::PropertyRequest::Cal(cal::PropertyRequest::CalendarHomeSet)) => 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), v => dav::AnyProperty::Request(v),
}).collect() }).collect()
} }
fn put(&self, policy: PutPolicy, stream: Content) -> BoxFuture<Result<()>> {
todo!()
}
} }
#[derive(Clone)] #[derive(Clone)]
@ -184,6 +196,10 @@ impl DavNode for CalendarListNode {
v => dav::AnyProperty::Request(v), v => dav::AnyProperty::Request(v),
}).collect() }).collect()
} }
fn put(&self, policy: PutPolicy, stream: Content) -> BoxFuture<Result<()>> {
todo!()
}
} }
#[derive(Clone)] #[derive(Clone)]
@ -270,6 +286,10 @@ impl DavNode for CalendarNode {
v => dav::AnyProperty::Request(v), v => dav::AnyProperty::Request(v),
}).collect() }).collect()
} }
fn put(&self, policy: PutPolicy, stream: Content) -> BoxFuture<Result<()>> {
todo!()
}
} }
const FAKE_ICS: &str = r#"BEGIN:VCALENDAR const FAKE_ICS: &str = r#"BEGIN:VCALENDAR
@ -350,6 +370,10 @@ impl DavNode for EventNode {
v => dav::AnyProperty::Request(v), v => dav::AnyProperty::Request(v),
}).collect() }).collect()
} }
fn put(&self, policy: PutPolicy, stream: Content) -> BoxFuture<Result<()>> {
todo!()
}
} }
#[derive(Clone)] #[derive(Clone)]
@ -383,4 +407,9 @@ impl DavNode for CreateEventNode {
fn properties(&self, _user: &ArcUser, prop: dav::PropName<All>) -> Vec<dav::AnyProperty<All>> { fn properties(&self, _user: &ArcUser, prop: dav::PropName<All>) -> Vec<dav::AnyProperty<All>> {
vec![] vec![]
} }
fn put(&self, policy: PutPolicy, stream: Content) -> BoxFuture<Result<()>> {
//@TODO write file
todo!()
}
} }