From 5cc627425e6502b8a025cee810c14136e69071cc Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Fri, 30 Apr 2010 15:35:40 +0200 Subject: [PATCH] Add the "list_graphs" action. --- Makefile | 4 +++- action_list_graphs.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ action_list_graphs.h | 7 +++++++ fcgi_test.c | 8 +++++++- 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 action_list_graphs.c create mode 100644 action_list_graphs.h diff --git a/Makefile b/Makefile index 970d85f..7360c5a 100644 --- a/Makefile +++ b/Makefile @@ -15,10 +15,12 @@ graph_list.o: graph_list.c graph_list.h utils_params.o: utils_params.c utils_params.h +action_list_graphs.o: action_list_graphs.c action_list_graphs.h + test: test.c utils_params.o fcgi_test: LDLIBS = -lfcgi -fcgi_test: fcgi_test.c common.o graph_list.o utils_params.o +fcgi_test: fcgi_test.c common.o graph_list.o utils_params.o action_list_graphs.o .PHONY: clean diff --git a/action_list_graphs.c b/action_list_graphs.c new file mode 100644 index 0000000..8c78ac1 --- /dev/null +++ b/action_list_graphs.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include + +#include +#include + +#include "graph_list.h" + +static int print_graph (const graph_list_t *gl, void *user_data) /* {{{ */ +{ + _Bool *first; + + if ((gl == NULL) || (user_data == NULL)) + return (EINVAL); + + first = (_Bool *) user_data; + if (!*first) + printf (",\n"); + *first = 0; + + printf (" {"); + + printf ("\"host\":\"%s\"", gl->host); + + printf (",\"plugin\":\"%s\"", gl->plugin); + if (gl->plugin_instance != NULL) + printf (",\"plugin_instance\":\"%s\"", gl->plugin_instance); + else + printf (",\"plugin_instance\":null"); + + printf (",\"type\":\"%s\"", gl->type); + if (gl->type_instance != NULL) + printf (",\"type_instance\":\"%s\"", gl->type_instance); + else + printf (",\"type_instance\":null"); + + printf ("}"); + + return (0); +} /* }}} int print_graph */ + +int action_list_graphs (void) /* {{{ */ +{ + _Bool first = 1; + + printf ("Content-Type: text/plain\n\n"); + + gl_update (); + + printf ("[\n"); + gl_foreach (print_graph, /* user_data = */ &first); + printf ("\n]"); +} /* }}} int action_list_graphs */ + +/* vim: set sw=2 sts=2 et fdm=marker : */ diff --git a/action_list_graphs.h b/action_list_graphs.h new file mode 100644 index 0000000..dd7edf9 --- /dev/null +++ b/action_list_graphs.h @@ -0,0 +1,7 @@ +#ifndef ACTION_LIST_GRAPHS_H +#define ACTION_LIST_GRAPHS_H 1 + +int action_list_graphs (void); + +#endif /* ACTION_LIST_GRAPHS_H */ +/* vim: set sw=2 sts=2 et fdm=marker : */ diff --git a/fcgi_test.c b/fcgi_test.c index e0d3035..a6ca107 100644 --- a/fcgi_test.c +++ b/fcgi_test.c @@ -16,6 +16,8 @@ #include "graph_list.h" #include "utils_params.h" +#include "action_list_graphs.h" + struct str_array_s { char **ptr; @@ -72,7 +74,7 @@ static int array_add (const char *entry, void *user_data) /* {{{ */ return (0); } /* }}} int array_add */ -static int print_graph (const graph_list_t *gl, void *user_data) +static int print_graph (const graph_list_t *gl, void *user_data) /* {{{ */ { if (gl == NULL) return (EINVAL); @@ -131,6 +133,10 @@ static int handle_request (void) /* {{{ */ { return (action_usage ()); } + else if (strcmp ("list_graphs", action) == 0) + { + return (action_list_graphs ()); + } else if (strcmp ("hello", action) == 0) { return (action_hello ()); -- 2.11.0