6 #include "action_list_graphs.h"
8 #include "graph_ident.h"
9 #include "graph_list.h"
10 #include "utils_params.h"
13 #include <fcgi_stdio.h>
15 static int print_graph_inst_json (__attribute__((unused)) graph_config_t *cfg, /* {{{ */
16 graph_instance_t *inst,
25 ident = inst_get_selector (inst);
29 json = ident_to_json (ident);
32 ident_destroy (ident);
39 printf (",\n%s", json);
43 ident_destroy (ident);
45 } /* }}} int print_graph_inst_json */
47 static int print_graph_json (graph_config_t *cfg, /* {{{ */
50 return (gl_graph_instance_get_all (cfg, print_graph_inst_json, user_data));
51 } /* }}} int print_graph_json */
53 static int list_graphs_json (void) /* {{{ */
57 printf ("Content-Type: application/json\n\n");
60 gl_graph_get_all (print_graph_json, /* user_data = */ &first);
64 } /* }}} int list_graphs_json */
66 struct callback_data_s
70 typedef struct callback_data_s callback_data_t;
72 static int print_graph_inst_html (graph_config_t *cfg, /* {{{ */
73 graph_instance_t *inst,
76 callback_data_t *data = user_data;
82 if (data->cfg != NULL)
83 printf (" </ul></li>\n");
85 memset (desc, 0, sizeof (desc));
86 graph_get_title (cfg, desc, sizeof (desc));
88 printf (" <li>%s\n <ul>\n", desc);
93 memset (params, 0, sizeof (params));
94 inst_get_params (cfg, inst, params, sizeof (params));
96 memset (desc, 0, sizeof (desc));
97 inst_describe (cfg, inst, desc, sizeof (desc));
99 printf (" <li><a href=\"%s?action=graph;%s\">%s</a></li>\n",
100 script_name (), params, desc);
103 } /* }}} int print_graph_inst_html */
105 static int list_graphs_html (const char *term) /* {{{ */
107 callback_data_t data = { NULL };
108 printf ("Content-Type: text/html\n\n");
110 printf ("<html>\n <head>\n");
112 printf (" <title>c4: Graphs matching "%s"</title>\n", term);
114 printf (" <title>c4: List of all graphs</title>\n");
115 printf (" </head>\n <body>\n");
117 printf ("<form action=\"%s\" method=\"get\">\n"
118 " <input type=\"hidden\" name=\"action\" value=\"list_graphs\" />\n"
119 " <input type=\"text\" name=\"search\" value=\"%s\" />\n"
120 " <input type=\"submit\" name=\"button\" value=\"Search\" />\n"
122 script_name (), (term != NULL) ? term : "");
126 gl_instance_get_all (print_graph_inst_html, /* user_data = */ &data);
128 gl_search (term, print_graph_inst_html, /* user_data = */ &data);
130 if (data.cfg != NULL)
131 printf (" </ul></li>\n");
135 printf (" </body>\n</html>\n");
138 } /* }}} int list_graphs_html */
140 int action_list_graphs (void) /* {{{ */
146 format = param ("format");
150 if (strcmp ("json", format) == 0)
151 return (list_graphs_json ());
153 return (list_graphs_html (param ("search")));
154 } /* }}} int action_list_graphs */
156 /* vim: set sw=2 sts=2 et fdm=marker : */