view_calendar.js: finalized a fetch design pattern
[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
14         // Determine the date/time range requested by the client
15         time_t lo = atol(range);
16         char *colon = strchr(range, ':');
17         time_t hi = colon ? atol(++colon) : LONG_MAX;
18
19         // Rule out impossible ranges
20         if (hi < lo) {
21                 do_404(h);
22                 return;
23         }
24
25         // Begin by requesting all messages in the room
26         int i = 0;
27         Array *msglist = get_msglist(c, "ALL");
28         if (msglist == NULL) {
29                 do_404(h);
30                 return;
31         }
32
33         for (i = 0; i < array_len(msglist); ++i) {
34                 long m;
35                 memcpy(&m, array_get_element_at(msglist, i), sizeof(long));
36                 syslog(LOG_DEBUG, "FIXME %ld", m);
37
38                 // now we have to:
39                 // 1. fetch the message from citadel server
40                 // 2. parse the ical
41                 // 3. figure out range
42                 // we should steal code from webcit-classic for this
43
44         }
45         array_free(msglist);
46
47         // FIXME we still fail because we aren't finished yet
48         add_response_header(h, strdup("Content-type"), strdup("application/json"));
49         h->response_code = 200;
50         h->response_string = strdup("OK");
51         h->response_body = "{ \"one\":111 , \"two\":222 , \"three\":333 }";
52         h->response_body_length = strlen(h->response_body);
53 }