mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 07:02:24 +00:00
dav push: Split into multiple files
This commit is contained in:
@@ -1,80 +1,5 @@
|
|||||||
use rustical_xml::{XmlDeserialize, XmlRootTag, XmlSerialize};
|
mod prop;
|
||||||
|
mod push_register;
|
||||||
|
|
||||||
#[derive(Debug, Clone, XmlSerialize, PartialEq)]
|
pub use prop::*;
|
||||||
pub enum Transport {
|
pub use push_register::*;
|
||||||
#[xml(ns = "crate::namespace::NS_DAVPUSH")]
|
|
||||||
WebPush,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, XmlSerialize, PartialEq)]
|
|
||||||
pub struct Transports {
|
|
||||||
#[xml(flatten, ty = "untagged")]
|
|
||||||
#[xml(ns = "crate::namespace::NS_DAVPUSH")]
|
|
||||||
transports: Vec<Transport>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Transports {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
transports: vec![Transport::WebPush],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
|
||||||
#[xml(ns = "crate::namespace::NS_DAVPUSH")]
|
|
||||||
pub struct WebPushSubscription {
|
|
||||||
#[xml(ns = "crate::namespace::NS_DAVPUSH")]
|
|
||||||
pub push_resource: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
|
||||||
pub struct SubscriptionElement {
|
|
||||||
#[xml(ns = "crate::namespace::NS_DAVPUSH")]
|
|
||||||
pub web_push_subscription: WebPushSubscription,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlRootTag, Clone, Debug, PartialEq)]
|
|
||||||
#[xml(root = b"push-register")]
|
|
||||||
#[xml(ns = "crate::namespace::NS_DAVPUSH")]
|
|
||||||
pub struct PushRegister {
|
|
||||||
#[xml(ns = "crate::namespace::NS_DAVPUSH")]
|
|
||||||
pub subscription: SubscriptionElement,
|
|
||||||
#[xml(ns = "crate::namespace::NS_DAVPUSH")]
|
|
||||||
pub expires: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use rustical_xml::XmlDocument;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_xml_push_register() {
|
|
||||||
let push_register = PushRegister::parse_str(
|
|
||||||
r#"
|
|
||||||
<?xml version="1.0" encoding="utf-8" ?>
|
|
||||||
<push-register xmlns="https://bitfire.at/webdav-push">
|
|
||||||
<subscription>
|
|
||||||
<web-push-subscription>
|
|
||||||
<push-resource>https://up.example.net/yohd4yai5Phiz1wi</push-resource>
|
|
||||||
</web-push-subscription>
|
|
||||||
</subscription>
|
|
||||||
<expires>Wed, 20 Dec 2023 10:03:31 GMT</expires>
|
|
||||||
</push-register>
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(
|
|
||||||
push_register,
|
|
||||||
PushRegister {
|
|
||||||
subscription: SubscriptionElement {
|
|
||||||
web_push_subscription: WebPushSubscription {
|
|
||||||
push_resource: "https://up.example.net/yohd4yai5Phiz1wi".to_owned()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
expires: Some("Wed, 20 Dec 2023 10:03:31 GMT".to_owned())
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
22
crates/dav/src/push/prop.rs
Normal file
22
crates/dav/src/push/prop.rs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
use rustical_xml::XmlSerialize;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, XmlSerialize, PartialEq)]
|
||||||
|
pub enum Transport {
|
||||||
|
#[xml(ns = "crate::namespace::NS_DAVPUSH")]
|
||||||
|
WebPush,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, XmlSerialize, PartialEq)]
|
||||||
|
pub struct Transports {
|
||||||
|
#[xml(flatten, ty = "untagged")]
|
||||||
|
#[xml(ns = "crate::namespace::NS_DAVPUSH")]
|
||||||
|
transports: Vec<Transport>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Transports {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
transports: vec![Transport::WebPush],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
59
crates/dav/src/push/push_register.rs
Normal file
59
crates/dav/src/push/push_register.rs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
use rustical_xml::{XmlDeserialize, XmlRootTag};
|
||||||
|
|
||||||
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||||
|
#[xml(ns = "crate::namespace::NS_DAVPUSH")]
|
||||||
|
pub struct WebPushSubscription {
|
||||||
|
#[xml(ns = "crate::namespace::NS_DAVPUSH")]
|
||||||
|
pub push_resource: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||||
|
pub struct SubscriptionElement {
|
||||||
|
#[xml(ns = "crate::namespace::NS_DAVPUSH")]
|
||||||
|
pub web_push_subscription: WebPushSubscription,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(XmlDeserialize, XmlRootTag, Clone, Debug, PartialEq)]
|
||||||
|
#[xml(root = b"push-register")]
|
||||||
|
#[xml(ns = "crate::namespace::NS_DAVPUSH")]
|
||||||
|
pub struct PushRegister {
|
||||||
|
#[xml(ns = "crate::namespace::NS_DAVPUSH")]
|
||||||
|
pub subscription: SubscriptionElement,
|
||||||
|
#[xml(ns = "crate::namespace::NS_DAVPUSH")]
|
||||||
|
pub expires: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use rustical_xml::XmlDocument;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_xml_push_register() {
|
||||||
|
let push_register = PushRegister::parse_str(
|
||||||
|
r#"
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<push-register xmlns="https://bitfire.at/webdav-push">
|
||||||
|
<subscription>
|
||||||
|
<web-push-subscription>
|
||||||
|
<push-resource>https://up.example.net/yohd4yai5Phiz1wi</push-resource>
|
||||||
|
</web-push-subscription>
|
||||||
|
</subscription>
|
||||||
|
<expires>Wed, 20 Dec 2023 10:03:31 GMT</expires>
|
||||||
|
</push-register>
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
push_register,
|
||||||
|
PushRegister {
|
||||||
|
subscription: SubscriptionElement {
|
||||||
|
web_push_subscription: WebPushSubscription {
|
||||||
|
push_resource: "https://up.example.net/yohd4yai5Phiz1wi".to_owned()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
expires: Some("Wed, 20 Dec 2023 10:03:31 GMT".to_owned())
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user