From f10bc4b73e757315913214d678d33f54328fa19c Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Thu, 10 Jul 2014 17:59:53 +0200 Subject: [PATCH] config: add utility function vdgoption_bool() Signed-off-by: Ralph Boehme --- libatalk/util/netatalk_conf.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/libatalk/util/netatalk_conf.c b/libatalk/util/netatalk_conf.c index b20446d2..1a4f9fa6 100644 --- a/libatalk/util/netatalk_conf.c +++ b/libatalk/util/netatalk_conf.c @@ -547,6 +547,36 @@ static int getoption_bool(const dictionary *conf, const char *vol, const char *o 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 * -- 2.39.2