summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 990c22b)
raw | patch | inline | side by side (parent: 990c22b)
author | Florian Forster <ff@octo.it> | |
Wed, 21 Jul 2010 11:56:10 +0000 (13:56 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Wed, 21 Jul 2010 11:56:10 +0000 (13:56 +0200) |
src/action_show_graph_json.c | patch | blob | history |
index d36520526f5eab773858d1390a33745c9d4e03de..0820fb025614997ae39aca7737ded1406c82a75f 100644 (file)
#include <fcgiapp.h>
#include <fcgi_stdio.h>
-static int write_buffer (char *buffer, size_t buffer_size) /* {{{ */
+static void write_callback (__attribute__((unused)) void *ctx, /* {{{ */
+ const char *str, unsigned int len)
{
- size_t status;
-
- while (buffer_size > 0)
- {
- status = fwrite (buffer, /* size = */ 1,
- /* nmemb = */ buffer_size, stdout);
- if (status == 0)
- return (errno);
-
- buffer += status;
- buffer_size -= status;
- }
-
- return (0);
-} /* }}} int write_buffer */
+ fwrite ((void *) str, /* size = */ len, /* nmemb = */ 1, stdout);
+} /* }}} void write_callback */
int action_show_graph_json (void) /* {{{ */
{
yajl_gen_config handler_config;
yajl_gen handler;
- const unsigned char *buffer;
- unsigned int buffer_length;
-
time_t now;
char time_buffer[128];
int status;
handler_config.beautify = 1;
handler_config.indentString = " ";
- handler = yajl_gen_alloc (&handler_config,
- /* alloc functions = */ NULL);
+ handler = yajl_gen_alloc2 (write_callback,
+ &handler_config,
+ /* alloc functions = */ NULL,
+ /* context = */ NULL);
if (handler == NULL)
{
graph_destroy (cfg);
printf ("\n");
status = graph_to_json (cfg, handler);
- if (status != 0)
- {
- graph_destroy (cfg);
- yajl_gen_free (handler);
- return (status);
- }
-
- buffer = NULL;
- buffer_length = 0;
- status = (int) yajl_gen_get_buf (handler, &buffer, &buffer_length);
-
- write_buffer ((char *) buffer, (size_t) buffer_length);
graph_destroy (cfg);
yajl_gen_free (handler);
- return (0);
+
+ return (status);
} /* }}} int action_show_graph_json */
/* vim: set sw=2 sts=2 et fdm=marker : */