]> code.citadel.org Git - citadel.git/blobdiff - citadel/server/modules/calendar/serv_calendar.c
START_CHAT_MODE is renamed to SEND_THEN_RECV
[citadel.git] / citadel / server / modules / calendar / serv_calendar.c
index 02be85f0ffd15ed7e6e82a93395100c7bbdee6c1..6b05678a079c5215d9eb2c9f1d91153463599a57 100644 (file)
@@ -1711,74 +1711,6 @@ void ical_putics(void) {
 }
 
 
-// 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;
@@ -1917,9 +1849,8 @@ void ical_send_out_invitations(icalcomponent *top_level_cal, icalcomponent *cal)
 
        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;
@@ -2062,17 +1993,14 @@ void ical_send_out_invitations(icalcomponent *top_level_cal, icalcomponent *cal)
 }
 
 
-/*
- * 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;
@@ -2091,10 +2019,8 @@ void ical_saving_vevent(icalcomponent *top_level_cal, icalcomponent *cal) {
        }
 
        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) {
@@ -2106,10 +2032,8 @@ void ical_saving_vevent(icalcomponent *top_level_cal, icalcomponent *cal) {
                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);
                        }
@@ -2128,12 +2052,10 @@ void ical_saving_vevent(icalcomponent *top_level_cal, icalcomponent *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)
@@ -2223,13 +2145,11 @@ void ical_obj_beforesave_backend(char *name, char *filename, char *partnum,
 }
 
 
-/*
- * 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)
@@ -2262,9 +2182,7 @@ int ical_obj_beforesave(struct CtdlMessage *msg, struct recptypes *recp) {
 }
 
 
-/*
- * 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)
@@ -2278,11 +2196,10 @@ void ical_obj_aftersave_backend(char *name, char *filename, char *partnum,
                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"))
        ) {
@@ -2295,17 +2212,13 @@ void ical_obj_aftersave_backend(char *name, char *filename, char *partnum,
 }
 
 
-/* 
- * 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);
@@ -2413,6 +2326,88 @@ void ical_fixed_output(char *ptr, int len) {
 }
 
 
+// This is an experimental implementation of CALDAV REPORT operations (RFC 4791 section 7)
+// fundamentally handled in the Citadel Server.  A web implementation should be able to just
+// change the encapsulation to HTTP with the data format unchanged.
+void ical_report(void) {
+       cprintf("%d Hi from Citadel\n", CIT_OK);
+}
+
+
+// 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, "report")) {
+               ical_report();
+               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) {