// This program is open source software. Use, duplication, or disclosure
// are subject to the terms of the GNU General Public License version 3.
-#define PRODID "-//Citadel//NONSGML Citadel Calendar//EN"
-
-#include "../../ctdl_module.h"
#include <libical/ical.h>
+#include "../../ctdl_module.h"
#include "../../msgbase.h"
#include "../../internet_addressing.h"
-#include "serv_calendar.h"
#include "../../room_ops.h"
#include "../../euidindex.h"
#include "../../default_timezone.h"
#include "../../config.h"
-
-struct ical_respond_data {
- char desired_partnum[SIZ];
- icalcomponent *cal;
-};
-
+#include "serv_calendar.h"
// Utility function to create a new VCALENDAR component with some of the
// required fields already set the way we like them.
// If the caller did not supply a user, write to the currently selected room
if (!u) {
- struct CitContext *CCC = CC;
StrBuf *MsgBody;
msg = malloc(sizeof(struct CtdlMessage));
msg->cm_magic = CTDLMESSAGE_MAGIC;
msg->cm_anon_type = MES_NORMAL;
msg->cm_format_type = 4;
- CM_SetField(msg, eAuthor, CCC->user.fullname);
- CM_SetField(msg, eOriginalRoom, CCC->room.QRname);
+ CM_SetField(msg, eAuthor, CC->user.fullname);
+ CM_SetField(msg, eOriginalRoom, CC->room.QRname);
MsgBody = NewStrBufPlain(NULL, serlen + 100);
StrBufAppendBufPlain(MsgBody, HKEY("Content-type: text/calendar\r\n\r\n"), 0);
if (ird.cal == NULL) return;
- // Here we go: put the VEVENT into the VCALENDAR. We now no longer
- // are responsible for "the_request"'s memory -- it will be freed
- // when we free "encaps".
+ // Here we go: put the VEVENT componment into the VCALENDAR container.
- // If the top-level component is *not* a VCALENDAR, we can drop it right in.
- // This will almost never happen.
+ // If the top-level component is *not* a VCALENDAR container, we can drop it right in.
+ // This is rare but we have to be able to handle it.
if (icalcomponent_isa(ird.cal) != ICAL_VCALENDAR_COMPONENT) {
icalcomponent_add_component(encaps, ird.cal);
+ // And now, the parent VCALENDAR container owns the child component's memory.
}
- // In the more likely event that we're looking at a VCALENDAR with the VEVENT
- // and other components encapsulated inside, we have to extract them.
+ // In the more likely event that we're looking at a VCALENDAR container with the VEVENT
+ // and other components encapsulated inside, we have to extract them first.
else {
for (c = icalcomponent_get_first_component(ird.cal, ICAL_ANY_COMPONENT);
(c != NULL);
c = icalcomponent_get_next_component(ird.cal, ICAL_ANY_COMPONENT)
) {
-
// 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));
+ icalcomponent_add_component(encaps, icalcomponent_new_clone(c));
}
}
}
icalcomponent_add_component(encaps, icalcomponent_new_clone(c));
}
}
- icalcomponent_free(ird.cal);
+ icalcomponent_free(ird.cal); // we cloned this component so free the original.
}
}
icalcomponent *encaps = NULL;
char *ser = NULL;
+ // Only allow this operation if we're in a room containing a calendar or tasks view
if ( (CC->room.QRdefaultview != VIEW_CALENDAR)
- &&(CC->room.QRdefaultview != VIEW_TASKS)
+ && (CC->room.QRdefaultview != VIEW_TASKS)
) {
cprintf("%d Not a calendar room\n", ERROR+NOT_HERE);
return; // This room does not contain a calendar.
&& (CC->room.QRdefaultview != VIEW_TASKS)
) {
cprintf("%d Not a calendar room\n", ERROR+NOT_HERE);
- return;
+ return; // This room does not contain a calendar.
}
// Only allow this operation if we have permission to overwrite the existing calendar
}
-// All Citadel calendar commands from the client come through here.
-void cmd_ical(char *argbuf) {
- char subcmd[64];
- long msgnum;
- char partnum[256];
- char action[256];
- char who[256];
-
- extract_token(subcmd, argbuf, 0, '|', sizeof subcmd);
-
- // Allow "test" and "freebusy" subcommands without logging in.
-
- if (!strcasecmp(subcmd, "test")) {
- cprintf("%d This server supports calendaring\n", CIT_OK);
- return;
- }
-
- if (!strcasecmp(subcmd, "freebusy")) {
- extract_token(who, argbuf, 1, '|', sizeof who);
- ical_freebusy(who);
- return;
- }
-
- if (!strcasecmp(subcmd, "sgi")) {
- CIT_ICAL->server_generated_invitations = (extract_int(argbuf, 1) ? 1 : 0) ;
- cprintf("%d %d\n", CIT_OK, CIT_ICAL->server_generated_invitations);
- return;
- }
-
- if (CtdlAccessCheck(ac_logged_in)) return;
-
- if (!strcasecmp(subcmd, "respond")) {
- msgnum = extract_long(argbuf, 1);
- extract_token(partnum, argbuf, 2, '|', sizeof partnum);
- extract_token(action, argbuf, 3, '|', sizeof action);
- ical_respond(msgnum, partnum, action);
- return;
- }
-
- if (!strcasecmp(subcmd, "handle_rsvp")) {
- msgnum = extract_long(argbuf, 1);
- extract_token(partnum, argbuf, 2, '|', sizeof partnum);
- extract_token(action, argbuf, 3, '|', sizeof action);
- ical_handle_rsvp(msgnum, partnum, action);
- return;
- }
-
- if (!strcasecmp(subcmd, "conflicts")) {
- msgnum = extract_long(argbuf, 1);
- extract_token(partnum, argbuf, 2, '|', sizeof partnum);
- ical_conflicts(msgnum, partnum);
- return;
- }
-
- if (!strcasecmp(subcmd, "getics")) {
- ical_getics();
- return;
- }
-
- if (!strcasecmp(subcmd, "putics")) {
- ical_putics();
- return;
- }
-
- cprintf("%d Invalid subcommand\n", ERROR + CMD_NOT_SUPPORTED);
-}
-
-
// We don't know if the calendar room exists so we just create it at login
void ical_CtdlCreateRoom(void) {
struct ctdlroom qr;
syslog(LOG_DEBUG, "calendar: <%d> attendees: <%s>", num_attendees, attendees_string);
- /* If there are no attendees, there are no invitations to send, so...
- * don't bother putting one together! Punch out, Maverick!
- */
+ // If there are no attendees, there are no invitations to send, so...
+ // don't bother putting one together! Punch out, Maverick!
if (num_attendees == 0) {
icalcomponent_free(the_request);
return;
}
-/*
- * When a calendar object is being saved, determine whether it's a VEVENT
- * 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.
- *
- */
+// When a calendar object is being saved, determine whether it's a VEVENT
+// 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 *top_level_cal, icalcomponent *cal) {
icalcomponent *c;
icalproperty *organizer = NULL;
}
strcpy(organizer_string, "");
- /*
- * The VEVENT subcomponent is the one we're interested in.
- * Send out invitations if, and only if, this user is the Organizer.
- */
+ // The VEVENT subcomponent is the one we're interested in.
+ // Send out invitations if, and only if, this user is the Organizer.
if (icalcomponent_isa(cal) == ICAL_VEVENT_COMPONENT) {
organizer = icalcomponent_get_first_property(cal, ICAL_ORGANIZER_PROPERTY);
if (organizer != NULL) {
if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
strcpy(organizer_string, &organizer_string[7]);
string_trim(organizer_string);
- /*
- * If the user saving the event is listed as the
- * organizer, then send out invitations.
- */
+ // If the user saving the event is listed as the
+ // organizer, then send out invitations.
if (CtdlIsMe(organizer_string, sizeof organizer_string)) {
ical_send_out_invitations(top_level_cal, cal);
}
}
-/*
- * Back end for ical_obj_beforesave()
- * This hunts for the UID of the calendar event (becomes Citadel msg EUID),
- * the summary of the event (becomes message subject),
- * and the start time (becomes message date/time).
- */
+// Back end for ical_obj_beforesave()
+// This hunts for the UID of the calendar event (becomes Citadel msg EUID),
+// the summary of the event (becomes message subject),
+// and the start time (becomes message date/time).
void ical_obj_beforesave_backend(char *name, char *filename, char *partnum,
char *disp, void *content, char *cbtype, char *cbcharset, size_t length,
char *encoding, char *cbid, void *cbuserdata)
}
-/*
- * See if we need to prevent the object from being saved (we don't allow
- * MIME types other than text/calendar in "calendar" or "tasks" rooms).
- *
- * If the message is being saved, we also set various message header fields
- * using data found in the iCalendar object.
- */
+// See if we need to prevent the object from being saved (we don't allow
+// MIME types other than text/calendar in "calendar" or "tasks" rooms).
+//
+// If the message is being saved, we also set various message header fields
+// using data found in the iCalendar object.
int ical_obj_beforesave(struct CtdlMessage *msg, struct recptypes *recp) {
// First determine if this is a calendar or tasks room
if ( (CC->room.QRdefaultview != VIEW_CALENDAR)
}
-/*
- * Things we need to do after saving a calendar event.
- */
+// Things we need to do after saving a calendar event.
void ical_obj_aftersave_backend(char *name, char *filename, char *partnum,
char *disp, void *content, char *cbtype, char *cbcharset, size_t length,
char *encoding, char *cbid, void *cbuserdata)
return;
}
- /* Hunt for the UID and drop it in
- * the "user data" pointer for the MIME parser. When
- * ical_obj_beforesave() sees it there, it'll set the Exclusive msgid
- * to that string.
- */
+ // Hunt for the UID and drop it in
+ // the "user data" pointer for the MIME parser. When
+ // ical_obj_beforesave() sees it there, it'll set the Exclusive msgid
+ // to that string.
if ( (!strcasecmp(cbtype, "text/calendar"))
|| (!strcasecmp(cbtype, "application/ics"))
) {
}
-/*
- * Things we need to do after saving a calendar event.
- * (This will start back end tasks such as automatic generation of invitations,
- * if such actions are appropriate.)
- */
+// Things we need to do after saving a calendar event.
+// (This will start back end tasks such as automatic generation of invitations,
+// if such actions are appropriate.)
int ical_obj_aftersave(struct CtdlMessage *msg, struct recptypes *recp) {
char roomname[ROOMNAMELEN];
- /*
- * If this isn't the Calendar> room, no further action is necessary.
- */
+ // If this isn't the Calendar> room, no further action is necessary.
// First determine if this is our room
CtdlMailboxName(roomname, sizeof roomname, &CC->user, USERCALENDARROOM);
}
+// All Citadel calendar commands from the client come through here.
+void cmd_ical(char *argbuf) {
+ char subcmd[64];
+ long msgnum;
+ char partnum[256];
+ char action[256];
+ char who[256];
+
+ extract_token(subcmd, argbuf, 0, '|', sizeof subcmd);
+
+ // Allow "test" and "freebusy" and "sgi" subcommands without logging in.
+
+ if (!strcasecmp(subcmd, "test")) {
+ cprintf("%d This server supports calendaring\n", CIT_OK);
+ return;
+ }
+
+ if (!strcasecmp(subcmd, "freebusy")) {
+ extract_token(who, argbuf, 1, '|', sizeof who);
+ ical_freebusy(who);
+ return;
+ }
+
+ if (!strcasecmp(subcmd, "sgi")) {
+ CIT_ICAL->server_generated_invitations = (extract_int(argbuf, 1) ? 1 : 0) ;
+ cprintf("%d %d\n", CIT_OK, CIT_ICAL->server_generated_invitations);
+ return;
+ }
+
+ // All other commands require a user to be logged in.
+ if (CtdlAccessCheck(ac_logged_in)) return;
+
+ if (!strcasecmp(subcmd, "query")) {
+ calendar_query();
+ return;
+ }
+
+ if (!strcasecmp(subcmd, "respond")) {
+ msgnum = extract_long(argbuf, 1);
+ extract_token(partnum, argbuf, 2, '|', sizeof partnum);
+ extract_token(action, argbuf, 3, '|', sizeof action);
+ ical_respond(msgnum, partnum, action);
+ return;
+ }
+
+ if (!strcasecmp(subcmd, "handle_rsvp")) {
+ msgnum = extract_long(argbuf, 1);
+ extract_token(partnum, argbuf, 2, '|', sizeof partnum);
+ extract_token(action, argbuf, 3, '|', sizeof action);
+ ical_handle_rsvp(msgnum, partnum, action);
+ return;
+ }
+
+ if (!strcasecmp(subcmd, "conflicts")) {
+ msgnum = extract_long(argbuf, 1);
+ extract_token(partnum, argbuf, 2, '|', sizeof partnum);
+ ical_conflicts(msgnum, partnum);
+ return;
+ }
+
+ if (!strcasecmp(subcmd, "getics")) {
+ ical_getics();
+ return;
+ }
+
+ if (!strcasecmp(subcmd, "putics")) {
+ ical_putics();
+ return;
+ }
+
+ cprintf("%d Invalid subcommand\n", ERROR + CMD_NOT_SUPPORTED);
+}
+
+
// Initialization function, called from modules_init.c
char *ctdl_module_init_calendar(void) {
if (!threading) {