]> arthur.barton.de Git - netatalk.git/commitdiff
config: add utility function vdgoption_bool()
authorRalph Boehme <rb@sernet.de>
Thu, 10 Jul 2014 15:59:53 +0000 (17:59 +0200)
committerRalph Boehme <rb@sernet.de>
Thu, 10 Jul 2014 16:02:27 +0000 (18:02 +0200)
Signed-off-by: Ralph Boehme <rb@sernet.de>
libatalk/util/netatalk_conf.c

index b20446d2177c470d849b0e0e4578d62e56fe4f08..1a4f9fa64de8b6feec41932bb7a5c9dd39a0a5f6 100644 (file)
@@ -547,6 +547,36 @@ static int getoption_bool(const dictionary *conf, const char *vol, const char *o
     return result;
 }
 
     return result;
 }
 
+/*!
+ * Get boolean option from volume, default section or global - use default value if not set
+ *
+ * Order of precedence: volume -> default section -> global -> default value
+ *
+ * "vdg" means volume, default section or global
+ *
+ * @param conf    (r) config handle
+ * @param vol     (r) volume name (must be section name ie wo vars expanded)
+ * @param opt     (r) option
+ * @param defsec  (r) if "option" is not found in "vol", try to find it in section "defsec"
+ * @param defval  (r) if neither "vol" nor "defsec" contain "opt" return "defval"
+ *
+ * @returns       const option string from "vol" or "defsec", or "defval" if not found
+ */
+static int vdgoption_bool(const dictionary *conf, const char *vol, const char *opt, const char *defsec, int defval)
+{
+    int result;
+
+    result = atalk_iniparser_getboolean(conf, vol, opt, -1);
+
+    if ((result == -1) && (defsec != NULL))
+        result = atalk_iniparser_getboolean(conf, defsec, opt, -1);
+
+    if (result == -1)
+        result = atalk_iniparser_getboolean(conf, INISEC_GLOBAL, opt, defval);
+
+    return result;
+}
+
 /*!
  * Create volume struct
  *
 /*!
  * Create volume struct
  *