added conf_get_bool

This commit is contained in:
Richard Aas 2011-03-08 09:26:45 +00:00
parent 38256d469e
commit 42b8f434c8
2 changed files with 33 additions and 0 deletions

View file

@ -15,4 +15,5 @@ int conf_get(struct conf *conf, const char *name, struct pl *pl);
int conf_get_str(struct conf *conf, const char *name, char *str,
size_t size);
int conf_get_u32(struct conf *conf, const char *name, uint32_t *num);
int conf_get_bool(struct conf *conf, const char *name, bool *val);
int conf_apply(struct conf *conf, const char *name, conf_h *ch, void *arg);

View file

@ -220,6 +220,38 @@ int conf_get_u32(struct conf *conf, const char *name, uint32_t *num)
}
/**
* Get the boolean value of a configuration item
*
* @param conf Configuration object
* @param name Name of config item key
* @param val Returned boolean value of config item, if present
*
* @return 0 if success, otherwise errorcode
*/
int conf_get_bool(struct conf *conf, const char *name, bool *val)
{
struct pl pl;
int err;
if (!conf || !name || !val)
return EINVAL;
err = conf_get(conf, name, &pl);
if (err)
return err;
if (!pl_strcasecmp(&pl, "true"))
*val = true;
else if (!pl_strcasecmp(&pl, "yes"))
*val = true;
else
*val = false;
return 0;
}
/**
* Apply a function handler to all config items of a certain key
*