]> code.citadel.org Git - citadel.git/blobdiff - webcit/calendar_tools.c
* Calendar objects UID now generated by generate_uuid() which creates
[citadel.git] / webcit / calendar_tools.c
index 154f43e03cf5f093917a3877c119094118c21655..713a7feb046990b3ee705faeccca300c977cef83 100644 (file)
@@ -43,7 +43,7 @@ char *hourname[] = {
        "7pm", "8pm", "9pm", "10pm", "11pm"
 };
 
-#ifdef HAVE_ICAL_H
+#ifdef WEBCIT_WITH_CALENDAR_SERVICE
 
 /*
  * The display_icaltimetype_as_webform() and icaltime_from_webform() functions
@@ -65,23 +65,27 @@ char *hourname[] = {
 
 void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
        int i;
-
        time_t now;
        struct tm tm_now;
        int this_year;
-
        time_t tt;
        struct tm tm;
-
        const int span = 10;
+       int all_day_event = 0;
 
        now = time(NULL);
-       memcpy(&tm_now, localtime(&now), sizeof(struct tm));
+       localtime_r(&now, &tm_now);
        this_year = tm_now.tm_year + 1900;
 
        if (t == NULL) return;
+       if (t->is_date) all_day_event = 1;
        tt = icaltime_as_timet(*t);
-       memcpy(&tm, localtime(&tt), sizeof(struct tm));
+       if (all_day_event) {
+               gmtime_r(&tt, &tm);
+       }
+       else {
+               localtime_r(&tt, &tm);
+       }
 
        wprintf("Month: ");
        wprintf("<SELECT NAME=\"%s_month\" SIZE=\"1\">\n", prefix);
@@ -135,10 +139,12 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
        wprintf("Minute: ");
        wprintf("<SELECT NAME=\"%s_minute\" SIZE=\"1\">\n", prefix);
        for (i=0; i<=59; ++i) {
-               wprintf("<OPTION %s VALUE=\"%d\">:%02d</OPTION>\n",
-                       ((tm.tm_min == i) ? "SELECTED" : ""),
-                       i, i
-               );
+               if ( (i % 5 == 0) || (tm.tm_min == i) ) {
+                       wprintf("<OPTION %s VALUE=\"%d\">:%02d</OPTION>\n",
+                               ((tm.tm_min == i) ? "SELECTED" : ""),
+                               i, i
+                       );
+               }
        }
        wprintf("</SELECT>\n");
 }
@@ -151,7 +157,7 @@ struct icaltimetype icaltime_from_webform(char *prefix) {
        char vname[SIZ];
 
        tt = time(NULL);
-       memcpy(&tm, localtime(&tt), sizeof(struct tm));
+       localtime_r(&tt, &tm);
 
        sprintf(vname, "%s_month", prefix);     tm.tm_mon = atoi(bstr(vname)) - 1;
        sprintf(vname, "%s_day", prefix);       tm.tm_mday = atoi(bstr(vname));
@@ -166,18 +172,6 @@ struct icaltimetype icaltime_from_webform(char *prefix) {
 }
 
 
-/*
- * Generae a new, globally unique UID parameter for a calendar object.
- */
-void generate_new_uid(char *buf) {
-       static int seq = 0;
-
-       sprintf(buf, "%ld-%d@%s",
-               (long)time(NULL),
-               (seq++),
-               serv_info.serv_fqdn);
-}
-
 /*
  * Render a PARTSTAT parameter as a string (and put it in parentheses)
  */
@@ -228,4 +222,55 @@ void partstat_as_string(char *buf, icalproperty *attendee) {
 }
 
 
+/*
+ * Utility function to encapsulate a subcomponent into a full VCALENDAR
+ */
+icalcomponent *ical_encapsulate_subcomponent(icalcomponent *subcomp) {
+       icalcomponent *encaps;
+
+       lprintf(9, "ical_encapsulate_subcomponent() called\n");
+
+       if (subcomp == NULL) {
+               lprintf(3, "ERROR: called with NULL argument!\n");
+               return NULL;
+       }
+
+       /* If we're already looking at a full VCALENDAR component,
+        * don't bother ... just return itself.
+        */
+       if (icalcomponent_isa(subcomp) == ICAL_VCALENDAR_COMPONENT) {
+               lprintf(9, "Already encapsulated.  Returning itself.\n");
+               return subcomp;
+       }
+
+       /* Encapsulate the VEVENT component into a complete VCALENDAR */
+       encaps = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
+       if (encaps == NULL) {
+               lprintf(3, "Error at %s:%d - could not allocate component!\n",
+                       __FILE__, __LINE__);
+               return NULL;
+       }
+
+       /* Set the Product ID */
+       icalcomponent_add_property(encaps, icalproperty_new_prodid(PRODID));
+
+       /* Set the Version Number */
+       icalcomponent_add_property(encaps, icalproperty_new_version("2.0"));
+
+       /* Encapsulate the subcomponent inside */
+       lprintf(9, "Doing the encapsulation\n");
+       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);
+}
+
+
+
+
 #endif