6 #include "action_search_json.h"
9 #include "graph_ident.h"
10 #include "graph_instance.h"
11 #include "graph_list.h"
12 #include "utils_cgi.h"
15 #include <fcgi_stdio.h>
17 #define RESULT_LIMIT 10
19 struct callback_data_s
25 typedef struct callback_data_s callback_data_t;
27 static int json_begin_graph (graph_config_t *cfg) /* {{{ */
34 graph_get_title (cfg, desc, sizeof (desc));
36 printf ("{\"title\":\"%s\",\"instances\":[", desc);
39 } /* }}} int json_begin_graph */
41 static int json_end_graph (void) /* {{{ */
46 } /* }}} int json_end_graph */
48 static int json_print_instance (graph_config_t *cfg, /* {{{ */
49 graph_instance_t *inst)
54 if ((cfg == NULL) || (inst == NULL))
57 memset (desc, 0, sizeof (desc));
58 inst_describe (cfg, inst, desc, sizeof (desc));
60 memset (params, 0, sizeof (params));
61 inst_get_params (cfg, inst, params, sizeof (params));
63 printf ("{\"description\":\"%s\",\"params\":\"%s\"}",
67 } /* }}} int json_print_instance */
69 static int json_print_graph_instance (graph_config_t *cfg, /* {{{ */
70 graph_instance_t *inst,
73 callback_data_t *data = user_data;
82 json_begin_graph (cfg);
87 else /* if (not first instance) */
92 json_print_instance (cfg, inst);
101 } /* }}} int json_print_graph_instance */
103 static int list_graphs_json (const char *term) /* {{{ */
105 callback_data_t data;
108 char time_buffer[128];
111 printf ("Content-Type: application/json\n");
114 status = time_to_rfc1123 (now + 300, time_buffer, sizeof (time_buffer));
116 printf ("Expires: %s\n"
117 "Cache-Control: public\n",
122 data.limit = RESULT_LIMIT;
127 gl_instance_get_all (json_print_graph_instance, /* user_data = */ &data);
129 gl_search (term, json_print_graph_instance, /* user_data = */ &data);
137 } /* }}} int list_graphs_json */
139 int action_search_json (void) /* {{{ */
146 search = strtolower_copy (param ("q"));
148 status = list_graphs_json (search);
153 } /* }}} int action_search_json */
155 /* vim: set sw=2 sts=2 et fdm=marker : */