[Asterisk-code-review] res calendar icalendar: Filter out the occurrences supersede... (asterisk[13])

Benoît Dereck-Tricot asteriskteam at digium.com
Thu Sep 28 07:32:57 CDT 2017


Benoît Dereck-Tricot has uploaded this change for review. ( https://gerrit.asterisk.org/6625


Change subject: res_calendar_icalendar: Filter out the occurrences superseded by an other VEVENT
......................................................................

res_calendar_icalendar: Filter out the occurrences superseded by an other VEVENT

When we are loading the calendars, we call libical's
icalcomponent_foreach_recurrence method for each VEVENT component that we have
in our calendar.
That method has no knowledge concerning the existence of the other VEVENT
components and will feed our callback with all ocurrences matching the requested
time span.
The occurrences generated by icalcomponent_foreach_recurrence while expanding a
recurring VEVENT's RRULE and RDATE properties can be superseded by an other
VEVENT sharing the same UID.
I use an external iterator (in libical terminology) to avoid messing with
the internal ones from the calling function, and search for VEVENTS which could
supersede the current occurrence.
The event which can invalidate this occurence needs to have
- the same UID as our recurrent component (comp)
- a RECURRENCE-ID property, which represents the start time of this occurrence
If one component is found, just clean and return

ASTERISK-27296

Change-Id: I8587ae3eaa765af7cb21eda3b6bf84e8a1c87af8
---
M res/res_calendar_icalendar.c
1 file changed, 32 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/25/6625/1

diff --git a/res/res_calendar_icalendar.c b/res/res_calendar_icalendar.c
index a6ce627..73443d7 100644
--- a/res/res_calendar_icalendar.c
+++ b/res/res_calendar_icalendar.c
@@ -251,7 +251,38 @@
 		}
 	}
 
-	/* Get the attendees */
+    /*
+     * If comp has an RRULE and/or RDATE property, we need to check whether an other vevent component
+     * supersedes this span. Such a component would have two characteristics:
+     *  - its UID is the same as comp
+     *  - its RECURRENCE-ID property is the same time as span->start
+     */
+    if (   icalcomponent_get_first_property(comp, ICAL_RRULE_PROPERTY)
+        || icalcomponent_get_first_property(comp, ICAL_RDATE_PROPERTY)) {
+        icalcompiter comp_iter;
+        icaltimetype span_start = icaltime_from_timet_with_zone(event->start,
+                                                                icaltime_is_date(start),
+                                                                icaltime_get_timezone(start));
+        icaltime_set_timezone(&span_start, icaltime_get_timezone(start));
+
+        for (comp_iter = icalcomponent_begin_component(pvt->data, ICAL_VEVENT_COMPONENT);
+             icalcompiter_deref(&comp_iter) != 0;
+             icalcompiter_next(&comp_iter)) {
+            icalcomponent *vevent = icalcompiter_deref(&comp_iter);
+            icalproperty *uid = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
+
+            if ( uid && ! strcmp(icalproperty_get_value_as_string(uid), event->uid)) {
+                icaltimetype recurrence_id = icalcomponent_get_recurrenceid(vevent);
+                if ( ! (icaltime_compare(recurrence_id, span_start))
+                     && (icaltime_is_date(span_start) == icaltime_is_date(recurrence_id))) {
+                    event = ast_calendar_unref_event(event);
+                    return;
+                }
+            }
+        }
+    }
+
+    /* Get the attendees */
 	for (prop = icalcomponent_get_first_property(comp, ICAL_ATTENDEE_PROPERTY);
 			prop; prop = icalcomponent_get_next_property(comp, ICAL_ATTENDEE_PROPERTY)) {
 		struct ast_calendar_attendee *attendee;

-- 
To view, visit https://gerrit.asterisk.org/6625
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8587ae3eaa765af7cb21eda3b6bf84e8a1c87af8
Gerrit-Change-Number: 6625
Gerrit-PatchSet: 1
Gerrit-Owner: Benoît Dereck-Tricot <benoit.dereck-tricot at eyepea.eu>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20170928/25b79d86/attachment.html>


More information about the asterisk-code-review mailing list