summaryrefslogtreecommitdiff
path: root/libnm-core/nm-vpn-plugin-info.c
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-06-07 11:10:23 +0200
committerThomas Haller <thaller@redhat.com>2016-06-15 10:32:32 +0200
commit57783347bd23d88d7313a36523ddd5c9ba13375d (patch)
treec47f4ca0f9d75402e7ef830c9ec94f51aabcd457 /libnm-core/nm-vpn-plugin-info.c
parenta2b34f7f126491215ef9de9c78289c0287ade05b (diff)
downloadNetworkManager-57783347bd23d88d7313a36523ddd5c9ba13375d.tar.gz
libnm/vpn: refactor nm_vpn_plugin_info_list_find_by_service() and prefer aliases first
Refactor code to add function _list_find_by_service(), which will be used in the next commit. A notable change is that we now search also through the aliases together with the service-name. That makes a difference, if one plugin privdes an "alias" which another plugin provides as "service". Due to that change, we would also find the aliased plugin first. In practice it shouldn't matter, because different plugins are not supposed to provide identical services.
Diffstat (limited to 'libnm-core/nm-vpn-plugin-info.c')
-rw-r--r--libnm-core/nm-vpn-plugin-info.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/libnm-core/nm-vpn-plugin-info.c b/libnm-core/nm-vpn-plugin-info.c
index d5e3dc0ba9..2f03431b07 100644
--- a/libnm-core/nm-vpn-plugin-info.c
+++ b/libnm-core/nm-vpn-plugin-info.c
@@ -573,10 +573,24 @@ nm_vpn_plugin_info_list_find_by_filename (GSList *list, const char *filename)
return NULL;
}
+static NMVpnPluginInfo *
+_list_find_by_service (GSList *list, const char *service)
+{
+ for (; list; list = list->next) {
+ NMVpnPluginInfoPrivate *priv = NM_VPN_PLUGIN_INFO_GET_PRIVATE (list->data);
+
+ if ( nm_streq (priv->service, service)
+ || _nm_utils_strv_find_first (priv->aliases, -1, service) >= 0)
+ return list->data;
+ }
+ return NULL;
+}
+
/**
* nm_vpn_plugin_info_list_find_by_service:
* @list: (element-type NMVpnPluginInfo): list of plugins
- * @service: service to search
+ * @service: service to search. This can be the main service-type
+ * or one of the provided aliases.
*
* Returns: (transfer none): the first plugin with a matching @service (or %NULL).
*
@@ -585,25 +599,9 @@ nm_vpn_plugin_info_list_find_by_filename (GSList *list, const char *filename)
NMVpnPluginInfo *
nm_vpn_plugin_info_list_find_by_service (GSList *list, const char *service)
{
- GSList *iter;
-
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_service (iter->data), 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 (_nm_utils_strv_find_first (aliases, -1, service) >= 0)
- return iter->data;
- }
- return NULL;
+ return _list_find_by_service (list, service);
}
/*********************************************************************/