summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-05-26 11:10:12 +0200
committerThomas Haller <thaller@redhat.com>2015-05-28 18:49:33 +0200
commit7389c869fecde7edd185249915c413cc9a4b1e19 (patch)
treeddde3598ba80308068bcca8ad1bbdc6f2cb811cc
parent63ac2a38375e3df0a92e148cf8dedd245e1c2395 (diff)
downloadNetworkManager-th/libnm-vpn-plugin-bgo749877-1.tar.gz
tui: use NMVpnPluginInfo in vpn-helper.cth/libnm-vpn-plugin-bgo749877-1
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.
-rw-r--r--clients/tui/vpn-helpers.c164
-rw-r--r--clients/tui/vpn-helpers.h8
2 files changed, 45 insertions, 127 deletions
diff --git a/clients/tui/vpn-helpers.c b/clients/tui/vpn-helpers.c
index ab6469183c..3e116ced9f 100644
--- a/clients/tui/vpn-helpers.c
+++ b/clients/tui/vpn-helpers.c
@@ -35,140 +35,60 @@
#include <gmodule.h>
#include <glib/gi18n.h>
-#include <nm-connection.h>
-#include <nm-setting-connection.h>
-#include <nm-setting-vpn.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"
+#include "nm-utils-internal.h"
-static GHashTable *plugins = NULL;
+static gboolean plugins_loaded;
+static GSList *plugins = NULL;
-G_DEFINE_QUARK (NMA_ERROR, nma_error)
-#define NMA_ERROR nma_error_quark ()
-#define NMA_ERROR_GENERIC 0
-
-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 (!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) {
+ /* load does only try to load the plugin once. Later it will return
+ * the cached plugin -- or NULL if the first attempt failed.
+ * This is what we want here. */
+ plugin = nm_vpn_plugin_info_load_editor_plugin (plugin_info,
+ FALSE,
+ getuid (),
+ NULL,
+ NULL,
+ 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);
+ GSList *infos, *info;
- if (plugins)
+ if (plugins_loaded)
return plugins;
+ plugins_loaded = TRUE;
- 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;
- }
+ infos = nm_vpn_plugin_info_load_dir (NULL,
+ TRUE,
+ getuid (),
+ NULL,
+ NULL);
+ for (info = infos; info; info = info->next)
+ nm_vpn_plugin_info_list_add (&plugins, info->data, NULL);
- 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);
+ g_slist_free_full (infos, g_object_unref);
return plugins;
}
@@ -409,7 +329,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 +341,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 28019ca9c8..9e8fb6cd57 100644
--- a/clients/tui/vpn-helpers.h
+++ b/clients/tui/vpn-helpers.h
@@ -20,14 +20,12 @@
#define _VPN_HELPERS_H_
#include <glib.h>
-#include <nm-connection.h>
-#define NM_VPN_API_SUBJECT_TO_CHANGE
-#include <nm-vpn-plugin-ui-interface.h>
+#include <NetworkManager.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);