Citadel Server and libcitadel version 922
[citadel.git] / citadel / ical_dezonify.c
index 40e2516617c5122cb58a36fcaab345428eac70e7..04d41e7c90b0887cd5c2b02dac946bd8028d4c4c 100644 (file)
@@ -1,7 +1,17 @@
-/* 
+/*
  * Function to go through an ical component set and convert all non-UTC
  * date/time properties to UTC.  It also strips out any VTIMEZONE
  * subcomponents afterwards, because they're irrelevant.
+ *
+ * Copyright (c) 1987-2017 by the citadel.org team
+ *
+ * This program is open source software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  */
 
 
@@ -13,6 +23,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <strings.h>
+#include <syslog.h>
 #include <libical/ical.h>
 #include <libcitadel.h>
 #include "citadel.h"
@@ -22,7 +33,6 @@
 #include "support.h"
 #include "config.h"
 #include "ical_dezonify.h"
-
 #include "ctdl_module.h"
 
 
 icaltimezone *get_default_icaltimezone(void) {
 
         icaltimezone *zone = NULL;
-       char *default_zone_name = config.c_default_cal_zone;
-       //char *default_zone_name = "America/New_York";
+       char *default_zone_name = CtdlGetConfigStr("c_default_cal_zone");
 
         if (!zone) {
                 zone = icaltimezone_get_builtin_timezone(default_zone_name);
         }
         if (!zone) {
-               CtdlLogPrintf(CTDL_ALERT,
-                       "Unable to load '%s' time zone.  Defaulting to UTC.\n",
-                       default_zone_name);
+               syslog(LOG_ERR, "ical: Unable to load '%s' time zone.  Defaulting to UTC.", default_zone_name);
                 zone = icaltimezone_get_utc_timezone();
        }
        if (!zone) {
-               CtdlLogPrintf(CTDL_ALERT, "Unable to load UTC time zone!\n");
+               syslog(LOG_ERR, "ical: unable to load UTC time zone!");
        }
         return zone;
 }
@@ -81,16 +88,16 @@ void ical_dezonify_backend(icalcomponent *cal,
 
                /* Convert it to an icaltimezone type. */
                if (tzid != NULL) {
-                       /* CtdlLogPrintf(CTDL_DEBUG, "                * Stringy supplied timezone is: '%s'\n", tzid); */
+                       /* syslog(LOG_DEBUG, "                * Stringy supplied timezone is: '%s'\n", tzid); */
                        if ( (!strcasecmp(tzid, "UTC")) || (!strcasecmp(tzid, "GMT")) ) {
                                utc_declared_as_tzid = 1;
-                               /* CtdlLogPrintf(CTDL_DEBUG, "                * ...and we handle that internally.\n"); */
+                               /* syslog(LOG_DEBUG, "                * ...and we handle that internally.\n"); */
                        }
                        else {
                                /* try attached first */
                                t = icalcomponent_get_timezone(cal, tzid);
 /*
-                               lprintf(CTDL_DEBUG, "                * ...and I %s have tzdata for that zone.\n",
+                               syslog(LOG_DEBUG, "                * ...and I %s have tzdata for that zone.\n",
                                        (t ? "DO" : "DO NOT")
                                );
 */
@@ -99,7 +106,7 @@ void ical_dezonify_backend(icalcomponent *cal,
                                        t = icaltimezone_get_builtin_timezone(tzid);
 /*
                                        if (t) {
-                                               lprintf(CTDL_DEBUG, "                * Using system tzdata!\n");
+                                               syslog(LOG_DEBUG, "                * Using system tzdata!\n");
                                        }
 */
                                }
@@ -126,24 +133,24 @@ void ical_dezonify_backend(icalcomponent *cal,
                return;
        }
 
-       /* CtdlLogPrintf(CTDL_DEBUG, "                * Was: %s\n", icaltime_as_ical_string(TheTime)); */
+       /* syslog(LOG_DEBUG, "                * Was: %s\n", icaltime_as_ical_string(TheTime)); */
 
-       if (TheTime.is_utc) {
-               /* CtdlLogPrintf(CTDL_DEBUG, "                * This property is ALREADY UTC.\n"); */
+       if (icaltime_is_utc(TheTime)) {
+               /* syslog(LOG_DEBUG, "                * This property is ALREADY UTC.\n"); */
        }
 
        else if (utc_declared_as_tzid) {
-               /* CtdlLogPrintf(CTDL_DEBUG, "                * Replacing '%s' TZID with 'Z' suffix.\n", tzid); */
-               TheTime.is_utc = 1;
+               /* syslog(LOG_DEBUG, "                * Replacing '%s' TZID with 'Z' suffix.\n", tzid); */
+               TheTime.zone = icaltimezone_get_utc_timezone();
        }
 
        else {
                /* Do the conversion. */
                if (t != NULL) {
-                       /* CtdlLogPrintf(CTDL_DEBUG, "                * Timezone prop found.  Converting to UTC.\n"); */
+                       /* syslog(LOG_DEBUG, "                * Timezone prop found.  Converting to UTC.\n"); */
                }
                else {
-                       /* CtdlLogPrintf(CTDL_DEBUG, "                * Converting default timezone to UTC.\n"); */
+                       /* syslog(LOG_DEBUG, "                * Converting default timezone to UTC.\n"); */
                }
 
                if (t == NULL) {
@@ -154,11 +161,11 @@ void ical_dezonify_backend(icalcomponent *cal,
                                        t,
                                        icaltimezone_get_utc_timezone()
                );
-               TheTime.is_utc = 1;
+               TheTime.zone = icaltimezone_get_utc_timezone();
        }
 
        icalproperty_remove_parameter_by_kind(prop, ICAL_TZID_PARAMETER);
-       /* CtdlLogPrintf(CTDL_DEBUG, "                * Now: %s\n", icaltime_as_ical_string(TheTime)); */
+       /* syslog(LOG_DEBUG, "                * Now: %s\n", icaltime_as_ical_string(TheTime)); */
 
        /* Now add the converted property back in. */
        if (icalproperty_isa(prop) == ICAL_DTSTART_PROPERTY) {
@@ -224,7 +231,7 @@ void ical_dezonify_recurse(icalcomponent *cal, icalcomponent *rcal) {
 void ical_dezonify(icalcomponent *cal) {
        icalcomponent *vt = NULL;
 
-       /* CtdlLogPrintf(CTDL_DEBUG, "ical_dezonify() started\n"); */
+       /* syslog(LOG_DEBUG, "ical_dezonify() started\n"); */
 
        /* Convert all times to UTC */
        ical_dezonify_recurse(cal, cal);
@@ -236,5 +243,5 @@ void ical_dezonify(icalcomponent *cal) {
                icalcomponent_free(vt);
        }
 
-       /* CtdlLogPrintf(CTDL_DEBUG, "ical_dezonify() completed\n"); */
+       /* syslog(LOG_DEBUG, "ical_dezonify() completed\n"); */
 }