X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=action_list_graphs.c;h=14a13bbc6211c9ba6338a7388c7d6b0d2f9a6dca;hb=052657ddb5a25bf53e3ad4a0a5ec3c3afd48ec8c;hp=8c78ac10428e508ccd9c494923b0acbb72bc1bb8;hpb=5cc627425e6502b8a025cee810c14136e69071cc;p=collection4.git diff --git a/action_list_graphs.c b/action_list_graphs.c index 8c78ac1..14a13bb 100644 --- a/action_list_graphs.c +++ b/action_list_graphs.c @@ -6,9 +6,11 @@ #include #include +#include "action_list_graphs.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; @@ -39,19 +41,74 @@ 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 ("
  • "); - gl_update (); + printf ("host, gl->plugin); + if (gl->plugin_instance != NULL) + printf ("plugin_instance=%s;", gl->plugin_instance); + printf ("type=%s;", gl->type); + if (gl->type_instance != NULL) + printf ("type_instance=%s;", gl->type_instance); + printf ("\">"); + + 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"); + + 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 : */