summaryrefslogtreecommitdiff
path: root/src/vpn-manager/nm-vpn-manager.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vpn-manager/nm-vpn-manager.c')
-rw-r--r--src/vpn-manager/nm-vpn-manager.c51
1 files changed, 30 insertions, 21 deletions
diff --git a/src/vpn-manager/nm-vpn-manager.c b/src/vpn-manager/nm-vpn-manager.c
index 38b06b19c..6772bb18d 100644
--- a/src/vpn-manager/nm-vpn-manager.c
+++ b/src/vpn-manager/nm-vpn-manager.c
@@ -115,22 +115,26 @@ find_active_vpn_connection_by_connection (NMVPNManager *self, NMConnection *conn
NMVPNManagerPrivate *priv = NM_VPN_MANAGER_GET_PRIVATE (self);
GHashTableIter iter;
gpointer data;
- GSList *connections, *elt;
+ GSList *active, *aiter;
+ NMVPNConnection *found = NULL;
g_return_val_if_fail (connection, NULL);
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
g_hash_table_iter_init (&iter, priv->services);
- while (g_hash_table_iter_next (&iter, NULL, &data)) {
- connections = nm_vpn_service_get_active_connections (NM_VPN_SERVICE (data));
- for (elt = connections; elt; elt = g_slist_next (elt)) {
- NMVPNConnection *vpn = NM_VPN_CONNECTION (elt->data);
+ while (g_hash_table_iter_next (&iter, NULL, &data) && (found == NULL)) {
+ active = nm_vpn_service_get_active_connections (NM_VPN_SERVICE (data));
+ for (aiter = active; aiter; aiter = g_slist_next (aiter)) {
+ NMVPNConnection *vpn = NM_VPN_CONNECTION (aiter->data);
- if (nm_vpn_connection_get_connection (vpn) == connection)
- return vpn;
+ if (nm_vpn_connection_get_connection (vpn) == connection) {
+ found = vpn;
+ break;
+ }
}
+ g_slist_free (active);
}
- return NULL;
+ return found;
}
static void
@@ -158,6 +162,8 @@ NMVPNConnection *
nm_vpn_manager_activate_connection (NMVPNManager *manager,
NMConnection *connection,
NMDevice *device,
+ gboolean user_requested,
+ gulong user_uid,
GError **error)
{
NMSettingVPN *vpn_setting;
@@ -203,7 +209,7 @@ nm_vpn_manager_activate_connection (NMVPNManager *manager,
return NULL;
}
- vpn = nm_vpn_service_activate (service, connection, device, error);
+ vpn = nm_vpn_service_activate (service, connection, device, user_requested, user_uid, error);
if (vpn) {
g_signal_connect (vpn, "vpn-state-changed",
G_CALLBACK (connection_vpn_state_changed),
@@ -221,7 +227,8 @@ nm_vpn_manager_deactivate_connection (NMVPNManager *self,
NMVPNManagerPrivate *priv;
GHashTableIter iter;
gpointer data;
- GSList *active, *elt;
+ GSList *active, *aiter;
+ gboolean success = FALSE;
g_return_val_if_fail (self, FALSE);
g_return_val_if_fail (NM_IS_VPN_MANAGER (self), FALSE);
@@ -229,21 +236,23 @@ nm_vpn_manager_deactivate_connection (NMVPNManager *self,
priv = NM_VPN_MANAGER_GET_PRIVATE (self);
g_hash_table_iter_init (&iter, priv->services);
- while (g_hash_table_iter_next (&iter, NULL, &data)) {
+ while (g_hash_table_iter_next (&iter, NULL, &data) && (success == FALSE)) {
active = nm_vpn_service_get_active_connections (NM_VPN_SERVICE (data));
- for (elt = active; elt; elt = g_slist_next (elt)) {
- NMVPNConnection *vpn = NM_VPN_CONNECTION (elt->data);
+ for (aiter = active; aiter; aiter = g_slist_next (aiter)) {
+ NMVPNConnection *vpn = NM_VPN_CONNECTION (aiter->data);
const char *vpn_path;
vpn_path = nm_vpn_connection_get_active_connection_path (vpn);
if (!strcmp (path, vpn_path)) {
nm_vpn_connection_disconnect (vpn, reason);
- return TRUE;
+ success = TRUE;
+ break;
}
}
+ g_slist_free (active);
}
- return FALSE;
+ return success;
}
void
@@ -254,7 +263,7 @@ nm_vpn_manager_add_active_connections (NMVPNManager *self,
NMVPNManagerPrivate *priv;
GHashTableIter iter;
gpointer data;
- GSList *active, *elt;
+ GSList *active, *aiter;
g_return_if_fail (self);
g_return_if_fail (NM_IS_VPN_MANAGER (self));
@@ -264,8 +273,8 @@ nm_vpn_manager_add_active_connections (NMVPNManager *self,
g_hash_table_iter_init (&iter, priv->services);
while (g_hash_table_iter_next (&iter, NULL, &data)) {
active = nm_vpn_service_get_active_connections (NM_VPN_SERVICE (data));
- for (elt = active; elt; elt = g_slist_next (elt)) {
- NMVPNConnection *vpn = NM_VPN_CONNECTION (elt->data);
+ for (aiter = active; aiter; aiter = g_slist_next (aiter)) {
+ NMVPNConnection *vpn = NM_VPN_CONNECTION (aiter->data);
const char *path;
if (!filter || (nm_vpn_connection_get_connection (vpn) == filter)) {
@@ -273,6 +282,7 @@ nm_vpn_manager_add_active_connections (NMVPNManager *self,
g_ptr_array_add (array, g_strdup (path));
}
}
+ g_slist_free (active);
}
}
@@ -282,7 +292,7 @@ nm_vpn_manager_get_active_connections (NMVPNManager *self)
NMVPNManagerPrivate *priv;
GHashTableIter iter;
gpointer data;
- GSList *list = NULL, *active, *elt;
+ GSList *list = NULL, *active;
g_return_val_if_fail (self, NULL);
g_return_val_if_fail (NM_IS_VPN_MANAGER (self), NULL);
@@ -291,8 +301,7 @@ nm_vpn_manager_get_active_connections (NMVPNManager *self)
g_hash_table_iter_init (&iter, priv->services);
while (g_hash_table_iter_next (&iter, NULL, &data)) {
active = nm_vpn_service_get_active_connections (NM_VPN_SERVICE (data));
- for (elt = active; elt; elt = g_slist_next (elt))
- list = g_slist_append (list, g_object_ref (G_OBJECT (elt->data)));
+ list = g_slist_concat (list, active);
}
return list;
}