WIP encoding

This commit is contained in:
Quentin 2024-03-02 23:01:56 +01:00
parent 61ee5f153b
commit 17142bd687
Signed by: quentin
GPG key ID: E9602264D639FF68
3 changed files with 71 additions and 21 deletions

View file

@ -278,8 +278,6 @@ impl<C: CalContext> QuickWritable<C> for Violation {
Self::SupportedCalendarData => atom("supported-calendar-data").await, Self::SupportedCalendarData => atom("supported-calendar-data").await,
Self::ValidCalendarObjectResource => atom("valid-calendar-object-resource").await, Self::ValidCalendarObjectResource => atom("valid-calendar-object-resource").await,
Self::SupportedCalendarComponent => atom("supported-calendar-component").await, Self::SupportedCalendarComponent => atom("supported-calendar-component").await,
Self::ValidCalendarObjectResource => atom("valid-calendar-object-resource").await,
Self::SupportedCalendarComponent => atom("SupportedCalendarComponent").await,
Self::NoUidConflict(href) => { Self::NoUidConflict(href) => {
let start = ctx.create_cal_element("no-uid-conflict"); let start = ctx.create_cal_element("no-uid-conflict");
let end = start.to_end(); let end = start.to_end();
@ -391,43 +389,82 @@ impl<C: CalContext> QuickWritable<C> for CalendarDataEmpty {
impl<C: CalContext> QuickWritable<C> for Comp { impl<C: CalContext> QuickWritable<C> for Comp {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
unimplemented!(); let mut start = ctx.create_cal_element("calendar-data");
start.push_attribute(("name", self.name.as_str()));
let end = start.to_end();
xml.write_event_async(Event::Start(start.clone())).await?;
self.prop_kind.write(xml, ctx.child()).await?;
self.comp_kind.write(xml, ctx.child()).await?;
xml.write_event_async(Event::End(end)).await
} }
} }
impl<C: CalContext> QuickWritable<C> for CompSupport { impl<C: CalContext> QuickWritable<C> for CompSupport {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
unimplemented!(); let mut empty = ctx.create_cal_element("comp");
empty.push_attribute(("name", self.0.as_str()));
xml.write_event_async(Event::Empty(empty)).await
} }
} }
impl<C: CalContext> QuickWritable<C> for CompKind { impl<C: CalContext> QuickWritable<C> for CompKind {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
unimplemented!(); match self {
Self::AllComp => xml.write_event_async(Event::Empty(ctx.create_cal_element("allcomp"))).await,
Self::Comp(many_comp) => {
for comp in many_comp.iter() {
// Required: recursion in an async fn requires boxing
// rustc --explain E0733
Box::pin(comp.write(xml, ctx.child())).await?;
}
Ok(())
}
}
} }
} }
impl<C: CalContext> QuickWritable<C> for PropKind { impl<C: CalContext> QuickWritable<C> for PropKind {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
unimplemented!(); match self {
Self::AllProp => xml.write_event_async(Event::Empty(ctx.create_cal_element("allprop"))).await,
Self::Prop(many_prop) => {
for prop in many_prop.iter() {
prop.write(xml, ctx.child()).await?;
}
Ok(())
}
}
} }
} }
impl<C: CalContext> QuickWritable<C> for CalProp { impl<C: CalContext> QuickWritable<C> for CalProp {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
unimplemented!(); let mut empty = ctx.create_cal_element("prop");
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")),
}
xml.write_event_async(Event::Empty(empty)).await
} }
} }
impl<C: CalContext> QuickWritable<C> for RecurrenceModifier { impl<C: CalContext> QuickWritable<C> for RecurrenceModifier {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
unimplemented!(); match self {
Self::Expand(exp) => exp.write(xml, ctx).await,
Self::LimitRecurrenceSet(lrs) => lrs.write(xml, ctx).await,
}
} }
} }
impl<C: CalContext> QuickWritable<C> for Expand { impl<C: CalContext> QuickWritable<C> for Expand {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
unimplemented!(); let mut empty = ctx.create_cal_element("expand");
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()));
xml.write_event_async(Event::Empty(empty)).await
} }
} }

