13 #include <fcgi_stdio.h>
16 #include "graph_list.h"
17 #include "utils_params.h"
24 typedef struct str_array_s str_array_t;
26 static str_array_t *array_alloc (void) /* {{{ */
30 a = malloc (sizeof (*a));
34 memset (a, 0, sizeof (*a));
39 } /* }}} str_array_t *array_alloc */
41 static void array_free (str_array_t *a) /* {{{ */
51 } /* }}} void array_free */
53 static int array_add (const char *entry, void *user_data) /* {{{ */
55 str_array_t *a = user_data;
58 if ((entry == NULL) || (a == NULL))
61 ptr = realloc (a->ptr, sizeof (*a->ptr) * (a->size + 1));
65 ptr = a->ptr + a->size;
67 *ptr = strdup (entry);
73 } /* }}} int array_add */
75 static int print_graph (const graph_list_t *gl, void *user_data)
80 printf ("host = %s; plugin = %s;", gl->host, gl->plugin);
81 if (gl->plugin_instance != NULL)
82 printf (" plugin_instance = %s;", gl->plugin_instance);
83 printf (" type = %s;", gl->type);
84 if (gl->type_instance != NULL)
85 printf (" type_instance = %s;", gl->type_instance);
89 } /* }}} int print_graph */
91 static int get_graphs_list (char ***ret_graphs, /* {{{ */
92 size_t *ret_graphs_num)
95 gl_foreach (print_graph, /* user_data = */ NULL);
98 } /* }}} int get_graphs_list */
100 static int action_hello (void) /* {{{ */
102 printf ("Content-Type: text/plain\n\n");
104 get_graphs_list (NULL, NULL);
107 } /* }}} int action_hello */
109 static int action_usage (void) /* {{{ */
111 printf ("Content-Type: text/plain\n\n");
115 " Available actions:\n"
121 } /* }}} int action_usage */
123 static int handle_request (void) /* {{{ */
129 action = param ("action");
132 return (action_usage ());
134 else if (strcmp ("hello", action) == 0)
136 return (action_hello ());
140 return (action_usage ());
142 } /* }}} int handle_request */
144 static int run (void) /* {{{ */
146 while (FCGI_Accept() >= 0)
155 int main (int argc, char **argv) /* {{{ */
163 status = handle_request ();
167 exit ((status == 0) ? EXIT_SUCCESS : EXIT_FAILURE);
170 /* vim: set sw=2 sts=2 et fdm=marker : */