summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-04-23 16:34:59 +0200
committerThomas Haller <thaller@redhat.com>2019-04-23 16:37:23 +0200
commit4e9ea585bd2a86e00c1f332c77de3f6d5cbd010f (patch)
tree99c3af2daa4bc15454f317f2145caeb90c44ad85
parentf519a90994e2dcbeddd421a9ce8dd001f8219fc0 (diff)
downloadNetworkManager-4e9ea585bd2a86e00c1f332c77de3f6d5cbd010f.tar.gz
cli: drop GValue transform functions for strdict and implement it in _get_fcn_gobject_impl()
The only remaining GValue transform function was from GHashTable (of (str,str) type) to string. Drop that too, and implement the conversion in _get_fcn_gobject_impl(). Note that there are few GObject properties of type GHashTable and most of them implement their own logic. This only applies to "802-3-ethernet.s390-options". Also, always sort the keys. Otherwise, the output is not stable.
-rw-r--r--clients/cli/nmcli.c36
-rw-r--r--clients/common/nm-meta-setting-desc.c35
2 files changed, 26 insertions, 45 deletions
diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c
index 9076e13d7c..ad45f179a5 100644
--- a/clients/cli/nmcli.c
+++ b/clients/cli/nmcli.c
@@ -915,40 +915,6 @@ signal_handler (gpointer user_data)
return G_SOURCE_CONTINUE;
}
-static void
-nmc_convert_string_hash_to_string (const GValue *src_value, GValue *dest_value)
-{
- GHashTable *hash;
- GHashTableIter iter;
- const char *key, *value;
- GString *string;
-
- hash = (GHashTable *) g_value_get_boxed (src_value);
-
- string = g_string_new (NULL);
- if (hash) {
- g_hash_table_iter_init (&iter, hash);
- while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &value)) {
- if (string->len)
- g_string_append_c (string, ',');
- g_string_append_printf (string, "%s=%s", key, value);
- }
- }
-
- g_value_take_string (dest_value, g_string_free (string, FALSE));
-}
-
-static void
-nmc_value_transforms_register (void)
-{
- /* This depends on the fact that all of the hash-table-valued properties
- * in libnm-core are string->string.
- */
- g_value_register_transform_func (G_TYPE_HASH_TABLE,
- G_TYPE_STRING,
- nmc_convert_string_hash_to_string);
-}
-
void
nm_cli_spawn_pager (NmCli *nmc)
{
@@ -1006,8 +972,6 @@ main (int argc, char *argv[])
/* Save terminal settings */
tcgetattr (STDIN_FILENO, &termios_orig);
- nmc_value_transforms_register ();
-
nm_cli.return_text = g_string_new (_("Success"));
loop = g_main_loop_new (NULL, FALSE);
diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c
index 40cf5be88e..0491afa0e4 100644
--- a/clients/common/nm-meta-setting-desc.c
+++ b/clients/common/nm-meta-setting-desc.c
@@ -848,17 +848,11 @@ _get_fcn_gobject_impl (const NMMetaPropertyInfo *property_info,
glib_handles_str_transform = !NM_IN_SET (gtype_prop, G_TYPE_BOOLEAN,
G_TYPE_STRV,
- G_TYPE_BYTES);
+ G_TYPE_BYTES,
+ G_TYPE_HASH_TABLE);
if (glib_handles_str_transform) {
- /* We rely on the type convertion of the gobject property to string.
- *
- * Note that we register some transformations via nmc_value_transforms_register()
- * to make that working for G_TYPE_HASH_TABLE.
- *
- * FIXME: that is particularly ugly because it's non-obvious which code relies
- * on nmc_value_transforms_register(). Also, nmc_value_transforms_register() is
- * in clients/cli, while we are here in clients/common. */
+ /* We rely on the type convertion of the gobject property to string. */
g_value_init (&val, G_TYPE_STRING);
} else
g_value_init (&val, gtype_prop);
@@ -911,6 +905,29 @@ _get_fcn_gobject_impl (const NMMetaPropertyInfo *property_info,
RETURN_STR_TO_FREE (str);
}
+ if (gtype_prop == G_TYPE_HASH_TABLE) {
+ GHashTable *strdict;
+ gs_free const char **keys = NULL;
+ GString *str;
+ gsize i;
+
+ strdict = g_value_get_boxed (&val);
+ keys = nm_utils_strdict_get_keys (strdict, TRUE, NULL);
+ if (!keys)
+ return NULL;
+
+ str = g_string_new (NULL);
+ for (i = 0; keys[i]; i++) {
+ if (str->len > 0)
+ g_string_append_c (str, ',');
+ g_string_append_printf (str,
+ "%s=%s",
+ keys[i],
+ (const char *) g_hash_table_lookup (strdict, keys[i]));
+ }
+ RETURN_STR_TO_FREE (g_string_free (str, FALSE));
+ }
+
nm_assert_not_reached ();
return NULL;
}