indent -kr -i8 -brf -bbb -fnc -l132 -nce on all of webcit-classic
[citadel.git] / webcit / jsonview_renderer.c
1 #include "webcit.h"
2 #include "webserver.h"
3 #include "dav.h"
4
5 int json_GetParamsGetServerCall(SharedMessageStatus * Stat,
6                                 void **ViewSpecific, long oper, char *cmd, long len, char *filter, long flen) {
7         Stat->defaultsortorder = 2;
8         Stat->sortit = 1;
9         Stat->load_seen = 1;
10         /* Generally using maxmsgs|startmsg is not required
11            in mailbox view, but we have a 'safemode' for clients
12            (*cough* Exploder) that simply can't handle too many */
13         if (havebstr("maxmsgs"))
14                 Stat->maxmsgs = ibstr("maxmsgs");
15         else
16                 Stat->maxmsgs = 9999999;
17         if (havebstr("startmsg"))
18                 Stat->startmsg = lbstr("startmsg");
19         snprintf(cmd, len, "MSGS %s|%s||1", (oper == do_search) ? "SEARCH" : "ALL", (oper == do_search) ? bstr("query") : "");
20
21         return 200;
22 }
23 int json_MessageListHdr(SharedMessageStatus * Stat, void **ViewSpecific) {
24         /* TODO: make a generic function */
25         hprintf("HTTP/1.1 200 OK\r\n");
26         hprintf("Content-type: application/json; charset=utf-8\r\n");
27         hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
28         hprintf("Connection: close\r\n");
29         hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
30         begin_burst();
31         return 0;
32 }
33
34 int json_RenderView_or_Tail(SharedMessageStatus * Stat, void **ViewSpecific, long oper) {
35         DoTemplate(HKEY("mailsummary_json"), NULL, NULL);
36
37         return 0;
38 }
39
40 int json_Cleanup(void **ViewSpecific) {
41         /* Note: wDumpContent() will output one additional </div> tag. */
42         /* We ought to move this out into template */
43         end_burst();
44
45         return 0;
46 }
47
48 void InitModule_JSONRENDERER(void) {
49         RegisterReadLoopHandlerset(VIEW_JSON_LIST, json_GetParamsGetServerCall, json_MessageListHdr, NULL,      /* TODO: is this right? */
50                                    ParseMessageListHeaders_Detail, NULL, json_RenderView_or_Tail, json_Cleanup, NULL);
51
52 }