13 #include "graph_list.h"
14 #include "utils_cgi.h"
16 #include "action_graph.h"
17 #include "action_list_graphs.h"
18 #include "action_search_json.h"
19 #include "action_show_instance.h"
21 /* Include this last, so the macro magic of <fcgi_stdio.h> doesn't interfere
22 * with our own header files. */
24 #include <fcgi_stdio.h>
29 int (*callback) (void);
31 typedef struct action_s action_t;
33 static int action_usage (void);
35 static const action_t actions[] =
37 { "graph", action_graph },
38 { "list_graphs", action_list_graphs },
39 { "search_json", action_search_json },
40 { "show_instance", action_show_instance },
41 { "usage", action_usage }
43 static const size_t actions_num = sizeof (actions) / sizeof (actions[0]);
46 static int action_usage (void) /* {{{ */
50 printf ("Content-Type: text/plain\n\n");
54 " Available actions:\n"
57 for (i = 0; i < actions_num; i++)
58 printf (" * %s\n", actions[i].name);
63 } /* }}} int action_usage */
65 static int handle_request (void) /* {{{ */
71 action = param ("action");
74 return (action_usage ());
80 for (i = 0; i < actions_num; i++)
82 if (strcmp (action, actions[i].name) == 0)
83 return ((*actions[i].callback) ());
86 return (action_usage ());
88 } /* }}} int handle_request */
90 static int run (void) /* {{{ */
92 while (FCGI_Accept() >= 0)
101 int main (int argc, char **argv) /* {{{ */
109 status = handle_request ();
113 exit ((status == 0) ? EXIT_SUCCESS : EXIT_FAILURE);
116 /* vim: set sw=2 sts=2 et fdm=marker : */