[network-manager-applet] vpn: make use of new NMVpnPluginInfo class to load vpn plugins
- From: Thomas Haller <thaller src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet] vpn: make use of new NMVpnPluginInfo class to load vpn plugins
- Date: Sat, 1 Aug 2015 10:16:22 +0000 (UTC)
commit 2fa478eab14093203937d69d24d563bfd88dac0d
Author: Thomas Haller <thaller redhat com>
Date: Sat Aug 1 10:48:48 2015 +0200
vpn: make use of new NMVpnPluginInfo class to load vpn plugins
https://bugzilla.gnome.org/show_bug.cgi?id=749877
src/connection-editor/connection-helpers.c | 41 +------
src/connection-editor/nm-connection-list.c | 6 -
src/connection-editor/vpn-helpers.c | 165 ++++++++--------------------
src/connection-editor/vpn-helpers.h | 2 +-
4 files changed, 53 insertions(+), 161 deletions(-)
---
diff --git a/src/connection-editor/connection-helpers.c b/src/connection-editor/connection-helpers.c
index 27bca67..ed2cd52 100644
--- a/src/connection-editor/connection-helpers.c
+++ b/src/connection-editor/connection-helpers.c
@@ -38,33 +38,12 @@
#include "page-vpn.h"
#include "vpn-helpers.h"
-static GSList *vpn_plugins;
-
#define COL_MARKUP 0
#define COL_SENSITIVE 1
#define COL_NEW_FUNC 2
#define COL_VPN_PLUGIN 3
static gint
-sort_vpn_plugins (gconstpointer a, gconstpointer b)
-{
- NMVpnEditorPlugin *aa = NM_VPN_EDITOR_PLUGIN (a);
- NMVpnEditorPlugin *bb = NM_VPN_EDITOR_PLUGIN (b);
- char *aa_desc = NULL, *bb_desc = NULL;
- int ret;
-
- g_object_get (aa, NM_VPN_EDITOR_PLUGIN_NAME, &aa_desc, NULL);
- g_object_get (bb, NM_VPN_EDITOR_PLUGIN_NAME, &bb_desc, NULL);
-
- ret = g_strcmp0 (aa_desc, bb_desc);
-
- g_free (aa_desc);
- g_free (bb_desc);
-
- return ret;
-}
-
-static gint
sort_types (gconstpointer a, gconstpointer b)
{
ConnectionTypeData *typea = (ConnectionTypeData *)a;
@@ -111,8 +90,6 @@ get_connection_type_list (void)
{
GArray *array;
static ConnectionTypeData *list;
- GHashTable *vpn_plugins_hash;
- gboolean have_vpn_plugins;
if (list)
return list;
@@ -137,21 +114,9 @@ get_connection_type_list (void)
add_type_data_virtual (array, _("VLAN"), vlan_connection_new, NM_TYPE_SETTING_VLAN);
/* Add "VPN" only if there are plugins */
- vpn_plugins_hash = vpn_get_plugins (NULL);
- have_vpn_plugins = vpn_plugins_hash && g_hash_table_size (vpn_plugins_hash);
- if (have_vpn_plugins) {
- GHashTableIter iter;
- gpointer name, plugin;
-
+ if (vpn_get_plugins ())
add_type_data_virtual (array, _("VPN"), vpn_connection_new, NM_TYPE_SETTING_VPN);
- vpn_plugins = NULL;
- g_hash_table_iter_init (&iter, vpn_plugins_hash);
- while (g_hash_table_iter_next (&iter, &name, &plugin))
- vpn_plugins = g_slist_prepend (vpn_plugins, plugin);
- vpn_plugins = g_slist_sort (vpn_plugins, sort_vpn_plugins);
- }
-
g_array_sort (array, sort_types);
return (ConnectionTypeData *)g_array_free (array, FALSE);
@@ -224,6 +189,7 @@ set_up_connection_type_combo (GtkComboBox *combo,
gboolean added_virtual_header = FALSE;
gboolean show_headers = (type_filter_func == NULL);
char *markup;
+ GSList *vpn_plugins;
gtk_combo_box_set_row_separator_func (combo, combo_row_separator_func, NULL, NULL);
g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK (combo_changed_cb), description_label);
@@ -280,6 +246,7 @@ set_up_connection_type_combo (GtkComboBox *combo,
added++;
}
+ vpn_plugins = vpn_get_plugins ();
if (!vpn_plugins || vpn_index == -1) {
gtk_combo_box_set_active (combo, show_headers ? active + 1 : active);
return;
@@ -296,7 +263,7 @@ set_up_connection_type_combo (GtkComboBox *combo,
}
for (p = vpn_plugins; p; p = p->next) {
- NMVpnEditorPlugin *plugin = NM_VPN_EDITOR_PLUGIN (p->data);
+ NMVpnEditorPlugin *plugin = nm_vpn_plugin_info_get_editor_plugin (p->data);
char *desc;
g_object_get (plugin, NM_VPN_EDITOR_PLUGIN_NAME, &desc, NULL);
diff --git a/src/connection-editor/nm-connection-list.c b/src/connection-editor/nm-connection-list.c
index 3b6b064..1149433 100644
--- a/src/connection-editor/nm-connection-list.c
+++ b/src/connection-editor/nm-connection-list.c
@@ -33,7 +33,6 @@
#include "ce-page.h"
#include "nm-connection-editor.h"
#include "nm-connection-list.h"
-#include "vpn-helpers.h"
#include "ce-polkit-button.h"
#include "connection-helpers.h"
@@ -887,11 +886,6 @@ nm_connection_list_new (void)
gtk_window_set_keep_above (GTK_WINDOW (list->dialog), TRUE);
g_signal_connect (G_OBJECT (list->dialog), "response", G_CALLBACK (dialog_response_cb), list);
- if (!vpn_get_plugins (&error)) {
- g_warning ("%s: failed to load VPN plugins: %s", __func__, error->message);
- g_error_free (error);
- }
-
return list;
error:
diff --git a/src/connection-editor/vpn-helpers.c b/src/connection-editor/vpn-helpers.c
index d4bd704..8da4b4b 100644
--- a/src/connection-editor/vpn-helpers.c
+++ b/src/connection-editor/vpn-helpers.c
@@ -31,133 +31,64 @@
#include "vpn-helpers.h"
#include "utils.h"
-#define VPN_NAME_FILES_DIR SYSCONFDIR"/NetworkManager/VPN"
-
-static GHashTable *plugins = NULL;
-
NMVpnEditorPlugin *
vpn_get_plugin_by_service (const char *service)
{
- g_return_val_if_fail (service != NULL, NULL);
+ NMVpnPluginInfo *plugin_info;
- return g_hash_table_lookup (plugins, service);
+ plugin_info = nm_vpn_plugin_info_list_find_by_service (vpn_get_plugins (), service);
+ if (plugin_info)
+ return nm_vpn_plugin_info_get_editor_plugin (plugin_info);
+ return NULL;
}
-GHashTable *
-vpn_get_plugins (GError **error)
+static gint
+_sort_vpn_plugins (NMVpnPluginInfo *aa, NMVpnPluginInfo *bb)
{
- GDir *dir;
- const char *f;
+ return strcmp (nm_vpn_plugin_info_get_name (aa), nm_vpn_plugin_info_get_name (bb));
+}
- if (error)
- g_return_val_if_fail (*error == NULL, NULL);
+GSList *
+vpn_get_plugins ()
+{
+ static gboolean plugins_loaded = FALSE;
+ static GSList *plugins = NULL;
+ GSList *p;
- 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 = NULL;
- NMVpnEditorPluginFactory 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, "libnm", "plugin", NULL);
- if (!so_path)
- goto next;
-
- if (g_path_is_absolute (so_path))
- module = g_module_open (so_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
-
- if (!module) {
- /* 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_editor_plugin_factory", (gpointer) &factory)) {
- NMVpnEditorPlugin *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_EDITOR_PLUGIN_NAME, &plug_name,
- NM_VPN_EDITOR_PLUGIN_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);
+ plugins_loaded = TRUE;
+
+ p = nm_vpn_plugin_info_list_load ();
+ plugins = NULL;
+ while (p) {
+ NMVpnPluginInfo *plugin_info = NM_VPN_PLUGIN_INFO (p->data);
+ GError *error = NULL;
+
+ /* load the editor plugin, and preserve only those NMVpnPluginInfo that can
+ * successfully load the plugin. */
+ if (nm_vpn_plugin_info_load_editor_plugin (plugin_info, &error))
+ plugins = g_slist_prepend (plugins, plugin_info);
+ else {
+ if ( !nm_vpn_plugin_info_get_plugin (plugin_info)
+ && nm_vpn_plugin_info_lookup_property (plugin_info,
NM_VPN_PLUGIN_INFO_KF_GROUP_GNOME, "properties")) {
+ g_message ("Cannot load legacy-only plugin '%s' (%s)",
+ nm_vpn_plugin_info_get_name (plugin_info),
+ nm_vpn_plugin_info_get_filename (plugin_info));
} else {
- g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "cannot load VPN plugin in
'%s': %s",
- g_module_name (module), g_module_error ());
+ g_warning ("Could not load '%s' plugin %s: %s",
+ nm_vpn_plugin_info_get_name (plugin_info),
+ nm_vpn_plugin_info_get_filename (plugin_info),
+ error->message);
}
-
- if (!success)
- g_module_close (module);
- } else {
- g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "cannot locate
nm_vpn_editor_plugin_factory() in '%s': %s",
- g_module_name (module), g_module_error ());
- g_module_close (module);
+ g_clear_error (&error);
+ g_object_unref (plugin_info);
}
-
- next:
- g_free (so_path);
- g_free (service);
- g_key_file_free (keyfile);
- g_free (path);
+ p = g_slist_delete_link (p, p);
}
- g_dir_close (dir);
+ /* sort the list of plugins alphabetically. */
+ plugins = g_slist_sort (plugins, (GCompareFunc) _sort_vpn_plugins);
return plugins;
}
@@ -171,9 +102,7 @@ import_vpn_from_file_cb (GtkWidget *dialog, gint response, gpointer user_data)
{
char *filename = NULL;
ActionInfo *info = (ActionInfo *) user_data;
- GHashTableIter iter;
- gpointer key;
- NMVpnEditorPlugin *plugin;
+ GSList *iter;
NMConnection *connection = NULL;
GError *error = NULL;
@@ -186,8 +115,10 @@ import_vpn_from_file_cb (GtkWidget *dialog, gint response, gpointer user_data)
goto out;
}
- g_hash_table_iter_init (&iter, plugins);
- while (!connection && g_hash_table_iter_next (&iter, &key, (gpointer *)&plugin)) {
+ for (iter = vpn_get_plugins (); !connection && iter; iter = iter->next) {
+ 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);
}
diff --git a/src/connection-editor/vpn-helpers.h b/src/connection-editor/vpn-helpers.h
index 10c9f55..bc017fb 100644
--- a/src/connection-editor/vpn-helpers.h
+++ b/src/connection-editor/vpn-helpers.h
@@ -28,7 +28,7 @@
#include <NetworkManager.h>
-GHashTable *vpn_get_plugins (GError **error);
+GSList *vpn_get_plugins (void);
NMVpnEditorPlugin *vpn_get_plugin_by_service (const char *service);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]