From 47817a576cb055552b1fe74ad48c500edea187ae Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 29 Jun 2020 17:35:21 +0200 Subject: [PATCH] ifcfg-rh: add generic shvar getter and setter for ternary variables --- src/settings/plugins/ifcfg-rh/shvar.c | 23 +++++++++++++++++++++++ src/settings/plugins/ifcfg-rh/shvar.h | 3 +++ 2 files changed, 26 insertions(+) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index cd63661d9a..a447720690 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -1214,6 +1214,20 @@ svGetValueBoolean (shvarFile *s, const char *key, int fallback) return svParseBoolean (value, fallback); } +/* svGetValueTernary: + * @s: fhe file + * @key: the name of the key to read + * + * Reads a value @key and converts it to a NMTernary value. + * + * Returns: the parsed NMTernary + */ +NMTernary +svGetValueTernary (shvarFile *s, const char *key) +{ + return svGetValueBoolean (s, key, NM_TERNARY_DEFAULT); +} + /* svGetValueInt64: * @s: fhe file * @key: the name of the key to read @@ -1428,6 +1442,15 @@ svSetValueBoolean (shvarFile *s, const char *key, gboolean value) return svSetValue (s, key, value ? "yes" : "no"); } +gboolean +svSetValueTernary (shvarFile *s, const char *key, NMTernary value) +{ + if (NM_IN_SET (value, NM_TERNARY_TRUE, NM_TERNARY_FALSE)) + return svSetValueBoolean (s, key, (gboolean) value); + else + return svUnsetValue (s, key); +} + gboolean svSetValueBoolean_cond_true (shvarFile *s, const char *key, gboolean value) { diff --git a/src/settings/plugins/ifcfg-rh/shvar.h b/src/settings/plugins/ifcfg-rh/shvar.h index 410284f8cb..852dd4c1de 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.h +++ b/src/settings/plugins/ifcfg-rh/shvar.h @@ -66,6 +66,8 @@ const char **svGetKeysSorted (shvarFile *s, */ int svGetValueBoolean (shvarFile *s, const char *key, int def); +NMTernary svGetValueTernary (shvarFile *s, const char *key); + gint64 svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 max, gint64 fallback); gboolean svGetValueEnum (shvarFile *s, const char *key, @@ -84,6 +86,7 @@ gboolean svSetValueBoolean_cond_true (shvarFile *s, const char *key, gboolean va gboolean svSetValueInt64 (shvarFile *s, const char *key, gint64 value); gboolean svSetValueInt64_cond (shvarFile *s, const char *key, gboolean do_set, gint64 value); gboolean svSetValueEnum (shvarFile *s, const char *key, GType gtype, int value); +gboolean svSetValueTernary (shvarFile *s, const char *key, NMTernary value); gboolean svUnsetValue (shvarFile *s, const char *key); gboolean svUnsetAll (shvarFile *s, SvKeyType match_key_type);