some refactoring

This commit is contained in:
Lennart
2025-01-01 15:22:51 +01:00
parent 646919587e
commit 40c8624703
6 changed files with 49 additions and 65 deletions

View File

@@ -1,9 +1,10 @@
use derive_more::derive::From;
use rustical_xml::{XmlDeserialize, XmlSerialize}; use rustical_xml::{XmlDeserialize, XmlSerialize};
#[derive(Debug, Clone, XmlDeserialize, XmlSerialize, PartialEq)] #[derive(Debug, Clone, XmlDeserialize, XmlSerialize, PartialEq, From)]
pub struct SupportedCalendarComponent { pub struct SupportedCalendarComponent {
#[xml(ty = "attr")] #[xml(ty = "attr")]
pub name: String, pub name: &'static str,
} }
#[derive(Debug, Clone, XmlDeserialize, XmlSerialize, PartialEq)] #[derive(Debug, Clone, XmlDeserialize, XmlSerialize, PartialEq)]
@@ -12,6 +13,14 @@ pub struct SupportedCalendarComponentSet {
pub comp: Vec<SupportedCalendarComponent>, pub comp: Vec<SupportedCalendarComponent>,
} }
impl Default for SupportedCalendarComponentSet {
fn default() -> Self {
Self {
comp: vec!["VEVENT".into(), "VTODO".into(), "VJOURNAL".into()],
}
}
}
#[derive(Debug, Clone, XmlSerialize, PartialEq)] #[derive(Debug, Clone, XmlSerialize, PartialEq)]
pub struct CalendarData { pub struct CalendarData {
#[xml(ty = "attr")] #[xml(ty = "attr")]

View File

@@ -41,8 +41,8 @@ pub enum CalendarProp {
// WebDAV (RFC 2518) // WebDAV (RFC 2518)
#[xml(ns = "rustical_dav::namespace::NS_DAV")] #[xml(ns = "rustical_dav::namespace::NS_DAV")]
Displayname(Option<String>), Displayname(Option<String>),
#[xml(ns = "rustical_dav::namespace::NS_DAV")] #[xml(ns = "rustical_dav::namespace::NS_DAV", skip_deserializing)]
Getcontenttype(String), Getcontenttype(&'static str),
// WebDav Push // WebDav Push
// NOTE: Here we implement an older version of the spec since the new property name is not reflected // NOTE: Here we implement an older version of the spec since the new property name is not reflected
@@ -62,11 +62,9 @@ pub enum CalendarProp {
CalendarTimezone(Option<String>), CalendarTimezone(Option<String>),
#[xml(ns = "rustical_dav::namespace::NS_ICAL")] #[xml(ns = "rustical_dav::namespace::NS_ICAL")]
CalendarOrder(Option<i64>), CalendarOrder(Option<i64>),
// TODO: Re-add #[xml(ns = "rustical_dav::namespace::NS_CALDAV", skip_deserializing)]
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
SupportedCalendarComponentSet(SupportedCalendarComponentSet), SupportedCalendarComponentSet(SupportedCalendarComponentSet),
#[xml(skip_deserializing)] #[xml(ns = "rustical_dav::namespace::NS_CALDAV", skip_deserializing)]
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
SupportedCalendarData(SupportedCalendarData), SupportedCalendarData(SupportedCalendarData),
#[xml(ns = "rustical_dav::namespace::NS_DAV")] #[xml(ns = "rustical_dav::namespace::NS_DAV")]
MaxResourceSize(i64), MaxResourceSize(i64),
@@ -119,25 +117,13 @@ impl Resource for CalendarResource {
} }
CalendarPropName::CalendarOrder => CalendarProp::CalendarOrder(Some(self.0.order)), CalendarPropName::CalendarOrder => CalendarProp::CalendarOrder(Some(self.0.order)),
CalendarPropName::SupportedCalendarComponentSet => { CalendarPropName::SupportedCalendarComponentSet => {
CalendarProp::SupportedCalendarComponentSet(SupportedCalendarComponentSet { CalendarProp::SupportedCalendarComponentSet(SupportedCalendarComponentSet::default())
comp: vec![
SupportedCalendarComponent {
name: "VEVENT".to_owned(),
},
SupportedCalendarComponent {
name: "VTODO".to_owned(),
},
SupportedCalendarComponent {
name: "VJOURNAL".to_owned(),
},
],
})
} }
CalendarPropName::SupportedCalendarData => { CalendarPropName::SupportedCalendarData => {
CalendarProp::SupportedCalendarData(SupportedCalendarData::default()) CalendarProp::SupportedCalendarData(SupportedCalendarData::default())
} }
CalendarPropName::Getcontenttype => { CalendarPropName::Getcontenttype => {
CalendarProp::Getcontenttype("text/calendar;charset=utf-8".to_owned()) CalendarProp::Getcontenttype("text/calendar;charset=utf-8")
} }
CalendarPropName::Transports => CalendarProp::Transports(Default::default()), CalendarPropName::Transports => CalendarProp::Transports(Default::default()),
CalendarPropName::Topic => { CalendarPropName::Topic => {

View File

@@ -30,8 +30,8 @@ pub enum CalendarObjectProp {
// WebDAV (RFC 2518) // WebDAV (RFC 2518)
#[xml(ns = "rustical_dav::namespace::NS_DAV")] #[xml(ns = "rustical_dav::namespace::NS_DAV")]
Getetag(String), Getetag(String),
#[xml(ns = "rustical_dav::namespace::NS_DAV")] #[xml(ns = "rustical_dav::namespace::NS_DAV", skip_deserializing)]
Getcontenttype(String), Getcontenttype(&'static str),
// CalDAV (RFC 4791) // CalDAV (RFC 4791)
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")] #[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
@@ -66,7 +66,7 @@ impl Resource for CalendarObjectResource {
CalendarObjectProp::CalendarData(self.object.get_ics().to_owned()) CalendarObjectProp::CalendarData(self.object.get_ics().to_owned())
} }
CalendarObjectPropName::Getcontenttype => { CalendarObjectPropName::Getcontenttype => {
CalendarObjectProp::Getcontenttype("text/calendar;charset=utf-8".to_owned()) CalendarObjectProp::Getcontenttype("text/calendar;charset=utf-8")
} }
}) })
} }

View File

@@ -31,8 +31,8 @@ pub enum AddressObjectProp {
// WebDAV (RFC 2518) // WebDAV (RFC 2518)
#[xml(ns = "rustical_dav::namespace::NS_DAV")] #[xml(ns = "rustical_dav::namespace::NS_DAV")]
Getetag(String), Getetag(String),
#[xml(ns = "rustical_dav::namespace::NS_DAV")] #[xml(ns = "rustical_dav::namespace::NS_DAV", skip_deserializing)]
Getcontenttype(String), Getcontenttype(&'static str),
// CalDAV (RFC 4791) // CalDAV (RFC 4791)
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")] #[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
@@ -67,7 +67,7 @@ impl Resource for AddressObjectResource {
AddressObjectProp::AddressData(self.object.get_vcf().to_owned()) AddressObjectProp::AddressData(self.object.get_vcf().to_owned())
} }
AddressObjectPropName::Getcontenttype => { AddressObjectPropName::Getcontenttype => {
AddressObjectProp::Getcontenttype("text/vcard;charset=utf-8".to_owned()) AddressObjectProp::Getcontenttype("text/vcard;charset=utf-8")
} }
}) })
} }

