mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 10:32:19 +00:00
WIP: Complete work of propfind parsing
This commit is contained in:
@@ -5,9 +5,9 @@ use crate::resource::PrincipalUri;
|
||||
use crate::resource::Resource;
|
||||
use crate::resource::ResourceService;
|
||||
use crate::xml::MultistatusElement;
|
||||
use crate::xml::PropElement;
|
||||
use crate::xml::PropfindElement;
|
||||
use crate::xml::PropfindType;
|
||||
use rustical_xml::PropName;
|
||||
use rustical_xml::XmlDocument;
|
||||
use tracing::instrument;
|
||||
|
||||
@@ -58,37 +58,36 @@ pub(crate) async fn route_propfind<R: ResourceService>(
|
||||
}
|
||||
|
||||
// A request body is optional. If empty we MUST return all props
|
||||
let propfind: PropfindElement = if !body.is_empty() {
|
||||
PropfindElement::parse_str(&body).map_err(Error::XmlError)?
|
||||
} else {
|
||||
PropfindElement {
|
||||
prop: PropfindType::Allprop,
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: respect namespaces?
|
||||
let props = match &propfind.prop {
|
||||
PropfindType::Allprop => vec!["allprop"],
|
||||
PropfindType::Propname => vec!["propname"],
|
||||
PropfindType::Prop(PropElement(prop_tags)) => prop_tags
|
||||
.iter()
|
||||
.map(|propname| propname.name.as_str())
|
||||
.collect(),
|
||||
};
|
||||
let propfind_self: PropfindElement<<<R::Resource as Resource>::Prop as PropName>::Names> =
|
||||
if !body.is_empty() {
|
||||
PropfindElement::parse_str(&body).map_err(Error::XmlError)?
|
||||
} else {
|
||||
PropfindElement {
|
||||
prop: PropfindType::Allprop,
|
||||
}
|
||||
};
|
||||
let propfind_member: PropfindElement<<<R::MemberType as Resource>::Prop as PropName>::Names> =
|
||||
if !body.is_empty() {
|
||||
PropfindElement::parse_str(&body).map_err(Error::XmlError)?
|
||||
} else {
|
||||
PropfindElement {
|
||||
prop: PropfindType::Allprop,
|
||||
}
|
||||
};
|
||||
|
||||
let mut member_responses = Vec::new();
|
||||
if depth != Depth::Zero {
|
||||
for (subpath, member) in resource_service.get_members(path_components).await? {
|
||||
member_responses.push(member.propfind(
|
||||
member_responses.push(member.propfind_typed(
|
||||
&format!("{}/{}", path.trim_end_matches('/'), subpath),
|
||||
&props,
|
||||
&propfind_member.prop,
|
||||
puri,
|
||||
&user,
|
||||
)?);
|
||||
}
|
||||
}
|
||||
|
||||
let response = resource.propfind(path, &props, puri, &user)?;
|
||||
let response = resource.propfind_typed(path, &propfind_self.prop, puri, &user)?;
|
||||
|
||||
Ok(MultistatusElement {
|
||||
responses: vec![response],
|
||||
|
||||
@@ -7,7 +7,8 @@ use crate::xml::TagList;
|
||||
use crate::xml::multistatus::{PropstatElement, PropstatWrapper, ResponseElement};
|
||||
use http::StatusCode;
|
||||
use quick_xml::name::Namespace;
|
||||
use rustical_xml::EnumUnitVariants;
|
||||
use rustical_xml::NamespaceOwned;
|
||||
use rustical_xml::PropName;
|
||||
use rustical_xml::Unparsed;
|
||||
use rustical_xml::XmlDeserialize;
|
||||
use rustical_xml::XmlDocument;
|
||||
@@ -111,13 +112,15 @@ pub(crate) async fn route_proppatch<R: ResourceService>(
|
||||
}) => {
|
||||
match property {
|
||||
SetPropertyPropWrapper::Valid(prop) => {
|
||||
let propname: <<R::Resource as Resource>::Prop as EnumUnitVariants>::UnitVariants = prop.clone().into();
|
||||
let propname: <<R::Resource as Resource>::Prop as PropName>::Names =
|
||||
prop.clone().into();
|
||||
let (ns, propname): (Option<Namespace>, &str) = propname.into();
|
||||
match resource.set_prop(prop) {
|
||||
Ok(()) => props_ok.push((ns, propname.to_owned())),
|
||||
Err(Error::PropReadOnly) => {
|
||||
props_conflict.push((ns, propname.to_owned()))
|
||||
Ok(()) => {
|
||||
props_ok.push((ns.map(NamespaceOwned::from), propname.to_owned()))
|
||||
}
|
||||
Err(Error::PropReadOnly) => props_conflict
|
||||
.push((ns.map(NamespaceOwned::from), propname.to_owned())),
|
||||
Err(err) => return Err(err.into()),
|
||||
};
|
||||
}
|
||||
@@ -128,7 +131,7 @@ pub(crate) async fn route_proppatch<R: ResourceService>(
|
||||
.into_iter()
|
||||
.find_map(|(ns, tag)| {
|
||||
if tag == propname.as_str() {
|
||||
Some((ns, tag.to_owned()))
|
||||
Some((ns.map(NamespaceOwned::from), tag.to_owned()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -146,14 +149,12 @@ pub(crate) async fn route_proppatch<R: ResourceService>(
|
||||
}
|
||||
Operation::Remove(remove_el) => {
|
||||
let propname = remove_el.prop.0.0;
|
||||
match <<R::Resource as Resource>::Prop as EnumUnitVariants>::UnitVariants::from_str(
|
||||
&propname,
|
||||
) {
|
||||
match <<R::Resource as Resource>::Prop as PropName>::Names::from_str(&propname) {
|
||||
Ok(prop) => match resource.remove_prop(&prop) {
|
||||
Ok(()) => props_ok.push((None, propname)),
|
||||
Err(Error::PropReadOnly) => props_conflict.push({
|
||||
let (ns, tag) = prop.into();
|
||||
(ns, tag.to_owned())
|
||||
(ns.map(NamespaceOwned::from), tag.to_owned())
|
||||
}),
|
||||
Err(err) => return Err(err.into()),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user