mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 14:42:30 +00:00
DAV Push: Add supported-triggers
This commit is contained in:
@@ -48,7 +48,7 @@ pub fn caldav_service<
|
||||
HeaderName::from_static("dav"),
|
||||
// https://datatracker.ietf.org/doc/html/rfc4918#section-18
|
||||
HeaderValue::from_static(
|
||||
"1, 3, access-control, calendar-access, extended-mkcol, calendar-no-timezone",
|
||||
"1, 3, access-control, calendar-access, extended-mkcol, calendar-no-timezone, webdav-push",
|
||||
),
|
||||
));
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ pub fn carddav_service<AP: AuthenticationProvider, A: AddressbookStore, S: Subsc
|
||||
HeaderName::from_static("dav"),
|
||||
// https://datatracker.ietf.org/doc/html/rfc4918#section-18
|
||||
HeaderValue::from_static(
|
||||
"1, 3, access-control, addressbook, extended-mkcol",
|
||||
"1, 3, access-control, addressbook, extended-mkcol, webdav-push",
|
||||
),
|
||||
));
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use actix_web::{http::StatusCode, FromRequest, HttpRequest, ResponseError};
|
||||
use futures_util::future::{err, ok, Ready};
|
||||
use actix_web::{FromRequest, HttpRequest, ResponseError, http::StatusCode};
|
||||
use futures_util::future::{Ready, err, ok};
|
||||
use rustical_xml::ValueSerialize;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
@@ -12,13 +13,24 @@ impl ResponseError for InvalidDepthHeader {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Depth {
|
||||
Zero,
|
||||
One,
|
||||
Infinity,
|
||||
}
|
||||
|
||||
impl ValueSerialize for Depth {
|
||||
fn serialize(&self) -> String {
|
||||
match self {
|
||||
Depth::Zero => "0",
|
||||
Depth::One => "1",
|
||||
Depth::Infinity => "Infinity",
|
||||
}
|
||||
.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&[u8]> for Depth {
|
||||
type Error = InvalidDepthHeader;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::Transports;
|
||||
use crate::{ContentUpdate, PropertyUpdate, SupportedTrigger, SupportedTriggers, Transports};
|
||||
use rustical_dav::header::Depth;
|
||||
use rustical_xml::{EnumUnitVariants, EnumVariants, XmlDeserialize, XmlSerialize};
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumUnitVariants, EnumVariants)]
|
||||
@@ -10,11 +11,21 @@ pub enum DavPushExtensionProp {
|
||||
Transports(Transports),
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAVPUSH")]
|
||||
Topic(String),
|
||||
#[xml(skip_deserializing)]
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAVPUSH")]
|
||||
SupportedTriggers(SupportedTriggers),
|
||||
}
|
||||
|
||||
pub trait DavPushExtension {
|
||||
fn get_topic(&self) -> String;
|
||||
|
||||
fn supported_triggers(&self) -> SupportedTriggers {
|
||||
SupportedTriggers(vec![
|
||||
SupportedTrigger::ContentUpdate(ContentUpdate(Depth::One)),
|
||||
SupportedTrigger::PropertyUpdate(PropertyUpdate(Depth::One)),
|
||||
])
|
||||
}
|
||||
|
||||
fn get_prop(
|
||||
&self,
|
||||
prop: &DavPushExtensionPropName,
|
||||
@@ -24,6 +35,9 @@ pub trait DavPushExtension {
|
||||
DavPushExtensionProp::Transports(Default::default())
|
||||
}
|
||||
DavPushExtensionPropName::Topic => DavPushExtensionProp::Topic(self.get_topic()),
|
||||
DavPushExtensionPropName::SupportedTriggers => {
|
||||
DavPushExtensionProp::SupportedTriggers(self.supported_triggers())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use rustical_dav::header::Depth;
|
||||
use rustical_xml::XmlSerialize;
|
||||
|
||||
#[derive(Debug, Clone, XmlSerialize, PartialEq)]
|
||||
@@ -20,3 +21,24 @@ impl Default for Transports {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(XmlSerialize, PartialEq, Clone)]
|
||||
pub struct SupportedTriggers(#[xml(flatten, ty = "untagged")] pub Vec<SupportedTrigger>);
|
||||
|
||||
#[derive(XmlSerialize, PartialEq, Clone)]
|
||||
pub enum SupportedTrigger {
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAVPUSH")]
|
||||
ContentUpdate(ContentUpdate),
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAVPUSH")]
|
||||
PropertyUpdate(PropertyUpdate),
|
||||
}
|
||||
|
||||
#[derive(XmlSerialize, PartialEq, Clone)]
|
||||
pub struct ContentUpdate(
|
||||
#[xml(rename = b"depth", ns = "rustical_dav::namespace::NS_DAV")] pub Depth,
|
||||
);
|
||||
|
||||
#[derive(XmlSerialize, PartialEq, Clone)]
|
||||
pub struct PropertyUpdate(
|
||||
#[xml(rename = b"depth", ns = "rustical_dav::namespace::NS_DAV")] pub Depth,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user