From: Eric Leblond Date: Sat, 6 Jan 2018 09:01:55 +0000 (+0100) Subject: conf: add function to get child with default X-Git-Tag: suricata-4.1.0-beta1~359 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba0899a77f3ec04fdef34ff9a8d71b97c6c0ad59;p=thirdparty%2Fsuricata.git conf: add function to get child with default --- 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);