summary refs log tree commit diff
path: root/clients/common
diff options
context:
space:
mode:
Diffstat (limited to 'clients/common')
-rw-r--r--clients/common/nm-polkit-listener.h6
-rw-r--r--clients/common/nm-secret-agent-simple.h4
-rw-r--r--clients/common/nm-vpn-helpers.c115
-rw-r--r--clients/common/nm-vpn-helpers.h13
4 files changed, 21 insertions, 117 deletions
diff --git a/clients/common/nm-polkit-listener.h b/clients/common/nm-polkit-listener.h
index 22c436c1..a8256460 100644
--- a/clients/common/nm-polkit-listener.h
+++ b/clients/common/nm-polkit-listener.h
@@ -22,10 +22,6 @@
 #define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE
 #include <polkitagent/polkitagent.h>
 
-#include "nm-default.h"
-
-G_BEGIN_DECLS
-
 #define NM_TYPE_POLKIT_LISTENER            (nm_polkit_listener_get_type ())
 #define NM_POLKIT_LISTENER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_POLKIT_LISTENER, NMPolkitListener))
 #define NM_POLKIT_LISTENER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_POLKIT_LISTENER, NMPolkitListenerClass))
@@ -99,6 +95,4 @@ void nm_polkit_listener_set_show_error_callback (NMPolkitListener *self,
 void nm_polkit_listener_set_completed_callback  (NMPolkitListener *self,
                                                  NMPolkitListenerOnCompletedFunc completed_callback);
 
-G_END_DECLS
-
 #endif /* __NM_POLKIT_LISTENER_H__ */
diff --git a/clients/common/nm-secret-agent-simple.h b/clients/common/nm-secret-agent-simple.h
index d2c58822..ba819ae3 100644
--- a/clients/common/nm-secret-agent-simple.h
+++ b/clients/common/nm-secret-agent-simple.h
@@ -22,8 +22,6 @@
 #include <NetworkManager.h>
 #include <nm-secret-agent-old.h>
 
-G_BEGIN_DECLS
-
 #define NM_TYPE_SECRET_AGENT_SIMPLE            (nm_secret_agent_simple_get_type ())
 #define NM_SECRET_AGENT_SIMPLE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimple))
 #define NM_SECRET_AGENT_SIMPLE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimpleClass))
@@ -59,6 +57,4 @@ void              nm_secret_agent_simple_response            (NMSecretAgentSimpl
 void              nm_secret_agent_simple_enable              (NMSecretAgentSimple *self,
                                                               const char          *path);
 
-G_END_DECLS
-
 #endif /* __NM_SECRET_AGENT_SIMPLE_H__ */
diff --git a/clients/common/nm-vpn-helpers.c b/clients/common/nm-vpn-helpers.c
index fe777ef5..f6f12176 100644
--- a/clients/common/nm-vpn-helpers.c
+++ b/clients/common/nm-vpn-helpers.c
@@ -19,8 +19,6 @@
 /**
  * SECTION:nm-vpn-helpers
  * @short_description: VPN-related utilities
- *
- * Some functions should probably eventually move into libnm.
  */
 
 #include "nm-default.h"
@@ -28,34 +26,26 @@
 #include "nm-vpn-helpers.h"
 
 #include <string.h>
-#include <gmodule.h>
 
 #include "nm-utils.h"
 
-static gboolean plugins_loaded;
-static GSList *plugins = NULL;
+/*****************************************************************************/
 
 NMVpnEditorPlugin *
-nm_vpn_lookup_plugin (const char *name, const char *service, GError **error)
+nm_vpn_get_editor_plugin (const char *service_type, GError **error)
 {
 	NMVpnEditorPlugin *plugin = NULL;
 	NMVpnPluginInfo *plugin_info;
 	gs_free_error GError *local = NULL;
 
-	g_return_val_if_fail (!service ^ !name, NULL);
+	g_return_val_if_fail (service_type, NULL);
 	g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
-	if (G_UNLIKELY (!plugins_loaded))
-		nm_vpn_get_plugins ();
-
-	if (service)
-		plugin_info = nm_vpn_plugin_info_list_find_by_service (plugins, service);
-	else
-		plugin_info = nm_vpn_plugin_info_list_find_by_name (plugins, name);
+	plugin_info = nm_vpn_plugin_info_list_find_by_service (nm_vpn_get_plugin_infos (), service_type);
 
 	if (!plugin_info) {
 		g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_FAILED,
-		             _("unknown VPN plugin \"%s\""), service ?: name);
+		             _("unknown VPN plugin \"%s\""), service_type);
 		return NULL;
 	}
 	plugin = nm_vpn_plugin_info_get_editor_plugin (plugin_info);
@@ -87,8 +77,11 @@ nm_vpn_lookup_plugin (const char *name, const char *service, GError **error)
 }
 
 GSList *
-nm_vpn_get_plugins (void)
+nm_vpn_get_plugin_infos (void)
 {
+	static bool plugins_loaded;
+	static GSList *plugins = NULL;
+
 	if (G_LIKELY (plugins_loaded))
 		return plugins;
 	plugins_loaded = TRUE;
@@ -96,80 +89,6 @@ nm_vpn_get_plugins (void)
 	return plugins;
 }
 
