libnm-glib: convert DHCP option parsing to GHashTableIter

This commit is contained in:
Dan Williams 2013-03-27 08:21:18 -05:00
parent a492d29ceb
commit afc7f17191
2 changed files with 16 additions and 22 deletions

View file

@ -51,26 +51,23 @@ nm_dhcp4_config_init (NMDHCP4Config *config)
{
}
static void
copy_options (gpointer key, gpointer data, gpointer user_data)
{
GHashTable *options = (GHashTable *) user_data;
GValue *value = (GValue *) data;
g_hash_table_insert (options, g_strdup (key), g_value_dup_string (value));
}
static gboolean
demarshal_dhcp4_options (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
{
NMDHCP4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object);
GHashTable *new_options;
GHashTableIter iter;
const char *key;
GValue *opt;
g_hash_table_remove_all (priv->options);
new_options = g_value_get_boxed (value);
if (new_options)
g_hash_table_foreach (new_options, copy_options, priv->options);
if (new_options) {
g_hash_table_iter_init (&iter, new_options);
while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &opt))
g_hash_table_insert (priv->options, g_strdup (key), g_value_dup_string (opt));
}
_nm_object_queue_notify (object, NM_DHCP4_CONFIG_OPTIONS);
return TRUE;

View file

@ -51,26 +51,23 @@ nm_dhcp6_config_init (NMDHCP6Config *config)
{
}
static void
copy_options (gpointer key, gpointer data, gpointer user_data)
{
GHashTable *options = (GHashTable *) user_data;
GValue *value = (GValue *) data;
g_hash_table_insert (options, g_strdup (key), g_value_dup_string (value));
}
static gboolean
demarshal_dhcp6_options (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
{
NMDHCP6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (object);
GHashTable *new_options;
GHashTableIter iter;
const char *key;
GValue *opt;
g_hash_table_remove_all (priv->options);
new_options = g_value_get_boxed (value);
if (new_options)
g_hash_table_foreach (new_options, copy_options, priv->options);
if (new_options) {
g_hash_table_iter_init (&iter, new_options);
while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &opt))
g_hash_table_insert (priv->options, g_strdup (key), g_value_dup_string (opt));
}
_nm_object_queue_notify (object, NM_DHCP6_CONFIG_OPTIONS);
return TRUE;