summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c2cff27)
raw | patch | inline | side by side (parent: c2cff27)
author | Florian Forster <ff@octo.it> | |
Sun, 2 May 2010 07:11:29 +0000 (09:11 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 2 May 2010 07:11:29 +0000 (09:11 +0200) |
action_list_graphs.c | patch | blob | history |
diff --git a/action_list_graphs.c b/action_list_graphs.c
index 8c78ac10428e508ccd9c494923b0acbb72bc1bb8..9fc8f45a5079207721a1084fb569c1b6073c7b29 100644 (file)
--- a/action_list_graphs.c
+++ b/action_list_graphs.c
#include <fcgi_stdio.h>
#include "graph_list.h"
+#include "utils_params.h"
-static int print_graph (const graph_list_t *gl, void *user_data) /* {{{ */
+static int print_graph_json (const graph_list_t *gl, void *user_data) /* {{{ */
{
_Bool *first;
printf ("}");
return (0);
-} /* }}} int print_graph */
+} /* }}} int print_graph_json */
-int action_list_graphs (void) /* {{{ */
+static int print_graph_html (const graph_list_t *gl,
+ void __attribute__((unused)) *user_data)
{
- _Bool first = 1;
+ if (gl == NULL)
+ return (EINVAL);
- printf ("Content-Type: text/plain\n\n");
+ printf ("<li>%s/%s", gl->host, gl->plugin);
+ if (gl->plugin_instance != NULL)
+ printf ("-%s", gl->plugin_instance);
+ printf ("/%s", gl->type);
+ if (gl->type_instance != NULL)
+ printf ("-%s", gl->type_instance);
+ printf ("</li>\n");
- gl_update ();
+ return (0);
+}
+
+static int list_graphs_json (void) /* {{{ */
+{
+ _Bool first = 1;
+
+ printf ("Content-Type: application/json\n\n");
printf ("[\n");
- gl_foreach (print_graph, /* user_data = */ &first);
+ gl_foreach (print_graph_json, /* user_data = */ &first);
printf ("\n]");
+
+ return (0);
+} /* }}} int list_graphs_json */
+
+static int list_graphs_html (void) /* {{{ */
+{
+ printf ("Content-Type: text/html\n\n");
+
+ printf ("<ul>\n");
+ gl_foreach (print_graph_html, /* user_data = */ NULL);
+ printf ("</ul>\n");
+
+ return (0);
+} /* }}} int list_graphs_html */
+
+int action_list_graphs (void) /* {{{ */
+{
+ const char *format;
+
+ gl_update ();
+
+ format = param ("format");
+ if (format == NULL)
+ format = "html";
+
+ if (strcmp ("json", format) == 0)
+ return (list_graphs_json ());
+ else
+ return (list_graphs_html ());
} /* }}} int action_list_graphs */
/* vim: set sw=2 sts=2 et fdm=marker : */