-static int
-_strcmp_data (gconstpointer a, gconstpointer b, gpointer unused)
-{
-	return strcmp (a, b);
-}
-
-const char **
-nm_vpn_get_plugin_names (gboolean only_available_plugins)
-{
-	GSList *p;
-	const char **list;
-	const char *known_names[] = {
-		"openvpn",
-		"vpnc",
-		"pptp",
-		"openconnect",
-		"openswan",
-		"libreswan",
-		"strongswan",
-		"ssh",
-		"l2tp",
-		"iodine",
-		"fortisslvpn",
-	};
-	guint i, j, k;
-
-	p = nm_vpn_get_plugins ();
-	list = g_new0 (const char *, g_slist_length (p) + G_N_ELEMENTS (known_names) + 1);
-
-	i = 0;
-	for (i = 0; p; p = p->next)
-		list[i++] = nm_vpn_plugin_info_get_name (p->data);
-	if (!only_available_plugins) {
-		for (j = 0; j < G_N_ELEMENTS (known_names); j++)
-			list[i++] = known_names[j];
-	}
-
-	g_qsort_with_data (list, i, sizeof (gpointer), _strcmp_data, NULL);
-
-	/* remove duplicates */
-	for (k = 0, j = 1; j < i; j++) {
-		if (nm_streq (list[k], list[j]))
-			continue;
-		list[k++] = list[j];
-	}
-	list[k++] = NULL;
-
-	return list;
-}
-
-const char *
-nm_vpn_get_service_for_name (const char *name)
-{
-	NMVpnPluginInfo *plugin_info;
-
-	g_return_val_if_fail (name, NULL);
-
-	plugin_info = nm_vpn_plugin_info_list_find_by_name (nm_vpn_get_plugins (), name);
-	if (plugin_info) {
-		/* this only means we have a .name file (NMVpnPluginInfo). Possibly the
-		 * NMVpnEditorPlugin is not loadable. */
-		return nm_vpn_plugin_info_lookup_property (plugin_info,
-		                                           NM_VPN_PLUGIN_INFO_KF_GROUP_CONNECTION,
-		                                           "service");
-	}
-	return NULL;
-}
-
-char *
-nm_vpn_get_service_for_name_default (const char *name)
-{
-	return g_strdup_printf ("%s.%s", NM_DBUS_INTERFACE, name);
-}
-
 gboolean
 nm_vpn_supports_ipv6 (NMConnection *connection)
 {
@@ -185,7 +104,7 @@ nm_vpn_supports_ipv6 (NMConnection *connection)
 	if (!service_type)
 		return FALSE;
 
-	plugin = nm_vpn_lookup_plugin (NULL, service_type, NULL);
+	plugin = nm_vpn_get_editor_plugin (service_type, NULL);
 	if (!plugin)
 		return FALSE;
 
@@ -194,7 +113,7 @@ nm_vpn_supports_ipv6 (NMConnection *connection)
 }
 
 const VpnPasswordName *
-nm_vpn_get_secret_names (const char *vpn_type)
+nm_vpn_get_secret_names (const char *service_type)
 {
 	const char *type;
 	static VpnPasswordName generic_vpn_secrets[] = { {"password", N_("Password")}, {NULL, NULL} };
@@ -213,14 +132,16 @@ nm_vpn_get_secret_names (const char *vpn_type)
 	                                                 {"gwcert", N_("Gateway certificate hash")},
 	                                                 {NULL, NULL} };
 
-	if (!vpn_type)
+	if (!service_type)
 		return NULL;
 
-	if (g_str_has_prefix (vpn_type, NM_DBUS_INTERFACE))
-		type = vpn_type + strlen (NM_DBUS_INTERFACE) + 1;
-	else
-		type = vpn_type;
+	if (   !g_str_has_prefix (service_type, NM_DBUS_INTERFACE)
+	    || service_type[NM_STRLEN (NM_DBUS_INTERFACE)] != '.') {
+		/* all our well-known, hard-coded vpn-types start with NM_DBUS_INTERFACE. */
+		return NULL;
+	}
 
+	type = service_type + (NM_STRLEN (NM_DBUS_INTERFACE) + 1);
 	if (   !g_strcmp0 (type, "pptp")
 	    || !g_strcmp0 (type, "iodine")
 	    || !g_strcmp0 (type, "ssh")
diff --git a/clients/common/nm-vpn-helpers.h b/clients/common/nm-vpn-helpers.h
index 79fc94e9..9c23f37c 100644
--- a/clients/common/nm-vpn-helpers.h
+++ b/clients/common/nm-vpn-helpers.h
@@ -21,25 +21,18 @@
 
 #include <NetworkManager.h>
 
-#include "nm-default.h"
-
 struct {
 	const char *name;
 	const char *ui_name;
 } typedef VpnPasswordName;
 
-GSList *nm_vpn_get_plugins (void);
-
-const char **nm_vpn_get_plugin_names (gboolean only_available_plugins);
-
-const char *nm_vpn_get_service_for_name (const char *name);
-char *      nm_vpn_get_service_for_name_default (const char *name);
+GSList *nm_vpn_get_plugin_infos (void);
 
-NMVpnEditorPlugin *nm_vpn_lookup_plugin (const char *name, const char *service, GError **error);
+NMVpnEditorPlugin *nm_vpn_get_editor_plugin (const char *service_type, GError **error);
 
 gboolean nm_vpn_supports_ipv6 (NMConnection *connection);
 
-const VpnPasswordName * nm_vpn_get_secret_names (const char *vpn_type);
+const VpnPasswordName * nm_vpn_get_secret_names (const char *service_type);
 
 gboolean nm_vpn_openconnect_authenticate_helper (const char *host,
                                                  char **cookie,