6 #include "action_search_json.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 10
18 struct callback_data_s
24 typedef struct callback_data_s callback_data_t;
26 static int json_begin_graph (graph_config_t *cfg) /* {{{ */
33 graph_get_title (cfg, desc, sizeof (desc));
35 printf ("{\"title\":\"%s\",\"instances\":[", desc);
38 } /* }}} int json_begin_graph */
40 static int json_end_graph (void) /* {{{ */
45 } /* }}} int json_end_graph */
47 static int json_print_instance (graph_config_t *cfg, /* {{{ */
48 graph_instance_t *inst)
53 if ((cfg == NULL) || (inst == NULL))
56 memset (desc, 0, sizeof (desc));
57 inst_describe (cfg, inst, desc, sizeof (desc));
59 memset (params, 0, sizeof (params));
60 inst_get_params (cfg, inst, params, sizeof (params));
62 printf ("{\"description\":\"%s\",\"params\":\"%s\"}",
66 } /* }}} int json_print_instance */
68 static int json_print_graph_instance (graph_config_t *cfg, /* {{{ */
69 graph_instance_t *inst,
72 callback_data_t *data = user_data;
81 json_begin_graph (cfg);
86 else /* if (not first instance) */
91 json_print_instance (cfg, inst);
100 } /* }}} int json_print_graph_instance */
102 static int list_graphs_json (const char *term) /* {{{ */
104 callback_data_t data;
107 char time_buffer[128];
110 printf ("Content-Type: application/json\n");
113 status = time_to_rfc1123 (now + 300, time_buffer, sizeof (time_buffer));
115 printf ("Expires: %s\n"
116 "Cache-Control: public\n",
121 data.limit = RESULT_LIMIT;
126 gl_instance_get_all (json_print_graph_instance, /* user_data = */ &data);
128 gl_search (term, json_print_graph_instance, /* user_data = */ &data);
136 } /* }}} int list_graphs_json */
138 int action_search_json (void) /* {{{ */
145 search = strtolower_copy (param ("q"));
147 status = list_graphs_json (search);
152 } /* }}} int action_search_json */
154 /* vim: set sw=2 sts=2 et fdm=marker : */