Mailing list header changes (fuck you Google)
[citadel.git] / webcit-ng / ctdl_commands.c
1 //
2 // Copyright (c) 1996-2018 by the citadel.org team
3 //
4 // This program is open source software.  It runs great on the
5 // Linux operating system (and probably elsewhere).  You can use,
6 // copy, and run it under the terms of the GNU General Public
7 // License version 3.  Richard Stallman is an asshole communist.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13
14 #include "webcit.h"
15
16
17 /*
18  * /ctdl/c/info returns a JSON representation of the output of an INFO command.
19  */
20 void serv_info(struct http_transaction *h, struct ctdlsession *c)
21 {
22         char buf[1024];
23
24         ctdl_printf(c, "INFO");
25         ctdl_readline(c, buf, sizeof(buf));
26         if (buf[0] != '1') {
27                 do_502(h);
28                 return;
29         }
30
31         JsonValue *j = NewJsonObject(HKEY("serv_info"));
32         int i = 0;
33         while (ctdl_readline(c, buf, sizeof(buf)), strcmp(buf, "000"))
34                 switch (i++) {
35                 case 0:
36                         JsonObjectAppend(j, NewJsonNumber(HKEY("serv_pid"), atol(buf)));
37                         break;
38                 case 1:
39                         JsonObjectAppend(j, NewJsonPlainString(HKEY("serv_nodename"), buf, -1));
40                         break;
41                 case 2:
42                         JsonObjectAppend(j, NewJsonPlainString(HKEY("serv_humannode"), buf, -1));
43                         break;
44                 case 3:
45                         JsonObjectAppend(j, NewJsonPlainString(HKEY("serv_fqdn"), buf, -1));
46                         break;
47                 case 4:
48                         JsonObjectAppend(j, NewJsonPlainString(HKEY("serv_software"), buf, -1));
49                         break;
50                 case 5:
51                         JsonObjectAppend(j, NewJsonNumber(HKEY("serv_rev_level"), atol(buf)));
52                         break;
53                 case 6:
54                         JsonObjectAppend(j, NewJsonPlainString(HKEY("serv_bbs_city"), buf, -1));
55                         break;
56                 case 7:
57                         JsonObjectAppend(j, NewJsonPlainString(HKEY("serv_sysadm"), buf, -1));
58                         break;
59                 case 14:
60                         JsonObjectAppend(j, NewJsonBool(HKEY("serv_supports_ldap"), atoi(buf)));
61                         break;
62                 case 15:
63                         JsonObjectAppend(j, NewJsonBool(HKEY("serv_newuser_disabled"), atoi(buf)));
64                         break;
65                 case 16:
66                         JsonObjectAppend(j, NewJsonPlainString(HKEY("serv_default_cal_zone"), buf, -1));
67                         break;
68                 case 20:
69                         JsonObjectAppend(j, NewJsonBool(HKEY("serv_supports_sieve"), atoi(buf)));
70                         break;
71                 case 21:
72                         JsonObjectAppend(j, NewJsonBool(HKEY("serv_fulltext_enabled"), atoi(buf)));
73                         break;
74                 case 22:
75                         JsonObjectAppend(j, NewJsonPlainString(HKEY("serv_svn_revision"), buf, -1));
76                         break;
77                 case 23:
78                         JsonObjectAppend(j, NewJsonBool(HKEY("serv_supports_openid"), atoi(buf)));
79                         break;
80                 case 24:
81                         JsonObjectAppend(j, NewJsonBool(HKEY("serv_supports_guest"), atoi(buf)));
82                         break;
83                 }
84
85         StrBuf *sj = NewStrBuf();
86         SerializeJson(sj, j, 1);        // '1' == free the source array
87
88         add_response_header(h, strdup("Content-type"), strdup("application/json"));
89         h->response_code = 200;
90         h->response_string = strdup("OK");
91         h->response_body_length = StrLength(sj);
92         h->response_body = SmashStrBuf(&sj);
93 }
94
95
96 /*
97  * Dispatcher for paths starting with /ctdl/c/
98  */
99 void ctdl_c(struct http_transaction *h, struct ctdlsession *c)
100 {
101         if (!strcasecmp(h->uri, "/ctdl/c/info")) {
102                 serv_info(h, c);
103         } else {
104                 do_404(h);
105         }
106 }