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_query()
21 void calendar_query_backend(long msgnum, void *data) {
22 struct CtdlMessage *msg = NULL;
23 struct ical_respond_data ird;
25 syslog(LOG_DEBUG, "calendar_query: calendar_query_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 // This is where we need to perform our search reduction.
47 char *ser = icalcomponent_as_ical_string_r(ird.cal);
49 size_t len = strlen(ser); // Output the object, ensuring it terminates with a newline.
50 client_write(ser, len);
51 if ( (len>0) && (ser[len-1] != '\n') ) {
52 client_write(HKEY("\n"));
57 icalcomponent_free(ird.cal); // Return the memory we got from the callback.
61 // Go through a calendar room and output calendar objects after applying caller specified filters.
62 // It is intended as a data source for WebCit (both the UI and CalDAV)
63 void calendar_query(void) {
64 void *filter_rules; // Don't know yet what form this will take
66 // Only allow this operation if we're in a room containing a calendar or tasks view
67 if ( (CC->room.QRdefaultview != VIEW_CALENDAR)
68 && (CC->room.QRdefaultview != VIEW_TASKS)
70 cprintf("%d Not a calendar room\n", ERROR+NOT_HERE);
71 return; // This room does not contain a calendar.
74 cprintf("%d Filtered calendar listing:\n", LISTING_FOLLOWS);
76 // Now go through the room encapsulating all calendar items.
77 CtdlForEachMessage(MSGS_ALL, 0, NULL,
80 calendar_query_backend,