13 #include <fcgi_stdio.h>
16 #include "graph_list.h"
17 #include "utils_params.h"
19 #include "action_list_graphs.h"
24 int (*callback) (void);
26 typedef struct action_s action_t;
34 typedef struct str_array_s str_array_t;
37 static int action_usage (void);
39 static const action_t actions[] =
41 { "list_graphs", action_list_graphs },
42 { "usage", action_usage }
44 static const size_t actions_num = sizeof (actions) / sizeof (actions[0]);
47 static str_array_t *array_alloc (void) /* {{{ */
51 a = malloc (sizeof (*a));
55 memset (a, 0, sizeof (*a));
60 } /* }}} str_array_t *array_alloc */
62 static void array_free (str_array_t *a) /* {{{ */
72 } /* }}} void array_free */
74 static int array_add (const char *entry, void *user_data) /* {{{ */
76 str_array_t *a = user_data;
79 if ((entry == NULL) || (a == NULL))
82 ptr = realloc (a->ptr, sizeof (*a->ptr) * (a->size + 1));
86 ptr = a->ptr + a->size;
88 *ptr = strdup (entry);
94 } /* }}} int array_add */
97 static int action_usage (void) /* {{{ */
101 printf ("Content-Type: text/plain\n\n");
105 " Available actions:\n"
108 for (i = 0; i < actions_num; i++)
109 printf (" * %s\n", actions[i].name);
114 } /* }}} int action_usage */
116 static int handle_request (void) /* {{{ */
122 action = param ("action");
125 return (action_usage ());
131 for (i = 0; i < actions_num; i++)
133 if (strcmp (action, actions[i].name) == 0)
134 return ((*actions[i].callback) ());
137 return (action_usage ());
139 } /* }}} int handle_request */
141 static int run (void) /* {{{ */
143 while (FCGI_Accept() >= 0)
152 int main (int argc, char **argv) /* {{{ */
160 status = handle_request ();
164 exit ((status == 0) ? EXIT_SUCCESS : EXIT_FAILURE);
167 /* vim: set sw=2 sts=2 et fdm=marker : */