summaryrefslogtreecommitdiff
path: root/libnm-core/nm-setting.c
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2018-07-26 11:59:24 +0200
committerLubomir Rintel <lkundrak@v3.sk>2018-07-26 12:26:18 +0200
commitf957ea2b343828ad1fa2014bc7a4dedaf854f3bc (patch)
tree2cf745e6c603fab9ae091519bf7c022af962f0b5 /libnm-core/nm-setting.c
parente0a93ac1e52365fce6e69d8d882f69537679415f (diff)
downloadNetworkManager-f957ea2b343828ad1fa2014bc7a4dedaf854f3bc.tar.gz
core/setting: rework nm_connection_dump()
Utilize _nm_setting_to_dbus() to serialize the setting. The main reason is that this way we can also print the more complicated values g_strdup_value_contents() can't grok, e.g. the GArrays and GHashTables. Some effort was spent on tidying up the results in a manner it was done previously, instead of reducing this to a plain g_variant_print(). It looks good that way: Before: vpn service-type : "org.freedesktop.NetworkManager.VPN.Novpn" (s) user-name : NULL (sd) persistent : FALSE (sd) data : ((GHashTable*) 0xc61060) (s) secrets : ((GHashTable*) 0xdda640) (s) timeout : 0 (sd) After: vpn service-type : 'org.freedesktop.NetworkManager.VPN.Novpn' data : {'gateway': 'novpn.example.com', 'username': 'hello'} secrets : {'password': 'world'} Note that no effort was spent on printing the defaults. There are multiple ways that could be achieved, but I'm not sure it would be all that necessary given this is really just a quick'n'dirty debugging facilty.
Diffstat (limited to 'libnm-core/nm-setting.c')
-rw-r--r--libnm-core/nm-setting.c53
1 files changed, 17 insertions, 36 deletions
diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c
index 575305e220..1ee14d88b9 100644
--- a/libnm-core/nm-setting.c
+++ b/libnm-core/nm-setting.c
@@ -1969,59 +1969,40 @@ nm_setting_set_secret_flags (NMSetting *setting,
* nm_setting_to_string:
* @setting: the #NMSetting
*
- * Convert the setting into a string. For debugging purposes ONLY, should NOT
- * be used for serialization of the setting, or machine-parsed in any way. The
- * output format is not guaranteed to be stable and may change at any time.
+ * Convert the setting (including secrets!) into a string. For debugging
+ * purposes ONLY, should NOT be used for serialization of the setting,
+ * or machine-parsed in any way. The output format is not guaranteed to
+ * be stable and may change at any time.
*
* Returns: an allocated string containing a textual representation of the
- * setting's properties and values (including secrets!), which the caller should
+ * setting's properties and values, which the caller should
* free with g_free()
**/
char *
nm_setting_to_string (NMSetting *setting)
{
GString *string;
- GParamSpec **property_specs;
- guint n_property_specs;
- guint i;
-
- g_return_val_if_fail (NM_IS_SETTING (setting), NULL);
-
- property_specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (setting), &n_property_specs);
+ gs_unref_variant GVariant *variant;
+ GVariant *child;
+ GVariantIter iter;
string = g_string_new (nm_setting_get_name (setting));
g_string_append_c (string, '\n');
- for (i = 0; i < n_property_specs; i++) {
- GParamSpec *prop_spec = property_specs[i];
- GValue value = G_VALUE_INIT;
- char *value_str;
- gboolean is_default;
-
- if (strcmp (prop_spec->name, NM_SETTING_NAME) == 0)
- continue;
-
- g_value_init (&value, prop_spec->value_type);
- g_object_get_property (G_OBJECT (setting), prop_spec->name, &value);
+ variant = _nm_setting_to_dbus (setting, NULL, NM_CONNECTION_SERIALIZE_ALL);
- value_str = g_strdup_value_contents (&value);
- g_string_append_printf (string, "\t%s : %s", prop_spec->name, value_str);
- g_free (value_str);
+ g_variant_iter_init (&iter, variant);
+ while ((child = g_variant_iter_next_value (&iter))) {
+ gs_free char *name;
+ gs_free char *value_str;
+ gs_unref_variant GVariant *value;
- is_default = g_param_value_defaults (prop_spec, &value);
- g_value_unset (&value);
+ g_variant_get (child, "{sv}", &name, &value);
+ value_str = g_variant_print (value, FALSE);
- g_string_append (string, " (");
- g_string_append_c (string, 's');
- if (is_default)
- g_string_append_c (string, 'd');
- g_string_append_c (string, ')');
- g_string_append_c (string, '\n');
+ g_string_append_printf (string, "\t%s : %s\n", name, value_str);
}
- g_free (property_specs);
- g_string_append_c (string, '\n');
-
return g_string_free (string, FALSE);
}