mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-04 20:00:32 +01:00
system-settings: clean up settings service classes
Make NMSettingsService implement most of the NMSettingsInterface API to make subclasses simpler, and consolidate exporting of NMExportedConnection subclasses in NMSettingsService instead of in 3 places. Make NMSysconfigSettings a subclass of NMSettingsService and save a ton of code.
This commit is contained in:
parent
f64354d0cc
commit
890866bef9
11 changed files with 162 additions and 283 deletions
|
|
@ -6,19 +6,6 @@
|
|||
Implemented by the system settings service to provide additional settings to NetworkManager.
|
||||
</tp:docstring>
|
||||
|
||||
<method name="AddConnection">
|
||||
<tp:docstring>
|
||||
DEPRECATED. Adds new connection.
|
||||
</tp:docstring>
|
||||
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_add_connection"/>
|
||||
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
|
||||
<arg name="connection" type="a{sa{sv}}" direction="in">
|
||||
<tp:docstring>
|
||||
Connection properties.
|
||||
</tp:docstring>
|
||||
</arg>
|
||||
</method>
|
||||
|
||||
<method name="SaveHostname">
|
||||
<tp:docstring>
|
||||
Save the hostname to persistent configuration.
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ global:
|
|||
nm_settings_interface_get_type;
|
||||
nm_settings_interface_list_connections;
|
||||
nm_settings_service_export;
|
||||
nm_settings_service_export_connection;
|
||||
nm_settings_service_get_connection_by_path;
|
||||
nm_settings_service_get_type;
|
||||
nm_settings_system_interface_get_type;
|
||||
|
|
|
|||
|
|
@ -51,41 +51,12 @@ G_DEFINE_TYPE (NMExportedConnection, nm_exported_connection, NM_TYPE_CONNECTION)
|
|||
NMExportedConnectionPrivate))
|
||||
|
||||
typedef struct {
|
||||
DBusGConnection *bus;
|
||||
gboolean disposed;
|
||||
gboolean foo;
|
||||
} NMExportedConnectionPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_BUS,
|
||||
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
|
||||
/**************************************************************/
|
||||
|
||||
void
|
||||
nm_exported_connection_export (NMExportedConnection *self)
|
||||
{
|
||||
NMExportedConnectionPrivate *priv;
|
||||
static guint32 ec_counter = 0;
|
||||
char *path;
|
||||
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (NM_IS_EXPORTED_CONNECTION (self));
|
||||
|
||||
priv = NM_EXPORTED_CONNECTION_GET_PRIVATE (self);
|
||||
|
||||
/* Don't allow exporting twice */
|
||||
g_return_if_fail (nm_connection_get_path (NM_CONNECTION (self)) == NULL);
|
||||
|
||||
path = g_strdup_printf ("%s/%u", NM_DBUS_PATH_SETTINGS, ec_counter++);
|
||||
nm_connection_set_path (NM_CONNECTION (self), path);
|
||||
dbus_g_connection_register_g_object (priv->bus, path, G_OBJECT (self));
|
||||
g_free (path);
|
||||
}
|
||||
|
||||
static GHashTable *
|
||||
real_get_settings (NMExportedConnection *self, GError **error)
|
||||
{
|
||||
|
|
@ -183,124 +154,35 @@ impl_exported_connection_get_secrets (NMExportedConnection *self,
|
|||
|
||||
/**
|
||||
* nm_exported_connection_new:
|
||||
* @bus: a valid and connected D-Bus connection
|
||||
* @scope: the Connection scope (either user or system)
|
||||
* @path: the D-Bus path of the connection as exported by the settings service
|
||||
* indicated by @scope
|
||||
*
|
||||
* Creates a new object representing the remote connection.
|
||||
*
|
||||
* Returns: the new exported connection object on success, or %NULL on failure
|
||||
**/
|
||||
NMExportedConnection *
|
||||
nm_exported_connection_new (DBusGConnection *bus,
|
||||
NMConnectionScope scope)
|
||||
nm_exported_connection_new (NMConnectionScope scope)
|
||||
{
|
||||
g_return_val_if_fail (bus != NULL, NULL);
|
||||
g_return_val_if_fail (scope != NM_CONNECTION_SCOPE_UNKNOWN, NULL);
|
||||
|
||||
return (NMExportedConnection *) g_object_new (NM_TYPE_EXPORTED_CONNECTION,
|
||||
NM_EXPORTED_CONNECTION_BUS, bus,
|
||||
NM_CONNECTION_SCOPE, scope,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static GObject *
|
||||
constructor (GType type,
|
||||
guint n_construct_params,
|
||||
GObjectConstructParam *construct_params)
|
||||
{
|
||||
GObject *object;
|
||||
NMExportedConnectionPrivate *priv;
|
||||
|
||||
object = G_OBJECT_CLASS (nm_exported_connection_parent_class)->constructor (type, n_construct_params, construct_params);
|
||||
if (!object)
|
||||
return NULL;
|
||||
|
||||
priv = NM_EXPORTED_CONNECTION_GET_PRIVATE (object);
|
||||
g_assert (priv->bus);
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
static void
|
||||
nm_exported_connection_init (NMExportedConnection *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
set_property (GObject *object, guint prop_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NMExportedConnectionPrivate *priv = NM_EXPORTED_CONNECTION_GET_PRIVATE (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_BUS:
|
||||
/* Construct only */
|
||||
priv->bus = dbus_g_connection_ref ((DBusGConnection *) g_value_get_boxed (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)
|
||||
{
|
||||
NMExportedConnectionPrivate *priv = NM_EXPORTED_CONNECTION_GET_PRIVATE (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_BUS:
|
||||
g_value_set_boxed (value, priv->bus);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
dispose (GObject *object)
|
||||
{
|
||||
NMExportedConnectionPrivate *priv = NM_EXPORTED_CONNECTION_GET_PRIVATE (object);
|
||||
|
||||
if (!priv->disposed) {
|
||||
priv->disposed = TRUE;
|
||||
dbus_g_connection_unref (priv->bus);
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (nm_exported_connection_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
nm_exported_connection_class_init (NMExportedConnectionClass *class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||
|
||||
g_type_class_add_private (class, sizeof (NMExportedConnectionPrivate));
|
||||
|
||||
/* Virtual methods */
|
||||
object_class->dispose = dispose;
|
||||
object_class->constructor = constructor;
|
||||
object_class->get_property = get_property;
|
||||
object_class->set_property = set_property;
|
||||
|
||||
class->get_settings = real_get_settings;
|
||||
|
||||
/**
|
||||
* NMExportedConnection:bus:
|
||||
*
|
||||
* The %DBusGConnection which this object is exported on
|
||||
**/
|
||||
g_object_class_install_property (object_class, PROP_BUS,
|
||||
g_param_spec_boxed (NM_EXPORTED_CONNECTION_BUS,
|
||||
"Bus",
|
||||
"Bus",
|
||||
DBUS_TYPE_G_CONNECTION,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (class),
|
||||
&dbus_glib_nm_exported_connection_object_info);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,8 +33,6 @@ G_BEGIN_DECLS
|
|||
#define NM_IS_EXPORTED_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_EXPORTED_CONNECTION))
|
||||
#define NM_EXPORTED_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_EXPORTED_CONNECTION, NMExportedConnectionClass))
|
||||
|
||||
#define NM_EXPORTED_CONNECTION_BUS "bus"
|
||||
|
||||
typedef struct {
|
||||
NMConnection parent;
|
||||
} NMExportedConnection;
|
||||
|
|
@ -61,10 +59,7 @@ typedef struct {
|
|||
|
||||
GType nm_exported_connection_get_type (void);
|
||||
|
||||
NMExportedConnection *nm_exported_connection_new (DBusGConnection *bus,
|
||||
NMConnectionScope scope);
|
||||
|
||||
void nm_exported_connection_export (NMExportedConnection *self);
|
||||
NMExportedConnection *nm_exported_connection_new (NMConnectionScope scope);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
* (C) Copyright 2008 - 2009 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <NetworkManager.h>
|
||||
#include <dbus/dbus-glib-lowlevel.h>
|
||||
|
||||
|
|
@ -115,11 +116,18 @@ impl_settings_list_connections (NMSettingsService *self,
|
|||
static NMSettingsConnectionInterface *
|
||||
get_connection_by_path (NMSettingsInterface *settings, const char *path)
|
||||
{
|
||||
NMExportedConnection *connection;
|
||||
NMExportedConnection *connection = NULL;
|
||||
GSList *list = NULL, *iter;
|
||||
|
||||
list = list_connections (settings);
|
||||
for (iter = list; iter; iter = g_slist_next (iter)) {
|
||||
if (!strcmp (nm_connection_get_path (NM_CONNECTION (iter->data)), path)) {
|
||||
connection = NM_EXPORTED_CONNECTION (iter->data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_slist_free (list);
|
||||
|
||||
/* Must always be implemented */
|
||||
g_assert (NM_SETTINGS_SERVICE_GET_CLASS (settings)->get_connection_by_path);
|
||||
connection = NM_SETTINGS_SERVICE_GET_CLASS (settings)->get_connection_by_path (NM_SETTINGS_SERVICE (settings), path);
|
||||
return (NMSettingsConnectionInterface *) connection;
|
||||
}
|
||||
|
||||
|
|
@ -133,6 +141,48 @@ nm_settings_service_get_connection_by_path (NMSettingsService *self,
|
|||
return (NMExportedConnection *) get_connection_by_path (NM_SETTINGS_INTERFACE (self), path);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
add_connection (NMSettingsInterface *settings,
|
||||
NMSettingsConnectionInterface *connection,
|
||||
NMSettingsAddConnectionFunc callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMSettingsService *self = NM_SETTINGS_SERVICE (settings);
|
||||
GError *error = NULL;
|
||||
gboolean success = FALSE;
|
||||
|
||||
if (NM_SETTINGS_SERVICE_GET_CLASS (self)->add_connection) {
|
||||
NM_SETTINGS_SERVICE_GET_CLASS (self)->add_connection (NM_SETTINGS_SERVICE (self),
|
||||
connection,
|
||||
NULL,
|
||||
callback,
|
||||
user_data);
|
||||
success = TRUE;
|
||||
} else {
|
||||
error = g_error_new (NM_SETTINGS_INTERFACE_ERROR,
|
||||
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
|
||||
"%s: %s:%d add_connection() not implemented",
|
||||
__func__, __FILE__, __LINE__);
|
||||
callback (settings, error, user_data);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static void
|
||||
dbus_add_connection_cb (NMSettingsInterface *settings,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
DBusGMethodInvocation *context = user_data;
|
||||
|
||||
if (error)
|
||||
dbus_g_method_return_error (context, error);
|
||||
else
|
||||
dbus_g_method_return (context);
|
||||
}
|
||||
|
||||
static void
|
||||
impl_settings_add_connection (NMSettingsService *self,
|
||||
GHashTable *settings,
|
||||
|
|
@ -149,11 +199,14 @@ impl_settings_add_connection (NMSettingsService *self,
|
|||
g_error_free (error);
|
||||
return;
|
||||
}
|
||||
g_object_unref (tmp);
|
||||
|
||||
if (NM_SETTINGS_SERVICE_GET_CLASS (self)->add_connection)
|
||||
NM_SETTINGS_SERVICE_GET_CLASS (self)->add_connection (self, settings, context);
|
||||
else {
|
||||
if (NM_SETTINGS_SERVICE_GET_CLASS (self)->add_connection) {
|
||||
NM_SETTINGS_SERVICE_GET_CLASS (self)->add_connection (NM_SETTINGS_SERVICE (self),
|
||||
NM_SETTINGS_CONNECTION_INTERFACE (tmp),
|
||||
context,
|
||||
dbus_add_connection_cb,
|
||||
context);
|
||||
} else {
|
||||
error = g_error_new (NM_SETTINGS_INTERFACE_ERROR,
|
||||
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
|
||||
"%s: %s:%d add_connection() not implemented",
|
||||
|
|
@ -161,6 +214,30 @@ impl_settings_add_connection (NMSettingsService *self,
|
|||
dbus_g_method_return_error (context, error);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
g_object_unref (tmp);
|
||||
}
|
||||
|
||||
void
|
||||
nm_settings_service_export_connection (NMSettingsService *self,
|
||||
NMSettingsConnectionInterface *connection)
|
||||
{
|
||||
NMSettingsServicePrivate *priv = NM_SETTINGS_SERVICE_GET_PRIVATE (self);
|
||||
static guint32 ec_counter = 0;
|
||||
char *path;
|
||||
|
||||
g_return_if_fail (connection != NULL);
|
||||
g_return_if_fail (NM_IS_SETTINGS_CONNECTION_INTERFACE (connection));
|
||||
|
||||
/* Don't allow exporting twice */
|
||||
g_return_if_fail (nm_connection_get_path (NM_CONNECTION (connection)) == NULL);
|
||||
|
||||
path = g_strdup_printf ("%s/%u", NM_DBUS_PATH_SETTINGS, ec_counter++);
|
||||
nm_connection_set_path (NM_CONNECTION (connection), path);
|
||||
nm_connection_set_scope (NM_CONNECTION (connection), priv->scope);
|
||||
|
||||
dbus_g_connection_register_g_object (priv->bus, path, G_OBJECT (connection));
|
||||
g_free (path);
|
||||
}
|
||||
|
||||
/**************************************************************/
|
||||
|
|
@ -171,6 +248,10 @@ settings_interface_init (NMSettingsInterface *iface)
|
|||
/* interface implementation */
|
||||
iface->list_connections = list_connections;
|
||||
iface->get_connection_by_path = get_connection_by_path;
|
||||
iface->add_connection = add_connection;
|
||||
|
||||
dbus_g_object_type_install_info (G_TYPE_FROM_INTERFACE (iface),
|
||||
&dbus_glib_nm_settings_object_info);
|
||||
}
|
||||
|
||||
static GObject *
|
||||
|
|
@ -181,8 +262,10 @@ constructor (GType type,
|
|||
GObject *object;
|
||||
|
||||
object = G_OBJECT_CLASS (nm_settings_service_parent_class)->constructor (type, n_construct_params, construct_params);
|
||||
if (object)
|
||||
if (object) {
|
||||
g_assert (NM_SETTINGS_SERVICE_GET_PRIVATE (object)->scope != NM_CONNECTION_SCOPE_UNKNOWN);
|
||||
g_assert (NM_SETTINGS_SERVICE_GET_PRIVATE (object)->bus != NULL);
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
|
|
@ -196,11 +279,14 @@ set_property (GObject *object, guint prop_id,
|
|||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NMSettingsServicePrivate *priv = NM_SETTINGS_SERVICE_GET_PRIVATE (object);
|
||||
DBusGConnection *bus;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_BUS:
|
||||
/* Construct only */
|
||||
priv->bus = dbus_g_connection_ref ((DBusGConnection *) g_value_get_boxed (value));
|
||||
bus = g_value_get_boxed (value);
|
||||
if (bus)
|
||||
priv->bus = dbus_g_connection_ref (bus);
|
||||
break;
|
||||
case PROP_SCOPE:
|
||||
/* Construct only */
|
||||
|
|
@ -277,9 +363,9 @@ nm_settings_service_class_init (NMSettingsServiceClass *class)
|
|||
g_param_spec_uint (NM_SETTINGS_SERVICE_SCOPE,
|
||||
"Scope",
|
||||
"Scope",
|
||||
NM_CONNECTION_SCOPE_USER,
|
||||
NM_CONNECTION_SCOPE_SYSTEM,
|
||||
NM_CONNECTION_SCOPE_USER,
|
||||
NM_CONNECTION_SCOPE_USER,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (class),
|
||||
|
|
|
|||
|
|
@ -51,12 +51,11 @@ typedef struct {
|
|||
*/
|
||||
GSList * (*list_connections) (NMSettingsService *self);
|
||||
|
||||
NMExportedConnection * (*get_connection_by_path) (NMSettingsService *self,
|
||||
const char *path);
|
||||
|
||||
void (*add_connection) (NMSettingsService *self,
|
||||
GHashTable *settings,
|
||||
DBusGMethodInvocation *context);
|
||||
NMSettingsConnectionInterface *connection,
|
||||
DBusGMethodInvocation *context, /* Only present for D-Bus calls */
|
||||
NMSettingsAddConnectionFunc callback,
|
||||
gpointer user_data);
|
||||
} NMSettingsServiceClass;
|
||||
|
||||
GType nm_settings_service_get_type (void);
|
||||
|
|
@ -66,6 +65,9 @@ NMExportedConnection *nm_settings_service_get_connection_by_path (NMSettingsServ
|
|||
|
||||
void nm_settings_service_export (NMSettingsService *self);
|
||||
|
||||
void nm_settings_service_export_connection (NMSettingsService *self,
|
||||
NMSettingsConnectionInterface *exported);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_SETTINGS_SERVICE_H */
|
||||
|
|
|
|||
|
|
@ -2508,6 +2508,7 @@ nm_manager_get (const char *config_file, const char *plugins, GError **error)
|
|||
{
|
||||
static NMManager *singleton = NULL;
|
||||
NMManagerPrivate *priv;
|
||||
DBusGConnection *bus;
|
||||
|
||||
if (singleton)
|
||||
return g_object_ref (singleton);
|
||||
|
|
@ -2517,11 +2518,15 @@ nm_manager_get (const char *config_file, const char *plugins, GError **error)
|
|||
|
||||
priv = NM_MANAGER_GET_PRIVATE (singleton);
|
||||
|
||||
priv->sys_settings = nm_sysconfig_settings_new (config_file, plugins, error);
|
||||
bus = nm_dbus_manager_get_connection (priv->dbus_mgr);
|
||||
g_assert (bus);
|
||||
|
||||
priv->sys_settings = nm_sysconfig_settings_new (config_file, plugins, bus, error);
|
||||
if (!priv->sys_settings) {
|
||||
g_object_unref (singleton);
|
||||
return NULL;
|
||||
}
|
||||
nm_settings_service_export (NM_SETTINGS_SERVICE (priv->sys_settings));
|
||||
|
||||
priv->config_file = g_strdup (config_file);
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ G_DEFINE_TYPE_EXTENDED (NMSysconfigConnection, nm_sysconfig_connection, NM_TYPE_
|
|||
NMSysconfigConnectionPrivate))
|
||||
|
||||
typedef struct {
|
||||
DBusGConnection *bus;
|
||||
PolkitAuthority *authority;
|
||||
} NMSysconfigConnectionPrivate;
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@
|
|||
#include "nm-dbus-glib-types.h"
|
||||
#include "nm-sysconfig-settings.h"
|
||||
#include "nm-sysconfig-connection.h"
|
||||
#include "nm-dbus-manager.h"
|
||||
#include "nm-polkit-helpers.h"
|
||||
#include "nm-system-config-error.h"
|
||||
#include "nm-utils.h"
|
||||
|
|
@ -67,25 +66,15 @@ static void claim_connection (NMSysconfigSettings *self,
|
|||
NMSettingsConnectionInterface *connection,
|
||||
gboolean do_export);
|
||||
|
||||
static gboolean impl_settings_list_connections (NMSysconfigSettings *self,
|
||||
GPtrArray **connections,
|
||||
GError **error);
|
||||
|
||||
static void impl_settings_add_connection (NMSysconfigSettings *self,
|
||||
GHashTable *settings,
|
||||
DBusGMethodInvocation *context);
|
||||
|
||||
static void impl_settings_save_hostname (NMSysconfigSettings *self,
|
||||
const char *hostname,
|
||||
DBusGMethodInvocation *context);
|
||||
|
||||
#include "nm-settings-glue.h"
|
||||
#include "nm-settings-system-glue.h"
|
||||
|
||||
static void unmanaged_specs_changed (NMSystemConfigInterface *config, gpointer user_data);
|
||||
|
||||
typedef struct {
|
||||
NMDBusManager *dbus_mgr;
|
||||
PolkitAuthority *authority;
|
||||
char *config_file;
|
||||
|
||||
|
|
@ -96,13 +85,9 @@ typedef struct {
|
|||
char *orig_hostname;
|
||||
} NMSysconfigSettingsPrivate;
|
||||
|
||||
static void settings_interface_init (NMSettingsInterface *klass);
|
||||
|
||||
static void settings_system_interface_init (NMSettingsSystemInterface *klass);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (NMSysconfigSettings, nm_sysconfig_settings, G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (NM_TYPE_SETTINGS_INTERFACE,
|
||||
settings_interface_init)
|
||||
G_DEFINE_TYPE_WITH_CODE (NMSysconfigSettings, nm_sysconfig_settings, NM_TYPE_SETTINGS_SERVICE,
|
||||
G_IMPLEMENT_INTERFACE (NM_TYPE_SETTINGS_SYSTEM_INTERFACE,
|
||||
settings_system_interface_init))
|
||||
|
||||
|
|
@ -157,50 +142,20 @@ load_connections (NMSysconfigSettings *self)
|
|||
unmanaged_specs_changed (NULL, self);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
impl_settings_list_connections (NMSysconfigSettings *self,
|
||||
GPtrArray **connections,
|
||||
GError **error)
|
||||
static GSList *
|
||||
list_connections (NMSettingsService *settings)
|
||||
{
|
||||
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
||||
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (settings);
|
||||
GHashTableIter iter;
|
||||
gpointer key;
|
||||
GSList *list = NULL;
|
||||
|
||||
load_connections (self);
|
||||
|
||||
*connections = g_ptr_array_sized_new (g_hash_table_size (priv->connections));
|
||||
load_connections (NM_SYSCONFIG_SETTINGS (settings));
|
||||
|
||||
g_hash_table_iter_init (&iter, priv->connections);
|
||||
while (g_hash_table_iter_next (&iter, &key, NULL)) {
|
||||
NMSettingsConnectionInterface *connection = key;
|
||||
char *path = NULL;
|
||||
|
||||
g_object_get (G_OBJECT (connection), NM_SETTINGS_CONNECTION_INTERFACE_PATH, &path, NULL);
|
||||
g_assert (path);
|
||||
g_ptr_array_add (*connections, path);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static NMSettingsConnectionInterface *
|
||||
get_connection_by_path (NMSettingsInterface *self,
|
||||
const char *path)
|
||||
{
|
||||
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
||||
GHashTableIter iter;
|
||||
gpointer key;
|
||||
|
||||
g_hash_table_iter_init (&iter, priv->connections);
|
||||
while (g_hash_table_iter_next (&iter, &key, NULL)) {
|
||||
NMConnection *candidate = NM_CONNECTION (key);
|
||||
const char *candidate_path;
|
||||
|
||||
candidate_path = nm_connection_get_path (candidate);
|
||||
g_assert (candidate_path);
|
||||
if (!strcmp (path, candidate_path))
|
||||
return NM_SETTINGS_CONNECTION_INTERFACE (candidate);
|
||||
}
|
||||
return NULL;
|
||||
while (g_hash_table_iter_next (&iter, &key, NULL))
|
||||
list = g_slist_prepend (list, NM_EXPORTED_CONNECTION (key));
|
||||
return g_slist_reverse (list);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -514,28 +469,6 @@ connection_removed (NMSettingsConnectionInterface *connection,
|
|||
g_hash_table_remove (priv->connections, connection);
|
||||
}
|
||||
|
||||
static void
|
||||
export_connection (NMSysconfigSettings *self,
|
||||
NMSettingsConnectionInterface *connection)
|
||||
{
|
||||
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
||||
static guint32 ec_counter = 0;
|
||||
char *path;
|
||||
DBusGConnection *bus;
|
||||
|
||||
g_return_if_fail (connection != NULL);
|
||||
g_return_if_fail (NM_IS_SETTINGS_CONNECTION_INTERFACE (connection));
|
||||
|
||||
path = g_strdup_printf ("%s/%u", NM_DBUS_PATH_SETTINGS, ec_counter++);
|
||||
nm_connection_set_path (NM_CONNECTION (connection), path);
|
||||
nm_connection_set_scope (NM_CONNECTION (connection), NM_CONNECTION_SCOPE_SYSTEM);
|
||||
|
||||
bus = nm_dbus_manager_get_connection (priv->dbus_mgr);
|
||||
dbus_g_connection_register_g_object (bus, path, G_OBJECT (connection));
|
||||
|
||||
g_free (path);
|
||||
}
|
||||
|
||||
static void
|
||||
claim_connection (NMSysconfigSettings *self,
|
||||
NMSettingsConnectionInterface *connection,
|
||||
|
|
@ -554,7 +487,7 @@ claim_connection (NMSysconfigSettings *self,
|
|||
g_signal_connect (connection, "removed", G_CALLBACK (connection_removed), self);
|
||||
|
||||
if (do_export) {
|
||||
export_connection (self, connection);
|
||||
nm_settings_service_export_connection (NM_SETTINGS_SERVICE (self), connection);
|
||||
g_signal_emit_by_name (self, "new-connection", connection);
|
||||
}
|
||||
}
|
||||
|
|
@ -582,6 +515,9 @@ typedef struct {
|
|||
GCancellable *cancellable;
|
||||
|
||||
NMConnection *connection;
|
||||
NMSettingsAddConnectionFunc callback;
|
||||
gpointer callback_data;
|
||||
|
||||
char *hostname;
|
||||
} PolkitCall;
|
||||
|
||||
|
|
@ -589,6 +525,8 @@ static PolkitCall *
|
|||
polkit_call_new (NMSysconfigSettings *self,
|
||||
DBusGMethodInvocation *context,
|
||||
NMConnection *connection,
|
||||
NMSettingsAddConnectionFunc callback,
|
||||
gpointer callback_data,
|
||||
const char *hostname)
|
||||
{
|
||||
PolkitCall *call;
|
||||
|
|
@ -600,7 +538,12 @@ polkit_call_new (NMSysconfigSettings *self,
|
|||
call = g_malloc0 (sizeof (PolkitCall));
|
||||
call->self = self;
|
||||
call->context = context;
|
||||
call->connection = connection;
|
||||
if (connection)
|
||||
call->connection = g_object_ref (connection);
|
||||
if (callback) {
|
||||
call->callback = callback;
|
||||
call->callback_data = callback_data;
|
||||
}
|
||||
if (hostname)
|
||||
call->hostname = g_strdup (hostname);
|
||||
call->cancellable = g_cancellable_new ();
|
||||
|
|
@ -668,7 +611,7 @@ pk_add_cb (GObject *object, GAsyncResult *result, gpointer user_data)
|
|||
&error);
|
||||
/* Some random error happened */
|
||||
if (error) {
|
||||
dbus_g_method_return_error (call->context, error);
|
||||
call->callback (NM_SETTINGS_INTERFACE (self), error, call->callback_data);
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
|
@ -677,20 +620,20 @@ pk_add_cb (GObject *object, GAsyncResult *result, gpointer user_data)
|
|||
error = g_error_new_literal (NM_SYSCONFIG_SETTINGS_ERROR,
|
||||
NM_SYSCONFIG_SETTINGS_ERROR_NOT_PRIVILEGED,
|
||||
"Insufficient privileges.");
|
||||
dbus_g_method_return_error (call->context, error);
|
||||
call->callback (NM_SETTINGS_INTERFACE (self), error, call->callback_data);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (add_new_connection (self, call->connection, &add_error)) {
|
||||
dbus_g_method_return (call->context);
|
||||
} else {
|
||||
if (add_new_connection (self, call->connection, &add_error))
|
||||
call->callback (NM_SETTINGS_INTERFACE (self), NULL, call->callback_data);
|
||||
else {
|
||||
error = g_error_new (NM_SYSCONFIG_SETTINGS_ERROR,
|
||||
NM_SYSCONFIG_SETTINGS_ERROR_ADD_FAILED,
|
||||
"Saving connection failed: (%d) %s",
|
||||
add_error ? add_error->code : -1,
|
||||
(add_error && add_error->message) ? add_error->message : "(unknown)");
|
||||
g_error_free (add_error);
|
||||
dbus_g_method_return_error (call->context, error);
|
||||
call->callback (NM_SETTINGS_INTERFACE (self), error, call->callback_data);
|
||||
}
|
||||
|
||||
out:
|
||||
|
|
@ -701,13 +644,15 @@ out:
|
|||
}
|
||||
|
||||
static void
|
||||
impl_settings_add_connection (NMSysconfigSettings *self,
|
||||
GHashTable *settings,
|
||||
DBusGMethodInvocation *context)
|
||||
add_connection (NMSettingsService *service,
|
||||
NMSettingsConnectionInterface *connection,
|
||||
DBusGMethodInvocation *context, /* Only present for D-Bus calls */
|
||||
NMSettingsAddConnectionFunc callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMSysconfigSettings *self = NM_SYSCONFIG_SETTINGS (service);
|
||||
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
||||
PolkitCall *call;
|
||||
NMConnection *tmp;
|
||||
GError *error = NULL;
|
||||
|
||||
/* Do any of the plugins support adding? */
|
||||
|
|
@ -715,21 +660,12 @@ impl_settings_add_connection (NMSysconfigSettings *self,
|
|||
error = g_error_new_literal (NM_SYSCONFIG_SETTINGS_ERROR,
|
||||
NM_SYSCONFIG_SETTINGS_ERROR_ADD_NOT_SUPPORTED,
|
||||
"None of the registered plugins support add.");
|
||||
dbus_g_method_return_error (context, error);
|
||||
callback (NM_SETTINGS_INTERFACE (service), error, user_data);
|
||||
g_error_free (error);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check if the settings are valid first */
|
||||
tmp = nm_connection_new_from_hash (settings, &error);
|
||||
if (!tmp) {
|
||||
g_assert (error);
|
||||
dbus_g_method_return_error (context, error);
|
||||
g_error_free (error);
|
||||
return;
|
||||
}
|
||||
|
||||
call = polkit_call_new (self, context, tmp, NULL);
|
||||
call = polkit_call_new (self, context, NM_CONNECTION (connection), callback, user_data, NULL);
|
||||
g_assert (call);
|
||||
polkit_authority_check_authorization (priv->authority,
|
||||
call->subject,
|
||||
|
|
@ -816,7 +752,7 @@ impl_settings_save_hostname (NMSysconfigSettings *self,
|
|||
return;
|
||||
}
|
||||
|
||||
call = polkit_call_new (self, context, NULL, hostname);
|
||||
call = polkit_call_new (self, context, NULL, NULL, NULL, hostname);
|
||||
g_assert (call);
|
||||
polkit_authority_check_authorization (priv->authority,
|
||||
call->subject,
|
||||
|
|
@ -1123,13 +1059,16 @@ nm_sysconfig_settings_device_removed (NMSysconfigSettings *self, NMDevice *devic
|
|||
NMSysconfigSettings *
|
||||
nm_sysconfig_settings_new (const char *config_file,
|
||||
const char *plugins,
|
||||
DBusGConnection *bus,
|
||||
GError **error)
|
||||
{
|
||||
NMSysconfigSettings *self;
|
||||
NMSysconfigSettingsPrivate *priv;
|
||||
DBusGConnection *g_connection;
|
||||
|
||||
self = g_object_new (NM_TYPE_SYSCONFIG_SETTINGS, NULL);
|
||||
self = g_object_new (NM_TYPE_SYSCONFIG_SETTINGS,
|
||||
NM_SETTINGS_SERVICE_BUS, bus,
|
||||
NM_SETTINGS_SERVICE_SCOPE, NM_CONNECTION_SCOPE_SYSTEM,
|
||||
NULL);
|
||||
if (!self)
|
||||
return NULL;
|
||||
|
||||
|
|
@ -1137,12 +1076,6 @@ nm_sysconfig_settings_new (const char *config_file,
|
|||
|
||||
priv->config_file = g_strdup (config_file);
|
||||
|
||||
priv->dbus_mgr = nm_dbus_manager_get ();
|
||||
g_assert (priv->dbus_mgr);
|
||||
|
||||
g_connection = nm_dbus_manager_get_connection (priv->dbus_mgr);
|
||||
dbus_g_connection_register_g_object (g_connection, NM_DBUS_PATH_SETTINGS, G_OBJECT (self));
|
||||
|
||||
if (plugins) {
|
||||
/* Load the plugins; fail if a plugin is not found. */
|
||||
if (!load_plugins (self, plugins, error)) {
|
||||
|
|
@ -1172,23 +1105,12 @@ finalize (GObject *object)
|
|||
if (priv->authority)
|
||||
g_object_unref (priv->authority);
|
||||
|
||||
g_object_unref (priv->dbus_mgr);
|
||||
|
||||
g_free (priv->orig_hostname);
|
||||
g_free (priv->config_file);
|
||||
|
||||
G_OBJECT_CLASS (nm_sysconfig_settings_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
settings_interface_init (NMSettingsInterface *iface)
|
||||
{
|
||||
iface->get_connection_by_path = get_connection_by_path;
|
||||
|
||||
dbus_g_object_type_install_info (G_TYPE_FROM_INTERFACE (iface),
|
||||
&dbus_glib_nm_settings_object_info);
|
||||
}
|
||||
|
||||
static void
|
||||
settings_system_interface_init (NMSettingsSystemInterface *iface)
|
||||
{
|
||||
|
|
@ -1231,6 +1153,7 @@ static void
|
|||
nm_sysconfig_settings_class_init (NMSysconfigSettingsClass *class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||
NMSettingsServiceClass *ss_class = NM_SETTINGS_SERVICE_CLASS (class);
|
||||
|
||||
g_type_class_add_private (class, sizeof (NMSysconfigSettingsPrivate));
|
||||
|
||||
|
|
@ -1238,6 +1161,8 @@ nm_sysconfig_settings_class_init (NMSysconfigSettingsClass *class)
|
|||
object_class->notify = notify;
|
||||
object_class->get_property = get_property;
|
||||
object_class->finalize = finalize;
|
||||
ss_class->list_connections = list_connections;
|
||||
ss_class->add_connection = add_connection;
|
||||
|
||||
/* properties */
|
||||
g_object_class_install_property
|
||||
|
|
@ -1266,9 +1191,6 @@ nm_sysconfig_settings_class_init (NMSysconfigSettingsClass *class)
|
|||
g_cclosure_marshal_VOID__BOXED,
|
||||
G_TYPE_NONE, 1, DBUS_TYPE_G_MAP_OF_VARIANT);
|
||||
|
||||
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (class),
|
||||
&dbus_glib_nm_settings_object_info);
|
||||
|
||||
dbus_g_error_domain_register (NM_SYSCONFIG_SETTINGS_ERROR,
|
||||
NM_DBUS_IFACE_SETTINGS_SYSTEM,
|
||||
NM_TYPE_SYSCONFIG_SETTINGS_ERROR);
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
#define __NM_SYSCONFIG_SETTINGS_H__
|
||||
|
||||
#include <nm-connection.h>
|
||||
#include <nm-settings-service.h>
|
||||
|
||||
#include "nm-sysconfig-connection.h"
|
||||
#include "nm-system-config-interface.h"
|
||||
|
|
@ -42,11 +43,11 @@
|
|||
#define NM_SYSCONFIG_SETTINGS_UNMANAGED_SPECS "unmanaged-specs"
|
||||
|
||||
typedef struct {
|
||||
GObject parent_instance;
|
||||
NMSettingsService parent_instance;
|
||||
} NMSysconfigSettings;
|
||||
|
||||
typedef struct {
|
||||
GObjectClass parent_class;
|
||||
NMSettingsServiceClass parent_class;
|
||||
|
||||
/* Signals */
|
||||
void (*properties_changed) (NMSysconfigSettings *self, GHashTable *properties);
|
||||
|
|
@ -56,6 +57,7 @@ GType nm_sysconfig_settings_get_type (void);
|
|||
|
||||
NMSysconfigSettings *nm_sysconfig_settings_new (const char *config_file,
|
||||
const char *plugins,
|
||||
DBusGConnection *bus,
|
||||
GError **error);
|
||||
|
||||
const GSList *nm_sysconfig_settings_get_unmanaged_specs (NMSysconfigSettings *self);
|
||||
|
|
|
|||
|
|
@ -31,8 +31,6 @@
|
|||
#include <net/ethernet.h>
|
||||
#include <netinet/ether.h>
|
||||
|
||||
#include <dbus/dbus-glib.h>
|
||||
|
||||
#include <nm-setting-connection.h>
|
||||
|
||||
#ifndef NO_GIO
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue