New config option: set smtp_advertise_starttls to nonzero to advertise STARTTLS in...
[citadel.git] / citadel / server / modules / calendar / calendar_report.c
1 // This is a handler for calendar "report" operations.
2 // It is expected that CALDAV REPORT operations should be able to use this directly.
3 //
4 // Copyright (c) 1987-2024 by the citadel.org team
5 //
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.
8
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"
18
19
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;
24
25         syslog(LOG_DEBUG, "calendar_report: calendar_report_backend(%ld)", msgnum);
26
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_");
32         mime_parser(
33                 CM_RANGE(msg, eMessageText),
34                 *ical_locate_part,              // This callback function extracts a vcalendar item from the message.
35                 NULL,
36                 NULL,
37                 (void *) &ird,                  // Give it this place to put the vcalendar object.
38                 0
39         );
40         CM_Free(msg);
41         if (ird.cal == NULL) return;            // If there was no calendar item in this message, do nothing else.
42
43
44         char *ser = icalcomponent_as_ical_string_r(ird.cal);
45         if (ser) {
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"));
51                 }
52                 free(ser);
53         }
54
55
56         icalcomponent_free(ird.cal);            // Return the memory we got from the callback.
57 }
58
59
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
64
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)
68         ) {
69                 cprintf("%d Not a calendar room\n", ERROR+NOT_HERE);
70                 return;         // This room does not contain a calendar.
71         }
72
73         cprintf("%d Filtered calendar listing:\n", LISTING_FOLLOWS);
74
75         // Now go through the room encapsulating all calendar items.
76         CtdlForEachMessage(MSGS_ALL, 0, NULL,
77                 NULL,
78                 NULL,
79                 calendar_report_backend,
80                 (void *) filter_rules
81         );
82
83         cprintf("000\n");
84 }
85
86