1 // This is a handler for calendar "report" operations.
2 // It is expected that CALDAV REPORT operations should be able to use this directly.
4 // Copyright (c) 1987-2024 by the citadel.org team
6 // This program is open source software. Use, duplication, or disclosure
7 // are subject to the terms of the GNU General Public License version 3.
9 #include <libical/ical.h>
10 #include "../../ctdl_module.h"
11 #include "../../msgbase.h"
12 #include "../../internet_addressing.h"
13 #include "../../room_ops.h"
14 #include "../../euidindex.h"
15 #include "../../default_timezone.h"
16 #include "../../config.h"
17 #include "serv_calendar.h"
20 // CtdlForEachMessage callback for calendar_report()
21 void calendar_report_backend(long msgnum, void *data) {
22 struct CtdlMessage *msg = NULL;
23 struct ical_respond_data ird;
25 syslog(LOG_DEBUG, "calendar_report: calendar_report_backend(%ld)", msgnum);
27 // Look for the calendar event...
28 msg = CtdlFetchMessage(msgnum, 1);
29 if (msg == NULL) return;
30 memset(&ird, 0, sizeof ird);
31 strcpy(ird.desired_partnum, "_HUNT_");
33 CM_RANGE(msg, eMessageText),
34 *ical_locate_part, // This callback function extracts a vcalendar item from the message.
37 (void *) &ird, // Give it this place to put the vcalendar object.
41 if (ird.cal == NULL) return; // If there was no calendar item in this message, do nothing else.
44 char *ser = icalcomponent_as_ical_string_r(ird.cal);
46 size_t len = strlen(ser);
47 client_write(ser, len);
48 if ( (len>0) && (ser[len-1] != '\n') ) {
49 syslog(LOG_DEBUG, "last char was %d", ser[len]);
50 client_write(HKEY("\n"));
56 icalcomponent_free(ird.cal); // Return the memory we got from the callback.
60 // Go through a calendar room and output calendar objects after applying caller specified filters.
61 // It is intended as a data source for WebCit (both the UI and CalDAV)
62 void calendar_report(void) {
63 void *filter_rules; // Don't know yet what form this will take
65 // Only allow this operation if we're in a room containing a calendar or tasks view
66 if ( (CC->room.QRdefaultview != VIEW_CALENDAR)
67 && (CC->room.QRdefaultview != VIEW_TASKS)
69 cprintf("%d Not a calendar room\n", ERROR+NOT_HERE);
70 return; // This room does not contain a calendar.
73 cprintf("%d Filtered calendar listing:\n", LISTING_FOLLOWS);
75 // Now go through the room encapsulating all calendar items.
76 CtdlForEachMessage(MSGS_ALL, 0, NULL,
79 calendar_report_backend,