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.
This commit is contained in:
@@ -1995,9 +1995,10 @@ nm_connection_for_each_setting_value (NMConnection *connection,
|
|||||||
* nm_connection_dump:
|
* nm_connection_dump:
|
||||||
* @connection: the #NMConnection
|
* @connection: the #NMConnection
|
||||||
*
|
*
|
||||||
* Print the connection to stdout. For debugging purposes ONLY, should NOT
|
* Print the connection (including secrets!) to stdout. For debugging
|
||||||
* be used for serialization of the connection or machine-parsed in any way. The
|
* purposes ONLY, should NOT be used for serialization of the setting,
|
||||||
* output format is not guaranteed to be stable and may change at any time.
|
* or machine-parsed in any way. The output format is not guaranteed to
|
||||||
|
* be stable and may change at any time.
|
||||||
**/
|
**/
|
||||||
void
|
void
|
||||||
nm_connection_dump (NMConnection *connection)
|
nm_connection_dump (NMConnection *connection)
|
||||||
|
@@ -1969,59 +1969,40 @@ nm_setting_set_secret_flags (NMSetting *setting,
|
|||||||
* nm_setting_to_string:
|
* nm_setting_to_string:
|
||||||
* @setting: the #NMSetting
|
* @setting: the #NMSetting
|
||||||
*
|
*
|
||||||
* Convert the setting into a string. For debugging purposes ONLY, should NOT
|
* Convert the setting (including secrets!) into a string. For debugging
|
||||||
* be used for serialization of the setting, or machine-parsed in any way. The
|
* purposes ONLY, should NOT be used for serialization of the setting,
|
||||||
* output format is not guaranteed to be stable and may change at any time.
|
* 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
|
* 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()
|
* free with g_free()
|
||||||
**/
|
**/
|
||||||
char *
|
char *
|
||||||
nm_setting_to_string (NMSetting *setting)
|
nm_setting_to_string (NMSetting *setting)
|
||||||
{
|
{
|
||||||
GString *string;
|
GString *string;
|
||||||
GParamSpec **property_specs;
|
gs_unref_variant GVariant *variant;
|
||||||
guint n_property_specs;
|
GVariant *child;
|
||||||
guint i;
|
GVariantIter iter;
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
string = g_string_new (nm_setting_get_name (setting));
|
string = g_string_new (nm_setting_get_name (setting));
|
||||||
g_string_append_c (string, '\n');
|
g_string_append_c (string, '\n');
|
||||||
|
|
||||||
for (i = 0; i < n_property_specs; i++) {
|
variant = _nm_setting_to_dbus (setting, NULL, NM_CONNECTION_SERIALIZE_ALL);
|
||||||
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)
|
g_variant_iter_init (&iter, variant);
|
||||||
continue;
|
while ((child = g_variant_iter_next_value (&iter))) {
|
||||||
|
gs_free char *name;
|
||||||
|
gs_free char *value_str;
|
||||||
|
gs_unref_variant GVariant *value;
|
||||||
|
|
||||||
g_value_init (&value, prop_spec->value_type);
|
g_variant_get (child, "{sv}", &name, &value);
|
||||||
g_object_get_property (G_OBJECT (setting), prop_spec->name, &value);
|
value_str = g_variant_print (value, FALSE);
|
||||||
|
|
||||||
value_str = g_strdup_value_contents (&value);
|
g_string_append_printf (string, "\t%s : %s\n", name, value_str);
|
||||||
g_string_append_printf (string, "\t%s : %s", prop_spec->name, value_str);
|
|
||||||
g_free (value_str);
|
|
||||||
|
|
||||||
is_default = g_param_value_defaults (prop_spec, &value);
|
|
||||||
g_value_unset (&value);
|
|
||||||
|
|
||||||
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_free (property_specs);
|
|
||||||
g_string_append_c (string, '\n');
|
|
||||||
|
|
||||||
return g_string_free (string, FALSE);
|
return g_string_free (string, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user