2024-03-04 12:36:41 +00:00
|
|
|
use std::borrow::Cow;
|
2024-03-04 21:27:37 +00:00
|
|
|
use std::future::Future;
|
2024-03-04 12:36:41 +00:00
|
|
|
|
2024-03-04 16:55:48 +00:00
|
|
|
use quick_xml::events::{Event, BytesStart, BytesDecl, BytesText};
|
2024-03-04 12:36:41 +00:00
|
|
|
use quick_xml::events::attributes::AttrError;
|
2024-03-04 16:55:48 +00:00
|
|
|
use quick_xml::name::{Namespace, QName, PrefixDeclaration, ResolveResult, ResolveResult::*};
|
|
|
|
use quick_xml::reader::NsReader;
|
2024-03-04 12:36:41 +00:00
|
|
|
use tokio::io::AsyncBufRead;
|
|
|
|
|
|
|
|
use super::types::*;
|
2024-03-05 18:06:04 +00:00
|
|
|
use super::error::ParsingError;
|
2024-03-06 22:24:54 +00:00
|
|
|
use super::xml::{Node, QRead, Reader, IRead, DAV_URN, CAL_URN};
|
2024-03-04 12:36:41 +00:00
|
|
|
|
2024-03-06 15:09:20 +00:00
|
|
|
//@TODO (1) Rewrite all objects as Href,
|
|
|
|
// where we return Ok(None) instead of trying to find the object at any cost.
|
|
|
|
// Add a xml.find<E: Qread>() -> Result<Option<E>, ParsingError> or similar for the cases we
|
|
|
|
// really need the object
|
|
|
|
// (2) Rewrite QRead and replace Result<Option<_>, _> with Result<_, _>, not found being a possible
|
|
|
|
// error.
|
|
|
|
// (3) Rewrite vectors with xml.collect<E: QRead>() -> Result<Vec<E>, _>
|
|
|
|
// (4) Something for alternatives would be great but no idea yet
|
|
|
|
|
2024-03-06 09:12:02 +00:00
|
|
|
// ---- ROOT ----
|
2024-03-06 11:42:27 +00:00
|
|
|
|
|
|
|
/// Propfind request
|
2024-03-05 18:06:04 +00:00
|
|
|
impl<E: Extension> QRead<PropFind<E>> for PropFind<E> {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
2024-03-04 16:55:48 +00:00
|
|
|
// Find propfind
|
2024-03-06 22:24:54 +00:00
|
|
|
xml.open(DAV_URN, "propfind").await?;
|
|
|
|
|
2024-03-04 16:55:48 +00:00
|
|
|
// Find any tag
|
2024-03-04 21:27:37 +00:00
|
|
|
let propfind: PropFind<E> = loop {
|
2024-03-04 16:55:48 +00:00
|
|
|
match xml.peek() {
|
2024-03-04 21:27:37 +00:00
|
|
|
Event::Start(_) if xml.is_tag(DAV_URN, "allprop") => {
|
2024-03-06 22:24:54 +00:00
|
|
|
xml.open(DAV_URN, "allprop").await?;
|
|
|
|
let includ = xml.maybe_find::<Include<E>>().await?;
|
|
|
|
let r = PropFind::AllProp(includ);
|
2024-03-04 21:27:37 +00:00
|
|
|
xml.tag_stop(DAV_URN, "allprop").await?;
|
|
|
|
break r
|
2024-03-04 16:55:48 +00:00
|
|
|
},
|
2024-03-04 21:27:37 +00:00
|
|
|
Event::Start(_) if xml.is_tag(DAV_URN, "prop") => {
|
2024-03-06 22:24:54 +00:00
|
|
|
break PropFind::Prop(xml.find::<PropName<E>>().await?);
|
2024-03-04 16:55:48 +00:00
|
|
|
},
|
2024-03-04 21:27:37 +00:00
|
|
|
Event::Empty(_) if xml.is_tag(DAV_URN, "allprop") => {
|
|
|
|
xml.next().await?;
|
|
|
|
break PropFind::AllProp(None)
|
|
|
|
},
|
|
|
|
Event::Empty(_) if xml.is_tag(DAV_URN, "propname") => {
|
|
|
|
xml.next().await?;
|
|
|
|
break PropFind::PropName
|
|
|
|
},
|
|
|
|
_ => { xml.skip().await?; },
|
2024-03-04 16:55:48 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Close tag
|
2024-03-04 21:27:37 +00:00
|
|
|
xml.tag_stop(DAV_URN, "propfind").await?;
|
|
|
|
|
2024-03-06 22:24:54 +00:00
|
|
|
Ok(propfind)
|
2024-03-04 21:27:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-06 11:42:27 +00:00
|
|
|
/// PROPPATCH request
|
|
|
|
impl<E: Extension> QRead<PropertyUpdate<E>> for PropertyUpdate<E> {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "propertyupdate").await?;
|
|
|
|
let collected_items = xml.collect::<PropertyUpdateItem<E>>().await?;
|
2024-03-06 11:42:27 +00:00
|
|
|
xml.tag_stop(DAV_URN, "propertyupdate").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
Ok(PropertyUpdate(collected_items))
|
2024-03-06 11:42:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-06 15:09:20 +00:00
|
|
|
/// Generic response
|
2024-03-06 19:58:41 +00:00
|
|
|
impl<E: Extension, N: Node<N>> QRead<Multistatus<E,N>> for Multistatus<E,N> {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "multistatus").await?;
|
2024-03-06 17:35:54 +00:00
|
|
|
let mut responses = Vec::new();
|
|
|
|
let mut responsedescription = None;
|
|
|
|
|
|
|
|
loop {
|
2024-03-06 22:24:54 +00:00
|
|
|
let mut dirty = false;
|
|
|
|
xml.maybe_push(&mut responses, &mut dirty).await?;
|
|
|
|
xml.maybe_read(&mut responsedescription, &mut dirty).await?;
|
|
|
|
if !dirty {
|
2024-03-06 17:35:54 +00:00
|
|
|
match xml.peek() {
|
|
|
|
Event::End(_) => break,
|
|
|
|
_ => xml.skip().await?,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xml.tag_stop(DAV_URN, "multistatus").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
Ok(Multistatus { responses, responsedescription })
|
2024-03-06 17:35:54 +00:00
|
|
|
}
|
|
|
|
}
|
2024-03-06 11:42:27 +00:00
|
|
|
|
2024-03-06 15:09:20 +00:00
|
|
|
// LOCK REQUEST
|
|
|
|
impl QRead<LockInfo> for LockInfo {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "lockinfo").await?;
|
2024-03-06 15:09:20 +00:00
|
|
|
let (mut m_scope, mut m_type, mut owner) = (None, None, None);
|
|
|
|
loop {
|
2024-03-06 22:24:54 +00:00
|
|
|
let mut dirty = false;
|
|
|
|
xml.maybe_read::<LockScope>(&mut m_scope, &mut dirty).await?;
|
|
|
|
xml.maybe_read::<LockType>(&mut m_type, &mut dirty).await?;
|
|
|
|
xml.maybe_read::<Owner>(&mut owner, &mut dirty).await?;
|
|
|
|
|
|
|
|
if !dirty {
|
2024-03-06 15:09:20 +00:00
|
|
|
match xml.peek() {
|
|
|
|
Event::End(_) => break,
|
|
|
|
_ => xml.skip().await?,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xml.tag_stop(DAV_URN, "lockinfo").await?;
|
|
|
|
match (m_scope, m_type) {
|
2024-03-06 22:24:54 +00:00
|
|
|
(Some(lockscope), Some(locktype)) => Ok(LockInfo { lockscope, locktype, owner }),
|
2024-03-06 15:09:20 +00:00
|
|
|
_ => Err(ParsingError::MissingChild),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// LOCK RESPONSE
|
|
|
|
impl<E: Extension> QRead<PropValue<E>> for PropValue<E> {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "prop").await?;
|
|
|
|
let mut acc = xml.collect::<Property<E>>().await?;
|
2024-03-06 15:09:20 +00:00
|
|
|
xml.tag_stop(DAV_URN, "prop").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
Ok(PropValue(acc))
|
2024-03-06 15:09:20 +00:00
|
|
|
}
|
|
|
|
}
|
2024-03-06 11:42:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// Error response
|
2024-03-06 09:12:02 +00:00
|
|
|
impl<E: Extension> QRead<Error<E>> for Error<E> {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "error").await?;
|
|
|
|
let violations = xml.collect::<Violation<E>>().await?;
|
2024-03-06 09:12:02 +00:00
|
|
|
xml.tag_stop(DAV_URN, "error").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
Ok(Error(violations))
|
2024-03-06 09:12:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-06 11:42:27 +00:00
|
|
|
|
|
|
|
|
2024-03-06 09:12:02 +00:00
|
|
|
// ---- INNER XML
|
2024-03-06 19:58:41 +00:00
|
|
|
impl<E: Extension, N: Node<N>> QRead<Response<E,N>> for Response<E,N> {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "response").await?;
|
2024-03-06 19:58:41 +00:00
|
|
|
let (mut status, mut error, mut responsedescription, mut location) = (None, None, None, None);
|
|
|
|
let mut href = Vec::new();
|
|
|
|
let mut propstat = Vec::new();
|
2024-03-06 17:35:54 +00:00
|
|
|
|
2024-03-06 19:58:41 +00:00
|
|
|
loop {
|
2024-03-06 22:24:54 +00:00
|
|
|
let mut dirty = false;
|
|
|
|
xml.maybe_read::<Status>(&mut status, &mut dirty).await?;
|
|
|
|
xml.maybe_push::<Href>(&mut href, &mut dirty).await?;
|
|
|
|
xml.maybe_push::<PropStat<E,N>>(&mut propstat, &mut dirty).await?;
|
|
|
|
xml.maybe_read::<Error<E>>(&mut error, &mut dirty).await?;
|
|
|
|
xml.maybe_read::<ResponseDescription>(&mut responsedescription, &mut dirty).await?;
|
|
|
|
xml.maybe_read::<Location>(&mut location, &mut dirty).await?;
|
|
|
|
|
|
|
|
if !dirty {
|
2024-03-06 19:58:41 +00:00
|
|
|
match xml.peek() {
|
|
|
|
Event::End(_) => break,
|
|
|
|
_ => { xml.skip().await? },
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xml.tag_stop(DAV_URN, "response").await?;
|
|
|
|
match (status, &propstat[..], &href[..]) {
|
2024-03-06 22:24:54 +00:00
|
|
|
(Some(status), &[], &[_, ..]) => Ok(Response {
|
2024-03-06 19:58:41 +00:00
|
|
|
status_or_propstat: StatusOrPropstat::Status(href, status),
|
|
|
|
error, responsedescription, location,
|
2024-03-06 22:24:54 +00:00
|
|
|
}),
|
|
|
|
(None, &[_, ..], &[_, ..]) => Ok(Response {
|
2024-03-06 19:58:41 +00:00
|
|
|
status_or_propstat: StatusOrPropstat::PropStat(href.into_iter().next().unwrap(), propstat),
|
|
|
|
error, responsedescription, location,
|
2024-03-06 22:24:54 +00:00
|
|
|
}),
|
2024-03-06 19:58:41 +00:00
|
|
|
(Some(_), &[_, ..], _) => Err(ParsingError::InvalidValue),
|
|
|
|
_ => Err(ParsingError::MissingChild),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<E: Extension, N: Node<N>> QRead<PropStat<E,N>> for PropStat<E,N> {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "propstat").await?;
|
|
|
|
|
|
|
|
let (mut m_prop, mut m_status, mut error, mut responsedescription) = (None, None, None, None);
|
|
|
|
|
|
|
|
loop {
|
|
|
|
let mut dirty = false;
|
|
|
|
xml.maybe_read::<N>(&mut m_prop, &mut dirty).await?;
|
|
|
|
xml.maybe_read::<Status>(&mut m_status, &mut dirty).await?;
|
|
|
|
xml.maybe_read::<Error<E>>(&mut error, &mut dirty).await?;
|
|
|
|
xml.maybe_read::<ResponseDescription>(&mut responsedescription, &mut dirty).await?;
|
|
|
|
|
|
|
|
if !dirty {
|
|
|
|
match xml.peek() {
|
|
|
|
Event::End(_) => break,
|
|
|
|
_ => xml.skip().await?,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xml.tag_stop(DAV_URN, "propstat").await?;
|
|
|
|
match (m_prop, m_status) {
|
|
|
|
(Some(prop), Some(status)) => Ok(PropStat { prop, status, error, responsedescription }),
|
|
|
|
_ => Err(ParsingError::MissingChild),
|
2024-03-06 19:58:41 +00:00
|
|
|
}
|
2024-03-06 17:35:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-06 19:58:41 +00:00
|
|
|
impl QRead<Status> for Status {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "status").await?;
|
2024-03-06 19:58:41 +00:00
|
|
|
let fullcode = xml.tag_string().await?;
|
|
|
|
let txtcode = fullcode.splitn(3, ' ').nth(1).ok_or(ParsingError::InvalidValue)?;
|
|
|
|
let code = http::status::StatusCode::from_bytes(txtcode.as_bytes()).or(Err(ParsingError::InvalidValue))?;
|
|
|
|
xml.tag_stop(DAV_URN, "status").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
Ok(Status(code))
|
2024-03-06 19:58:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-06 17:35:54 +00:00
|
|
|
impl QRead<ResponseDescription> for ResponseDescription {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "responsedescription").await?;
|
2024-03-06 17:35:54 +00:00
|
|
|
let cnt = xml.tag_string().await?;
|
|
|
|
xml.tag_stop(DAV_URN, "responsedescription").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
Ok(ResponseDescription(cnt))
|
2024-03-06 17:35:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-06 19:58:41 +00:00
|
|
|
impl QRead<Location> for Location {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "location").await?;
|
|
|
|
let href = xml.find::<Href>().await?;
|
2024-03-06 19:58:41 +00:00
|
|
|
xml.tag_stop(DAV_URN, "location").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
Ok(Location(href))
|
2024-03-06 19:58:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-06 11:42:27 +00:00
|
|
|
impl<E: Extension> QRead<PropertyUpdateItem<E>> for PropertyUpdateItem<E> {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
match Remove::qread(xml).await {
|
|
|
|
Err(ParsingError::Recoverable) => (),
|
|
|
|
otherwise => return otherwise.map(PropertyUpdateItem::Remove),
|
2024-03-06 11:42:27 +00:00
|
|
|
}
|
2024-03-06 22:24:54 +00:00
|
|
|
Set::qread(xml).await.map(PropertyUpdateItem::Set)
|
2024-03-06 11:42:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<E: Extension> QRead<Remove<E>> for Remove<E> {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "remove").await?;
|
|
|
|
let propname = xml.find::<PropName<E>>().await?;
|
2024-03-06 11:42:27 +00:00
|
|
|
xml.tag_stop(DAV_URN, "remove").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
Ok(Remove(propname))
|
2024-03-06 11:42:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<E: Extension> QRead<Set<E>> for Set<E> {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "set").await?;
|
|
|
|
let propvalue = xml.find::<PropValue<E>>().await?;
|
2024-03-06 11:42:27 +00:00
|
|
|
xml.tag_stop(DAV_URN, "set").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
Ok(Set(propvalue))
|
2024-03-06 11:42:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-06 09:12:02 +00:00
|
|
|
impl<E: Extension> QRead<Violation<E>> for Violation<E> {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
let bs = match xml.peek() {
|
|
|
|
Event::Start(b) | Event::Empty(b) => b,
|
|
|
|
_ => return Err(ParsingError::Recoverable),
|
|
|
|
};
|
|
|
|
|
|
|
|
// Option 1: a pure DAV property
|
|
|
|
let (ns, loc) = xml.rdr.resolve_element(bs.name());
|
|
|
|
if matches!(ns, Bound(Namespace(ns)) if ns == DAV_URN) {
|
|
|
|
match loc.into_inner() {
|
|
|
|
b"lock-token-matches-request-uri" => {
|
|
|
|
xml.next().await?;
|
|
|
|
return Ok(Violation::LockTokenMatchesRequestUri)
|
|
|
|
},
|
|
|
|
b"lock-token-submitted" => {
|
|
|
|
xml.next().await?;
|
|
|
|
let links = xml.collect::<Href>().await?;
|
|
|
|
xml.tag_stop(DAV_URN, "lock-token-submitted").await?;
|
|
|
|
return Ok(Violation::LockTokenSubmitted(links))
|
|
|
|
},
|
|
|
|
b"no-conflicting-lock" => {
|
|
|
|
// start tag
|
|
|
|
xml.next().await?;
|
|
|
|
let links = xml.collect::<Href>().await?;
|
|
|
|
xml.tag_stop(DAV_URN, "no-conflicting-lock").await?;
|
|
|
|
return Ok(Violation::NoConflictingLock(links))
|
|
|
|
},
|
|
|
|
b"no-external-entities" => {
|
|
|
|
xml.next().await?;
|
|
|
|
return Ok(Violation::NoExternalEntities)
|
|
|
|
},
|
|
|
|
b"preserved-live-properties" => {
|
|
|
|
xml.next().await?;
|
|
|
|
return Ok(Violation::PreservedLiveProperties)
|
2024-03-06 09:12:02 +00:00
|
|
|
},
|
2024-03-06 22:24:54 +00:00
|
|
|
b"propfind-finite-depth" => {
|
|
|
|
xml.next().await?;
|
|
|
|
return Ok(Violation::PropfindFiniteDepth)
|
|
|
|
},
|
|
|
|
b"cannot-modify-protected-property" => {
|
|
|
|
xml.next().await?;
|
|
|
|
return Ok(Violation::CannotModifyProtectedProperty)
|
|
|
|
},
|
|
|
|
_ => (),
|
2024-03-06 09:12:02 +00:00
|
|
|
};
|
|
|
|
}
|
2024-03-06 22:24:54 +00:00
|
|
|
|
|
|
|
// Option 2: an extension property, delegating
|
|
|
|
E::Error::qread(xml).await.map(Violation::Extension)
|
2024-03-06 09:12:02 +00:00
|
|
|
}
|
|
|
|
}
|
2024-03-04 21:27:37 +00:00
|
|
|
|
2024-03-05 18:06:04 +00:00
|
|
|
impl<E: Extension> QRead<Include<E>> for Include<E> {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "include").await?;
|
|
|
|
let acc = xml.collect::<PropertyRequest<E>>().await?;
|
2024-03-04 21:27:37 +00:00
|
|
|
xml.tag_stop(DAV_URN, "include").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
Ok(Include(acc))
|
2024-03-04 21:27:37 +00:00
|
|
|
}
|
|
|
|
}
|
2024-03-04 16:55:48 +00:00
|
|
|
|
2024-03-05 18:06:04 +00:00
|
|
|
impl<E: Extension> QRead<PropName<E>> for PropName<E> {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "prop").await?;
|
|
|
|
let acc = xml.collect::<PropertyRequest<E>>().await?;
|
2024-03-04 21:27:37 +00:00
|
|
|
xml.tag_stop(DAV_URN, "prop").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
Ok(PropName(acc))
|
2024-03-04 21:27:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 18:06:04 +00:00
|
|
|
impl<E: Extension> QRead<PropertyRequest<E>> for PropertyRequest<E> {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
2024-03-06 11:42:27 +00:00
|
|
|
let bs = match xml.peek() {
|
|
|
|
Event::Start(b) | Event::Empty(b) => b,
|
2024-03-06 22:24:54 +00:00
|
|
|
_ => return Err(ParsingError::Recoverable),
|
2024-03-06 11:42:27 +00:00
|
|
|
};
|
2024-03-05 15:07:47 +00:00
|
|
|
|
2024-03-06 11:42:27 +00:00
|
|
|
// Option 1: a pure core DAV property
|
|
|
|
let (ns, loc) = xml.rdr.resolve_element(bs.name());
|
|
|
|
if matches!(ns, Bound(Namespace(ns)) if ns == DAV_URN) {
|
2024-03-06 22:24:54 +00:00
|
|
|
let maybe_res = match loc.into_inner() {
|
2024-03-06 11:42:27 +00:00
|
|
|
b"creationdate" => Some(PropertyRequest::CreationDate),
|
|
|
|
b"displayname" => Some(PropertyRequest::DisplayName),
|
|
|
|
b"getcontentlanguage" => Some(PropertyRequest::GetContentLanguage),
|
|
|
|
b"getcontentlength" => Some(PropertyRequest::GetContentLength),
|
|
|
|
b"getcontenttype" => Some(PropertyRequest::GetContentType),
|
|
|
|
b"getetag" => Some(PropertyRequest::GetEtag),
|
|
|
|
b"getlastmodified" => Some(PropertyRequest::GetLastModified),
|
|
|
|
b"lockdiscovery" => Some(PropertyRequest::LockDiscovery),
|
|
|
|
b"resourcetype" => Some(PropertyRequest::ResourceType),
|
|
|
|
b"supportedlock" => Some(PropertyRequest::SupportedLock),
|
|
|
|
_ => None,
|
|
|
|
};
|
|
|
|
// Close the current tag if we read something
|
2024-03-06 22:24:54 +00:00
|
|
|
if let Some(res) = maybe_res {
|
2024-03-06 11:42:27 +00:00
|
|
|
xml.skip().await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
return Ok(res)
|
2024-03-05 15:07:47 +00:00
|
|
|
}
|
2024-03-06 11:42:27 +00:00
|
|
|
}
|
2024-03-05 15:07:47 +00:00
|
|
|
|
2024-03-06 11:42:27 +00:00
|
|
|
// Option 2: an extension property, delegating
|
2024-03-06 22:24:54 +00:00
|
|
|
E::PropertyRequest::qread(xml).await.map(PropertyRequest::Extension)
|
2024-03-06 11:42:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<E: Extension> QRead<Property<E>> for Property<E> {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
2024-03-06 11:42:27 +00:00
|
|
|
use chrono::{DateTime, FixedOffset, TimeZone};
|
|
|
|
|
|
|
|
let bs = match xml.peek() {
|
|
|
|
Event::Start(b) | Event::Empty(b) => b,
|
2024-03-06 22:24:54 +00:00
|
|
|
_ => return Err(ParsingError::Recoverable),
|
2024-03-06 09:12:02 +00:00
|
|
|
};
|
|
|
|
|
2024-03-06 11:42:27 +00:00
|
|
|
// Option 1: a pure core DAV property
|
|
|
|
let (ns, loc) = xml.rdr.resolve_element(bs.name());
|
|
|
|
if matches!(ns, Bound(Namespace(ns)) if ns == DAV_URN) {
|
2024-03-06 22:24:54 +00:00
|
|
|
match loc.into_inner() {
|
2024-03-06 11:42:27 +00:00
|
|
|
b"creationdate" => {
|
|
|
|
xml.next().await?;
|
|
|
|
let datestr = xml.tag_string().await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
return Ok(Property::CreationDate(DateTime::parse_from_rfc3339(datestr.as_str())?))
|
2024-03-06 11:42:27 +00:00
|
|
|
},
|
|
|
|
b"displayname" => {
|
|
|
|
xml.next().await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
return Ok(Property::DisplayName(xml.tag_string().await?))
|
2024-03-06 11:42:27 +00:00
|
|
|
},
|
|
|
|
b"getcontentlanguage" => {
|
|
|
|
xml.next().await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
return Ok(Property::GetContentLanguage(xml.tag_string().await?))
|
2024-03-06 11:42:27 +00:00
|
|
|
},
|
|
|
|
b"getcontentlength" => {
|
|
|
|
xml.next().await?;
|
|
|
|
let cl = xml.tag_string().await?.parse::<u64>()?;
|
2024-03-06 22:24:54 +00:00
|
|
|
return Ok(Property::GetContentLength(cl))
|
2024-03-06 11:42:27 +00:00
|
|
|
},
|
|
|
|
b"getcontenttype" => {
|
|
|
|
xml.next().await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
return Ok(Property::GetContentType(xml.tag_string().await?))
|
2024-03-06 11:42:27 +00:00
|
|
|
},
|
|
|
|
b"getetag" => {
|
|
|
|
xml.next().await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
return Ok(Property::GetEtag(xml.tag_string().await?))
|
2024-03-06 11:42:27 +00:00
|
|
|
},
|
|
|
|
b"getlastmodified" => {
|
|
|
|
xml.next().await?;
|
|
|
|
let datestr = xml.tag_string().await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
return Ok(Property::CreationDate(DateTime::parse_from_rfc2822(datestr.as_str())?))
|
2024-03-06 11:42:27 +00:00
|
|
|
},
|
|
|
|
b"lockdiscovery" => {
|
|
|
|
xml.next().await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
let acc = xml.collect::<ActiveLock>().await?;
|
2024-03-06 11:42:27 +00:00
|
|
|
xml.tag_stop(DAV_URN, "lockdiscovery").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
return Ok(Property::LockDiscovery(acc))
|
2024-03-06 11:42:27 +00:00
|
|
|
},
|
|
|
|
b"resourcetype" => {
|
|
|
|
xml.next().await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
let acc = xml.collect::<ResourceType<E>>().await?;
|
2024-03-06 11:42:27 +00:00
|
|
|
xml.tag_stop(DAV_URN, "resourcetype").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
return Ok(Property::ResourceType(acc))
|
2024-03-06 11:42:27 +00:00
|
|
|
},
|
|
|
|
b"supportedlock" => {
|
|
|
|
xml.next().await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
let acc = xml.collect::<LockEntry>().await?;
|
2024-03-06 11:42:27 +00:00
|
|
|
xml.tag_stop(DAV_URN, "supportedlock").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
return Ok(Property::SupportedLock(acc))
|
2024-03-06 11:42:27 +00:00
|
|
|
},
|
2024-03-06 22:24:54 +00:00
|
|
|
_ => (),
|
2024-03-06 11:42:27 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Option 2: an extension property, delegating
|
2024-03-06 22:24:54 +00:00
|
|
|
E::Property::qread(xml).await.map(Property::Extension)
|
2024-03-06 11:42:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl QRead<ActiveLock> for ActiveLock {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "activelock").await?;
|
2024-03-06 15:09:20 +00:00
|
|
|
let (mut m_scope, mut m_type, mut m_depth, mut owner, mut timeout, mut locktoken, mut m_root) =
|
|
|
|
(None, None, None, None, None, None, None);
|
|
|
|
|
|
|
|
loop {
|
2024-03-06 22:24:54 +00:00
|
|
|
let mut dirty = false;
|
|
|
|
xml.maybe_read::<LockScope>(&mut m_scope, &mut dirty).await?;
|
|
|
|
xml.maybe_read::<LockType>(&mut m_type, &mut dirty).await?;
|
|
|
|
xml.maybe_read::<Depth>(&mut m_depth, &mut dirty).await?;
|
|
|
|
xml.maybe_read::<Owner>(&mut owner, &mut dirty).await?;
|
|
|
|
xml.maybe_read::<Timeout>(&mut timeout, &mut dirty).await?;
|
|
|
|
xml.maybe_read::<LockToken>(&mut locktoken, &mut dirty).await?;
|
|
|
|
xml.maybe_read::<LockRoot>(&mut m_root, &mut dirty).await?;
|
|
|
|
|
|
|
|
if !dirty {
|
2024-03-06 15:09:20 +00:00
|
|
|
match xml.peek() {
|
|
|
|
Event::End(_) => break,
|
|
|
|
_ => { xml.skip().await?; },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xml.tag_stop(DAV_URN, "activelock").await?;
|
|
|
|
match (m_scope, m_type, m_depth, m_root) {
|
|
|
|
(Some(lockscope), Some(locktype), Some(depth), Some(lockroot)) =>
|
2024-03-06 22:24:54 +00:00
|
|
|
Ok(ActiveLock { lockscope, locktype, depth, owner, timeout, locktoken, lockroot }),
|
2024-03-06 15:09:20 +00:00
|
|
|
_ => Err(ParsingError::MissingChild),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl QRead<Depth> for Depth {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "depth").await?;
|
2024-03-06 15:09:20 +00:00
|
|
|
let depth_str = xml.tag_string().await?;
|
|
|
|
xml.tag_stop(DAV_URN, "depth").await?;
|
|
|
|
match depth_str.as_str() {
|
2024-03-06 22:24:54 +00:00
|
|
|
"0" => Ok(Depth::Zero),
|
|
|
|
"1" => Ok(Depth::One),
|
|
|
|
"infinity" => Ok(Depth::Infinity),
|
2024-03-06 15:09:20 +00:00
|
|
|
_ => Err(ParsingError::WrongToken),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl QRead<Owner> for Owner {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "owner").await?;
|
2024-03-06 15:09:20 +00:00
|
|
|
|
|
|
|
let mut owner = Owner::Unknown;
|
|
|
|
loop {
|
|
|
|
match xml.peek() {
|
|
|
|
Event::Text(_) | Event::CData(_) => {
|
|
|
|
let txt = xml.tag_string().await?;
|
|
|
|
if matches!(owner, Owner::Unknown) {
|
|
|
|
owner = Owner::Txt(txt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Event::Start(_) | Event::Empty(_) => {
|
2024-03-06 22:24:54 +00:00
|
|
|
match Href::qread(xml).await {
|
|
|
|
Ok(href) => { owner = Owner::Href(href); },
|
|
|
|
Err(ParsingError::Recoverable) => { xml.skip().await?; },
|
|
|
|
Err(e) => return Err(e),
|
2024-03-06 15:09:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Event::End(_) => break,
|
|
|
|
_ => { xml.skip().await?; },
|
|
|
|
}
|
|
|
|
};
|
|
|
|
xml.tag_stop(DAV_URN, "owner").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
Ok(owner)
|
2024-03-06 15:09:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl QRead<Timeout> for Timeout {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
2024-03-06 15:09:20 +00:00
|
|
|
const SEC_PFX: &str = "SEC_PFX";
|
2024-03-06 22:24:54 +00:00
|
|
|
xml.open(DAV_URN, "timeout").await?;
|
2024-03-06 15:09:20 +00:00
|
|
|
|
|
|
|
let timeout = match xml.tag_string().await?.as_str() {
|
|
|
|
"Infinite" => Timeout::Infinite,
|
|
|
|
seconds => match seconds.strip_prefix(SEC_PFX) {
|
|
|
|
Some(secs) => Timeout::Seconds(secs.parse::<u32>()?),
|
|
|
|
None => return Err(ParsingError::InvalidValue),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
xml.tag_stop(DAV_URN, "timeout").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
Ok(timeout)
|
2024-03-06 15:09:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl QRead<LockToken> for LockToken {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "locktoken").await?;
|
|
|
|
let href = Href::qread(xml).await?;
|
2024-03-06 15:09:20 +00:00
|
|
|
xml.tag_stop(DAV_URN, "locktoken").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
Ok(LockToken(href))
|
2024-03-06 15:09:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl QRead<LockRoot> for LockRoot {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "lockroot").await?;
|
|
|
|
let href = Href::qread(xml).await?;
|
2024-03-06 15:09:20 +00:00
|
|
|
xml.tag_stop(DAV_URN, "lockroot").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
Ok(LockRoot(href))
|
2024-03-06 11:42:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<E: Extension> QRead<ResourceType<E>> for ResourceType<E> {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
2024-03-06 11:42:27 +00:00
|
|
|
match xml.peek() {
|
|
|
|
Event::Empty(b) if xml.is_tag(DAV_URN, "collection") => {
|
|
|
|
xml.next().await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
Ok(ResourceType::Collection)
|
2024-03-06 11:42:27 +00:00
|
|
|
},
|
2024-03-06 22:24:54 +00:00
|
|
|
_ => E::ResourceType::qread(xml).await.map(ResourceType::Extension),
|
2024-03-06 11:42:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl QRead<LockEntry> for LockEntry {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "lockentry").await?;
|
2024-03-06 11:42:27 +00:00
|
|
|
let (mut maybe_scope, mut maybe_type) = (None, None);
|
|
|
|
|
2024-03-06 09:12:02 +00:00
|
|
|
loop {
|
2024-03-06 22:24:54 +00:00
|
|
|
let mut dirty = false;
|
|
|
|
xml.maybe_read::<LockScope>(&mut maybe_scope, &mut dirty).await?;
|
|
|
|
xml.maybe_read::<LockType>(&mut maybe_type, &mut dirty).await?;
|
|
|
|
if !dirty {
|
|
|
|
match xml.peek() {
|
|
|
|
Event::End(_) => break,
|
|
|
|
_ => xml.skip().await?,
|
|
|
|
};
|
2024-03-06 11:42:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xml.tag_stop(DAV_URN, "lockentry").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
match (maybe_scope, maybe_type) {
|
|
|
|
(Some(lockscope), Some(locktype)) => Ok(LockEntry { lockscope, locktype }),
|
|
|
|
_ => Err(ParsingError::MissingChild),
|
|
|
|
}
|
2024-03-06 11:42:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl QRead<LockScope> for LockScope {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "lockscope").await?;
|
2024-03-06 15:09:20 +00:00
|
|
|
|
2024-03-06 11:42:27 +00:00
|
|
|
let lockscope = loop {
|
|
|
|
match xml.peek() {
|
2024-03-06 15:09:20 +00:00
|
|
|
Event::Empty(_) if xml.is_tag(DAV_URN, "exclusive") => {
|
2024-03-06 11:42:27 +00:00
|
|
|
xml.next().await?;
|
|
|
|
break LockScope::Exclusive
|
2024-03-06 09:12:02 +00:00
|
|
|
},
|
2024-03-06 15:09:20 +00:00
|
|
|
Event::Empty(_) if xml.is_tag(DAV_URN, "shared") => {
|
2024-03-06 11:42:27 +00:00
|
|
|
xml.next().await?;
|
|
|
|
break LockScope::Shared
|
2024-03-06 09:12:02 +00:00
|
|
|
}
|
|
|
|
_ => xml.skip().await?,
|
|
|
|
};
|
2024-03-06 11:42:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
xml.tag_stop(DAV_URN, "lockscope").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
Ok(lockscope)
|
2024-03-06 11:42:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl QRead<LockType> for LockType {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "locktype").await?;
|
2024-03-06 15:09:20 +00:00
|
|
|
|
2024-03-06 11:42:27 +00:00
|
|
|
let locktype = loop {
|
|
|
|
match xml.peek() {
|
|
|
|
Event::Empty(b) if xml.is_tag(DAV_URN, "write") => {
|
|
|
|
xml.next().await?;
|
|
|
|
break LockType::Write
|
|
|
|
}
|
|
|
|
_ => xml.skip().await?,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
xml.tag_stop(DAV_URN, "locktype").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
Ok(locktype)
|
2024-03-06 11:42:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl QRead<Href> for Href {
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
|
|
|
|
xml.open(DAV_URN, "href").await?;
|
2024-03-06 11:42:27 +00:00
|
|
|
let mut url = xml.tag_string().await?;
|
2024-03-06 09:12:02 +00:00
|
|
|
xml.tag_stop(DAV_URN, "href").await?;
|
2024-03-06 22:24:54 +00:00
|
|
|
Ok(Href(url))
|
2024-03-06 09:12:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-04 16:55:48 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2024-03-05 18:06:04 +00:00
|
|
|
use crate::dav::realization::Core;
|
2024-03-04 12:36:41 +00:00
|
|
|
|
2024-03-04 16:55:48 +00:00
|
|
|
#[tokio::test]
|
2024-03-05 15:07:47 +00:00
|
|
|
async fn basic_propfind_propname() {
|
2024-03-04 21:27:37 +00:00
|
|
|
let src = r#"<?xml version="1.0" encoding="utf-8" ?>
|
|
|
|
<rando/>
|
|
|
|
<garbage><old/></garbage>
|
|
|
|
<D:propfind xmlns:D="DAV:">
|
|
|
|
<D:propname/>
|
|
|
|
</D:propfind>
|
|
|
|
"#;
|
2024-03-04 12:36:41 +00:00
|
|
|
|
2024-03-05 18:06:04 +00:00
|
|
|
let mut rdr = Reader::new(NsReader::from_reader(src.as_bytes())).await.unwrap();
|
2024-03-06 22:24:54 +00:00
|
|
|
let got = rdr.find::<PropFind::<Core>>().await.unwrap();
|
2024-03-05 18:06:04 +00:00
|
|
|
|
|
|
|
assert_eq!(got, PropFind::<Core>::PropName);
|
2024-03-04 12:36:41 +00:00
|
|
|
}
|
2024-03-05 18:06:04 +00:00
|
|
|
|
2024-03-05 15:07:47 +00:00
|
|
|
#[tokio::test]
|
|
|
|
async fn basic_propfind_prop() {
|
|
|
|
let src = r#"<?xml version="1.0" encoding="utf-8" ?>
|
|
|
|
<rando/>
|
|
|
|
<garbage><old/></garbage>
|
|
|
|
<D:propfind xmlns:D="DAV:">
|
|
|
|
<D:prop>
|
2024-03-05 18:06:04 +00:00
|
|
|
<D:displayname/>
|
|
|
|
<D:getcontentlength/>
|
|
|
|
<D:getcontenttype/>
|
|
|
|
<D:getetag/>
|
|
|
|
<D:getlastmodified/>
|
|
|
|
<D:resourcetype/>
|
|
|
|
<D:supportedlock/>
|
2024-03-05 15:07:47 +00:00
|
|
|
</D:prop>
|
|
|
|
</D:propfind>
|
|
|
|
"#;
|
|
|
|
|
2024-03-05 18:06:04 +00:00
|
|
|
let mut rdr = Reader::new(NsReader::from_reader(src.as_bytes())).await.unwrap();
|
2024-03-06 22:24:54 +00:00
|
|
|
let got = rdr.find::<PropFind::<Core>>().await.unwrap();
|
2024-03-05 18:06:04 +00:00
|
|
|
|
2024-03-05 15:07:47 +00:00
|
|
|
assert_eq!(got, PropFind::Prop(PropName(vec![
|
|
|
|
PropertyRequest::DisplayName,
|
|
|
|
PropertyRequest::GetContentLength,
|
|
|
|
PropertyRequest::GetContentType,
|
|
|
|
PropertyRequest::GetEtag,
|
|
|
|
PropertyRequest::GetLastModified,
|
|
|
|
PropertyRequest::ResourceType,
|
|
|
|
PropertyRequest::SupportedLock,
|
|
|
|
])));
|
|
|
|
}
|
2024-03-06 09:12:02 +00:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn rfc_lock_error() {
|
|
|
|
let src = r#"<?xml version="1.0" encoding="utf-8" ?>
|
|
|
|
<D:error xmlns:D="DAV:">
|
|
|
|
<D:lock-token-submitted>
|
|
|
|
<D:href>/locked/</D:href>
|
|
|
|
</D:lock-token-submitted>
|
|
|
|
</D:error>"#;
|
|
|
|
|
|
|
|
let mut rdr = Reader::new(NsReader::from_reader(src.as_bytes())).await.unwrap();
|
2024-03-06 22:24:54 +00:00
|
|
|
let got = rdr.find::<Error::<Core>>().await.unwrap();
|
2024-03-06 09:12:02 +00:00
|
|
|
|
|
|
|
assert_eq!(got, Error(vec![
|
|
|
|
Violation::LockTokenSubmitted(vec![
|
|
|
|
Href("/locked/".into())
|
|
|
|
])
|
|
|
|
]));
|
|
|
|
}
|
2024-03-06 15:09:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn rfc_propertyupdate() {
|
|
|
|
let src = r#"<?xml version="1.0" encoding="utf-8" ?>
|
|
|
|
<D:propertyupdate xmlns:D="DAV:"
|
|
|
|
xmlns:Z="http://ns.example.com/standards/z39.50/">
|
|
|
|
<D:set>
|
|
|
|
<D:prop>
|
|
|
|
<Z:Authors>
|
|
|
|
<Z:Author>Jim Whitehead</Z:Author>
|
|
|
|
<Z:Author>Roy Fielding</Z:Author>
|
|
|
|
</Z:Authors>
|
|
|
|
</D:prop>
|
|
|
|
</D:set>
|
|
|
|
<D:remove>
|
|
|
|
<D:prop><Z:Copyright-Owner/></D:prop>
|
|
|
|
</D:remove>
|
|
|
|
</D:propertyupdate>"#;
|
|
|
|
|
|
|
|
let mut rdr = Reader::new(NsReader::from_reader(src.as_bytes())).await.unwrap();
|
2024-03-06 22:24:54 +00:00
|
|
|
let got = rdr.find::<PropertyUpdate::<Core>>().await.unwrap();
|
2024-03-06 15:09:20 +00:00
|
|
|
|
|
|
|
assert_eq!(got, PropertyUpdate(vec![
|
|
|
|
PropertyUpdateItem::Set(Set(PropValue(vec![]))),
|
|
|
|
PropertyUpdateItem::Remove(Remove(PropName(vec![]))),
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
2024-03-06 22:24:54 +00:00
|
|
|
async fn rfc_lockinfo() {
|
2024-03-06 15:09:20 +00:00
|
|
|
let src = r#"
|
|
|
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
|
|
<D:lockinfo xmlns:D='DAV:'>
|
|
|
|
<D:lockscope><D:exclusive/></D:lockscope>
|
|
|
|
<D:locktype><D:write/></D:locktype>
|
|
|
|
<D:owner>
|
|
|
|
<D:href>http://example.org/~ejw/contact.html</D:href>
|
|
|
|
</D:owner>
|
|
|
|
</D:lockinfo>
|
|
|
|
"#;
|
|
|
|
|
|
|
|
let mut rdr = Reader::new(NsReader::from_reader(src.as_bytes())).await.unwrap();
|
2024-03-06 22:24:54 +00:00
|
|
|
let got = rdr.find::<LockInfo>().await.unwrap();
|
|
|
|
|
2024-03-06 15:09:20 +00:00
|
|
|
assert_eq!(got, LockInfo {
|
|
|
|
lockscope: LockScope::Exclusive,
|
|
|
|
locktype: LockType::Write,
|
|
|
|
owner: Some(Owner::Href(Href("http://example.org/~ejw/contact.html".into()))),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-03-06 22:24:54 +00:00
|
|
|
#[tokio::test]
|
|
|
|
async fn rfc_multistatus_name() {
|
|
|
|
let src = r#"
|
|
|
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
|
|
<multistatus xmlns="DAV:">
|
|
|
|
<response>
|
|
|
|
<href>http://www.example.com/container/</href>
|
|
|
|
<propstat>
|
|
|
|
<prop xmlns:R="http://ns.example.com/boxschema/">
|
|
|
|
<R:bigbox/>
|
|
|
|
<R:author/>
|
|
|
|
<creationdate/>
|
|
|
|
<displayname/>
|
|
|
|
<resourcetype/>
|
|
|
|
<supportedlock/>
|
|
|
|
</prop>
|
|
|
|
<status>HTTP/1.1 200 OK</status>
|
|
|
|
</propstat>
|
|
|
|
</response>
|
|
|
|
<response>
|
|
|
|
<href>http://www.example.com/container/front.html</href>
|
|
|
|
<propstat>
|
|
|
|
<prop xmlns:R="http://ns.example.com/boxschema/">
|
|
|
|
<R:bigbox/>
|
|
|
|
<creationdate/>
|
|
|
|
<displayname/>
|
|
|
|
<getcontentlength/>
|
|
|
|
<getcontenttype/>
|
|
|
|
<getetag/>
|
|
|
|
<getlastmodified/>
|
|
|
|
<resourcetype/>
|
|
|
|
<supportedlock/>
|
|
|
|
</prop>
|
|
|
|
<status>HTTP/1.1 200 OK</status>
|
|
|
|
</propstat>
|
|
|
|
</response>
|
|
|
|
</multistatus>
|
|
|
|
"#;
|
|
|
|
|
|
|
|
let mut rdr = Reader::new(NsReader::from_reader(src.as_bytes())).await.unwrap();
|
|
|
|
let got = rdr.find::<Multistatus::<Core, PropName<Core>>>().await.unwrap();
|
|
|
|
|
2024-03-07 08:49:09 +00:00
|
|
|
assert_eq!(got, Multistatus {
|
2024-03-06 22:24:54 +00:00
|
|
|
responses: vec![
|
|
|
|
Response {
|
2024-03-07 08:49:09 +00:00
|
|
|
status_or_propstat: StatusOrPropstat::PropStat(
|
|
|
|
Href("http://www.example.com/container/".into()),
|
|
|
|
vec![PropStat {
|
|
|
|
prop: PropName(vec![
|
|
|
|
PropertyRequest::CreationDate,
|
|
|
|
PropertyRequest::DisplayName,
|
|
|
|
PropertyRequest::ResourceType,
|
|
|
|
PropertyRequest::SupportedLock,
|
|
|
|
]),
|
|
|
|
status: Status(http::status::StatusCode::OK),
|
|
|
|
error: None,
|
|
|
|
responsedescription: None,
|
|
|
|
}],
|
|
|
|
),
|
|
|
|
error: None,
|
|
|
|
responsedescription: None,
|
|
|
|
location: None,
|
|
|
|
},
|
|
|
|
Response {
|
|
|
|
status_or_propstat: StatusOrPropstat::PropStat(
|
|
|
|
Href("http://www.example.com/container/front.html".into()),
|
|
|
|
vec![PropStat {
|
|
|
|
prop: PropName(vec![
|
|
|
|
PropertyRequest::CreationDate,
|
|
|
|
PropertyRequest::DisplayName,
|
|
|
|
PropertyRequest::GetContentLength,
|
|
|
|
PropertyRequest::GetContentType,
|
|
|
|
PropertyRequest::GetEtag,
|
|
|
|
PropertyRequest::GetLastModified,
|
|
|
|
PropertyRequest::ResourceType,
|
|
|
|
PropertyRequest::SupportedLock,
|
|
|
|
]),
|
|
|
|
status: Status(http::status::StatusCode::OK),
|
|
|
|
error: None,
|
|
|
|
responsedescription: None,
|
|
|
|
}],
|
|
|
|
),
|
|
|
|
error: None,
|
|
|
|
responsedescription: None,
|
|
|
|
location: None,
|
2024-03-06 22:24:54 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
responsedescription: None,
|
2024-03-07 08:49:09 +00:00
|
|
|
});
|
2024-03-06 22:24:54 +00:00
|
|
|
}
|
2024-03-04 12:36:41 +00:00
|
|
|
}
|