summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 366c100)
raw | patch | inline | side by side (parent: 366c100)
author | Florian Forster <ff@octo.it> | |
Tue, 6 Jul 2010 07:43:02 +0000 (09:43 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Tue, 6 Jul 2010 07:43:02 +0000 (09:43 +0200) |
src/action_graph.c | patch | blob | history | |
src/common.c | patch | blob | history | |
src/common.h | patch | blob | history |
diff --git a/src/action_graph.c b/src/action_graph.c
index f9322d858000ae5148132102e606cb6e6521f9ea..b3b815f66c943e399f34e687729ca8e47f294d70 100644 (file)
--- a/src/action_graph.c
+++ b/src/action_graph.c
};
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;
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)
diff --git a/src/common.c b/src/common.c
index 23714ea71eed2c89a7a8c4dcc22453812265ae88..2a5bf45262a565943c5d6ec26b4686afee0e86c7 100644 (file)
--- a/src/common.c
+++ b/src/common.c
#include "common.h"
#include "graph_list.h"
+#include "utils_cgi.h"
#include <fcgiapp.h>
#include <fcgi_stdio.h>
return (strtolower (strdup (str)));
} /* }}} char *strtolower_copy */
+int get_time_args (long *ret_begin, long *ret_end, /* {{{ */
+ long *ret_now)
+{
+ const char *begin_str;
+ const char *end_str;
+ long now;
+ long begin;
+ long end;
+ char *endptr;
+ long tmp;
+
+ if ((ret_begin == NULL) || (ret_end == NULL))
+ return (EINVAL);
+
+ begin_str = param ("begin");
+ end_str = param ("end");
+
+ now = (long) time (NULL);
+ if (ret_now != NULL)
+ *ret_now = now;
+ *ret_begin = now - 86400;
+ *ret_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;
+ }
+
+ *ret_begin = begin;
+ *ret_end = end;
+
+ return (0);
+} /* }}} int get_time_args */
+
/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/src/common.h b/src/common.h
index 351fe3f8c1bdd7ed56d332cce5a8b087abd74529..79a83ec4579a4178f77b1bc1a3cab5983d3dadbf 100644 (file)
--- a/src/common.h
+++ b/src/common.h
char *strtolower (char *str);
char *strtolower_copy (const char *str);
+/*
+ * Parses the time parameters "begin" and "end" and returns the specified time
+ * in epoch in the longs pointed to by "ret_begin" and "ret_end". Returns
+ * non-zero on failure. If the optional "ret_now" pointer is not-NULL, the
+ * current time will be assigned to it.
+ */
+int get_time_args (long *ret_begin, long *ret_end,
+ long *ret_now);
+
#endif /* COMMON_H */
/* vim: set sw=2 sts=2 et fdm=marker : */