4 // Copyright (c) 1996-2022 by the citadel.org team
6 // This program is open source software. It runs great on the
7 // Linux operating system (and probably elsewhere). You can use,
8 // copy, and run it under the terms of the GNU General Public
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
19 // Dispatcher for "/ctdl/f" and "/ctdl/f/" for the floor list
20 void floor_list(struct http_transaction *h, struct ctdlsession *c) {
24 ctdl_printf(c, "LFLR");
25 ctdl_readline(c, buf, sizeof(buf));
31 JsonValue *j = NewJsonArray(HKEY("lflr"));
32 while (ctdl_readline(c, buf, sizeof(buf)), strcmp(buf, "000")) {
36 JsonValue *jr = NewJsonObject(HKEY("floor"));
38 extract_token(floorname, buf, 1, '|', sizeof floorname);
39 JsonObjectAppend(jr, NewJsonPlainString(HKEY("name"), floorname, -1));
41 JsonObjectAppend(jr, NewJsonNumber(HKEY("num"), extract_int(buf, 0)));
42 JsonObjectAppend(jr, NewJsonNumber(HKEY("refcount"), extract_int(buf, 2)));
44 JsonArrayAppend(j, jr); // add the room to the array
47 StrBuf *sj = NewStrBuf();
48 SerializeJson(sj, j, 1); // '1' == free the source array
50 add_response_header(h, strdup("Content-type"), strdup("application/json"));
51 h->response_code = 200;
52 h->response_string = strdup("OK");
53 h->response_body_length = StrLength(sj);
54 h->response_body = SmashStrBuf(&sj);
58 // Dispatcher for paths starting with /ctdl/f/
59 // (This is a stub ... we will need to add more functions when we can do more than just a floor list)
60 void ctdl_f(struct http_transaction *h, struct ctdlsession *c) {