From ba0899a77f3ec04fdef34ff9a8d71b97c6c0ad59 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Sat, 6 Jan 2018 10:01:55 +0100 Subject: [PATCH] conf: add function to get child with default --- src/conf.c | 13 +++++++++++++ src/conf.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/conf.c b/src/conf.c index 5ea30fc603..4d7ad84be5 100644 --- a/src/conf.c +++ b/src/conf.c @@ -399,6 +399,19 @@ int ConfGetChildValue(const ConfNode *base, const char *name, const char **vptr) } } +ConfNode *ConfGetChildWithDefault(const ConfNode *base, const ConfNode *dflt, + const char *name) +{ + ConfNode *node = ConfNodeLookupChild(base, name); + if (node != NULL) + return node; + + /* Get 'default' value */ + if (dflt) { + return ConfNodeLookupChild(dflt, name); + } + return NULL; +} int ConfGetChildValueWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, const char **vptr) diff --git a/src/conf.h b/src/conf.h index 171cc83db5..e44a45d5ce 100644 --- a/src/conf.h +++ b/src/conf.h @@ -82,6 +82,7 @@ int ConfValIsFalse(const char *val); void ConfNodePrune(ConfNode *node); int ConfRemove(const char *name); +ConfNode *ConfGetChildWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name); ConfNode *ConfNodeLookupKeyValue(const ConfNode *base, const char *key, const char *value); int ConfGetChildValue(const ConfNode *base, const char *name, const char **vptr); int ConfGetChildValueInt(const ConfNode *base, const char *name, intmax_t *val); -- 2.47.2