2024-02-29 19:40:40 +00:00
|
|
|
use quick_xml::Error as QError;
|
|
|
|
use quick_xml::events::{Event, BytesEnd, BytesStart, BytesText};
|
|
|
|
use quick_xml::name::PrefixDeclaration;
|
|
|
|
use tokio::io::AsyncWrite;
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
use super::caltypes::*;
|
|
|
|
use super::xml::{QWrite, IWrite, Writer};
|
|
|
|
use super::types::Extension;
|
2024-03-02 15:52:52 +00:00
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
const ICAL_DATETIME_FMT: &str = "%Y%m%dT%H%M%SZ";
|
2024-03-02 15:52:52 +00:00
|
|
|
|
|
|
|
// ==================== Calendar Types Serialization =========================
|
|
|
|
|
|
|
|
// -------------------- MKCALENDAR METHOD ------------------------------------
|
2024-03-05 17:02:43 +00:00
|
|
|
impl<E: Extension> QWrite for MkCalendar<E> {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let start = xml.create_cal_element("mkcalendar");
|
2024-03-02 17:19:03 +00:00
|
|
|
let end = start.to_end();
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
|
|
|
self.0.qwrite(xml).await?;
|
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl<E: Extension> QWrite for MkCalendarResponse<E> {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let start = xml.create_cal_element("mkcalendar-response");
|
2024-03-02 17:19:03 +00:00
|
|
|
let end = start.to_end();
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
2024-03-02 17:19:03 +00:00
|
|
|
for propstat in self.0.iter() {
|
2024-03-05 17:02:43 +00:00
|
|
|
propstat.qwrite(xml).await?;
|
2024-03-02 17:19:03 +00:00
|
|
|
}
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------- REPORT METHOD -------------------------------------
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl<E: Extension> QWrite for CalendarQuery<E> {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let start = xml.create_cal_element("calendar-query");
|
2024-03-02 17:19:03 +00:00
|
|
|
let end = start.to_end();
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
2024-03-02 17:19:03 +00:00
|
|
|
if let Some(selector) = &self.selector {
|
2024-03-05 17:02:43 +00:00
|
|
|
selector.qwrite(xml).await?;
|
2024-03-02 17:19:03 +00:00
|
|
|
}
|
2024-03-05 17:02:43 +00:00
|
|
|
self.filter.qwrite(xml).await?;
|
2024-03-02 17:19:03 +00:00
|
|
|
if let Some(tz) = &self.timezone {
|
2024-03-05 17:02:43 +00:00
|
|
|
tz.qwrite(xml).await?;
|
2024-03-02 17:19:03 +00:00
|
|
|
}
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl<E: Extension> QWrite for CalendarMultiget<E> {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let start = xml.create_cal_element("calendar-multiget");
|
2024-03-02 17:19:03 +00:00
|
|
|
let end = start.to_end();
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
2024-03-02 17:19:03 +00:00
|
|
|
if let Some(selector) = &self.selector {
|
2024-03-05 17:02:43 +00:00
|
|
|
selector.qwrite(xml).await?;
|
2024-03-02 17:19:03 +00:00
|
|
|
}
|
|
|
|
for href in self.href.iter() {
|
2024-03-05 17:02:43 +00:00
|
|
|
href.qwrite(xml).await?;
|
2024-03-02 17:19:03 +00:00
|
|
|
}
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for FreeBusyQuery {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let start = xml.create_cal_element("free-busy-query");
|
2024-03-02 17:19:03 +00:00
|
|
|
let end = start.to_end();
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
|
|
|
self.0.qwrite(xml).await?;
|
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------- DAV::prop --------------------------------------
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for PropertyRequest {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let mut atom = async |c| {
|
|
|
|
let empty_tag = xml.create_cal_element(c);
|
|
|
|
xml.q.write_event_async(Event::Empty(empty_tag)).await
|
|
|
|
};
|
2024-03-02 17:19:03 +00:00
|
|
|
|
|
|
|
match self {
|
|
|
|
Self::CalendarDescription => atom("calendar-description").await,
|
|
|
|
Self::CalendarTimezone => atom("calendar-timezone").await,
|
|
|
|
Self::SupportedCalendarComponentSet => atom("supported-calendar-component-set").await,
|
|
|
|
Self::SupportedCalendarData => atom("supported-calendar-data").await,
|
|
|
|
Self::MaxResourceSize => atom("max-resource-size").await,
|
|
|
|
Self::MinDateTime => atom("min-date-time").await,
|
|
|
|
Self::MaxDateTime => atom("max-date-time").await,
|
|
|
|
Self::MaxInstances => atom("max-instances").await,
|
|
|
|
Self::MaxAttendeesPerInstance => atom("max-attendees-per-instance").await,
|
|
|
|
Self::SupportedCollationSet => atom("supported-collation-set").await,
|
2024-03-05 17:02:43 +00:00
|
|
|
Self::CalendarData(req) => req.qwrite(xml).await,
|
2024-03-02 17:19:03 +00:00
|
|
|
}
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for Property {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
2024-03-02 17:19:03 +00:00
|
|
|
match self {
|
|
|
|
Self::CalendarDescription { lang, text } => {
|
2024-03-05 17:02:43 +00:00
|
|
|
let mut start = xml.create_cal_element("calendar-description");
|
2024-03-02 17:19:03 +00:00
|
|
|
if let Some(the_lang) = lang {
|
|
|
|
start.push_attribute(("xml:lang", the_lang.as_str()));
|
|
|
|
}
|
|
|
|
let end = start.to_end();
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
|
|
|
xml.q.write_event_async(Event::Text(BytesText::new(text))).await?;
|
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 17:19:03 +00:00
|
|
|
},
|
|
|
|
Self::CalendarTimezone(payload) => {
|
2024-03-05 17:02:43 +00:00
|
|
|
let start = xml.create_cal_element("calendar-timezone");
|
2024-03-02 17:19:03 +00:00
|
|
|
let end = start.to_end();
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
|
|
|
xml.q.write_event_async(Event::Text(BytesText::new(payload))).await?;
|
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 17:19:03 +00:00
|
|
|
},
|
|
|
|
Self::SupportedCalendarComponentSet(many_comp) => {
|
2024-03-05 17:02:43 +00:00
|
|
|
let start = xml.create_cal_element("supported-calendar-component-set");
|
2024-03-02 17:19:03 +00:00
|
|
|
let end = start.to_end();
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
2024-03-02 17:19:03 +00:00
|
|
|
for comp in many_comp.iter() {
|
2024-03-05 17:02:43 +00:00
|
|
|
comp.qwrite(xml).await?;
|
2024-03-02 17:19:03 +00:00
|
|
|
}
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 17:19:03 +00:00
|
|
|
},
|
|
|
|
Self::SupportedCalendarData(many_mime) => {
|
2024-03-05 17:02:43 +00:00
|
|
|
let start = xml.create_cal_element("supported-calendar-data");
|
2024-03-02 17:19:03 +00:00
|
|
|
let end = start.to_end();
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
2024-03-02 17:19:03 +00:00
|
|
|
for mime in many_mime.iter() {
|
2024-03-05 17:02:43 +00:00
|
|
|
mime.qwrite(xml).await?;
|
2024-03-02 17:19:03 +00:00
|
|
|
}
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 17:19:03 +00:00
|
|
|
},
|
|
|
|
Self::MaxResourceSize(bytes) => {
|
2024-03-05 17:02:43 +00:00
|
|
|
let start = xml.create_cal_element("max-resource-size");
|
2024-03-02 17:19:03 +00:00
|
|
|
let end = start.to_end();
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
|
|
|
xml.q.write_event_async(Event::Text(BytesText::new(bytes.to_string().as_str()))).await?;
|
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 17:19:03 +00:00
|
|
|
},
|
|
|
|
Self::MinDateTime(dt) => {
|
2024-03-05 17:02:43 +00:00
|
|
|
let start = xml.create_cal_element("min-date-time");
|
2024-03-02 17:19:03 +00:00
|
|
|
let end = start.to_end();
|
|
|
|
|
|
|
|
let dtstr = format!("{}", dt.format(ICAL_DATETIME_FMT));
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
|
|
|
xml.q.write_event_async(Event::Text(BytesText::new(dtstr.as_str()))).await?;
|
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 17:19:03 +00:00
|
|
|
},
|
|
|
|
Self::MaxDateTime(dt) => {
|
2024-03-05 17:02:43 +00:00
|
|
|
let start = xml.create_cal_element("max-date-time");
|
2024-03-02 17:19:03 +00:00
|
|
|
let end = start.to_end();
|
|
|
|
|
|
|
|
let dtstr = format!("{}", dt.format(ICAL_DATETIME_FMT));
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
|
|
|
xml.q.write_event_async(Event::Text(BytesText::new(dtstr.as_str()))).await?;
|
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 17:19:03 +00:00
|
|
|
},
|
|
|
|
Self::MaxInstances(count) => {
|
2024-03-05 17:02:43 +00:00
|
|
|
let start = xml.create_cal_element("max-instances");
|
2024-03-02 17:19:03 +00:00
|
|
|
let end = start.to_end();
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
|
|
|
xml.q.write_event_async(Event::Text(BytesText::new(count.to_string().as_str()))).await?;
|
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 17:19:03 +00:00
|
|
|
},
|
|
|
|
Self::MaxAttendeesPerInstance(count) => {
|
2024-03-05 17:02:43 +00:00
|
|
|
let start = xml.create_cal_element("max-attendees-per-instance");
|
2024-03-02 17:19:03 +00:00
|
|
|
let end = start.to_end();
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
|
|
|
xml.q.write_event_async(Event::Text(BytesText::new(count.to_string().as_str()))).await?;
|
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 17:19:03 +00:00
|
|
|
},
|
|
|
|
Self::SupportedCollationSet(many_collations) => {
|
2024-03-05 17:02:43 +00:00
|
|
|
let start = xml.create_cal_element("supported-collation-set");
|
2024-03-02 17:19:03 +00:00
|
|
|
let end = start.to_end();
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
2024-03-02 17:19:03 +00:00
|
|
|
for collation in many_collations.iter() {
|
2024-03-05 17:02:43 +00:00
|
|
|
collation.qwrite(xml).await?;
|
2024-03-02 17:19:03 +00:00
|
|
|
}
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 17:19:03 +00:00
|
|
|
},
|
2024-03-05 17:02:43 +00:00
|
|
|
Self::CalendarData(inner) => inner.qwrite(xml).await,
|
2024-03-02 17:19:03 +00:00
|
|
|
}
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------- DAV::resourcetype ----------------------------------
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for ResourceType {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
2024-03-02 15:52:52 +00:00
|
|
|
match self {
|
2024-03-05 17:02:43 +00:00
|
|
|
Self::Calendar => {
|
|
|
|
let empty_tag = xml.create_dav_element("calendar");
|
|
|
|
xml.q.write_event_async(Event::Empty(empty_tag)).await
|
|
|
|
},
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
2024-02-29 19:40:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-02 15:52:52 +00:00
|
|
|
// --------------------------- DAV::error ------------------------------------
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for Violation {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let mut atom = async |c| {
|
|
|
|
let empty_tag = xml.create_cal_element(c);
|
|
|
|
xml.q.write_event_async(Event::Empty(empty_tag)).await
|
|
|
|
};
|
2024-03-02 17:35:11 +00:00
|
|
|
|
2024-02-29 19:40:40 +00:00
|
|
|
match self {
|
2024-03-02 17:35:11 +00:00
|
|
|
//@FIXME
|
|
|
|
// DAV elements, should not be here but in RFC3744 on ACLs
|
|
|
|
// (we do not use atom as this error is in the DAV namespace, not the caldav one)
|
2024-03-05 17:02:43 +00:00
|
|
|
Self::NeedPrivileges => {
|
|
|
|
let empty_tag = xml.create_dav_element("need-privileges");
|
|
|
|
xml.q.write_event_async(Event::Empty(empty_tag)).await
|
|
|
|
},
|
2024-03-02 17:35:11 +00:00
|
|
|
|
|
|
|
// Regular CalDAV errors
|
|
|
|
Self::ResourceMustBeNull => atom("resource-must-be-null").await,
|
|
|
|
Self::CalendarCollectionLocationOk => atom("calendar-collection-location-ok").await,
|
|
|
|
Self::ValidCalendarData => atom("valid-calendar-data").await,
|
|
|
|
Self::InitializeCalendarCollection => atom("initialize-calendar-collection").await,
|
|
|
|
Self::SupportedCalendarData => atom("supported-calendar-data").await,
|
|
|
|
Self::ValidCalendarObjectResource => atom("valid-calendar-object-resource").await,
|
|
|
|
Self::SupportedCalendarComponent => atom("supported-calendar-component").await,
|
|
|
|
Self::NoUidConflict(href) => {
|
2024-03-05 17:02:43 +00:00
|
|
|
let start = xml.create_cal_element("no-uid-conflict");
|
2024-03-02 17:35:11 +00:00
|
|
|
let end = start.to_end();
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
|
|
|
href.qwrite(xml).await?;
|
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 17:35:11 +00:00
|
|
|
},
|
|
|
|
Self::MaxResourceSize => atom("max-resource-size").await,
|
|
|
|
Self::MinDateTime => atom("min-date-time").await,
|
|
|
|
Self::MaxDateTime => atom("max-date-time").await,
|
|
|
|
Self::MaxInstances => atom("max-instances").await,
|
|
|
|
Self::MaxAttendeesPerInstance => atom("max-attendees-per-instance").await,
|
|
|
|
Self::ValidFilter => atom("valid-filter").await,
|
|
|
|
Self::SupportedFilter { comp, prop, param } => {
|
2024-03-05 17:02:43 +00:00
|
|
|
let start = xml.create_cal_element("supported-filter");
|
2024-03-02 17:35:11 +00:00
|
|
|
let end = start.to_end();
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
2024-03-02 17:35:11 +00:00
|
|
|
for comp_item in comp.iter() {
|
2024-03-05 17:02:43 +00:00
|
|
|
comp_item.qwrite(xml).await?;
|
2024-03-02 17:35:11 +00:00
|
|
|
}
|
|
|
|
for prop_item in prop.iter() {
|
2024-03-05 17:02:43 +00:00
|
|
|
prop_item.qwrite(xml).await?;
|
2024-03-02 17:35:11 +00:00
|
|
|
}
|
|
|
|
for param_item in param.iter() {
|
2024-03-05 17:02:43 +00:00
|
|
|
param_item.qwrite(xml).await?;
|
2024-03-02 17:35:11 +00:00
|
|
|
}
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 17:35:11 +00:00
|
|
|
},
|
|
|
|
Self::NumberOfMatchesWithinLimits => atom("number-of-matches-within-limits").await,
|
|
|
|
}
|
2024-02-29 19:40:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-01 09:12:19 +00:00
|
|
|
|
2024-03-02 15:52:52 +00:00
|
|
|
// ---------------------------- Inner XML ------------------------------------
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for SupportedCollation {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let start = xml.create_cal_element("supported-collation");
|
2024-03-02 18:01:20 +00:00
|
|
|
let end = start.to_end();
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
|
|
|
self.0.qwrite(xml).await?;
|
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 18:01:20 +00:00
|
|
|
|
2024-03-01 09:12:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for Collation {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
2024-03-02 18:01:20 +00:00
|
|
|
let col = match self {
|
|
|
|
Self::AsciiCaseMap => "i;ascii-casemap",
|
|
|
|
Self::Octet => "i;octet",
|
|
|
|
Self::Unknown(v) => v.as_str(),
|
|
|
|
};
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Text(BytesText::new(col))).await
|
2024-03-01 13:28:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for CalendarDataPayload {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let mut start = xml.create_cal_element("calendar-data");
|
2024-03-02 18:01:20 +00:00
|
|
|
if let Some(mime) = &self.mime {
|
|
|
|
start.push_attribute(("content-type", mime.content_type.as_str()));
|
|
|
|
start.push_attribute(("version", mime.version.as_str()));
|
|
|
|
}
|
|
|
|
let end = start.to_end();
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
|
|
|
xml.q.write_event_async(Event::Text(BytesText::new(self.payload.as_str()))).await?;
|
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for CalendarDataRequest {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let mut start = xml.create_cal_element("calendar-data");
|
2024-03-02 18:01:20 +00:00
|
|
|
if let Some(mime) = &self.mime {
|
|
|
|
start.push_attribute(("content-type", mime.content_type.as_str()));
|
|
|
|
start.push_attribute(("version", mime.version.as_str()));
|
|
|
|
}
|
|
|
|
let end = start.to_end();
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
2024-03-02 18:01:20 +00:00
|
|
|
if let Some(comp) = &self.comp {
|
2024-03-05 17:02:43 +00:00
|
|
|
comp.qwrite(xml).await?;
|
2024-03-02 18:01:20 +00:00
|
|
|
}
|
|
|
|
if let Some(recurrence) = &self.recurrence {
|
2024-03-05 17:02:43 +00:00
|
|
|
recurrence.qwrite(xml).await?;
|
2024-03-02 18:01:20 +00:00
|
|
|
}
|
|
|
|
if let Some(freebusy) = &self.limit_freebusy_set {
|
2024-03-05 17:02:43 +00:00
|
|
|
freebusy.qwrite(xml).await?;
|
2024-03-02 18:01:20 +00:00
|
|
|
}
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for CalendarDataEmpty {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let mut empty = xml.create_cal_element("calendar-data");
|
2024-03-02 18:01:20 +00:00
|
|
|
if let Some(mime) = &self.0 {
|
|
|
|
empty.push_attribute(("content-type", mime.content_type.as_str()));
|
|
|
|
empty.push_attribute(("version", mime.version.as_str()));
|
|
|
|
}
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Empty(empty)).await
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for Comp {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let mut start = xml.create_cal_element("comp");
|
2024-03-02 22:01:56 +00:00
|
|
|
start.push_attribute(("name", self.name.as_str()));
|
2024-03-04 08:02:24 +00:00
|
|
|
match &self.additional_rules {
|
2024-03-05 17:02:43 +00:00
|
|
|
None => xml.q.write_event_async(Event::Empty(start)).await,
|
2024-03-04 08:02:24 +00:00
|
|
|
Some(rules) => {
|
|
|
|
let end = start.to_end();
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
|
|
|
rules.prop_kind.qwrite(xml).await?;
|
|
|
|
rules.comp_kind.qwrite(xml).await?;
|
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-04 08:02:24 +00:00
|
|
|
},
|
|
|
|
}
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for CompSupport {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let mut empty = xml.create_cal_element("comp");
|
2024-03-02 22:01:56 +00:00
|
|
|
empty.push_attribute(("name", self.0.as_str()));
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Empty(empty)).await
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for CompKind {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
2024-03-02 22:01:56 +00:00
|
|
|
match self {
|
2024-03-05 17:02:43 +00:00
|
|
|
Self::AllComp => {
|
|
|
|
let empty_tag = xml.create_cal_element("allcomp");
|
|
|
|
xml.q.write_event_async(Event::Empty(empty_tag)).await
|
|
|
|
},
|
2024-03-02 22:01:56 +00:00
|
|
|
Self::Comp(many_comp) => {
|
|
|
|
for comp in many_comp.iter() {
|
|
|
|
// Required: recursion in an async fn requires boxing
|
|
|
|
// rustc --explain E0733
|
2024-03-05 17:02:43 +00:00
|
|
|
Box::pin(comp.qwrite(xml)).await?;
|
2024-03-02 22:01:56 +00:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for PropKind {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
2024-03-02 22:01:56 +00:00
|
|
|
match self {
|
2024-03-05 17:02:43 +00:00
|
|
|
Self::AllProp => {
|
|
|
|
let empty_tag = xml.create_cal_element("allprop");
|
|
|
|
xml.q.write_event_async(Event::Empty(empty_tag)).await
|
|
|
|
},
|
2024-03-02 22:01:56 +00:00
|
|
|
Self::Prop(many_prop) => {
|
|
|
|
for prop in many_prop.iter() {
|
2024-03-05 17:02:43 +00:00
|
|
|
prop.qwrite(xml).await?;
|
2024-03-02 22:01:56 +00:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for CalProp {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let mut empty = xml.create_cal_element("prop");
|
2024-03-02 22:01:56 +00:00
|
|
|
empty.push_attribute(("name", self.name.0.as_str()));
|
|
|
|
match self.novalue {
|
|
|
|
None => (),
|
|
|
|
Some(true) => empty.push_attribute(("novalue", "yes")),
|
|
|
|
Some(false) => empty.push_attribute(("novalue", "no")),
|
|
|
|
}
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Empty(empty)).await
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for RecurrenceModifier {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
2024-03-02 22:01:56 +00:00
|
|
|
match self {
|
2024-03-05 17:02:43 +00:00
|
|
|
Self::Expand(exp) => exp.qwrite(xml).await,
|
|
|
|
Self::LimitRecurrenceSet(lrs) => lrs.qwrite(xml).await,
|
2024-03-02 22:01:56 +00:00
|
|
|
}
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for Expand {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let mut empty = xml.create_cal_element("expand");
|
2024-03-02 22:01:56 +00:00
|
|
|
empty.push_attribute(("start", format!("{}", self.0.format(ICAL_DATETIME_FMT)).as_str()));
|
|
|
|
empty.push_attribute(("end", format!("{}", self.1.format(ICAL_DATETIME_FMT)).as_str()));
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Empty(empty)).await
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for LimitRecurrenceSet {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let mut empty = xml.create_cal_element("limit-recurrence-set");
|
2024-03-03 09:50:32 +00:00
|
|
|
empty.push_attribute(("start", format!("{}", self.0.format(ICAL_DATETIME_FMT)).as_str()));
|
|
|
|
empty.push_attribute(("end", format!("{}", self.1.format(ICAL_DATETIME_FMT)).as_str()));
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Empty(empty)).await
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for LimitFreebusySet {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let mut empty = xml.create_cal_element("limit-freebusy-set");
|
2024-03-03 09:50:32 +00:00
|
|
|
empty.push_attribute(("start", format!("{}", self.0.format(ICAL_DATETIME_FMT)).as_str()));
|
|
|
|
empty.push_attribute(("end", format!("{}", self.1.format(ICAL_DATETIME_FMT)).as_str()));
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Empty(empty)).await
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl<E: Extension> QWrite for CalendarSelector<E> {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
2024-03-03 09:50:32 +00:00
|
|
|
match self {
|
2024-03-05 17:02:43 +00:00
|
|
|
Self::AllProp => {
|
|
|
|
let empty_tag = xml.create_dav_element("allprop");
|
|
|
|
xml.q.write_event_async(Event::Empty(empty_tag)).await
|
|
|
|
},
|
|
|
|
Self::PropName => {
|
|
|
|
let empty_tag = xml.create_dav_element("propname");
|
|
|
|
xml.q.write_event_async(Event::Empty(empty_tag)).await
|
|
|
|
},
|
|
|
|
Self::Prop(prop) => prop.qwrite(xml).await,
|
2024-03-03 09:50:32 +00:00
|
|
|
}
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for CompFilter {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let mut start = xml.create_cal_element("comp-filter");
|
2024-03-03 09:50:32 +00:00
|
|
|
start.push_attribute(("name", self.name.as_str()));
|
|
|
|
|
|
|
|
match &self.additional_rules {
|
2024-03-05 17:02:43 +00:00
|
|
|
None => xml.q.write_event_async(Event::Empty(start)).await,
|
2024-03-03 09:50:32 +00:00
|
|
|
Some(rules) => {
|
|
|
|
let end = start.to_end();
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
|
|
|
rules.qwrite(xml).await?;
|
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-03 09:50:32 +00:00
|
|
|
}
|
|
|
|
}
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for CompFilterRules {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
2024-03-03 09:50:32 +00:00
|
|
|
match self {
|
2024-03-05 17:02:43 +00:00
|
|
|
Self::IsNotDefined => {
|
|
|
|
let empty_tag = xml.create_dav_element("is-not-defined");
|
|
|
|
xml.q.write_event_async(Event::Empty(empty_tag)).await
|
|
|
|
},
|
|
|
|
Self::Matches(cfm) => cfm.qwrite(xml).await,
|
2024-03-03 09:50:32 +00:00
|
|
|
}
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for CompFilterMatch {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
2024-03-03 09:50:32 +00:00
|
|
|
if let Some(time_range) = &self.time_range {
|
2024-03-05 17:02:43 +00:00
|
|
|
time_range.qwrite(xml).await?;
|
2024-03-03 09:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for prop_item in self.prop_filter.iter() {
|
2024-03-05 17:02:43 +00:00
|
|
|
prop_item.qwrite(xml).await?;
|
2024-03-03 09:50:32 +00:00
|
|
|
}
|
|
|
|
for comp_item in self.comp_filter.iter() {
|
|
|
|
// Required: recursion in an async fn requires boxing
|
|
|
|
// rustc --explain E0733
|
2024-03-05 17:02:43 +00:00
|
|
|
Box::pin(comp_item.qwrite(xml)).await?;
|
2024-03-03 09:50:32 +00:00
|
|
|
}
|
|
|
|
Ok(())
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for PropFilter {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let mut start = xml.create_cal_element("prop-filter");
|
2024-03-03 09:50:32 +00:00
|
|
|
start.push_attribute(("name", self.name.as_str()));
|
|
|
|
|
|
|
|
match &self.additional_rules {
|
2024-03-05 17:02:43 +00:00
|
|
|
None => xml.q.write_event_async(Event::Empty(start.clone())).await,
|
2024-03-03 09:50:32 +00:00
|
|
|
Some(rules) => {
|
|
|
|
let end = start.to_end();
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
|
|
|
rules.qwrite(xml).await?;
|
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-03 09:50:32 +00:00
|
|
|
}
|
|
|
|
}
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for PropFilterRules {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
2024-03-03 09:50:32 +00:00
|
|
|
match self {
|
2024-03-05 17:02:43 +00:00
|
|
|
Self::IsNotDefined => {
|
|
|
|
let empty_tag = xml.create_dav_element("is-not-defined");
|
|
|
|
xml.q.write_event_async(Event::Empty(empty_tag)).await
|
|
|
|
},
|
|
|
|
Self::Match(prop_match) => prop_match.qwrite(xml).await,
|
2024-03-03 09:50:32 +00:00
|
|
|
}
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for PropFilterMatch {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
2024-03-03 09:50:32 +00:00
|
|
|
if let Some(time_range) = &self.time_range {
|
2024-03-05 17:02:43 +00:00
|
|
|
time_range.qwrite(xml).await?;
|
2024-03-03 09:50:32 +00:00
|
|
|
}
|
|
|
|
if let Some(time_or_text) = &self.time_or_text {
|
2024-03-05 17:02:43 +00:00
|
|
|
time_or_text.qwrite(xml).await?;
|
2024-03-03 09:50:32 +00:00
|
|
|
}
|
|
|
|
for param_item in self.param_filter.iter() {
|
2024-03-05 17:02:43 +00:00
|
|
|
param_item.qwrite(xml).await?;
|
2024-03-03 09:50:32 +00:00
|
|
|
}
|
|
|
|
Ok(())
|
2024-03-01 09:29:16 +00:00
|
|
|
}
|
|
|
|
}
|
2024-02-29 19:40:40 +00:00
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for TimeOrText {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
2024-03-03 09:50:32 +00:00
|
|
|
match self {
|
2024-03-05 17:02:43 +00:00
|
|
|
Self::Time(time) => time.qwrite(xml).await,
|
|
|
|
Self::Text(txt) => txt.qwrite(xml).await,
|
2024-03-03 09:50:32 +00:00
|
|
|
}
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for TextMatch {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let mut start = xml.create_cal_element("text-match");
|
2024-03-03 10:00:10 +00:00
|
|
|
if let Some(collation) = &self.collation {
|
|
|
|
start.push_attribute(("collation", collation.as_str()));
|
|
|
|
}
|
|
|
|
match self.negate_condition {
|
|
|
|
None => (),
|
|
|
|
Some(true) => start.push_attribute(("negate-condition", "yes")),
|
|
|
|
Some(false) => start.push_attribute(("negate-condition", "no")),
|
|
|
|
}
|
|
|
|
let end = start.to_end();
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
|
|
|
xml.q.write_event_async(Event::Text(BytesText::new(self.text.as_str()))).await?;
|
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for ParamFilter {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let mut start = xml.create_cal_element("param-filter");
|
2024-03-03 10:00:10 +00:00
|
|
|
start.push_attribute(("name", self.name.as_str()));
|
|
|
|
|
|
|
|
match &self.additional_rules {
|
2024-03-05 17:02:43 +00:00
|
|
|
None => xml.q.write_event_async(Event::Empty(start)).await,
|
2024-03-03 10:00:10 +00:00
|
|
|
Some(rules) => {
|
|
|
|
let end = start.to_end();
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
|
|
|
rules.qwrite(xml).await?;
|
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-03 10:00:10 +00:00
|
|
|
}
|
|
|
|
}
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for ParamFilterMatch {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
2024-03-03 10:00:10 +00:00
|
|
|
match self {
|
2024-03-05 17:02:43 +00:00
|
|
|
Self::IsNotDefined => {
|
|
|
|
let empty_tag = xml.create_dav_element("is-not-defined");
|
|
|
|
xml.q.write_event_async(Event::Empty(empty_tag)).await
|
|
|
|
},
|
|
|
|
Self::Match(tm) => tm.qwrite(xml).await,
|
2024-03-03 10:00:10 +00:00
|
|
|
}
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for TimeZone {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let mut start = xml.create_cal_element("timezone");
|
2024-03-03 10:08:00 +00:00
|
|
|
let end = start.to_end();
|
2024-03-02 15:52:52 +00:00
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
|
|
|
xml.q.write_event_async(Event::Text(BytesText::new(self.0.as_str()))).await?;
|
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for Filter {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let mut start = xml.create_cal_element("filter");
|
2024-03-03 10:08:00 +00:00
|
|
|
let end = start.to_end();
|
2024-03-02 15:52:52 +00:00
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Start(start.clone())).await?;
|
|
|
|
self.0.qwrite(xml).await?;
|
|
|
|
xml.q.write_event_async(Event::End(end)).await
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:02:43 +00:00
|
|
|
impl QWrite for TimeRange {
|
|
|
|
async fn qwrite(&self, xml: &mut Writer<impl IWrite>) -> Result<(), QError> {
|
|
|
|
let mut empty = xml.create_cal_element("time-range");
|
2024-03-03 10:08:00 +00:00
|
|
|
match self {
|
|
|
|
Self::OnlyStart(start) => empty.push_attribute(("start", format!("{}", start.format(ICAL_DATETIME_FMT)).as_str())),
|
|
|
|
Self::OnlyEnd(end) => empty.push_attribute(("end", format!("{}", end.format(ICAL_DATETIME_FMT)).as_str())),
|
|
|
|
Self::FullRange(start, end) => {
|
|
|
|
empty.push_attribute(("start", format!("{}", start.format(ICAL_DATETIME_FMT)).as_str()));
|
|
|
|
empty.push_attribute(("end", format!("{}", end.format(ICAL_DATETIME_FMT)).as_str()));
|
|
|
|
}
|
|
|
|
}
|
2024-03-05 17:02:43 +00:00
|
|
|
xml.q.write_event_async(Event::Empty(empty)).await
|
2024-03-02 15:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-29 19:40:40 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2024-03-03 10:26:32 +00:00
|
|
|
use crate::dav::types as dav;
|
2024-03-05 17:15:03 +00:00
|
|
|
use crate::dav::realization::Calendar;
|
2024-02-29 19:40:40 +00:00
|
|
|
use tokio::io::AsyncWriteExt;
|
2024-03-04 08:02:24 +00:00
|
|
|
use chrono::{Utc,TimeZone,DateTime};
|
2024-02-29 19:40:40 +00:00
|
|
|
|
2024-03-05 17:15:03 +00:00
|
|
|
async fn serialize(elem: &impl QWrite) -> String {
|
2024-02-29 19:40:40 +00:00
|
|
|
let mut buffer = Vec::new();
|
|
|
|
let mut tokio_buffer = tokio::io::BufWriter::new(&mut buffer);
|
2024-03-05 17:15:03 +00:00
|
|
|
let q = quick_xml::writer::Writer::new_with_indent(&mut tokio_buffer, b' ', 4);
|
|
|
|
let ns_to_apply = vec![
|
|
|
|
("xmlns:D".into(), "DAV:".into()),
|
|
|
|
("xmlns:C".into(), "urn:ietf:params:xml:ns:caldav".into()),
|
|
|
|
];
|
|
|
|
let mut writer = Writer { q, ns_to_apply };
|
|
|
|
|
|
|
|
elem.qwrite(&mut writer).await.expect("xml serialization");
|
2024-03-03 10:26:32 +00:00
|
|
|
tokio_buffer.flush().await.expect("tokio buffer flush");
|
|
|
|
let got = std::str::from_utf8(buffer.as_slice()).unwrap();
|
2024-02-29 19:40:40 +00:00
|
|
|
|
2024-03-03 10:26:32 +00:00
|
|
|
return got.into()
|
|
|
|
}
|
2024-02-29 19:40:40 +00:00
|
|
|
|
2024-03-03 10:26:32 +00:00
|
|
|
#[tokio::test]
|
|
|
|
async fn basic_violation() {
|
|
|
|
let got = serialize(
|
2024-03-05 17:15:03 +00:00
|
|
|
&dav::Error::<Calendar>(vec![
|
2024-03-03 10:26:32 +00:00
|
|
|
dav::Violation::Extension(Violation::ResourceMustBeNull),
|
|
|
|
])
|
|
|
|
).await;
|
2024-02-29 19:40:40 +00:00
|
|
|
|
|
|
|
let expected = r#"<D:error xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
|
2024-03-02 09:08:51 +00:00
|
|
|
<C:resource-must-be-null/>
|
2024-02-29 19:40:40 +00:00
|
|
|
</D:error>"#;
|
|
|
|
|
2024-03-03 10:26:32 +00:00
|
|
|
assert_eq!(&got, expected, "\n---GOT---\n{got}\n---EXP---\n{expected}\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
2024-03-04 08:29:03 +00:00
|
|
|
async fn rfc_calendar_query1_req() {
|
2024-03-03 10:26:32 +00:00
|
|
|
let got = serialize(
|
2024-03-05 17:15:03 +00:00
|
|
|
&CalendarQuery::<Calendar> {
|
2024-03-03 10:26:32 +00:00
|
|
|
selector: Some(CalendarSelector::Prop(dav::PropName(vec![
|
2024-03-03 12:07:22 +00:00
|
|
|
dav::PropertyRequest::GetEtag,
|
|
|
|
dav::PropertyRequest::Extension(PropertyRequest::CalendarData(CalendarDataRequest {
|
|
|
|
mime: None,
|
|
|
|
comp: Some(Comp {
|
|
|
|
name: Component::VCalendar,
|
2024-03-04 08:02:24 +00:00
|
|
|
additional_rules: Some(CompInner {
|
|
|
|
prop_kind: PropKind::Prop(vec![
|
|
|
|
CalProp {
|
|
|
|
name: ComponentProperty("VERSION".into()),
|
|
|
|
novalue: None,
|
|
|
|
}
|
|
|
|
]),
|
|
|
|
comp_kind: CompKind::Comp(vec![
|
|
|
|
Comp {
|
|
|
|
name: Component::VEvent,
|
|
|
|
additional_rules: Some(CompInner {
|
|
|
|
prop_kind: PropKind::Prop(vec![
|
|
|
|
CalProp { name: ComponentProperty("SUMMARY".into()), novalue: None },
|
|
|
|
CalProp { name: ComponentProperty("UID".into()), novalue: None },
|
|
|
|
CalProp { name: ComponentProperty("DTSTART".into()), novalue: None },
|
|
|
|
CalProp { name: ComponentProperty("DTEND".into()), novalue: None },
|
|
|
|
CalProp { name: ComponentProperty("DURATION".into()), novalue: None },
|
|
|
|
CalProp { name: ComponentProperty("RRULE".into()), novalue: None },
|
|
|
|
CalProp { name: ComponentProperty("RDATE".into()), novalue: None },
|
|
|
|
CalProp { name: ComponentProperty("EXRULE".into()), novalue: None },
|
|
|
|
CalProp { name: ComponentProperty("EXDATE".into()), novalue: None },
|
|
|
|
CalProp { name: ComponentProperty("RECURRENCE-ID".into()), novalue: None },
|
|
|
|
]),
|
|
|
|
comp_kind: CompKind::Comp(vec![]),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
Comp {
|
|
|
|
name: Component::VTimeZone,
|
|
|
|
additional_rules: None,
|
|
|
|
}
|
|
|
|
]),
|
|
|
|
}),
|
2024-03-03 12:07:22 +00:00
|
|
|
}),
|
|
|
|
recurrence: None,
|
|
|
|
limit_freebusy_set: None,
|
|
|
|
})),
|
2024-03-03 10:26:32 +00:00
|
|
|
]))),
|
|
|
|
filter: Filter(CompFilter {
|
|
|
|
name: Component::VCalendar,
|
2024-03-04 08:02:24 +00:00
|
|
|
additional_rules: Some(CompFilterRules::Matches(CompFilterMatch {
|
|
|
|
time_range: None,
|
|
|
|
prop_filter: vec![],
|
|
|
|
comp_filter: vec![
|
|
|
|
CompFilter {
|
|
|
|
name: Component::VEvent,
|
|
|
|
additional_rules: Some(CompFilterRules::Matches(CompFilterMatch {
|
|
|
|
time_range: Some(TimeRange::FullRange(
|
|
|
|
Utc.with_ymd_and_hms(2006,1,4,0,0,0).unwrap(),
|
|
|
|
Utc.with_ymd_and_hms(2006,1,5,0,0,0).unwrap(),
|
|
|
|
)),
|
|
|
|
prop_filter: vec![],
|
|
|
|
comp_filter: vec![],
|
|
|
|
})),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})),
|
2024-03-03 10:26:32 +00:00
|
|
|
}),
|
|
|
|
timezone: None,
|
|
|
|
}
|
|
|
|
).await;
|
|
|
|
|
|
|
|
let expected = r#"<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
|
|
|
|
<D:prop>
|
|
|
|
<D:getetag/>
|
|
|
|
<C:calendar-data>
|
|
|
|
<C:comp name="VCALENDAR">
|
|
|
|
<C:prop name="VERSION"/>
|
|
|
|
<C:comp name="VEVENT">
|
|
|
|
<C:prop name="SUMMARY"/>
|
|
|
|
<C:prop name="UID"/>
|
|
|
|
<C:prop name="DTSTART"/>
|
|
|
|
<C:prop name="DTEND"/>
|
|
|
|
<C:prop name="DURATION"/>
|
|
|
|
<C:prop name="RRULE"/>
|
|
|
|
<C:prop name="RDATE"/>
|
|
|
|
<C:prop name="EXRULE"/>
|
|
|
|
<C:prop name="EXDATE"/>
|
|
|
|
<C:prop name="RECURRENCE-ID"/>
|
|
|
|
</C:comp>
|
|
|
|
<C:comp name="VTIMEZONE"/>
|
|
|
|
</C:comp>
|
|
|
|
</C:calendar-data>
|
|
|
|
</D:prop>
|
|
|
|
<C:filter>
|
|
|
|
<C:comp-filter name="VCALENDAR">
|
|
|
|
<C:comp-filter name="VEVENT">
|
|
|
|
<C:time-range start="20060104T000000Z" end="20060105T000000Z"/>
|
|
|
|
</C:comp-filter>
|
|
|
|
</C:comp-filter>
|
|
|
|
</C:filter>
|
|
|
|
</C:calendar-query>"#;
|
|
|
|
|
2024-03-04 08:29:03 +00:00
|
|
|
assert_eq!(&got, expected, "\n---GOT---\n{got}\n---EXP---\n{expected}\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn rfc_calendar_query1_res() {
|
|
|
|
let got = serialize(
|
2024-03-05 17:15:03 +00:00
|
|
|
&dav::Multistatus::<Calendar> {
|
2024-03-04 08:29:03 +00:00
|
|
|
responses: vec![
|
|
|
|
dav::Response {
|
|
|
|
href: dav::Href("http://cal.example.com/bernard/work/abcd2.ics".into()),
|
|
|
|
status_or_propstat: dav::StatusOrPropstat::PropStat(vec![dav::PropStat {
|
|
|
|
prop: dav::AnyProp::Value(dav::PropValue(vec![
|
|
|
|
dav::Property::GetEtag("\"fffff-abcd2\"".into()),
|
|
|
|
dav::Property::Extension(Property::CalendarData(CalendarDataPayload {
|
|
|
|
mime: None,
|
|
|
|
payload: "PLACEHOLDER".into()
|
|
|
|
})),
|
|
|
|
])),
|
|
|
|
status: dav::Status(http::status::StatusCode::OK),
|
|
|
|
error: None,
|
|
|
|
responsedescription: None,
|
|
|
|
}]),
|
|
|
|
location: None,
|
|
|
|
error: None,
|
|
|
|
responsedescription: None,
|
|
|
|
},
|
|
|
|
dav::Response {
|
|
|
|
href: dav::Href("http://cal.example.com/bernard/work/abcd3.ics".into()),
|
|
|
|
status_or_propstat: dav::StatusOrPropstat::PropStat(vec![dav::PropStat {
|
|
|
|
prop: dav::AnyProp::Value(dav::PropValue(vec![
|
|
|
|
dav::Property::GetEtag("\"fffff-abcd3\"".into()),
|
|
|
|
dav::Property::Extension(Property::CalendarData(CalendarDataPayload{
|
|
|
|
mime: None,
|
|
|
|
payload: "PLACEHOLDER".into(),
|
|
|
|
})),
|
|
|
|
])),
|
|
|
|
status: dav::Status(http::status::StatusCode::OK),
|
|
|
|
error: None,
|
|
|
|
responsedescription: None,
|
|
|
|
}]),
|
|
|
|
location: None,
|
|
|
|
error: None,
|
|
|
|
responsedescription: None,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
responsedescription: None,
|
|
|
|
},
|
|
|
|
).await;
|
|
|
|
|
|
|
|
let expected = r#"<D:multistatus xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
|
|
|
|
<D:response>
|
|
|
|
<D:href>http://cal.example.com/bernard/work/abcd2.ics</D:href>
|
|
|
|
<D:propstat>
|
|
|
|
<D:prop>
|
|
|
|
<D:getetag>"fffff-abcd2"</D:getetag>
|
|
|
|
<C:calendar-data>PLACEHOLDER</C:calendar-data>
|
|
|
|
</D:prop>
|
|
|
|
<D:status>HTTP/1.1 200 OK</D:status>
|
|
|
|
</D:propstat>
|
|
|
|
</D:response>
|
|
|
|
<D:response>
|
|
|
|
<D:href>http://cal.example.com/bernard/work/abcd3.ics</D:href>
|
|
|
|
<D:propstat>
|
|
|
|
<D:prop>
|
|
|
|
<D:getetag>"fffff-abcd3"</D:getetag>
|
|
|
|
<C:calendar-data>PLACEHOLDER</C:calendar-data>
|
|
|
|
</D:prop>
|
|
|
|
<D:status>HTTP/1.1 200 OK</D:status>
|
|
|
|
</D:propstat>
|
|
|
|
</D:response>
|
|
|
|
</D:multistatus>"#;
|
|
|
|
|
|
|
|
|
2024-03-03 10:26:32 +00:00
|
|
|
assert_eq!(&got, expected, "\n---GOT---\n{got}\n---EXP---\n{expected}\n");
|
2024-02-29 19:40:40 +00:00
|
|
|
}
|
|
|
|
}
|