2007-09-26 Tambet Ingo <tambet@gmail.com>

* src/nm-manager.c (manager_device_state_changed): Listen to
        * device' NEED_AUTH
        state and try to get the secrets.

        * src/NetworkManagerPolicy.c (nm_policy_auto_get_best_device):
        * Get the list of
        connections from NMManager and let the device to choose the best
from the list.
        Since the connection list is sorted by system ones first and
user ones later,
        the devices still prefer system connections like they did
before.
        (deactivate_old_device): Implement. When a device starts
activation, we have a
        policy (for now at least) to deactivate any other device that
might be either
        active or still activating.

        * src/vpn-manager/nm-vpn-manager.c: Add NMManager back to the
        * private structure.
        It's set on construction, there will be no other way to access
it.

        * src/nm-device-802-11-wireless.c: Don't touch NMManager,
        * NMManager can listen to
        device events and drive the device, not the other way around.

        * src/nm-device-802-3-ethernet.c: Ditto.

        * src/nm-device.c (nm_device_get_best_connection): The
        * connections list is now
        sent along, pass it on to virtual functions.

        * src/nm-device-interface.c (nm_device_interface_get_iface):
        * Implement. It's static
        for now, but should really be public instead of
nm_device_get_iface() since iface
        is a property of the DeviceInterface, not Device.
        (impl_device_activate): Don't touch NMManager!




git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2889 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Tambet Ingo
2007-09-26 15:38:51 +00:00
parent eb179bc0ad
commit 95e0ef0922
11 changed files with 119 additions and 122 deletions

View File

@@ -1,3 +1,32 @@
2007-09-26 Tambet Ingo <tambet@gmail.com>
* src/nm-manager.c (manager_device_state_changed): Listen to device' NEED_AUTH
state and try to get the secrets.
* src/NetworkManagerPolicy.c (nm_policy_auto_get_best_device): Get the list of
connections from NMManager and let the device to choose the best from the list.
Since the connection list is sorted by system ones first and user ones later,
the devices still prefer system connections like they did before.
(deactivate_old_device): Implement. When a device starts activation, we have a
policy (for now at least) to deactivate any other device that might be either
active or still activating.
* src/vpn-manager/nm-vpn-manager.c: Add NMManager back to the private structure.
It's set on construction, there will be no other way to access it.
* src/nm-device-802-11-wireless.c: Don't touch NMManager, NMManager can listen to
device events and drive the device, not the other way around.
* src/nm-device-802-3-ethernet.c: Ditto.
* src/nm-device.c (nm_device_get_best_connection): The connections list is now
sent along, pass it on to virtual functions.
* src/nm-device-interface.c (nm_device_interface_get_iface): Implement. It's static
for now, but should really be public instead of nm_device_get_iface() since iface
is a property of the DeviceInterface, not Device.
(impl_device_activate): Don't touch NMManager!
2007-09-26 Jürg Billeter <j@bitron.ch> 2007-09-26 Jürg Billeter <j@bitron.ch>
* initscript/paldo/NetworkManager.in: * initscript/paldo/NetworkManager.in:

View File

