diff --git a/src/conf.c b/src/conf.c index 20fb859fe4..252dcb897f 100644 --- a/src/conf.c +++ b/src/conf.c @@ -42,6 +42,7 @@ #include "util-debug.h" #include "util-path.h" #include "util-conf.h" +#include "rust.h" /** Maximum size of a complete domain name. */ #define NODE_NAME_MAX 1024 @@ -647,6 +648,36 @@ int SCConfGetFloat(const char *name, float *val) return 1; } +/** + * \brief Retrieve a configuration value as a time duration in seconds. + * + * The configuration value is expected to be a string with a number + * followed by an optional time-describing unit (e.g. s, seconds, weeks, years). + * If no unit is specified, seconds are assumed. + * + * \param name Name of configuration parameter to get. + * \param val Pointer to an uint64_t that will be set the + * configuration value in seconds. + * + * \retval 1 will be returned if the name is found and was properly + * converted to a time duration, otherwise 0 will be returned. + */ +int SCConfGetTime(const char *name, uint64_t *val) +{ + const char *strval = NULL; + + if (SCConfGet(name, &strval) == 0) + return 0; + + if (strval == NULL || strval[0] == '\0') + return 0; + + if (SCParseTimeDuration(strval, val) != 0) + return 0; + + return 1; +} + /** * \brief Remove (and SCFree) the provided configuration node. */ diff --git a/src/conf.h b/src/conf.h index 123afcb7ca..1de4481df1 100644 --- a/src/conf.h +++ b/src/conf.h @@ -67,6 +67,7 @@ int SCConfGetInt(const char *name, intmax_t *val); int SCConfGetBool(const char *name, int *val); int SCConfGetDouble(const char *name, double *val); int SCConfGetFloat(const char *name, float *val); +int SCConfGetTime(const char *name, uint64_t *val); int SCConfSet(const char *name, const char *val); int SCConfSetFromString(const char *input, int final); int SCConfSetFinal(const char *name, const char *val);