]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
New function to test if a configuration node is a sequence or not.
authorJason Ish <ish@unx.ca>
Thu, 15 Jan 2015 20:43:22 +0000 (14:43 -0600)
committerVictor Julien <victor@inliniac.net>
Wed, 11 Mar 2015 14:44:09 +0000 (15:44 +0100)
src/conf.c
src/conf.h

index c42ff4957542e87eab14a54b6db903c4b445b1ec..50a9d13ec74e3fcabc9021ffe562f873b70bb090 100644 (file)
@@ -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 */
index 6bc7414e6aadb6e485c19ec51d04aad677902581..2c01a43ee1831de97e72dfef7792151a855e073c 100644 (file)
@@ -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__ */