From 3517084b92aa64817ce8cd82163e5ab6e1947017 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Sun, 1 Nov 2015 11:58:49 +0100 Subject: [PATCH 1/2] vpn-plugin-info: drop nm_vpn_plugin_info_get_service() It is not used externally and its use might be confusing and undesired when we add plugin aliases. The external users should only use the name when idenfiying the plugin and nm_vpn_plugin_info_list_find_by_service() when matchin the plugin. --- libnm-core/nm-vpn-plugin-info.c | 20 ++------------------ libnm-core/nm-vpn-plugin-info.h | 2 -- libnm/libnm.ver | 1 - src/vpn-manager/nm-vpn-connection.c | 1 - 4 files changed, 2 insertions(+), 22 deletions(-) diff --git a/libnm-core/nm-vpn-plugin-info.c b/libnm-core/nm-vpn-plugin-info.c index 6cd1eb8ca3..a059f2ec5b 100644 --- a/libnm-core/nm-vpn-plugin-info.c +++ b/libnm-core/nm-vpn-plugin-info.c @@ -526,7 +526,7 @@ nm_vpn_plugin_info_list_find_by_service (GSList *list, const char *service) g_return_val_if_reached (NULL); for (iter = list; iter; iter = iter->next) { - if (strcmp (nm_vpn_plugin_info_get_service (iter->data), service) == 0) + if (strcmp (NM_VPN_PLUGIN_INFO_GET_PRIVATE (iter->data)->service, service) == 0) return iter->data; } return NULL; @@ -566,22 +566,6 @@ nm_vpn_plugin_info_get_name (NMVpnPluginInfo *self) return NM_VPN_PLUGIN_INFO_GET_PRIVATE (self)->name; } -/** - * nm_vpn_plugin_info_get_service: - * @self: plugin info instance - * - * Returns: (transfer none): the service. Cannot be %NULL. - * - * Since: 1.2 - */ -const char * -nm_vpn_plugin_info_get_service (NMVpnPluginInfo *self) -{ - g_return_val_if_fail (NM_IS_VPN_PLUGIN_INFO (self), NULL); - - return NM_VPN_PLUGIN_INFO_GET_PRIVATE (self)->service; -} - /** * nm_vpn_plugin_info_get_plugin: * @self: plugin info instance @@ -760,7 +744,7 @@ nm_vpn_plugin_info_load_editor_plugin (NMVpnPluginInfo *self, GError **error) priv->editor_plugin_loaded = TRUE; priv->editor_plugin = nm_vpn_editor_plugin_load_from_file (plugin_filename, - nm_vpn_plugin_info_get_service (self), + priv->service, getuid (), NULL, NULL, diff --git a/libnm-core/nm-vpn-plugin-info.h b/libnm-core/nm-vpn-plugin-info.h index ead6fb708b..667a4fe2d9 100644 --- a/libnm-core/nm-vpn-plugin-info.h +++ b/libnm-core/nm-vpn-plugin-info.h @@ -75,8 +75,6 @@ const char *nm_vpn_plugin_info_get_name (NMVpnPluginInfo *self); NM_AVAILABLE_IN_1_2 const char *nm_vpn_plugin_info_get_filename (NMVpnPluginInfo *self); NM_AVAILABLE_IN_1_2 -const char *nm_vpn_plugin_info_get_service (NMVpnPluginInfo *self); -NM_AVAILABLE_IN_1_2 const char *nm_vpn_plugin_info_get_plugin (NMVpnPluginInfo *self); NM_AVAILABLE_IN_1_2 const char *nm_vpn_plugin_info_get_program (NMVpnPluginInfo *self); diff --git a/libnm/libnm.ver b/libnm/libnm.ver index 5bf877a811..71ae69f3aa 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -906,7 +906,6 @@ global: nm_vpn_plugin_info_get_name; nm_vpn_plugin_info_get_plugin; nm_vpn_plugin_info_get_program; - nm_vpn_plugin_info_get_service; nm_vpn_plugin_info_get_type; nm_vpn_plugin_info_load_editor_plugin; nm_vpn_plugin_info_lookup_property; diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c index b3ac9d3e05..0c0ac1c740 100644 --- a/src/vpn-manager/nm-vpn-connection.c +++ b/src/vpn-manager/nm-vpn-connection.c @@ -2046,7 +2046,6 @@ nm_vpn_connection_activate (NMVpnConnection *self, g_return_if_fail (s_vpn); service = nm_setting_vpn_get_service_type (s_vpn); - g_return_if_fail (!g_strcmp0 (service, nm_vpn_plugin_info_get_service (plugin_info))); if (nm_vpn_plugin_info_supports_multiple (plugin_info)) { const char *path; From cde053c0b055bf7e306dcdd45ed80d42c894a8ba Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Sun, 1 Nov 2015 13:01:58 +0100 Subject: [PATCH 2/2] vpn-plugin-info: add vpn plugin service aliases --- libnm-core/nm-vpn-plugin-info.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libnm-core/nm-vpn-plugin-info.c b/libnm-core/nm-vpn-plugin-info.c index a059f2ec5b..3a4796b9b5 100644 --- a/libnm-core/nm-vpn-plugin-info.c +++ b/libnm-core/nm-vpn-plugin-info.c @@ -48,6 +48,7 @@ typedef struct { char *filename; char *name; char *service; + char **aliases; GKeyFile *keyfile; /* It is convenient for nm_vpn_plugin_info_lookup_property() to return a const char *, @@ -426,7 +427,7 @@ nm_vpn_plugin_info_list_add (GSList **list, NMVpnPluginInfo *plugin_info, GError } /* the plugin must have unique values for certain properties. E.g. two different - * plugins cannot share the same D-Bus service name. */ + * plugins cannot share the same service name. */ if (!_check_no_conflict (plugin_info, iter->data, error)) return FALSE; } @@ -525,10 +526,21 @@ nm_vpn_plugin_info_list_find_by_service (GSList *list, const char *service) if (!service) g_return_val_if_reached (NULL); + /* First, consider the primary service name. */ for (iter = list; iter; iter = iter->next) { if (strcmp (NM_VPN_PLUGIN_INFO_GET_PRIVATE (iter->data)->service, service) == 0) return iter->data; } + + /* Then look into the aliases. */ + for (iter = list; iter; iter = iter->next) { + char **aliases = (NM_VPN_PLUGIN_INFO_GET_PRIVATE (iter->data))->aliases; + + if (!aliases) + continue; + if (_nm_utils_strv_find_first (aliases, -1, service) >= 0) + return iter->data; + } return NULL; } @@ -855,6 +867,8 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) return FALSE; } + priv->aliases = g_key_file_get_string_list (priv->keyfile, NM_VPN_PLUGIN_INFO_KF_GROUP_CONNECTION, "aliases", NULL, NULL); + priv->keys = g_hash_table_new_full (_nm_utils_strstrdictkey_hash, _nm_utils_strstrdictkey_equal, g_free, g_free); @@ -935,6 +949,7 @@ finalize (GObject *object) g_free (priv->name); g_free (priv->service); + g_strfreev (priv->aliases); g_free (priv->filename); g_key_file_unref (priv->keyfile); g_hash_table_unref (priv->keys);