3 * Copyright (C) 2010 Florian octo Forster
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA
21 * Florian octo Forster <ff at octo.it>
30 #include <sys/types.h>
36 #include "graph_list.h"
37 #include "utils_cgi.h"
39 #include "action_graph.h"
40 #include "action_graph_def_json.h"
41 #include "action_list_graphs.h"
42 #include "action_list_hosts.h"
43 #include "action_search.h"
44 #include "action_search_json.h"
45 #include "action_show_graph.h"
46 #include "action_show_graph_json.h"
47 #include "action_show_instance.h"
49 /* Include this last, so the macro magic of <fcgi_stdio.h> doesn't interfere
50 * with our own header files. */
52 #include <fcgi_stdio.h>
57 int (*callback) (void);
59 typedef struct action_s action_t;
61 static int action_usage (void);
63 static const action_t actions[] =
65 { "graph", action_graph },
66 { "graph_def_json", action_graph_def_json },
67 { "list_graphs", action_list_graphs },
68 { "list_hosts", action_list_hosts },
69 { "search", action_search },
70 { "search_json", action_search_json },
71 { "show_graph", action_show_graph },
72 { "show_graph_json", action_show_graph_json },
73 { "show_instance", action_show_instance },
74 { "usage", action_usage }
76 static const size_t actions_num = sizeof (actions) / sizeof (actions[0]);
79 static int action_usage (void) /* {{{ */
83 printf ("Content-Type: text/plain\n\n");
87 " Available actions:\n"
90 for (i = 0; i < actions_num; i++)
91 printf (" * %s\n", actions[i].name);
96 } /* }}} int action_usage */
98 static int handle_request (void) /* {{{ */
104 action = param ("action");
107 return (action_usage ());
114 gl_update (/* request_served = */ 0);
116 for (i = 0; i < actions_num; i++)
118 if (strcmp (action, actions[i].name) == 0)
120 status = (*actions[i].callback) ();
125 if (i >= actions_num)
126 status = action_usage ();
131 gl_update (/* request_served = */ 1);
135 } /* }}} int handle_request */
137 static int run (void) /* {{{ */
139 while (FCGI_Accept() >= 0)
148 int main (int argc, char **argv) /* {{{ */
156 status = handle_request ();
160 exit ((status == 0) ? EXIT_SUCCESS : EXIT_FAILURE);
163 /* vim: set sw=2 sts=2 et fdm=marker : */