9 #include "action_show_graph.h"
11 #include "graph_list.h"
12 #include "utils_cgi.h"
15 #include <fcgi_stdio.h>
17 #define OUTPUT_ERROR(...) do { \
18 printf ("Content-Type: text/plain\n\n"); \
19 printf (__VA_ARGS__); \
23 struct show_graph_data_s
26 graph_instance_t *inst;
28 typedef struct show_graph_data_s show_graph_data_t;
30 static int show_instance_list_cb (graph_instance_t *inst, /* {{{ */
33 show_graph_data_t *data = user_data;
37 memset (descr, 0, sizeof (descr));
38 inst_describe (data->cfg, inst, descr, sizeof (descr));
39 html_escape_buffer (descr, sizeof (descr));
41 if (inst == data->inst)
43 printf (" <li class=\"instance\"><strong>%s</strong></li>\n", descr);
47 memset (params, 0, sizeof (params));
48 inst_get_params (data->cfg, inst, params, sizeof (params));
49 html_escape_buffer (params, sizeof (params));
51 printf (" <li class=\"instance\"><a href=\"%s?action=show_graph;%s\">%s</a></li>\n",
52 script_name (), params, descr);
55 } /* }}} int show_instance_list_cb */
57 static int show_instance_list (void *user_data) /* {{{ */
59 show_graph_data_t *data = user_data;
60 graph_instance_t *inst;
63 memset (title, 0, sizeof (title));
64 graph_get_title (data->cfg, title, sizeof (title));
65 html_escape_buffer (title, sizeof (title));
67 printf ("<ul class=\"graph_list\">\n"
68 " <li class=\"graph\">%s\n"
69 " <ul class=\"instance_list\">\n", title);
71 inst = graph_get_instances (data->cfg);
72 inst_foreach (inst, show_instance_list_cb, user_data);
78 } /* }}} int show_instance_list */
80 static int show_graph (void *user_data) /* {{{ */
82 show_graph_data_t *data = user_data;
87 memset (title, 0, sizeof (title));
88 graph_get_title (data->cfg, title, sizeof (title));
89 html_escape_buffer (title, sizeof (title));
91 memset (descr, 0, sizeof (descr));
92 inst_describe (data->cfg, data->inst, descr, sizeof (descr));
93 html_escape_buffer (descr, sizeof (descr));
95 memset (params, 0, sizeof (params));
96 inst_get_params (data->cfg, data->inst, params, sizeof (params));
97 html_escape_buffer (params, sizeof (params));
99 printf ("<div class=\"graph-img\"><img src=\"%s?action=graph;%s\" "
100 "title=\"%s / %s\" /></div>\n",
101 script_name (), params, title, descr);
104 } /* }}} int show_graph */
106 int action_show_graph (void) /* {{{ */
108 page_callbacks_t pg_callbacks = PAGE_CALLBACKS_INIT;
109 show_graph_data_t pg_data;
113 char html_title[128];
115 pg_data.cfg = gl_graph_get_selected ();
116 if (pg_data.cfg == NULL)
117 OUTPUT_ERROR ("gl_graph_get_selected () failed.\n");
119 pg_data.inst = inst_get_selected (pg_data.cfg);
120 if (pg_data.inst == NULL)
121 OUTPUT_ERROR ("inst_get_selected (%p) failed.\n", (void *) pg_data.cfg);
123 memset (title, 0, sizeof (title));
124 graph_get_title (pg_data.cfg, title, sizeof (title));
126 memset (descr, 0, sizeof (descr));
127 inst_describe (pg_data.cfg, pg_data.inst, descr, sizeof (descr));
129 snprintf (html_title, sizeof (html_title), "Graph \"%s / %s\"",
131 html_title[sizeof (html_title) - 1] = 0;
133 pg_callbacks.top_right = html_print_search_box;
134 pg_callbacks.middle_center = show_graph;
135 pg_callbacks.middle_left = show_instance_list;
137 html_print_page (html_title, &pg_callbacks, &pg_data);
140 } /* }}} int action_graph */
142 /* vim: set sw=2 sts=2 et fdm=marker : */