summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-04-28 11:53:07 +0200
committerThomas Haller <thaller@redhat.com>2017-04-28 12:21:17 +0200
commit7298798a64fb5ae571b29610408bc28edce0aeae (patch)
tree1d6e0efe4f8c7995267ddb9eaed6b484bf0f2d57
parente81bdf19fa826750ef4e157c200f422179abc16e (diff)
downloadNetworkManager-7298798a64fb5ae571b29610408bc28edce0aeae.tar.gz
ifcfg-rh: add svGetValueEnum()
-rw-r--r--src/settings/plugins/ifcfg-rh/shvar.c28
-rw-r--r--src/settings/plugins/ifcfg-rh/shvar.h4
2 files changed, 32 insertions, 0 deletions
diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c
index 76c8d7c926..cddf3daa72 100644
--- a/src/settings/plugins/ifcfg-rh/shvar.c
+++ b/src/settings/plugins/ifcfg-rh/shvar.c
@@ -1057,6 +1057,34 @@ svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 m
return result;
}
+gboolean
+svGetValueEnum (shvarFile *s, const char *key,
+ GType gtype, int *out_value,
+ GError **error)
+{
+ gs_free char *to_free = NULL;
+ const char *svalue;
+ gs_free char *err_token = NULL;
+ int value;
+
+ svalue = _svGetValue (s, key, &to_free);
+ if (!svalue) {
+ /* don't touch out_value. The caller is supposed
+ * to initialize it with the default value. */
+ return TRUE;
+ }
+
+ if (!nm_utils_enum_from_str (gtype, svalue, &value, &err_token)) {
+ g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_UNKNOWN,
+ "Invalid token \"%s\" in \"%s\" for %s",
+ err_token, svalue, key);
+ return FALSE;
+ }
+
+ NM_SET_OUT (out_value, value);
+ return TRUE;
+}
+
/*****************************************************************************/
/* Same as svSetValueStr() but it preserves empty @value -- contrary to
diff --git a/src/settings/plugins/ifcfg-rh/shvar.h b/src/settings/plugins/ifcfg-rh/shvar.h
index 7ad2bc8863..8654d73c75 100644
--- a/src/settings/plugins/ifcfg-rh/shvar.h
+++ b/src/settings/plugins/ifcfg-rh/shvar.h
@@ -64,6 +64,10 @@ gint svGetValueBoolean (shvarFile *s, const char *key, gint def);
gint64 svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 max, gint64 fallback);
+gboolean svGetValueEnum (shvarFile *s, const char *key,
+ GType gtype, int *out_value,
+ GError **error);
+
/* Set the variable <key> equal to the value <value>.
* If <key> does not exist, and the <current> pointer is set, append
* the key=value pair after that line. Otherwise, prepend the pair