core: reorganize activation flow by splitting out VPN activation work
Just split the VPN-specific stuff out to its own function so that nm_manager_activate_connection() isn't so large.
This commit is contained in:
113
src/nm-manager.c
113
src/nm-manager.c
@@ -2366,6 +2366,57 @@ internal_activate_device (NMManager *manager,
|
||||
return success ? NM_ACTIVE_CONNECTION (req) : NULL;
|
||||
}
|
||||
|
||||
static NMActiveConnection *
|
||||
activate_vpn_connection (NMManager *self,
|
||||
NMConnection *connection,
|
||||
const char *specific_object,
|
||||
const char *device_path,
|
||||
gulong sender_uid,
|
||||
GError **error)
|
||||
{
|
||||
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
|
||||
NMActRequest *parent_req = NULL;
|
||||
NMDevice *device = NULL;
|
||||
GSList *iter;
|
||||
|
||||
if (specific_object) {
|
||||
/* Find the specifc connection the client requested we use */
|
||||
parent_req = nm_manager_get_act_request_by_path (self, specific_object, &device);
|
||||
if (!parent_req) {
|
||||
g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_CONNECTION_NOT_ACTIVE,
|
||||
"Base connection for VPN connection not active.");
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
/* Just find the current default connection */
|
||||
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
|
||||
NMDevice *candidate = NM_DEVICE (iter->data);
|
||||
NMActRequest *candidate_req;
|
||||
|
||||
candidate_req = nm_device_get_act_request (candidate);
|
||||
if (candidate_req && nm_active_connection_get_default (NM_ACTIVE_CONNECTION (candidate_req))) {
|
||||
device = candidate;
|
||||
parent_req = candidate_req;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!device || !parent_req) {
|
||||
g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_DEVICE,
|
||||
"Could not find source connection, or the source connection had no active device.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return nm_vpn_manager_activate_connection (priv->vpn_manager,
|
||||
connection,
|
||||
device,
|
||||
nm_active_connection_get_path (NM_ACTIVE_CONNECTION (parent_req)),
|
||||
TRUE,
|
||||
sender_uid,
|
||||
error);
|
||||
}
|
||||
|
||||
NMActiveConnection *
|
||||
nm_manager_activate_connection (NMManager *manager,
|
||||
NMConnection *connection,
|
||||
@@ -2376,9 +2427,11 @@ nm_manager_activate_connection (NMManager *manager,
|
||||
{
|
||||
NMManagerPrivate *priv;
|
||||
NMDevice *device = NULL;
|
||||
NMSettingConnection *s_con;
|
||||
gulong sender_uid = 0;
|
||||
DBusError dbus_error;
|
||||
NMDeviceState state;
|
||||
char *iface;
|
||||
NMDevice *parent = NULL;
|
||||
|
||||
g_return_val_if_fail (manager != NULL, NULL);
|
||||
g_return_val_if_fail (connection != NULL, NULL);
|
||||
@@ -2402,58 +2455,9 @@ nm_manager_activate_connection (NMManager *manager,
|
||||
}
|
||||
}
|
||||
|
||||
s_con = nm_connection_get_setting_connection (connection);
|
||||
g_assert (s_con);
|
||||
|
||||
if (!strcmp (nm_setting_connection_get_connection_type (s_con), NM_SETTING_VPN_SETTING_NAME)) {
|
||||
NMActRequest *parent_req = NULL;
|
||||
|
||||
/* VPN connection */
|
||||
|
||||
if (specific_object) {
|
||||
/* Find the specifc connection the client requested we use */
|
||||
parent_req = nm_manager_get_act_request_by_path (manager, specific_object, &device);
|
||||
if (!parent_req) {
|
||||
g_set_error (error,
|
||||
NM_MANAGER_ERROR, NM_MANAGER_ERROR_CONNECTION_NOT_ACTIVE,
|
||||
"%s", "Base connection for VPN connection not active.");
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
GSList *iter;
|
||||
|
||||
/* Just find the current default connection */
|
||||
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
|
||||
NMDevice *candidate = NM_DEVICE (iter->data);
|
||||
NMActRequest *candidate_req;
|
||||
|
||||
candidate_req = nm_device_get_act_request (candidate);
|
||||
if (candidate_req && nm_active_connection_get_default (NM_ACTIVE_CONNECTION (candidate_req))) {
|
||||
device = candidate;
|
||||
parent_req = candidate_req;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!device || !parent_req) {
|
||||
g_set_error (error,
|
||||
NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_DEVICE,
|
||||
"%s", "Could not find source connection, or the source connection had no active device.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return nm_vpn_manager_activate_connection (priv->vpn_manager,
|
||||
connection,
|
||||
device,
|
||||
nm_active_connection_get_path (NM_ACTIVE_CONNECTION (parent_req)),
|
||||
TRUE,
|
||||
sender_uid,
|
||||
error);
|
||||
} else {
|
||||
NMDeviceState state;
|
||||
char *iface;
|
||||
NMDevice *parent = NULL;
|
||||
/* VPN ? */
|
||||
if (nm_connection_is_type (connection, NM_SETTING_VPN_SETTING_NAME))
|
||||
return activate_vpn_connection (manager, connection, specific_object, device_path, sender_uid, error);
|
||||
|
||||
/* Device-based connection */
|
||||
if (device_path) {
|
||||
@@ -2528,9 +2532,6 @@ nm_manager_activate_connection (NMManager *manager,
|
||||
FALSE,
|
||||
NULL,
|
||||
error);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user