Split up the conflict checker again, this time into six different
authorArt Cancro <ajc@citadel.org>
Tue, 19 Aug 2008 02:58:48 +0000 (02:58 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 19 Aug 2008 02:58:48 +0000 (02:58 +0000)
functions.  Right now it looks like excessive modularity, but over the next couple of commits I'll
be adding expansion of recurrences in both the proposed and existing events.  Now this can be done
without making the code unreadable.

citadel/modules/calendar/serv_calendar.c
webcit/calendar.c

index 5cabf6bdf97ea9ee0b4202d7e7877b49b8bbb8f2..d8f02831cc673768a252325ba15a5323433a93c7 100644 (file)
@@ -890,33 +890,80 @@ int ical_ctdl_is_overlap(
 
 
 
+/* 
+ * 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
+                       )
+               );
+               CtdlLogPrintf(CTDL_DEBUG, "  --- CONFLICT --- \n");
+       }
+       else {
+               CtdlLogPrintf(CTDL_DEBUG, "  --- no conflict --- \n");
+       }
+
+}
+
+
 
 /*
- * 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;
 
        /* initialization */
 
-       strcpy(compare_uid, "");
        strcpy(conflict_event_uid, "");
        strcpy(conflict_event_summary, "");
+       t2start = icaltime_null_time();
+       t2end = icaltime_null_time();
 
 
        /* existing event stuff */
@@ -939,6 +986,38 @@ void ical_output_conflicts(icalcomponent *proposed_event,
        }
 
 
+       ical_conflicts_phase6(t1start, t1end, t2start, t2end,
+                               existing_msgnum, conflict_event_uid, conflict_event_summary, compare_uid
+       );
+
+}
+
+
+
+
+/*
+ * 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];
+
+
+       /* initialization */
+
+       strcpy(compare_uid, "");
+
+
        /* proposed event stuff */
 
        p = ical_ctdl_get_subprop(proposed_event, ICAL_DTSTART_PROPERTY);
@@ -953,26 +1032,13 @@ void ical_output_conflicts(icalcomponent *proposed_event,
                strcpy(compare_uid, icalproperty_get_comment(p));
        }
 
-
-       /* 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
-                       )
-               );
-       }
-
+       ical_conflicts_phase5(t1start, t1end, existing_event, existing_msgnum, compare_uid);
 }
 
 
 
 /*
+ * Phase 3 of "hunt for conflicts"
  * Called by ical_hunt_for_conflicts()
  */
 void ical_hunt_for_conflicts_backend(long msgnum, void *data) {
@@ -997,8 +1063,7 @@ 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);
 }
 
index 77bc4ddea3d1d5e3d0da440cef88001fab6df7ee..fb3f19e89427a6a11b0f1617f3a64417e7976668 100644 (file)
@@ -485,8 +485,7 @@ void display_individual_cal(icalcomponent *cal, long msgnum, char *from, int unr
        /*
         * Just let libical iterate the recurrence, and keep looping back to the top of this function,
         * adding new hash entries that all point back to the same msgnum, until either the iteration
-        * stops or some outer bound is reached.  The display code *should* automatically do the right
-        * thing (but we'll have to see).
+        * stops or some outer bound is reached.  The display code will automatically do the Right Thing.
         */
 
        rrule = icalcomponent_get_first_property(Cal->cal, ICAL_RRULE_PROPERTY);