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.
remotes/origin/master-1.1.x
Jason Ish 15 years ago committed by Victor Julien
parent b819643635
commit 7257fed0f3

@ -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

@ -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__ */

@ -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);

Loading…
Cancel
Save