]> code.citadel.org Git - citadel.git/blob - webcit-ng/floor_functions.c
new license declaration text
[citadel.git] / webcit-ng / floor_functions.c
1 //
2 // Floor functions
3 //
4 // Copyright (c) 1996-2022 by the citadel.org team
5 //
6 // This program is open source software.  Use, duplication, or
7 // disclosure are subject to the GNU General Public License v3.
8
9 #include "webcit.h"
10
11
12 // Dispatcher for "/ctdl/f" and "/ctdl/f/" for the floor list
13 void floor_list(struct http_transaction *h, struct ctdlsession *c) {
14         char buf[1024];
15         char floorname[1024];
16
17         ctdl_printf(c, "LFLR");
18         ctdl_readline(c, buf, sizeof(buf));
19         if (buf[0] != '1') {
20                 do_502(h);
21                 return;
22         }
23
24         JsonValue *j = NewJsonArray(HKEY("lflr"));
25         while (ctdl_readline(c, buf, sizeof(buf)), strcmp(buf, "000")) {
26
27                 // 0  |1   |2
28                 // num|name|refcount
29                 JsonValue *jr = NewJsonObject(HKEY("floor"));
30
31                 extract_token(floorname, buf, 1, '|', sizeof floorname);
32                 JsonObjectAppend(jr, NewJsonPlainString(HKEY("name"), floorname, -1));
33
34                 JsonObjectAppend(jr, NewJsonNumber(HKEY("num"), extract_int(buf, 0)));
35                 JsonObjectAppend(jr, NewJsonNumber(HKEY("refcount"), extract_int(buf, 2)));
36
37                 JsonArrayAppend(j, jr); // add the room to the array
38         }
39
40         StrBuf *sj = NewStrBuf();
41         SerializeJson(sj, j, 1);        // '1' == free the source array
42
43         add_response_header(h, strdup("Content-type"), strdup("application/json"));
44         h->response_code = 200;
45         h->response_string = strdup("OK");
46         h->response_body_length = StrLength(sj);
47         h->response_body = SmashStrBuf(&sj);
48 }
49
50
51 // Dispatcher for paths starting with /ctdl/f/
52 // (This is a stub ... we will need to add more functions when we can do more than just a floor list)
53 void ctdl_f(struct http_transaction *h, struct ctdlsession *c) {
54         floor_list(h, c);
55         return;
56 }