mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
DAV Push: Add supported-triggers
This commit is contained in:
@@ -48,7 +48,7 @@ pub fn caldav_service<
|
|||||||
HeaderName::from_static("dav"),
|
HeaderName::from_static("dav"),
|
||||||
// https://datatracker.ietf.org/doc/html/rfc4918#section-18
|
// https://datatracker.ietf.org/doc/html/rfc4918#section-18
|
||||||
HeaderValue::from_static(
|
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"),
|
HeaderName::from_static("dav"),
|
||||||
// https://datatracker.ietf.org/doc/html/rfc4918#section-18
|
// https://datatracker.ietf.org/doc/html/rfc4918#section-18
|
||||||
HeaderValue::from_static(
|
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 actix_web::{FromRequest, HttpRequest, ResponseError, http::StatusCode};
|
||||||
use futures_util::future::{err, ok, Ready};
|
use futures_util::future::{Ready, err, ok};
|
||||||
|
use rustical_xml::ValueSerialize;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
@@ -12,13 +13,24 @@ impl ResponseError for InvalidDepthHeader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum Depth {
|
pub enum Depth {
|
||||||
Zero,
|
Zero,
|
||||||
One,
|
One,
|
||||||
Infinity,
|
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 {
|
impl TryFrom<&[u8]> for Depth {
|
||||||
type Error = InvalidDepthHeader;
|
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};
|
use rustical_xml::{EnumUnitVariants, EnumVariants, XmlDeserialize, XmlSerialize};
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumUnitVariants, EnumVariants)]
|
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumUnitVariants, EnumVariants)]
|
||||||
@@ -10,11 +11,21 @@ pub enum DavPushExtensionProp {
|
|||||||
Transports(Transports),
|
Transports(Transports),
|
||||||
#[xml(ns = "rustical_dav::namespace::NS_DAVPUSH")]
|
#[xml(ns = "rustical_dav::namespace::NS_DAVPUSH")]
|
||||||
Topic(String),
|
Topic(String),
|
||||||
|
#[xml(skip_deserializing)]
|
||||||
|
#[xml(ns = "rustical_dav::namespace::NS_DAVPUSH")]
|
||||||
|
SupportedTriggers(SupportedTriggers),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait DavPushExtension {
|
pub trait DavPushExtension {
|
||||||
fn get_topic(&self) -> String;
|
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(
|
fn get_prop(
|
||||||
&self,
|
&self,
|
||||||
prop: &DavPushExtensionPropName,
|
prop: &DavPushExtensionPropName,
|
||||||
@@ -24,6 +35,9 @@ pub trait DavPushExtension {
|
|||||||
DavPushExtensionProp::Transports(Default::default())
|
DavPushExtensionProp::Transports(Default::default())
|
||||||
}
|
}
|
||||||
DavPushExtensionPropName::Topic => DavPushExtensionProp::Topic(self.get_topic()),
|
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;
|
use rustical_xml::XmlSerialize;
|
||||||
|
|
||||||
#[derive(Debug, Clone, XmlSerialize, PartialEq)]
|
#[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