View File

@@ -3,29 +3,28 @@ use rustical_xml::XmlSerialize;
#[derive(Debug, Clone, XmlSerialize, PartialEq)] #[derive(Debug, Clone, XmlSerialize, PartialEq)]
pub struct AddressDataType { pub struct AddressDataType {
#[xml(ty = "attr")] #[xml(ty = "attr")]
pub content_type: String, pub content_type: &'static str,
#[xml(ty = "attr")] #[xml(ty = "attr")]
pub version: String, pub version: &'static str,
} }
#[derive(Debug, Clone, XmlSerialize, PartialEq)] #[derive(Debug, Clone, XmlSerialize, PartialEq)]
pub struct SupportedAddressData { pub struct SupportedAddressData {
// #[serde(rename = "CARD:address-data-type", alias = "address-data-type")] #[xml(ns = "rustical_dav::namespace::NS_CARDDAV", flatten)]
#[xml(flatten)] address_data_type: &'static [AddressDataType],
address_data_type: Vec<AddressDataType>,
} }
impl Default for SupportedAddressData { impl Default for SupportedAddressData {
fn default() -> Self { fn default() -> Self {
Self { Self {
address_data_type: vec![ address_data_type: &[
AddressDataType { AddressDataType {
content_type: "text/vcard".to_owned(), content_type: "text/vcard",
version: "3.0".to_owned(), version: "3.0",
}, },
AddressDataType { AddressDataType {
content_type: "text/vcard".to_owned(), content_type: "text/vcard",
version: "4.0".to_owned(), version: "4.0",
}, },
], ],
} }
@@ -34,42 +33,34 @@ impl Default for SupportedAddressData {
#[derive(Debug, Clone, XmlSerialize, PartialEq)] #[derive(Debug, Clone, XmlSerialize, PartialEq)]
pub enum ReportMethod { pub enum ReportMethod {
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
AddressbookMultiget, AddressbookMultiget,
SyncCollection, SyncCollection,
} }
#[derive(Debug, Clone, XmlSerialize, PartialEq)]
pub struct ReportWrapper {
#[xml(ty = "untagged")]
report: ReportMethod,
}
#[derive(Debug, Clone, XmlSerialize, PartialEq)] #[derive(Debug, Clone, XmlSerialize, PartialEq)]
pub struct SupportedReportWrapper { pub struct SupportedReportWrapper {
report: ReportWrapper, #[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
} report: ReportMethod,
impl From<ReportMethod> for SupportedReportWrapper {
fn from(value: ReportMethod) -> Self {
Self {
report: ReportWrapper { report: value },
}
}
} }
// RFC 3253 section-3.1.5 // RFC 3253 section-3.1.5
#[derive(Debug, Clone, XmlSerialize, PartialEq)] #[derive(Debug, Clone, XmlSerialize, PartialEq)]
pub struct SupportedReportSet { pub struct SupportedReportSet {
#[xml(flatten)] #[xml(ns = "rustical_dav::namespace::NS_CARDDAV", flatten)]
supported_report: Vec<SupportedReportWrapper>, supported_report: &'static [SupportedReportWrapper],
} }
impl Default for SupportedReportSet { impl Default for SupportedReportSet {
fn default() -> Self { fn default() -> Self {
Self { Self {
supported_report: vec![ supported_report: &[
ReportMethod::AddressbookMultiget.into(), SupportedReportWrapper {
ReportMethod::SyncCollection.into(), report: ReportMethod::AddressbookMultiget,
},
SupportedReportWrapper {
report: ReportMethod::SyncCollection,
},
], ],
} }
} }

View File

@@ -35,17 +35,15 @@ pub enum AddressbookProp {
// WebDAV (RFC 2518) // WebDAV (RFC 2518)
#[xml(ns = "rustical_dav::namespace::NS_DAV")] #[xml(ns = "rustical_dav::namespace::NS_DAV")]
Displayname(Option<String>), Displayname(Option<String>),
#[xml(ns = "rustical_dav::namespace::NS_DAV")] #[xml(ns = "rustical_dav::namespace::NS_DAV", skip_deserializing)]
Getcontenttype(String), Getcontenttype(&'static str),
// CardDAV (RFC 6352) // CardDAV (RFC 6352)
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")] #[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
AddressbookDescription(Option<String>), AddressbookDescription(Option<String>),
#[xml(skip_deserializing)] #[xml(ns = "rustical_dav::namespace::NS_CARDDAV", skip_deserializing)]
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
SupportedAddressData(SupportedAddressData), SupportedAddressData(SupportedAddressData),
#[xml(skip_deserializing)] #[xml(ns = "rustical_dav::namespace::NS_CARDDAV", skip_deserializing)]
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
SupportedReportSet(SupportedReportSet), SupportedReportSet(SupportedReportSet),
#[xml(ns = "rustical_dav::namespace::NS_DAV")] #[xml(ns = "rustical_dav::namespace::NS_DAV")]
MaxResourceSize(i64), MaxResourceSize(i64),
@@ -83,7 +81,7 @@ impl Resource for AddressbookResource {
AddressbookProp::Displayname(self.0.displayname.clone()) AddressbookProp::Displayname(self.0.displayname.clone())
} }
AddressbookPropName::Getcontenttype => { AddressbookPropName::Getcontenttype => {
AddressbookProp::Getcontenttype("text/vcard;charset=utf-8".to_owned()) AddressbookProp::Getcontenttype("text/vcard;charset=utf-8")
} }
AddressbookPropName::MaxResourceSize => AddressbookProp::MaxResourceSize(10000000), AddressbookPropName::MaxResourceSize => AddressbookProp::MaxResourceSize(10000000),
AddressbookPropName::SupportedReportSet => { AddressbookPropName::SupportedReportSet => {