xml: Add janky implementation for namespaces without prefix

This commit is contained in:
Lennart
2025-01-01 14:44:02 +01:00
parent 11fa0f24c7
commit 72688f1761
5 changed files with 33 additions and 5 deletions

View File

@@ -33,6 +33,7 @@ struct SetPropertyPropWrapperWrapper<T: XmlDeserialize> {
// We are <set>
#[derive(XmlDeserialize, Clone, Debug)]
struct SetPropertyElement<T: XmlDeserialize> {
#[xml(ns = "crate::namespace::NS_DAV")]
prop: T,
}
@@ -50,17 +51,21 @@ struct PropertyElement {
#[derive(XmlDeserialize, Clone, Debug)]
struct RemovePropertyElement {
#[xml(ns = "crate::namespace::NS_DAV")]
prop: PropertyElement,
}
#[derive(XmlDeserialize, Clone, Debug)]
enum Operation<T: XmlDeserialize> {
#[xml(ns = "crate::namespace::NS_DAV")]
Set(SetPropertyElement<T>),
#[xml(ns = "crate::namespace::NS_DAV")]
Remove(RemovePropertyElement),
}
#[derive(XmlDeserialize, XmlRootTag, Clone, Debug)]
#[xml(root = b"propertyupdate")]
#[xml(ns = "crate::namespace::NS_DAV")]
struct PropertyupdateElement<T: XmlDeserialize> {
#[xml(ty = "untagged", flatten)]
operations: Vec<Operation<T>>,

View File

@@ -88,7 +88,7 @@ impl<PT: XmlSerialize> Default for ResponseElement<PT> {
#[derive(XmlSerialize, XmlRootTag)]
#[xml(root = b"multistatus", ns = "crate::namespace::NS_DAV")]
#[xml(ns_prefix(
crate::namespace::NS_DAV = b"D",
crate::namespace::NS_DAV = b"",
crate::namespace::NS_CARDDAV = b"CARD",
crate::namespace::NS_CALDAV = b"CAL",
crate::namespace::NS_CALENDARSERVER = b"CS"

View File

@@ -248,7 +248,12 @@ impl NamedStruct {
.ns_prefix
.iter()
.map(|(ns, prefix)| {
let attr_name = [b"xmlns:".as_ref(), &prefix.value()].concat();
let sep = if !prefix.value().is_empty() {
b":".to_vec()
} else {
b"".to_vec()
};
let attr_name = [b"xmlns".as_ref(), &sep, &prefix.value()].concat();
let a = syn::LitByteStr::new(&attr_name, prefix.span());
quote! {
bytes_start.push_attribute((#a.as_ref(), #ns.as_ref()));
@@ -275,7 +280,13 @@ impl NamedStruct {
let prefix = ns
.map(|ns| namespaces.get(&ns))
.unwrap_or(None)
.map(|prefix| [*prefix, b":"].concat());
.map(|prefix| {
if !prefix.is_empty() {
[*prefix, b":"].concat()
} else {
Vec::new()
}
});
let has_prefix = prefix.is_some();
let tagname = tag.map(|tag| [&prefix.unwrap_or_default(), tag].concat());
let qname = tagname.as_ref().map(|tagname| ::quick_xml::name::QName(tagname));

View File

@@ -47,7 +47,13 @@ impl XmlSerialize for () {
let prefix = ns
.map(|ns| namespaces.get(&ns))
.unwrap_or(None)
.map(|prefix| [*prefix, b":"].concat());
.map(|prefix| {
if !prefix.is_empty() {
[*prefix, b":"].concat()
} else {
Vec::new()
}
});
let has_prefix = prefix.is_some();
let tagname = tag.map(|tag| [&prefix.unwrap_or_default(), tag].concat());
let qname = tagname.as_ref().map(|tagname| QName(tagname));

View File

@@ -103,7 +103,13 @@ impl<T: Value> XmlSerialize for T {
let prefix = ns
.map(|ns| namespaces.get(&ns))
.unwrap_or(None)
.map(|prefix| [*prefix, b":"].concat());
.map(|prefix| {
if !prefix.is_empty() {
[*prefix, b":"].concat()
} else {
Vec::new()
}
});
let has_prefix = prefix.is_some();
let tagname = tag.map(|tag| [&prefix.unwrap_or_default(), tag].concat());
let qname = tagname.as_ref().map(|tagname| QName(tagname));