NMVpnEditorPlugin * vpn_get_plugin_by_service (const char *service) { NMVpnPluginInfo *plugin_info; plugin_info = nm_vpn_plugin_info_list_find_by_service (vpn_get_plugin_infos (), service); if (plugin_info) return nm_vpn_plugin_info_get_editor_plugin (plugin_info); return NULL; }
gboolean nm_vpn_manager_activate_connection (NMVpnManager *manager, NMVpnConnection *vpn, GError **error) { NMVpnManagerPrivate *priv; NMVpnPluginInfo *plugin_info; const char *service_name; NMDevice *device; g_return_val_if_fail (NM_IS_VPN_MANAGER (manager), FALSE); g_return_val_if_fail (NM_IS_VPN_CONNECTION (vpn), FALSE); g_return_val_if_fail (!error || !*error, FALSE); priv = NM_VPN_MANAGER_GET_PRIVATE (manager); device = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (vpn)); g_assert (device); if ( nm_device_get_state (device) != NM_DEVICE_STATE_ACTIVATED && nm_device_get_state (device) != NM_DEVICE_STATE_SECONDARIES) { g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_DEPENDENCY_FAILED, "The base device for the VPN connection was not active."); return FALSE; } service_name = nm_vpn_connection_get_service (vpn); plugin_info = nm_vpn_plugin_info_list_find_by_service (priv->plugins, service_name); if (!plugin_info) { g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_CONNECTION_NOT_AVAILABLE, "The VPN service '%s' was not installed.", service_name); return FALSE; } if ( !nm_vpn_plugin_info_supports_multiple (plugin_info) && g_hash_table_contains (priv->active_services, service_name)) { g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_CONNECTION_NOT_AVAILABLE, "The '%s' plugin only supports a single active connection.", nm_vpn_plugin_info_get_name (plugin_info)); return FALSE; } nm_vpn_connection_activate (vpn, plugin_info); if (!nm_vpn_plugin_info_supports_multiple (plugin_info)) { /* Block activations of the connections of the same service type. */ g_hash_table_add (priv->active_services, g_strdup (service_name)); g_signal_connect (vpn, "notify::" NM_ACTIVE_CONNECTION_STATE, G_CALLBACK (vpn_state_changed), g_object_ref (manager)); } return TRUE; }