mirror of
https://github.com/lennart-k/rustical.git
synced 2026-01-30 11:48:18 +00:00
xml: Implement namespace for Unparsed
This commit is contained in:
@@ -71,6 +71,7 @@ pub async fn axum_route_proppatch<R: ResourceService>(
|
|||||||
route_proppatch(&path, uri.path(), &body, &principal, &resource_service).await
|
route_proppatch(&path, uri.path(), &body, &principal, &resource_service).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_lines)]
|
||||||
pub async fn route_proppatch<R: ResourceService>(
|
pub async fn route_proppatch<R: ResourceService>(
|
||||||
path_components: &R::PathComponents,
|
path_components: &R::PathComponents,
|
||||||
path: &str,
|
path: &str,
|
||||||
@@ -116,12 +117,14 @@ pub async fn route_proppatch<R: ResourceService>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
SetPropertyPropWrapper::Invalid(invalid) => {
|
SetPropertyPropWrapper::Invalid(invalid) => {
|
||||||
let propname = invalid.tag_name();
|
let Unparsed(propns, propname) = invalid;
|
||||||
|
|
||||||
if let Some(full_propname) = <R::Resource as Resource>::list_props()
|
if let Some(full_propname) = <R::Resource as Resource>::list_props()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find_map(|(ns, tag)| {
|
.find_map(|(ns, tag)| {
|
||||||
if tag == propname.as_str() {
|
if (ns, tag)
|
||||||
|
== (propns.as_ref().map(NamespaceOwned::as_ref), &propname)
|
||||||
|
{
|
||||||
Some((ns.map(NamespaceOwned::from), tag.to_owned()))
|
Some((ns.map(NamespaceOwned::from), tag.to_owned()))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@@ -133,7 +136,7 @@ pub async fn route_proppatch<R: ResourceService>(
|
|||||||
// - internal properties
|
// - internal properties
|
||||||
props_conflict.push(full_propname);
|
props_conflict.push(full_propname);
|
||||||
} else {
|
} else {
|
||||||
props_not_found.push((None, propname));
|
props_not_found.push((propns, propname));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ impl Error {
|
|||||||
Self::NotFound => StatusCode::NOT_FOUND,
|
Self::NotFound => StatusCode::NOT_FOUND,
|
||||||
Self::AlreadyExists => StatusCode::CONFLICT,
|
Self::AlreadyExists => StatusCode::CONFLICT,
|
||||||
Self::ReadOnly => StatusCode::FORBIDDEN,
|
Self::ReadOnly => StatusCode::FORBIDDEN,
|
||||||
// TODO: Can also be Bad Request, depending on when this is raised
|
|
||||||
Self::IcalError(_err) => StatusCode::INTERNAL_SERVER_ERROR,
|
Self::IcalError(_err) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
Self::InvalidPrincipalType(_) => StatusCode::BAD_REQUEST,
|
Self::InvalidPrincipalType(_) => StatusCode::BAD_REQUEST,
|
||||||
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use quick_xml::name::Namespace;
|
use quick_xml::name::Namespace;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
|
||||||
pub struct NamespaceOwned(pub Vec<u8>);
|
pub struct NamespaceOwned(pub Vec<u8>);
|
||||||
|
|
||||||
impl<'a> From<Namespace<'a>> for NamespaceOwned {
|
impl<'a> From<Namespace<'a>> for NamespaceOwned {
|
||||||
|
|||||||
@@ -1,18 +1,21 @@
|
|||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
|
|
||||||
use quick_xml::events::BytesStart;
|
use quick_xml::{events::BytesStart, name::ResolveResult};
|
||||||
|
|
||||||
use crate::{XmlDeserialize, XmlError};
|
use crate::{NamespaceOwned, XmlDeserialize, XmlError};
|
||||||
|
|
||||||
// TODO: actually implement
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct Unparsed(String);
|
pub struct Unparsed(pub Option<NamespaceOwned>, pub String);
|
||||||
|
|
||||||
impl Unparsed {
|
impl Unparsed {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn tag_name(&self) -> String {
|
pub const fn ns(&self) -> Option<&NamespaceOwned> {
|
||||||
// TODO: respect namespace?
|
self.0.as_ref()
|
||||||
self.0.clone()
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub const fn tag_name(&self) -> &str {
|
||||||
|
self.1.as_str()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,7 +30,12 @@ impl XmlDeserialize for Unparsed {
|
|||||||
let mut buf = vec![];
|
let mut buf = vec![];
|
||||||
reader.read_to_end_into(start.name(), &mut buf)?;
|
reader.read_to_end_into(start.name(), &mut buf)?;
|
||||||
}
|
}
|
||||||
let tag_name = String::from_utf8_lossy(start.local_name().as_ref()).to_string();
|
let (ns, tag_name) = reader.resolver().resolve_element(start.name());
|
||||||
Ok(Self(tag_name))
|
let ns: Option<NamespaceOwned> = match ns {
|
||||||
|
ResolveResult::Bound(ns) => Some(ns.into()),
|
||||||
|
ResolveResult::Unbound | ResolveResult::Unknown(_) => None,
|
||||||
|
};
|
||||||
|
let tag_name = String::from_utf8_lossy(tag_name.as_ref()).to_string();
|
||||||
|
Ok(Self(ns, tag_name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user