2 * collection4 - action_show_graph_json.c
3 * Copyright (C) 2010 Florian octo Forster
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA
21 * Florian octo Forster <ff at octo.it>
32 #include "action_show_graph_json.h"
35 #include "graph_ident.h"
36 #include "graph_instance.h"
37 #include "graph_list.h"
38 #include "utils_cgi.h"
41 #include <fcgi_stdio.h>
43 static int write_buffer (char *buffer, size_t buffer_size) /* {{{ */
47 while (buffer_size > 0)
49 status = fwrite (buffer, buffer_size, /* nmemb = */ 1, stdout);
54 buffer_size -= status;
58 } /* }}} int write_buffer */
60 int action_show_graph_json (void) /* {{{ */
64 yajl_gen_config handler_config;
67 const unsigned char *buffer;
68 unsigned int buffer_length;
71 char time_buffer[128];
74 cfg = gl_graph_get_selected ();
78 memset (&handler_config, 0, sizeof (handler_config));
79 handler_config.beautify = 1;
80 handler_config.indentString = " ";
82 handler = yajl_gen_alloc (&handler_config,
83 /* alloc functions = */ NULL);
90 printf ("Content-Type: application/json\n");
93 status = time_to_rfc1123 (now + 300, time_buffer, sizeof (time_buffer));
95 printf ("Expires: %s\n"
96 "Cache-Control: public\n",
100 status = graph_to_json (cfg, handler);
104 yajl_gen_free (handler);
110 status = (int) yajl_gen_get_buf (handler, &buffer, &buffer_length);
112 write_buffer ((char *) buffer, (size_t) buffer_length);
115 yajl_gen_free (handler);
117 } /* }}} int action_show_graph_json */
119 /* vim: set sw=2 sts=2 et fdm=marker : */