diff --git a/ChangeLog b/ChangeLog index d1cbbcbbfa..e8db7a4dfa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2008-05-05 Tambet Ingo + + * system-settings/plugins/keyfile/nm-keyfile-connection.[ch]: Implement. + + * system-settings/plugins/keyfile/plugin.c: Work with + NMKeyfileConnections. + + * system-settings/src/dbus-settings.c: Remove NMSysconfigExportedConnection. + Plugins are supposed to return NMExportedConnections now and handle the + updated(), removed(), and GetSecrets(). + Store the internal list of connections in hash table to make it easier + to find duplicates. + 2008-05-07 Tambet Ingo * src/backends/NetworkManagerSuSE.c (nm_system_set_hostname): Update diff --git a/system-settings/plugins/ifcfg-suse/Makefile.am b/system-settings/plugins/ifcfg-suse/Makefile.am index 65e224696b..74f2f0285d 100644 --- a/system-settings/plugins/ifcfg-suse/Makefile.am +++ b/system-settings/plugins/ifcfg-suse/Makefile.am @@ -17,6 +17,7 @@ libnm_settings_plugin_ifcfg_suse_la_CPPFLAGS = \ -I${top_srcdir}/system-settings/src \ -I$(top_srcdir)/include \ -I$(top_srcdir)/libnm-util \ + -I${top_srcdir}/libnm-glib \ -DSYSCONFDIR=\"$(sysconfdir)\" libnm_settings_plugin_ifcfg_suse_la_LDFLAGS = -module -avoid-version @@ -24,5 +25,6 @@ libnm_settings_plugin_ifcfg_suse_la_LIBADD = \ $(GLIB_LIBS) \ $(GMODULE_LIBS) \ $(GIO_LIBS) \ - $(top_builddir)/libnm-util/libnm-util.la + $(top_builddir)/libnm-util/libnm-util.la \ + $(top_builddir)/libnm-glib/libnm_glib.la diff --git a/system-settings/plugins/keyfile/Makefile.am b/system-settings/plugins/keyfile/Makefile.am index f48768fea8..e3c1ca8422 100644 --- a/system-settings/plugins/keyfile/Makefile.am +++ b/system-settings/plugins/keyfile/Makefile.am @@ -2,6 +2,8 @@ pkglib_LTLIBRARIES = libnm-settings-plugin-keyfile.la libnm_settings_plugin_keyfile_la_SOURCES = \ + nm-keyfile-connection.c \ + nm-keyfile-connection.h \ plugin.c \ plugin.h \ reader.c \ @@ -17,6 +19,7 @@ libnm_settings_plugin_keyfile_la_CPPFLAGS = \ -I${top_srcdir}/system-settings/src \ -I$(top_srcdir)/include \ -I$(top_srcdir)/libnm-util \ + -I${top_srcdir}/libnm-glib \ -DKEYFILE_DIR=\""$(sysconfdir)/NetworkManager/system_config"\" libnm_settings_plugin_keyfile_la_LDFLAGS = -module -avoid-version @@ -25,5 +28,6 @@ libnm_settings_plugin_keyfile_la_LIBADD = \ $(GMODULE_LIBS) \ $(DBUS_LIBS) \ $(GIO_LIBS) \ - $(top_builddir)/libnm-util/libnm-util.la + $(top_builddir)/libnm-util/libnm-util.la \ + $(top_builddir)/libnm-glib/libnm_glib.la diff --git a/system-settings/plugins/keyfile/nm-keyfile-connection.c b/system-settings/plugins/keyfile/nm-keyfile-connection.c new file mode 100644 index 0000000000..d653874f41 --- /dev/null +++ b/system-settings/plugins/keyfile/nm-keyfile-connection.c @@ -0,0 +1,182 @@ +/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ + +#include +#include +#include +#include "nm-keyfile-connection.h" +#include "reader.h" +#include "writer.h" + +G_DEFINE_TYPE (NMKeyfileConnection, nm_keyfile_connection, NM_TYPE_EXPORTED_CONNECTION) + +#define NM_KEYFILE_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_KEYFILE_CONNECTION, NMKeyfileConnectionPrivate)) + +typedef struct { + char *filename; +} NMKeyfileConnectionPrivate; + +enum { + PROP_0, + PROP_FILENAME, + + LAST_PROP +}; + +NMKeyfileConnection * +nm_keyfile_connection_new (const char *filename) +{ + g_return_val_if_fail (filename != NULL, NULL); + + return (NMKeyfileConnection *) g_object_new (NM_TYPE_KEYFILE_CONNECTION, + NM_KEYFILE_CONNECTION_FILENAME, filename, + NULL); +} + +const char * +nm_keyfile_connection_get_filename (NMKeyfileConnection *self) +{ + g_return_val_if_fail (NM_IS_KEYFILE_CONNECTION (self), NULL); + + return NM_KEYFILE_CONNECTION_GET_PRIVATE (self)->filename; +} + +static GHashTable * +get_settings (NMExportedConnection *exported) +{ + return nm_connection_to_hash (nm_exported_connection_get_connection (exported)); +} + +static const char * +get_id (NMExportedConnection *exported) +{ + return NM_KEYFILE_CONNECTION_GET_PRIVATE (exported)->filename; +} + +static void +update (NMExportedConnection *exported, GHashTable *new_settings) +{ + write_connection (nm_exported_connection_get_connection (exported)); +} + +static void +delete (NMExportedConnection *exported) +{ + NMKeyfileConnectionPrivate *priv = NM_KEYFILE_CONNECTION_GET_PRIVATE (exported); + + g_unlink (priv->filename); +} + +/* GObject */ + +static void +nm_keyfile_connection_init (NMKeyfileConnection *connection) +{ +} + +static GObject * +constructor (GType type, + guint n_construct_params, + GObjectConstructParam *construct_params) +{ + GObject *object; + NMKeyfileConnectionPrivate *priv; + NMConnection *wrapped; + + object = G_OBJECT_CLASS (nm_keyfile_connection_parent_class)->constructor (type, n_construct_params, construct_params); + + if (!object) + return NULL; + + priv = NM_KEYFILE_CONNECTION_GET_PRIVATE (object); + + if (!priv->filename) { + g_warning ("Keyfile file name not provided."); + goto err; + } + + wrapped = connection_from_file (priv->filename); + if (!wrapped) + goto err; + + g_object_set (object, NM_EXPORTED_CONNECTION_CONNECTION, wrapped, NULL); + g_object_unref (wrapped); + + return object; + + err: + g_object_unref (object); + + return NULL; +} + +static void +finalize (GObject *object) +{ + NMKeyfileConnectionPrivate *priv = NM_KEYFILE_CONNECTION_GET_PRIVATE (object); + + g_free (priv->filename); + + G_OBJECT_CLASS (nm_keyfile_connection_parent_class)->finalize (object); +} + +static void +set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ + NMKeyfileConnectionPrivate *priv = NM_KEYFILE_CONNECTION_GET_PRIVATE (object); + + switch (prop_id) { + case PROP_FILENAME: + /* Construct only */ + priv->filename = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + NMKeyfileConnectionPrivate *priv = NM_KEYFILE_CONNECTION_GET_PRIVATE (object); + + switch (prop_id) { + case PROP_FILENAME: + g_value_set_string (value, priv->filename); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +nm_keyfile_connection_class_init (NMKeyfileConnectionClass *keyfile_connection_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (keyfile_connection_class); + NMExportedConnectionClass *connection_class = NM_EXPORTED_CONNECTION_CLASS (keyfile_connection_class); + + g_type_class_add_private (keyfile_connection_class, sizeof (NMKeyfileConnectionPrivate)); + + /* Virtual methods */ + object_class->constructor = constructor; + object_class->set_property = set_property; + object_class->get_property = get_property; + object_class->finalize = finalize; + + connection_class->get_settings = get_settings; + connection_class->get_id = get_id; + connection_class->update = update; + connection_class->delete = delete; + + /* Properties */ + g_object_class_install_property + (object_class, PROP_FILENAME, + g_param_spec_string (NM_KEYFILE_CONNECTION_FILENAME, + "FileName", + "File name", + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); +} diff --git a/system-settings/plugins/keyfile/nm-keyfile-connection.h b/system-settings/plugins/keyfile/nm-keyfile-connection.h new file mode 100644 index 0000000000..bdd538c31f --- /dev/null +++ b/system-settings/plugins/keyfile/nm-keyfile-connection.h @@ -0,0 +1,35 @@ +/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ + +#ifndef NM_KEYFILE_CONNECTION_H +#define NM_KEYFILE_CONNECTION_H + +#include + +G_BEGIN_DECLS + +#define NM_TYPE_KEYFILE_CONNECTION (nm_keyfile_connection_get_type ()) +#define NM_KEYFILE_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_KEYFILE_CONNECTION, NMKeyfileConnection)) +#define NM_KEYFILE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_KEYFILE_CONNECTION, NMKeyfileConnectionClass)) +#define NM_IS_KEYFILE_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_KEYFILE_CONNECTION)) +#define NM_IS_KEYFILE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_KEYFILE_CONNECTION)) +#define NM_KEYFILE_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_KEYFILE_CONNECTION, NMKeyfileConnectionClass)) + +#define NM_KEYFILE_CONNECTION_FILENAME "filename" + +typedef struct { + NMExportedConnection parent; +} NMKeyfileConnection; + +typedef struct { + NMExportedConnectionClass parent; +} NMKeyfileConnectionClass; + +GType nm_keyfile_connection_get_type (void); + +NMKeyfileConnection *nm_keyfile_connection_new (const char *filename); + +const char *nm_keyfile_connection_get_filename (NMKeyfileConnection *self); + +G_END_DECLS + +#endif /* NM_KEYFILE_CONNECTION_H */ diff --git a/system-settings/plugins/keyfile/plugin.c b/system-settings/plugins/keyfile/plugin.c index c1d7deafa9..32591cd0cd 100644 --- a/system-settings/plugins/keyfile/plugin.c +++ b/system-settings/plugins/keyfile/plugin.c @@ -13,7 +13,7 @@ #include "plugin.h" #include "nm-system-config-interface.h" -#include "reader.h" +#include "nm-keyfile-connection.h" #include "writer.h" #define KEYFILE_PLUGIN_NAME "keyfile" @@ -36,19 +36,17 @@ typedef struct { gboolean disposed; } SCPluginKeyfilePrivate; -static NMConnection * +static NMKeyfileConnection * read_one_connection (NMSystemConfigInterface *config, const char *filename) { SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (config); - char *full_path; - NMConnection *connection = NULL; + NMKeyfileConnection *connection; - full_path = g_build_filename (KEYFILE_DIR, filename, NULL); - connection = connection_from_file (full_path); + connection = nm_keyfile_connection_new (filename); if (connection) - g_hash_table_insert (priv->hash, g_strdup (filename), connection); - - g_free (full_path); + g_hash_table_insert (priv->hash, + (gpointer) nm_keyfile_connection_get_filename (connection), + g_object_ref (connection)); return connection; } @@ -63,8 +61,13 @@ read_connections (NMSystemConfigInterface *config) if (dir) { const char *item; - while ((item = g_dir_read_name (dir))) - read_one_connection (config, item); + while ((item = g_dir_read_name (dir))) { + char *full_path; + + full_path = g_build_filename (KEYFILE_DIR, item, NULL); + read_one_connection (config, full_path); + g_free (full_path); + } g_dir_close (dir); } else { @@ -73,30 +76,6 @@ read_connections (NMSystemConfigInterface *config) } } -static void -delete_connection (NMSystemConfigInterface *config, NMConnection *connection) -{ - SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (config); - NMSettingConnection *s_con; - char *filename; - - s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION)); - if (!s_con) - return; - - filename = g_build_filename (KEYFILE_DIR, s_con->id, NULL); - - if (g_hash_table_lookup (priv->hash, s_con->id)) { - if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) - /* Monitoring takes care of the rest */ - g_unlink (filename); - else - g_warning ("File '%s' does not exist", filename); - } - - g_free (filename); -} - /* Monitoring */ static void @@ -109,37 +88,29 @@ dir_changed (GFileMonitor *monitor, NMSystemConfigInterface *config = NM_SYSTEM_CONFIG_INTERFACE (user_data); SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (config); char *name; - NMConnection *connection; + NMKeyfileConnection *connection; - name = g_file_get_basename (file); + name = g_file_get_path (file); connection = g_hash_table_lookup (priv->hash, name); switch (event_type) { case G_FILE_MONITOR_EVENT_DELETED: if (connection) { g_hash_table_remove (priv->hash, name); - g_signal_emit_by_name (config, "connection-removed", connection); + nm_exported_connection_signal_removed (NM_EXPORTED_CONNECTION (connection)); } break; - case G_FILE_MONITOR_EVENT_CREATED: case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: if (connection) { /* Update */ - char *full_path; - NMConnection *tmp; - - full_path = g_file_get_path (file); - tmp = connection_from_file (full_path); - g_free (full_path); + NMExportedConnection *tmp; + tmp = (NMExportedConnection *) nm_keyfile_connection_new (name); if (tmp) { GHashTable *settings; - settings = nm_connection_to_hash (tmp); - - if (nm_connection_replace_settings (connection, settings)) - g_signal_emit_by_name (config, "connection-updated", connection); - + settings = nm_connection_to_hash (nm_exported_connection_get_connection (tmp)); + nm_exported_connection_update (NM_EXPORTED_CONNECTION (connection), settings); g_hash_table_destroy (settings); g_object_unref (tmp); } @@ -164,7 +135,7 @@ setup_monitoring (NMSystemConfigInterface *config) GFile *file; GFileMonitor *monitor; - priv->hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); + priv->hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); file = g_file_new_for_path (KEYFILE_DIR); monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL); @@ -208,18 +179,6 @@ add_connection (NMSystemConfigInterface *config, NMConnection *connection) write_connection (connection); } -static void -update_connection (NMSystemConfigInterface *config, NMConnection *connection) -{ - write_connection (connection); -} - -static void -remove_connection (NMSystemConfigInterface *config, NMConnection *connection) -{ - delete_connection (config, connection); -} - /* GObject */ static void @@ -292,8 +251,6 @@ system_config_interface_init (NMSystemConfigInterface *system_config_interface_c /* interface implementation */ system_config_interface_class->get_connections = get_connections; system_config_interface_class->add_connection = add_connection; - system_config_interface_class->update_connection = update_connection; - system_config_interface_class->remove_connection = remove_connection; } G_MODULE_EXPORT GObject * diff --git a/system-settings/src/dbus-settings.c b/system-settings/src/dbus-settings.c index 9235939b96..24cf0df61a 100644 --- a/system-settings/src/dbus-settings.c +++ b/system-settings/src/dbus-settings.c @@ -32,166 +32,21 @@ #include "dbus-settings.h" #include "nm-utils.h" -#define NM_SS_PLUGIN_TAG "nm-ss-plugin" - -static void exported_connection_get_secrets (NMExportedConnection *connection, - const gchar *setting_name, - const gchar **hints, - gboolean request_new, - DBusGMethodInvocation *context); - -G_DEFINE_TYPE (NMSysconfigExportedConnection, nm_sysconfig_exported_connection, NM_TYPE_EXPORTED_CONNECTION); - -/* - * NMSysconfigExportedConnection - */ - -static void -check_for_secrets (gpointer key, gpointer data, gpointer user_data) -{ - gboolean *have_secrets = (gboolean *) user_data; - - if (*have_secrets) - return; - - *have_secrets = g_hash_table_size ((GHashTable *) data) ? TRUE : FALSE; -} - -static void -exported_connection_get_secrets (NMExportedConnection *sys_connection, - const gchar *setting_name, - const gchar **hints, - gboolean request_new, - DBusGMethodInvocation *context) -{ - NMConnection *connection; - GError *error = NULL; - NMSettingConnection *s_con; - NMSetting *setting; - GHashTable *settings = NULL; - NMSystemConfigInterface *plugin; - gboolean have_secrets = FALSE; - - connection = nm_exported_connection_get_connection (sys_connection); - - g_return_if_fail (NM_IS_CONNECTION (connection)); - g_return_if_fail (setting_name != NULL); - - setting = nm_connection_get_setting_by_name (connection, setting_name); - if (!setting) { - g_set_error (&error, NM_SETTINGS_ERROR, 1, - "%s.%d - Connection didn't have requested setting '%s'.", - __FILE__, __LINE__, setting_name); - goto error; - } - - s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, - NM_TYPE_SETTING_CONNECTION)); - if (!s_con || !s_con->id || !strlen (s_con->id) || !s_con->type) { - g_set_error (&error, NM_SETTINGS_ERROR, 1, - "%s.%d - Connection didn't have required '" - NM_SETTING_CONNECTION_SETTING_NAME - "' setting , or the connection name was invalid.", - __FILE__, __LINE__); - goto error; - } - - plugin = g_object_get_data (G_OBJECT (sys_connection), NM_SS_PLUGIN_TAG); - if (!plugin) { - g_set_error (&error, NM_SETTINGS_ERROR, 1, - "%s.%d - Connection had no plugin to ask for secrets.", - __FILE__, __LINE__); - goto error; - } - - settings = nm_system_config_interface_get_secrets (plugin, connection, setting); - if (!settings || (g_hash_table_size (settings) == 0)) { - g_set_error (&error, NM_SETTINGS_ERROR, 1, - "%s.%d - Connection's plugin did not return a secrets hash.", - __FILE__, __LINE__); - goto error; - } - - g_hash_table_foreach (settings, check_for_secrets, &have_secrets); - if (!have_secrets) { - g_set_error (&error, NM_SETTINGS_ERROR, 1, - "%s.%d - Secrets were found for setting '%s' but none" - " were valid.", __FILE__, __LINE__, setting_name); - goto error; - } else { - dbus_g_method_return (context, settings); - } - - g_hash_table_destroy (settings); - return; - -error: - if (settings) - g_hash_table_destroy (settings); - - g_warning (error->message); - dbus_g_method_return_error (context, error); - g_error_free (error); -} - -static void -nm_sysconfig_exported_connection_finalize (GObject *object) -{ - G_OBJECT_CLASS (nm_sysconfig_exported_connection_parent_class)->finalize (object); -} - -static void -nm_sysconfig_exported_connection_class_init (NMSysconfigExportedConnectionClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - NMExportedConnectionClass *connection = NM_EXPORTED_CONNECTION_CLASS (class); - - object_class->finalize = nm_sysconfig_exported_connection_finalize; - - connection->get_secrets = exported_connection_get_secrets; -} - -static void -nm_sysconfig_exported_connection_init (NMSysconfigExportedConnection *sysconfig_exported_connection) -{ -} - -NMSysconfigExportedConnection * -nm_sysconfig_exported_connection_new (NMConnection *connection, - DBusGConnection *g_conn) -{ - NMSysconfigExportedConnection *exported; - - exported = g_object_new (NM_TYPE_SYSCONFIG_EXPORTED_CONNECTION, - NM_EXPORTED_CONNECTION_CONNECTION, connection, - NULL); - - nm_exported_connection_register_object (NM_EXPORTED_CONNECTION (exported), - NM_CONNECTION_SCOPE_SYSTEM, - g_conn); - - return exported; -} - -/* - * NMSettings - */ - static gboolean impl_settings_add_connection (NMSysconfigSettings *self, GHashTable *hash, GError **err); #include "nm-settings-system-glue.h" +static void unmanaged_devices_changed (NMSystemConfigInterface *config, gpointer user_data); + typedef struct { DBusGConnection *g_connection; NMSystemConfigHalManager *hal_mgr; GSList *plugins; gboolean connections_loaded; - GSList *connections; + GHashTable *connections; GHashTable *unmanaged_devices; - - gboolean in_plugin_signal_handler; } NMSysconfigSettingsPrivate; G_DEFINE_TYPE (NMSysconfigSettings, nm_sysconfig_settings, NM_TYPE_SETTINGS); @@ -213,12 +68,50 @@ enum { LAST_PROP }; +static void +hash_keys_to_slist (gpointer key, gpointer val, gpointer user_data) +{ + GSList **list = (GSList **) user_data; + + *list = g_slist_prepend (*list, key); +} + static GSList * list_connections (NMSettings *settings) { NMSysconfigSettings *self = NM_SYSCONFIG_SETTINGS (settings); + NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self); + GSList *list = NULL; - return g_slist_copy (nm_sysconfig_settings_get_connections (self)); + if (!priv->connections_loaded) { + GSList *iter; + + for (iter = priv->plugins; iter; iter = g_slist_next (iter)) { + NMSystemConfigInterface *plugin = NM_SYSTEM_CONFIG_INTERFACE (iter->data); + GSList *plugin_connections; + GSList *elt; + + plugin_connections = nm_system_config_interface_get_connections (plugin); + + // FIXME: ensure connections from plugins loaded with a lower priority + // get rejected when they conflict with connections from a higher + // priority plugin. + + for (elt = plugin_connections; elt; elt = g_slist_next (elt)) + nm_sysconfig_settings_add_connection (self, NM_EXPORTED_CONNECTION (elt->data)); + + g_slist_free (plugin_connections); + } + + /* FIXME: Bad hack */ + unmanaged_devices_changed (NULL, self); + + priv->connections_loaded = TRUE; + } + + g_hash_table_foreach (priv->connections, hash_keys_to_slist, &list); + + return list; } static void @@ -227,12 +120,7 @@ settings_finalize (GObject *object) NMSysconfigSettings *self = NM_SYSCONFIG_SETTINGS (object); NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self); - if (priv->connections) { - g_slist_foreach (priv->connections, (GFunc) g_object_unref, NULL); - g_slist_free (priv->connections); - priv->connections = NULL; - } - + g_hash_table_destroy (priv->connections); g_hash_table_destroy (priv->unmanaged_devices); g_slist_foreach (priv->plugins, (GFunc) g_object_unref, NULL); @@ -366,6 +254,7 @@ nm_sysconfig_settings_init (NMSysconfigSettings *self) { NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self); + priv->connections = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, NULL); priv->unmanaged_devices = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); } @@ -390,34 +279,10 @@ nm_sysconfig_settings_new (DBusGConnection *g_conn, NMSystemConfigHalManager *ha static void plugin_connection_added (NMSystemConfigInterface *config, - NMConnection *connection, + NMExportedConnection *connection, gpointer user_data) { - nm_sysconfig_settings_add_connection (NM_SYSCONFIG_SETTINGS (user_data), config, connection); -} - -static void -plugin_connection_removed (NMSystemConfigInterface *config, - NMConnection *connection, - gpointer user_data) -{ - NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (user_data); - - priv->in_plugin_signal_handler = TRUE; - nm_sysconfig_settings_remove_connection (NM_SYSCONFIG_SETTINGS (user_data), connection); - priv->in_plugin_signal_handler = FALSE; -} - -static void -plugin_connection_updated (NMSystemConfigInterface *config, - NMConnection *connection, - gpointer user_data) -{ - NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (user_data); - - priv->in_plugin_signal_handler = TRUE; - nm_sysconfig_settings_update_connection (NM_SYSCONFIG_SETTINGS (user_data), connection); - priv->in_plugin_signal_handler = FALSE; + nm_sysconfig_settings_add_connection (NM_SYSCONFIG_SETTINGS (user_data), connection); } static void @@ -466,9 +331,6 @@ nm_sysconfig_settings_add_plugin (NMSysconfigSettings *self, priv->plugins = g_slist_append (priv->plugins, g_object_ref (plugin)); g_signal_connect (plugin, "connection-added", G_CALLBACK (plugin_connection_added), self); - g_signal_connect (plugin, "connection-removed", G_CALLBACK (plugin_connection_removed), self); - g_signal_connect (plugin, "connection-updated", G_CALLBACK (plugin_connection_updated), self); - g_signal_connect (plugin, "unmanaged-devices-changed", G_CALLBACK (unmanaged_devices_changed), self); nm_system_config_interface_init (plugin, priv->hal_mgr); @@ -484,184 +346,51 @@ nm_sysconfig_settings_add_plugin (NMSysconfigSettings *self, } static void -connection_updated (NMExportedConnection *sys_connection, - GHashTable *new_settings, +connection_removed (NMExportedConnection *connection, gpointer user_data) { NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (user_data); - NMSystemConfigInterface *plugin; - NMConnection *connection; - if (priv->in_plugin_signal_handler) - return; - - connection = nm_exported_connection_get_connection (sys_connection); - plugin = (NMSystemConfigInterface *) g_object_get_data (G_OBJECT (sys_connection), NM_SS_PLUGIN_TAG); - - if (plugin) { - nm_system_config_interface_update_connection (plugin, connection); - } else { - GSList *iter; - - for (iter = priv->plugins; iter; iter = iter->next) - nm_system_config_interface_update_connection (NM_SYSTEM_CONFIG_INTERFACE (iter->data), connection); - } -} - -static void -connection_removed (NMExportedConnection *sys_connection, - gpointer user_data) -{ - NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (user_data); - NMSystemConfigInterface *plugin; - NMConnection *connection; - - if (priv->in_plugin_signal_handler) - return; - - connection = nm_exported_connection_get_connection (sys_connection); - plugin = (NMSystemConfigInterface *) g_object_get_data (G_OBJECT (sys_connection), NM_SS_PLUGIN_TAG); - - if (plugin) { - nm_system_config_interface_remove_connection (plugin, connection); - } else { - GSList *iter; - - for (iter = priv->plugins; iter; iter = iter->next) - nm_system_config_interface_remove_connection (NM_SYSTEM_CONFIG_INTERFACE (iter->data), connection); - } -} - -static NMExportedConnection * -find_existing_connection (NMSysconfigSettings *self, NMConnection *connection) -{ - NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self); - GSList *iter; - - for (iter = priv->connections; iter; iter = g_slist_next (iter)) { - NMExportedConnection *exported = NM_EXPORTED_CONNECTION (iter->data); - NMConnection *wrapped = nm_exported_connection_get_connection (exported); - - if (wrapped == connection) - return exported; - } - - return NULL; + g_hash_table_remove (priv->connections, connection); } void nm_sysconfig_settings_add_connection (NMSysconfigSettings *self, - NMSystemConfigInterface *plugin, - NMConnection *connection) + NMExportedConnection *connection) { NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self); - NMSysconfigExportedConnection *exported; g_return_if_fail (NM_IS_SYSCONFIG_SETTINGS (self)); - g_return_if_fail (NM_IS_CONNECTION (connection)); + g_return_if_fail (NM_IS_EXPORTED_CONNECTION (connection)); - if (find_existing_connection (self, connection)) { + if (g_hash_table_lookup (priv->connections, connection)) { /* A plugin is lying to us */ g_message ("Connection is already added, ignoring"); return; } - exported = nm_sysconfig_exported_connection_new (connection, priv->g_connection); - if (exported) { - priv->connections = g_slist_append (priv->connections, exported); + g_hash_table_insert (priv->connections, connection, GINT_TO_POINTER (1)); + g_signal_connect (connection, "removed", G_CALLBACK (connection_removed), self); - g_signal_connect (exported, "updated", G_CALLBACK (connection_updated), self); - g_signal_connect (exported, "removed", G_CALLBACK (connection_removed), self); - - if (plugin) - g_object_set_data (G_OBJECT (exported), NM_SS_PLUGIN_TAG, plugin); - - nm_settings_signal_new_connection (NM_SETTINGS (self), NM_EXPORTED_CONNECTION (exported)); - } else - g_warning ("%s: couldn't export the connection!", __func__); + nm_exported_connection_register_object (connection, NM_CONNECTION_SCOPE_SYSTEM, priv->g_connection); + nm_settings_signal_new_connection (NM_SETTINGS (self), connection); } void nm_sysconfig_settings_remove_connection (NMSysconfigSettings *self, - NMConnection *connection) + NMExportedConnection *connection) { - NMExportedConnection *exported; + NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self); g_return_if_fail (NM_IS_SYSCONFIG_SETTINGS (self)); - g_return_if_fail (NM_IS_CONNECTION (connection)); + g_return_if_fail (NM_IS_EXPORTED_CONNECTION (connection)); - exported = find_existing_connection (self, connection); - if (exported) { - NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self); - - priv->connections = g_slist_remove (priv->connections, exported); - nm_exported_connection_signal_removed (exported); - g_object_unref (exported); + if (g_hash_table_lookup (priv->connections, connection)) { + nm_exported_connection_signal_removed (connection); + g_hash_table_remove (priv->connections, connection); } } -void -nm_sysconfig_settings_update_connection (NMSysconfigSettings *self, - NMConnection *connection) -{ - NMExportedConnection *exported; - - g_return_if_fail (NM_IS_SYSCONFIG_SETTINGS (self)); - g_return_if_fail (NM_IS_CONNECTION (connection)); - - exported = find_existing_connection (self, connection); - if (exported) { - if (nm_connection_verify (connection)) { - GHashTable *hash; - - hash = nm_connection_to_hash (connection); - nm_exported_connection_signal_updated (exported, hash); - g_hash_table_destroy (hash); - } else - /* If the connection is no longer valid, it gets removed */ - nm_sysconfig_settings_remove_connection (self, connection); - } else - g_warning ("%s: cannot update unknown connection", __func__); -} - -GSList * -nm_sysconfig_settings_get_connections (NMSysconfigSettings *self) -{ - NMSysconfigSettingsPrivate *priv; - - g_return_val_if_fail (NM_IS_SYSCONFIG_SETTINGS (self), NULL); - - priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self); - - if (!priv->connections_loaded) { - GSList *iter; - - for (iter = priv->plugins; iter; iter = g_slist_next (iter)) { - NMSystemConfigInterface *plugin = NM_SYSTEM_CONFIG_INTERFACE (iter->data); - GSList *plugin_connections; - GSList *elt; - - plugin_connections = nm_system_config_interface_get_connections (plugin); - - // FIXME: ensure connections from plugins loaded with a lower priority - // get rejected when they conflict with connections from a higher - // priority plugin. - - for (elt = plugin_connections; elt; elt = g_slist_next (elt)) - nm_sysconfig_settings_add_connection (self, plugin, NM_CONNECTION (elt->data)); - - g_slist_free (plugin_connections); - } - - /* FIXME: Bad hack */ - unmanaged_devices_changed (NULL, self); - - priv->connections_loaded = TRUE; - } - - return priv->connections; -} - gboolean nm_sysconfig_settings_is_device_managed (NMSysconfigSettings *self, const char *udi) diff --git a/system-settings/src/dbus-settings.h b/system-settings/src/dbus-settings.h index 1a1340f96b..85df116b9f 100644 --- a/system-settings/src/dbus-settings.h +++ b/system-settings/src/dbus-settings.h @@ -28,37 +28,6 @@ #include "nm-system-config-interface.h" #include "nm-system-config-hal-manager.h" -typedef struct _NMSysconfigExportedConnection NMSysconfigExportedConnection; -typedef struct _NMSysconfigExportedConnectionClass NMSysconfigExportedConnectionClass; - -/* - * NMSysconfigExportedConnection - */ - -#define NM_TYPE_SYSCONFIG_EXPORTED_CONNECTION (nm_sysconfig_exported_connection_get_type ()) -#define NM_SYSCONFIG_EXPORTED_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SYSCONFIG_EXPORTED_CONNECTION, NMSysconfigExportedConnection)) -#define NM_SYSCONFIG_EXPORTED_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SYSCONFIG_EXPORTED_CONNECTION, NMSysconfigExportedConnectionClass)) -#define NM_IS_SYSCONFIG_EXPORTED_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SYSCONFIG_EXPORTED_CONNECTION)) -#define NM_IS_SYSCONFIG_EXPORTED_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SYSCONFIG_EXPORTED_CONNECTION)) -#define NM_SYSCONFIG_EXPORTED_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SYSCONFIG_EXPORTED_CONNECTION, NMSysconfigExportedConnectionClass)) - -struct _NMSysconfigExportedConnection -{ - NMExportedConnection parent_instance; -}; - -struct _NMSysconfigExportedConnectionClass -{ - NMExportedConnectionClass parent_class; -}; - -GType nm_sysconfig_exported_connection_get_type (void); -NMSysconfigExportedConnection *nm_sysconfig_exported_connection_new (NMConnection *connection, - DBusGConnection *g_conn); - -/* - * NMSysconfigSettings - */ typedef struct _NMSysconfigSettings NMSysconfigSettings; typedef struct _NMSysconfigSettingsClass NMSysconfigSettingsClass; @@ -93,16 +62,10 @@ void nm_sysconfig_settings_add_plugin (NMSysconfigSettings *settings, NMSystemConfigInterface *plugin); void nm_sysconfig_settings_add_connection (NMSysconfigSettings *settings, - NMSystemConfigInterface *plugin, - NMConnection *connection); + NMExportedConnection *connection); void nm_sysconfig_settings_remove_connection (NMSysconfigSettings *settings, - NMConnection *connection); - -void nm_sysconfig_settings_update_connection (NMSysconfigSettings *settings, - NMConnection *connection); - -GSList *nm_sysconfig_settings_get_connections (NMSysconfigSettings *settings); + NMExportedConnection *connection); void nm_sysconfig_settings_update_unamanged_devices (NMSysconfigSettings *settings, GSList *new_list); diff --git a/system-settings/src/main.c b/system-settings/src/main.c index 10e2d98cc7..f007593dfb 100644 --- a/system-settings/src/main.c +++ b/system-settings/src/main.c @@ -190,7 +190,7 @@ load_stuff (gpointer user_data) typedef struct { Application *app; - NMConnection *connection; + NMExportedConnection *connection; guint add_id; char *udi; GByteArray *mac; @@ -281,7 +281,7 @@ have_connection_for_device (Application *app, GByteArray *mac) /* If the device doesn't have a connection advertised by any of the * plugins, create a new default DHCP-enabled connection for it. */ - list = nm_sysconfig_settings_get_connections (app->settings); + list = nm_settings_list_connections (NM_SETTINGS (app->settings)); for (iter = list; iter; iter = g_slist_next (iter)) { NMExportedConnection *exported = NM_EXPORTED_CONNECTION (iter->data); NMConnection *connection; @@ -319,6 +319,7 @@ add_default_dhcp_connection (gpointer user_data) WiredDeviceInfo *info = (WiredDeviceInfo *) user_data; NMSettingConnection *s_con; NMSettingWired *s_wired; + NMConnection *wrapped; if (info->add_id) info->add_id = 0; @@ -340,13 +341,15 @@ add_default_dhcp_connection (gpointer user_data) if (have_connection_for_device (info->app, info->mac)) goto ignore; - info->connection = nm_connection_new (); + wrapped = nm_connection_new (); + info->connection = nm_exported_connection_new (wrapped); + g_object_unref (wrapped); s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ()); s_con->id = g_strdup_printf (_("Auto %s"), info->iface); s_con->type = g_strdup (NM_SETTING_WIRED_SETTING_NAME); s_con->autoconnect = TRUE; - nm_connection_add_setting (info->connection, NM_SETTING (s_con)); + nm_connection_add_setting (wrapped, NM_SETTING (s_con)); g_message ("Adding default connection '%s' for %s", s_con->id, info->udi); @@ -354,9 +357,9 @@ add_default_dhcp_connection (gpointer user_data) s_wired = NM_SETTING_WIRED (nm_setting_wired_new ()); s_wired->mac_address = g_byte_array_sized_new (ETH_ALEN); g_byte_array_append (s_wired->mac_address, info->mac->data, ETH_ALEN); - nm_connection_add_setting (info->connection, NM_SETTING (s_wired)); + nm_connection_add_setting (wrapped, NM_SETTING (s_wired)); - nm_sysconfig_settings_add_connection (info->app->settings, NULL, info->connection); + nm_sysconfig_settings_add_connection (info->app->settings, info->connection); return FALSE; diff --git a/system-settings/src/nm-system-config-interface.c b/system-settings/src/nm-system-config-interface.c index b3fda79598..3f9923f169 100644 --- a/system-settings/src/nm-system-config-interface.c +++ b/system-settings/src/nm-system-config-interface.c @@ -56,25 +56,7 @@ interface_init (gpointer g_iface) NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, - G_TYPE_OBJECT); - - g_signal_new ("connection-removed", - iface_type, - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMSystemConfigInterface, connection_removed), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - G_TYPE_OBJECT); - - g_signal_new ("connection-updated", - iface_type, - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMSystemConfigInterface, connection_updated), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - G_TYPE_OBJECT); + NM_TYPE_EXPORTED_CONNECTION); g_signal_new ("unmanaged-devices-changed", iface_type, @@ -137,20 +119,6 @@ nm_system_config_interface_get_connections (NMSystemConfigInterface *config) return NULL; } -GHashTable * -nm_system_config_interface_get_secrets (NMSystemConfigInterface *config, - NMConnection *connection, - NMSetting *setting) -{ - g_return_val_if_fail (config != NULL, NULL); - g_return_val_if_fail (connection != NULL, NULL); - g_return_val_if_fail (setting != NULL, NULL); - - if (NM_SYSTEM_CONFIG_INTERFACE_GET_INTERFACE (config)->get_secrets) - return NM_SYSTEM_CONFIG_INTERFACE_GET_INTERFACE (config)->get_secrets (config, connection, setting); - return NULL; -} - GSList * nm_system_config_interface_get_unmanaged_devices (NMSystemConfigInterface *config) { @@ -171,25 +139,3 @@ nm_system_config_interface_add_connection (NMSystemConfigInterface *config, if (NM_SYSTEM_CONFIG_INTERFACE_GET_INTERFACE (config)->add_connection) NM_SYSTEM_CONFIG_INTERFACE_GET_INTERFACE (config)->add_connection (config, connection); } - -void -nm_system_config_interface_update_connection (NMSystemConfigInterface *config, - NMConnection *connection) -{ - g_return_if_fail (config != NULL); - g_return_if_fail (NM_IS_CONNECTION (connection)); - - if (NM_SYSTEM_CONFIG_INTERFACE_GET_INTERFACE (config)->update_connection) - NM_SYSTEM_CONFIG_INTERFACE_GET_INTERFACE (config)->update_connection (config, connection); -} - -void -nm_system_config_interface_remove_connection (NMSystemConfigInterface *config, - NMConnection *connection) -{ - g_return_if_fail (config != NULL); - g_return_if_fail (NM_IS_CONNECTION (connection)); - - if (NM_SYSTEM_CONFIG_INTERFACE_GET_INTERFACE (config)->remove_connection) - NM_SYSTEM_CONFIG_INTERFACE_GET_INTERFACE (config)->remove_connection (config, connection); -} diff --git a/system-settings/src/nm-system-config-interface.h b/system-settings/src/nm-system-config-interface.h index b91b0921bc..a7b3c5c8c4 100644 --- a/system-settings/src/nm-system-config-interface.h +++ b/system-settings/src/nm-system-config-interface.h @@ -25,6 +25,7 @@ #include #include #include +#include #include "nm-system-config-hal-manager.h" @@ -81,17 +82,6 @@ struct _NMSystemConfigInterface { */ GSList * (*get_connections) (NMSystemConfigInterface *config); - /* Return the secrets associated with settings of a specific - * connection. The returned hash table is unreffed by the system settings - * service. Returned hash table should itself contain string::hashtable - * mappings, each value being a hash table of secrets for a single setting. - * - * string :: (string :: GValue) - * - * The returned hash table will be freed by the system settings service. - */ - GHashTable * (*get_secrets) (NMSystemConfigInterface *config, NMConnection *connection, NMSetting *setting); - /* * Return a list of HAL UDIs of devices which NetworkManager should not * manage. Returned list will be freed by the system settings service, and @@ -104,27 +94,10 @@ struct _NMSystemConfigInterface { */ void (*add_connection) (NMSystemConfigInterface *config, NMConnection *connection); - /* - * Update the connection. - */ - void (*update_connection) (NMSystemConfigInterface *config, NMConnection *connection); - - /* - * Remove the connection. - */ - void (*remove_connection) (NMSystemConfigInterface *config, NMConnection *connection); - - /* Signals */ /* Emitted when a new connection has been found by the plugin */ - void (*connection_added) (NMSystemConfigInterface *config, NMConnection *connection); - - /* Emitted when a connection has been removed by the plugin */ - void (*connection_removed) (NMSystemConfigInterface *config, NMConnection *connection); - - /* Emitted when any non-secret settings of the connection change */ - void (*connection_updated) (NMSystemConfigInterface *config, NMConnection *connection); + void (*connection_added) (NMSystemConfigInterface *config, NMExportedConnection *connection); /* Emitted when the list of unmanaged devices changes */ void (*unmanaged_devices_changed) (NMSystemConfigInterface *config); @@ -137,21 +110,11 @@ void nm_system_config_interface_init (NMSystemConfigInterface *config, GSList * nm_system_config_interface_get_connections (NMSystemConfigInterface *config); -GHashTable *nm_system_config_interface_get_secrets (NMSystemConfigInterface *config, - NMConnection *connection, - NMSetting *setting); - GSList *nm_system_config_interface_get_unmanaged_devices (NMSystemConfigInterface *config); void nm_system_config_interface_add_connection (NMSystemConfigInterface *config, NMConnection *connection); -void nm_system_config_interface_update_connection (NMSystemConfigInterface *config, - NMConnection *connection); - -void nm_system_config_interface_remove_connection (NMSystemConfigInterface *config, - NMConnection *connection); - G_END_DECLS #endif /* NM_SYSTEM_CONFIG_INTERFACE_H */