From 1b688b134dfe0ed09297fdaa71c7f4c908880f62 Mon Sep 17 00:00:00 2001 From: Lennart <18233294+lennart-k@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:28:00 +0100 Subject: [PATCH] dav push: Split into multiple files --- crates/dav/src/push/mod.rs | 83 ++-------------------------- crates/dav/src/push/prop.rs | 22 ++++++++ crates/dav/src/push/push_register.rs | 59 ++++++++++++++++++++ 3 files changed, 85 insertions(+), 79 deletions(-) create mode 100644 crates/dav/src/push/prop.rs create mode 100644 crates/dav/src/push/push_register.rs diff --git a/crates/dav/src/push/mod.rs b/crates/dav/src/push/mod.rs index e48aaa8..4a1c4eb 100644 --- a/crates/dav/src/push/mod.rs +++ b/crates/dav/src/push/mod.rs @@ -1,80 +1,5 @@ -use rustical_xml::{XmlDeserialize, XmlRootTag, XmlSerialize}; +mod prop; +mod push_register; -#[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, -} - -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, -} - -#[cfg(test)] -mod tests { - use super::*; - use rustical_xml::XmlDocument; - - #[test] - fn test_xml_push_register() { - let push_register = PushRegister::parse_str( - r#" - - - - - https://up.example.net/yohd4yai5Phiz1wi - - - Wed, 20 Dec 2023 10:03:31 GMT - - "#, - ) - .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()) - } - ) - } -} +pub use prop::*; +pub use push_register::*; diff --git a/crates/dav/src/push/prop.rs b/crates/dav/src/push/prop.rs new file mode 100644 index 0000000..ffb8307 --- /dev/null +++ b/crates/dav/src/push/prop.rs @@ -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, +} + +impl Default for Transports { + fn default() -> Self { + Self { + transports: vec![Transport::WebPush], + } + } +} diff --git a/crates/dav/src/push/push_register.rs b/crates/dav/src/push/push_register.rs new file mode 100644 index 0000000..aae3c76 --- /dev/null +++ b/crates/dav/src/push/push_register.rs @@ -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, +} + +#[cfg(test)] +mod tests { + use super::*; + use rustical_xml::XmlDocument; + + #[test] + fn test_xml_push_register() { + let push_register = PushRegister::parse_str( + r#" + + + + + https://up.example.net/yohd4yai5Phiz1wi + + + Wed, 20 Dec 2023 10:03:31 GMT + + "#, + ) + .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()) + } + ) + } +}