From 7257fed0f39aa903e489646fdf8fc96a73853636 Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Thu, 26 May 2011 23:03:48 -0600 Subject: [PATCH] Fix bug 288, accept true in output configuration. Refactor a bit to run checks for truth through a common function that takes yes, true, on and 1 as true values. --- src/conf.c | 38 +++++++++++++++++++++++++++----------- src/conf.h | 1 + src/runmodes.c | 2 +- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/conf.c b/src/conf.c index 160ee1f9e8..2ee17a42d8 100644 --- a/src/conf.c +++ b/src/conf.c @@ -292,21 +292,40 @@ int ConfGetBool(char *name, int *val) { char *strval; - char *trues[] = {"1", "yes", "true", "on"}; - size_t u; *val = 0; if (ConfGet(name, &strval) != 1) return 0; + *val = ConfValIsTrue(strval); + + return 1; +} + +/** + * \brief Check if a value is true. + * + * The value of considered true if it is a string with the value of 1, + * yes, true or on. The test is not case sensitive, any other value + * is false. + * + * \param val The string to test for a true value. + * + * \retval 1 If the value is true, 0 if not. + */ +int +ConfValIsTrue(const char *val) +{ + char *trues[] = {"1", "yes", "true", "on"}; + size_t u; + for (u = 0; u < sizeof(trues) / sizeof(trues[0]); u++) { - if (strcasecmp(strval, trues[u]) == 0) { - *val = 1; - break; + if (strcasecmp(val, trues[u]) == 0) { + return 1; } } - return 1; + return 0; } /** @@ -556,11 +575,8 @@ ConfNodeChildValueIsTrue(ConfNode *node, const char *key) const char *val; val = ConfNodeLookupChildValue(node, key); - if (val != NULL) { - if ((strcasecmp(val, "yes") == 0) || (strcasecmp(val, "true") == 0)) - return 1; - } - return 0; + + return val != NULL ? ConfValIsTrue(val) : 0; } #ifdef UNITTESTS diff --git a/src/conf.h b/src/conf.h index 20a71060a7..6f6de34d5e 100644 --- a/src/conf.h +++ b/src/conf.h @@ -68,5 +68,6 @@ const char *ConfNodeLookupChildValue(ConfNode *node, const char *key); void ConfNodeRemove(ConfNode *); void ConfRegisterTests(); int ConfNodeChildValueIsTrue(ConfNode *node, const char *key); +int ConfValIsTrue(const char *val); #endif /* ! __CONF_H__ */ diff --git a/src/runmodes.c b/src/runmodes.c index f42841c7ad..d8a3dec467 100644 --- a/src/runmodes.c +++ b/src/runmodes.c @@ -346,7 +346,7 @@ void RunModeInitializeOutputs(void) } enabled = ConfNodeLookupChildValue(output_config, "enabled"); - if (enabled != NULL && strcasecmp(enabled, "yes") == 0) { + if (enabled != NULL && ConfValIsTrue(enabled)) { OutputCtx *output_ctx = NULL; if (module->InitFunc != NULL) { output_ctx = module->InitFunc(output_config);