diff options
29 files changed, 367 insertions, 547 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 1ff890ff56..e61e5aa9dd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -397,8 +397,6 @@ libNetworkManager_la_SOURCES = \ nm-config.h \ nm-config-data.c \ nm-config-data.h \ - nm-connection-provider.c \ - nm-connection-provider.h \ nm-connectivity.c \ nm-connectivity.h \ nm-dcb.c \ diff --git a/src/devices/bluetooth/nm-bluez-device.c b/src/devices/bluetooth/nm-bluez-device.c index dcfa5eec24..3463da6be8 100644 --- a/src/devices/bluetooth/nm-bluez-device.c +++ b/src/devices/bluetooth/nm-bluez-device.c @@ -28,6 +28,7 @@ #include "nm-bt-error.h" #include "nm-bluez-common.h" #include "nm-bluez-device.h" +#include "nm-settings.h" #include "nm-settings-connection.h" #include "NetworkManagerUtils.h" @@ -67,7 +68,7 @@ typedef struct { NMBluez5DunContext *b5_dun_context; #endif - NMConnectionProvider *provider; + NMSettings *settings; GSList *connections; NMConnection *pan_connection; @@ -96,7 +97,7 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; -static void cp_connection_added (NMConnectionProvider *provider, +static void cp_connection_added (NMSettings *settings, NMConnection *connection, NMBluezDevice *self); static gboolean connection_compatible (NMBluezDevice *self, NMConnection *connection); @@ -233,9 +234,9 @@ pan_connection_check_create (NMBluezDevice *self) /* Adding a new connection raises a signal which eventually calls check_emit_usable (again) * which then already finds the suitable connection in priv->connections. This is confusing, * so block the signal. check_emit_usable will succeed after this function call returns. */ - g_signal_handlers_block_by_func (priv->provider, cp_connection_added, self); - added = nm_connection_provider_add_connection (priv->provider, connection, FALSE, &error); - g_signal_handlers_unblock_by_func (priv->provider, cp_connection_added, self); + g_signal_handlers_block_by_func (priv->settings, cp_connection_added, self); + added = NM_CONNECTION (nm_settings_add_connection (priv->settings, connection, FALSE, &error)); + g_signal_handlers_unblock_by_func (priv->settings, cp_connection_added, self); if (added) { g_assert (!g_slist_find (priv->connections, added)); @@ -367,7 +368,7 @@ _internal_track_connection (NMBluezDevice *self, NMConnection *connection, gbool } static void -cp_connection_added (NMConnectionProvider *provider, +cp_connection_added (NMSettings *settings, NMConnection *connection, NMBluezDevice *self) { @@ -378,7 +379,7 @@ cp_connection_added (NMConnectionProvider *provider, } static void -cp_connection_removed (NMConnectionProvider *provider, +cp_connection_removed (NMSettings *settings, NMConnection *connection, NMBluezDevice *self) { @@ -387,8 +388,9 @@ cp_connection_removed (NMConnectionProvider *provider, } static void -cp_connection_updated (NMConnectionProvider *provider, +cp_connection_updated (NMSettings *settings, NMConnection *connection, + gboolean by_user, NMBluezDevice *self) { if (_internal_track_connection (self, connection, @@ -400,12 +402,13 @@ static void load_connections (NMBluezDevice *self) { NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self); - const GSList *connections, *iter; + NMSettingsConnection *const*connections; + guint i; gboolean changed = FALSE; - connections = nm_connection_provider_get_connections (priv->provider); - for (iter = connections; iter; iter = g_slist_next (iter)) { - NMConnection *connection = iter->data; + connections = nm_settings_get_connections (priv->settings, NULL); + for (i = 0; connections[i]; i++) { + NMConnection *connection = (NMConnection *) connections[i]; if (connection_compatible (self, connection)) changed |= _internal_track_connection (self, connection, TRUE); @@ -1029,7 +1032,7 @@ on_bus_acquired (GObject *object, GAsyncResult *res, NMBluezDevice *self) NMBluezDevice * nm_bluez_device_new (const char *path, const char *adapter_address, - NMConnectionProvider *provider, + NMSettings *settings, int bluez_version) { NMBluezDevice *self; @@ -1037,7 +1040,7 @@ nm_bluez_device_new (const char *path, const char *interface_name = NULL; g_return_val_if_fail (path != NULL, NULL); - g_return_val_if_fail (NM_IS_CONNECTION_PROVIDER (provider), NULL); + g_return_val_if_fail (NM_IS_SETTINGS (settings), NULL); g_return_val_if_fail (bluez_version == 4 || bluez_version == 5, NULL); self = (NMBluezDevice *) g_object_new (NM_TYPE_BLUEZ_DEVICE, @@ -1051,14 +1054,14 @@ nm_bluez_device_new (const char *path, priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self); priv->bluez_version = bluez_version; - priv->provider = g_object_ref (provider); + priv->settings = g_object_ref (settings); g_return_val_if_fail (bluez_version == 5 || (bluez_version == 4 && adapter_address), NULL); if (adapter_address) set_adapter_address (self, adapter_address); - g_signal_connect (priv->provider, NM_CP_SIGNAL_CONNECTION_ADDED, G_CALLBACK (cp_connection_added), self); - g_signal_connect (priv->provider, NM_CP_SIGNAL_CONNECTION_REMOVED, G_CALLBACK (cp_connection_removed), self); - g_signal_connect (priv->provider, NM_CP_SIGNAL_CONNECTION_UPDATED, G_CALLBACK (cp_connection_updated), self); + g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_ADDED, G_CALLBACK (cp_connection_added), self); + g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_REMOVED, G_CALLBACK (cp_connection_removed), self); + g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_UPDATED, G_CALLBACK (cp_connection_updated), self); g_bus_get (G_BUS_TYPE_SYSTEM, NULL, @@ -1116,10 +1119,10 @@ dispose (GObject *object) } #endif - if (priv->provider) { - g_signal_handlers_disconnect_by_func (priv->provider, cp_connection_added, self); - g_signal_handlers_disconnect_by_func (priv->provider, cp_connection_removed, self); - g_signal_handlers_disconnect_by_func (priv->provider, cp_connection_updated, self); + if (priv->settings) { + g_signal_handlers_disconnect_by_func (priv->settings, cp_connection_added, self); + g_signal_handlers_disconnect_by_func (priv->settings, cp_connection_removed, self); + g_signal_handlers_disconnect_by_func (priv->settings, cp_connection_updated, self); } g_slist_free_full (priv->connections, g_object_unref); @@ -1137,7 +1140,7 @@ dispose (GObject *object) g_object_unref (to_delete); } - g_clear_object (&priv->provider); + g_clear_object (&priv->settings); } static void diff --git a/src/devices/bluetooth/nm-bluez-device.h b/src/devices/bluetooth/nm-bluez-device.h index c956054074..66a349e0db 100644 --- a/src/devices/bluetooth/nm-bluez-device.h +++ b/src/devices/bluetooth/nm-bluez-device.h @@ -22,7 +22,6 @@ #define __NETWORKMANAGER_BLUEZ_DEVICE_H__ #include "nm-connection.h" -#include "nm-connection-provider.h" #define NM_TYPE_BLUEZ_DEVICE (nm_bluez_device_get_type ()) #define NM_BLUEZ_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_BLUEZ_DEVICE, NMBluezDevice)) @@ -59,7 +58,7 @@ GType nm_bluez_device_get_type (void); NMBluezDevice *nm_bluez_device_new (const char *path, const char *adapter_address, - NMConnectionProvider *provider, + NMSettings *settings, int bluez_version); const char *nm_bluez_device_get_path (NMBluezDevice *self); diff --git a/src/devices/bluetooth/nm-bluez-manager.c b/src/devices/bluetooth/nm-bluez-manager.c index 766ecc0abc..0d2e302cfc 100644 --- a/src/devices/bluetooth/nm-bluez-manager.c +++ b/src/devices/bluetooth/nm-bluez-manager.c @@ -20,19 +20,20 @@ #include "nm-default.h" +#include "nm-bluez-manager.h" + #include <signal.h> #include <string.h> #include <stdlib.h> #include <gmodule.h> -#include "nm-bluez-manager.h" #include "nm-device-factory.h" #include "nm-setting-bluetooth.h" +#include "nm-settings.h" #include "nm-bluez4-manager.h" #include "nm-bluez5-manager.h" #include "nm-bluez-device.h" #include "nm-bluez-common.h" -#include "nm-connection-provider.h" #include "nm-device-bt.h" #include "nm-core-internal.h" #include "nm-platform.h" @@ -51,7 +52,7 @@ typedef struct { int bluez_version; - NMConnectionProvider *provider; + NMSettings *settings; NMBluez4Manager *manager4; NMBluez5Manager *manager5; @@ -190,7 +191,7 @@ setup_bluez4 (NMBluezManager *self) g_return_if_fail (!priv->manager4 && !priv->manager5 && !priv->bluez_version); setup_version_number (self, 4); - priv->manager4 = manager = nm_bluez4_manager_new (priv->provider); + priv->manager4 = manager = nm_bluez4_manager_new (priv->settings); g_signal_connect (manager, NM_BLUEZ_MANAGER_BDADDR_ADDED, @@ -209,7 +210,7 @@ setup_bluez5 (NMBluezManager *self) g_return_if_fail (!priv->manager4 && !priv->manager5 && !priv->bluez_version); setup_version_number (self, 5); - priv->manager5 = manager = nm_bluez5_manager_new (priv->provider); + priv->manager5 = manager = nm_bluez5_manager_new (priv->settings); g_signal_connect (manager, NM_BLUEZ_MANAGER_BDADDR_ADDED, @@ -407,9 +408,9 @@ dispose (GObject *object) priv->bluez_version = 0; - g_clear_object (&priv->provider); - G_OBJECT_CLASS (nm_bluez_manager_parent_class)->dispose (object); + + g_clear_object (&priv->settings); } static void @@ -417,7 +418,7 @@ nm_bluez_manager_init (NMBluezManager *self) { NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE (self); - priv->provider = g_object_ref (nm_connection_provider_get ()); + priv->settings = g_object_ref (NM_SETTINGS_GET); } static NMDevice * diff --git a/src/devices/bluetooth/nm-bluez-manager.h b/src/devices/bluetooth/nm-bluez-manager.h index 1f5597d831..d23b33a7d8 100644 --- a/src/devices/bluetooth/nm-bluez-manager.h +++ b/src/devices/bluetooth/nm-bluez-manager.h @@ -22,10 +22,6 @@ #ifndef __NETWORKMANAGER_BLUEZ_MANAGER_H__ #define __NETWORKMANAGER_BLUEZ_MANAGER_H__ -#include "nm-default.h" - -G_BEGIN_DECLS - #define NM_TYPE_BLUEZ_MANAGER (nm_bluez_manager_get_type ()) #define NM_BLUEZ_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_BLUEZ_MANAGER, NMBluezManager)) diff --git a/src/devices/bluetooth/nm-bluez4-adapter.c b/src/devices/bluetooth/nm-bluez4-adapter.c index 9d8fd21056..2ef071a8bf 100644 --- a/src/devices/bluetooth/nm-bluez4-adapter.c +++ b/src/devices/bluetooth/nm-bluez4-adapter.c @@ -20,13 +20,15 @@ #include "nm-default.h" +#include "nm-bluez4-adapter.h" + #include <string.h> #include "nm-dbus-interface.h" -#include "nm-bluez4-adapter.h" #include "nm-bluez-device.h" #include "nm-bluez-common.h" #include "nm-core-internal.h" +#include "nm-settings.h" G_DEFINE_TYPE (NMBluez4Adapter, nm_bluez4_adapter, G_TYPE_OBJECT) @@ -41,7 +43,7 @@ typedef struct { GHashTable *devices; /* Cached for devices */ - NMConnectionProvider *provider; + NMSettings *settings; } NMBluez4AdapterPrivate; @@ -160,7 +162,7 @@ device_created (GDBusProxy *proxy, const char *path, gpointer user_data) NMBluez4AdapterPrivate *priv = NM_BLUEZ4_ADAPTER_GET_PRIVATE (self); NMBluezDevice *device; - device = nm_bluez_device_new (path, priv->address, priv->provider, 4); + device = nm_bluez_device_new (path, priv->address, priv->settings, 4); g_signal_connect (device, "initialized", G_CALLBACK (device_initialized), self); g_signal_connect (device, "notify::usable", G_CALLBACK (device_usable), self); g_hash_table_insert (priv->devices, (gpointer) nm_bluez_device_get_path (device), device); @@ -234,17 +236,19 @@ query_properties (NMBluez4Adapter *self) /***********************************************************/ NMBluez4Adapter * -nm_bluez4_adapter_new (const char *path, NMConnectionProvider *provider) +nm_bluez4_adapter_new (const char *path, NMSettings *settings) { NMBluez4Adapter *self; NMBluez4AdapterPrivate *priv; + g_return_val_if_fail (NM_IS_SETTINGS (settings), NULL); + self = (NMBluez4Adapter *) g_object_new (NM_TYPE_BLUEZ4_ADAPTER, NM_BLUEZ4_ADAPTER_PATH, path, NULL); priv = NM_BLUEZ4_ADAPTER_GET_PRIVATE (self); - priv->provider = provider; + priv->settings = g_object_ref (settings); priv->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, @@ -301,6 +305,8 @@ finalize (GObject *object) g_object_unref (priv->proxy); G_OBJECT_CLASS (nm_bluez4_adapter_parent_class)->finalize (object); + + g_object_unref (priv->settings); } static void diff --git a/src/devices/bluetooth/nm-bluez4-adapter.h b/src/devices/bluetooth/nm-bluez4-adapter.h index a8a2bfb4d2..ee61112f2e 100644 --- a/src/devices/bluetooth/nm-bluez4-adapter.h +++ b/src/devices/bluetooth/nm-bluez4-adapter.h @@ -21,10 +21,7 @@ #ifndef __NETWORKMANAGER_BLUEZ4_ADAPTER_H__ #define __NETWORKMANAGER_BLUEZ4_ADAPTER_H__ - -#include "nm-default.h" #include "nm-bluez-device.h" -#include "nm-connection-provider.h" #define NM_TYPE_BLUEZ4_ADAPTER (nm_bluez4_adapter_get_type ()) #define NM_BLUEZ4_ADAPTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_BLUEZ4_ADAPTER, NMBluez4Adapter)) @@ -54,7 +51,7 @@ typedef struct { GType nm_bluez4_adapter_get_type (void); NMBluez4Adapter *nm_bluez4_adapter_new (const char *path, - NMConnectionProvider *provider); + NMSettings *settings); const char *nm_bluez4_adapter_get_path (NMBluez4Adapter *self); diff --git a/src/devices/bluetooth/nm-bluez4-manager.c b/src/devices/bluetooth/nm-bluez4-manager.c index 146612a890..36bc30e59c 100644 --- a/src/devices/bluetooth/nm-bluez4-manager.c +++ b/src/devices/bluetooth/nm-bluez4-manager.c @@ -21,20 +21,22 @@ #include "nm-default.h" +#include "nm-bluez4-manager.h" + #include <signal.h> #include <string.h> #include <stdlib.h> -#include "nm-bluez-manager.h" -#include "nm-bluez4-manager.h" #include "nm-bluez4-adapter.h" +#include "nm-bluez-manager.h" #include "nm-bluez-common.h" #include "nm-core-internal.h" +#include "nm-settings.h" typedef struct { gulong name_owner_changed_id; - NMConnectionProvider *provider; + NMSettings *settings; GDBusProxy *proxy; @@ -155,7 +157,7 @@ default_adapter_changed (GDBusProxy *proxy, const char *path, NMBluez4Manager *s /* Add the new default adapter */ if (path) { - priv->adapter = nm_bluez4_adapter_new (path, priv->provider); + priv->adapter = nm_bluez4_adapter_new (path, priv->settings); g_signal_connect (priv->adapter, "initialized", G_CALLBACK (adapter_initialized), self); } } @@ -223,12 +225,14 @@ name_owner_changed_cb (GObject *object, /****************************************************************/ NMBluez4Manager * -nm_bluez4_manager_new (NMConnectionProvider *provider) +nm_bluez4_manager_new (NMSettings *settings) { NMBluez4Manager *instance; + g_return_val_if_fail (NM_IS_SETTINGS (settings), NULL); + instance = g_object_new (NM_TYPE_BLUEZ4_MANAGER, NULL); - NM_BLUEZ4_MANAGER_GET_PRIVATE (instance)->provider = provider; + NM_BLUEZ4_MANAGER_GET_PRIVATE (instance)->settings = g_object_ref (settings); return instance; } @@ -264,6 +268,8 @@ dispose (GObject *object) g_clear_object (&priv->adapter); G_OBJECT_CLASS (nm_bluez4_manager_parent_class)->dispose (object); + + g_clear_object (&priv->settings); } static void diff --git a/src/devices/bluetooth/nm-bluez4-manager.h b/src/devices/bluetooth/nm-bluez4-manager.h index f6bf76586b..dbf7688940 100644 --- a/src/devices/bluetooth/nm-bluez4-manager.h +++ b/src/devices/bluetooth/nm-bluez4-manager.h @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ /* NetworkManager -- Network link manager * * This program is free software; you can redistribute it and/or modify @@ -23,7 +22,6 @@ #define __NETWORKMANAGER_BLUEZ4_MANAGER_H__ #include "nm-default.h" -#include "nm-connection-provider.h" G_BEGIN_DECLS @@ -51,7 +49,7 @@ typedef struct { GType nm_bluez4_manager_get_type (void); -NMBluez4Manager *nm_bluez4_manager_new (NMConnectionProvider *provider); +NMBluez4Manager *nm_bluez4_manager_new (NMSettings *settings); void nm_bluez4_manager_query_devices (NMBluez4Manager *manager); diff --git a/src/devices/bluetooth/nm-bluez5-manager.c b/src/devices/bluetooth/nm-bluez5-manager.c index 66d171bf2e..183f23c1e4 100644 --- a/src/devices/bluetooth/nm-bluez5-manager.c +++ b/src/devices/bluetooth/nm-bluez5-manager.c @@ -22,19 +22,21 @@ #include "nm-default.h" +#include "nm-bluez5-manager.h" + #include <signal.h> #include <string.h> #include <stdlib.h> +#include "nm-core-internal.h" + #include "nm-bluez-manager.h" -#include "nm-bluez5-manager.h" #include "nm-bluez-device.h" #include "nm-bluez-common.h" - -#include "nm-core-internal.h" +#include "nm-settings.h" typedef struct { - NMConnectionProvider *provider; + NMSettings *settings; GDBusProxy *proxy; @@ -140,7 +142,7 @@ device_added (GDBusProxy *proxy, const gchar *path, NMBluez5Manager *self) NMBluez5ManagerPrivate *priv = NM_BLUEZ5_MANAGER_GET_PRIVATE (self); NMBluezDevice *device; - device = nm_bluez_device_new (path, NULL, priv->provider, 5); + device = nm_bluez_device_new (path, NULL, priv->settings, 5); g_signal_connect (device, "initialized", G_CALLBACK (device_initialized), self); g_signal_connect (device, "notify::usable", G_CALLBACK (device_usable), self); g_hash_table_insert (priv->devices, (gpointer) nm_bluez_device_get_path (device), device); @@ -309,12 +311,14 @@ bluez_cleanup (NMBluez5Manager *self, gboolean do_signal) /****************************************************************/ NMBluez5Manager * -nm_bluez5_manager_new (NMConnectionProvider *provider) +nm_bluez5_manager_new (NMSettings *settings) { NMBluez5Manager *instance = NULL; + g_return_val_if_fail (NM_IS_SETTINGS (settings), NULL); + instance = g_object_new (NM_TYPE_BLUEZ5_MANAGER, NULL); - NM_BLUEZ5_MANAGER_GET_PRIVATE (instance)->provider = provider; + NM_BLUEZ5_MANAGER_GET_PRIVATE (instance)->settings = g_object_ref (settings); return instance; } @@ -347,6 +351,8 @@ finalize (GObject *object) g_hash_table_destroy (priv->devices); G_OBJECT_CLASS (nm_bluez5_manager_parent_class)->finalize (object); + + g_object_unref (priv->settings); } static void diff --git a/src/devices/bluetooth/nm-bluez5-manager.h b/src/devices/bluetooth/nm-bluez5-manager.h index 1c531090b7..0e309d33a3 100644 --- a/src/devices/bluetooth/nm-bluez5-manager.h +++ b/src/devices/bluetooth/nm-bluez5-manager.h @@ -22,11 +22,6 @@ #ifndef __NETWORKMANAGER_BLUEZ5_MANAGER_H__ #define __NETWORKMANAGER_BLUEZ5_MANAGER_H__ -#include "nm-default.h" -#include "nm-connection-provider.h" - -G_BEGIN_DECLS - #define NM_TYPE_BLUEZ5_MANAGER (nm_bluez5_manager_get_type ()) #define NM_BLUEZ5_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_BLUEZ5_MANAGER, NMBluez5Manager)) #define NM_BLUEZ5_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_BLUEZ5_MANAGER, NMBluez5ManagerClass)) @@ -51,7 +46,7 @@ typedef struct { GType nm_bluez5_manager_get_type (void); -NMBluez5Manager *nm_bluez5_manager_new (NMConnectionProvider *provider); +NMBluez5Manager *nm_bluez5_manager_new (NMSettings *settings); void nm_bluez5_manager_query_devices (NMBluez5Manager *manager); diff --git a/src/devices/nm-device-ethernet-utils.c b/src/devices/nm-device-ethernet-utils.c index d034ddfc77..298e6dff95 100644 --- a/src/devices/nm-device-ethernet-utils.c +++ b/src/devices/nm-device-ethernet-utils.c @@ -25,30 +25,26 @@ #include "nm-device-ethernet-utils.h" char * -nm_device_ethernet_utils_get_default_wired_name (const GSList *connections) +nm_device_ethernet_utils_get_default_wired_name (NMConnection *const *connections) { - const GSList *iter; - char *cname = NULL; - int i = 0; + char *temp; + guint j; + int i; /* Find the next available unique connection name */ - while (!cname && (i++ < 10000)) { - char *temp; - gboolean found = FALSE; - + for (i = 1; i <= 10000; i++) { temp = g_strdup_printf (_("Wired connection %d"), i); - for (iter = connections; iter; iter = iter->next) { - if (g_strcmp0 (nm_connection_get_id (NM_CONNECTION (iter->data)), temp) == 0) { - found = TRUE; + for (j = 0; connections[j]; j++) { + if (nm_streq0 (nm_connection_get_id (connections[j]), temp)) { g_free (temp); - break; + goto next; } } - - if (found == FALSE) - cname = temp; + return temp; +next: + ; } - return cname; + return NULL; } diff --git a/src/devices/nm-device-ethernet-utils.h b/src/devices/nm-device-ethernet-utils.h index 31d645d851..197d0a9ea4 100644 --- a/src/devices/nm-device-ethernet-utils.h +++ b/src/devices/nm-device-ethernet-utils.h @@ -19,8 +19,6 @@ #ifndef __NETWORKMANAGER_DEVICE_ETHERNET_UTILS_H__ #define __NETWORKMANAGER_DEVICE_ETHERNET_UTILS_H__ -#include "nm-default.h" - -char *nm_device_ethernet_utils_get_default_wired_name (const GSList *connections); +char *nm_device_ethernet_utils_get_default_wired_name (NMConnection *const *connections); #endif /* NETWORKMANAGER_DEVICE_ETHERNET_UTILS_H */ diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index d27f7dcaf1..96cc6db34e 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -21,6 +21,8 @@ #include "nm-default.h" +#include "nm-device-ethernet.h" + #include <netinet/in.h> #include <string.h> #include <stdlib.h> @@ -29,7 +31,6 @@ #include <gudev/gudev.h> -#include "nm-device-ethernet.h" #include "nm-device-private.h" #include "nm-activation-request.h" #include "NetworkManagerUtils.h" @@ -44,7 +45,7 @@ #include "nm-settings-connection.h" #include "nm-config.h" #include "nm-device-ethernet-utils.h" -#include "nm-connection-provider.h" +#include "nm-settings.h" #include "nm-device-factory.h" #include "nm-core-internal.h" #include "NetworkManagerUtils.h" @@ -1435,7 +1436,7 @@ static NMConnection * new_default_connection (NMDevice *self) { NMConnection *connection; - const GSList *connections; + NMSettingsConnection *const*connections; NMSetting *setting; const char *hw_address; gs_free char *defname = NULL; @@ -1453,8 +1454,8 @@ new_default_connection (NMDevice *self) setting = nm_setting_connection_new (); nm_connection_add_setting (connection, setting); - connections = nm_connection_provider_get_connections (nm_connection_provider_get ()); - defname = nm_device_ethernet_utils_get_default_wired_name (connections); + connections = nm_settings_get_connections (nm_device_get_settings (self), NULL); + defname = nm_device_ethernet_utils_get_default_wired_name ((NMConnection *const*) connections); if (!defname) return NULL; diff --git a/src/devices/nm-device-ip-tunnel.c b/src/devices/nm-device-ip-tunnel.c index 089b10352c..785010ebfa 100644 --- a/src/devices/nm-device-ip-tunnel.c +++ b/src/devices/nm-device-ip-tunnel.c @@ -20,19 +20,20 @@ #include "nm-default.h" +#include "nm-device-ip-tunnel.h" + #include <string.h> #include <netinet/in.h> #include <linux/if.h> #include <linux/ip.h> #include <linux/if_tunnel.h> -#include "nm-device-ip-tunnel.h" #include "nm-device-private.h" #include "nm-manager.h" #include "nm-platform.h" #include "nm-device-factory.h" #include "nm-core-internal.h" -#include "nm-connection-provider.h" +#include "nm-settings.h" #include "nm-activation-request.h" #include "nm-ip4-config.h" @@ -385,8 +386,8 @@ update_connection (NMDevice *device, NMConnection *connection) NMConnection *parent_connection; /* Don't change a parent specified by UUID if it's still valid */ - parent_connection = nm_connection_provider_get_connection_by_uuid (nm_connection_provider_get (), - setting_parent); + parent_connection = (NMConnection *) nm_settings_get_connection_by_uuid (nm_device_get_settings (device), + setting_parent); if (parent_connection && nm_device_check_connection_compatible (parent, parent_connection)) new_parent = NULL; } diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c index c431fe891c..c5443ecd23 100644 --- a/src/devices/nm-device-macvlan.c +++ b/src/devices/nm-device-macvlan.c @@ -20,11 +20,12 @@ #include "nm-default.h" +#include "nm-device-macvlan.h" + #include <string.h> -#include "nm-device-macvlan.h" #include "nm-device-private.h" -#include "nm-connection-provider.h" +#include "nm-settings.h" #include "nm-activation-request.h" #include "nm-manager.h" #include "nm-platform.h" @@ -488,7 +489,7 @@ update_connection (NMDevice *device, NMConnection *connection) NMConnection *parent_connection; /* Don't change a parent specified by UUID if it's still valid */ - parent_connection = nm_connection_provider_get_connection_by_uuid (nm_connection_provider_get (), setting_parent); + parent_connection = (NMConnection *) nm_settings_get_connection_by_uuid (nm_device_get_settings (device), setting_parent); if (parent_connection && nm_device_check_connection_compatible (priv->parent, parent_connection)) new_parent = NULL; } diff --git a/src/devices/nm-device-private.h b/src/devices/nm-device-private.h index 1f81ed0eab..418ae2d9ca 100644 --- a/src/devices/nm-device-private.h +++ b/src/devices/nm-device-private.h @@ -42,6 +42,8 @@ enum NMActStageReturn { #define NM_DEVICE_CAP_INTERNAL_MASK 0xc0000000 +NMSettings *nm_device_get_settings (NMDevice *self); + void nm_device_set_ip_iface (NMDevice *self, const char *iface); void nm_device_activate_schedule_stage3_ip_config_start (NMDevice *device); diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c index eb6527de8e..95f36298f5 100644 --- a/src/devices/nm-device-vlan.c +++ b/src/devices/nm-device-vlan.c @@ -20,15 +20,16 @@ #include "nm-default.h" +#include "nm-device-vlan.h" + #include <sys/socket.h> -#include "nm-device-vlan.h" #include "nm-manager.h" #include "nm-utils.h" #include "NetworkManagerUtils.h" #include "nm-device-private.h" #include "nm-enum-types.h" -#include "nm-connection-provider.h" +#include "nm-settings.h" #include "nm-activation-request.h" #include "nm-ip4-config.h" #include "nm-platform.h" @@ -515,7 +516,7 @@ update_connection (NMDevice *device, NMConnection *connection) NMConnection *parent_connection; /* Don't change a parent specified by UUID if it's still valid */ - parent_connection = nm_connection_provider_get_connection_by_uuid (nm_connection_provider_get (), setting_parent); + parent_connection = (NMConnection *) nm_settings_get_connection_by_uuid (nm_device_get_settings (device), setting_parent); if (parent_connection && nm_device_check_connection_compatible (priv->parent, parent_connection)) new_parent = NULL; } diff --git a/src/devices/nm-device-vxlan.c b/src/devices/nm-device-vxlan.c index d308d47abc..f3dfbd9ef5 100644 --- a/src/devices/nm-device-vxlan.c +++ b/src/devices/nm-device-vxlan.c @@ -20,9 +20,10 @@ #include "nm-default.h" +#include "nm-device-vxlan.h" + #include <string.h> -#include "nm-device-vxlan.h" #include "nm-device-private.h" #include "nm-manager.h" #include "nm-platform.h" @@ -30,7 +31,7 @@ #include "nm-device-factory.h" #include "nm-setting-vxlan.h" #include "nm-setting-wired.h" -#include "nm-connection-provider.h" +#include "nm-settings.h" #include "nm-activation-request.h" #include "nm-ip4-config.h" @@ -411,8 +412,8 @@ update_connection (NMDevice *device, NMConnection *connection) NMConnection *parent_connection; /* Don't change a parent specified by UUID if it's still valid */ - parent_connection = nm_connection_provider_get_connection_by_uuid (nm_connection_provider_get (), - setting_parent); + parent_connection = (NMConnection *) nm_settings_get_connection_by_uuid (nm_device_get_settings (device), + setting_parent); if (parent_connection && nm_device_check_connection_compatible (parent, parent_connection)) new_parent = NULL; } diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index b8cbe8bc15..1726687825 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -21,6 +21,8 @@ #include "nm-default.h" +#include "nm-device.h" + #include <netinet/in.h> #include <string.h> #include <unistd.h> @@ -34,7 +36,6 @@ #include <netlink/route/addr.h> #include <linux/if_addr.h> -#include "nm-device.h" #include "nm-device-private.h" #include "NetworkManagerUtils.h" #include "nm-manager.h" @@ -52,7 +53,7 @@ #include "nm-firewall-manager.h" #include "nm-enum-types.h" #include "nm-settings-connection.h" -#include "nm-connection-provider.h" +#include "nm-settings.h" #include "nm-auth-utils.h" #include "nm-dispatcher.h" #include "nm-config.h" @@ -72,7 +73,18 @@ _LOG_DECLARE_SELF (NMDevice); G_DEFINE_ABSTRACT_TYPE (NMDevice, nm_device, NM_TYPE_EXPORTED_OBJECT) -#define NM_DEVICE_GET_PRIVATE(o) ((o)->priv) +#define NM_DEVICE_GET_PRIVATE(o) \ + ({ \ + /* preserve the const-ness of self. Unfortunately, that + * way, @self cannot be a void pointer */ \ + typeof (self) _self = (self); \ + \ + /* Get compiler error if variable is of wrong type */ \ + _nm_unused const NMDevice *_self2 = (_self); \ + \ + nm_assert (NM_IS_DEVICE (_self)); \ + _self->priv; \ + }) enum { STATE_CHANGED, @@ -376,7 +388,8 @@ typedef struct _NMDevicePrivate { NMMetered metered; - NMConnectionProvider *con_provider; + NMSettings *settings; + NMLldpListener *lldp_listener; guint check_delete_unrealized_id; @@ -537,6 +550,12 @@ NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_reason_to_string, NMDeviceStateReason, /***********************************************************/ +NMSettings * +nm_device_get_settings (NMDevice *self) +{ + return NM_DEVICE_GET_PRIVATE (self)->settings; +} + static void init_ip4_config_dns_priority (NMDevice *self, NMIP4Config *config) { @@ -1642,7 +1661,7 @@ device_link_changed (NMDevice *self) ip_ifname_changed = !priv->ip_iface; if (nm_device_get_unmanaged_flags (self, NM_UNMANAGED_PLATFORM_INIT)) - nm_device_set_unmanaged_by_user_settings (self, nm_connection_provider_get_unmanaged_specs (priv->con_provider)); + nm_device_set_unmanaged_by_user_settings (self, nm_settings_get_unmanaged_specs (priv->settings)); else update_unmanaged_specs = TRUE; @@ -1720,7 +1739,7 @@ device_link_changed (NMDevice *self) } if (update_unmanaged_specs) - nm_device_set_unmanaged_by_user_settings (self, nm_connection_provider_get_unmanaged_specs (priv->con_provider)); + nm_device_set_unmanaged_by_user_settings (self, nm_settings_get_unmanaged_specs (priv->settings)); return G_SOURCE_REMOVE; } @@ -8988,7 +9007,7 @@ capture_lease_config (NMDevice *self, NMIP6Config **out_ip6_config) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - const GSList *connections, *citer; + NMSettingsConnection *const*connections; guint i; gboolean dhcp_used = FALSE; @@ -9021,9 +9040,9 @@ capture_lease_config (NMDevice *self, if (!dhcp_used) return; - connections = nm_connection_provider_get_connections (priv->con_provider); - for (citer = connections; citer; citer = citer->next) { - NMConnection *candidate = citer->data; + connections = nm_settings_get_connections (priv->settings, NULL); + for (i = 0; connections[i]; i++) { + NMConnection *candidate = (NMConnection *) connections[i]; const char *method; if (!nm_device_check_connection_compatible (self, candidate)) @@ -10071,50 +10090,45 @@ void nm_device_recheck_available_connections (NMDevice *self) { NMDevicePrivate *priv; - const GSList *connections, *iter; + NMSettingsConnection *const*connections; gboolean changed = FALSE; GHashTableIter h_iter; NMConnection *connection; + guint i; + gs_unref_hashtable GHashTable *prune_list = NULL; g_return_if_fail (NM_IS_DEVICE (self)); priv = NM_DEVICE_GET_PRIVATE(self); - if (priv->con_provider) { - gs_unref_hashtable GHashTable *prune_list = NULL; - - if (g_hash_table_size (priv->available_connections) > 0) { - prune_list = g_hash_table_new (g_direct_hash, g_direct_equal); - g_hash_table_iter_init (&h_iter, priv->available_connections); - while (g_hash_table_iter_next (&h_iter, (gpointer *) &connection, NULL)) - g_hash_table_add (prune_list, connection); - } + if (g_hash_table_size (priv->available_connections) > 0) { + prune_list = g_hash_table_new (g_direct_hash, g_direct_equal); + g_hash_table_iter_init (&h_iter, priv->available_connections); + while (g_hash_table_iter_next (&h_iter, (gpointer *) &connection, NULL)) + g_hash_table_add (prune_list, connection); + } - connections = nm_connection_provider_get_connections (priv->con_provider); - for (iter = connections; iter; iter = g_slist_next (iter)) { - connection = NM_CONNECTION (iter->data); + connections = nm_settings_get_connections (priv->settings, NULL); + for (i = 0; connections[i]; i++) { + connection = (NMConnection *) connections[i]; - if (nm_device_check_connection_available (self, - connection, - NM_DEVICE_CHECK_CON_AVAILABLE_NONE, - NULL)) { - if (available_connections_add (self, connection)) - changed = TRUE; - if (prune_list) - g_hash_table_remove (prune_list, connection); - } + if (nm_device_check_connection_available (self, + connection, + NM_DEVICE_CHECK_CON_AVAILABLE_NONE, + NULL)) { + if (available_connections_add (self, connection)) + changed = TRUE; + if (prune_list) + g_hash_table_remove (prune_list, connection); } + } - if (prune_list) { - g_hash_table_iter_init (&h_iter, prune_list); - while (g_hash_table_iter_next (&h_iter, (gpointer *) &connection, NULL)) { - if (available_connections_del (self, connection)) - changed = TRUE; - } + if (prune_list) { + g_hash_table_iter_init (&h_iter, prune_list); + while (g_hash_table_iter_next (&h_iter, (gpointer *) &connection, NULL)) { + if (available_connections_del (self, connection)) + changed = TRUE; } - } else { - if (available_connections_del_all (self)) - changed = TRUE; } if (changed) @@ -10175,10 +10189,9 @@ nm_device_get_best_connection (NMDevice *self, } static void -cp_connection_added_or_updated (NMConnectionProvider *cp, NMConnection *connection, gpointer user_data) +cp_connection_added_or_updated (NMDevice *self, NMConnection *connection) { gboolean changed; - NMDevice *self = user_data; g_return_if_fail (NM_IS_DEVICE (self)); g_return_if_fail (NM_IS_SETTINGS_CONNECTION (connection)); @@ -10198,6 +10211,18 @@ cp_connection_added_or_updated (NMConnectionProvider *cp, NMConnection *connecti } static void +cp_connection_added (NMConnectionProvider *cp, NMConnection *connection, gpointer user_data) +{ + cp_connection_added_or_updated (user_data, connection); +} + +static void +cp_connection_updated (NMConnectionProvider *cp, NMConnection *connection, gboolean by_user, gpointer user_data) +{ + cp_connection_added_or_updated (user_data, connection); +} + +static void cp_connection_removed (NMConnectionProvider *cp, NMConnection *connection, gpointer user_data) { NMDevice *self = user_data; @@ -11510,21 +11535,20 @@ constructed (GObject *object) g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, G_CALLBACK (device_ipx_changed), self); g_signal_connect (platform, NM_PLATFORM_SIGNAL_LINK_CHANGED, G_CALLBACK (link_changed_cb), self); - priv->con_provider = nm_connection_provider_get (); - g_assert (priv->con_provider); - g_signal_connect (priv->con_provider, - NM_CP_SIGNAL_CONNECTION_ADDED, - G_CALLBACK (cp_connection_added_or_updated), - self); + priv->settings = g_object_ref (NM_SETTINGS_GET); + g_assert (priv->settings); - g_signal_connect (priv->con_provider, - NM_CP_SIGNAL_CONNECTION_REMOVED, - G_CALLBACK (cp_connection_removed), + g_signal_connect (priv->settings, + NM_SETTINGS_SIGNAL_CONNECTION_ADDED, + G_CALLBACK (cp_connection_added), self); - - g_signal_connect (priv->con_provider, - NM_CP_SIGNAL_CONNECTION_UPDATED, - G_CALLBACK (cp_connection_added_or_updated), + g_signal_connect (priv->settings, + NM_SETTINGS_SIGNAL_CONNECTION_UPDATED, + G_CALLBACK (cp_connection_updated), + self); + g_signal_connect (priv->settings, + NM_SETTINGS_SIGNAL_CONNECTION_REMOVED, + G_CALLBACK (cp_connection_removed), self); G_OBJECT_CLASS (nm_device_parent_class)->constructed (object); @@ -11573,10 +11597,10 @@ dispose (GObject *object) link_disconnect_action_cancel (self); - if (priv->con_provider) { - g_signal_handlers_disconnect_by_func (priv->con_provider, cp_connection_added_or_updated, self); - g_signal_handlers_disconnect_by_func (priv->con_provider, cp_connection_removed, self); - priv->con_provider = NULL; + if (priv->settings) { + g_signal_handlers_disconnect_by_func (priv->settings, cp_connection_added, self); + g_signal_handlers_disconnect_by_func (priv->settings, cp_connection_updated, self); + g_signal_handlers_disconnect_by_func (priv->settings, cp_connection_removed, self); } available_connections_del_all (self); @@ -11634,6 +11658,11 @@ finalize (GObject *object) g_hash_table_unref (priv->available_connections); G_OBJECT_CLASS (nm_device_parent_class)->finalize (object); + + /* for testing, NMDeviceTest does not invoke NMDevice::constructed, + * and thus @settings might be unset. */ + if (priv->settings) + g_object_unref (priv->settings); } static void diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 3dada1ad4f..5f1a168352 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -26,7 +26,6 @@ #include "nm-exported-object.h" #include "nm-dbus-interface.h" -#include "nm-default.h" #include "nm-connection.h" #include "nm-rfkill-manager.h" #include "NetworkManagerUtils.h" diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 95a89eab32..1fa527a776 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -21,13 +21,14 @@ #include "nm-default.h" +#include "nm-device-wifi.h" + #include <netinet/in.h> #include <string.h> #include <unistd.h> #include <errno.h> #include "nm-device.h" -#include "nm-device-wifi.h" #include "nm-device-private.h" #include "nm-utils.h" #include "NetworkManagerUtils.h" @@ -45,8 +46,8 @@ #include "nm-platform.h" #include "nm-auth-utils.h" #include "nm-settings-connection.h" +#include "nm-settings.h" #include "nm-enum-types.h" -#include "nm-connection-provider.h" #include "nm-core-internal.h" #include "nm-config.h" @@ -1197,7 +1198,7 @@ check_scanning_allowed (NMDeviceWifi *self) } static gboolean -hidden_filter_func (NMConnectionProvider *provider, +hidden_filter_func (NMSettings *settings, NMConnection *connection, gpointer user_data) { @@ -1224,12 +1225,12 @@ build_hidden_probe_list (NMDeviceWifi *self) if (G_UNLIKELY (nullssid == NULL)) nullssid = g_byte_array_new (); - connections = nm_connection_provider_get_best_connections (nm_connection_provider_get (), - max_scan_ssids - 1, - NM_SETTING_WIRELESS_SETTING_NAME, - NULL, - hidden_filter_func, - NULL); + connections = nm_settings_get_best_connections (nm_device_get_settings ((NMDevice *) self), + max_scan_ssids - 1, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL, + hidden_filter_func, + NULL); if (connections && connections->data) { ssids = g_ptr_array_new_full (max_scan_ssids - 1, (GDestroyNotify) g_byte_array_unref); g_ptr_array_add (ssids, g_byte_array_ref (nullssid)); /* Add wildcard SSID */ @@ -1456,10 +1457,12 @@ schedule_ap_list_dump (NMDeviceWifi *self) } static void -try_fill_ssid_for_hidden_ap (NMAccessPoint *ap) +try_fill_ssid_for_hidden_ap (NMDeviceWifi *self, + NMAccessPoint *ap) { const char *bssid; - const GSList *connections, *iter; + NMSettingsConnection *const*connections; + guint i; g_return_if_fail (nm_ap_get_ssid (ap) == NULL); @@ -1468,9 +1471,9 @@ try_fill_ssid_for_hidden_ap (NMAccessPoint *ap) /* Look for this AP's BSSID in the seen-bssids list of a connection, * and if a match is found, copy over the SSID */ - connections = nm_connection_provider_get_connections (nm_connection_provider_get ()); - for (iter = connections; iter; iter = g_slist_next (iter)) { - NMConnection *connection = NM_CONNECTION (iter->data); + connections = nm_settings_get_connections (nm_device_get_settings ((NMDevice *) self), NULL); + for (i = 0; connections[i]; i++) { + NMConnection *connection = (NMConnection *) connections[i]; NMSettingWireless *s_wifi; s_wifi = nm_connection_get_setting_wireless (connection); @@ -1520,7 +1523,7 @@ supplicant_iface_new_bss_cb (NMSupplicantInterface *iface, ssid = nm_ap_get_ssid (ap); if (!ssid || nm_utils_is_empty_ssid (ssid->data, ssid->len)) { /* Try to fill the SSID from the AP database */ - try_fill_ssid_for_hidden_ap (ap); + try_fill_ssid_for_hidden_ap (self, ap); ssid = nm_ap_get_ssid (ap); if (ssid && (nm_utils_is_empty_ssid (ssid->data, ssid->len) == FALSE)) { diff --git a/src/nm-connection-provider.c b/src/nm-connection-provider.c deleted file mode 100644 index fe1ea7e205..0000000000 --- a/src/nm-connection-provider.c +++ /dev/null @@ -1,135 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details: - * - * Copyright (C) 2012 Red Hat, Inc. - */ - -#include "nm-default.h" - -#include "nm-connection-provider.h" - -#include "nm-utils.h" - -G_DEFINE_INTERFACE (NMConnectionProvider, nm_connection_provider, G_TYPE_OBJECT) - -GSList * -nm_connection_provider_get_best_connections (NMConnectionProvider *self, - guint max_requested, - const char *ctype1, - const char *ctype2, - NMConnectionFilterFunc func, - gpointer func_data) -{ - g_return_val_if_fail (NM_IS_CONNECTION_PROVIDER (self), NULL); - - if (NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_best_connections) - return NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_best_connections (self, max_requested, ctype1, ctype2, func, func_data); - return NULL; -} - -const GSList * -nm_connection_provider_get_connections (NMConnectionProvider *self) -{ - g_return_val_if_fail (NM_IS_CONNECTION_PROVIDER (self), NULL); - - if (NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_connections) - return NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_connections (self); - return NULL; -} - -/** - * nm_connection_provider_add_connection: - * @self: the #NMConnectionProvider - * @connection: the source connection to create a new #NMSettingsConnection from - * @save_to_disk: %TRUE to save the connection to disk immediately, %FALSE to - * not save to disk - * @error: on return, a location to store any errors that may occur - * - * Creates a new #NMSettingsConnection for the given source @connection. - * The plugin owns the returned object and the caller must reference the object - * to continue using it. - * - * Returns: the new #NMSettingsConnection or %NULL - */ -NMConnection * -nm_connection_provider_add_connection (NMConnectionProvider *self, - NMConnection *connection, - gboolean save_to_disk, - GError **error) -{ - g_return_val_if_fail (NM_IS_CONNECTION_PROVIDER (self), NULL); - - g_assert (NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->add_connection); - return NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->add_connection (self, connection, save_to_disk, error); -} - -/** - * nm_connection_provider_get_connection_by_uuid: - * @self: the #NMConnectionProvider - * @uuid: the UUID to search for - * - * Returns: the connection with the given @uuid, or %NULL - */ -NMConnection * -nm_connection_provider_get_connection_by_uuid (NMConnectionProvider *self, - const char *uuid) -{ - g_return_val_if_fail (NM_IS_CONNECTION_PROVIDER (self), NULL); - g_return_val_if_fail (uuid != NULL, NULL); - g_return_val_if_fail (nm_utils_is_uuid (uuid), NULL); - - g_assert (NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_connection_by_uuid); - return NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_connection_by_uuid (self, uuid); -} - -const GSList * -nm_connection_provider_get_unmanaged_specs (NMConnectionProvider *self) -{ - g_return_val_if_fail (NM_IS_CONNECTION_PROVIDER (self), NULL); - - return NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_unmanaged_specs (self); -} - -/*****************************************************************************/ - -static void -nm_connection_provider_default_init (NMConnectionProviderInterface *g_iface) -{ - GType iface_type = G_TYPE_FROM_INTERFACE (g_iface); - static gboolean initialized = FALSE; - - if (initialized) - return; - initialized = TRUE; - - /* Signals */ - g_signal_new (NM_CP_SIGNAL_CONNECTION_ADDED, - iface_type, - G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, G_TYPE_OBJECT); - - g_signal_new (NM_CP_SIGNAL_CONNECTION_UPDATED, - iface_type, - G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, G_TYPE_OBJECT); - - g_signal_new (NM_CP_SIGNAL_CONNECTION_REMOVED, - iface_type, - G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, G_TYPE_OBJECT); -} diff --git a/src/nm-connection-provider.h b/src/nm-connection-provider.h deleted file mode 100644 index 1209213bcb..0000000000 --- a/src/nm-connection-provider.h +++ /dev/null @@ -1,129 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details: - * - * Copyright (C) 2012 Red Hat, Inc. - */ - -#ifndef __NETWORKMANAGER_CONNECTION_PROVIDER_H__ -#define __NETWORKMANAGER_CONNECTION_PROVIDER_H__ - -#include "nm-connection.h" - -#define NM_TYPE_CONNECTION_PROVIDER (nm_connection_provider_get_type ()) -#define NM_CONNECTION_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CONNECTION_PROVIDER, NMConnectionProvider)) -#define NM_IS_CONNECTION_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_CONNECTION_PROVIDER)) -#define NM_CONNECTION_PROVIDER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), NM_TYPE_CONNECTION_PROVIDER, NMConnectionProviderInterface)) - -#define NM_CP_SIGNAL_CONNECTION_ADDED "cp-connection-added" -#define NM_CP_SIGNAL_CONNECTION_UPDATED "cp-connection-updated" -#define NM_CP_SIGNAL_CONNECTION_REMOVED "cp-connection-removed" - - -/** - * NMConnectionFilterFunc: - * @provider: The provider requesting the filtering - * @connection: the connection to be filtered - * @func_data: the caller-provided data pointer - * - * Returns: %TRUE to allow the connection, %FALSE to ignore it - */ -typedef gboolean (*NMConnectionFilterFunc) (NMConnectionProvider *provider, - NMConnection *connection, - gpointer func_data); - - -typedef struct { - GTypeInterface g_iface; - - /* Methods */ - GSList * (*get_best_connections) (NMConnectionProvider *self, - guint max_requested, - const char *ctype1, - const char *ctype2, - NMConnectionFilterFunc func, - gpointer func_data); - - const GSList * (*get_connections) (NMConnectionProvider *self); - - NMConnection * (*add_connection) (NMConnectionProvider *self, - NMConnection *connection, - gboolean save_to_disk, - GError **error); - - NMConnection * (*get_connection_by_uuid) (NMConnectionProvider *self, - const char *uuid); - - const GSList * (*get_unmanaged_specs) (NMConnectionProvider *self); -} NMConnectionProviderInterface; - -GType nm_connection_provider_get_type (void); - -/** - * nm_connection_provider_get: - * - * Returns: the global #NMConnectionProvider - */ -NMConnectionProvider *nm_connection_provider_get (void); - -/** - * nm_connection_provider_get_best_connections: - * @self: the #NMConnectionProvider - * @max_requested: if non-zero, the maximum number of connections to return - * @ctype1: an #NMSetting base type (eg NM_SETTING_WIRELESS_SETTING_NAME) to - * filter connections against - * @ctype2: a second #NMSetting base type (eg NM_SETTING_WIRELESS_SETTING_NAME) - * to filter connections against - * @func: caller-supplied function for filtering connections - * @func_data: caller-supplied data passed to @func - * - * Returns: a #GSList of #NMConnection objects in sorted order representing the - * "best" or highest-priority connections filtered by @ctype1 and/or @ctype2, - * and/or @func. Caller is responsible for freeing the returned #GSList, but - * the contained values do not need to be unreffed. - */ -GSList *nm_connection_provider_get_best_connections (NMConnectionProvider *self, - guint max_requested, - const char *ctype1, - const char *ctype2, - NMConnectionFilterFunc func, - gpointer func_data); - -/** - * nm_connection_provider_get_connections: - * @self: the #NMConnectionProvider - * - * Returns: a #GSList of #NMConnection objects representing all known - * connections. Returned list is owned by the connection provider and must - * not be freed. - */ -const GSList *nm_connection_provider_get_connections (NMConnectionProvider *self); - -/** - * nm_connection_provider_add_connection: - * @self: the #NMConnectionProvider - * @connection: the connection to be added - * @save_to_disk: whether to store the connection on disk - * @error: returns any error if adding fails - * - * returns: a newly added #NMConnection. - */ -NMConnection *nm_connection_provider_add_connection (NMConnectionProvider *self, - NMConnection *connection, - gboolean save_to_disk, - GError **error); - -NMConnection *nm_connection_provider_get_connection_by_uuid (NMConnectionProvider *self, - const char *uuid); - -const GSList *nm_connection_provider_get_unmanaged_specs (NMConnectionProvider *self); - -#endif /* __NETWORKMANAGER_CONNECTION_PROVIDER_H__ */ diff --git a/src/nm-manager.c b/src/nm-manager.c index 9e782e4b80..f6a31e3c93 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -21,13 +21,14 @@ #include "nm-default.h" +#include "nm-manager.h" + #include <stdlib.h> #include <fcntl.h> #include <errno.h> #include <string.h> #include <unistd.h> -#include "nm-manager.h" #include "nm-bus-manager.h" #include "nm-vpn-manager.h" #include "nm-device.h" @@ -45,7 +46,6 @@ #include "nm-sleep-monitor.h" #include "nm-connectivity.h" #include "nm-policy.h" -#include "nm-connection-provider.h" #include "nm-session-monitor.h" #include "nm-activation-request.h" #include "nm-core-internal.h" @@ -407,7 +407,7 @@ find_ac_for_connection (NMManager *manager, NMConnection *connection) } /* Filter out connections that are already active. - * nm_settings_get_connections() returns sorted list. We need to preserve the + * nm_settings_get_connections_sorted() returns sorted list. We need to preserve the * order so that we didn't change auto-activation order (recent timestamps * are first). * Caller is responsible for freeing the returned list with g_slist_free(). @@ -416,7 +416,7 @@ GSList * nm_manager_get_activatable_connections (NMManager *manager) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); - GSList *all_connections = nm_settings_get_connections (priv->settings); + GSList *all_connections = nm_settings_get_connections_sorted (priv->settings); GSList *connections = NULL, *iter; NMSettingsConnection *connection; @@ -1131,7 +1131,7 @@ system_create_virtual_device (NMManager *self, NMConnection *connection) } /* Create backing resources if the device has any autoconnect connections */ - connections = nm_settings_get_connections (priv->settings); + connections = nm_settings_get_connections_sorted (priv->settings); for (iter = connections; iter; iter = g_slist_next (iter)) { NMConnection *candidate = iter->data; NMSettingConnection *s_con; @@ -1166,7 +1166,7 @@ retry_connections_for_parent_device (NMManager *self, NMDevice *device) g_return_if_fail (device); - connections = nm_settings_get_connections (priv->settings); + connections = nm_settings_get_connections_sorted (priv->settings); for (iter = connections; iter; iter = g_slist_next (iter)) { NMConnection *candidate = iter->data; gs_free_error GError *error = NULL; @@ -2603,7 +2603,7 @@ find_slaves (NMManager *manager, * even if a slave was already active, it might be deactivated during * master reactivation. */ - all_connections = nm_settings_get_connections (priv->settings); + all_connections = nm_settings_get_connections_sorted (priv->settings); for (iter = all_connections; iter; iter = iter->next) { NMSettingsConnection *master_connection = NULL; NMDevice *master_device = NULL; @@ -3598,7 +3598,7 @@ impl_manager_add_and_activate_connection (NMManager *self, if (!subject) goto error; - all_connections = nm_settings_get_connections (priv->settings); + all_connections = nm_settings_get_connections_sorted (priv->settings); if (vpn) { /* Try to fill the VPN's connection setting and name at least */ if (!nm_connection_get_setting_vpn (connection)) { @@ -4546,7 +4546,7 @@ nm_manager_start (NMManager *self, GError **error) * connection-added signals thus devices have to be created manually. */ _LOGD (LOGD_CORE, "creating virtual devices..."); - connections = nm_settings_get_connections (priv->settings); + connections = nm_settings_get_connections_sorted (priv->settings); for (iter = connections; iter; iter = iter->next) connection_changed (self, NM_CONNECTION (iter->data)); g_slist_free (connections); @@ -5174,16 +5174,12 @@ nm_manager_get (void) return singleton_instance; } -NMConnectionProvider * -nm_connection_provider_get (void) +NMSettings * +nm_settings_get (void) { - NMConnectionProvider *p; - g_return_val_if_fail (singleton_instance, NULL); - p = NM_CONNECTION_PROVIDER (NM_MANAGER_GET_PRIVATE (singleton_instance)->settings); - g_return_val_if_fail (p, NULL); - return p; + return NM_MANAGER_GET_PRIVATE (singleton_instance)->settings; } NMManager * diff --git a/src/nm-policy.c b/src/nm-policy.c index 7af311270d..0d39723344 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -862,7 +862,7 @@ reset_autoconnect_all (NMPolicy *self, NMDevice *device) } else _LOGD (LOGD_DEVICE, "re-enabling autoconnect for all connections"); - connections = nm_settings_get_connections (priv->settings); + connections = nm_settings_get_connections_sorted (priv->settings); for (iter = connections; iter; iter = g_slist_next (iter)) { if (!device || nm_device_check_connection_compatible (device, iter->data)) { nm_settings_connection_reset_autoconnect_retries (iter->data); @@ -880,7 +880,7 @@ reset_autoconnect_for_failed_secrets (NMPolicy *self) _LOGD (LOGD_DEVICE, "re-enabling autoconnect for all connections with failed secrets"); - connections = nm_settings_get_connections (priv->settings); + connections = nm_settings_get_connections_sorted (priv->settings); for (iter = connections; iter; iter = g_slist_next (iter)) { NMSettingsConnection *connection = NM_SETTINGS_CONNECTION (iter->data); @@ -908,7 +908,7 @@ block_autoconnect_for_device (NMPolicy *self, NMDevice *device) if (!nm_device_is_software (device)) return; - connections = nm_settings_get_connections (priv->settings); + connections = nm_settings_get_connections_sorted (priv->settings); for (iter = connections; iter; iter = g_slist_next (iter)) { if (nm_device_check_connection_compatible (device, iter->data)) { nm_settings_connection_set_autoconnect_blocked_reason (NM_SETTINGS_CONNECTION (iter->data), @@ -990,7 +990,7 @@ reset_connections_retries (gpointer user_data) min_stamp = 0; now = nm_utils_get_monotonic_timestamp_s (); - connections = nm_settings_get_connections (priv->settings); + connections = nm_settings_get_connections_sorted (priv->settings); for (iter = connections; iter; iter = g_slist_next (iter)) { NMSettingsConnection *connection = NM_SETTINGS_CONNECTION (iter->data); @@ -1043,7 +1043,7 @@ activate_slave_connections (NMPolicy *self, NMDevice *device) } } - connections = nm_settings_get_connections (priv->settings); + connections = nm_settings_get_connections_sorted (priv->settings); for (iter = connections; iter; iter = g_slist_next (iter)) { NMConnection *slave; NMSettingConnection *s_slave_con; diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index 7c42213585..fab5383c79 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -25,6 +25,8 @@ #include "nm-default.h" +#include "nm-settings.h" + #include <unistd.h> #include <sys/stat.h> #include <errno.h> @@ -59,7 +61,6 @@ #include "nm-core-internal.h" #include "nm-device-ethernet.h" -#include "nm-settings.h" #include "nm-settings-connection.h" #include "nm-settings-plugin.h" #include "nm-bus-manager.h" @@ -68,7 +69,6 @@ #include "nm-session-monitor.h" #include "plugins/keyfile/plugin.h" #include "nm-agent-manager.h" -#include "nm-connection-provider.h" #include "nm-config.h" #include "nm-audit-manager.h" #include "NetworkManagerUtils.h" @@ -132,15 +132,11 @@ static void claim_connection (NMSettings *self, static void unmanaged_specs_changed (NMSettingsPlugin *config, gpointer user_data); static void unrecognized_specs_changed (NMSettingsPlugin *config, gpointer user_data); -static void connection_provider_iface_init (NMConnectionProviderInterface *cp_iface); - static void connection_ready_changed (NMSettingsConnection *conn, GParamSpec *pspec, gpointer user_data); -G_DEFINE_TYPE_EXTENDED (NMSettings, nm_settings, NM_TYPE_EXPORTED_OBJECT, 0, - G_IMPLEMENT_INTERFACE (NM_TYPE_CONNECTION_PROVIDER, connection_provider_iface_init)) - +G_DEFINE_TYPE (NMSettings, nm_settings, NM_TYPE_EXPORTED_OBJECT); typedef struct { NMAgentManager *agent_mgr; @@ -152,9 +148,9 @@ typedef struct { GSList *plugins; gboolean connections_loaded; GHashTable *connections; + NMSettingsConnection **connections_cached_list; GSList *unmanaged_specs; GSList *unrecognized_specs; - GSList *get_connections_cache; gboolean started; gboolean startup_complete; @@ -409,13 +405,60 @@ connection_sort (gconstpointer pa, gconstpointer pb) return 1; } +/** + * nm_settings_get_connections: + * @self: the #NMSettings + * @out_len: (out): (allow-none): returns the number of returned + * connections. + * + * Returns: (transfer-none): a list of NMSettingsConnections. The list is + * unsorted and NULL terminated. The result is never %NULL, in case of no + * connections, it returns an empty list. + * The returned list is cached internally, only valid until the next + * NMSettings operation. + */ +NMSettingsConnection *const* +nm_settings_get_connections (NMSettings *self, guint *out_len) +{ + GHashTableIter iter; + NMSettingsPrivate *priv; + guint l, i; + NMSettingsConnection **v; + NMSettingsConnection *con; + + g_return_val_if_fail (NM_IS_SETTINGS (self), NULL); + + priv = NM_SETTINGS_GET_PRIVATE (self); + + if (priv->connections_cached_list) { + NM_SET_OUT (out_len, g_hash_table_size (priv->connections)); + return priv->connections_cached_list; + } + + l = g_hash_table_size (priv->connections); + + v = g_new (NMSettingsConnection *, l + 1); + + i = 0; + g_hash_table_iter_init (&iter, priv->connections); + while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &con)) + v[i++] = con; + v[i] = NULL; + + nm_assert (i == l); + + NM_SET_OUT (out_len, l); + priv->connections_cached_list = v; + return v; +} + /* Returns a list of NMSettingsConnections. * The list is sorted in the order suitable for auto-connecting, i.e. * first go connections with autoconnect=yes and most recent timestamp. * Caller must free the list with g_slist_free(). */ GSList * -nm_settings_get_connections (NMSettings *self) +nm_settings_get_connections_sorted (NMSettings *self) { GHashTableIter iter; gpointer data = NULL; @@ -894,7 +937,6 @@ connection_updated (NMSettingsConnection *connection, gboolean by_user, gpointer 0, connection, by_user); - g_signal_emit_by_name (NM_SETTINGS (user_data), NM_CP_SIGNAL_CONNECTION_UPDATED, connection); } static void @@ -934,12 +976,12 @@ connection_removed (NMSettingsConnection *connection, gpointer user_data) /* Forget about the connection internally */ g_hash_table_remove (priv->connections, (gpointer) cpath); + g_clear_pointer (&priv->connections_cached_list, g_free); /* Notify D-Bus */ g_signal_emit (self, signals[CONNECTION_REMOVED], 0, connection); /* Re-emit for listeners like NMPolicy */ - g_signal_emit_by_name (self, NM_CP_SIGNAL_CONNECTION_REMOVED, connection); _notify (self, PROP_CONNECTIONS); if (nm_exported_object_is_exported (NM_EXPORTED_OBJECT (connection))) nm_exported_object_unexport (NM_EXPORTED_OBJECT (connection)); @@ -1078,6 +1120,7 @@ claim_connection (NMSettings *self, NMSettingsConnection *connection) g_hash_table_insert (priv->connections, (gpointer) nm_connection_get_path (NM_CONNECTION (connection)), g_object_ref (connection)); + g_clear_pointer (&priv->connections_cached_list, g_free); nm_utils_log_connection_diff (NM_CONNECTION (connection), NULL, LOGL_DEBUG, LOGD_CORE, "new connection", "++ "); @@ -1087,7 +1130,6 @@ claim_connection (NMSettings *self, NMSettingsConnection *connection) if (priv->connections_loaded) { /* Internal added signal */ g_signal_emit (self, signals[CONNECTION_ADDED], 0, connection); - g_signal_emit_by_name (self, NM_CP_SIGNAL_CONNECTION_ADDED, connection); _notify (self, PROP_CONNECTIONS); /* Exported D-Bus signal */ @@ -1163,16 +1205,6 @@ nm_settings_add_connection (NMSettings *self, return NULL; } -static NMConnection * -_nm_connection_provider_add_connection (NMConnectionProvider *provider, - NMConnection *connection, - gboolean save_to_disk, - GError **error) -{ - g_assert (NM_IS_CONNECTION_PROVIDER (provider) && NM_IS_SETTINGS (provider)); - return NM_CONNECTION (nm_settings_add_connection (NM_SETTINGS (provider), connection, save_to_disk, error)); -} - static gboolean secrets_filter_cb (NMSetting *setting, const char *secret, @@ -2080,22 +2112,41 @@ nm_settings_sort_connections (gconstpointer a, gconstpointer b) return 0; } -static GSList * -get_best_connections (NMConnectionProvider *provider, - guint max_requested, - const char *ctype1, - const char *ctype2, - NMConnectionFilterFunc func, - gpointer func_data) +/** + * nm_settings_get_best_connections: + * @self: the #NMSetting + * @max_requested: if non-zero, the maximum number of connections to return + * @ctype1: an #NMSetting base type (eg NM_SETTING_WIRELESS_SETTING_NAME) to + * filter connections against + * @ctype2: a second #NMSetting base type (eg NM_SETTING_WIRELESS_SETTING_NAME) + * to filter connections against + * @func: caller-supplied function for filtering connections + * @func_data: caller-supplied data passed to @func + * + * Returns: a #GSList of #NMConnection objects in sorted order representing the + * "best" or highest-priority connections filtered by @ctype1 and/or @ctype2, + * and/or @func. Caller is responsible for freeing the returned #GSList, but + * the contained values do not need to be unreffed. + */ +GSList * +nm_settings_get_best_connections (NMSettings *self, + guint max_requested, + const char *ctype1, + const char *ctype2, + NMConnectionFilterFunc func, + gpointer func_data) { - NMSettings *self = NM_SETTINGS (provider); - NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); + NMSettingsPrivate *priv; GSList *sorted = NULL; GHashTableIter iter; NMSettingsConnection *connection; guint added = 0; guint64 oldest = 0; + g_return_val_if_fail (NM_IS_SETTINGS (self), NULL); + + priv = NM_SETTINGS_GET_PRIVATE (self); + g_hash_table_iter_init (&iter, priv->connections); while (g_hash_table_iter_next (&iter, NULL, (gpointer) &connection)) { guint64 cur_ts = 0; @@ -2104,7 +2155,7 @@ get_best_connections (NMConnectionProvider *provider, continue; if (ctype2 && !nm_connection_is_type (NM_CONNECTION (connection), ctype2)) continue; - if (func && !func (provider, NM_CONNECTION (connection), func_data)) + if (func && !func (self, NM_CONNECTION (connection), func_data)) continue; /* Don't bother with a connection that's older than the oldest one in the list */ @@ -2130,33 +2181,6 @@ get_best_connections (NMConnectionProvider *provider, return g_slist_reverse (sorted); } -static const GSList * -get_connections (NMConnectionProvider *provider) -{ - GSList *list = NULL; - NMSettings *self = NM_SETTINGS (provider); - NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); - - list = _nm_utils_hash_values_to_slist (priv->connections); - - /* Cache the list every call so we can keep it 'const' for callers */ - g_slist_free (priv->get_connections_cache); - priv->get_connections_cache = list; - return list; -} - -static NMConnection * -cp_get_connection_by_uuid (NMConnectionProvider *provider, const char *uuid) -{ - return NM_CONNECTION (nm_settings_get_connection_by_uuid (NM_SETTINGS (provider), uuid)); -} - -static const GSList * -cp_get_unmanaged_specs (NMConnectionProvider *provider) -{ - return nm_settings_get_unmanaged_specs (NM_SETTINGS (provider)); -} - /***************************************************************/ gboolean @@ -2318,16 +2342,6 @@ nm_settings_start (NMSettings *self, GError **error) } static void -connection_provider_iface_init (NMConnectionProviderInterface *cp_iface) -{ - cp_iface->get_best_connections = get_best_connections; - cp_iface->get_connections = get_connections; - cp_iface->add_connection = _nm_connection_provider_add_connection; - cp_iface->get_connection_by_uuid = cp_get_connection_by_uuid; - cp_iface->get_unmanaged_specs = cp_get_unmanaged_specs; -} - -static void nm_settings_init (NMSettings *self) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); @@ -2391,7 +2405,7 @@ finalize (GObject *object) NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); g_hash_table_destroy (priv->connections); - g_slist_free (priv->get_connections_cache); + g_clear_pointer (&priv->connections_cached_list, g_free); g_slist_free_full (priv->unmanaged_specs, g_free); g_slist_free_full (priv->unrecognized_specs, g_free); diff --git a/src/settings/nm-settings.h b/src/settings/nm-settings.h index 5d41e5bc92..a0be42eef3 100644 --- a/src/settings/nm-settings.h +++ b/src/settings/nm-settings.h @@ -49,6 +49,18 @@ #define NM_SETTINGS_SIGNAL_CONNECTION_VISIBILITY_CHANGED "connection-visibility-changed" #define NM_SETTINGS_SIGNAL_AGENT_REGISTERED "agent-registered" +/** + * NMConnectionFilterFunc: + * @settings: The #NMSettings requesting the filtering + * @connection: the connection to be filtered + * @func_data: the caller-provided data pointer + * + * Returns: %TRUE to allow the connection, %FALSE to ignore it + */ +typedef gboolean (*NMConnectionFilterFunc) (NMSettings *settings, + NMConnection *connection, + gpointer func_data); + struct _NMSettings { NMExportedObject parent_instance; }; @@ -61,6 +73,9 @@ typedef void (*NMSettingsSetHostnameCb) (const char *name, gboolean result, gpoi GType nm_settings_get_type (void); +NMSettings *nm_settings_get (void); +#define NM_SETTINGS_GET (nm_settings_get ()) + NMSettings *nm_settings_new (void); gboolean nm_settings_start (NMSettings *self, GError **error); @@ -86,10 +101,16 @@ void nm_settings_add_connection_dbus (NMSettings *self, NMSettingsAddCallback callback, gpointer user_data); -/* Returns a list of NMSettingsConnections. Caller must free the list with - * g_slist_free(). - */ -GSList *nm_settings_get_connections (NMSettings *settings); +NMSettingsConnection *const* nm_settings_get_connections (NMSettings *settings, guint *out_len); + +GSList *nm_settings_get_connections_sorted (NMSettings *settings); + +GSList *nm_settings_get_best_connections (NMSettings *self, + guint max_requested, + const char *ctype1, + const char *ctype2, + NMConnectionFilterFunc func, + gpointer func_data); NMSettingsConnection *nm_settings_add_connection (NMSettings *settings, NMConnection *connection, diff --git a/src/tests/test-wired-defname.c b/src/tests/test-wired-defname.c index bed1bb5ad1..3ae3a19d95 100644 --- a/src/tests/test-wired-defname.c +++ b/src/tests/test-wired-defname.c @@ -41,12 +41,28 @@ _new_connection (const char *id) /*******************************************/ +static char * +_get_default_wired_name (GSList *list) +{ + gs_free NMConnection **v = NULL; + guint l, i; + + l = g_slist_length (list); + v = g_new0 (NMConnection *, l + 1); + for (i = 0; list; list = list->next, i++) + v[i] = NM_CONNECTION (list->data); + g_assert (i == l); + return nm_device_ethernet_utils_get_default_wired_name (v); +} + +/*******************************************/ + static void test_defname_no_connections (void) { gs_free char *name = NULL; - name = nm_device_ethernet_utils_get_default_wired_name (NULL); + name = _get_default_wired_name (NULL); g_assert_cmpstr (name, ==, "Wired connection 1"); } @@ -62,7 +78,7 @@ test_defname_no_conflict (void) list = g_slist_append (list, _new_connection ("work wifi")); list = g_slist_append (list, _new_connection ("random gsm connection")); - name = nm_device_ethernet_utils_get_default_wired_name (list); + name = _get_default_wired_name (list); g_assert_cmpstr (name, ==, "Wired connection 1"); g_slist_free_full (list, g_object_unref); @@ -80,7 +96,7 @@ test_defname_conflict (void) list = g_slist_append (list, _new_connection ("Wired connection 1")); list = g_slist_append (list, _new_connection ("random gsm connection")); - name = nm_device_ethernet_utils_get_default_wired_name (list); + name = _get_default_wired_name (list); g_assert_cmpstr (name, ==, "Wired connection 2"); g_slist_free_full (list, g_object_unref); @@ -102,7 +118,7 @@ test_defname_multiple_conflicts (void) list = g_slist_append (list, _new_connection ("work wifi")); list = g_slist_append (list, _new_connection ("a vpn")); - name = nm_device_ethernet_utils_get_default_wired_name (list); + name = _get_default_wired_name (list); g_assert_cmpstr (name, ==, "Wired connection 4"); g_slist_free_full (list, g_object_unref); |