From a243a42bdf1bf4bc88deebc2408c51af7e85df5a Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Thu, 15 Jan 2015 14:43:22 -0600 Subject: [PATCH] New function to test if a configuration node is a sequence or not. --- src/conf.c | 31 +++++++++++++++++++++++++++++++ src/conf.h | 1 + 2 files changed, 32 insertions(+) diff --git a/src/conf.c b/src/conf.c index c42ff49575..50a9d13ec7 100644 --- a/src/conf.c +++ b/src/conf.c @@ -840,6 +840,19 @@ ConfNodePrune(ConfNode *node) } } +/** + * \brief Check if a node is a sequence or node. + * + * \param node the node to check. + * + * \return 1 if node is a seuence, otherwise 0. + */ +int +ConfNodeIsSequence(const ConfNode *node) +{ + return node->is_seq == 0 ? 0 : 1; +} + #ifdef UNITTESTS /** @@ -1398,6 +1411,23 @@ end: return ret; } +int +ConfNodeIsSequenceTest(void) +{ + ConfNode *node = ConfNodeNew(); + if (node == NULL) { + return 0; + } + if (ConfNodeIsSequence(node)) { + return 0; + } + node->is_seq = 1; + if (!ConfNodeIsSequence(node)) { + return 0; + } + return 1; +} + void ConfRegisterTests(void) { @@ -1416,6 +1446,7 @@ ConfRegisterTests(void) UtRegisterTest("ConfGetChildValueBoolWithDefaultTest", ConfGetChildValueBoolWithDefaultTest, 1); UtRegisterTest("ConfGetNodeOrCreateTest", ConfGetNodeOrCreateTest, 1); UtRegisterTest("ConfNodePruneTest", ConfNodePruneTest, 1); + UtRegisterTest("ConfNodeIsSequenceTest", ConfNodeIsSequenceTest, 1); } #endif /* UNITTESTS */ diff --git a/src/conf.h b/src/conf.h index 6bc7414e6a..2c01a43ee1 100644 --- a/src/conf.h +++ b/src/conf.h @@ -87,5 +87,6 @@ int ConfGetChildValueWithDefault(const ConfNode *base, const ConfNode *dflt, con int ConfGetChildValueIntWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, intmax_t *val); int ConfGetChildValueBoolWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, int *val); char *ConfLoadCompleteIncludePath(const char *); +int ConfNodeIsSequence(const ConfNode *node); #endif /* ! __CONF_H__ */