]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
conf: introduce WithDefault function
authorEric Leblond <eric@regit.org>
Mon, 21 Jan 2013 08:27:08 +0000 (09:27 +0100)
committerEric Leblond <eric@regit.org>
Mon, 21 Jan 2013 15:12:03 +0000 (16:12 +0100)
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
src/conf.h

index 4d3f5e083635e1b926f3eff8dfc4f54c965bc950..10a50d5fd1249f56b9fdff3f620f90c14d6ada23 100644 (file)
@@ -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.
  *
index 8aad1e7ff2de6bf30fdd53bdab7409e5d15933cf..c9a089f771bca184b4e5ad3c83339eedcd902891 100644 (file)
@@ -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__ */