X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Faction_graph.c;h=b3b815f66c943e399f34e687729ca8e47f294d70;hb=e6c6e8043f974b474e912f0cf76e491721f4e2a9;hp=878973099edcdf8bef31a4c9809d7c9d547cbe11;hpb=8a3753760230b270c8f4615891cba2586a661d21;p=collection4.git diff --git a/src/action_graph.c b/src/action_graph.c index 8789730..b3b815f 100644 --- a/src/action_graph.c +++ b/src/action_graph.c @@ -1,3 +1,28 @@ +/** + * 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 "config.h" + #include #include #include @@ -33,80 +58,6 @@ struct graph_data_s }; typedef struct graph_data_s graph_data_t; -static int get_time_args (graph_data_t *data) /* {{{ */ -{ - const char *begin_str; - const char *end_str; - long now; - long begin; - long end; - char *endptr; - long tmp; - - begin_str = param ("begin"); - end_str = param ("end"); - - now = (long) time (NULL); - data->now = now; - data->begin = now - 86400; - data->end = now; - - if (begin_str != NULL) - { - endptr = NULL; - errno = 0; - tmp = strtol (begin_str, &endptr, /* base = */ 0); - if ((endptr == begin_str) || (errno != 0)) - return (-1); - if (tmp <= 0) - begin = now + tmp; - else - begin = tmp; - } - else /* if (begin_str == NULL) */ - { - begin = now - 86400; - } - - if (end_str != NULL) - { - endptr = NULL; - errno = 0; - tmp = strtol (end_str, &endptr, /* base = */ 0); - if ((endptr == end_str) || (errno != 0)) - return (-1); - end = tmp; - if (tmp <= 0) - end = now + tmp; - else - end = tmp; - } - else /* if (end_str == NULL) */ - { - end = now; - } - - if (begin == end) - return (-1); - - if (begin > end) - { - tmp = begin; - begin = end; - end = tmp; - } - - data->begin = begin; - data->end = 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 */ - static void emulate_graph (int argc, char **argv) /* {{{ */ { int i; @@ -185,6 +136,7 @@ static int output_graph (graph_data_t *data) /* {{{ */ if (status == 0) printf ("Expires: %s\n", time_buffer); + printf ("X-Generator: "PACKAGE_STRING"\n"); printf ("\n"); fwrite (img->value.u_blo.ptr, img->value.u_blo.size, @@ -226,7 +178,14 @@ int action_graph (void) /* {{{ */ array_append (data.args->options, "--imgformat"); array_append (data.args->options, "PNG"); - get_time_args (&data); + status = get_time_args (&data.begin, &data.end, &data.now); + if (status == 0) + { + array_append (data.args->options, "-s"); + array_append_format (data.args->options, "%li", data.begin); + array_append (data.args->options, "-e"); + array_append_format (data.args->options, "%li", data.end); + } status = inst_get_rrdargs (cfg, inst, data.args); if (status != 0)