mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
xml: Add janky implementation for namespaces without prefix
This commit is contained in:
@@ -33,6 +33,7 @@ struct SetPropertyPropWrapperWrapper<T: XmlDeserialize> {
|
|||||||
// We are <set>
|
// We are <set>
|
||||||
#[derive(XmlDeserialize, Clone, Debug)]
|
#[derive(XmlDeserialize, Clone, Debug)]
|
||||||
struct SetPropertyElement<T: XmlDeserialize> {
|
struct SetPropertyElement<T: XmlDeserialize> {
|
||||||
|
#[xml(ns = "crate::namespace::NS_DAV")]
|
||||||
prop: T,
|
prop: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,17 +51,21 @@ struct PropertyElement {
|
|||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug)]
|
#[derive(XmlDeserialize, Clone, Debug)]
|
||||||
struct RemovePropertyElement {
|
struct RemovePropertyElement {
|
||||||
|
#[xml(ns = "crate::namespace::NS_DAV")]
|
||||||
prop: PropertyElement,
|
prop: PropertyElement,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug)]
|
#[derive(XmlDeserialize, Clone, Debug)]
|
||||||
enum Operation<T: XmlDeserialize> {
|
enum Operation<T: XmlDeserialize> {
|
||||||
|
#[xml(ns = "crate::namespace::NS_DAV")]
|
||||||
Set(SetPropertyElement<T>),
|
Set(SetPropertyElement<T>),
|
||||||
|
#[xml(ns = "crate::namespace::NS_DAV")]
|
||||||
Remove(RemovePropertyElement),
|
Remove(RemovePropertyElement),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlRootTag, Clone, Debug)]
|
#[derive(XmlDeserialize, XmlRootTag, Clone, Debug)]
|
||||||
#[xml(root = b"propertyupdate")]
|
#[xml(root = b"propertyupdate")]
|
||||||
|
#[xml(ns = "crate::namespace::NS_DAV")]
|
||||||
struct PropertyupdateElement<T: XmlDeserialize> {
|
struct PropertyupdateElement<T: XmlDeserialize> {
|
||||||
#[xml(ty = "untagged", flatten)]
|
#[xml(ty = "untagged", flatten)]
|
||||||
operations: Vec<Operation<T>>,
|
operations: Vec<Operation<T>>,
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ impl<PT: XmlSerialize> Default for ResponseElement<PT> {
|
|||||||
#[derive(XmlSerialize, XmlRootTag)]
|
#[derive(XmlSerialize, XmlRootTag)]
|
||||||
#[xml(root = b"multistatus", ns = "crate::namespace::NS_DAV")]
|
#[xml(root = b"multistatus", ns = "crate::namespace::NS_DAV")]
|
||||||
#[xml(ns_prefix(
|
#[xml(ns_prefix(
|
||||||
crate::namespace::NS_DAV = b"D",
|
crate::namespace::NS_DAV = b"",
|
||||||
crate::namespace::NS_CARDDAV = b"CARD",
|
crate::namespace::NS_CARDDAV = b"CARD",
|
||||||
crate::namespace::NS_CALDAV = b"CAL",
|
crate::namespace::NS_CALDAV = b"CAL",
|
||||||
crate::namespace::NS_CALENDARSERVER = b"CS"
|
crate::namespace::NS_CALENDARSERVER = b"CS"
|
||||||
|
|||||||
@@ -248,7 +248,12 @@ impl NamedStruct {
|
|||||||
.ns_prefix
|
.ns_prefix
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(ns, prefix)| {
|
.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());
|
let a = syn::LitByteStr::new(&attr_name, prefix.span());
|
||||||
quote! {
|
quote! {
|
||||||
bytes_start.push_attribute((#a.as_ref(), #ns.as_ref()));
|
bytes_start.push_attribute((#a.as_ref(), #ns.as_ref()));
|
||||||
@@ -275,7 +280,13 @@ impl NamedStruct {
|
|||||||
let prefix = ns
|
let prefix = ns
|
||||||
.map(|ns| namespaces.get(&ns))
|
.map(|ns| namespaces.get(&ns))
|
||||||
.unwrap_or(None)
|
.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 has_prefix = prefix.is_some();
|
||||||
let tagname = tag.map(|tag| [&prefix.unwrap_or_default(), tag].concat());
|
let tagname = tag.map(|tag| [&prefix.unwrap_or_default(), tag].concat());
|
||||||
let qname = tagname.as_ref().map(|tagname| ::quick_xml::name::QName(tagname));
|
let qname = tagname.as_ref().map(|tagname| ::quick_xml::name::QName(tagname));
|
||||||
|
|||||||
@@ -47,7 +47,13 @@ impl XmlSerialize for () {
|
|||||||
let prefix = ns
|
let prefix = ns
|
||||||
.map(|ns| namespaces.get(&ns))
|
.map(|ns| namespaces.get(&ns))
|
||||||
.unwrap_or(None)
|
.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 has_prefix = prefix.is_some();
|
||||||
let tagname = tag.map(|tag| [&prefix.unwrap_or_default(), tag].concat());
|
let tagname = tag.map(|tag| [&prefix.unwrap_or_default(), tag].concat());
|
||||||
let qname = tagname.as_ref().map(|tagname| QName(tagname));
|
let qname = tagname.as_ref().map(|tagname| QName(tagname));
|
||||||
|
|||||||
@@ -103,7 +103,13 @@ impl<T: Value> XmlSerialize for T {
|
|||||||
let prefix = ns
|
let prefix = ns
|
||||||
.map(|ns| namespaces.get(&ns))
|
.map(|ns| namespaces.get(&ns))
|
||||||
.unwrap_or(None)
|
.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 has_prefix = prefix.is_some();
|
||||||
let tagname = tag.map(|tag| [&prefix.unwrap_or_default(), tag].concat());
|
let tagname = tag.map(|tag| [&prefix.unwrap_or_default(), tag].concat());
|
||||||
let qname = tagname.as_ref().map(|tagname| QName(tagname));
|
let qname = tagname.as_ref().map(|tagname| QName(tagname));
|
||||||
|
|||||||
Reference in New Issue
Block a user