#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
-#include <ical.h>
+#include <libical/ical.h>
#include <libcitadel.h>
#include "citadel.h"
#include "server.h"
/* Encapsulate the subcomponent inside */
icalcomponent_add_component(encaps, subcomp);
- /* Convert all timestamps to UTC so we don't have to deal with
- * stupid VTIMEZONE crap.
- */
- ical_dezonify(encaps);
-
/* Return the object we just created. */
return(encaps);
}
return;
}
- ser = icalcomponent_as_ical_string(cal);
+ ser = icalcomponent_as_ical_string_r(cal);
if (ser == NULL) return;
/* If the caller supplied a user, write to that user's default calendar room */
}
/* In either case, now we can free the serialized calendar object */
-// free(ser);
+ free(ser);
}
void ical_add(icalcomponent *cal, int recursion_level) {
icalcomponent *c;
+#if 1
+ /* Write the whole thing because it may need to save timezones etc.
+ * FIXME - if this works, we can probably eliminate this entire function
+ */
+
+ ical_write_to_cal(&CC->user, cal);
+
+#else /* this was the old code to kill everything but the VEVENT component ... probably ng now */
+
/*
* The VEVENT subcomponent is the one we're interested in saving.
*/
/* Recursively process subcomponent */
ical_add(c, recursion_level+1);
}
+#endif
}
}
/* Now generate the reply message and send it out. */
- serialized_reply = strdup(icalcomponent_as_ical_string(the_reply));
+ serialized_reply = icalcomponent_as_ical_string_r(the_reply);
icalcomponent_free(the_reply); /* don't need this anymore */
if (serialized_reply == NULL) return;
*/
void ical_locate_part(char *name, char *filename, char *partnum, char *disp,
void *content, char *cbtype, char *cbcharset, size_t length, char *encoding,
- void *cbuserdata) {
+ char *cbid, void *cbuserdata) {
struct ical_respond_data *ird = NULL;
}
ird->cal = icalcomponent_new_from_string(content);
- if (ird->cal != NULL) {
- ical_dezonify(ird->cal);
- }
}
*/
void ical_locate_original_event(char *name, char *filename, char *partnum, char *disp,
void *content, char *cbtype, char *cbcharset, size_t length, char *encoding,
- void *cbuserdata) {
+ char *cbid, void *cbuserdata) {
struct original_event_container *oec = NULL;
ical_merge_attendee_reply(original_event, cal);
/* Serialize it */
- serialized_event = strdup(icalcomponent_as_ical_string(original_event));
+ serialized_event = icalcomponent_as_ical_string_r(original_event);
icalcomponent_free(original_event); /* Don't need this anymore. */
if (serialized_event == NULL) return(2);
+/*
+ * Phase 6 of "hunt for conflicts"
+ * called by ical_conflicts_phase5()
+ *
+ * Now both the proposed and existing events have been boiled down to start and end times.
+ * Check for overlap and output any conflicts.
+ */
+void ical_conflicts_phase6(struct icaltimetype t1start,
+ struct icaltimetype t1end,
+ struct icaltimetype t2start,
+ struct icaltimetype t2end,
+ long existing_msgnum,
+ char *conflict_event_uid,
+ char *conflict_event_summary,
+ char *compare_uid)
+{
+
+ /* debugging cruft */
+ // time_t tt;
+ // tt = icaltime_as_timet(t1start);
+ // CtdlLogPrintf(CTDL_DEBUG, "PROPOSED START: %s", ctime(&tt));
+ // tt = icaltime_as_timet(t1end);
+ // CtdlLogPrintf(CTDL_DEBUG, " PROPOSED END: %s", ctime(&tt));
+ // tt = icaltime_as_timet(t2start);
+ // CtdlLogPrintf(CTDL_DEBUG, "EXISTING START: %s", ctime(&tt));
+ // tt = icaltime_as_timet(t2end);
+ // CtdlLogPrintf(CTDL_DEBUG, " EXISTING END: %s", ctime(&tt));
+
+ /* compare and output */
+
+ if (ical_ctdl_is_overlap(t1start, t1end, t2start, t2end)) {
+ cprintf("%ld||%s|%s|%d|\n",
+ existing_msgnum,
+ conflict_event_uid,
+ conflict_event_summary,
+ ( ((strlen(compare_uid)>0)
+ &&(!strcasecmp(compare_uid,
+ conflict_event_uid))) ? 1 : 0
+ )
+ );
+ }
+
+}
+
+
/*
- * Called by ical_hunt_for_conflicts_backend()
+ * Phase 5 of "hunt for conflicts"
+ * Called by ical_conflicts_phase4()
*
- * At this point we've got it boiled down to two icalcomponent events in memory.
- * If they conflict, output something to the client.
+ * We have the proposed event boiled down to start and end times.
+ * Now check it against an existing event.
*/
-void ical_output_conflicts(icalcomponent *proposed_event,
- icalcomponent *existing_event,
- long existing_msgnum)
+void ical_conflicts_phase5(struct icaltimetype t1start,
+ struct icaltimetype t1end,
+ icalcomponent *existing_event,
+ long existing_msgnum,
+ char *compare_uid)
{
- struct icaltimetype t1start, t1end, t2start, t2end;
- t1start = icaltime_null_time();
- t1end = icaltime_null_time();
- t2start = icaltime_null_time();
- t1end = icaltime_null_time();
- icalproperty *p;
char conflict_event_uid[SIZ];
char conflict_event_summary[SIZ];
- char compare_uid[SIZ];
+ struct icaltimetype t2start, t2end;
+ icalproperty *p;
+ /* recur variables */
+ icalproperty *rrule = NULL;
+ struct icalrecurrencetype recur;
+ icalrecur_iterator *ritr = NULL;
+ struct icaldurationtype dur;
+ int num_recur = 0;
/* initialization */
-
- strcpy(compare_uid, "");
strcpy(conflict_event_uid, "");
strcpy(conflict_event_summary, "");
-
+ t2start = icaltime_null_time();
+ t2end = icaltime_null_time();
/* existing event stuff */
-
p = ical_ctdl_get_subprop(existing_event, ICAL_DTSTART_PROPERTY);
if (p == NULL) return;
if (p != NULL) t2start = icalproperty_get_dtstart(p);
-
- p = ical_ctdl_get_subprop(existing_event, ICAL_DTEND_PROPERTY);
- if (p != NULL) t2end = icalproperty_get_dtend(p);
- p = ical_ctdl_get_subprop(existing_event, ICAL_UID_PROPERTY);
+ p = ical_ctdl_get_subprop(existing_event, ICAL_DTEND_PROPERTY);
if (p != NULL) {
- strcpy(conflict_event_uid, icalproperty_get_comment(p));
+ t2end = icalproperty_get_dtend(p);
+ dur = icaltime_subtract(t2end, t2start);
}
- p = ical_ctdl_get_subprop(existing_event, ICAL_SUMMARY_PROPERTY);
- if (p != NULL) {
- strcpy(conflict_event_summary, icalproperty_get_comment(p));
+ rrule = ical_ctdl_get_subprop(existing_event, ICAL_RRULE_PROPERTY);
+ if (rrule) {
+ recur = icalproperty_get_rrule(rrule);
+ ritr = icalrecur_iterator_new(recur, t2start);
+ CtdlLogPrintf(CTDL_DEBUG, "Recurrence found: %s\n", icalrecurrencetype_as_string(&recur));
}
+ do {
+ p = ical_ctdl_get_subprop(existing_event, ICAL_UID_PROPERTY);
+ if (p != NULL) {
+ strcpy(conflict_event_uid, icalproperty_get_comment(p));
+ }
+
+ p = ical_ctdl_get_subprop(existing_event, ICAL_SUMMARY_PROPERTY);
+ if (p != NULL) {
+ strcpy(conflict_event_summary, icalproperty_get_comment(p));
+ }
+
+ ical_conflicts_phase6(t1start, t1end, t2start, t2end,
+ existing_msgnum, conflict_event_uid, conflict_event_summary, compare_uid
+ );
+
+ if (rrule) {
+ t2start = icalrecur_iterator_next(ritr);
+ if (!icaltime_is_null_time(t2end)) {
+ t2end = icaltime_add(t2start, dur);
+ }
+ ++num_recur;
+ }
+
+ } while ( (rrule) && (!icaltime_is_null_time(t2start)) && (num_recur < MAX_RECUR) );
+ icalrecur_iterator_free(ritr);
+ if (num_recur > 0) CtdlLogPrintf(CTDL_DEBUG, "Iterated over existing event %d times.\n", num_recur);
+}
+
+
+
+
+/*
+ * Phase 4 of "hunt for conflicts"
+ * Called by ical_hunt_for_conflicts_backend()
+ *
+ * At this point we've got it boiled down to two icalcomponent events in memory.
+ * If they conflict, output something to the client.
+ */
+void ical_conflicts_phase4(icalcomponent *proposed_event,
+ icalcomponent *existing_event,
+ long existing_msgnum)
+{
+ struct icaltimetype t1start, t1end;
+ t1start = icaltime_null_time();
+ t1end = icaltime_null_time();
+ icalproperty *p;
+ char compare_uid[SIZ];
+
+ /* recur variables */
+ icalproperty *rrule = NULL;
+ struct icalrecurrencetype recur;
+ icalrecur_iterator *ritr = NULL;
+ struct icaldurationtype dur;
+ int num_recur = 0;
+
+ /* initialization */
+ strcpy(compare_uid, "");
/* proposed event stuff */
if (p != NULL) t1start = icalproperty_get_dtstart(p);
p = ical_ctdl_get_subprop(proposed_event, ICAL_DTEND_PROPERTY);
- if (p != NULL) t1end = icalproperty_get_dtend(p);
-
+ if (p != NULL) {
+ t1end = icalproperty_get_dtend(p);
+ dur = icaltime_subtract(t1end, t1start);
+ }
+
+ rrule = ical_ctdl_get_subprop(proposed_event, ICAL_RRULE_PROPERTY);
+ if (rrule) {
+ recur = icalproperty_get_rrule(rrule);
+ ritr = icalrecur_iterator_new(recur, t1start);
+ CtdlLogPrintf(CTDL_DEBUG, "Recurrence found: %s\n", icalrecurrencetype_as_string(&recur));
+ }
+
p = ical_ctdl_get_subprop(proposed_event, ICAL_UID_PROPERTY);
if (p != NULL) {
strcpy(compare_uid, icalproperty_get_comment(p));
}
+ do {
+ ical_conflicts_phase5(t1start, t1end, existing_event, existing_msgnum, compare_uid);
- /* compare and output */
-
- if (ical_ctdl_is_overlap(t1start, t1end, t2start, t2end)) {
- cprintf("%ld||%s|%s|%d|\n",
- existing_msgnum,
- conflict_event_uid,
- conflict_event_summary,
- ( ((strlen(compare_uid)>0)
- &&(!strcasecmp(compare_uid,
- conflict_event_uid))) ? 1 : 0
- )
- );
- }
+ if (rrule) {
+ t1start = icalrecur_iterator_next(ritr);
+ if (!icaltime_is_null_time(t1end)) {
+ t1end = icaltime_add(t1start, dur);
+ }
+ ++num_recur;
+ }
+ } while ( (rrule) && (!icaltime_is_null_time(t1start)) && (num_recur < MAX_RECUR) );
+ icalrecur_iterator_free(ritr);
+ if (num_recur > 0) CtdlLogPrintf(CTDL_DEBUG, "Iterated over proposed event %d times.\n", num_recur);
}
/*
+ * Phase 3 of "hunt for conflicts"
* Called by ical_hunt_for_conflicts()
*/
void ical_hunt_for_conflicts_backend(long msgnum, void *data) {
if (ird.cal == NULL) return;
- /* here it is */
- ical_output_conflicts(proposed_event, ird.cal, msgnum);
+ ical_conflicts_phase4(proposed_event, ird.cal, msgnum);
icalcomponent_free(ird.cal);
}
return;
}
- ical_dezonify(cal);
-
/* If this event is not opaque, the user isn't publishing it as
* busy time, so don't bother doing anything else.
*/
/* Serialize it */
CtdlLogPrintf(CTDL_DEBUG, "Serializing\n");
- serialized_request = strdup(icalcomponent_as_ical_string(encaps));
+ serialized_request = icalcomponent_as_ical_string_r(encaps);
icalcomponent_free(encaps); /* Don't need this anymore. */
cprintf("%d Here is the free/busy data:\n", LISTING_FOLLOWS);
(void *) encaps
);
- ser = strdup(icalcomponent_as_ical_string(encaps));
+ ser = icalcomponent_as_ical_string_r(encaps);
client_write(ser, strlen(ser));
free(ser);
cprintf("\n000\n");
cal = icalcomponent_new_from_string(calstream);
free(calstream);
- ical_dezonify(cal);
/* We got our data stream -- now do something with it. */
/* Set the method to REQUEST */
icalcomponent_set_method(encaps, ICAL_METHOD_REQUEST);
- /* Now make sure all of the DTSTART and DTEND properties are UTC. */
- ical_dezonify(the_request);
-
/* Here we go: put the VEVENT into the VCALENDAR. We now no longer
* are responsible for "the_request"'s memory -- it will be freed
* when we free "encaps".
icalcomponent_add_component(encaps, the_request);
/* Serialize it */
- serialized_request = strdup(icalcomponent_as_ical_string(encaps));
+ serialized_request = icalcomponent_as_ical_string_r(encaps);
icalcomponent_free(encaps); /* Don't need this anymore. */
if (serialized_request == NULL) return;
*/
void ical_obj_beforesave_backend(char *name, char *filename, char *partnum,
char *disp, void *content, char *cbtype, char *cbcharset, size_t length,
- char *encoding, void *cbuserdata)
+ char *encoding, char *cbid, void *cbuserdata)
{
icalcomponent *cal, *nested_event, *nested_todo, *whole_cal;
icalproperty *p;
*/
void ical_obj_aftersave_backend(char *name, char *filename, char *partnum,
char *disp, void *content, char *cbtype, char *cbcharset, size_t length,
- char *encoding, void *cbuserdata)
+ char *encoding, char *cbid, void *cbuserdata)
{
icalcomponent *cal;
return;
}
- ical_dezonify(cal);
ical_fixed_output_backend(cal, 0);
/* Free the memory we obtained from libical's constructor */
{
if (!threading)
{
+
+ /* Tell libical to return errors instead of aborting if it gets bad data */
+ icalerror_errors_are_fatal = 0;
+
+ /* Use our own application prefix in tzid's generated from system tzdata */
+ icaltimezone_set_tzid_prefix("/citadel.org/");
+
+ /* Initialize our hook functions */
CtdlRegisterMessageHook(ical_obj_beforesave, EVT_BEFORESAVE);
CtdlRegisterMessageHook(ical_obj_aftersave, EVT_AFTERSAVE);
CtdlRegisterSessionHook(ical_create_room, EVT_LOGIN);