Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 489 lines (402 sloc) 12.965 kB
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /* Cherokee
4 *
5 * Authors:
6 * Alvaro Lopez Ortega <alvaro@alobbs.com>
7 *
920e20b @alobbs Happy new year!
alobbs authored
8 * Copyright (C) 2001-2011 Alvaro Lopez Ortega
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
2c39092 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2660 5dc97367-9…
alobbs authored
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * 02110-1301, USA.
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
23 */
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
24
603d94e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1282 5dc97367-9…
alobbs authored
25 #include "common-internal.h"
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
26 #include "admin_server.h"
603d94e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1282 5dc97367-9…
alobbs authored
27
d12e63b @alobbs Enhances cherokee_admin_server_reply_kill_source(). It is not finished
alobbs authored
28 #include <signal.h>
29
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
30 #include "bind.h"
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
31 #include "server-protected.h"
32 #include "connection-protected.h"
33 #include "connection_info.h"
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
34 #include "source_interpreter.h"
e460d3c @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@426 5dc97367-97…
alobbs authored
35 #include "util.h"
36
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
37
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
38 ret_t
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
39 cherokee_admin_server_reply_get_ports (cherokee_handler_t *hdl,
40 cherokee_dwriter_t *dwriter)
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
41 {
dd0a852 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2652 5dc97367-9…
alobbs authored
42 cherokee_list_t *i;
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
43 cherokee_bind_t *bind_entry;
44 cherokee_server_t *srv = HANDLER_SRV(hdl);
651edbd @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1439 5dc97367-9…
alobbs authored
45
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
46 cherokee_dwriter_list_open (dwriter);
651edbd @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1439 5dc97367-9…
alobbs authored
47
dd0a852 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2652 5dc97367-9…
alobbs authored
48 list_for_each (i, &srv->listeners) {
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
49 bind_entry = BIND(i);
dd0a852 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2652 5dc97367-9…
alobbs authored
50
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
51 cherokee_dwriter_dict_open (dwriter);
dd0a852 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2652 5dc97367-9…
alobbs authored
52
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
53 cherokee_dwriter_cstring (dwriter, "id");
54 cherokee_dwriter_integer (dwriter, bind_entry->id);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
55
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
56 cherokee_dwriter_cstring (dwriter, "bind");
57 cherokee_dwriter_bstring (dwriter, &bind_entry->ip);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
58
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
59 cherokee_dwriter_cstring (dwriter, "port");
60 cherokee_dwriter_integer (dwriter, bind_entry->port);
651edbd @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1439 5dc97367-9…
alobbs authored
61
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
62 cherokee_dwriter_cstring (dwriter, "tls");
63 cherokee_dwriter_bool (dwriter, BIND_IS_TLS(bind_entry));
651edbd @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1439 5dc97367-9…
alobbs authored
64
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
65 cherokee_dwriter_dict_close (dwriter);
dd0a852 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2652 5dc97367-9…
alobbs authored
66 }
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
67 cherokee_dwriter_list_close (dwriter);
651edbd @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1439 5dc97367-9…
alobbs authored
68
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
69 return ret_ok;
70 }
71
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
72 ret_t
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
73 cherokee_admin_server_reply_get_traffic (cherokee_handler_t *hdl,
74 cherokee_dwriter_t *dwriter)
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
75 {
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
76 cherokee_server_t *srv = HANDLER_SRV(hdl);
77 cherokee_buffer_t *tmp = THREAD_TMP_BUF2 (HANDLER_THREAD(hdl));
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
78
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
79 cherokee_dwriter_dict_open (dwriter);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
80
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
81 cherokee_dwriter_cstring (dwriter, "tx");
82 if (srv->collector) {
83 cherokee_dwriter_integer (dwriter, COLLECTOR_TX(srv->collector));
84 } else {
85 cherokee_dwriter_number (dwriter, "-1", 2);
86 }
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
87
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
88 cherokee_dwriter_cstring (dwriter, "rx");
89 if (srv->collector) {
90 cherokee_dwriter_integer (dwriter, COLLECTOR_RX(srv->collector));
91 } else {
92 cherokee_dwriter_number (dwriter, "-1", 2);
93 }
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
94
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
95 cherokee_dwriter_cstring (dwriter, "tx_formatted");
96 if (srv->collector != NULL) {
97 cherokee_buffer_clean (tmp);
98 cherokee_buffer_add_fsize (tmp, COLLECTOR_TX(srv->collector));
99 cherokee_dwriter_bstring (dwriter, tmp);
100 } else {
101 cherokee_dwriter_null (dwriter);
102 }
651edbd @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1439 5dc97367-9…
alobbs authored
103
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
104 cherokee_dwriter_cstring (dwriter, "rx_formatted");
105 if (srv->collector != NULL) {
106 cherokee_buffer_clean (tmp);
107 cherokee_buffer_add_fsize (tmp, COLLECTOR_RX(srv->collector));
108 cherokee_dwriter_bstring (dwriter, tmp);
109 } else {
110 cherokee_dwriter_null (dwriter);
111 }
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
112
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
113 cherokee_dwriter_dict_close (dwriter);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
114 return ret_ok;
115 }
116
117
118 static void
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
119 render_connection_info (cherokee_connection_info_t *conn_info,
120 cherokee_dwriter_t *dwriter)
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
121 {
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
122 cherokee_dwriter_dict_open (dwriter);
123
124 cherokee_dwriter_cstring (dwriter, "id");
125 cherokee_dwriter_bstring (dwriter, &conn_info->id);
126 cherokee_dwriter_cstring (dwriter, "ip");
127 cherokee_dwriter_bstring (dwriter, &conn_info->ip);
128 cherokee_dwriter_cstring (dwriter, "phase");
129 cherokee_dwriter_bstring (dwriter, &conn_info->phase);
130
131 if (! cherokee_buffer_is_empty(&conn_info->rx)) {
132 cherokee_dwriter_cstring (dwriter, "rx");
133 cherokee_dwriter_bstring (dwriter, &conn_info->rx);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
134 }
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
135 if (! cherokee_buffer_is_empty(&conn_info->tx)) {
136 cherokee_dwriter_cstring (dwriter, "tx");
137 cherokee_dwriter_bstring (dwriter, &conn_info->tx);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
138 }
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
139 if (! cherokee_buffer_is_empty(&conn_info->request)) {
140 cherokee_dwriter_cstring (dwriter, "request");
141 cherokee_dwriter_bstring (dwriter, &conn_info->request);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
142 }
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
143 if (! cherokee_buffer_is_empty(&conn_info->handler)) {
144 cherokee_dwriter_cstring (dwriter, "handler");
145 cherokee_dwriter_bstring (dwriter, &conn_info->handler);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
146 }
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
147 if (! cherokee_buffer_is_empty(&conn_info->total_size)) {
148 cherokee_dwriter_cstring (dwriter, "total_size");
149 cherokee_dwriter_bstring (dwriter, &conn_info->total_size);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
150 }
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
151 if (! cherokee_buffer_is_empty(&conn_info->percent)) {
152 cherokee_dwriter_cstring (dwriter, "percent");
153 cherokee_dwriter_bstring (dwriter, &conn_info->percent);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
154 }
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
155 if (! cherokee_buffer_is_empty(&conn_info->icon)) {
156 cherokee_dwriter_cstring (dwriter, "icon");
157 cherokee_dwriter_bstring (dwriter, &conn_info->icon);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
158 }
159
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
160 cherokee_dwriter_dict_close (dwriter);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
161 }
162
163 ret_t
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
164 cherokee_admin_server_reply_get_conns (cherokee_handler_t *hdl,
165 cherokee_dwriter_t *dwriter)
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
166 {
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
167 ret_t ret;
168 cherokee_list_t connections;
169 cherokee_list_t *i, *tmp;
170 cherokee_server_t *srv = HANDLER_SRV(hdl);
651edbd @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1439 5dc97367-9…
alobbs authored
171
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
172 /* Build the connection-info list
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
173 */
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
174 INIT_LIST_HEAD (&connections);
175
176 ret = cherokee_connection_info_list_server (&connections, srv, HANDLER(hdl));
177 if (unlikely (ret == ret_error)) {
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
178 return ret_error;
179 }
180
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
181 /* Render it
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
182 */
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
183 cherokee_dwriter_list_open (dwriter);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
184 list_for_each (i, &connections) {
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
185 cherokee_connection_info_t *conn_info = CONN_INFO(i);
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
186
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
187 /* It won't include details about the admin requests
188 */
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
189 if (! cherokee_buffer_cmp_str (&conn_info->handler, "admin")) {
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
190 continue;
191 }
192
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
193 render_connection_info (conn_info, dwriter);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
194 }
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
195 cherokee_dwriter_list_close (dwriter);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
196
197 /* Free the connection info objects
198 */
199 list_for_each_safe (i, tmp, &connections) {
200 cherokee_connection_info_free (CONN_INFO(i));
201 }
202
203 return ret_ok;
204 }
205
206
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
207 ret_t
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
208 cherokee_admin_server_reply_close_conn (cherokee_handler_t *hdl,
209 cherokee_dwriter_t *dwriter,
210 cherokee_buffer_t *question)
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
211 {
212 ret_t ret;
213 char *begin;
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
214 cherokee_server_t *server = HANDLER_SRV(hdl);
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
215
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
216 if (strncmp (question->buf, "del server.connection ", 22)) {
217 return ret_error;
218 }
219
220 begin = question->buf + 22;
221 ret = cherokee_server_del_connection (server, begin);
222
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
223 cherokee_dwriter_dict_open (dwriter);
224 cherokee_dwriter_cstring (dwriter, "close");
225 cherokee_dwriter_cstring (dwriter, ret == ret_ok ? "ok" : "failed");
226 cherokee_dwriter_dict_close (dwriter);
227
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
228 return ret_ok;
229 }
230
231
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
232 ret_t
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
233 cherokee_admin_server_reply_get_trace (cherokee_handler_t *hdl,
234 cherokee_dwriter_t *dwriter)
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
235 {
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
236 ret_t ret;
237 cherokee_buffer_t *traces_ref = NULL;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
238
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
239 UNUSED (hdl);
651edbd @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1439 5dc97367-9…
alobbs authored
240
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
241 ret = cherokee_trace_get_trace (&traces_ref);
242 if (ret != ret_ok) {
243 return ret_error;
244 }
245
246 cherokee_dwriter_dict_open (dwriter);
247 cherokee_dwriter_cstring (dwriter, "trace");
248
249 if (cherokee_buffer_is_empty (traces_ref)) {
250 cherokee_dwriter_null (dwriter);
251 } else {
252 cherokee_dwriter_bstring (dwriter, traces_ref);
253 }
254
255 cherokee_dwriter_dict_close (dwriter);
256 return ret_ok;
257 }
258
259 ret_t
260 cherokee_admin_server_reply_set_trace (cherokee_handler_t *hdl,
261 cherokee_dwriter_t *dwriter,
262 cherokee_buffer_t *question)
263 {
264 ret_t ret;
265
266 UNUSED (hdl);
267
268 /* Process question
269 */
270 if (strncmp (question->buf, "set server.trace ", sizeof("set server.trace ")-1)) {
271 return ret_error;
272 }
273 cherokee_buffer_move_to_begin (question, sizeof("set server.trace "-1));
274
275 /* Set the traces
276 */
277 ret = cherokee_trace_set_modules (question);
278 if (ret != ret_ok) {
279 return ret_error;
280 }
281
282 /* Reply
283 */
284 cherokee_dwriter_dict_open (dwriter);
285 cherokee_dwriter_cstring (dwriter, "set");
286 cherokee_dwriter_bool (dwriter, ret == ret_ok);
287 cherokee_dwriter_dict_close (dwriter);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
288 return ret_ok;
289 }
290
291
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
292 ret_t
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
293 cherokee_admin_server_reply_set_backup_mode (cherokee_handler_t *hdl,
294 cherokee_dwriter_t *dwriter,
295 cherokee_buffer_t *question)
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
296 {
297 ret_t ret;
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
298 cherokee_server_t *srv = HANDLER_SRV(hdl);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
299 cherokee_boolean_t active;
300 cherokee_boolean_t mode;
301
302 /* Read if the resquest if for turning it on or off
303 */
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
304 if (cherokee_buffer_cmp_str (question, "set server.backup_mode on") == 0) {
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
305 mode = true;
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
306 } else if (cherokee_buffer_cmp_str (question, "set server.backup_mode off") == 0) {
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
307 mode = false;
308 } else {
309 return ret_error;
310 }
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
311
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
312 /* Do it
313 */
314 ret = cherokee_server_set_backup_mode (srv, mode);
315 if (ret != ret_ok) return ret;
316
317 /* Build the reply
318 */
319 cherokee_server_get_backup_mode (srv, &active);
320
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
321 cherokee_dwriter_dict_open (dwriter);
322 cherokee_dwriter_cstring (dwriter, "backup_mode");
323 cherokee_dwriter_bool (dwriter, mode);
324 cherokee_dwriter_dict_close (dwriter);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
325
326 return ret_ok;
327 }
328
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
329 ret_t
330 cherokee_admin_server_reply_get_thread_num (cherokee_handler_t *hdl,
331 cherokee_dwriter_t *dwriter)
332 {
333 cherokee_server_t *srv = HANDLER_SRV(hdl);
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
334
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
335 cherokee_dwriter_dict_open (dwriter);
336 cherokee_dwriter_cstring (dwriter, "thread_num");
337 cherokee_dwriter_integer (dwriter, srv->thread_num);
338 cherokee_dwriter_dict_close (dwriter);
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
339
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
340 return ret_ok;
341 }
342
343
344 static ret_t
345 sources_while (cherokee_buffer_t *key, void *value, void *param)
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
346 {
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
347 cherokee_dwriter_t *dwriter = DWRITER(param);
348 cherokee_source_t *source = SOURCE(value);
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
349
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
350 cherokee_dwriter_dict_open (dwriter);
651edbd @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1439 5dc97367-9…
alobbs authored
351
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
352 cherokee_dwriter_cstring (dwriter, "id");
353 cherokee_dwriter_bstring (dwriter, key);
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
354
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
355 cherokee_dwriter_cstring (dwriter, "type");
356 switch (source->type) {
357 case source_host:
358 cherokee_dwriter_cstring (dwriter, "host");
359 break;
360 case source_interpreter:
361 cherokee_dwriter_cstring (dwriter, "interpreter");
362 break;
363 default:
364 cherokee_dwriter_dict_close (dwriter);
365 SHOULDNT_HAPPEN;
366 return ret_error;
367 }
368
369 cherokee_dwriter_cstring (dwriter, "bind");
370 cherokee_dwriter_bstring (dwriter, &source->original);
371
372 if (source->type == source_interpreter) {
373 cherokee_source_interpreter_t *source_int = SOURCE_INT(source);
374
375 cherokee_dwriter_cstring (dwriter, "PID");
376 cherokee_dwriter_integer (dwriter, source_int->pid);
377
378 cherokee_dwriter_cstring (dwriter, "debug");
379 cherokee_dwriter_bool (dwriter, source_int->debug);
380
381 cherokee_dwriter_cstring (dwriter, "timeout");
382 cherokee_dwriter_integer (dwriter, source_int->timeout);
383
384 cherokee_dwriter_cstring (dwriter, "interpreter");
385 cherokee_dwriter_bstring (dwriter, &source_int->interpreter);
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
386 }
387
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
388 cherokee_dwriter_dict_close (dwriter);
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
389 return ret_ok;
390 }
391
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
392 ret_t
393 cherokee_admin_server_reply_get_sources (cherokee_handler_t *hdl,
394 cherokee_dwriter_t *dwriter)
395 {
396 cherokee_server_t *srv = HANDLER_SRV(hdl);
397
398 cherokee_dwriter_list_open (dwriter);
399 cherokee_avl_while (&srv->sources, sources_while, dwriter, NULL, NULL);
400 cherokee_dwriter_list_close (dwriter);
401
402 return ret_ok;
403 }
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
404
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
405 ret_t
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
406 cherokee_admin_server_reply_kill_source (cherokee_handler_t *hdl,
407 cherokee_dwriter_t *dwriter,
408 cherokee_buffer_t *question)
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
409 {
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
410 ret_t ret;
411 char *begin;
d12e63b @alobbs Enhances cherokee_admin_server_reply_kill_source(). It is not finished
alobbs authored
412 char *end;
413 char *p;
414 cuint_t n;
415 char id[10];
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
416 cherokee_source_t *source = NULL;
417 cherokee_server_t *srv = HANDLER_SRV(hdl);
418
d12e63b @alobbs Enhances cherokee_admin_server_reply_kill_source(). It is not finished
alobbs authored
419 /* Check the command
420 */
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
421 if (strncmp (question->buf, "kill server.source ", sizeof("kill server.source ")-1)) {
422 return ret_error;
423 }
424 begin = question->buf + sizeof("kill server.source ")-1;
d12e63b @alobbs Enhances cherokee_admin_server_reply_kill_source(). It is not finished
alobbs authored
425 end = question->buf + question->len;
426
427 /* Check the source to be killed
428 */
429 n = 0;
430 p = begin;
431 while (CHEROKEE_CHAR_IS_DIGIT(*p) && (p < end)) {
432 id[n] = *p;
433 p++;
434 n++;
435 }
436 id[n] = '\0';
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
437
d12e63b @alobbs Enhances cherokee_admin_server_reply_kill_source(). It is not finished
alobbs authored
438 if (unlikely ((n <= 0) || (n >= sizeof(n)))) {
439 cherokee_dwriter_dict_open (dwriter);
440 cherokee_dwriter_cstring (dwriter, "source");
441 cherokee_dwriter_cstring (dwriter, "invalid");
442 cherokee_dwriter_dict_close (dwriter);
443 return ret_ok;
444 }
445
446 /* Find it on the AVL tree
447 */
448 ret = cherokee_avl_get_ptr (&srv->sources, id, (void **)&source);
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
449 if (ret != ret_ok) {
450 cherokee_dwriter_dict_open (dwriter);
451 cherokee_dwriter_cstring (dwriter, "source");
452 cherokee_dwriter_cstring (dwriter, "not found");
453 cherokee_dwriter_dict_close (dwriter);
454 return ret_ok;
455 }
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
456
8507a57 @skinkie Implements an extra check after cherokee_avl_get_ptr where the return…
skinkie authored
457 if ((source != NULL) &&
458 ((source->type != source_interpreter) ||
459 ((source->type == source_interpreter) && (SOURCE_INT(source)->pid <= 1))))
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
460 {
461 cherokee_dwriter_dict_open (dwriter);
462 cherokee_dwriter_cstring (dwriter, "source");
463 cherokee_dwriter_cstring (dwriter, "nothing to kill");
464 cherokee_dwriter_dict_close (dwriter);
465 return ret_ok;
466 }
651edbd @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1439 5dc97367-9…
alobbs authored
467
d12e63b @alobbs Enhances cherokee_admin_server_reply_kill_source(). It is not finished
alobbs authored
468 /* Kill the process
469 */
470 if (getuid() == 0) {
471 /* Looks like we can actully kill the process
472 */
473 kill (SOURCE_INT(source)->pid, SIGTERM);
474 goto ok;
475 } else {
476 /* It should be the 'cherokee' supervisor (running as root)
477 * the one in charge of killing the process.
478 */
479 // TODO
480 }
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
481
d12e63b @alobbs Enhances cherokee_admin_server_reply_kill_source(). It is not finished
alobbs authored
482 ok:
197ba3c @alobbs The admin_client classes are not longer needed, so libcherokee-config
alobbs authored
483 cherokee_dwriter_dict_open (dwriter);
484 cherokee_dwriter_cstring (dwriter, "source");
485 cherokee_dwriter_cstring (dwriter, "killed");
486 cherokee_dwriter_dict_close (dwriter);
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
487 return ret_ok;
488 }
Something went wrong with that request. Please try again.