calendar server -- further split up the conflict checker
authorArt Cancro <ajc@citadel.org>
Mon, 11 Aug 2008 21:03:26 +0000 (21:03 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 11 Aug 2008 21:03:26 +0000 (21:03 +0000)
(was two functions, is now three) in order to prepare for handling
recurring events.  I might split it up even further.

citadel/modules/calendar/serv_calendar.c

index 41bedf0268047948043c0daec435e99abed8e7b6..5cabf6bdf97ea9ee0b4202d7e7877b49b8bbb8f2 100644 (file)
@@ -890,79 +890,75 @@ int ical_ctdl_is_overlap(
 
 
 
+
 /*
- * Backend for ical_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_hunt_for_conflicts_backend(long msgnum, void *data) {
-       icalcomponent *cal;
-       struct CtdlMessage *msg = NULL;
-       struct ical_respond_data ird;
+void ical_output_conflicts(icalcomponent *proposed_event,
+               icalcomponent *existing_event,
+               long existing_msgnum)
+{
        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];
 
-       cal = (icalcomponent *)data;
+
+       /* initialization */
+
        strcpy(compare_uid, "");
        strcpy(conflict_event_uid, "");
        strcpy(conflict_event_summary, "");
 
-       msg = CtdlFetchMessage(msgnum, 1);
-       if (msg == NULL) return;
-       memset(&ird, 0, sizeof ird);
-       strcpy(ird.desired_partnum, "_HUNT_");
-       mime_parser(msg->cm_fields['M'],
-               NULL,
-               *ical_locate_part,              /* callback function */
-               NULL, NULL,
-               (void *) &ird,                  /* user data */
-               0
-       );
-       CtdlFreeMessage(msg);
 
-       if (ird.cal == NULL) return;
+       /* existing event stuff */
 
-       t1start = icaltime_null_time();
-       t1end = icaltime_null_time();
-       t2start = icaltime_null_time();
-       t1end = icaltime_null_time();
-
-       /* Now compare cal to ird.cal */
-       p = ical_ctdl_get_subprop(ird.cal, ICAL_DTSTART_PROPERTY);
+       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(ird.cal, ICAL_DTEND_PROPERTY);
+       p = ical_ctdl_get_subprop(existing_event, ICAL_DTEND_PROPERTY);
        if (p != NULL) t2end = icalproperty_get_dtend(p);
 
-       p = ical_ctdl_get_subprop(cal, ICAL_DTSTART_PROPERTY);
+       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));
+       }
+
+
+       /* proposed event stuff */
+
+       p = ical_ctdl_get_subprop(proposed_event, ICAL_DTSTART_PROPERTY);
        if (p == NULL) return;
        if (p != NULL) t1start = icalproperty_get_dtstart(p);
        
-       p = ical_ctdl_get_subprop(cal, ICAL_DTEND_PROPERTY);
+       p = ical_ctdl_get_subprop(proposed_event, ICAL_DTEND_PROPERTY);
        if (p != NULL) t1end = icalproperty_get_dtend(p);
        
-       p = ical_ctdl_get_subprop(cal, ICAL_UID_PROPERTY);
+       p = ical_ctdl_get_subprop(proposed_event, ICAL_UID_PROPERTY);
        if (p != NULL) {
                strcpy(compare_uid, icalproperty_get_comment(p));
        }
 
-       p = ical_ctdl_get_subprop(ird.cal, ICAL_UID_PROPERTY);
-       if (p != NULL) {
-               strcpy(conflict_event_uid, icalproperty_get_comment(p));
-       }
-
-       p = ical_ctdl_get_subprop(ird.cal, ICAL_SUMMARY_PROPERTY);
-       if (p != NULL) {
-               strcpy(conflict_event_summary, icalproperty_get_comment(p));
-       }
 
-       icalcomponent_free(ird.cal);
+       /* compare and output */
 
        if (ical_ctdl_is_overlap(t1start, t1end, t2start, t2end)) {
                cprintf("%ld||%s|%s|%d|\n",
-                       msgnum,
+                       existing_msgnum,
                        conflict_event_uid,
                        conflict_event_summary,
                        (       ((strlen(compare_uid)>0)
@@ -971,6 +967,39 @@ void ical_hunt_for_conflicts_backend(long msgnum, void *data) {
                        )
                );
        }
+
+}
+
+
+
+/*
+ * Called by ical_hunt_for_conflicts()
+ */
+void ical_hunt_for_conflicts_backend(long msgnum, void *data) {
+       icalcomponent *proposed_event;
+       struct CtdlMessage *msg = NULL;
+       struct ical_respond_data ird;
+
+       proposed_event = (icalcomponent *)data;
+
+       msg = CtdlFetchMessage(msgnum, 1);
+       if (msg == NULL) return;
+       memset(&ird, 0, sizeof ird);
+       strcpy(ird.desired_partnum, "_HUNT_");
+       mime_parser(msg->cm_fields['M'],
+               NULL,
+               *ical_locate_part,              /* callback function */
+               NULL, NULL,
+               (void *) &ird,                  /* user data */
+               0
+       );
+       CtdlFreeMessage(msg);
+
+       if (ird.cal == NULL) return;
+
+       /* here it is */
+       ical_output_conflicts(proposed_event, ird.cal, msgnum);
+       icalcomponent_free(ird.cal);
 }
 
 
@@ -978,7 +1007,7 @@ void ical_hunt_for_conflicts_backend(long msgnum, void *data) {
 /* 
  * Phase 2 of "hunt for conflicts" operation.
  * At this point we have a calendar object which represents the VEVENT that
- * we're considering adding to the calendar.  Now hunt through the user's
+ * is proposed for addition to the calendar.  Now hunt through the user's
  * calendar room, and output zero or more existing VEVENTs which conflict
  * with this one.
  */