From: Florian Forster Date: Sun, 2 May 2010 07:11:29 +0000 (+0200) Subject: action_list_graphs.c: Implement real simple HTML output. X-Git-Tag: v4.0.0~299 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=7549e5e9405595cc9069faa86478de3a65a61ce2;p=collection4.git action_list_graphs.c: Implement real simple HTML output. --- diff --git a/action_list_graphs.c b/action_list_graphs.c index 8c78ac1..9fc8f45 100644 --- a/action_list_graphs.c +++ b/action_list_graphs.c @@ -7,8 +7,9 @@ #include #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; @@ -39,19 +40,63 @@ static int print_graph (const graph_list_t *gl, void *user_data) /* {{{ */ 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 ("
  • %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 ("
  • \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 ("\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 : */