summaryrefslogtreecommitdiff
path: root/clients
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-05-26 11:10:12 +0200
committerThomas Haller <thaller@redhat.com>2015-07-29 22:34:35 +0200
commitb378ae19fceac3626a5173c7122e5939ddd62506 (patch)
tree57c50227694210025a20c93fefeb08b87e09f8ff /clients
parentd2d40cc75b13f03c986dc284d4f244c3640c1776 (diff)
downloadNetworkManager-b378ae19fceac3626a5173c7122e5939ddd62506.tar.gz
tui: use NMVpnPluginInfo in vpn-helper.c
vpn-helper.c is currently not yet used. It was added for future VPN support for nmtui. Refactor it to make use of the new vpn helper functions in libnm.
Diffstat (limited to 'clients')
-rw-r--r--clients/tui/vpn-helpers.c151
-rw-r--r--clients/tui/vpn-helpers.h9
2 files changed, 28 insertions, 132 deletions
diff --git a/clients/tui/vpn-helpers.c b/clients/tui/vpn-helpers.c
index be8f538463..9cf8ce84c0 100644
--- a/clients/tui/vpn-helpers.c
+++ b/clients/tui/vpn-helpers.c
@@ -34,142 +34,41 @@
#include <gmodule.h>
#include <glib/gi18n.h>
-#include <nm-connection.h>
-#include <nm-setting-connection.h>
-#include <nm-setting-vpn.h>
-
#include "nm-glib.h"
#include "vpn-helpers.h"
-#define NM_VPN_API_SUBJECT_TO_CHANGE
-#include "nm-vpn-plugin-ui-interface.h"
-
-#define VPN_NAME_FILES_DIR SYSCONFDIR"/NetworkManager/VPN"
-
-static GHashTable *plugins = NULL;
+#include "nm-macros-internal.h"
-G_DEFINE_QUARK (NMA_ERROR, nma_error)
-#define NMA_ERROR nma_error_quark ()
-#define NMA_ERROR_GENERIC 0
+static gboolean plugins_loaded;
+static GSList *plugins = NULL;
-NMVpnPluginUiInterface *
+NMVpnEditorPlugin *
vpn_get_plugin_by_service (const char *service)
{
+ NMVpnEditorPlugin *plugin = NULL;
+ NMVpnPluginInfo *plugin_info;
+
g_return_val_if_fail (service != NULL, NULL);
- return g_hash_table_lookup (plugins, service);
+ if (G_UNLIKELY (!plugins_loaded))
+ vpn_get_plugins ();
+
+ plugin_info = nm_vpn_plugin_info_list_find_by_service (plugins, service);
+ if (plugin_info) {
+ plugin = nm_vpn_plugin_info_get_editor_plugin (plugin_info);
+ if (!plugin)
+ plugin = nm_vpn_plugin_info_load_editor_plugin (plugin_info, NULL);
+ }
+ return plugin;
}
-GHashTable *
-vpn_get_plugins (GError **error)
+GSList *
+vpn_get_plugins ()
{
- GDir *dir;
- const char *f;
-
- if (error)
- g_return_val_if_fail (*error == NULL, NULL);
-
- if (plugins)
+ if (G_LIKELY (plugins_loaded))
return plugins;
-
- dir = g_dir_open (VPN_NAME_FILES_DIR, 0, NULL);
- if (!dir) {
- g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "Couldn't read VPN .name files directory " VPN_NAME_FILES_DIR ".");
- return NULL;
- }
-
- plugins = g_hash_table_new_full (g_str_hash, g_str_equal,
- (GDestroyNotify) g_free, (GDestroyNotify) g_object_unref);
-
- while ((f = g_dir_read_name (dir))) {
- char *path = NULL, *service = NULL;
- char *so_path = NULL, *so_name = NULL;
- GKeyFile *keyfile = NULL;
- GModule *module;
- NMVpnPluginUiFactory factory = NULL;
-
- if (!g_str_has_suffix (f, ".name"))
- continue;
-
- path = g_strdup_printf ("%s/%s", VPN_NAME_FILES_DIR, f);
-
- keyfile = g_key_file_new ();
- if (!g_key_file_load_from_file (keyfile, path, 0, NULL))
- goto next;
-
- service = g_key_file_get_string (keyfile, "VPN Connection", "service", NULL);
- if (!service)
- goto next;
-
- so_path = g_key_file_get_string (keyfile, "GNOME", "properties", NULL);
- if (!so_path)
- goto next;
-
- /* Remove any path and extension components, then reconstruct path
- * to the SO in LIBDIR
- */
- so_name = g_path_get_basename (so_path);
- g_free (so_path);
- so_path = g_strdup_printf ("%s/NetworkManager/%s", LIBDIR, so_name);
- g_free (so_name);
-
- module = g_module_open (so_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
- if (!module) {
- g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "Cannot load the VPN plugin which provides the "
- "service '%s'.", service);
- goto next;
- }
-
- if (g_module_symbol (module, "nm_vpn_plugin_ui_factory", (gpointer) &factory)) {
- NMVpnPluginUiInterface *plugin;
- GError *factory_error = NULL;
- gboolean success = FALSE;
-
- plugin = factory (&factory_error);
- if (plugin) {
- char *plug_name = NULL, *plug_service = NULL;
-
- /* Validate plugin properties */
- g_object_get (G_OBJECT (plugin),
- NM_VPN_PLUGIN_UI_INTERFACE_NAME, &plug_name,
- NM_VPN_PLUGIN_UI_INTERFACE_SERVICE, &plug_service,
- NULL);
- if (!plug_name || !strlen (plug_name)) {
- g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "cannot load VPN plugin in '%s': missing plugin name",
- g_module_name (module));
- } else if (!plug_service || strcmp (plug_service, service)) {
- g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "cannot load VPN plugin in '%s': invalid service name",
- g_module_name (module));
- } else {
- /* Success! */
- g_object_set_data_full (G_OBJECT (plugin), "gmodule", module,
- (GDestroyNotify) g_module_close);
- g_hash_table_insert (plugins, g_strdup (service), plugin);
- success = TRUE;
- }
- g_free (plug_name);
- g_free (plug_service);
- } else {
- g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "cannot load VPN plugin in '%s': %s",
- g_module_name (module), g_module_error ());
- }
-
- if (!success)
- g_module_close (module);
- } else {
- g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "cannot locate nm_vpn_plugin_ui_factory() in '%s': %s",
- g_module_name (module), g_module_error ());
- g_module_close (module);
- }
-
- next:
- g_free (so_path);
- g_free (service);
- g_key_file_free (keyfile);
- g_free (path);
- }
- g_dir_close (dir);
-
+ plugins_loaded = TRUE;
+ plugins = nm_vpn_plugin_info_list_load ();
return plugins;
}
@@ -409,7 +308,7 @@ vpn_supports_ipv6 (NMConnection *connection)
{
NMSettingVpn *s_vpn;
const char *service_type;
- NMVpnPluginUiInterface *plugin;
+ NMVpnEditorPlugin *plugin;
guint32 capabilities;
s_vpn = nm_connection_get_setting_vpn (connection);
@@ -421,6 +320,6 @@ vpn_supports_ipv6 (NMConnection *connection)
plugin = vpn_get_plugin_by_service (service_type);
g_return_val_if_fail (plugin != NULL, FALSE);
- capabilities = nm_vpn_plugin_ui_interface_get_capabilities (plugin);
- return (capabilities & NM_VPN_PLUGIN_UI_CAPABILITY_IPV6) != 0;
+ capabilities = nm_vpn_editor_plugin_get_capabilities (plugin);
+ return NM_FLAGS_HAS (capabilities, NM_VPN_EDITOR_PLUGIN_CAPABILITY_IPV6);
}
diff --git a/clients/tui/vpn-helpers.h b/clients/tui/vpn-helpers.h
index 3bb26c6d76..4503b8178f 100644
--- a/clients/tui/vpn-helpers.h
+++ b/clients/tui/vpn-helpers.h
@@ -19,16 +19,13 @@
#ifndef _VPN_HELPERS_H_
#define _VPN_HELPERS_H_
-#include <nm-connection.h>
-
-#define NM_VPN_API_SUBJECT_TO_CHANGE
-#include <nm-vpn-plugin-ui-interface.h>
+#include <NetworkManager.h>
#include "nm-glib.h"
-GHashTable *vpn_get_plugins (GError **error);
+GSList *vpn_get_plugins (void);
-NMVpnPluginUiInterface *vpn_get_plugin_by_service (const char *service);
+NMVpnEditorPlugin *vpn_get_plugin_by_service (const char *service);
typedef void (*VpnImportSuccessCallback) (NMConnection *connection, gpointer user_data);
void vpn_import (VpnImportSuccessCallback callback, gpointer user_data);