-// This is a handler for calendar "report" operations.
-// It is expected that CALDAV REPORT operations should be able to use this directly.
-//
-// Copyright (c) 1987-2024 by the citadel.org team
-//
-// This program is open source software. Use, duplication, or disclosure
-// are subject to the terms of the GNU General Public License version 3.
-
-#include <libical/ical.h>
-#include "../../ctdl_module.h"
-#include "../../msgbase.h"
-#include "../../internet_addressing.h"
-#include "../../room_ops.h"
-#include "../../euidindex.h"
-#include "../../default_timezone.h"
-#include "../../config.h"
-#include "serv_calendar.h"
-
-
-// CtdlForEachMessage callback for calendar_query()
-void calendar_query_backend(long msgnum, void *data) {
- struct CtdlMessage *msg = NULL;
- struct ical_respond_data ird;
-
- syslog(LOG_DEBUG, "calendar_query: calendar_query_backend(%ld)", msgnum);
-
- // Look for the calendar event...
- msg = CtdlFetchMessage(msgnum, 1);
- if (msg == NULL) return;
- memset(&ird, 0, sizeof ird);
- strcpy(ird.desired_partnum, "_HUNT_");
- mime_parser(
- CM_RANGE(msg, eMessageText),
- *ical_locate_part, // This callback function extracts a vcalendar item from the message.
- NULL,
- NULL,
- (void *) &ird, // Give it this place to put the vcalendar object.
- 0
- );
- CM_Free(msg);
- if (ird.cal == NULL) return; // If there was no calendar item in this message, do nothing else.
-
-
- // This is where we need to perform our search reduction.
-
-
- char *ser = icalcomponent_as_ical_string_r(ird.cal);
- if (ser) {
- size_t len = strlen(ser); // Output the object, ensuring it terminates with a newline.
- client_write(ser, len);
- if ( (len>0) && (ser[len-1] != '\n') ) {
- client_write(HKEY("\n"));
- }
- free(ser);
- }
-
- icalcomponent_free(ird.cal); // Return the memory we got from the callback.
-}
-
-
-// Go through a calendar room and output calendar objects after applying caller specified filters.
-// It is intended as a data source for WebCit (both the UI and CalDAV)
-void calendar_query(void) {
- void *filter_rules; // Don't know yet what form this will take
-
- // 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)
- ) {
- cprintf("%d Not a calendar room\n", ERROR+NOT_HERE);
- return; // This room does not contain a calendar.
- }
-
- cprintf("%d Filtered calendar listing:\n", LISTING_FOLLOWS);
-
- // Now go through the room encapsulating all calendar items.
- CtdlForEachMessage(MSGS_ALL, 0, NULL,
- NULL,
- NULL,
- calendar_query_backend,
- (void *) filter_rules
- );
-
- cprintf("000\n");
-}