4 * This module implements iCalendar object processing and the Calendar>
5 * room on a Citadel/UX server. It handles iCalendar objects using the
6 * iTIP protocol. See RFCs 2445 and 2446.
10 #define PRODID "-//Citadel//NONSGML Citadel Calendar//EN"
14 #include <sys/types.h>
23 #include "citserver.h"
24 #include "sysdep_decls.h"
27 #include "serv_extensions.h"
32 #include "mime_parser.h"
33 #include "serv_calendar.h"
35 #ifdef CITADEL_WITH_CALENDAR_SERVICE
38 #include "ical_dezonify.h"
40 struct ical_respond_data {
41 char desired_partnum[SIZ];
47 * Utility function to create a new VCALENDAR component with some of the
48 * required fields already set the way we like them.
50 icalcomponent *icalcomponent_new_citadel_vcalendar(void) {
51 icalcomponent *encaps;
53 encaps = icalcomponent_new_vcalendar();
55 lprintf(CTDL_CRIT, "Error at %s:%d - could not allocate component!\n",
60 /* Set the Product ID */
61 icalcomponent_add_property(encaps, icalproperty_new_prodid(PRODID));
63 /* Set the Version Number */
64 icalcomponent_add_property(encaps, icalproperty_new_version("2.0"));
71 * Utility function to encapsulate a subcomponent into a full VCALENDAR
73 icalcomponent *ical_encapsulate_subcomponent(icalcomponent *subcomp) {
74 icalcomponent *encaps;
76 /* If we're already looking at a full VCALENDAR component,
77 * don't bother ... just return itself.
79 if (icalcomponent_isa(subcomp) == ICAL_VCALENDAR_COMPONENT) {
83 /* Encapsulate the VEVENT component into a complete VCALENDAR */
84 encaps = icalcomponent_new_citadel_vcalendar();
85 if (encaps == NULL) return NULL;
87 /* Encapsulate the subcomponent inside */
88 icalcomponent_add_component(encaps, subcomp);
90 /* Convert all timestamps to UTC so we don't have to deal with
91 * stupid VTIMEZONE crap.
93 ical_dezonify(encaps);
95 /* Return the object we just created. */
103 * Write a calendar object into the specified user's calendar room.
107 void ical_write_to_cal(struct ctdluser *u, icalcomponent *cal) {
111 icalcomponent *encaps;
113 if (cal == NULL) return;
115 /* If the supplied object is a subcomponent, encapsulate it in
116 * a full VCALENDAR component, and save that instead.
118 if (icalcomponent_isa(cal) != ICAL_VCALENDAR_COMPONENT) {
119 encaps = ical_encapsulate_subcomponent(
120 icalcomponent_new_clone(cal)
122 ical_write_to_cal(u, encaps);
123 icalcomponent_free(encaps);
127 strcpy(temp, tmpnam(NULL));
128 ser = icalcomponent_as_ical_string(cal);
129 if (ser == NULL) return;
131 /* Make a temp file out of it */
132 fp = fopen(temp, "w");
133 if (fp == NULL) return;
134 fwrite(ser, strlen(ser), 1, fp);
137 /* This handy API function does all the work for us.
139 CtdlWriteObject(USERCALENDARROOM, /* which room */
140 "text/calendar", /* MIME type */
141 temp, /* temp file */
144 0, /* don't delete others of this type */
152 * Add a calendar object to the user's calendar
154 * ok because it uses ical_write_to_cal()
156 void ical_add(icalcomponent *cal, int recursion_level) {
160 * The VEVENT subcomponent is the one we're interested in saving.
162 if (icalcomponent_isa(cal) == ICAL_VEVENT_COMPONENT) {
164 ical_write_to_cal(&CC->user, cal);
168 /* If the component has subcomponents, recurse through them. */
169 for (c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
171 c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)) {
172 /* Recursively process subcomponent */
173 ical_add(c, recursion_level+1);
181 * Send a reply to a meeting invitation.
183 * 'request' is the invitation to reply to.
184 * 'action' is the string "accept" or "decline".
186 * (Sorry about this being more than 80 columns ... there was just
187 * no easy way to break it down sensibly.)
191 void ical_send_a_reply(icalcomponent *request, char *action) {
192 icalcomponent *the_reply = NULL;
193 icalcomponent *vevent = NULL;
194 icalproperty *attendee = NULL;
195 char attendee_string[SIZ];
196 icalproperty *organizer = NULL;
197 char organizer_string[SIZ];
198 icalproperty *summary = NULL;
199 char summary_string[SIZ];
200 icalproperty *me_attend = NULL;
201 struct recptypes *recp = NULL;
202 icalparameter *partstat = NULL;
203 char *serialized_reply = NULL;
204 char *reply_message_text = NULL;
205 struct CtdlMessage *msg = NULL;
206 struct recptypes *valid = NULL;
208 strcpy(organizer_string, "");
209 strcpy(summary_string, "Calendar item");
211 if (request == NULL) {
212 lprintf(CTDL_ERR, "ERROR: trying to reply to NULL event?\n");
216 the_reply = icalcomponent_new_clone(request);
217 if (the_reply == NULL) {
218 lprintf(CTDL_ERR, "ERROR: cannot clone request\n");
222 /* Change the method from REQUEST to REPLY */
223 icalcomponent_set_method(the_reply, ICAL_METHOD_REPLY);
225 vevent = icalcomponent_get_first_component(the_reply, ICAL_VEVENT_COMPONENT);
226 if (vevent != NULL) {
227 /* Hunt for attendees, removing ones that aren't us.
228 * (Actually, remove them all, cloning our own one so we can
229 * re-insert it later)
231 while (attendee = icalcomponent_get_first_property(vevent,
232 ICAL_ATTENDEE_PROPERTY), (attendee != NULL)
234 if (icalproperty_get_attendee(attendee)) {
235 strcpy(attendee_string,
236 icalproperty_get_attendee(attendee) );
237 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
238 strcpy(attendee_string, &attendee_string[7]);
239 striplt(attendee_string);
240 recp = validate_recipients(attendee_string);
242 if (!strcasecmp(recp->recp_local, CC->user.fullname)) {
243 if (me_attend) icalproperty_free(me_attend);
244 me_attend = icalproperty_new_clone(attendee);
251 icalcomponent_remove_property(vevent, attendee);
252 icalproperty_free(attendee);
255 /* We found our own address in the attendee list. */
257 /* Change the partstat from NEEDS-ACTION to ACCEPT or DECLINE */
258 icalproperty_remove_parameter(me_attend, ICAL_PARTSTAT_PARAMETER);
260 if (!strcasecmp(action, "accept")) {
261 partstat = icalparameter_new_partstat(ICAL_PARTSTAT_ACCEPTED);
263 else if (!strcasecmp(action, "decline")) {
264 partstat = icalparameter_new_partstat(ICAL_PARTSTAT_DECLINED);
266 else if (!strcasecmp(action, "tentative")) {
267 partstat = icalparameter_new_partstat(ICAL_PARTSTAT_TENTATIVE);
270 if (partstat) icalproperty_add_parameter(me_attend, partstat);
272 /* Now insert it back into the vevent. */
273 icalcomponent_add_property(vevent, me_attend);
276 /* Figure out who to send this thing to */
277 organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
278 if (organizer != NULL) {
279 if (icalproperty_get_organizer(organizer)) {
280 strcpy(organizer_string,
281 icalproperty_get_organizer(organizer) );
284 if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
285 strcpy(organizer_string, &organizer_string[7]);
286 striplt(organizer_string);
288 strcpy(organizer_string, "");
291 /* Extract the summary string -- we'll use it as the
292 * message subject for the reply
294 summary = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
295 if (summary != NULL) {
296 if (icalproperty_get_summary(summary)) {
297 strcpy(summary_string,
298 icalproperty_get_summary(summary) );
304 /* Now generate the reply message and send it out. */
305 serialized_reply = strdup(icalcomponent_as_ical_string(the_reply));
306 icalcomponent_free(the_reply); /* don't need this anymore */
307 if (serialized_reply == NULL) return;
309 reply_message_text = malloc(strlen(serialized_reply) + SIZ);
310 if (reply_message_text != NULL) {
311 sprintf(reply_message_text,
312 "Content-type: text/calendar\r\n\r\n%s\r\n",
316 msg = CtdlMakeMessage(&CC->user, organizer_string,
317 CC->room.QRname, 0, FMT_RFC822,
319 summary_string, /* Use summary for subject */
323 valid = validate_recipients(organizer_string);
324 CtdlSubmitMsg(msg, valid, "");
325 CtdlFreeMessage(msg);
328 free(serialized_reply);
334 * Callback function for mime parser that hunts for calendar content types
335 * and turns them into calendar objects
337 void ical_locate_part(char *name, char *filename, char *partnum, char *disp,
338 void *content, char *cbtype, size_t length, char *encoding,
341 struct ical_respond_data *ird = NULL;
343 ird = (struct ical_respond_data *) cbuserdata;
345 /* desired_partnum can be set to "_HUNT_" to have it just look for
346 * the first part with a content type of text/calendar. Otherwise
347 * we have to only process the right one.
349 if (strcasecmp(ird->desired_partnum, "_HUNT_")) {
350 if (strcasecmp(partnum, ird->desired_partnum)) {
355 if (strcasecmp(cbtype, "text/calendar")) {
359 if (ird->cal != NULL) {
360 icalcomponent_free(ird->cal);
364 ird->cal = icalcomponent_new_from_string(content);
365 if (ird->cal != NULL) {
366 ical_dezonify(ird->cal);
372 * Respond to a meeting request.
374 void ical_respond(long msgnum, char *partnum, char *action) {
375 struct CtdlMessage *msg;
376 struct ical_respond_data ird;
379 (strcasecmp(action, "accept"))
380 && (strcasecmp(action, "decline"))
382 cprintf("%d Action must be 'accept' or 'decline'\n",
383 ERROR + ILLEGAL_VALUE
388 msg = CtdlFetchMessage(msgnum);
390 cprintf("%d Message %ld not found.\n",
391 ERROR + ILLEGAL_VALUE,
397 memset(&ird, 0, sizeof ird);
398 strcpy(ird.desired_partnum, partnum);
399 mime_parser(msg->cm_fields['M'],
401 *ical_locate_part, /* callback function */
403 (void *) &ird, /* user data */
407 /* We're done with the incoming message, because we now have a
408 * calendar object in memory.
410 CtdlFreeMessage(msg);
413 * Here is the real meat of this function. Handle the event.
415 if (ird.cal != NULL) {
416 /* Save this in the user's calendar if necessary */
417 if (!strcasecmp(action, "accept")) {
418 ical_add(ird.cal, 0);
421 /* Send a reply if necessary */
422 if (icalcomponent_get_method(ird.cal) == ICAL_METHOD_REQUEST) {
423 ical_send_a_reply(ird.cal, action);
426 /* Now that we've processed this message, we don't need it
427 * anymore. So delete it.
429 CtdlDeleteMessages(CC->room.QRname, msgnum, "");
431 /* Free the memory we allocated and return a response. */
432 icalcomponent_free(ird.cal);
434 cprintf("%d ok\n", CIT_OK);
438 cprintf("%d No calendar object found\n", ERROR + ROOM_NOT_FOUND);
442 /* should never get here */
447 * Figure out the UID of the calendar event being referred to in a
448 * REPLY object. This function is recursive.
450 void ical_learn_uid_of_reply(char *uidbuf, icalcomponent *cal) {
451 icalcomponent *subcomponent;
454 /* If this object is a REPLY, then extract the UID. */
455 if (icalcomponent_isa(cal) == ICAL_VEVENT_COMPONENT) {
456 p = icalcomponent_get_first_property(cal, ICAL_UID_PROPERTY);
458 strcpy(uidbuf, icalproperty_get_comment(p));
462 /* Otherwise, recurse through any VEVENT subcomponents. We do NOT want the
463 * UID of the reply; we want the UID of the invitation being replied to.
465 for (subcomponent = icalcomponent_get_first_component(cal, ICAL_VEVENT_COMPONENT);
466 subcomponent != NULL;
467 subcomponent = icalcomponent_get_next_component(cal, ICAL_VEVENT_COMPONENT) ) {
468 ical_learn_uid_of_reply(uidbuf, subcomponent);
474 * ical_update_my_calendar_with_reply() refers to this callback function; when we
475 * locate the message containing the calendar event we're replying to, this function
476 * gets called. It basically just sticks the message number in a supplied buffer.
478 void ical_hunt_for_event_to_update(long msgnum, void *data) {
481 msgnumptr = (long *) data;
486 struct original_event_container {
491 * Callback function for mime parser that hunts for calendar content types
492 * and turns them into calendar objects (called by ical_update_my_calendar_with_reply()
493 * to fetch the object being updated)
495 void ical_locate_original_event(char *name, char *filename, char *partnum, char *disp,
496 void *content, char *cbtype, size_t length, char *encoding,
499 struct original_event_container *oec = NULL;
501 if (strcasecmp(cbtype, "text/calendar")) {
504 oec = (struct original_event_container *) cbuserdata;
505 if (oec->c != NULL) {
506 icalcomponent_free(oec->c);
508 oec->c = icalcomponent_new_from_string(content);
513 * Merge updated attendee information from a REPLY into an existing event.
515 void ical_merge_attendee_reply(icalcomponent *event, icalcomponent *reply) {
517 icalproperty *e_attendee, *r_attendee;
519 /* First things first. If we're not looking at a VEVENT component,
520 * recurse through subcomponents until we find one.
522 if (icalcomponent_isa(event) != ICAL_VEVENT_COMPONENT) {
523 for (c = icalcomponent_get_first_component(event, ICAL_VEVENT_COMPONENT);
525 c = icalcomponent_get_next_component(event, ICAL_VEVENT_COMPONENT) ) {
526 ical_merge_attendee_reply(c, reply);
531 /* Now do the same thing with the reply.
533 if (icalcomponent_isa(reply) != ICAL_VEVENT_COMPONENT) {
534 for (c = icalcomponent_get_first_component(reply, ICAL_VEVENT_COMPONENT);
536 c = icalcomponent_get_next_component(reply, ICAL_VEVENT_COMPONENT) ) {
537 ical_merge_attendee_reply(event, c);
542 /* Clone the reply, because we're going to rip its guts out. */
543 reply = icalcomponent_new_clone(reply);
545 /* At this point we're looking at the correct subcomponents.
546 * Iterate through the attendees looking for a match.
549 for (e_attendee = icalcomponent_get_first_property(event, ICAL_ATTENDEE_PROPERTY);
551 e_attendee = icalcomponent_get_next_property(event, ICAL_ATTENDEE_PROPERTY)) {
553 for (r_attendee = icalcomponent_get_first_property(reply, ICAL_ATTENDEE_PROPERTY);
555 r_attendee = icalcomponent_get_next_property(reply, ICAL_ATTENDEE_PROPERTY)) {
557 /* Check to see if these two attendees match...
560 icalproperty_get_attendee(e_attendee),
561 icalproperty_get_attendee(r_attendee)
563 /* ...and if they do, remove the attendee from the event
564 * and replace it with the attendee from the reply. (The
565 * reply's copy will have the same address, but an updated
569 icalcomponent_remove_property(event, e_attendee);
571 icalproperty_free(e_attendee);
573 icalcomponent_remove_property(reply, r_attendee);
575 icalcomponent_add_property(event, r_attendee);
578 /* Since we diddled both sets of attendees, we have to start
579 * the iteration over again. This will not create an infinite
580 * loop because we removed the attendee from the reply. (That's
581 * why we cloned the reply, and that's what we mean by "ripping
590 /* Free the *clone* of the reply. */
591 icalcomponent_free(reply);
598 * Handle an incoming RSVP (object with method==ICAL_METHOD_REPLY) for a
599 * calendar event. The object has already been deserialized for us; all
600 * we have to do here is hunt for the event in our calendar, merge in the
601 * updated attendee status, and save it again.
603 * This function returns 0 on success, 1 if the event was not found in the
604 * user's calendar, or 2 if an internal error occurred.
606 int ical_update_my_calendar_with_reply(icalcomponent *cal) {
608 char hold_rm[ROOMNAMELEN];
609 long msgnum_being_replaced = 0;
610 struct CtdlMessage *template = NULL;
611 struct CtdlMessage *msg;
612 struct original_event_container oec;
613 icalcomponent *original_event;
614 char *serialized_event = NULL;
615 char roomname[ROOMNAMELEN];
616 char *message_text = NULL;
618 /* Figure out just what event it is we're dealing with */
619 strcpy(uid, "--==<< InVaLiD uId >>==--");
620 ical_learn_uid_of_reply(uid, cal);
621 lprintf(CTDL_DEBUG, "UID of event being replied to is <%s>\n", uid);
623 strcpy(hold_rm, CC->room.QRname); /* save current room */
625 if (getroom(&CC->room, USERCALENDARROOM) != 0) {
626 getroom(&CC->room, hold_rm);
627 lprintf(CTDL_CRIT, "cannot get user calendar room\n");
632 * Pound through the user's calendar looking for a message with
633 * the Citadel EUID set to the value we're looking for. Since
634 * Citadel always sets the message EUID to the vCalendar UID of
635 * the event, this will work.
637 template = (struct CtdlMessage *)
638 malloc(sizeof(struct CtdlMessage));
639 memset(template, 0, sizeof(struct CtdlMessage));
640 template->cm_fields['E'] = strdup(uid);
641 CtdlForEachMessage(MSGS_ALL, 0, "text/calendar",
642 template, ical_hunt_for_event_to_update, &msgnum_being_replaced);
643 CtdlFreeMessage(template);
644 getroom(&CC->room, hold_rm); /* return to saved room */
646 lprintf(CTDL_DEBUG, "msgnum_being_replaced == %ld\n", msgnum_being_replaced);
647 if (msgnum_being_replaced == 0) {
648 return(1); /* no calendar event found */
651 /* Now we know the ID of the message containing the event being updated.
652 * We don't actually have to delete it; that'll get taken care of by the
653 * server when we save another event with the same UID. This just gives
654 * us the ability to load the event into memory so we can diddle the
657 msg = CtdlFetchMessage(msgnum_being_replaced);
659 return(2); /* internal error */
662 mime_parser(msg->cm_fields['M'],
664 *ical_locate_original_event, /* callback function */
666 &oec, /* user data */
669 CtdlFreeMessage(msg);
671 original_event = oec.c;
672 if (original_event == NULL) {
673 lprintf(CTDL_ERR, "ERROR: Original_component is NULL.\n");
677 /* Merge the attendee's updated status into the event */
678 ical_merge_attendee_reply(original_event, cal);
681 serialized_event = strdup(icalcomponent_as_ical_string(original_event));
682 icalcomponent_free(original_event); /* Don't need this anymore. */
683 if (serialized_event == NULL) return(2);
685 MailboxName(roomname, sizeof roomname, &CC->user, USERCALENDARROOM);
687 message_text = malloc(strlen(serialized_event) + SIZ);
688 if (message_text != NULL) {
689 sprintf(message_text,
690 "Content-type: text/calendar\r\n\r\n%s\r\n",
694 msg = CtdlMakeMessage(&CC->user,
695 "", /* No recipient */
703 CIT_ICAL->avoid_sending_invitations = 1;
704 CtdlSubmitMsg(msg, NULL, roomname);
705 CtdlFreeMessage(msg);
706 CIT_ICAL->avoid_sending_invitations = 0;
709 free(serialized_event);
715 * Handle an incoming RSVP for an event. (This is the server subcommand part; it
716 * simply extracts the calendar object from the message, deserializes it, and
717 * passes it up to ical_update_my_calendar_with_reply() for processing.
719 void ical_handle_rsvp(long msgnum, char *partnum, char *action) {
720 struct CtdlMessage *msg;
721 struct ical_respond_data ird;
725 (strcasecmp(action, "update"))
726 && (strcasecmp(action, "ignore"))
728 cprintf("%d Action must be 'update' or 'ignore'\n",
729 ERROR + ILLEGAL_VALUE
734 msg = CtdlFetchMessage(msgnum);
736 cprintf("%d Message %ld not found.\n",
737 ERROR + ILLEGAL_VALUE,
743 memset(&ird, 0, sizeof ird);
744 strcpy(ird.desired_partnum, partnum);
745 mime_parser(msg->cm_fields['M'],
747 *ical_locate_part, /* callback function */
749 (void *) &ird, /* user data */
753 /* We're done with the incoming message, because we now have a
754 * calendar object in memory.
756 CtdlFreeMessage(msg);
759 * Here is the real meat of this function. Handle the event.
761 if (ird.cal != NULL) {
762 /* Update the user's calendar if necessary */
763 if (!strcasecmp(action, "update")) {
764 ret = ical_update_my_calendar_with_reply(ird.cal);
766 cprintf("%d Your calendar has been updated with this reply.\n",
770 cprintf("%d This event does not exist in your calendar.\n",
771 ERROR + FILE_NOT_FOUND);
774 cprintf("%d An internal error occurred.\n",
775 ERROR + INTERNAL_ERROR);
779 cprintf("%d This reply has been ignored.\n", CIT_OK);
782 /* Now that we've processed this message, we don't need it
783 * anymore. So delete it. (Maybe make this optional?)
785 CtdlDeleteMessages(CC->room.QRname, msgnum, "");
787 /* Free the memory we allocated and return a response. */
788 icalcomponent_free(ird.cal);
793 cprintf("%d No calendar object found\n", ERROR + ROOM_NOT_FOUND);
797 /* should never get here */
802 * Search for a property in both the top level and in a VEVENT subcomponent
804 icalproperty *ical_ctdl_get_subprop(
806 icalproperty_kind which_prop
811 p = icalcomponent_get_first_property(cal, which_prop);
813 c = icalcomponent_get_first_component(cal,
814 ICAL_VEVENT_COMPONENT);
816 p = icalcomponent_get_first_property(c, which_prop);
824 * Check to see if two events overlap. Returns nonzero if they do.
825 * (This function is used in both Citadel and WebCit. If you change it in
826 * one place, change it in the other. Better yet, put it in a library.)
828 int ical_ctdl_is_overlap(
829 struct icaltimetype t1start,
830 struct icaltimetype t1end,
831 struct icaltimetype t2start,
832 struct icaltimetype t2end
835 if (icaltime_is_null_time(t1start)) return(0);
836 if (icaltime_is_null_time(t2start)) return(0);
838 /* First, check for all-day events */
839 if (t1start.is_date) {
840 if (!icaltime_compare_date_only(t1start, t2start)) {
843 if (!icaltime_is_null_time(t2end)) {
844 if (!icaltime_compare_date_only(t1start, t2end)) {
850 if (t2start.is_date) {
851 if (!icaltime_compare_date_only(t2start, t1start)) {
854 if (!icaltime_is_null_time(t1end)) {
855 if (!icaltime_compare_date_only(t2start, t1end)) {
861 /* Now check for overlaps using date *and* time. */
863 /* First, bail out if either event 1 or event 2 is missing end time. */
864 if (icaltime_is_null_time(t1end)) return(0);
865 if (icaltime_is_null_time(t2end)) return(0);
867 /* If event 1 ends before event 2 starts, we're in the clear. */
868 if (icaltime_compare(t1end, t2start) <= 0) return(0);
870 /* If event 2 ends before event 1 starts, we're also ok. */
871 if (icaltime_compare(t2end, t1start) <= 0) return(0);
873 /* Otherwise, they overlap. */
880 * Backend for ical_hunt_for_conflicts()
882 void ical_hunt_for_conflicts_backend(long msgnum, void *data) {
884 struct CtdlMessage *msg;
885 struct ical_respond_data ird;
886 struct icaltimetype t1start, t1end, t2start, t2end;
888 char conflict_event_uid[SIZ];
889 char conflict_event_summary[SIZ];
890 char compare_uid[SIZ];
892 cal = (icalcomponent *)data;
893 strcpy(compare_uid, "");
894 strcpy(conflict_event_uid, "");
895 strcpy(conflict_event_summary, "");
897 msg = CtdlFetchMessage(msgnum);
898 if (msg == NULL) return;
899 memset(&ird, 0, sizeof ird);
900 strcpy(ird.desired_partnum, "_HUNT_");
901 mime_parser(msg->cm_fields['M'],
903 *ical_locate_part, /* callback function */
905 (void *) &ird, /* user data */
908 CtdlFreeMessage(msg);
910 if (ird.cal == NULL) return;
912 t1start = icaltime_null_time();
913 t1end = icaltime_null_time();
914 t2start = icaltime_null_time();
915 t1end = icaltime_null_time();
917 /* Now compare cal to ird.cal */
918 p = ical_ctdl_get_subprop(ird.cal, ICAL_DTSTART_PROPERTY);
919 if (p == NULL) return;
920 if (p != NULL) t2start = icalproperty_get_dtstart(p);
922 p = ical_ctdl_get_subprop(ird.cal, ICAL_DTEND_PROPERTY);
923 if (p != NULL) t2end = icalproperty_get_dtend(p);
925 p = ical_ctdl_get_subprop(cal, ICAL_DTSTART_PROPERTY);
926 if (p == NULL) return;
927 if (p != NULL) t1start = icalproperty_get_dtstart(p);
929 p = ical_ctdl_get_subprop(cal, ICAL_DTEND_PROPERTY);
930 if (p != NULL) t1end = icalproperty_get_dtend(p);
932 p = ical_ctdl_get_subprop(cal, ICAL_UID_PROPERTY);
934 strcpy(compare_uid, icalproperty_get_comment(p));
937 p = ical_ctdl_get_subprop(ird.cal, ICAL_UID_PROPERTY);
939 strcpy(conflict_event_uid, icalproperty_get_comment(p));
942 p = ical_ctdl_get_subprop(ird.cal, ICAL_SUMMARY_PROPERTY);
944 strcpy(conflict_event_summary, icalproperty_get_comment(p));
947 icalcomponent_free(ird.cal);
949 if (ical_ctdl_is_overlap(t1start, t1end, t2start, t2end)) {
950 cprintf("%ld||%s|%s|%d|\n",
953 conflict_event_summary,
954 ( ((strlen(compare_uid)>0)
955 &&(!strcasecmp(compare_uid,
956 conflict_event_uid))) ? 1 : 0
965 * Phase 2 of "hunt for conflicts" operation.
966 * At this point we have a calendar object which represents the VEVENT that
967 * we're considering adding to the calendar. Now hunt through the user's
968 * calendar room, and output zero or more existing VEVENTs which conflict
971 void ical_hunt_for_conflicts(icalcomponent *cal) {
972 char hold_rm[ROOMNAMELEN];
974 strcpy(hold_rm, CC->room.QRname); /* save current room */
976 if (getroom(&CC->room, USERCALENDARROOM) != 0) {
977 getroom(&CC->room, hold_rm);
978 cprintf("%d You do not have a calendar.\n", ERROR + ROOM_NOT_FOUND);
982 cprintf("%d Conflicting events:\n", LISTING_FOLLOWS);
984 CtdlForEachMessage(MSGS_ALL, 0, "text/calendar",
986 ical_hunt_for_conflicts_backend,
991 getroom(&CC->room, hold_rm); /* return to saved room */
998 * Hunt for conflicts (Phase 1 -- retrieve the object and call Phase 2)
1000 void ical_conflicts(long msgnum, char *partnum) {
1001 struct CtdlMessage *msg;
1002 struct ical_respond_data ird;
1004 msg = CtdlFetchMessage(msgnum);
1006 cprintf("%d Message %ld not found.\n",
1007 ERROR + ILLEGAL_VALUE,
1013 memset(&ird, 0, sizeof ird);
1014 strcpy(ird.desired_partnum, partnum);
1015 mime_parser(msg->cm_fields['M'],
1017 *ical_locate_part, /* callback function */
1019 (void *) &ird, /* user data */
1023 CtdlFreeMessage(msg);
1025 if (ird.cal != NULL) {
1026 ical_hunt_for_conflicts(ird.cal);
1027 icalcomponent_free(ird.cal);
1031 cprintf("%d No calendar object found\n", ERROR + ROOM_NOT_FOUND);
1035 /* should never get here */
1041 * Look for busy time in a VEVENT and add it to the supplied VFREEBUSY.
1043 void ical_add_to_freebusy(icalcomponent *fb, icalcomponent *cal) {
1046 struct icalperiodtype my_period;
1048 if (cal == NULL) return;
1049 my_period = icalperiodtype_null_period();
1051 if (icalcomponent_isa(cal) != ICAL_VEVENT_COMPONENT) {
1052 ical_add_to_freebusy(fb,
1053 icalcomponent_get_first_component(
1054 cal, ICAL_VEVENT_COMPONENT
1062 /* If this event is not opaque, the user isn't publishing it as
1063 * busy time, so don't bother doing anything else.
1065 p = icalcomponent_get_first_property(cal, ICAL_TRANSP_PROPERTY);
1067 v = icalproperty_get_value(p);
1069 if (icalvalue_get_transp(v) != ICAL_TRANSP_OPAQUE) {
1075 /* Convert the DTSTART and DTEND properties to an icalperiod. */
1076 p = icalcomponent_get_first_property(cal, ICAL_DTSTART_PROPERTY);
1078 my_period.start = icalproperty_get_dtstart(p);
1081 p = icalcomponent_get_first_property(cal, ICAL_DTEND_PROPERTY);
1083 my_period.end = icalproperty_get_dtstart(p);
1087 icalcomponent_add_property(fb,
1088 icalproperty_new_freebusy(my_period)
1096 * Backend for ical_freebusy()
1098 * This function simply loads the messages in the user's calendar room,
1099 * which contain VEVENTs, then strips them of all non-freebusy data, and
1100 * adds them to the supplied VCALENDAR.
1103 void ical_freebusy_backend(long msgnum, void *data) {
1105 struct CtdlMessage *msg;
1106 struct ical_respond_data ird;
1108 cal = (icalcomponent *)data;
1110 msg = CtdlFetchMessage(msgnum);
1111 if (msg == NULL) return;
1112 memset(&ird, 0, sizeof ird);
1113 strcpy(ird.desired_partnum, "_HUNT_");
1114 mime_parser(msg->cm_fields['M'],
1116 *ical_locate_part, /* callback function */
1118 (void *) &ird, /* user data */
1121 CtdlFreeMessage(msg);
1123 if (ird.cal == NULL) return;
1125 ical_add_to_freebusy(cal, ird.cal);
1127 /* Now free the memory. */
1128 icalcomponent_free(ird.cal);
1134 * Grab another user's free/busy times
1136 void ical_freebusy(char *who) {
1137 struct ctdluser usbuf;
1138 char calendar_room_name[ROOMNAMELEN];
1139 char hold_rm[ROOMNAMELEN];
1140 char *serialized_request = NULL;
1141 icalcomponent *encaps = NULL;
1142 icalcomponent *fb = NULL;
1144 if (getuser(&usbuf, who) != 0) {
1145 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1149 MailboxName(calendar_room_name, sizeof calendar_room_name,
1150 &usbuf, USERCALENDARROOM);
1152 strcpy(hold_rm, CC->room.QRname); /* save current room */
1154 if (getroom(&CC->room, calendar_room_name) != 0) {
1155 cprintf("%d Cannot open calendar\n", ERROR + ROOM_NOT_FOUND);
1156 getroom(&CC->room, hold_rm);
1160 /* Create a VFREEBUSY subcomponent */
1161 lprintf(CTDL_DEBUG, "Creating VFREEBUSY component\n");
1162 fb = icalcomponent_new_vfreebusy();
1164 cprintf("%d Internal error: cannot allocate memory.\n",
1165 ERROR + INTERNAL_ERROR);
1166 icalcomponent_free(encaps);
1167 getroom(&CC->room, hold_rm);
1171 lprintf(CTDL_DEBUG, "Adding busy time from events\n");
1172 CtdlForEachMessage(MSGS_ALL, 0, "text/calendar",
1173 NULL, ical_freebusy_backend, (void *)fb
1176 /* Set the method to PUBLISH */
1177 icalcomponent_set_method(fb, ICAL_METHOD_PUBLISH);
1179 /* Set the DTSTAMP to right now. */
1180 icalcomponent_set_dtstamp(fb, icaltime_from_timet(time(NULL), 0));
1182 /* FIXME we still need (at least) DTSTART, DTEND, and the user's
1183 * e-mail address as ORGANIZER.
1186 /* Put the freebusy component into the calendar component */
1187 lprintf(CTDL_DEBUG, "Encapsulating\n");
1188 encaps = ical_encapsulate_subcomponent(fb);
1189 if (encaps == NULL) {
1190 icalcomponent_free(fb);
1191 cprintf("%d Internal error: cannot allocate memory.\n",
1192 ERROR + INTERNAL_ERROR);
1193 getroom(&CC->room, hold_rm);
1197 /* Set the method to PUBLISH */
1198 lprintf(CTDL_DEBUG, "Setting method\n");
1199 icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
1202 lprintf(CTDL_DEBUG, "Serializing\n");
1203 serialized_request = strdup(icalcomponent_as_ical_string(encaps));
1204 icalcomponent_free(encaps); /* Don't need this anymore. */
1206 cprintf("%d Here is the free/busy data:\n", LISTING_FOLLOWS);
1207 if (serialized_request != NULL) {
1208 client_write(serialized_request, strlen(serialized_request));
1209 free(serialized_request);
1213 /* Go back to the room from which we came... */
1214 getroom(&CC->room, hold_rm);
1221 * All Citadel calendar commands from the client come through here.
1223 void cmd_ical(char *argbuf)
1231 extract(subcmd, argbuf, 0);
1233 /* Allow "test" and "freebusy" subcommands without logging in. */
1235 if (!strcasecmp(subcmd, "test")) {
1236 cprintf("%d This server supports calendaring\n", CIT_OK);
1240 if (!strcasecmp(subcmd, "freebusy")) {
1241 extract(who, argbuf, 1);
1246 if (!strcasecmp(subcmd, "sgi")) {
1247 CIT_ICAL->server_generated_invitations =
1248 (extract_int(argbuf, 1) ? 1 : 0) ;
1250 CIT_OK, CIT_ICAL->server_generated_invitations);
1254 if (CtdlAccessCheck(ac_logged_in)) return;
1256 if (!strcasecmp(subcmd, "respond")) {
1257 msgnum = extract_long(argbuf, 1);
1258 extract(partnum, argbuf, 2);
1259 extract(action, argbuf, 3);
1260 ical_respond(msgnum, partnum, action);
1264 if (!strcasecmp(subcmd, "handle_rsvp")) {
1265 msgnum = extract_long(argbuf, 1);
1266 extract(partnum, argbuf, 2);
1267 extract(action, argbuf, 3);
1268 ical_handle_rsvp(msgnum, partnum, action);
1272 if (!strcasecmp(subcmd, "conflicts")) {
1273 msgnum = extract_long(argbuf, 1);
1274 extract(partnum, argbuf, 2);
1275 ical_conflicts(msgnum, partnum);
1279 cprintf("%d Invalid subcommand\n", ERROR + CMD_NOT_SUPPORTED);
1285 * We don't know if the calendar room exists so we just create it at login
1287 void ical_create_room(void)
1292 /* Create the calendar room if it doesn't already exist */
1293 create_room(USERCALENDARROOM, 4, "", 0, 1, 0);
1295 /* Set expiration policy to manual; otherwise objects will be lost! */
1296 if (lgetroom(&qr, USERCALENDARROOM)) {
1297 lprintf(CTDL_CRIT, "Couldn't get the user calendar room!\n");
1300 qr.QRep.expire_mode = EXPIRE_MANUAL;
1301 qr.QRdefaultview = 3; /* 3 = calendar view */
1304 /* Set the view to a calendar view */
1305 CtdlGetRelationship(&vbuf, &CC->user, &qr);
1306 vbuf.v_view = 3; /* 3 = calendar */
1307 CtdlSetRelationship(&vbuf, &CC->user, &qr);
1309 /* Create the tasks list room if it doesn't already exist */
1310 create_room(USERTASKSROOM, 4, "", 0, 1, 0);
1312 /* Set expiration policy to manual; otherwise objects will be lost! */
1313 if (lgetroom(&qr, USERTASKSROOM)) {
1314 lprintf(CTDL_CRIT, "Couldn't get the user calendar room!\n");
1317 qr.QRep.expire_mode = EXPIRE_MANUAL;
1318 qr.QRdefaultview = 4; /* 4 = tasks view */
1321 /* Set the view to a task list view */
1322 CtdlGetRelationship(&vbuf, &CC->user, &qr);
1323 vbuf.v_view = 4; /* 4 = tasks */
1324 CtdlSetRelationship(&vbuf, &CC->user, &qr);
1331 * ical_send_out_invitations() is called by ical_saving_vevent() when it
1334 void ical_send_out_invitations(icalcomponent *cal) {
1335 icalcomponent *the_request = NULL;
1336 char *serialized_request = NULL;
1337 icalcomponent *encaps = NULL;
1338 char *request_message_text = NULL;
1339 struct CtdlMessage *msg = NULL;
1340 struct recptypes *valid = NULL;
1341 char attendees_string[SIZ];
1342 int num_attendees = 0;
1343 char this_attendee[SIZ];
1344 icalproperty *attendee = NULL;
1345 char summary_string[SIZ];
1346 icalproperty *summary = NULL;
1349 lprintf(CTDL_ERR, "ERROR: trying to reply to NULL event?\n");
1354 /* If this is a VCALENDAR component, look for a VEVENT subcomponent. */
1355 if (icalcomponent_isa(cal) == ICAL_VCALENDAR_COMPONENT) {
1356 ical_send_out_invitations(
1357 icalcomponent_get_first_component(
1358 cal, ICAL_VEVENT_COMPONENT
1364 /* Clone the event */
1365 the_request = icalcomponent_new_clone(cal);
1366 if (the_request == NULL) {
1367 lprintf(CTDL_ERR, "ERROR: cannot clone calendar object\n");
1371 /* Extract the summary string -- we'll use it as the
1372 * message subject for the request
1374 strcpy(summary_string, "Meeting request");
1375 summary = icalcomponent_get_first_property(the_request, ICAL_SUMMARY_PROPERTY);
1376 if (summary != NULL) {
1377 if (icalproperty_get_summary(summary)) {
1378 strcpy(summary_string,
1379 icalproperty_get_summary(summary) );
1383 /* Determine who the recipients of this message are (the attendees) */
1384 strcpy(attendees_string, "");
1385 for (attendee = icalcomponent_get_first_property(the_request, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(the_request, ICAL_ATTENDEE_PROPERTY)) {
1386 if (icalproperty_get_attendee(attendee)) {
1387 strcpy(this_attendee, icalproperty_get_attendee(attendee) );
1388 if (!strncasecmp(this_attendee, "MAILTO:", 7)) {
1389 strcpy(this_attendee, &this_attendee[7]);
1391 if (!CtdlIsMe(this_attendee)) { /* don't send an invitation to myself! */
1392 snprintf(&attendees_string[strlen(attendees_string)],
1393 sizeof(attendees_string) - strlen(attendees_string),
1403 lprintf(CTDL_DEBUG, "<%d> attendees: <%s>\n", num_attendees, attendees_string);
1405 /* If there are no attendees, there are no invitations to send, so...
1406 * don't bother putting one together! Punch out, Maverick!
1408 if (num_attendees == 0) {
1409 icalcomponent_free(the_request);
1413 /* Encapsulate the VEVENT component into a complete VCALENDAR */
1414 encaps = icalcomponent_new_vcalendar();
1415 if (encaps == NULL) {
1416 lprintf(CTDL_DEBUG, "Error at %s:%d - could not allocate component!\n",
1417 __FILE__, __LINE__);
1418 icalcomponent_free(the_request);
1422 /* Set the Product ID */
1423 icalcomponent_add_property(encaps, icalproperty_new_prodid(PRODID));
1425 /* Set the Version Number */
1426 icalcomponent_add_property(encaps, icalproperty_new_version("2.0"));
1428 /* Set the method to REQUEST */
1429 icalcomponent_set_method(encaps, ICAL_METHOD_REQUEST);
1431 /* Now make sure all of the DTSTART and DTEND properties are UTC. */
1432 ical_dezonify(the_request);
1434 /* Here we go: put the VEVENT into the VCALENDAR. We now no longer
1435 * are responsible for "the_request"'s memory -- it will be freed
1436 * when we free "encaps".
1438 icalcomponent_add_component(encaps, the_request);
1441 serialized_request = strdup(icalcomponent_as_ical_string(encaps));
1442 icalcomponent_free(encaps); /* Don't need this anymore. */
1443 if (serialized_request == NULL) return;
1445 request_message_text = malloc(strlen(serialized_request) + SIZ);
1446 if (request_message_text != NULL) {
1447 sprintf(request_message_text,
1448 "Content-type: text/calendar\r\n\r\n%s\r\n",
1452 msg = CtdlMakeMessage(&CC->user,
1453 "", /* No single recipient here */
1454 CC->room.QRname, 0, FMT_RFC822,
1456 summary_string, /* Use summary for subject */
1457 request_message_text);
1460 valid = validate_recipients(attendees_string);
1461 CtdlSubmitMsg(msg, valid, "");
1462 CtdlFreeMessage(msg);
1465 free(serialized_request);
1470 * When a calendar object is being saved, determine whether it's a VEVENT
1471 * and the user saving it is the organizer. If so, send out invitations
1472 * to any listed attendees.
1475 void ical_saving_vevent(icalcomponent *cal) {
1477 icalproperty *organizer = NULL;
1478 char organizer_string[SIZ];
1480 /* Don't send out invitations unless the client wants us to. */
1481 if (CIT_ICAL->server_generated_invitations == 0) {
1485 /* Don't send out invitations if we've been asked not to. */
1486 if (CIT_ICAL->avoid_sending_invitations > 0) {
1490 strcpy(organizer_string, "");
1492 * The VEVENT subcomponent is the one we're interested in.
1493 * Send out invitations if, and only if, this user is the Organizer.
1495 if (icalcomponent_isa(cal) == ICAL_VEVENT_COMPONENT) {
1496 organizer = icalcomponent_get_first_property(cal,
1497 ICAL_ORGANIZER_PROPERTY);
1498 if (organizer != NULL) {
1499 if (icalproperty_get_organizer(organizer)) {
1500 strcpy(organizer_string,
1501 icalproperty_get_organizer(organizer));
1504 if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
1505 strcpy(organizer_string, &organizer_string[7]);
1506 striplt(organizer_string);
1508 * If the user saving the event is listed as the
1509 * organizer, then send out invitations.
1511 if (CtdlIsMe(organizer_string)) {
1512 ical_send_out_invitations(cal);
1517 /* If the component has subcomponents, recurse through them. */
1518 for (c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
1520 c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)) {
1521 /* Recursively process subcomponent */
1522 ical_saving_vevent(c);
1530 * Back end for ical_obj_beforesave()
1531 * This hunts for the UID of the calendar event (becomes Citadel msg EUID),
1532 * the summary of the event (becomes message subject),
1533 * and the start time (becomes message date/time).
1535 void ical_ctdl_set_extended_msgid(char *name, char *filename, char *partnum,
1536 char *disp, void *content, char *cbtype, size_t length,
1537 char *encoding, void *cbuserdata)
1541 struct icalmessagemod *imm;
1543 imm = (struct icalmessagemod *)cbuserdata;
1545 /* If this is a text/calendar object, hunt for the UID and drop it in
1546 * the "user data" pointer for the MIME parser. When
1547 * ical_obj_beforesave() sees it there, it'll set the Extended msgid
1550 if (!strcasecmp(cbtype, "text/calendar")) {
1551 cal = icalcomponent_new_from_string(content);
1553 if (icalcomponent_isa(cal) == ICAL_VCALENDAR_COMPONENT) {
1554 cal = icalcomponent_get_first_component(
1555 cal, ICAL_VEVENT_COMPONENT
1560 p = ical_ctdl_get_subprop(cal, ICAL_UID_PROPERTY);
1562 strcpy(imm->uid, icalproperty_get_comment(p));
1564 p = ical_ctdl_get_subprop(cal, ICAL_SUMMARY_PROPERTY);
1566 strcpy(imm->subject,
1567 icalproperty_get_comment(p));
1569 p = ical_ctdl_get_subprop(cal, ICAL_DTSTART_PROPERTY);
1571 imm->dtstart = icaltime_as_timet(icalproperty_get_dtstart(p));
1573 icalcomponent_free(cal);
1583 * See if we need to prevent the object from being saved (we don't allow
1584 * MIME types other than text/calendar in the Calendar> room). Also, when
1585 * saving an event to the calendar, set the message's Citadel extended message
1586 * ID to the UID of the object. This causes our replication checker to
1587 * automatically delete any existing instances of the same object. (Isn't
1590 * We also set the message's Subject to the event summary, and the Date/time to
1591 * the event start time.
1593 int ical_obj_beforesave(struct CtdlMessage *msg)
1595 char roomname[ROOMNAMELEN];
1598 struct icalmessagemod imm;
1601 * Only messages with content-type text/calendar
1602 * may be saved to Calendar>. If the message is bound for
1603 * Calendar> but doesn't have this content-type, throw an error
1604 * so that the message may not be posted.
1607 /* First determine if this is our room */
1608 MailboxName(roomname, sizeof roomname, &CC->user, USERCALENDARROOM);
1609 if (strcasecmp(roomname, CC->room.QRname)) {
1610 return 0; /* It's not the Calendar room. */
1613 /* Then determine content-type of the message */
1615 /* It must be an RFC822 message! */
1616 /* FIXME: Not handling MIME multipart messages; implement with IMIP */
1617 if (msg->cm_format_type != 4)
1618 return 1; /* You tried to save a non-RFC822 message! */
1620 /* Find the Content-Type: header */
1621 p = msg->cm_fields['M'];
1624 if (!strncasecmp(p, "Content-Type: ", 14)) { /* Found it */
1625 if (!strncasecmp(p + 14, "text/calendar", 13)) {
1626 memset(&imm, 0, sizeof(struct icalmessagemod));
1627 mime_parser(msg->cm_fields['M'],
1629 *ical_ctdl_set_extended_msgid,
1634 if (strlen(imm.uid) > 0) {
1635 if (msg->cm_fields['E'] != NULL) {
1636 free(msg->cm_fields['E']);
1638 msg->cm_fields['E'] = strdup(imm.uid);
1640 if (strlen(imm.subject) > 0) {
1641 if (msg->cm_fields['U'] != NULL) {
1642 free(msg->cm_fields['U']);
1644 msg->cm_fields['U'] = strdup(imm.subject);
1646 if (imm.dtstart > 0) {
1647 if (msg->cm_fields['T'] != NULL) {
1648 free(msg->cm_fields['T']);
1650 msg->cm_fields['T'] = strdup("000000000000000000");
1651 sprintf(msg->cm_fields['T'], "%ld", imm.dtstart);
1662 /* Oops! No Content-Type in this message! How'd that happen? */
1663 lprintf(CTDL_ERR, "RFC822 message with no Content-Type header!\n");
1669 * Things we need to do after saving a calendar event.
1671 void ical_obj_aftersave_backend(char *name, char *filename, char *partnum,
1672 char *disp, void *content, char *cbtype, size_t length,
1673 char *encoding, void *cbuserdata)
1677 /* If this is a text/calendar object, hunt for the UID and drop it in
1678 * the "user data" pointer for the MIME parser. When
1679 * ical_obj_beforesave() sees it there, it'll set the Extended msgid
1682 if (!strcasecmp(cbtype, "text/calendar")) {
1683 cal = icalcomponent_new_from_string(content);
1685 ical_saving_vevent(cal);
1686 icalcomponent_free(cal);
1693 * Things we need to do after saving a calendar event.
1695 int ical_obj_aftersave(struct CtdlMessage *msg)
1697 char roomname[ROOMNAMELEN];
1702 * If this isn't the Calendar> room, no further action is necessary.
1705 /* First determine if this is our room */
1706 MailboxName(roomname, sizeof roomname, &CC->user, USERCALENDARROOM);
1707 if (strcasecmp(roomname, CC->room.QRname)) {
1708 return 0; /* It's not the Calendar room. */
1711 /* Then determine content-type of the message */
1713 /* It must be an RFC822 message! */
1714 /* FIXME: Not handling MIME multipart messages; implement with IMIP */
1715 if (msg->cm_format_type != 4) return(1);
1717 /* Find the Content-Type: header */
1718 p = msg->cm_fields['M'];
1721 if (!strncasecmp(p, "Content-Type: ", 14)) { /* Found it */
1722 if (!strncasecmp(p + 14, "text/calendar", 13)) {
1723 mime_parser(msg->cm_fields['M'],
1725 *ical_obj_aftersave_backend,
1739 /* Oops! No Content-Type in this message! How'd that happen? */
1740 lprintf(CTDL_ERR, "RFC822 message with no Content-Type header!\n");
1745 void ical_session_startup(void) {
1746 CtdlAllocUserData(SYM_CIT_ICAL, sizeof(struct cit_ical));
1747 memset(CIT_ICAL, 0, sizeof(struct cit_ical));
1751 #endif /* CITADEL_WITH_CALENDAR_SERVICE */
1754 * Register this module with the Citadel server.
1756 char *serv_calendar_init(void)
1758 #ifdef CITADEL_WITH_CALENDAR_SERVICE
1759 CtdlRegisterMessageHook(ical_obj_beforesave, EVT_BEFORESAVE);
1760 CtdlRegisterMessageHook(ical_obj_aftersave, EVT_AFTERSAVE);
1761 CtdlRegisterSessionHook(ical_create_room, EVT_LOGIN);
1762 CtdlRegisterProtoHook(cmd_ical, "ICAL", "Citadel iCal commands");
1763 CtdlRegisterSessionHook(ical_session_startup, EVT_START);