mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-04 15:40:22 +01:00
libnm: reuse _list_find_by_service() for searching NMVpnPluginInfo
This commit is contained in:
parent
2b814f4e87
commit
67c00353d3
1 changed files with 31 additions and 34 deletions
|
|
@ -52,6 +52,12 @@ G_DEFINE_TYPE_WITH_CODE (NMVpnPluginInfo, nm_vpn_plugin_info, G_TYPE_OBJECT,
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
static NMVpnPluginInfo *_list_find_by_service (GSList *list,
|
||||||
|
const char *name,
|
||||||
|
const char *service);
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nm_vpn_plugin_info_validate_filename:
|
* nm_vpn_plugin_info_validate_filename:
|
||||||
* @filename: the filename to check
|
* @filename: the filename to check
|
||||||
|
|
@ -351,33 +357,16 @@ nm_vpn_plugin_info_list_load ()
|
||||||
NMVpnPluginInfo *
|
NMVpnPluginInfo *
|
||||||
nm_vpn_plugin_info_new_search_file (const char *name, const char *service)
|
nm_vpn_plugin_info_new_search_file (const char *name, const char *service)
|
||||||
{
|
{
|
||||||
NMVpnPluginInfo *plugin_info = NULL;
|
NMVpnPluginInfo *info;
|
||||||
GSList *infos;
|
GSList *infos;
|
||||||
GSList *info;
|
|
||||||
|
|
||||||
if (!name && !service)
|
if (!name && !service)
|
||||||
g_return_val_if_reached (NULL);
|
g_return_val_if_reached (NULL);
|
||||||
|
|
||||||
infos = nm_vpn_plugin_info_list_load ();
|
infos = nm_vpn_plugin_info_list_load ();
|
||||||
|
info = nm_g_object_ref (_list_find_by_service (infos, name, service));
|
||||||
for (info = infos; info; info = info->next) {
|
|
||||||
NMVpnPluginInfo *p = info->data;
|
|
||||||
|
|
||||||
if ( name
|
|
||||||
&& !nm_streq (nm_vpn_plugin_info_get_name (p), name))
|
|
||||||
continue;
|
|
||||||
if ( service
|
|
||||||
&& !nm_streq (nm_vpn_plugin_info_get_service (p), service)
|
|
||||||
&& (nm_utils_strv_find_first (NM_VPN_PLUGIN_INFO_GET_PRIVATE (p)->aliases,
|
|
||||||
-1, service) < 0))
|
|
||||||
continue;
|
|
||||||
plugin_info = g_object_ref (p);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_slist_free_full (infos, g_object_unref);
|
g_slist_free_full (infos, g_object_unref);
|
||||||
|
return info;
|
||||||
return plugin_info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
@ -542,14 +531,22 @@ nm_vpn_plugin_info_list_find_by_filename (GSList *list, const char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
static NMVpnPluginInfo *
|
static NMVpnPluginInfo *
|
||||||
_list_find_by_service (GSList *list, const char *service)
|
_list_find_by_service (GSList *list,
|
||||||
|
const char *name,
|
||||||
|
const char *service)
|
||||||
{
|
{
|
||||||
for (; list; list = list->next) {
|
for (; list; list = list->next) {
|
||||||
NMVpnPluginInfoPrivate *priv = NM_VPN_PLUGIN_INFO_GET_PRIVATE (list->data);
|
NMVpnPluginInfoPrivate *priv = NM_VPN_PLUGIN_INFO_GET_PRIVATE (list->data);
|
||||||
|
|
||||||
if ( nm_streq (priv->service, service)
|
if ( name
|
||||||
|| nm_utils_strv_find_first (priv->aliases, -1, service) >= 0)
|
&& !nm_streq (name, priv->name))
|
||||||
return list->data;
|
continue;
|
||||||
|
if ( service
|
||||||
|
&& !nm_streq (priv->service, service)
|
||||||
|
&& (nm_utils_strv_find_first (priv->aliases, -1, service) < 0))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
return list->data;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -569,7 +566,7 @@ nm_vpn_plugin_info_list_find_by_service (GSList *list, const char *service)
|
||||||
{
|
{
|
||||||
if (!service)
|
if (!service)
|
||||||
g_return_val_if_reached (NULL);
|
g_return_val_if_reached (NULL);
|
||||||
return _list_find_by_service (list, service);
|
return _list_find_by_service (list, NULL, service);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* known_names are well known short names for the service-type. They all implicitly
|
/* known_names are well known short names for the service-type. They all implicitly
|
||||||
|
|
@ -612,26 +609,26 @@ static const char *known_names[] = {
|
||||||
char *
|
char *
|
||||||
nm_vpn_plugin_info_list_find_service_type (GSList *list, const char *name)
|
nm_vpn_plugin_info_list_find_service_type (GSList *list, const char *name)
|
||||||
{
|
{
|
||||||
GSList *iter;
|
NMVpnPluginInfo *info;
|
||||||
char *n;
|
char *n;
|
||||||
|
|
||||||
if (!name)
|
if (!name)
|
||||||
g_return_val_if_reached (NULL);
|
g_return_val_if_reached (NULL);
|
||||||
if (!*name)
|
if (!*name)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (!list)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
/* First, try to interpret @name as a full service-type (or alias). */
|
/* First, try to interpret @name as a full service-type (or alias). */
|
||||||
if (_list_find_by_service (list, name))
|
info = _list_find_by_service (list, NULL, name);
|
||||||
|
if (info)
|
||||||
return g_strdup (name);
|
return g_strdup (name);
|
||||||
|
|
||||||
/* try to interpret @name as plugin name, in which case we return
|
/* try to interpret @name as plugin name, in which case we return
|
||||||
* the main service-type (not an alias). */
|
* the main service-type (not an alias). */
|
||||||
for (iter = list; iter; iter = iter->next) {
|
info = _list_find_by_service (list, name, NULL);
|
||||||
NMVpnPluginInfoPrivate *priv = NM_VPN_PLUGIN_INFO_GET_PRIVATE (iter->data);
|
if (info)
|
||||||
|
return g_strdup (NM_VPN_PLUGIN_INFO_GET_PRIVATE (info)->service);
|
||||||
if (nm_streq (priv->name, name))
|
|
||||||
return g_strdup (priv->service);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check the hard-coded list of short-names. They all have have the same
|
/* check the hard-coded list of short-names. They all have have the same
|
||||||
* well-known prefix org.freedesktop.NetworkManager and the name. */
|
* well-known prefix org.freedesktop.NetworkManager and the name. */
|
||||||
|
|
@ -641,7 +638,7 @@ nm_vpn_plugin_info_list_find_service_type (GSList *list, const char *name)
|
||||||
/* try, if there exists a plugin with @name under org.freedesktop.NetworkManager.
|
/* try, if there exists a plugin with @name under org.freedesktop.NetworkManager.
|
||||||
* Allow this to be a valid abbreviation. */
|
* Allow this to be a valid abbreviation. */
|
||||||
n = g_strdup_printf ("%s.%s", NM_DBUS_INTERFACE, name);
|
n = g_strdup_printf ("%s.%s", NM_DBUS_INTERFACE, name);
|
||||||
if (_list_find_by_service (list, n))
|
if (_list_find_by_service (list, NULL, n))
|
||||||
return n;
|
return n;
|
||||||
g_free (n);
|
g_free (n);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue