encaps = icalcomponent_new_vcalendar();
if (encaps == NULL) {
- CtdlLogPrintf(CTDL_CRIT, "Error at %s:%d - could not allocate component!\n",
- __FILE__, __LINE__);
+ CtdlLogPrintf(CTDL_CRIT, "ERROR: could not allocate component!\n");
return NULL;
}
/* Encapsulate the subcomponent inside */
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);
}
}
-/*
- * Add a calendar object to the user's calendar
- *
- * ok because it uses ical_write_to_cal()
- */
-void ical_add(icalcomponent *cal, int recursion_level) {
- icalcomponent *c;
-
- /*
- * The VEVENT subcomponent is the one we're interested in saving.
- */
- if (icalcomponent_isa(cal) == ICAL_VEVENT_COMPONENT) {
-
- ical_write_to_cal(&CC->user, cal);
-
- }
-
- /* If the component has subcomponents, recurse through them. */
- for (c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
- (c != 0);
- c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)) {
- /* Recursively process subcomponent */
- ical_add(c, recursion_level+1);
- }
-
-}
-
-
-
/*
* Send a reply to a meeting invitation.
*
}
ird->cal = icalcomponent_new_from_string(content);
- if (ird->cal != NULL) {
- ical_dezonify(ird->cal);
- }
}
if (ird.cal != NULL) {
/* Save this in the user's calendar if necessary */
if (!strcasecmp(action, "accept")) {
- ical_add(ird.cal, 0);
+ ical_write_to_cal(&CC->user, ird.cal);
}
/* Send a reply if necessary */
ical_send_a_reply(ird.cal, action);
}
- /* Now that we've processed this message, we don't need it
- * anymore. So delete it. (NOTE we don't do this anymore.)
- CtdlDeleteMessages(CC->room.QRname, &msgnum, 1, "");
+ /* We used to delete the invitation after handling it.
+ * We don't do that anymore, but here is the code that handled it:
+ * CtdlDeleteMessages(CC->room.QRname, &msgnum, 1, "");
*/
/* Free the memory we allocated and return a response. */
return;
}
- ical_dezonify(cal);
-
/* If this event is not opaque, the user isn't publishing it as
* busy time, so don't bother doing anything else.
*/
for (c = icalcomponent_get_first_component(ird.cal, ICAL_ANY_COMPONENT);
(c != NULL);
c = icalcomponent_get_next_component(ird.cal, ICAL_ANY_COMPONENT)) {
- icalcomponent_add_component(encaps, icalcomponent_new_clone(c));
+
+ /* For VTIMEZONE components, suppress duplicates of the same tzid */
+
+ if (icalcomponent_isa(c) == ICAL_VTIMEZONE_COMPONENT) {
+ icalproperty *p = icalcomponent_get_first_property(c, ICAL_TZID_PROPERTY);
+ if (p) {
+ const char *tzid = icalproperty_get_tzid(p);
+ if (!icalcomponent_get_timezone(encaps, tzid)) {
+ icalcomponent_add_component(encaps,
+ icalcomponent_new_clone(c));
+ }
+ }
+ }
+
+ /* All other types of components can go in verbatim */
+ else {
+ icalcomponent_add_component(encaps, icalcomponent_new_clone(c));
+ }
}
icalcomponent_free(ird.cal);
}
encaps = icalcomponent_new_vcalendar();
if (encaps == NULL) {
- CtdlLogPrintf(CTDL_DEBUG, "Error at %s:%d - could not allocate component!\n",
- __FILE__, __LINE__);
+ CtdlLogPrintf(CTDL_DEBUG, "ERROR: could not allocate component!\n");
cprintf("%d Could not allocate memory\n", ERROR+INTERNAL_ERROR);
return;
}
);
ser = icalcomponent_as_ical_string_r(encaps);
+ icalcomponent_free(encaps); /* Don't need this anymore. */
client_write(ser, strlen(ser));
free(ser);
cprintf("\n000\n");
- icalcomponent_free(encaps); /* Don't need this anymore. */
-
}
cal = icalcomponent_new_from_string(calstream);
free(calstream);
- ical_dezonify(cal);
/* We got our data stream -- now do something with it. */
/*
- * ical_send_out_invitations() is called by ical_saving_vevent() when it
- * finds a VEVENT.
+ * ical_send_out_invitations() is called by ical_saving_vevent() when it finds a VEVENT.
+ *
+ * top_level_cal is the highest available level calendar object.
+ * cal is the subcomponent containing the VEVENT.
+ *
+ * Note: if you change the encapsulation code here, change it in WebCit's ical_encapsulate_subcomponent()
*/
-void ical_send_out_invitations(icalcomponent *cal) {
+void ical_send_out_invitations(icalcomponent *top_level_cal, icalcomponent *cal) {
icalcomponent *the_request = NULL;
char *serialized_request = NULL;
icalcomponent *encaps = NULL;
char summary_string[SIZ];
icalproperty *summary = NULL;
size_t reqsize;
+ icalproperty *p;
+ struct icaltimetype t;
+ icaltimezone *attached_zones[5] = { NULL, NULL, NULL, NULL, NULL };
+ int i;
+ icaltimezone *z;
+ int num_zones_attached = 0;
+ int zone_already_attached;
if (cal == NULL) {
CtdlLogPrintf(CTDL_ERR, "ERROR: trying to reply to NULL event?\n");
/* If this is a VCALENDAR component, look for a VEVENT subcomponent. */
if (icalcomponent_isa(cal) == ICAL_VCALENDAR_COMPONENT) {
- ical_send_out_invitations(
+ ical_send_out_invitations(top_level_cal,
icalcomponent_get_first_component(
cal, ICAL_VEVENT_COMPONENT
)
/* Encapsulate the VEVENT component into a complete VCALENDAR */
encaps = icalcomponent_new_vcalendar();
if (encaps == NULL) {
- CtdlLogPrintf(CTDL_DEBUG, "Error at %s:%d - could not allocate component!\n",
- __FILE__, __LINE__);
+ CtdlLogPrintf(CTDL_DEBUG, "ERROR: could not allocate component!\n");
icalcomponent_free(the_request);
return;
}
/* Set the method to REQUEST */
icalcomponent_set_method(encaps, ICAL_METHOD_REQUEST);
- /* Now make sure all of the DTSTART and DTEND properties are UTC. */
- ical_dezonify(the_request);
+ /* Look for properties containing timezone parameters, to see if we need to attach VTIMEZONEs */
+ for (p = icalcomponent_get_first_property(the_request, ICAL_ANY_PROPERTY);
+ p != NULL;
+ p = icalcomponent_get_next_property(the_request, ICAL_ANY_PROPERTY))
+ {
+ if ( (icalproperty_isa(p) == ICAL_COMPLETED_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_CREATED_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_DATEMAX_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_DATEMIN_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_DTEND_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_DTSTAMP_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_DTSTART_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_DUE_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_EXDATE_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_LASTMODIFIED_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_MAXDATE_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_MINDATE_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_RECURRENCEID_PROPERTY)
+ ) {
+ t = icalproperty_get_dtstart(p); // it's safe to use dtstart for all of them
+ CtdlLogPrintf(CTDL_DEBUG, "Found an icaltimetype: %s\n",
+ icaltime_as_ical_string(t)
+ );
+
+ /* First see if there's a timezone attached to the data structure itself */
+ if (icaltime_is_utc(t)) {
+ z = icaltimezone_get_utc_timezone();
+ }
+ else {
+ z = icaltime_get_timezone(t);
+ }
+ if (z) CtdlLogPrintf(CTDL_DEBUG, "Timezone is present in data structure\n");
+
+ /* If not, try to determine the tzid from the parameter using attached zones */
+ if (!z) {
+ z = icalcomponent_get_timezone(top_level_cal,
+ icalparameter_get_tzid(
+ icalproperty_get_first_parameter(p, ICAL_TZID_PARAMETER)
+ )
+ );
+ if (z) CtdlLogPrintf(CTDL_DEBUG, "Timezone was found in attached zones\n");
+ }
- /* Here we go: put the VEVENT into the VCALENDAR. We now no longer
+ /* Still no good? Try our internal database */
+ if (!z) {
+ z = icaltimezone_get_builtin_timezone_from_tzid(
+ icalparameter_get_tzid(
+ icalproperty_get_first_parameter(p, ICAL_TZID_PARAMETER)
+ )
+ );
+ if (z) CtdlLogPrintf(CTDL_DEBUG, "Timezone was found in internal db\n");
+ }
+
+ if (z) {
+ CtdlLogPrintf(CTDL_DEBUG, "Have valid timezone, need to attach it.\n");
+
+ zone_already_attached = 0;
+ for (i=0; i<5; ++i) {
+ if (z == attached_zones[i]) {
+ ++zone_already_attached;
+ CtdlLogPrintf(CTDL_DEBUG, "zone already attached!!\n");
+ }
+ }
+ if ((!zone_already_attached) && (num_zones_attached < 5)) {
+ CtdlLogPrintf(CTDL_DEBUG, "attach zone %d\n", num_zones_attached);
+ attached_zones[num_zones_attached++] = z;
+ }
+
+ icalproperty_set_parameter(p,
+ icalparameter_new_tzid(icaltimezone_get_tzid(z))
+ );
+ }
+ }
+ }
+
+ /* Encapsulate any timezones we need */
+ if (num_zones_attached > 0) for (i=0; i<num_zones_attached; ++i) {
+ icalcomponent *zc;
+ zc = icalcomponent_new_clone(icaltimezone_get_component(attached_zones[i]));
+ icalcomponent_add_component(encaps, zc);
+ }
+
+ /* Here we go: encapsulate the VEVENT into the VCALENDAR. We now no longer
* are responsible for "the_request"'s memory -- it will be freed
* when we free "encaps".
*/
icalcomponent_free(encaps); /* Don't need this anymore. */
if (serialized_request == NULL) return;
+ CtdlLogPrintf(CTDL_DEBUG, "SENDING INVITATIONS:\n%s\n", serialized_request);
+
reqsize = strlen(serialized_request) + SIZ;
request_message_text = malloc(reqsize);
if (request_message_text != NULL) {
* and the user saving it is the organizer. If so, send out invitations
* to any listed attendees.
*
+ * This function is recursive. The caller can simply supply the same object
+ * as both arguments. When it recurses it will alter the second argument
+ * while holding on to the top level object. This allows us to go back and
+ * grab things like time zones which might be attached.
+ *
*/
-void ical_saving_vevent(icalcomponent *cal) {
+void ical_saving_vevent(icalcomponent *top_level_cal, icalcomponent *cal) {
icalcomponent *c;
icalproperty *organizer = NULL;
char organizer_string[SIZ];
* organizer, then send out invitations.
*/
if (CtdlIsMe(organizer_string, sizeof organizer_string)) {
- ical_send_out_invitations(cal);
+ ical_send_out_invitations(top_level_cal, cal);
}
}
}
(c != NULL);
c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)) {
/* Recursively process subcomponent */
- ical_saving_vevent(c);
+ ical_saving_vevent(top_level_cal, c);
}
}
|| (!strcasecmp(cbtype, "application/ics")) ) {
cal = icalcomponent_new_from_string(content);
if (cal != NULL) {
- ical_saving_vevent(cal);
+ ical_saving_vevent(cal, cal);
icalcomponent_free(cal);
}
}
return;
}
- ical_dezonify(cal);
ical_fixed_output_backend(cal, 0);
/* Free the memory we obtained from libical's constructor */
/* Tell libical to return errors instead of aborting if it gets bad data */
icalerror_errors_are_fatal = 0;
+ /* Use our own application prefix in tzid's generated from system tzdata */
+ icaltimezone_set_tzid_prefix("/citadel.org/");
+
/* Initialize our hook functions */
CtdlRegisterMessageHook(ical_obj_beforesave, EVT_BEFORESAVE);
CtdlRegisterMessageHook(ical_obj_aftersave, EVT_AFTERSAVE);
/* return our Subversion id for the Log */
return "$Id$";
}
-