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::ValidCalendarObjectResource => atom("valid-calendar-object-resource").await,
Self::SupportedCalendarComponent => atom("supported-calendar-component").await,
Self::ValidCalendarObjectResource => atom("valid-calendar-object-resource").await,
Self::SupportedCalendarComponent => atom("SupportedCalendarComponent").await,
Self::NoUidConflict(href) => {
let start = ctx.create_cal_element("no-uid-conflict");
let end = start.to_end();
@ -391,43 +389,82 @@ impl<C: CalContext> QuickWritable<C> for CalendarDataEmpty {
impl<C: CalContext> QuickWritable<C> for Comp {
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 {
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 {
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 {
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 {
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 {
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 {
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
/// "DAV:" namespace.
pub struct Comp {
name: Component,
prop_kind: PropKind,
comp_kind: CompKind,
pub name: Component,
pub prop_kind: PropKind,
pub comp_kind: CompKind,
}
/// For SupportedCalendarComponentSet
@ -864,7 +864,7 @@ pub struct Comp {
/// <C:comp name="VEVENT"/>
/// <C:comp name="VTODO"/>
/// </C:supported-calendar-component-set>
pub struct CompSupport(Component);
pub struct CompSupport(pub Component);
/// Name: allcomp
///
@ -932,8 +932,8 @@ pub enum PropKind {
/// defined in the "urn:ietf:params:xml:ns:caldav" namespace instead
/// of the "DAV:" namespace.
pub struct CalProp {
name: ComponentProperty,
novalue: bool,
pub name: ComponentProperty,
pub novalue: Option<bool>,
}
pub enum RecurrenceModifier {
@ -981,7 +981,7 @@ pub enum RecurrenceModifier {
/// end CDATA #REQUIRED>
/// start 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
///
@ -1348,11 +1348,24 @@ pub enum Component {
VAlarm,
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.
/// Can be set on different objects: VCalendar, VEvent, etc.
/// Might be replaced by an enum later
pub struct ComponentProperty(String);
pub struct ComponentProperty(pub String);
/// like PARSTAT
pub struct PropertyParameter(String);

View File

@ -37,16 +37,16 @@ impl Context for NoExtension {
}
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!();
}
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!();
}
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!();
}
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!();
}
}