4 * Function to go through an ical component set and convert all non-UTC
5 * date/time properties to UTC. It also strips out any VTIMEZONE
6 * subcomponents afterwards, because they're irrelevant.
8 * Everything here will work on both a fully encapsulated VCALENDAR component
9 * or any type of subcomponent.
24 #include <sys/types.h>
26 #include <sys/socket.h>
27 #ifdef HAVE_SYS_TIME_H
33 #include <netinet/in.h>
34 #include <arpa/inet.h>
43 #include "webserver.h"
46 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
50 * Back end function for ical_dezonify()
52 * We supply this with the master component, the relevant component,
53 * and the property (which will be a DTSTART, DTEND, etc.)
54 * which we want to convert to UTC.
56 void ical_dezonify_backend(icalcomponent *cal,
60 icaltimezone *t = NULL;
63 struct icaltimetype TheTime;
65 /* Give me nothing and I will give you nothing in return. */
66 if (cal == NULL) return;
68 /* Hunt for a TZID parameter in this property. */
69 param = icalproperty_get_first_parameter(prop, ICAL_TZID_PARAMETER);
71 /* Get the stringish name of this TZID. */
73 tzid = icalparameter_get_tzid(param);
75 /* Convert it to an icaltimezone type. */
77 t = icalcomponent_get_timezone(cal, tzid);
82 /* Now we know the timezone. Convert to UTC. */
84 if (icalproperty_isa(prop) == ICAL_DTSTART_PROPERTY) {
85 TheTime = icalproperty_get_dtstart(prop);
87 else if (icalproperty_isa(prop) == ICAL_DTEND_PROPERTY) {
88 TheTime = icalproperty_get_dtend(prop);
90 else if (icalproperty_isa(prop) == ICAL_DUE_PROPERTY) {
91 TheTime = icalproperty_get_due(prop);
93 else if (icalproperty_isa(prop) == ICAL_EXDATE_PROPERTY) {
94 TheTime = icalproperty_get_exdate(prop);
100 /* Do the conversion. */
102 icaltimezone_convert_time(&TheTime,
104 icaltimezone_get_utc_timezone()
108 icalproperty_remove_parameter_by_kind(prop, ICAL_TZID_PARAMETER);
110 /* Now add the converted property back in. */
111 if (icalproperty_isa(prop) == ICAL_DTSTART_PROPERTY) {
112 icalproperty_set_dtstart(prop, TheTime);
114 else if (icalproperty_isa(prop) == ICAL_DTEND_PROPERTY) {
115 icalproperty_set_dtend(prop, TheTime);
117 else if (icalproperty_isa(prop) == ICAL_DUE_PROPERTY) {
118 icalproperty_set_due(prop, TheTime);
120 else if (icalproperty_isa(prop) == ICAL_EXDATE_PROPERTY) {
121 icalproperty_set_exdate(prop, TheTime);
127 * Recursive portion of ical_dezonify()
129 void ical_dezonify_recur(icalcomponent *cal, icalcomponent *rcal) {
134 * Recurse through all subcomponents *except* VTIMEZONE ones.
136 for (c=icalcomponent_get_first_component(
137 rcal, ICAL_ANY_COMPONENT);
139 c = icalcomponent_get_next_component(
140 rcal, ICAL_ANY_COMPONENT)
142 if (icalcomponent_isa(c) != ICAL_VTIMEZONE_COMPONENT) {
143 ical_dezonify_recur(cal, c);
148 * Now look for DTSTART and DTEND properties
150 for (p=icalcomponent_get_first_property(
151 rcal, ICAL_ANY_PROPERTY);
153 p = icalcomponent_get_next_property(
154 rcal, ICAL_ANY_PROPERTY)
157 (icalproperty_isa(p) == ICAL_DTSTART_PROPERTY)
158 || (icalproperty_isa(p) == ICAL_DTEND_PROPERTY)
159 || (icalproperty_isa(p) == ICAL_DUE_PROPERTY)
160 || (icalproperty_isa(p) == ICAL_EXDATE_PROPERTY)
162 ical_dezonify_backend(cal, rcal, p);
169 * Convert all DTSTART and DTEND properties in all subcomponents to UTC.
170 * This function will search any VTIMEZONE subcomponents to learn the
171 * relevant timezone information.
173 void ical_dezonify(icalcomponent *cal) {
174 icalcomponent *vt = NULL;
176 /* Convert all times to UTC */
177 ical_dezonify_recur(cal, cal);
179 /* Strip out VTIMEZONE subcomponents -- we don't need them anymore */
180 while (vt = icalcomponent_get_first_component(
181 cal, ICAL_VTIMEZONE_COMPONENT), vt != NULL) {
182 icalcomponent_remove_component(cal, vt);
183 icalcomponent_free(vt);
189 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */