13 #include <fcgi_stdio.h>
16 #include "graph_list.h"
17 #include "utils_params.h"
19 #include "action_graph.h"
20 #include "action_list_graphs.h"
25 int (*callback) (void);
27 typedef struct action_s action_t;
35 typedef struct str_array_s str_array_t;
38 static int action_usage (void);
40 static const action_t actions[] =
42 { "graph", action_graph },
43 { "list_graphs", action_list_graphs },
44 { "usage", action_usage }
46 static const size_t actions_num = sizeof (actions) / sizeof (actions[0]);
49 static str_array_t *array_alloc (void) /* {{{ */
53 a = malloc (sizeof (*a));
57 memset (a, 0, sizeof (*a));
62 } /* }}} str_array_t *array_alloc */
64 static void array_free (str_array_t *a) /* {{{ */
74 } /* }}} void array_free */
76 static int array_add (const char *entry, void *user_data) /* {{{ */
78 str_array_t *a = user_data;
81 if ((entry == NULL) || (a == NULL))
84 ptr = realloc (a->ptr, sizeof (*a->ptr) * (a->size + 1));
88 ptr = a->ptr + a->size;
90 *ptr = strdup (entry);
96 } /* }}} int array_add */
99 static int action_usage (void) /* {{{ */
103 printf ("Content-Type: text/plain\n\n");
107 " Available actions:\n"
110 for (i = 0; i < actions_num; i++)
111 printf (" * %s\n", actions[i].name);
116 } /* }}} int action_usage */
118 static int handle_request (void) /* {{{ */
124 action = param ("action");
127 return (action_usage ());
133 for (i = 0; i < actions_num; i++)
135 if (strcmp (action, actions[i].name) == 0)
136 return ((*actions[i].callback) ());
139 return (action_usage ());
141 } /* }}} int handle_request */
143 static int run (void) /* {{{ */
145 while (FCGI_Accept() >= 0)
154 int main (int argc, char **argv) /* {{{ */
162 status = handle_request ();
166 exit ((status == 0) ? EXIT_SUCCESS : EXIT_FAILURE);
169 /* vim: set sw=2 sts=2 et fdm=marker : */