d127b63de7d0e0f73b9097700f3dd3996c07fe36
[citadel.git] / webcit-ng / server / calendar_functions.c
1 // Calendar functions
2 //
3 // Copyright (c) 1996-2023 by the citadel.org team
4 //
5 // This program is open source software.  Use, duplication, or
6 // disclosure are subject to the GNU General Public License v3.
7
8 #include "webcit.h"
9
10
11 // Client is requesting a message list
12 void calendar_msglist(struct http_transaction *h, struct ctdlsession *c, char *range) {
13         char buf[SIZ];
14
15         // Determine the date/time range requested by the client
16         time_t lo = atol(range);
17         char *colon = strchr(range, ':');
18         time_t hi = colon ? atol(++colon) : LONG_MAX;
19
20         // Rule out impossible ranges
21         if (hi < lo) {
22                 do_404(h);
23                 return;
24         }
25
26         // Begin by requesting all messages in the room
27         int i = 0;
28         Array *msglist = get_msglist(c, "ALL");
29         if (msglist == NULL) {
30                 do_404(h);
31                 return;
32         }
33
34         // We're going to make a lot of MSG4 calls, and the preferred MIME type we want is "text/calendar".
35         // The iCalendar standard is mature now, and we are no longer interested in text/x-vcal or application/ics.
36         ctdl_printf(c, "MSGP text/calendar");
37         ctdl_readline(c, buf, sizeof buf);
38
39         // Iterate through our message list.
40         for (i = 0; i < array_len(msglist); ++i) {
41                 long m;
42                 memcpy(&m, array_get_element_at(msglist, i), sizeof(long));
43                 syslog(LOG_DEBUG, "FIXME %ld", m);
44
45                 // now we have to:
46                 // 1. fetch the message from citadel server
47                 // 2. parse the ical
48                 // 3. figure out range
49                 // we should steal code from webcit-classic for this
50
51                 StrBuf *one_item;
52                 one_item = fetch_ical(c, m);
53                 syslog(LOG_DEBUG, "calendar item:\n---\n\033[33m%s\n---\033[0m", ChrPtr(one_item));
54                 FreeStrBuf(&one_item);
55
56         }
57         array_free(msglist);
58
59         // FIXME we still fail because we aren't finished yet
60         add_response_header(h, strdup("Content-type"), strdup("application/json"));
61         h->response_code = 200;
62         h->response_string = strdup("OK");
63         h->response_body = "{ \"one\":111 , \"two\":222 , \"three\":333 }";
64         h->response_body_length = strlen(h->response_body);
65 }