From 42b8f434c871d5384de2e754cf61b166a1a3c5f8 Mon Sep 17 00:00:00 2001 From: Richard Aas Date: Tue, 8 Mar 2011 09:26:45 +0000 Subject: [PATCH] added conf_get_bool --- include/re_conf.h | 1 + src/conf/conf.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/re_conf.h b/include/re_conf.h index 1945458..a49fe3d 100644 --- a/include/re_conf.h +++ b/include/re_conf.h @@ -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); diff --git a/src/conf/conf.c b/src/conf/conf.c index 53f21e1..d0f6b27 100644 --- a/src/conf/conf.c +++ b/src/conf/conf.c @@ -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 *