X-Git-Url: https://git.octo.it/?p=collection4.git;a=blobdiff_plain;f=src%2Fcommon.c;h=2a5bf45262a565943c5d6ec26b4686afee0e86c7;hp=23714ea71eed2c89a7a8c4dcc22453812265ae88;hb=edac1d40c3b678b8210d786f3a24d10e7c6fe151;hpb=366c100ebb89651eef6b71139bd92b2c27b63738 diff --git a/src/common.c b/src/common.c index 23714ea..2a5bf45 100644 --- a/src/common.c +++ b/src/common.c @@ -39,6 +39,7 @@ #include "common.h" #include "graph_list.h" +#include "utils_cgi.h" #include #include @@ -264,4 +265,78 @@ char *strtolower_copy (const char *str) /* {{{ */ 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 : */