Serialize calendar-data

This commit is contained in:
Quentin 2024-03-02 19:01:20 +01:00
parent dba0dcdc41
commit 61ee5f153b
Signed by: quentin
GPG Key ID: E9602264D639FF68
2 changed files with 55 additions and 19 deletions

View File

@ -319,37 +319,73 @@ impl<C: CalContext> QuickWritable<C> for Violation {
// ---------------------------- Inner XML ------------------------------------
impl<C: CalContext> QuickWritable<C> for SupportedCollation {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
unimplemented!();
let start = ctx.create_cal_element("supported-collation");
let end = start.to_end();
xml.write_event_async(Event::Start(start.clone())).await?;
self.0.write(xml, ctx.child()).await?;
xml.write_event_async(Event::End(end)).await
}
}
impl<C: CalContext> QuickWritable<C> for Collation {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
unimplemented!();
let col = match self {
Self::AsciiCaseMap => "i;ascii-casemap",
Self::Octet => "i;octet",
Self::Unknown(v) => v.as_str(),
};
xml.write_event_async(Event::Text(BytesText::new(col))).await
}
}
impl<C: CalContext> QuickWritable<C> for CalendarDataPayload {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
unimplemented!();
let mut start = ctx.create_cal_element("calendar-data");
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();
xml.write_event_async(Event::Start(start.clone())).await?;
xml.write_event_async(Event::Text(BytesText::new(self.payload.as_str()))).await?;
xml.write_event_async(Event::End(end)).await
}
}
impl<C: CalContext> QuickWritable<C> for CalendarDataRequest {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
unimplemented!();
let mut start = ctx.create_cal_element("calendar-data");
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();
xml.write_event_async(Event::Start(start.clone())).await?;
if let Some(comp) = &self.comp {
comp.write(xml, ctx.child()).await?;
}
if let Some(recurrence) = &self.recurrence {
recurrence.write(xml, ctx.child()).await?;
}
if let Some(freebusy) = &self.limit_freebusy_set {
freebusy.write(xml, ctx.child()).await?;
}
xml.write_event_async(Event::End(end)).await
}
}
impl<C: CalContext> QuickWritable<C> for CalendarDataEmpty {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
unimplemented!();
}
}
impl<C: CalContext> QuickWritable<C> for CalendarDataSupport {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
unimplemented!();
let mut empty = ctx.create_cal_element("calendar-data");
if let Some(mime) = &self.0 {
empty.push_attribute(("content-type", mime.content_type.as_str()));
empty.push_attribute(("version", mime.version.as_str()));
}
xml.write_event_async(Event::Empty(empty)).await
}
}

View File

@ -770,7 +770,7 @@ pub enum Violation {
/// If the client chooses a collation not supported by the server, the
/// server MUST respond with a CALDAV:supported-collation precondition
/// error response.
pub struct SupportedCollation(Collation);
pub struct SupportedCollation(pub Collation);
#[derive(Default)]
pub enum Collation {
#[default]
@ -799,10 +799,10 @@ pub struct CalendarDataPayload {
/// REPORT request to specify which parts of calendar object
/// resources should be returned in the response;
pub struct CalendarDataRequest {
mime: Option<CalendarDataSupport>,
comp: Option<Comp>,
reccurence: Option<RecurrenceModifier>,
limit_freebusy_set: Option<LimitFreebusySet>,
pub mime: Option<CalendarDataSupport>,
pub comp: Option<Comp>,
pub recurrence: Option<RecurrenceModifier>,
pub limit_freebusy_set: Option<LimitFreebusySet>,
}
/// calendar-data specialization for Property
@ -812,7 +812,7 @@ pub struct CalendarDataRequest {
/// when nested in the CALDAV:supported-calendar-data property
/// to specify a supported media type for calendar object
/// resources;
pub struct CalendarDataEmpty(Option<CalendarDataSupport>);
pub struct CalendarDataEmpty(pub Option<CalendarDataSupport>);
/// <!ATTLIST calendar-data content-type CDATA "text/calendar"
/// version CDATA "2.0">
@ -821,8 +821,8 @@ pub struct CalendarDataEmpty(Option<CalendarDataSupport>);
/// attributes can be used on all three variants of the
/// CALDAV:calendar-data XML element.
pub struct CalendarDataSupport {
content_type: String,
version: String,
pub content_type: String,
pub version: String,
}
/// Name: comp