diff options
author | Dan Winship <danw@gnome.org> | 2014-06-24 17:40:08 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-09-04 09:20:11 -0400 |
commit | 9ed6bd2be58606e1700fe193c65e9991cf657ad0 (patch) | |
tree | 41506dcaa74b61265e8475ca2270c939816b17e6 /libnm-core | |
parent | 6a4127cfa063a77e3ee886a999441c71f6a0e11c (diff) | |
download | NetworkManager-9ed6bd2be58606e1700fe193c65e9991cf657ad0.tar.gz |
libnm-core: change map-of-string properties to G_TYPE_HASH_TABLE
Change all DBUS_TYPE_G_MAP_OF_STRING properties to G_TYPE_HASH_TABLE,
with annotations indicating they are string->string. Not much outside
libnm-core needs to changed for this, since DBUS_TYPE_G_MAP_OF_STRING
was already represented as a hash table.
(One change needed within libnm-core is that we now need to copy the
hash tables in get_property(), or else the caller will receive a
reffed copy of the object's own hash table, which we don't want.)
Diffstat (limited to 'libnm-core')
-rw-r--r-- | libnm-core/nm-core-internal.h | 2 | ||||
-rw-r--r-- | libnm-core/nm-setting-bond.c | 32 | ||||
-rw-r--r-- | libnm-core/nm-setting-vpn.c | 44 | ||||
-rw-r--r-- | libnm-core/nm-setting-wired.c | 24 | ||||
-rw-r--r-- | libnm-core/nm-utils-private.h | 5 | ||||
-rw-r--r-- | libnm-core/nm-utils.c | 30 | ||||
-rw-r--r-- | libnm-core/nm-value-transforms.c | 30 |
7 files changed, 82 insertions, 85 deletions
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index 1e6dd63892..b02bb69850 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -63,5 +63,7 @@ gboolean _nm_setting_ip4_config_add_address_with_label (NMSettingIP4Config *s GSList * _nm_utils_hash_values_to_slist (GHashTable *hash); +GHashTable *_nm_utils_copy_strdict (GHashTable *strdict); + #endif diff --git a/libnm-core/nm-setting-bond.c b/libnm-core/nm-setting-bond.c index 8c5ba5e3bb..22fa19f3e4 100644 --- a/libnm-core/nm-setting-bond.c +++ b/libnm-core/nm-setting-bond.c @@ -670,25 +670,15 @@ finalize (GObject *object) } static void -copy_hash (gpointer key, gpointer value, gpointer user_data) -{ - g_hash_table_insert ((GHashTable *) user_data, g_strdup (key), g_strdup (value)); -} - -static void set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (object); - GHashTable *new_hash; switch (prop_id) { case PROP_OPTIONS: - /* Must make a deep copy of the hash table here... */ - g_hash_table_remove_all (priv->options); - new_hash = g_value_get_boxed (value); - if (new_hash) - g_hash_table_foreach (new_hash, copy_hash, priv->options); + g_hash_table_unref (priv->options); + priv->options = _nm_utils_copy_strdict (g_value_get_boxed (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -704,7 +694,7 @@ get_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_OPTIONS: - g_value_set_boxed (value, priv->options); + g_value_take_boxed (value, _nm_utils_copy_strdict (priv->options)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -733,14 +723,20 @@ nm_setting_bond_class_init (NMSettingBondClass *setting_class) * Dictionary of key/value pairs of bonding options. Both keys and values * must be strings. Option names must contain only alphanumeric characters * (ie, [a-zA-Z0-9]). + * + * Type: GHashTable(utf8,utf8) **/ g_object_class_install_property (object_class, PROP_OPTIONS, - g_param_spec_boxed (NM_SETTING_BOND_OPTIONS, "", "", - DBUS_TYPE_G_MAP_OF_STRING, - G_PARAM_READWRITE | - NM_SETTING_PARAM_INFERRABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_boxed (NM_SETTING_BOND_OPTIONS, "", "", + G_TYPE_HASH_TABLE, + G_PARAM_READWRITE | + NM_SETTING_PARAM_INFERRABLE | + G_PARAM_STATIC_STRINGS)); + _nm_setting_class_transform_property (parent_class, NM_SETTING_BOND_OPTIONS, + DBUS_TYPE_G_MAP_OF_STRING, + _nm_utils_strdict_to_dbus, + _nm_utils_strdict_from_dbus); _nm_setting_class_add_dbus_only_property (parent_class, "interface-name", G_TYPE_STRING, _nm_setting_get_deprecated_virtual_interface_name, diff --git a/libnm-core/nm-setting-vpn.c b/libnm-core/nm-setting-vpn.c index 1e902e202c..30a4893d31 100644 --- a/libnm-core/nm-setting-vpn.c +++ b/libnm-core/nm-setting-vpn.c @@ -27,6 +27,7 @@ #include "nm-setting-vpn.h" #include "nm-utils.h" +#include "nm-utils-private.h" #include "nm-dbus-glib-types.h" #include "nm-setting-private.h" @@ -714,19 +715,10 @@ finalize (GObject *object) } static void -copy_hash (gpointer key, gpointer value, gpointer user_data) -{ - g_return_if_fail (value != NULL); - g_return_if_fail (strlen (value)); - g_hash_table_insert ((GHashTable *) user_data, g_strdup (key), g_strdup (value)); -} - -static void set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (object); - GHashTable *new_hash; switch (prop_id) { case PROP_SERVICE_TYPE: @@ -738,18 +730,12 @@ set_property (GObject *object, guint prop_id, priv->user_name = g_value_dup_string (value); break; case PROP_DATA: - /* Must make a deep copy of the hash table here... */ - g_hash_table_remove_all (priv->data); - new_hash = g_value_get_boxed (value); - if (new_hash) - g_hash_table_foreach (new_hash, copy_hash, priv->data); + g_hash_table_unref (priv->data); + priv->data = _nm_utils_copy_strdict (g_value_get_boxed (value)); break; case PROP_SECRETS: - /* Must make a deep copy of the hash table here... */ - g_hash_table_remove_all (priv->secrets); - new_hash = g_value_get_boxed (value); - if (new_hash) - g_hash_table_foreach (new_hash, copy_hash, priv->secrets); + g_hash_table_unref (priv->secrets); + priv->secrets = _nm_utils_copy_strdict (g_value_get_boxed (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -772,10 +758,10 @@ get_property (GObject *object, guint prop_id, g_value_set_string (value, nm_setting_vpn_get_user_name (setting)); break; case PROP_DATA: - g_value_set_boxed (value, priv->data); + g_value_take_boxed (value, _nm_utils_copy_strdict (priv->data)); break; case PROP_SECRETS: - g_value_set_boxed (value, priv->secrets); + g_value_take_boxed (value, _nm_utils_copy_strdict (priv->secrets)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -841,25 +827,37 @@ nm_setting_vpn_class_init (NMSettingVpnClass *setting_class) * * Dictionary of key/value pairs of VPN plugin specific data. Both keys and * values must be strings. + * + * Type: GHashTable(utf8,utf8) **/ g_object_class_install_property (object_class, PROP_DATA, g_param_spec_boxed (NM_SETTING_VPN_DATA, "", "", - DBUS_TYPE_G_MAP_OF_STRING, + G_TYPE_HASH_TABLE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + _nm_setting_class_transform_property (parent_class, NM_SETTING_VPN_DATA, + DBUS_TYPE_G_MAP_OF_STRING, + _nm_utils_strdict_to_dbus, + _nm_utils_strdict_from_dbus); /** * NMSettingVpn:secrets: * * Dictionary of key/value pairs of VPN plugin specific secrets like * passwords or private keys. Both keys and values must be strings. + * + * Type: GHashTable(utf8,utf8) **/ g_object_class_install_property (object_class, PROP_SECRETS, g_param_spec_boxed (NM_SETTING_VPN_SECRETS, "", "", - DBUS_TYPE_G_MAP_OF_STRING, + G_TYPE_HASH_TABLE, G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET | G_PARAM_STATIC_STRINGS)); + _nm_setting_class_transform_property (parent_class, NM_SETTING_VPN_SECRETS, + DBUS_TYPE_G_MAP_OF_STRING, + _nm_utils_strdict_to_dbus, + _nm_utils_strdict_from_dbus); } diff --git a/libnm-core/nm-setting-wired.c b/libnm-core/nm-setting-wired.c index e115da69db..f641e8a813 100644 --- a/libnm-core/nm-setting-wired.c +++ b/libnm-core/nm-setting-wired.c @@ -707,17 +707,10 @@ finalize (GObject *object) } static void -copy_hash (gpointer key, gpointer value, gpointer user_data) -{ - g_hash_table_insert ((GHashTable *) user_data, g_strdup (key), g_strdup (value)); -} - -static void set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { NMSettingWiredPrivate *priv = NM_SETTING_WIRED_GET_PRIVATE (object); - GHashTable *new_hash; switch (prop_id) { case PROP_PORT: @@ -759,11 +752,8 @@ set_property (GObject *object, guint prop_id, priv->s390_nettype = g_value_dup_string (value); break; case PROP_S390_OPTIONS: - /* Must make a deep copy of the hash table here... */ - g_hash_table_remove_all (priv->s390_options); - new_hash = g_value_get_boxed (value); - if (new_hash) - g_hash_table_foreach (new_hash, copy_hash, priv->s390_options); + g_hash_table_unref (priv->s390_options); + priv->s390_options = _nm_utils_copy_strdict (g_value_get_boxed (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -810,7 +800,7 @@ get_property (GObject *object, guint prop_id, g_value_set_string (value, nm_setting_wired_get_s390_nettype (setting)); break; case PROP_S390_OPTIONS: - g_value_set_boxed (value, priv->s390_options); + g_value_take_boxed (value, _nm_utils_copy_strdict (priv->s390_options)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -998,12 +988,18 @@ nm_setting_wired_class_init (NMSettingWiredClass *setting_class) * and values must be strings. Allowed keys include "portno", "layer2", * "portname", "protocol", among others. Key names must contain only * alphanumeric characters (ie, [a-zA-Z0-9]). + * + * Type: GHashTable(utf8,utf8) **/ g_object_class_install_property (object_class, PROP_S390_OPTIONS, g_param_spec_boxed (NM_SETTING_WIRED_S390_OPTIONS, "", "", - DBUS_TYPE_G_MAP_OF_STRING, + G_TYPE_HASH_TABLE, G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); + _nm_setting_class_transform_property (parent_class, NM_SETTING_WIRED_S390_OPTIONS, + DBUS_TYPE_G_MAP_OF_STRING, + _nm_utils_strdict_to_dbus, + _nm_utils_strdict_from_dbus); } diff --git a/libnm-core/nm-utils-private.h b/libnm-core/nm-utils-private.h index b4ddf6e8a0..9154a40598 100644 --- a/libnm-core/nm-utils-private.h +++ b/libnm-core/nm-utils-private.h @@ -39,6 +39,11 @@ void _nm_utils_hwaddr_to_dbus (const GValue *prop_value, void _nm_utils_hwaddr_from_dbus (const GValue *dbus_value, GValue *prop_value); +void _nm_utils_strdict_to_dbus (const GValue *prop_value, + GValue *dbus_value); +void _nm_utils_strdict_from_dbus (const GValue *dbus_value, + GValue *prop_value); + GSList * _nm_utils_strv_to_slist (char **strv); char ** _nm_utils_slist_to_strv (GSList *slist); diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 9945a79210..444a5d71e8 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -564,6 +564,36 @@ _nm_utils_hash_values_to_slist (GHashTable *hash) return list; } +void +_nm_utils_strdict_to_dbus (const GValue *prop_value, + GValue *dbus_value) +{ + g_value_set_boxed (dbus_value, g_value_get_boxed (prop_value)); +} + +void +_nm_utils_strdict_from_dbus (const GValue *dbus_value, + GValue *prop_value) +{ + g_value_set_boxed (prop_value, g_value_get_boxed (dbus_value)); +} + +GHashTable * +_nm_utils_copy_strdict (GHashTable *strdict) +{ + GHashTable *copy; + GHashTableIter iter; + gpointer key, value; + + copy = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + if (strdict) { + g_hash_table_iter_init (&iter, strdict); + while (g_hash_table_iter_next (&iter, &key, &value)) + g_hash_table_insert (copy, g_strdup (key), g_strdup (value)); + } + return copy; +} + GSList * _nm_utils_strv_to_slist (char **strv) { diff --git a/libnm-core/nm-value-transforms.c b/libnm-core/nm-value-transforms.c index 2631a9d651..de73d9b44e 100644 --- a/libnm-core/nm-value-transforms.c +++ b/libnm-core/nm-value-transforms.c @@ -174,33 +174,6 @@ _nm_utils_convert_gvalue_hash_to_string (const GValue *src_value, GValue *dest_v } static void -convert_one_string_hash_entry (gpointer key, gpointer value, gpointer user_data) -{ - GString *printable = (GString *) user_data; - - if (printable->len) - g_string_append_c (printable, ','); - g_string_append_printf (printable, "%s=%s", (const char *) key, (const char *) value); -} - -static void -_nm_utils_convert_string_hash_to_string (const GValue *src_value, GValue *dest_value) -{ - GHashTable *hash; - GString *printable; - - g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_MAP_OF_STRING)); - - hash = (GHashTable *) g_value_get_boxed (src_value); - - printable = g_string_new (NULL); - if (hash) - g_hash_table_foreach (hash, convert_one_string_hash_entry, printable); - - g_value_take_string (dest_value, g_string_free (printable, FALSE)); -} - -static void _nm_utils_convert_byte_array_to_string (const GValue *src_value, GValue *dest_value) { GArray *array; @@ -470,9 +443,6 @@ _nm_value_transforms_register (void) g_value_register_transform_func (DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_STRING, _nm_utils_convert_gvalue_hash_to_string); - g_value_register_transform_func (DBUS_TYPE_G_MAP_OF_STRING, - G_TYPE_STRING, - _nm_utils_convert_string_hash_to_string); g_value_register_transform_func (DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_STRING, _nm_utils_convert_byte_array_to_string); |