mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 08:12:24 +00:00
carddav: Implement DAV Push
This commit is contained in:
@@ -2,35 +2,13 @@ use crate::Error;
|
||||
use actix_web::http::header;
|
||||
use actix_web::web::{Data, Path};
|
||||
use actix_web::{HttpRequest, HttpResponse};
|
||||
use rustical_dav::push::PushRegister;
|
||||
use rustical_store::auth::User;
|
||||
use rustical_store::{CalendarStore, Subscription, SubscriptionStore};
|
||||
use rustical_xml::{XmlDeserialize, XmlDocument, XmlRootTag};
|
||||
use rustical_xml::XmlDocument;
|
||||
use tracing::instrument;
|
||||
use tracing_actix_web::RootSpan;
|
||||
|
||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAVPUSH")]
|
||||
struct WebPushSubscription {
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAVPUSH")]
|
||||
push_resource: String,
|
||||
}
|
||||
|
||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||
struct SubscriptionElement {
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAVPUSH")]
|
||||
pub web_push_subscription: WebPushSubscription,
|
||||
}
|
||||
|
||||
#[derive(XmlDeserialize, XmlRootTag, Clone, Debug, PartialEq)]
|
||||
#[xml(root = b"push-register")]
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAVPUSH")]
|
||||
struct PushRegister {
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAVPUSH")]
|
||||
subscription: SubscriptionElement,
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAVPUSH")]
|
||||
expires: Option<String>,
|
||||
}
|
||||
|
||||
#[instrument(parent = root_span.id(), skip(store, subscription_store, root_span, req))]
|
||||
pub async fn route_post<C: CalendarStore + ?Sized, S: SubscriptionStore + ?Sized>(
|
||||
path: Path<(String, String)>,
|
||||
@@ -79,37 +57,3 @@ pub async fn route_post<C: CalendarStore + ?Sized, S: SubscriptionStore + ?Sized
|
||||
.append_header((header::EXPIRES, expires.to_rfc2822()))
|
||||
.finish())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[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