summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2012-08-22 09:38:01 -0500
committerDan Williams <dcbw@redhat.com>2012-12-17 17:01:10 -0600
commit84603c23801875eac34e306e83ab10716a857dc1 (patch)
tree6e73de81893d776c1f423f97fe25d7077bc892e2
parent7a3c53e8ffc064c060e91bf018655ded5c6cd51d (diff)
downloadNetworkManager-84603c23801875eac34e306e83ab10716a857dc1.tar.gz
core: move most activation request logic to the active connection class
We'll want to use NMActiveConnection more in the manager and also fold the PendingActivation functionality into it. All this functionality applies to the VPN connections too, so it makes sense to have it all in the base class instead of both NMActRequest and NMVPNConnection.
-rw-r--r--src/nm-activation-request.c216
-rw-r--r--src/nm-activation-request.h19
-rw-r--r--src/nm-active-connection.c176
-rw-r--r--src/nm-active-connection.h28
-rw-r--r--src/nm-device.c10
-rw-r--r--src/nm-manager.c6
-rw-r--r--src/vpn-manager/nm-vpn-connection.c78
7 files changed, 294 insertions, 239 deletions
diff --git a/src/nm-activation-request.c b/src/nm-activation-request.c
index 4070edbae5..18d8bfd7c1 100644
--- a/src/nm-activation-request.c
+++ b/src/nm-activation-request.c
@@ -28,11 +28,9 @@
#include <dbus/dbus-glib.h>
#include "nm-activation-request.h"
-#include "nm-marshal.h"
#include "nm-logging.h"
#include "nm-setting-wireless-security.h"
#include "nm-setting-8021x.h"
-#include "nm-dbus-manager.h"
#include "nm-device.h"
#include "nm-active-connection.h"
#include "nm-settings-connection.h"
@@ -51,28 +49,32 @@ typedef struct {
} ShareRule;
typedef struct {
- gboolean disposed;
-
NMConnection *connection;
-
- GSList *secrets_calls;
-
NMDevice *device;
- gboolean user_requested;
- gulong user_uid;
+ guint device_state_id;
char *dbus_sender;
-
- NMDevice *master;
-
+ GSList *secrets_calls;
gboolean shared;
GSList *share_rules;
-
- gboolean assumed;
} NMActRequestPrivate;
-enum {
- PROP_MASTER = 2000,
-};
+/*******************************************************************/
+
+NMConnection *
+nm_act_request_get_connection (NMActRequest *req)
+{
+ g_return_val_if_fail (NM_IS_ACT_REQUEST (req), NULL);
+
+ return nm_active_connection_get_connection (NM_ACTIVE_CONNECTION (req));
+}
+
+const char *
+nm_act_request_get_dbus_sender (NMActRequest *req)
+{
+ g_return_val_if_fail (NM_IS_ACT_REQUEST (req), NULL);
+
+ return NM_ACT_REQUEST_GET_PRIVATE (req)->dbus_sender;
+}
/*******************************************************************/
@@ -112,6 +114,8 @@ nm_act_request_get_secrets (NMActRequest *self,
NMActRequestPrivate *priv;
GetSecretsInfo *info;
guint32 call_id;
+ NMConnection *connection;
+ gboolean user_requested;
g_return_val_if_fail (self, 0);
g_return_val_if_fail (NM_IS_ACT_REQUEST (self), 0);
@@ -123,12 +127,14 @@ nm_act_request_get_secrets (NMActRequest *self,
info->callback = callback;
info->callback_data = callback_data;
- if (priv->user_requested)
+ user_requested = nm_active_connection_get_user_requested (NM_ACTIVE_CONNECTION (self));
+ if (user_requested)
flags |= NM_SETTINGS_GET_SECRETS_FLAG_USER_REQUESTED;
- call_id = nm_settings_connection_get_secrets (NM_SETTINGS_CONNECTION (priv->connection),
- priv->user_requested,
- priv->user_uid,
+ connection = nm_active_connection_get_connection (NM_ACTIVE_CONNECTION (self));
+ call_id = nm_settings_connection_get_secrets (NM_SETTINGS_CONNECTION (connection),
+ user_requested,
+ nm_active_connection_get_user_uid (NM_ACTIVE_CONNECTION (self)),
setting_name,
flags,
hint,
@@ -171,62 +177,6 @@ nm_act_request_cancel_secrets (NMActRequest *self, guint32 call_id)
}
}
-/*******************************************************************/
-
-NMConnection *
-nm_act_request_get_connection (NMActRequest *req)
-{
- g_return_val_if_fail (NM_IS_ACT_REQUEST (req), NULL);
-
- return NM_ACT_REQUEST_GET_PRIVATE (req)->connection;
-}
-
-gboolean
-nm_act_request_get_user_requested (NMActRequest *req)
-{
- g_return_val_if_fail (NM_IS_ACT_REQUEST (req), FALSE);
-
- return NM_ACT_REQUEST_GET_PRIVATE (req)->user_requested;
-}
-
-gulong
-nm_act_request_get_user_uid (NMActRequest *req)
-{
- g_return_val_if_fail (NM_IS_ACT_REQUEST (req), 0);
-
- return NM_ACT_REQUEST_GET_PRIVATE (req)->user_uid;
-}
-
-const char *
-nm_act_request_get_dbus_sender (NMActRequest *req)
-{
- g_return_val_if_fail (NM_IS_ACT_REQUEST (req), NULL);
-
- return NM_ACT_REQUEST_GET_PRIVATE (req)->dbus_sender;
-}
-
-GObject *
-nm_act_request_get_device (NMActRequest *req)
-{
- g_return_val_if_fail (NM_IS_ACT_REQUEST (req), NULL);
-
- return G_OBJECT (NM_ACT_REQUEST_GET_PRIVATE (req)->device);
-}
-
-gboolean
-nm_act_request_get_assumed (NMActRequest *req)
-{
- g_return_val_if_fail (NM_IS_ACT_REQUEST (req), FALSE);
-
- return NM_ACT_REQUEST_GET_PRIVATE (req)->assumed;
-}
-
-GObject *
-nm_act_request_get_master (NMActRequest *req)
-{
- return (GObject *) NM_ACT_REQUEST_GET_PRIVATE (req)->master;
-}
-
/********************************************************************/
static void
@@ -345,17 +295,12 @@ nm_act_request_add_share_rule (NMActRequest *req,
/********************************************************************/
static void
-device_state_changed (NMDevice *device,
- NMDeviceState new_state,
- NMDeviceState old_state,
- NMDeviceStateReason reason,
- gpointer user_data)
+device_state_changed (NMDevice *device, GParamSpec *pspec, NMActRequest *self)
{
- NMActRequest *self = NM_ACT_REQUEST (user_data);
NMActiveConnectionState new_ac_state;
/* Set NMActiveConnection state based on the device's state */
- switch (new_state) {
+ switch (nm_device_get_state (device)) {
case NM_DEVICE_STATE_PREPARE:
case NM_DEVICE_STATE_CONFIG:
case NM_DEVICE_STATE_NEED_AUTH:
@@ -411,45 +356,26 @@ nm_act_request_new (NMConnection *connection,
gulong user_uid,
const char *dbus_sender,
gboolean assumed,
- gpointer *device,
- gpointer *master)
+ NMDevice *device,
+ NMDevice *master)
{
GObject *object;
- NMActRequestPrivate *priv;
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
g_return_val_if_fail (NM_DEVICE (device), NULL);
object = g_object_new (NM_TYPE_ACT_REQUEST,
+ NM_ACTIVE_CONNECTION_INT_CONNECTION, connection,
+ NM_ACTIVE_CONNECTION_INT_DEVICE, device,
NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, specific_object,
+ NM_ACTIVE_CONNECTION_INT_USER_REQUESTED, user_requested,
+ NM_ACTIVE_CONNECTION_INT_USER_UID, user_uid,
+ NM_ACTIVE_CONNECTION_INT_ASSUMED, assumed,
+ NM_ACTIVE_CONNECTION_INT_MASTER, master,
NULL);
- if (!object)
- return NULL;
-
- priv = NM_ACT_REQUEST_GET_PRIVATE (object);
-
- priv->connection = g_object_ref (connection);
- priv->device = NM_DEVICE (device);
- g_signal_connect (device, "state-changed",
- G_CALLBACK (device_state_changed),
- NM_ACT_REQUEST (object));
-
- priv->user_uid = user_uid;
- priv->user_requested = user_requested;
- priv->dbus_sender = g_strdup (dbus_sender);
- priv->assumed = assumed;
- if (master) {
- g_assert (NM_IS_DEVICE (master));
- g_assert (NM_DEVICE (master) != NM_DEVICE (device));
-
- priv->master = g_object_ref (master);
- }
-
- if (!nm_active_connection_export (NM_ACTIVE_CONNECTION (object),
- connection,
- nm_device_get_path (NM_DEVICE (device)))) {
- g_object_unref (object);
- object = NULL;
+ if (object) {
+ nm_active_connection_export (NM_ACTIVE_CONNECTION (object));
+ NM_ACT_REQUEST_GET_PRIVATE (object)->dbus_sender = g_strdup (dbus_sender);
}
return (NMActRequest *) object;
@@ -461,18 +387,24 @@ nm_act_request_init (NMActRequest *req)
}
static void
-get_property (GObject *object, guint prop_id,
- GValue *value, GParamSpec *pspec)
+constructed (GObject *object)
{
NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (object);
+ NMConnection *connection;
+ NMDevice *device;
- switch (prop_id) {
- case PROP_MASTER:
- g_value_set_boxed (value, priv->master ? nm_device_get_path (priv->master) : "/");
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
+ G_OBJECT_CLASS (nm_act_request_parent_class)->constructed (object);
+
+ connection = nm_active_connection_get_connection (NM_ACTIVE_CONNECTION (object));
+ priv->connection = g_object_ref (connection);
+
+ device = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (object));
+ if (device) {
+ priv->device = g_object_ref (device);
+ priv->device_state_id = g_signal_connect (priv->device,
+ "notify::" NM_DEVICE_STATE,
+ G_CALLBACK (device_state_changed),
+ NM_ACT_REQUEST (object));
}
}
@@ -482,47 +414,38 @@ dispose (GObject *object)
NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (object);
GSList *iter;
- if (priv->disposed) {
- G_OBJECT_CLASS (nm_act_request_parent_class)->dispose (object);
- return;
+ if (priv->device && priv->device_state_id) {
+ g_signal_handler_disconnect (priv->device, priv->device_state_id);
+ priv->device_state_id = 0;
}
- priv->disposed = TRUE;
-
- g_signal_handlers_disconnect_by_func (G_OBJECT (priv->device),
- G_CALLBACK (device_state_changed),
- NM_ACT_REQUEST (object));
/* Clear any share rules */
- nm_act_request_set_shared (NM_ACT_REQUEST (object), FALSE);
+ if (priv->share_rules) {
+ nm_act_request_set_shared (NM_ACT_REQUEST (object), FALSE);
+ clear_share_rules (NM_ACT_REQUEST (object));
+ }
/* Kill any in-progress secrets requests */
- g_assert (priv->connection);
for (iter = priv->secrets_calls; iter; iter = g_slist_next (iter)) {
GetSecretsInfo *info = iter->data;
+ g_assert (priv->connection);
nm_settings_connection_cancel_secrets (NM_SETTINGS_CONNECTION (priv->connection), info->call_id);
g_free (info);
}
g_slist_free (priv->secrets_calls);
-
- g_object_unref (priv->connection);
+ priv->secrets_calls = NULL;
g_free (priv->dbus_sender);
+ priv->dbus_sender = NULL;
- g_clear_object (&priv->master);
+ g_clear_object (&priv->device);
+ g_clear_object (&priv->connection);
G_OBJECT_CLASS (nm_act_request_parent_class)->dispose (object);
}
static void
-finalize (GObject *object)
-{
- clear_share_rules (NM_ACT_REQUEST (object));
-
- G_OBJECT_CLASS (nm_act_request_parent_class)->finalize (object);
-}
-
-static void
nm_act_request_class_init (NMActRequestClass *req_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (req_class);
@@ -530,10 +453,7 @@ nm_act_request_class_init (NMActRequestClass *req_class)
g_type_class_add_private (req_class, sizeof (NMActRequestPrivate));
/* virtual methods */
- object_class->get_property = get_property;
+ object_class->constructed = constructed;
object_class->dispose = dispose;
- object_class->finalize = finalize;
-
- g_object_class_override_property (object_class, PROP_MASTER, NM_ACTIVE_CONNECTION_MASTER);
}
diff --git a/src/nm-activation-request.h b/src/nm-activation-request.h
index 50dc67a382..1597109498 100644
--- a/src/nm-activation-request.h
+++ b/src/nm-activation-request.h
@@ -23,6 +23,7 @@
#include <glib.h>
#include <glib-object.h>
+#include "nm-types.h"
#include "nm-connection.h"
#include "nm-active-connection.h"
#include "nm-settings-flags.h"
@@ -35,11 +36,11 @@
#define NM_ACT_REQUEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_ACT_REQUEST, NMActRequestClass))
typedef struct {
- GObject parent;
+ NMActiveConnection parent;
} NMActRequest;
typedef struct {
- GObjectClass parent;
+ NMActiveConnectionClass parent;
/* Signals */
void (*properties_changed) (NMActRequest *req, GHashTable *properties);
@@ -53,12 +54,10 @@ NMActRequest *nm_act_request_new (NMConnection *connection,
gulong user_uid,
const char *dbus_sender,
gboolean assumed,
- gpointer *device, /* An NMDevice */
- gpointer *master); /* An NMDevice */
+ NMDevice *device,
+ NMDevice *master);
-NMConnection *nm_act_request_get_connection (NMActRequest *req);
-
-gboolean nm_act_request_get_user_requested (NMActRequest *req);
+NMConnection *nm_act_request_get_connection (NMActRequest *req);
gulong nm_act_request_get_user_uid (NMActRequest *req);
@@ -72,12 +71,6 @@ void nm_act_request_add_share_rule (NMActRequest *req,
const char *table,
const char *rule);
-GObject * nm_act_request_get_device (NMActRequest *req);
-
-gboolean nm_act_request_get_assumed (NMActRequest *req);
-
-GObject * nm_act_request_get_master (NMActRequest *req);
-
/* Secrets handling */
typedef void (*NMActRequestSecretsFunc) (NMActRequest *req,
diff --git a/src/nm-active-connection.c b/src/nm-active-connection.c
index 4fc0bce86e..239f5a6cc2 100644
--- a/src/nm-active-connection.c
+++ b/src/nm-active-connection.c
@@ -19,12 +19,14 @@
*/
#include <glib.h>
+#include "nm-types.h"
#include "nm-active-connection.h"
#include "NetworkManager.h"
#include "nm-logging.h"
#include "nm-dbus-glib-types.h"
#include "nm-dbus-manager.h"
#include "nm-properties-changed-signal.h"
+#include "nm-device.h"
#include "nm-active-connection-glue.h"
@@ -36,16 +38,20 @@ G_DEFINE_ABSTRACT_TYPE (NMActiveConnection, nm_active_connection, G_TYPE_OBJECT)
NMActiveConnectionPrivate))
typedef struct {
- gboolean disposed;
-
NMConnection *connection;
char *path;
char *specific_object;
- char *device_path;
+ NMDevice *device;
+
gboolean is_default;
gboolean is_default6;
NMActiveConnectionState state;
gboolean vpn;
+
+ gboolean user_requested;
+ gulong user_uid;
+ gboolean assumed;
+ NMDevice *master;
} NMActiveConnectionPrivate;
enum {
@@ -60,6 +66,13 @@ enum {
PROP_VPN,
PROP_MASTER,
+ PROP_INT_CONNECTION,
+ PROP_INT_DEVICE,
+ PROP_INT_USER_REQUESTED,
+ PROP_INT_USER_UID,
+ PROP_INT_ASSUMED,
+ PROP_INT_MASTER,
+
LAST_PROP
};
@@ -175,51 +188,65 @@ nm_active_connection_get_default6 (NMActiveConnection *self)
return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->is_default6;
}
-gboolean
-nm_active_connection_export (NMActiveConnection *self,
- NMConnection *connection,
- const char *devpath)
+void
+nm_active_connection_export (NMActiveConnection *self)
{
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self);
NMDBusManager *dbus_mgr;
static guint32 counter = 0;
- g_return_val_if_fail (connection != NULL, FALSE);
- g_return_val_if_fail (devpath != NULL, FALSE);
-
- priv->connection = g_object_ref (connection);
priv->path = g_strdup_printf (NM_DBUS_PATH "/ActiveConnection/%d", counter++);
- priv->device_path = g_strdup (devpath);
-
dbus_mgr = nm_dbus_manager_get ();
dbus_g_connection_register_g_object (nm_dbus_manager_get_connection (dbus_mgr),
priv->path, G_OBJECT (self));
g_object_unref (dbus_mgr);
- return TRUE;
}
-/****************************************************************/
+gboolean
+nm_active_connection_get_user_requested (NMActiveConnection *self)
+{
+ g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (self), FALSE);
-static void
-nm_active_connection_init (NMActiveConnection *self)
+ return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->user_requested;
+}
+
+gulong
+nm_active_connection_get_user_uid (NMActiveConnection *self)
{
+ g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (self), G_MAXULONG);
+
+ return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->user_uid;
}
-static void
-dispose (GObject *object)
+gboolean
+nm_active_connection_get_assumed (NMActiveConnection *self)
{
- NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object);
+ g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (self), FALSE);
- if (!priv->disposed) {
- priv->disposed = TRUE;
+ return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->assumed;
+}
- g_free (priv->path);
- g_free (priv->specific_object);
- g_free (priv->device_path);
- g_object_unref (priv->connection);
- }
+NMDevice *
+nm_active_connection_get_device (NMActiveConnection *self)
+{
+ g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (self), NULL);
- G_OBJECT_CLASS (nm_active_connection_parent_class)->dispose (object);
+ return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->device;
+}
+
+NMDevice *
+nm_active_connection_get_master (NMActiveConnection *self)
+{
+ g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (self), NULL);
+
+ return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->master;
+}
+
+/****************************************************************/
+
+static void
+nm_active_connection_init (NMActiveConnection *self)
+{
}
static void
@@ -229,6 +256,31 @@ set_property (GObject *object, guint prop_id,
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object);
switch (prop_id) {
+ case PROP_INT_CONNECTION:
+ g_warn_if_fail (priv->connection == NULL);
+ priv->connection = g_value_dup_object (value);
+ break;
+ case PROP_INT_DEVICE:
+ g_warn_if_fail (priv->device == NULL);
+ priv->device = g_value_dup_object (value);
+ if (priv->device)
+ g_warn_if_fail (priv->device != priv->master);
+ break;
+ case PROP_INT_USER_REQUESTED:
+ priv->user_requested = g_value_get_boolean (value);
+ break;
+ case PROP_INT_USER_UID:
+ priv->user_uid = g_value_get_ulong (value);
+ break;
+ case PROP_INT_ASSUMED:
+ priv->assumed = g_value_get_boolean (value);
+ break;
+ case PROP_INT_MASTER:
+ g_warn_if_fail (priv->master == NULL);
+ priv->master = g_value_dup_object (value);
+ if (priv->master)
+ g_warn_if_fail (priv->master != priv->device);
+ break;
case PROP_SPECIFIC_OBJECT:
priv->specific_object = g_value_dup_boxed (value);
break;
@@ -241,6 +293,8 @@ set_property (GObject *object, guint prop_id,
case PROP_VPN:
priv->vpn = g_value_get_boolean (value);
break;
+ case PROP_MASTER:
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -266,7 +320,8 @@ get_property (GObject *object, guint prop_id,
break;
case PROP_DEVICES:
devices = g_ptr_array_sized_new (1);
- g_ptr_array_add (devices, g_strdup (priv->device_path));
+ if (priv->device)
+ g_ptr_array_add (devices, g_strdup (nm_device_get_path (priv->device)));
g_value_take_boxed (value, devices);
break;
case PROP_STATE:
@@ -282,6 +337,7 @@ get_property (GObject *object, guint prop_id,
g_value_set_boolean (value, priv->vpn);
break;
case PROP_MASTER:
+ g_value_set_boxed (value, priv->master ? nm_device_get_path (priv->master) : "/");
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -290,6 +346,23 @@ get_property (GObject *object, guint prop_id,
}
static void
+dispose (GObject *object)
+{
+ NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object);
+
+ g_free (priv->path);
+ priv->path = NULL;
+ g_free (priv->specific_object);
+ priv->specific_object = NULL;
+
+ g_clear_object (&priv->connection);
+ g_clear_object (&priv->device);
+ g_clear_object (&priv->master);
+
+ G_OBJECT_CLASS (nm_active_connection_parent_class)->dispose (object);
+}
+
+static void
nm_active_connection_class_init (NMActiveConnectionClass *vpn_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (vpn_class);
@@ -301,7 +374,7 @@ nm_active_connection_class_init (NMActiveConnectionClass *vpn_class)
object_class->set_property = set_property;
object_class->dispose = dispose;
- /* properties */
+ /* D-Bus exported properties */
g_object_class_install_property (object_class, PROP_CONNECTION,
g_param_spec_boxed (NM_ACTIVE_CONNECTION_CONNECTION,
"Connection",
@@ -367,6 +440,49 @@ nm_active_connection_class_init (NMActiveConnectionClass *vpn_class)
DBUS_TYPE_G_OBJECT_PATH,
G_PARAM_READABLE));
+ /* Internal properties */
+ g_object_class_install_property (object_class, PROP_INT_CONNECTION,
+ g_param_spec_object (NM_ACTIVE_CONNECTION_INT_CONNECTION,
+ "Internal Connection",
+ "Internal connection",
+ NM_TYPE_CONNECTION,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | NM_PROPERTY_PARAM_NO_EXPORT));
+
+ g_object_class_install_property (object_class, PROP_INT_DEVICE,
+ g_param_spec_object (NM_ACTIVE_CONNECTION_INT_DEVICE,
+ "Internal device",
+ "Internal device",
+ NM_TYPE_DEVICE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | NM_PROPERTY_PARAM_NO_EXPORT));
+
+ g_object_class_install_property (object_class, PROP_INT_USER_REQUESTED,
+ g_param_spec_boolean (NM_ACTIVE_CONNECTION_INT_USER_REQUESTED,
+ "User requested",
+ "User requested",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | NM_PROPERTY_PARAM_NO_EXPORT));
+
+ g_object_class_install_property (object_class, PROP_INT_USER_UID,
+ g_param_spec_ulong (NM_ACTIVE_CONNECTION_INT_USER_UID,
+ "User UID",
+ "User UID (if user requested)",
+ 0, G_MAXULONG, 0,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | NM_PROPERTY_PARAM_NO_EXPORT));
+
+ g_object_class_install_property (object_class, PROP_INT_ASSUMED,
+ g_param_spec_boolean (NM_ACTIVE_CONNECTION_INT_ASSUMED,
+ "Assumed",
+ "Assumed",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | NM_PROPERTY_PARAM_NO_EXPORT));
+
+ g_object_class_install_property (object_class, PROP_INT_MASTER,
+ g_param_spec_object (NM_ACTIVE_CONNECTION_INT_MASTER,
+ "Internal master device",
+ "Internal device",
+ NM_TYPE_DEVICE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | NM_PROPERTY_PARAM_NO_EXPORT));
+
/* Signals */
signals[PROPERTIES_CHANGED] =
nm_properties_changed_signal_new (object_class,
diff --git a/src/nm-active-connection.h b/src/nm-active-connection.h
index 7bc6c9a674..2f17c58345 100644
--- a/src/nm-active-connection.h
+++ b/src/nm-active-connection.h
@@ -22,6 +22,7 @@
#define NM_ACTIVE_CONNECTION_H
#include <glib-object.h>
+#include "nm-types.h"
#include "nm-connection.h"
#define NM_TYPE_ACTIVE_CONNECTION (nm_active_connection_get_type ())
@@ -31,7 +32,7 @@
#define NM_IS_ACTIVE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_ACTIVE_CONNECTION))
#define NM_ACTIVE_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_ACTIVE_CONNECTION, NMActiveConnectionClass))
-/* Properties */
+/* D-Bus Exported Properties */
#define NM_ACTIVE_CONNECTION_CONNECTION "connection"
#define NM_ACTIVE_CONNECTION_UUID "uuid"
#define NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT "specific-object"
@@ -42,6 +43,15 @@
#define NM_ACTIVE_CONNECTION_VPN "vpn"
#define NM_ACTIVE_CONNECTION_MASTER "master"
+/* Internal non-exported construct-time properties */
+#define NM_ACTIVE_CONNECTION_INT_CONNECTION "int-connection"
+#define NM_ACTIVE_CONNECTION_INT_DEVICE "int-device"
+#define NM_ACTIVE_CONNECTION_INT_USER_REQUESTED "int-user-requested"
+#define NM_ACTIVE_CONNECTION_INT_USER_UID "int-user-uid"
+#define NM_ACTIVE_CONNECTION_INT_ASSUMED "int-assumed"
+#define NM_ACTIVE_CONNECTION_INT_MASTER "int-master"
+
+
typedef struct {
GObject parent;
} NMActiveConnection;
@@ -50,14 +60,12 @@ typedef struct {
GObjectClass parent;
/* Signals */
- void (*properties_changed) (NMActiveConnection *req, GHashTable *properties);
+ void (*properties_changed) (NMActiveConnection *active, GHashTable *properties);
} NMActiveConnectionClass;
GType nm_active_connection_get_type (void);
-gboolean nm_active_connection_export (NMActiveConnection *self,
- NMConnection *connection,
- const char *devpath);
+void nm_active_connection_export (NMActiveConnection *self);
NMConnection *nm_active_connection_get_connection (NMActiveConnection *self);
const char * nm_active_connection_get_name (NMActiveConnection *self);
@@ -84,4 +92,14 @@ NMActiveConnectionState nm_active_connection_get_state (NMActiveConnection *self
void nm_active_connection_set_state (NMActiveConnection *self,
NMActiveConnectionState state);
+NMDevice * nm_active_connection_get_device (NMActiveConnection *self);
+
+gboolean nm_active_connection_get_user_requested (NMActiveConnection *self);
+
+gulong nm_active_connection_get_user_uid (NMActiveConnection *self);
+
+gboolean nm_active_connection_get_assumed (NMActiveConnection *self);
+
+NMDevice * nm_active_connection_get_master (NMActiveConnection *self);
+
#endif /* NM_ACTIVE_CONNECTION_H */
diff --git a/src/nm-device.c b/src/nm-device.c
index 1fdcda6bb5..99dced2b4b 100644
--- a/src/nm-device.c
+++ b/src/nm-device.c
@@ -2761,7 +2761,7 @@ nm_device_activate_stage3_ip_config_start (gpointer user_data)
* in which case we postpone activation here until the master enslaves us,
* which calls nm_device_slave_notify_enslaved().
*/
- master = (NMDevice *) nm_act_request_get_master (priv->act_request);
+ master = nm_active_connection_get_master (NM_ACTIVE_CONNECTION (priv->act_request));
if (master) {
if (priv->enslaved == FALSE) {
nm_log_info (LOGD_DEVICE, "Activation (%s) connection '%s' waiting on master '%s'",
@@ -2824,7 +2824,7 @@ nm_device_activate_schedule_stage3_ip_config_start (NMDevice *self)
g_return_if_fail (priv->act_request);
state = nm_device_get_state (self);
- if (nm_act_request_get_assumed (priv->act_request) == FALSE)
+ if (nm_active_connection_get_assumed (NM_ACTIVE_CONNECTION (priv->act_request)) == FALSE)
g_warn_if_fail (state >= NM_DEVICE_STATE_PREPARE && state <= NM_DEVICE_STATE_NEED_AUTH);
/* Add the interface to the specified firewall zone */
@@ -3176,7 +3176,7 @@ nm_device_activate_ip4_config_commit (gpointer user_data)
/* Merge with user overrides */
nm_utils_merge_ip4_config (config, nm_connection_get_setting_ip4_config (connection));
- assumed = nm_act_request_get_assumed (priv->act_request);
+ assumed = nm_active_connection_get_assumed (NM_ACTIVE_CONNECTION (priv->act_request));
if (!nm_device_set_ip4_config (self, config, assumed, &reason)) {
nm_log_info (LOGD_DEVICE | LOGD_IP4,
"Activation (%s) Stage 5 of 5 (IPv4 Commit) failed",
@@ -3653,7 +3653,7 @@ nm_device_activate (NMDevice *self, NMActRequest *req)
priv->act_request = g_object_ref (req);
g_object_notify (G_OBJECT (self), NM_DEVICE_ACTIVE_CONNECTION);
- if (nm_act_request_get_assumed (req)) {
+ if (nm_active_connection_get_assumed (NM_ACTIVE_CONNECTION (req))) {
/* If it's an assumed connection, let the device subclass short-circuit
* the normal connection process and just copy its IP configs from the
* interface.
@@ -3671,7 +3671,7 @@ nm_device_activate (NMDevice *self, NMActRequest *req)
nm_device_state_changed (self, NM_DEVICE_STATE_PREPARE, NM_DEVICE_STATE_REASON_NONE);
/* Handle any dependencies this connection might have */
- master = (NMDevice *) nm_act_request_get_master (req);
+ master = nm_active_connection_get_master (NM_ACTIVE_CONNECTION (req));
if (master) {
/* Master should at least already be activating */
g_assert (nm_device_get_state (master) > NM_DEVICE_STATE_DISCONNECTED);
diff --git a/src/nm-manager.c b/src/nm-manager.c
index a600e25249..7b578e8567 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -2309,7 +2309,7 @@ internal_activate_device (NMManager *manager,
}
if (master)
- master_device = (NMDevice *) nm_act_request_get_device (NM_ACT_REQUEST (master));
+ master_device = nm_active_connection_get_device (master);
req = nm_act_request_new (connection,
specific_object,
@@ -2317,8 +2317,8 @@ internal_activate_device (NMManager *manager,
sender_uid,
dbus_sender,
assumed,
- (gpointer) device,
- (gpointer) master_device);
+ device,
+ master_device);
nm_device_activate (device, req);
g_object_unref (req);
diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c
index 3f6c0bcf38..0cc7562e86 100644
--- a/src/vpn-manager/nm-vpn-connection.c
+++ b/src/vpn-manager/nm-vpn-connection.c
@@ -69,8 +69,6 @@ typedef struct {
NMConnection *connection;
- gboolean user_requested;
- gulong user_uid;
guint32 secrets_id;
SecretsReq secrets_idx;
char *username;
@@ -347,42 +345,20 @@ nm_vpn_connection_new (NMConnection *connection,
gulong user_uid)
{
NMVPNConnection *self;
- NMVPNConnectionPrivate *priv;
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
g_return_val_if_fail (NM_IS_DEVICE (parent_device), NULL);
self = (NMVPNConnection *) g_object_new (NM_TYPE_VPN_CONNECTION,
+ NM_ACTIVE_CONNECTION_INT_CONNECTION, connection,
+ NM_ACTIVE_CONNECTION_INT_DEVICE, parent_device,
NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, specific_object,
+ NM_ACTIVE_CONNECTION_INT_USER_REQUESTED, user_requested,
+ NM_ACTIVE_CONNECTION_INT_USER_UID, user_uid,
NM_ACTIVE_CONNECTION_VPN, TRUE,
NULL);
- if (!self)
- return NULL;
-
- priv = NM_VPN_CONNECTION_GET_PRIVATE (self);
-
- priv->user_requested = user_requested;
- priv->user_uid = user_uid;
- priv->connection = g_object_ref (connection);
- priv->parent_dev = g_object_ref (parent_device);
-
- priv->device_monitor = g_signal_connect (parent_device, "state-changed",
- G_CALLBACK (device_state_changed),
- self);
-
- priv->device_ip4 = g_signal_connect (parent_device, "notify::" NM_DEVICE_IP4_CONFIG,
- G_CALLBACK (device_ip4_config_changed),
- self);
- priv->device_ip6 = g_signal_connect (parent_device, "notify::" NM_DEVICE_IP6_CONFIG,
- G_CALLBACK (device_ip6_config_changed),
- self);
-
- if (!nm_active_connection_export (NM_ACTIVE_CONNECTION (self),
- connection,
- nm_device_get_path (parent_device))) {
- g_object_unref (self);
- self = NULL;
- }
+ if (self)
+ nm_active_connection_export (NM_ACTIVE_CONNECTION (self));
return self;
}
@@ -1436,11 +1412,13 @@ get_secrets (NMVPNConnection *self, SecretsReq secrets_idx)
NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self);
NMSettingsGetSecretsFlags flags = NM_SETTINGS_GET_SECRETS_FLAG_NONE;
GError *error = NULL;
- gboolean filter_by_uid = priv->user_requested;
+ gboolean filter_by_uid;
g_return_if_fail (secrets_idx < SECRETS_REQ_LAST);
priv->secrets_idx = secrets_idx;
+ filter_by_uid = nm_active_connection_get_user_requested (NM_ACTIVE_CONNECTION (self));
+
nm_log_dbg (LOGD_VPN, "(%s/%s) requesting VPN secrets pass #%d",
nm_connection_get_uuid (priv->connection),
nm_connection_get_id (priv->connection),
@@ -1461,12 +1439,12 @@ get_secrets (NMVPNConnection *self, SecretsReq secrets_idx)
g_assert_not_reached ();
}
- if (priv->user_requested)
+ if (nm_active_connection_get_user_requested (NM_ACTIVE_CONNECTION (self)))
flags |= NM_SETTINGS_GET_SECRETS_FLAG_USER_REQUESTED;
priv->secrets_id = nm_settings_connection_get_secrets (NM_SETTINGS_CONNECTION (priv->connection),
filter_by_uid,
- priv->user_uid,
+ nm_active_connection_get_user_uid (NM_ACTIVE_CONNECTION (self)),
NM_SETTING_VPN_SETTING_NAME,
flags,
NULL,
@@ -1492,6 +1470,35 @@ nm_vpn_connection_init (NMVPNConnection *self)
}
static void
+constructed (GObject *object)
+{
+ NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (object);
+ NMConnection *connection;
+ NMDevice *device;
+
+ G_OBJECT_CLASS (nm_vpn_connection_parent_class)->constructed (object);
+
+ connection = nm_active_connection_get_connection (NM_ACTIVE_CONNECTION (object));
+ priv->connection = g_object_ref (connection);
+
+ device = (NMDevice *) nm_active_connection_get_device (NM_ACTIVE_CONNECTION (object));
+ g_assert (device);
+
+ priv->parent_dev = g_object_ref (device);
+
+ priv->device_monitor = g_signal_connect (device, "state-changed",
+ G_CALLBACK (device_state_changed),
+ object);
+
+ priv->device_ip4 = g_signal_connect (device, "notify::" NM_DEVICE_IP4_CONFIG,
+ G_CALLBACK (device_ip4_config_changed),
+ object);
+ priv->device_ip6 = g_signal_connect (device, "notify::" NM_DEVICE_IP6_CONFIG,
+ G_CALLBACK (device_ip6_config_changed),
+ object);
+}
+
+static void
dispose (GObject *object)
{
NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (object);
@@ -1517,7 +1524,7 @@ dispose (GObject *object)
if (priv->device_monitor)
g_signal_handler_disconnect (priv->parent_dev, priv->device_monitor);
- g_object_unref (priv->parent_dev);
+ g_clear_object (&priv->parent_dev);
if (priv->ip4_config)
g_object_unref (priv->ip4_config);
@@ -1535,7 +1542,7 @@ dispose (GObject *object)
priv->secrets_id);
}
- g_object_unref (priv->connection);
+ g_clear_object (&priv->connection);
g_free (priv->username);
G_OBJECT_CLASS (nm_vpn_connection_parent_class)->dispose (object);
@@ -1583,6 +1590,7 @@ nm_vpn_connection_class_init (NMVPNConnectionClass *connection_class)
/* virtual methods */
object_class->get_property = get_property;
+ object_class->constructed = constructed;
object_class->dispose = dispose;
object_class->finalize = finalize;