2008-11-19 Dan Williams <dcbw@redhat.com>
authorDan Williams <dcbw@redhat.com>
Wed, 19 Nov 2008 15:09:05 +0000 (15:09 +0000)
committerDan Williams <dcbw@redhat.com>
Wed, 19 Nov 2008 15:09:05 +0000 (15:09 +0000)
* libnm-util/nm-connection.c
  libnm-util/nm-connection.h
- (nm_connection_replace_settings): take a GError

* libnm-glib/nm-settings.c
  libnm-glib/nm-dbus-connection.c
  src/nm-manager.c
  system-settings/plugins/ifcfg-suse/nm-suse-connection.c
  system-settings/plugins/keyfile/nm-keyfile-connection.c
  system-settings/plugins/keyfile/plugin.c
- Handle, or don't handle, errors from nm_connection_replace_settings()

git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4298 4912f4e0-d625-0410-9fb7-b9a5a253dbdc

ChangeLog
libnm-glib/nm-dbus-connection.c
libnm-glib/nm-settings.c
libnm-util/nm-connection.c
libnm-util/nm-connection.h
src/nm-manager.c
system-settings/plugins/ifcfg-suse/nm-suse-connection.c
system-settings/plugins/keyfile/nm-keyfile-connection.c
system-settings/plugins/keyfile/plugin.c

index 8f5b535..9c06300 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2008-11-19  Dan Williams  <dcbw@redhat.com>
+
+       * libnm-util/nm-connection.c
+         libnm-util/nm-connection.h
+               - (nm_connection_replace_settings): take a GError
+
+       * libnm-glib/nm-settings.c
+         libnm-glib/nm-dbus-connection.c
+         src/nm-manager.c
+         system-settings/plugins/ifcfg-suse/nm-suse-connection.c
+         system-settings/plugins/keyfile/nm-keyfile-connection.c
+         system-settings/plugins/keyfile/plugin.c
+               - Handle, or don't handle, errors from nm_connection_replace_settings()
+
 2008-11-19  Dan Williams  <dcbw@redhat.com>
 
        * libnm-util/libnm-util.ver
