summaryrefslogtreecommitdiff
path: root/src/network/networkd-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-01-05 17:10:17 +0100
committerLennart Poettering <lennart@poettering.net>2016-01-05 17:30:43 +0100
commitb18b8662154b46f03ddeac00e52d157c87d474e3 (patch)
treee9bbf8b325c9ce60d5e629e3e533b17edc82426f /src/network/networkd-util.c
parent38e5900fc6e77b595151ae8e1548c5aace406bf8 (diff)
basic: add string table macros for "extended boolean" enums
In a couple of cases we maintain configuration settings that know an on and off state, like a boolean, plus some additional states. We generally parse them as booleans first, and if that fails check for specific additional values. This adds a generalized set of macros for parsing such settings, and ports one use in resolved and another in networkd over to it.
Diffstat (limited to 'src/network/networkd-util.c')
-rw-r--r--src/network/networkd-util.c45
1 files changed, 2 insertions, 43 deletions
diff --git a/src/network/networkd-util.c b/src/network/networkd-util.c
index 2545621a93..1cc4f07e1e 100644
--- a/src/network/networkd-util.c
+++ b/src/network/networkd-util.c
@@ -108,47 +108,6 @@ static const char* const resolve_support_table[_RESOLVE_SUPPORT_MAX] = {
[RESOLVE_SUPPORT_RESOLVE] = "resolve",
};
-DEFINE_STRING_TABLE_LOOKUP(resolve_support, ResolveSupport);
+DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(resolve_support, ResolveSupport, RESOLVE_SUPPORT_YES);
-int config_parse_resolve(
- const char* unit,
- const char *filename,
- unsigned line,
- const char *section,
- unsigned section_line,
- const char *lvalue,
- int ltype,
- const char *rvalue,
- void *data,
- void *userdata) {
-
- ResolveSupport *resolve = data;
- int k;
-
- assert(filename);
- assert(lvalue);
- assert(rvalue);
- assert(resolve);
-
- /* Our enum shall be a superset of booleans, hence first try
- * to parse as boolean, and then as enum */
-
- k = parse_boolean(rvalue);
- if (k > 0)
- *resolve = RESOLVE_SUPPORT_YES;
- else if (k == 0)
- *resolve = RESOLVE_SUPPORT_NO;
- else {
- ResolveSupport s;
-
- s = resolve_support_from_string(rvalue);
- if (s < 0){
- log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse %s= option, ignoring: %s", lvalue, rvalue);
- return 0;
- }
-
- *resolve = s;
- }
-
- return 0;
-}
+DEFINE_CONFIG_PARSE_ENUM(config_parse_resolve, resolve_support, ResolveSupport, "Failed to parse resolve support");