summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9e57703)
raw | patch | inline | side by side (parent: 9e57703)
author | Florian Forster <ff@octo.it> | |
Fri, 30 Apr 2010 13:35:40 +0000 (15:35 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Fri, 30 Apr 2010 13:35:40 +0000 (15:35 +0200) |
Makefile | patch | blob | history | |
action_list_graphs.c | [new file with mode: 0644] | patch | blob |
action_list_graphs.h | [new file with mode: 0644] | patch | blob |
fcgi_test.c | patch | blob | history |
diff --git a/Makefile b/Makefile
index 970d85f2c93d34453ff3683697807abb791d5520..7360c5ad9a5b5eee0001ac80fbee682e1d6a62ef 100644 (file)
--- a/Makefile
+++ b/Makefile
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
--- /dev/null
+++ b/action_list_graphs.c
@@ -0,0 +1,57 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include <fcgiapp.h>
+#include <fcgi_stdio.h>
+
+#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
--- /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 e0d303575267dd6de122624e3d9fd0a3e762bf48..a6ca107217399ca4bc7009de77dfe1dc72bf5246 100644 (file)
--- a/fcgi_test.c
+++ b/fcgi_test.c
#include "graph_list.h"
#include "utils_params.h"
+#include "action_list_graphs.h"
+
struct str_array_s
{
char **ptr;
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);
{
return (action_usage ());
}
+ else if (strcmp ("list_graphs", action) == 0)
+ {
+ return (action_list_graphs ());
+ }
else if (strcmp ("hello", action) == 0)
{
return (action_hello ());