diff options
-rw-r--r-- | src/connection-editor/connection-helpers.c | 39 | ||||
-rw-r--r-- | src/connection-editor/connection-helpers.h | 5 | ||||
-rw-r--r-- | src/connection-editor/nm-connection-list.c | 4 |
3 files changed, 36 insertions, 12 deletions
diff --git a/src/connection-editor/connection-helpers.c b/src/connection-editor/connection-helpers.c index 7ef75c67..a58a2fbb 100644 --- a/src/connection-editor/connection-helpers.c +++ b/src/connection-editor/connection-helpers.c @@ -163,7 +163,10 @@ no_description: } NMConnection * -connection_import_from_file (const char *filename, GType ctype, GError **error) +connection_import_from_file (const char *filename, + GType ctype, + const char *vpn_detail, + GError **error) { gs_free_error GError *unused_error = NULL; NMConnection *connection = NULL; @@ -181,14 +184,32 @@ connection_import_from_file (const char *filename, GType ctype, GError **error) } if (NM_IN_SET (ctype, G_TYPE_INVALID, NM_TYPE_SETTING_VPN)) { - for (iter = vpn_get_plugin_infos (); !connection && iter; iter = iter->next) { - NMVpnEditorPlugin *plugin; + GSList *plugin_infos = vpn_get_plugin_infos (); + NMVpnPluginInfo *plugin_info; + NMVpnEditorPlugin *plugin; - plugin = nm_vpn_plugin_info_get_editor_plugin (iter->data); - g_clear_error (error); - connection = nm_vpn_editor_plugin_import (plugin, filename, error); - if (connection) - break; + if (vpn_detail) { + gs_free char *service_type = NULL; + + if ((service_type = + nm_vpn_plugin_info_list_find_service_type (plugin_infos, vpn_detail)) && + (plugin_info = + nm_vpn_plugin_info_list_find_by_service (plugin_infos, service_type))) { + plugin = nm_vpn_plugin_info_get_editor_plugin (plugin_info); + connection = nm_vpn_editor_plugin_import (plugin, filename, error); + } else { + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, + _("VPN plugin “%s” not found"), vpn_detail); + } + } else { + for (iter = plugin_infos; iter; iter = iter->next) { + plugin_info = iter->data; + plugin = nm_vpn_plugin_info_get_editor_plugin (plugin_info); + g_clear_error (error); + connection = nm_vpn_editor_plugin_import (plugin, filename, error); + if (connection) + break; + } } if (connection) { @@ -248,7 +269,7 @@ import_vpn_from_file_cb (GtkWidget *dialog, gint response, gpointer user_data) } canceled = FALSE; - connection = connection_import_from_file (filename, G_TYPE_INVALID, &error); + connection = connection_import_from_file (filename, G_TYPE_INVALID, NULL, &error); if (!connection) { /* pass */ } else if (nm_streq (nm_connection_get_connection_type (connection), diff --git a/src/connection-editor/connection-helpers.h b/src/connection-editor/connection-helpers.h index af9985ff..37a8ad40 100644 --- a/src/connection-editor/connection-helpers.h +++ b/src/connection-editor/connection-helpers.h @@ -73,7 +73,10 @@ gboolean connection_supports_proxy (NMConnection *connection); gboolean connection_supports_ip4 (NMConnection *connection); gboolean connection_supports_ip6 (NMConnection *connection); -NMConnection *connection_import_from_file (const char *filename, GType ctype, GError **error); +NMConnection *connection_import_from_file (const char *filename, + GType ctype, + const char *vpn_detail, + GError **error); #endif /* __CONNECTION_HELPERS_H__ */ diff --git a/src/connection-editor/nm-connection-list.c b/src/connection-editor/nm-connection-list.c index d0271e36..1eb0a4c2 100644 --- a/src/connection-editor/nm-connection-list.c +++ b/src/connection-editor/nm-connection-list.c @@ -1045,13 +1045,13 @@ nm_connection_list_create (NMConnectionList *list, if (import_filename) { if (ctype == G_TYPE_INVALID) { - connection = connection_import_from_file (import_filename, ctype, NULL); + connection = connection_import_from_file (import_filename, ctype, NULL, NULL); if (!connection) { g_set_error (&error, NMA_ERROR, NMA_ERROR_GENERIC, _ ("Unrecognized connection type")); } } else if (NM_IN_SET (ctype, NM_TYPE_SETTING_VPN, NM_TYPE_SETTING_WIREGUARD)) { - connection = connection_import_from_file (import_filename, ctype, &error); + connection = connection_import_from_file (import_filename, ctype, detail, &error); } else { g_set_error (&error, NMA_ERROR, NMA_ERROR_GENERIC, _("Don’t know how to import “%s” connections"), g_type_name (ctype)); |