From 0bddf4f02f1a98b030277378f8e60a2b3721a137 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Mon, 21 Jan 2013 09:27:08 +0100 Subject: [PATCH] conf: introduce WithDefault function This patch introduces a new set of functions to the ConfGetChildValue family. They permit to look under a default node if looking under base node as failed. This will be used to access to default parameters for a data type (for instance, first usage will be interface). --- src/conf.c | 31 +++++++++++++++++++++++++++++++ src/conf.h | 3 +++ 2 files changed, 34 insertions(+) diff --git a/src/conf.c b/src/conf.c index 4d3f5e0836..10a50d5fd1 100644 --- a/src/conf.c +++ b/src/conf.c @@ -286,6 +286,17 @@ int ConfGetChildValue(ConfNode *base, char *name, char **vptr) } } + +int ConfGetChildValueWithDefault(ConfNode *base, ConfNode *dflt, char *name, char **vptr) +{ + int ret = ConfGetChildValue(base, name, vptr); + /* Get 'default' value */ + if (ret == 0 && dflt) { + return ConfGetChildValue(dflt, name, vptr); + } + return ret; +} + /** * \brief Retrieve a configuration value as an integer. * @@ -337,6 +348,15 @@ int ConfGetChildValueInt(ConfNode *base, char *name, intmax_t *val) } +int ConfGetChildValueIntWithDefault(ConfNode *base, ConfNode *dflt, char *name, intmax_t *val) +{ + int ret = ConfGetChildValueInt(base, name, val); + /* Get 'default' value */ + if (ret == 0 && dflt) { + return ConfGetChildValueInt(dflt, name, val); + } + return ret; +} /** @@ -376,6 +396,17 @@ int ConfGetChildValueBool(ConfNode *base, char *name, int *val) return 1; } +int ConfGetChildValueBoolWithDefault(ConfNode *base, ConfNode *dflt, char *name, int *val) +{ + int ret = ConfGetChildValueBool(base, name, val); + /* Get 'default' value */ + if (ret == 0 && dflt) { + return ConfGetChildValueBool(dflt, name, val); + } + return ret; +} + + /** * \brief Check if a value is true. * diff --git a/src/conf.h b/src/conf.h index 8aad1e7ff2..c9a089f771 100644 --- a/src/conf.h +++ b/src/conf.h @@ -80,6 +80,9 @@ ConfNode *ConfNodeLookupKeyValue(ConfNode *base, const char *key, const char *va int ConfGetChildValue(ConfNode *base, char *name, char **vptr); int ConfGetChildValueInt(ConfNode *base, char *name, intmax_t *val); int ConfGetChildValueBool(ConfNode *base, char *name, int *val); +int ConfGetChildValueWithDefault(ConfNode *base, ConfNode *dflt, char *name, char **vptr); +int ConfGetChildValueIntWithDefault(ConfNode *base, ConfNode *dflt, char *name, intmax_t *val); +int ConfGetChildValueBoolWithDefault(ConfNode *base, ConfNode *dflt, char *name, int *val); char *ConfLoadCompleteIncludePath(char *); #endif /* ! __CONF_H__ */