X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Faction_graph.c;h=492e5e7245581233a7c158f26e3a90c05257bb5d;hb=9740ba29aa604e3cc2e75d37b8af3ba5fcb571c9;hp=0bb58563e0a9094d6acd2315527217319edd4ba3;hpb=da630143f2fd8a152ec71a9c7ed8b0ae17081fa4;p=collection4.git diff --git a/src/action_graph.c b/src/action_graph.c index 0bb5856..492e5e7 100644 --- a/src/action_graph.c +++ b/src/action_graph.c @@ -1,3 +1,26 @@ +/** + * collection4 - action_graph.c + * Copyright (C) 2010 Florian octo Forster + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: + * Florian octo Forster + **/ + #include #include #include @@ -12,8 +35,10 @@ #include "common.h" #include "action_graph.h" +#include "graph.h" +#include "graph_instance.h" #include "graph_list.h" -#include "utils_params.h" +#include "utils_cgi.h" #include "utils_array.h" #include @@ -21,7 +46,7 @@ struct graph_data_s { - str_array_t *args; + rrd_args_t *args; rrd_info_t *info; time_t mtime; time_t expires; @@ -97,10 +122,10 @@ static int get_time_args (graph_data_t *data) /* {{{ */ data->begin = begin; data->end = end; - array_append (data->args, "-s"); - array_append_format (data->args, "%li", begin); - array_append (data->args, "-e"); - array_append_format (data->args, "%li", end); + array_append (data->args->options, "-s"); + array_append_format (data->args->options, "%li", begin); + array_append (data->args->options, "-e"); + array_append_format (data->args->options, "%li", end); return (0); } /* }}} int get_time_args */ @@ -204,6 +229,9 @@ int action_graph (void) /* {{{ */ graph_instance_t *inst; int status; + int argc; + char **argv; + cfg = gl_graph_get_selected (); if (cfg == NULL) OUTPUT_ERROR ("gl_graph_get_selected () failed.\n"); @@ -212,31 +240,39 @@ int action_graph (void) /* {{{ */ if (inst == NULL) OUTPUT_ERROR ("inst_get_selected (%p) failed.\n", (void *) cfg); - data.args = array_create (); + data.args = ra_create (); if (data.args == NULL) return (ENOMEM); - array_append (data.args, "graph"); - array_append (data.args, "-"); - array_append (data.args, "--imgformat"); - array_append (data.args, "PNG"); + array_append (data.args->options, "graph"); + array_append (data.args->options, "-"); + array_append (data.args->options, "--imgformat"); + array_append (data.args->options, "PNG"); get_time_args (&data); status = inst_get_rrdargs (cfg, inst, data.args); if (status != 0) { - array_destroy (data.args); + ra_destroy (data.args); OUTPUT_ERROR ("inst_get_rrdargs failed with status %i.\n", status); } + argc = ra_argc (data.args); + argv = ra_argv (data.args); + if ((argc < 0) || (argv == NULL)) + { + ra_destroy (data.args); + return (-1); + } + rrd_clear_error (); - data.info = rrd_graph_v (array_argc (data.args), array_argv (data.args)); + data.info = rrd_graph_v (argc, argv); if ((data.info == NULL) || rrd_test_error ()) { printf ("Content-Type: text/plain\n\n"); printf ("rrd_graph_v failed: %s\n", rrd_get_error ()); - emulate_graph (array_argc (data.args), array_argv (data.args)); + emulate_graph (argc, argv); } else { @@ -262,7 +298,8 @@ int action_graph (void) /* {{{ */ if (data.info != NULL) rrd_info_free (data.info); - array_destroy (data.args); + ra_argv_free (argv); + ra_destroy (data.args); data.args = NULL; return (0);