6 #include "action_list_graphs.h"
9 #include "graph_ident.h"
10 #include "graph_list.h"
11 #include "utils_cgi.h"
14 #include <fcgi_stdio.h>
16 #define RESULT_LIMIT 50
18 struct callback_data_s
24 typedef struct callback_data_s callback_data_t;
26 static int print_graph_inst_html (graph_config_t *cfg, /* {{{ */
27 graph_instance_t *inst,
30 callback_data_t *data = user_data;
36 if (data->cfg != NULL)
37 printf (" </ul></li>\n");
39 memset (desc, 0, sizeof (desc));
40 graph_get_title (cfg, desc, sizeof (desc));
41 html_escape_buffer (desc, sizeof (desc));
43 printf (" <li class=\"graph\">%s\n"
44 " <ul class=\"instance_list\">\n", desc);
49 memset (params, 0, sizeof (params));
50 inst_get_params (cfg, inst, params, sizeof (params));
51 html_escape_buffer (params, sizeof (params));
53 memset (desc, 0, sizeof (desc));
54 inst_describe (cfg, inst, desc, sizeof (desc));
55 html_escape_buffer (desc, sizeof (desc));
57 printf (" <li class=\"instance\"><a href=\"%s?action=graph;%s\">%s</a></li>\n",
58 script_name (), params, desc);
63 /* Abort scan if limit is reached. */
68 } /* }}} int print_graph_inst_html */
72 const char *search_term;
74 typedef struct page_data_s page_data_t;
76 static int print_search_result (void *user_data) /* {{{ */
78 page_data_t *pg_data = user_data;
79 callback_data_t cb_data = { NULL, /* limit = */ RESULT_LIMIT, /* first = */ 1 };
81 if (pg_data->search_term != NULL)
83 char *search_term_html = html_escape (pg_data->search_term);
84 printf (" <h2>Search results for "%s"</h2>\n",
86 free (search_term_html);
89 printf (" <ul id=\"search-output\" class=\"graph_list\">\n");
90 if (pg_data->search_term == NULL)
91 gl_instance_get_all (print_graph_inst_html, /* user_data = */ &cb_data);
94 char *term_lc = strtolower_copy (pg_data->search_term);
95 gl_search (term_lc, print_graph_inst_html, /* user_data = */ &cb_data);
99 if (cb_data.cfg != NULL)
100 printf (" </ul></li>\n");
105 } /* }}} int print_search_result */
107 struct print_host_list_data_s
112 typedef struct print_host_list_data_s print_host_list_data_t;
114 static int print_host_list_callback (graph_config_t *cfg, /* {{{ */
115 graph_instance_t *inst, void *user_data)
117 print_host_list_data_t *data = user_data;
118 graph_ident_t *ident;
121 /* make compiler happy */
124 ident = inst_get_selector (inst);
128 host = ident_get_host (ident);
131 ident_destroy (ident);
138 if ((data->last_host != NULL)
139 && (strcmp (data->last_host, host) == 0))
141 ident_destroy (ident);
145 free (data->last_host);
146 data->last_host = strdup (host);
148 array_append (data->array, host);
150 ident_destroy (ident);
152 } /* }}} int print_host_list_callback */
154 static int print_host_list (__attribute__((unused)) void *user_data) /* {{{ */
156 print_host_list_data_t data;
161 data.array = array_create ();
162 data.last_host = NULL;
164 gl_instance_get_all (print_host_list_callback, &data);
166 free (data.last_host);
167 data.last_host = NULL;
169 array_sort (data.array);
171 hosts_argc = array_argc (data.array);
172 hosts_argv = array_argv (data.array);
176 array_destroy (data.array);
180 printf ("<ul id=\"host-list\">\n");
181 for (i = 0; i < hosts_argc; i++)
183 char *host = hosts_argv[i];
186 if ((data.last_host != NULL) && (strcmp (data.last_host, host) == 0))
188 data.last_host = host;
190 host_html = html_escape (host);
192 printf (" <li><a href=\"%s?action=list_graphs&search=%s\">%s</a></li>\n",
193 script_name (), host_html, host_html);
199 array_destroy (data.array);
202 } /* }}} int print_host_list */
204 static int list_graphs_html (const char *term) /* {{{ */
207 page_callbacks_t pg_callbacks = PAGE_CALLBACKS_INIT;
211 snprintf (title, sizeof (title), "c4: Graphs matching \"%s\"", term);
213 strncpy (title, "c4: List of all graphs", sizeof (title));
214 title[sizeof (title) - 1] = 0;
216 memset (&pg_data, 0, sizeof (pg_data));
217 pg_data.search_term = term;
219 pg_callbacks.top_right = html_print_search_box;
220 pg_callbacks.middle_left = print_host_list;
221 pg_callbacks.middle_center = print_search_result;
223 html_print_page (title, &pg_callbacks, &pg_data);
226 } /* }}} int list_graphs_html */
228 int action_list_graphs (void) /* {{{ */
235 search = strtolower_copy (param ("search"));
237 status = list_graphs_html (search);
242 } /* }}} int action_list_graphs */
244 /* vim: set sw=2 sts=2 et fdm=marker : */