]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/calendar/serv_calendar.c
* Conflict checker loop now stops iterating over existing events when it goes out...
[citadel.git] / citadel / modules / calendar / serv_calendar.c
index 2300cd9c1076e98085e29821f982d05a3936bb1d..05504d3a7bac99eeb4d977039aa160364649708f 100644 (file)
@@ -870,15 +870,16 @@ void ical_conflicts_phase6(struct icaltimetype t1start,
 {
 
        /* 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));
+       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));
+       /* debugging cruft */
 
        /* compare and output */
 
@@ -922,6 +923,7 @@ void ical_conflicts_phase5(struct icaltimetype t1start,
        icalrecur_iterator *ritr = NULL;
        struct icaldurationtype dur;
        int num_recur = 0;
+       int out_of_scope = 0;
 
        /* initialization */
        strcpy(conflict_event_uid, "");
@@ -970,7 +972,12 @@ void ical_conflicts_phase5(struct icaltimetype t1start,
                        ++num_recur;
                }
 
-       } while ( (rrule) && (!icaltime_is_null_time(t2start)) && (num_recur < MAX_RECUR) );
+               if (icaltime_compare(t2start, t1end) < 0) {
+                       CtdlLogPrintf(CTDL_DEBUG, "Went out of scope after %d iterations\n", num_recur);
+                       out_of_scope = 1;
+               }
+
+       } while ((rrule) && (!icaltime_is_null_time(t2start)) && (num_recur < MAX_RECUR) && (!out_of_scope));
        icalrecur_iterator_free(ritr);
        if (num_recur > 0) CtdlLogPrintf(CTDL_DEBUG, "Iterated over existing event %d times.\n", num_recur);
 }
@@ -1572,18 +1579,17 @@ void ical_getics(void)
 
 
 /*
- * Helper callback function for ical_putics() to discover which TZID's we need
+ * Helper callback function for ical_putics() to discover which TZID's we need.
+ * Simply put the tzid name string into a hash table.  After the callbacks are
+ * done we'll go through them and attach the ones that we have.
  */
 void ical_putics_grabtzids(icalparameter *param, void *data)
 {
-       char *need_these_tzids = (char *) data;
        const char *tzid = icalparameter_get_tzid(param);
+       HashList *keys = (HashList *) data;
        
-       if ( (need_these_tzids) && (tzid) ) {
-               if (strlen(need_these_tzids) + strlen(tzid) < 1020) {
-                       strcat(need_these_tzids, icalparameter_get_tzid(param));
-                       strcat(need_these_tzids, "\n");
-               }
+       if ( (keys) && (tzid) && (!IsEmptyStr(tzid)) ) {
+               Put(keys, tzid, strlen(tzid), strdup(tzid), generic_free_handler);
        }
 }
 
@@ -1598,7 +1604,11 @@ void ical_putics(void)
        icalcomponent *cal;
        icalcomponent *c;
        icalcomponent *encaps = NULL;
-       int i;
+       HashList *tzidlist = NULL;
+       HashPos *HashPos;
+       void *Value;
+       const char *Key;
+       long len;
 
        /* Only allow this operation if we're in a room containing a calendar or tasks view */
        if ( (CC->room.QRdefaultview != VIEW_CALENDAR)
@@ -1655,11 +1665,36 @@ void ical_putics(void)
                                icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
 
                                /* Attach any needed timezones here */
-                               char need_these_tzids[1024] = "";
-                               icalcomponent_foreach_tzid(c, ical_putics_grabtzids, need_these_tzids);
-                               for (i=0; i<num_tokens(need_these_tzids, '\n'); ++i) {
-                                       CtdlLogPrintf(CTDL_DEBUG, "FIXME need to attach a tzid\n");
+                               tzidlist = NewHash(1, NULL);
+                               if (tzidlist) {
+                                       icalcomponent_foreach_tzid(c, ical_putics_grabtzids, tzidlist);
+                               }
+                               HashPos = GetNewHashPos(tzidlist, 0);
+
+                               while (GetNextHashPos(tzidlist, HashPos, &len, &Key, &Value)) {
+                                       CtdlLogPrintf(CTDL_DEBUG, "Attaching timezone '%s'\n", Value);
+                                       icaltimezone *t = NULL;
+
+                                       /* First look for a timezone attached to the original calendar */
+                                       t = icalcomponent_get_timezone(cal, Value);
+
+                                       /* Try built-in tzdata if the right one wasn't attached */
+                                       if (!t) {
+                                               t = icaltimezone_get_builtin_timezone(Value);
+                                       }
+
+                                       /* I've got a valid timezone to attach. */
+                                       if (t) {
+                                               icalcomponent_add_component(encaps,
+                                                       icalcomponent_new_clone(
+                                                               icaltimezone_get_component(t)
+                                                       )
+                                               );
+                                       }
+
                                }
+                               DeleteHashPos(&HashPos);
+                               DeleteHash(&tzidlist);
 
                                /* Now attach the component itself (usually a VEVENT or VTODO) */
                                icalcomponent_add_component(encaps, icalcomponent_new_clone(c));