13 #include <fcgi_stdio.h>
16 #include "graph_list.h"
17 #include "utils_params.h"
19 #include "action_list_graphs.h"
26 typedef struct str_array_s str_array_t;
28 static str_array_t *array_alloc (void) /* {{{ */
32 a = malloc (sizeof (*a));
36 memset (a, 0, sizeof (*a));
41 } /* }}} str_array_t *array_alloc */
43 static void array_free (str_array_t *a) /* {{{ */
53 } /* }}} void array_free */
55 static int array_add (const char *entry, void *user_data) /* {{{ */
57 str_array_t *a = user_data;
60 if ((entry == NULL) || (a == NULL))
63 ptr = realloc (a->ptr, sizeof (*a->ptr) * (a->size + 1));
67 ptr = a->ptr + a->size;
69 *ptr = strdup (entry);
75 } /* }}} int array_add */
77 static int print_graph (const graph_list_t *gl, void *user_data) /* {{{ */
82 printf ("host = %s; plugin = %s;", gl->host, gl->plugin);
83 if (gl->plugin_instance != NULL)
84 printf (" plugin_instance = %s;", gl->plugin_instance);
85 printf (" type = %s;", gl->type);
86 if (gl->type_instance != NULL)
87 printf (" type_instance = %s;", gl->type_instance);
91 } /* }}} int print_graph */
93 static int get_graphs_list (char ***ret_graphs, /* {{{ */
94 size_t *ret_graphs_num)
97 gl_foreach (print_graph, /* user_data = */ NULL);
100 } /* }}} int get_graphs_list */
102 static int action_hello (void) /* {{{ */
104 printf ("Content-Type: text/plain\n\n");
106 get_graphs_list (NULL, NULL);
109 } /* }}} int action_hello */
111 static int action_usage (void) /* {{{ */
113 printf ("Content-Type: text/plain\n\n");
117 " Available actions:\n"
123 } /* }}} int action_usage */
125 static int handle_request (void) /* {{{ */
131 action = param ("action");
134 return (action_usage ());
136 else if (strcmp ("list_graphs", action) == 0)
138 return (action_list_graphs ());
140 else if (strcmp ("hello", action) == 0)
142 return (action_hello ());
146 return (action_usage ());
148 } /* }}} int handle_request */
150 static int run (void) /* {{{ */
152 while (FCGI_Accept() >= 0)
161 int main (int argc, char **argv) /* {{{ */
169 status = handle_request ();
173 exit ((status == 0) ? EXIT_SUCCESS : EXIT_FAILURE);
176 /* vim: set sw=2 sts=2 et fdm=marker : */