@@ -345,7 +345,7 @@ main (int argc, char *argv[])
goto done; goto done;
} }
vpn_manager = nm_vpn_manager_new (); vpn_manager = nm_vpn_manager_new (manager);
if (!vpn_manager) { if (!vpn_manager) {
nm_warning ("Failed to start the VPN manager."); nm_warning ("Failed to start the VPN manager.");
goto done; goto done;

View File

@@ -1,3 +1,4 @@
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
/* NetworkManager -- Network link manager /* NetworkManager -- Network link manager
* *
* Dan Williams <dcbw@redhat.com> * Dan Williams <dcbw@redhat.com>
@@ -68,6 +69,7 @@ nm_policy_auto_get_best_device (NMPolicy *policy,
NMConnection **connection, NMConnection **connection,
char **specific_object) char **specific_object)
{ {
GSList *connections;
GSList * elt; GSList * elt;
NMDevice8023Ethernet * best_wired_dev = NULL; NMDevice8023Ethernet * best_wired_dev = NULL;
guint best_wired_prio = 0; guint best_wired_prio = 0;
@@ -87,6 +89,10 @@ nm_policy_auto_get_best_device (NMPolicy *policy,
if (nm_manager_get_state (policy->manager) == NM_STATE_ASLEEP) if (nm_manager_get_state (policy->manager) == NM_STATE_ASLEEP)
return NULL; return NULL;
/* System connections first, then user connections */
connections = nm_manager_get_connections (policy->manager, NM_CONNECTION_TYPE_SYSTEM);
connections = g_slist_concat (connections, nm_manager_get_connections (policy->manager, NM_CONNECTION_TYPE_USER));
for (elt = nm_manager_get_devices (policy->manager); elt; elt = elt->next) { for (elt = nm_manager_get_devices (policy->manager); elt; elt = elt->next) {
NMConnection *tmp_con = NULL; NMConnection *tmp_con = NULL;
char *tmp_obj = NULL; char *tmp_obj = NULL;
@@ -98,7 +104,7 @@ nm_policy_auto_get_best_device (NMPolicy *policy,
link_active = nm_device_has_active_link (dev); link_active = nm_device_has_active_link (dev);
caps = nm_device_get_capabilities (dev); caps = nm_device_get_capabilities (dev);
tmp_con = nm_device_get_best_connection (dev, &tmp_obj); tmp_con = nm_device_get_best_connection (dev, connections, &tmp_obj);
if (tmp_con == NULL) { if (tmp_con == NULL) {
NMActRequest *req = nm_device_get_act_request (dev); NMActRequest *req = nm_device_get_act_request (dev);
@@ -145,6 +151,8 @@ nm_policy_auto_get_best_device (NMPolicy *policy,
} }
} }
g_slist_free (connections);
if (best_wired_dev) { if (best_wired_dev) {
highest_priority_dev = NM_DEVICE (best_wired_dev); highest_priority_dev = NM_DEVICE (best_wired_dev);
*connection = best_wired_connection; *connection = best_wired_connection;
@@ -385,12 +393,41 @@ schedule_change_check (NMPolicy *policy)
device_change_check_done); device_change_check_done);
} }
/* FIXME: remove when multiple active device support has landed */
static void
deactivate_old_device (NMPolicy *policy, NMDevice *new_device)
{
GSList *iter;
for (iter = nm_manager_get_devices (policy->manager); iter; iter = iter->next) {
NMDevice *dev = NM_DEVICE (iter->data);
if (dev == new_device)
continue;
switch (nm_device_get_state (dev)) {
case NM_DEVICE_STATE_PREPARE:
case NM_DEVICE_STATE_CONFIG:
case NM_DEVICE_STATE_NEED_AUTH:
case NM_DEVICE_STATE_IP_CONFIG:
case NM_DEVICE_STATE_ACTIVATED:
nm_device_interface_deactivate (NM_DEVICE_INTERFACE (dev));
break;
default:
break;
}
}
}
static void static void
device_state_changed (NMDevice *device, NMDeviceState state, gpointer user_data) device_state_changed (NMDevice *device, NMDeviceState state, gpointer user_data)
{ {
NMPolicy *policy = (NMPolicy *) user_data; NMPolicy *policy = (NMPolicy *) user_data;
if (state == NM_DEVICE_STATE_FAILED || state == NM_DEVICE_STATE_CANCELLED) if (state == NM_DEVICE_STATE_PREPARE)
deactivate_old_device (policy, device); /* FIXME: remove when multiple active device support has landed */
else if (state == NM_DEVICE_STATE_FAILED || state == NM_DEVICE_STATE_CANCELLED)
schedule_change_check (policy); schedule_change_check (policy);
} }

View File

@@ -694,32 +694,19 @@ find_best_connection (gpointer data, gpointer user_data)
static NMConnection * static NMConnection *
real_get_best_connection (NMDevice *dev, real_get_best_connection (NMDevice *dev,
GSList *connections,
char **specific_object) char **specific_object)
{ {
NMDevice80211Wireless * self = NM_DEVICE_802_11_WIRELESS (dev); NMDevice80211Wireless * self = NM_DEVICE_802_11_WIRELESS (dev);
NMManager *manager = nm_manager_get ();
GSList *connections = NULL;
BestConnectionInfo find_info; BestConnectionInfo find_info;
/* System connections first */
connections = nm_manager_get_connections (manager, NM_CONNECTION_TYPE_SYSTEM);
memset (&find_info, 0, sizeof (BestConnectionInfo)); memset (&find_info, 0, sizeof (BestConnectionInfo));
find_info.self = self; find_info.self = self;
g_slist_foreach (connections, find_best_connection, &find_info); g_slist_foreach (connections, find_best_connection, &find_info);
g_slist_free (connections);
/* Then user connections */
if (!find_info.found) {
connections = nm_manager_get_connections (manager, NM_CONNECTION_TYPE_USER);
find_info.self = self;
g_slist_foreach (connections, find_best_connection, &find_info);
g_slist_free (connections);
}
g_object_unref (manager);
if (find_info.found) if (find_info.found)
*specific_object = (char *) nm_ap_get_dbus_path (find_info.found_ap); *specific_object = (char *) nm_ap_get_dbus_path (find_info.found_ap);
return find_info.found; return find_info.found;
} }
@@ -1919,7 +1906,6 @@ link_timeout_cb (gpointer user_data)
NMActRequest * req = NULL; NMActRequest * req = NULL;
NMAccessPoint * ap = NULL; NMAccessPoint * ap = NULL;
NMConnection * connection; NMConnection * connection;
NMManager * manager;
const char * setting_name; const char * setting_name;
gboolean auth_enforced, encrypted = FALSE; gboolean auth_enforced, encrypted = FALSE;
@@ -1969,13 +1955,6 @@ link_timeout_cb (gpointer user_data)
cleanup_association_attempt (self, TRUE); cleanup_association_attempt (self, TRUE);
nm_device_state_changed (dev, NM_DEVICE_STATE_NEED_AUTH); nm_device_state_changed (dev, NM_DEVICE_STATE_NEED_AUTH);
manager = nm_manager_get ();
nm_manager_get_connection_secrets (manager,
NM_DEVICE_INTERFACE (self),
connection,
setting_name,
TRUE);
g_object_unref (manager);
return FALSE; return FALSE;
time_out: time_out:
@@ -2361,20 +2340,12 @@ supplicant_connection_timeout_cb (gpointer user_data)
nm_device_get_iface (dev)); nm_device_get_iface (dev));
nm_device_state_changed (dev, NM_DEVICE_STATE_FAILED); nm_device_state_changed (dev, NM_DEVICE_STATE_FAILED);
} else { } else {
NMManager *manager = nm_manager_get ();
/* Authentication failed, encryption key is probably bad */ /* Authentication failed, encryption key is probably bad */
nm_info ("Activation (%s/wireless): association took too long, " nm_info ("Activation (%s/wireless): association took too long, "
"asking for new key.", "asking for new key.",
nm_device_get_iface (dev)); nm_device_get_iface (dev));
nm_device_state_changed (dev, NM_DEVICE_STATE_NEED_AUTH); nm_device_state_changed (dev, NM_DEVICE_STATE_NEED_AUTH);
nm_manager_get_connection_secrets (manager,
NM_DEVICE_INTERFACE (self),
connection,
NM_SETTING_WIRELESS_SECURITY,
TRUE);
g_object_unref (manager);
} }
return FALSE; return FALSE;
@@ -2556,20 +2527,11 @@ real_act_stage2_config (NMDevice *dev)
/* If we need secrets, get them */ /* If we need secrets, get them */
setting_name = nm_connection_need_secrets (connection); setting_name = nm_connection_need_secrets (connection);
if (setting_name) { if (setting_name) {
NMManager * manager = nm_manager_get ();
nm_info ("Activation (%s/wireless): access point '%s' has security," nm_info ("Activation (%s/wireless): access point '%s' has security,"
" but secrets are required.", " but secrets are required.",
iface, s_connection->name); iface, s_connection->name);
nm_device_state_changed (dev, NM_DEVICE_STATE_NEED_AUTH); nm_device_state_changed (dev, NM_DEVICE_STATE_NEED_AUTH);
nm_manager_get_connection_secrets (manager,
NM_DEVICE_INTERFACE (self),
connection,
setting_name,
FALSE);
g_object_unref (manager);
return NM_ACT_STAGE_RETURN_POSTPONE; return NM_ACT_STAGE_RETURN_POSTPONE;
} else { } else {
NMSettingWireless *s_wireless = (NMSettingWireless *) nm_connection_get_setting (connection, NM_SETTING_WIRELESS); NMSettingWireless *s_wireless = (NMSettingWireless *) nm_connection_get_setting (connection, NM_SETTING_WIRELESS);
@@ -2714,7 +2676,6 @@ real_act_stage4_ip_config_timeout (NMDevice *dev,
connection = nm_act_request_get_connection (req); connection = nm_act_request_get_connection (req);
auth_enforced = ap_auth_enforced (connection, ap, &encrypted); auth_enforced = ap_auth_enforced (connection, ap, &encrypted);
if (encrypted && !auth_enforced) { if (encrypted && !auth_enforced) {
NMManager *manager = nm_manager_get ();
const GByteArray * ssid = nm_ap_get_ssid (ap); const GByteArray * ssid = nm_ap_get_ssid (ap);
/* Activation failed, we must have bad encryption key */ /* Activation failed, we must have bad encryption key */
@@ -2723,12 +2684,6 @@ real_act_stage4_ip_config_timeout (NMDevice *dev,
nm_device_get_iface (dev), nm_device_get_iface (dev),
ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)"); ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)");
nm_device_state_changed (dev, NM_DEVICE_STATE_NEED_AUTH); nm_device_state_changed (dev, NM_DEVICE_STATE_NEED_AUTH);
nm_manager_get_connection_secrets (manager,
NM_DEVICE_INTERFACE (self),
connection,
NM_SETTING_WIRELESS_SECURITY,
TRUE);
g_object_unref (manager);
ret = NM_ACT_STAGE_RETURN_POSTPONE; ret = NM_ACT_STAGE_RETURN_POSTPONE;
} else if (nm_ap_get_mode (ap) == IW_MODE_ADHOC) { } else if (nm_ap_get_mode (ap) == IW_MODE_ADHOC) {
NMDevice80211WirelessClass * klass; NMDevice80211WirelessClass * klass;

View File

@@ -34,7 +34,6 @@
#include "nm-supplicant-manager.h" #include "nm-supplicant-manager.h"
#include "nm-netlink-monitor.h" #include "nm-netlink-monitor.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-manager.h"
#include "nm-device-802-3-ethernet-glue.h" #include "nm-device-802-3-ethernet-glue.h"
@@ -366,11 +365,10 @@ find_best_connection (gpointer data, gpointer user_data)
static NMConnection * static NMConnection *
real_get_best_connection (NMDevice *dev, real_get_best_connection (NMDevice *dev,
GSList *connections,
char **specific_object) char **specific_object)
{ {
NMDevice8023Ethernet * self = NM_DEVICE_802_3_ETHERNET (dev); NMDevice8023Ethernet * self = NM_DEVICE_802_3_ETHERNET (dev);
NMManager *manager;
GSList *connections = NULL;
BestConnectionInfo find_info; BestConnectionInfo find_info;
guint32 caps; guint32 caps;
gboolean link_active; gboolean link_active;
@@ -385,24 +383,9 @@ real_get_best_connection (NMDevice *dev,
if (!(caps & NM_DEVICE_CAP_CARRIER_DETECT)) if (!(caps & NM_DEVICE_CAP_CARRIER_DETECT))
return NULL; return NULL;
manager = nm_manager_get ();
/* System connections first */
connections = nm_manager_get_connections (manager, NM_CONNECTION_TYPE_SYSTEM);
memset (&find_info, 0, sizeof (BestConnectionInfo)); memset (&find_info, 0, sizeof (BestConnectionInfo));
find_info.self = self; find_info.self = self;
g_slist_foreach (connections, find_best_connection, &find_info); g_slist_foreach (connections, find_best_connection, &find_info);
g_slist_free (connections);
/* Then user connections */
if (!find_info.found) {
connections = nm_manager_get_connections (manager, NM_CONNECTION_TYPE_USER);
find_info.self = self;
g_slist_foreach (connections, find_best_connection, &find_info);
g_slist_free (connections);
}
g_object_unref (manager);
/* Wired devices autoconnect with DHCP by default if they have a link */ /* Wired devices autoconnect with DHCP by default if they have a link */
link_active = nm_device_has_active_link (dev); link_active = nm_device_has_active_link (dev);

View File

@@ -1,7 +1,7 @@
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
#include "nm-device-interface.h" #include "nm-device-interface.h"
#include "nm-ip4-config.h" #include "nm-ip4-config.h"
#include "nm-manager.h"
#include "nm-utils.h" #include "nm-utils.h"
static gboolean impl_device_activate (NMDeviceInterface *device, static gboolean impl_device_activate (NMDeviceInterface *device,
@@ -207,6 +207,19 @@ nm_device_interface_activate (NMDeviceInterface *device,
user_requested); user_requested);
} }
/* FIXME: This should be public and nm_device_get_iface() should be removed. */
static const char *
nm_device_interface_get_iface (NMDeviceInterface *device)
{
const char *iface = NULL;
g_return_val_if_fail (NM_IS_DEVICE_INTERFACE (device), NULL);
g_object_get (device, NM_DEVICE_INTERFACE_IFACE, &iface, NULL);
return iface;
}
static gboolean static gboolean
impl_device_activate (NMDeviceInterface *device, impl_device_activate (NMDeviceInterface *device,
const char *service_name, const char *service_name,
@@ -214,44 +227,7 @@ impl_device_activate (NMDeviceInterface *device,
const char *specific_object, const char *specific_object,
GError **err) GError **err)
{ {
NMManager *manager = nm_manager_get (); nm_info ("User request for activation of %s.", nm_device_interface_get_iface (device));
NMDevice *old_dev = NULL;
GSList *iter;
// FIXME: remove when multiple active device support has landed
switch (nm_manager_get_state (manager)) {
case NM_STATE_CONNECTED:
old_dev = nm_manager_get_active_device (manager);
break;
case NM_STATE_CONNECTING:
for (iter = nm_manager_get_devices (manager); iter; iter = iter->next) {
if (nm_device_is_activating (NM_DEVICE (iter->data))) {
old_dev = NM_DEVICE (iter->data);
break;
}
}
break;
case NM_STATE_DISCONNECTED:
/* Check for devices that have deferred activation requests */
for (iter = nm_manager_get_devices (manager); iter; iter = iter->next) {
NMActRequest *req = nm_device_get_act_request (NM_DEVICE (iter->data));
if (req && nm_act_request_is_deferred (req)) {
old_dev = NM_DEVICE (iter->data);
break;
}
}
break;
default:
break;
}
g_object_unref (manager);
nm_info ("User request for activation of %s.", nm_device_get_iface (NM_DEVICE (device)));
if (old_dev)
nm_device_interface_deactivate (NM_DEVICE_INTERFACE (old_dev));
nm_device_interface_activate (device, nm_device_interface_activate (device,
service_name, service_name,
connection_path, connection_path,

View File

@@ -389,6 +389,7 @@ nm_device_set_active_link (NMDevice *self,
NMConnection * NMConnection *
nm_device_get_best_connection (NMDevice *dev, nm_device_get_best_connection (NMDevice *dev,
GSList *connections,
char **specific_object) char **specific_object)
{ {
guint32 caps; guint32 caps;
@@ -405,7 +406,7 @@ nm_device_get_best_connection (NMDevice *dev,
if (!NM_DEVICE_GET_CLASS (dev)->get_best_connection) if (!NM_DEVICE_GET_CLASS (dev)->get_best_connection)
return NULL; return NULL;
return NM_DEVICE_GET_CLASS (dev)->get_best_connection (dev, specific_object); return NM_DEVICE_GET_CLASS (dev)->get_best_connection (dev, connections, specific_object);
} }
/* /*

View File

@@ -91,6 +91,7 @@ struct _NMDeviceClass
guint32 (* get_generic_capabilities) (NMDevice *self); guint32 (* get_generic_capabilities) (NMDevice *self);
NMConnection * (* get_best_connection) (NMDevice *self, NMConnection * (* get_best_connection) (NMDevice *self,
GSList *connections,
char **specific_object); char **specific_object);
void (* connection_secrets_updated) (NMDevice *self, void (* connection_secrets_updated) (NMDevice *self,
@@ -150,6 +151,7 @@ void * nm_device_get_system_config_data (NMDevice *dev);
NMActRequest * nm_device_get_act_request (NMDevice *dev); NMActRequest * nm_device_get_act_request (NMDevice *dev);
NMConnection * nm_device_get_best_connection (NMDevice *dev, NMConnection * nm_device_get_best_connection (NMDevice *dev,
GSList *connections,
char **specific_object); char **specific_object);
void nm_device_activate_schedule_stage1_device_prepare (NMDevice *device); void nm_device_activate_schedule_stage1_device_prepare (NMDevice *device);

View File

@@ -658,11 +658,26 @@ manager_device_added (NMManager *manager, NMDevice *device)
} }
static void static void
manager_device_state_changed (NMDevice *device, NMDeviceState state, gpointer user_data) manager_device_state_changed (NMDeviceInterface *device, NMDeviceState state, gpointer user_data)
{ {
NMManager *manager = NM_MANAGER (user_data); NMManager *manager = NM_MANAGER (user_data);
nm_manager_update_state (manager); nm_manager_update_state (manager);
if (state == NM_DEVICE_STATE_NEED_AUTH) {
NMActRequest *req;
NMConnection *connection;
req = nm_device_get_act_request (NM_DEVICE (device));
/* When device needs an auth it must be activating and thus have an act request. */
g_assert (req);
connection = nm_act_request_get_connection (req);
nm_manager_get_connection_secrets (manager, device,
connection,
nm_connection_need_secrets (connection),
TRUE);
}
} }
void void

View File

@@ -26,6 +26,7 @@ static gboolean impl_vpn_manager_get_connections (NMVPNManager *manager,
G_DEFINE_TYPE (NMVPNManager, nm_vpn_manager, G_TYPE_OBJECT) G_DEFINE_TYPE (NMVPNManager, nm_vpn_manager, G_TYPE_OBJECT)
typedef struct { typedef struct {
NMManager *nm_manager;
NMDBusManager *dbus_mgr; NMDBusManager *dbus_mgr;
GSList *services; GSList *services;
} NMVPNManagerPrivate; } NMVPNManagerPrivate;
@@ -99,13 +100,10 @@ nm_vpn_manager_connect (NMVPNManager *manager,
static NMDevice * static NMDevice *
find_device (NMVPNManager *manager, const char *device_path) find_device (NMVPNManager *manager, const char *device_path)
{ {
NMManager *nm_manager;
GSList *devices; GSList *devices;
GSList *iter; GSList *iter;
nm_manager = nm_manager_get (); devices = nm_manager_get_devices (NM_VPN_MANAGER_GET_PRIVATE (manager)->nm_manager);
devices = nm_manager_get_devices (nm_manager);
g_object_unref (nm_manager);
for (iter = devices; iter; iter = iter->next) { for (iter = devices; iter; iter = iter->next) {
NMDevice *device = NM_DEVICE (iter->data); NMDevice *device = NM_DEVICE (iter->data);
@@ -125,7 +123,6 @@ impl_vpn_manager_connect (NMVPNManager *manager,
char **vpn_connection_path, char **vpn_connection_path,
GError **err) GError **err)
{ {
NMManager *nm_manager;
NMDevice *device; NMDevice *device;
NMConnection *connection = NULL; NMConnection *connection = NULL;
NMVPNConnection *vpn_connection = NULL; NMVPNConnection *vpn_connection = NULL;
@@ -138,18 +135,14 @@ impl_vpn_manager_connect (NMVPNManager *manager,
goto out; goto out;
} }
nm_manager = nm_manager_get ();
if (!strcmp (connection_type, NM_DBUS_SERVICE_USER_SETTINGS)) if (!strcmp (connection_type, NM_DBUS_SERVICE_USER_SETTINGS))
connection = nm_manager_get_connection_by_object_path (nm_manager, connection = nm_manager_get_connection_by_object_path (NM_VPN_MANAGER_GET_PRIVATE (manager)->nm_manager,
NM_CONNECTION_TYPE_USER, NM_CONNECTION_TYPE_USER,
connection_path); connection_path);
else if (!strcmp (connection_type, NM_DBUS_SERVICE_USER_SETTINGS)) else if (!strcmp (connection_type, NM_DBUS_SERVICE_USER_SETTINGS))
connection = nm_manager_get_connection_by_object_path (nm_manager, connection = nm_manager_get_connection_by_object_path (NM_VPN_MANAGER_GET_PRIVATE (manager)->nm_manager,
NM_CONNECTION_TYPE_SYSTEM, NM_CONNECTION_TYPE_SYSTEM,
connection_path); connection_path);
g_object_unref (nm_manager);
if (connection == NULL) { if (connection == NULL) {
/* FIXME: set error */ /* FIXME: set error */
goto out; goto out;
@@ -207,11 +200,15 @@ impl_vpn_manager_get_connections (NMVPNManager *manager, GPtrArray **connections
} }
NMVPNManager * NMVPNManager *
nm_vpn_manager_new (void) nm_vpn_manager_new (NMManager *nm_manager)
{ {
NMVPNManager *manager; NMVPNManager *manager;
g_return_val_if_fail (NM_IS_MANAGER (nm_manager), NULL);
manager = (NMVPNManager *) g_object_new (NM_TYPE_VPN_MANAGER, NULL); manager = (NMVPNManager *) g_object_new (NM_TYPE_VPN_MANAGER, NULL);
if (manager)
NM_VPN_MANAGER_GET_PRIVATE (manager)->nm_manager = g_object_ref (nm_manager);
return manager; return manager;
} }
@@ -236,6 +233,7 @@ finalize (GObject *object)
g_slist_foreach (priv->services, (GFunc) g_object_unref, NULL); g_slist_foreach (priv->services, (GFunc) g_object_unref, NULL);
g_object_unref (priv->dbus_mgr); g_object_unref (priv->dbus_mgr);
g_object_unref (priv->nm_manager);
G_OBJECT_CLASS (nm_vpn_manager_parent_class)->finalize (object); G_OBJECT_CLASS (nm_vpn_manager_parent_class)->finalize (object);
} }

View File

@@ -5,6 +5,7 @@
#include <glib/gtypes.h> #include <glib/gtypes.h>
#include <glib-object.h> #include <glib-object.h>
#include "nm-manager.h"
#include "nm-vpn-connection.h" #include "nm-vpn-connection.h"
#define NM_TYPE_VPN_MANAGER (nm_vpn_manager_get_type ()) #define NM_TYPE_VPN_MANAGER (nm_vpn_manager_get_type ())
@@ -24,7 +25,7 @@ typedef struct {
GType nm_vpn_manager_get_type (void); GType nm_vpn_manager_get_type (void);
NMVPNManager *nm_vpn_manager_new (void); NMVPNManager *nm_vpn_manager_new (NMManager *nm_manager);
NMVPNConnection *nm_vpn_manager_connect (NMVPNManager *manager, NMVPNConnection *nm_vpn_manager_connect (NMVPNManager *manager,
NMConnection *connection, NMConnection *connection,