From 6fdff4f687429302dfc73534d9b41a3d34a976f8 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 4 Dec 2007 16:09:05 +0000 Subject: [PATCH] 2007-12-04 Dan Williams * libnm-util/nm-setting-vpn-properties.h - Clarify usage of the 'data' member of the setting * libnm-util/nm-setting-vpn-properties.c - (nm_setting_vpn_properties_init): initialize the 'data' hash table - (set_property): just remove all the settings; don't recreate the has - (update_one_secret): don't need to create the hash table here since it should always be present git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3129 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 11 +++++++++++ libnm-util/nm-setting-vpn-properties.c | 22 +++++++++------------- libnm-util/nm-setting-vpn-properties.h | 7 +++++++ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 17582447a1..66064b8a8b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2007-12-04 Dan Williams + + * libnm-util/nm-setting-vpn-properties.h + - Clarify usage of the 'data' member of the setting + + * libnm-util/nm-setting-vpn-properties.c + - (nm_setting_vpn_properties_init): initialize the 'data' hash table + - (set_property): just remove all the settings; don't recreate the has + - (update_one_secret): don't need to create the hash table here since + it should always be present + 2007-12-03 Tambet Ingo Implement PIN and PUK requesting. diff --git a/libnm-util/nm-setting-vpn-properties.c b/libnm-util/nm-setting-vpn-properties.c index cc68d84b70..1bd6251263 100644 --- a/libnm-util/nm-setting-vpn-properties.c +++ b/libnm-util/nm-setting-vpn-properties.c @@ -24,8 +24,7 @@ verify (NMSetting *setting, GSList *all_settings) { NMSettingVPNProperties *self = NM_SETTING_VPN_PROPERTIES (setting); - if (!self->data) - return FALSE; + g_return_val_if_fail (self->data != NULL, FALSE); /* FIXME: actually check the data as well */ @@ -51,8 +50,6 @@ update_one_secret (NMSetting *setting, const char *key, GValue *value) g_return_if_fail (value != NULL); /* Secrets are really only known to the VPNs themselves. */ - if (!self->data) - self->data = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, nm_gvalue_destroy); copy_val = g_slice_new0 (GValue); g_value_init (copy_val, G_VALUE_TYPE (value)); g_value_copy (value, copy_val); @@ -60,9 +57,11 @@ update_one_secret (NMSetting *setting, const char *key, GValue *value) } static void -nm_setting_vpn_properties_init (NMSettingVPNProperties *setting) +nm_setting_vpn_properties_init (NMSettingVPNProperties *self) { - ((NMSetting *) setting)->name = g_strdup (NM_SETTING_VPN_PROPERTIES_SETTING_NAME); + g_object_set (NM_SETTING (self), "name", NM_SETTING_VPN_PROPERTIES_SETTING_NAME, NULL); + + self->data = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, nm_gvalue_destroy); } static void @@ -78,14 +77,14 @@ finalize (GObject *object) static void copy_hash (gpointer key, gpointer data, gpointer user_data) { - NMSettingVPNProperties *setting = NM_SETTING_VPN_PROPERTIES (user_data); + GHashTable *hash = (GHashTable *) user_data; GValue *src_val = (GValue *) data; GValue *copy_val; copy_val = g_slice_new0 (GValue); g_value_init (copy_val, G_VALUE_TYPE (src_val)); g_value_copy (src_val, copy_val); - g_hash_table_insert (setting->data, g_strdup (key), copy_val); + g_hash_table_insert (hash, g_strdup (key), copy_val); } static void @@ -96,12 +95,9 @@ set_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_DATA: - if (setting->data) - g_hash_table_destroy (setting->data); - /* Must make a deep copy of the hash table here... */ - setting->data = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, nm_gvalue_destroy); - g_hash_table_foreach (g_value_get_boxed (value), copy_hash, setting); + g_hash_table_remove_all (setting->data); + g_hash_table_foreach (g_value_get_boxed (value), copy_hash, setting->data); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); diff --git a/libnm-util/nm-setting-vpn-properties.h b/libnm-util/nm-setting-vpn-properties.h index 8590149563..61a684c24c 100644 --- a/libnm-util/nm-setting-vpn-properties.h +++ b/libnm-util/nm-setting-vpn-properties.h @@ -20,6 +20,13 @@ G_BEGIN_DECLS typedef struct { NMSetting parent; + /* The hash table is created at setting object + * init time and should not be replaced. It is + * a char * -> GValue * mapping, and both the key + * and value are owned by the hash table. GValues + * inserted into the hash table must be allocated + * with the g_slice_* functions. + */ GHashTable *data; } NMSettingVPNProperties;