vpn: simplify VPN connection lookup

This commit is contained in:
Dan Williams 2014-05-16 11:28:58 -05:00
parent 0596939565
commit f3c67726dc
3 changed files with 13 additions and 18 deletions

View file

@ -80,25 +80,15 @@ find_active_vpn_connection (NMVPNManager *self, NMConnection *connection)
{
NMVPNManagerPrivate *priv = NM_VPN_MANAGER_GET_PRIVATE (self);
GHashTableIter iter;
gpointer data;
const GSList *active, *aiter;
NMVPNService *service;
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) && (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) {
found = vpn;
break;
}
}
}
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &service) && !found)
found = nm_vpn_service_get_vpn_for_connection (service, connection);
return found;
}

View file

@ -284,12 +284,16 @@ nm_vpn_service_activate (NMVPNService *service,
return TRUE;
}
const GSList *
nm_vpn_service_get_active_connections (NMVPNService *service)
NMVPNConnection *
nm_vpn_service_get_vpn_for_connection (NMVPNService *service, NMConnection *connection)
{
g_return_val_if_fail (NM_IS_VPN_SERVICE (service), NULL);
GSList *iter;
return NM_VPN_SERVICE_GET_PRIVATE (service)->connections;
for (iter = NM_VPN_SERVICE_GET_PRIVATE (service)->connections; iter; iter = iter->next) {
if (nm_vpn_connection_get_connection (NM_VPN_CONNECTION (iter->data)) == connection)
return NM_VPN_CONNECTION (iter->data);
}
return NULL;
}
static void

View file

@ -56,7 +56,8 @@ gboolean nm_vpn_service_activate (NMVPNService *service,
NMVPNConnection *vpn,
GError **error);
const GSList *nm_vpn_service_get_active_connections (NMVPNService *service);
NMVPNConnection *nm_vpn_service_get_vpn_for_connection (NMVPNService *service,
NMConnection *connection);
void nm_vpn_service_connections_stop (NMVPNService *service,
gboolean fail,