index f027b0a..631ee3c 100644 (file)
@@ -94,12 +94,20 @@ connection_updated_cb (DBusGProxy *proxy, GHashTable *settings, gpointer user_da
 {
        NMExportedConnection *exported = NM_EXPORTED_CONNECTION (user_data);
        NMConnection *wrapped;
+       GError *error = NULL;
 
        wrapped = nm_exported_connection_get_connection (exported);
-       if (nm_connection_replace_settings (wrapped, settings))
+       if (nm_connection_replace_settings (wrapped, settings, &error))
                nm_exported_connection_signal_updated (exported, settings);
-       else
+       else {
+               g_warning ("%s: '%s' / '%s' invalid: %d",
+                          __func__,
+                          error ? g_type_name (nm_connection_lookup_setting_type_by_quark (error->domain)) : "(none)",
+                          (error && error->message) ? error->message : "(none)",
+                          error ? error->code : -1);
+               g_clear_error (&error);
                nm_exported_connection_signal_removed (exported);
+       }
 }
 
 static void
index ab860f9..34516b7 100644 (file)
@@ -524,6 +524,7 @@ nm_exported_connection_update (NMExportedConnection *connection,
                                                 GError **err)
 {
        gboolean success = TRUE;
+       GError *error = NULL;
 
        g_return_val_if_fail (NM_IS_EXPORTED_CONNECTION (connection), FALSE);
        g_return_val_if_fail (new_settings != NULL, FALSE);
@@ -532,8 +533,16 @@ nm_exported_connection_update (NMExportedConnection *connection,
                success = EXPORTED_CONNECTION_CLASS (connection)->update (connection, new_settings, err);
 
        if (success) {
-               nm_connection_replace_settings (NM_EXPORTED_CONNECTION_GET_PRIVATE (connection)->wrapped, new_settings);
-               nm_exported_connection_signal_updated (connection, new_settings);
+               if (!nm_connection_replace_settings (NM_EXPORTED_CONNECTION_GET_PRIVATE (connection)->wrapped, new_settings, &error)) {
+                       g_warning ("%s: '%s' / '%s' invalid: %d",
+                                  __func__,
+                                  error ? g_type_name (nm_connection_lookup_setting_type_by_quark (error->domain)) : "(none)",
+                                  (error && error->message) ? error->message : "(none)",
+                                  error ? error->code : -1);
+                       g_clear_error (&error);
+                       success = FALSE;
+               } else
+                       nm_exported_connection_signal_updated (connection, new_settings);
        }
 
        return success;
index e44a144..c16f8a0 100644 (file)
@@ -347,29 +347,30 @@ nm_connection_get_setting_by_name (NMConnection *connection, const char *name)
        return type ? nm_connection_get_setting (connection, type) : NULL;
 }
 
+/**
+ * nm_connection_replace_settings:
+ * @connection: a #NMConnection
+ * @new_settings: a #GHashTable of settings
+ * @error: location to store error, or %NULL
+ *
+ * Returns: TRUE if the settings were valid and added to the connection, FALSE
+ * if they were not
+ **/
 gboolean
 nm_connection_replace_settings (NMConnection *connection,
-                                GHashTable *new_settings)
+                                GHashTable *new_settings,
+                                GError **error)
 {
-       GError *error = NULL;
-
+       g_return_val_if_fail (connection != NULL, FALSE);
        g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
        g_return_val_if_fail (new_settings != NULL, FALSE);
+       if (error)
+               g_return_val_if_fail (*error == NULL, FALSE);
 
        g_hash_table_remove_all (NM_CONNECTION_GET_PRIVATE (connection)->settings);
        g_hash_table_foreach (new_settings, parse_one_setting, connection);
 
-       if (!nm_connection_verify (connection, &error)) {
-               g_warning ("%s: '%s' / '%s' invalid: %d",
-                          __func__,
-                          g_type_name (nm_connection_lookup_setting_type_by_quark (error->domain)),
-                          error->message,
-                          error->code);
-               g_error_free (error);
-               return FALSE;
-       }
-
-       return TRUE;
+       return nm_connection_verify (connection, error);
 }
 
 typedef struct {
index 2722935..749340b 100644 (file)
@@ -92,7 +92,8 @@ NMSetting    *nm_connection_get_setting_by_name (NMConnection *connection,
                                                                            const char *name);
 
 gboolean      nm_connection_replace_settings (NMConnection *connection,
-                                                                        GHashTable *new_settings);
+                                              GHashTable *new_settings,
+                                              GError **error);
 
 /* Returns TRUE if the connections are the same */
 gboolean      nm_connection_compare       (NMConnection *connection,
index 5fc14ff..bf0b402 100644 (file)
@@ -970,7 +970,7 @@ connection_updated_cb (DBusGProxy *proxy, GHashTable *settings, gpointer user_da
        }
        g_object_unref (new_connection);
 
-       valid = nm_connection_replace_settings (old_connection, settings);
+       valid = nm_connection_replace_settings (old_connection, settings, NULL);
        if (valid) {
                g_signal_emit (manager, signals[CONNECTION_UPDATED], 0,
                               old_connection,
index 230da18..a3a9fbf 100644 (file)
@@ -37,9 +37,20 @@ file_changed (GFileMonitor *monitor,
        case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
                new_connection = parse_ifcfg (priv->iface, priv->dev_type);
                if (new_connection) {
+                       GError *error = NULL;
+
                        new_settings = nm_connection_to_hash (new_connection);
-                       nm_connection_replace_settings (nm_exported_connection_get_connection (exported), new_settings);
-                       nm_exported_connection_signal_updated (exported, new_settings);
+                       if (nm_connection_replace_settings (nm_exported_connection_get_connection (exported), new_settings, &error))
+                               nm_exported_connection_signal_updated (exported, new_settings);
+                       else {
+                               g_warning ("%s: '%s' / '%s' invalid: %d",
+                                          __func__,
+                                          error ? g_type_name (nm_connection_lookup_setting_type_by_quark (error->domain)) : "(none)",
+                                          (error && error->message) ? error->message : "(none)",
+                                          error ? error->code : -1);
+                               g_clear_error (&error);
+                               nm_exported_connection_signal_removed (exported);
+                       }
 
                        g_hash_table_destroy (new_settings);
                        g_object_unref (new_connection);
index 6bf3e39..3f15458 100644 (file)
@@ -222,14 +222,16 @@ update (NMExportedConnection *exported,
                char *filename = NULL;
 
                connection = nm_exported_connection_get_connection (exported);
-               nm_connection_replace_settings (connection, new_settings);
-               success = write_connection (connection, &filename, error);
-               if (success && filename && strcmp (priv->filename, filename)) {
-                       /* Update the filename if it changed */
-                       g_free (priv->filename);
-                       priv->filename = filename;
-               } else
-                       g_free (filename);
+               success = nm_connection_replace_settings (connection, new_settings, error);
+               if (success) {
+                       success = write_connection (connection, &filename, error);
+                       if (success && filename && strcmp (priv->filename, filename)) {
+                               /* Update the filename if it changed */
+                               g_free (priv->filename);
+                               priv->filename = filename;
+                       } else
+                               g_free (filename);
+               }
        }
 
        return success;
index 5de0f49..a2d4918 100644 (file)
@@ -133,11 +133,22 @@ update_connection_settings (NMExportedConnection *orig,
 {
        NMConnection *wrapped;
        GHashTable *new_settings;
+       GError *error = NULL;
 
        new_settings = nm_connection_to_hash (nm_exported_connection_get_connection (new));
        wrapped = nm_exported_connection_get_connection (orig);
-       nm_connection_replace_settings (wrapped, new_settings);
-       nm_exported_connection_signal_updated (orig, new_settings);
+       if (nm_connection_replace_settings (wrapped, new_settings, &error))
+               nm_exported_connection_signal_updated (orig, new_settings);
+       else {
+               g_warning ("%s: '%s' / '%s' invalid: %d",
+                          __func__,
+                          error ? g_type_name (nm_connection_lookup_setting_type_by_quark (error->domain)) : "(none)",
+                          (error && error->message) ? error->message : "(none)",
+                          error ? error->code : -1);
+               g_clear_error (&error);
+               nm_exported_connection_signal_removed (orig);
+       }
+
        g_hash_table_destroy (new_settings);
 }