View file

@ -846,9 +846,9 @@ pub struct CalendarDataSupport {
/// in the "urn:ietf:params:xml:ns:caldav" namespace instead of the /// in the "urn:ietf:params:xml:ns:caldav" namespace instead of the
/// "DAV:" namespace. /// "DAV:" namespace.
pub struct Comp { pub struct Comp {
name: Component, pub name: Component,
prop_kind: PropKind, pub prop_kind: PropKind,
comp_kind: CompKind, pub comp_kind: CompKind,
} }
/// For SupportedCalendarComponentSet /// For SupportedCalendarComponentSet
@ -864,7 +864,7 @@ pub struct Comp {
/// <C:comp name="VEVENT"/> /// <C:comp name="VEVENT"/>
/// <C:comp name="VTODO"/> /// <C:comp name="VTODO"/>
/// </C:supported-calendar-component-set> /// </C:supported-calendar-component-set>
pub struct CompSupport(Component); pub struct CompSupport(pub Component);
/// Name: allcomp /// Name: allcomp
/// ///
@ -932,8 +932,8 @@ pub enum PropKind {
/// defined in the "urn:ietf:params:xml:ns:caldav" namespace instead /// defined in the "urn:ietf:params:xml:ns:caldav" namespace instead
/// of the "DAV:" namespace. /// of the "DAV:" namespace.
pub struct CalProp { pub struct CalProp {
name: ComponentProperty, pub name: ComponentProperty,
novalue: bool, pub novalue: Option<bool>,
} }
pub enum RecurrenceModifier { pub enum RecurrenceModifier {
@ -981,7 +981,7 @@ pub enum RecurrenceModifier {
/// end CDATA #REQUIRED> /// end CDATA #REQUIRED>
/// start value: an iCalendar "date with UTC time" /// start value: an iCalendar "date with UTC time"
/// end value: an iCalendar "date with UTC time" /// end value: an iCalendar "date with UTC time"
pub struct Expand(DateTime<Utc>, DateTime<Utc>); pub struct Expand(pub DateTime<Utc>, pub DateTime<Utc>);
/// CALDAV:limit-recurrence-set XML Element /// CALDAV:limit-recurrence-set XML Element
/// ///
@ -1348,11 +1348,24 @@ pub enum Component {
VAlarm, VAlarm,
Unknown(String), Unknown(String),
} }
impl Component {
pub fn as_str<'a>(&'a self) -> &'a str {
match self {
Self::VCalendar => "VCALENDAR",
Self::VJournal => "VJOURNAL",
Self::VFreeBusy => "VFREEBUSY",
Self::VEvent => "VEVENT",
Self::VTodo => "VTODO",
Self::VAlarm => "VALARM",
Self::Unknown(c) => c,
}
}
}
/// name="VERSION", name="SUMMARY", etc. /// name="VERSION", name="SUMMARY", etc.
/// Can be set on different objects: VCalendar, VEvent, etc. /// Can be set on different objects: VCalendar, VEvent, etc.
/// Might be replaced by an enum later /// Might be replaced by an enum later
pub struct ComponentProperty(String); pub struct ComponentProperty(pub String);
/// like PARSTAT /// like PARSTAT
pub struct PropertyParameter(String); pub struct PropertyParameter(String);

View file

@ -37,16 +37,16 @@ impl Context for NoExtension {
} }
start start
} }
async fn hook_error(&self, err: &Disabled, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> { async fn hook_error(&self, _err: &Disabled, _xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> {
unreachable!(); unreachable!();
} }
async fn hook_property(&self, prop: &Disabled, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> { async fn hook_property(&self, _prop: &Disabled, _xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> {
unreachable!(); unreachable!();
} }
async fn hook_propertyrequest(&self, prop: &Disabled, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> { async fn hook_propertyrequest(&self, _prop: &Disabled, _xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> {
unreachable!(); unreachable!();
} }
async fn hook_resourcetype(&self, restype: &Disabled, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> { async fn hook_resourcetype(&self, _restype: &Disabled, _xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> {
unreachable!(); unreachable!();
} }
} }