mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-07-22 02:35:25 +00:00
all: use nm_utils_strv_find_first() from shared/nm-utils
This commit is contained in:
parent
a165907554
commit
11bc3f191e
|
@ -154,8 +154,6 @@ gssize _nm_utils_ptrarray_find_first (gconstpointer *list, gssize len, gconstpoi
|
|||
gssize _nm_utils_ptrarray_find_binary_search (gconstpointer *list, gsize len, gconstpointer needle, GCompareDataFunc cmpfcn, gpointer user_data);
|
||||
gssize _nm_utils_array_find_binary_search (gconstpointer list, gsize elem_size, gsize len, gconstpointer needle, GCompareDataFunc cmpfcn, gpointer user_data);
|
||||
|
||||
gssize _nm_utils_strv_find_first (char **list, gssize len, const char *needle);
|
||||
|
||||
char **_nm_utils_strv_cleanup (char **strv,
|
||||
gboolean strip_whitespace,
|
||||
gboolean skip_empty,
|
||||
|
|
|
@ -443,52 +443,6 @@ nm_utils_same_ssid (const guint8 *ssid1, gsize len1,
|
|||
return memcmp (ssid1, ssid2, len1) == 0 ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* _nm_utils_strv_find_first:
|
||||
* @list: the strv list to search
|
||||
* @len: the length of the list, or a negative value if @list is %NULL terminated.
|
||||
* @needle: the value to search for. The search is done using strcmp().
|
||||
*
|
||||
* Searches @list for @needle and returns the index of the first match (based
|
||||
* on strcmp()).
|
||||
*
|
||||
* For convenience, @list has type 'char**' instead of 'const char **'.
|
||||
*
|
||||
* Returns: index of first occurrence or -1 if @needle is not found in @list.
|
||||
*/
|
||||
gssize
|
||||
_nm_utils_strv_find_first (char **list, gssize len, const char *needle)
|
||||
{
|
||||
gssize i;
|
||||
|
||||
if (len > 0) {
|
||||
g_return_val_if_fail (list, -1);
|
||||
|
||||
if (!needle) {
|
||||
/* if we search a list with known length, %NULL is a valid @needle. */
|
||||
for (i = 0; i < len; i++) {
|
||||
if (!list[i])
|
||||
return i;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < len; i++) {
|
||||
if (list[i] && !strcmp (needle, list[i]))
|
||||
return i;
|
||||
}
|
||||
}
|
||||
} else if (len < 0) {
|
||||
g_return_val_if_fail (needle, -1);
|
||||
|
||||
if (list) {
|
||||
for (i = 0; list[i]; i++) {
|
||||
if (strcmp (needle, list[i]) == 0)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
char **
|
||||
_nm_utils_strv_cleanup (char **strv,
|
||||
gboolean strip_whitespace,
|
||||
|
@ -509,7 +463,7 @@ _nm_utils_strv_cleanup (char **strv,
|
|||
j = 0;
|
||||
for (i = 0; strv[i]; i++) {
|
||||
if ( (skip_empty && !*strv[i])
|
||||
|| (skip_repeated && _nm_utils_strv_find_first (strv, j, strv[i]) >= 0))
|
||||
|| (skip_repeated && nm_utils_strv_find_first (strv, j, strv[i]) >= 0))
|
||||
g_free (strv[i]);
|
||||
else
|
||||
strv[j++] = strv[i];
|
||||
|
|
|
@ -339,7 +339,7 @@ nm_vpn_plugin_info_list_load ()
|
|||
|
||||
for (i = 0; i < G_N_ELEMENTS (dir); i++) {
|
||||
if ( !dir[i]
|
||||
|| _nm_utils_strv_find_first ((char **) dir, i, dir[i]) >= 0)
|
||||
|| nm_utils_strv_find_first ((char **) dir, i, dir[i]) >= 0)
|
||||
continue;
|
||||
|
||||
infos = _nm_vpn_plugin_info_list_load_dir (dir[i], TRUE, uid, NULL, NULL);
|
||||
|
@ -384,7 +384,7 @@ nm_vpn_plugin_info_new_search_file (const char *name, const char *service)
|
|||
|
||||
for (i = 0; !plugin_info && i < G_N_ELEMENTS (dir); i++) {
|
||||
if ( !dir[i]
|
||||
|| _nm_utils_strv_find_first ((char **) dir, i, dir[i]) >= 0)
|
||||
|| nm_utils_strv_find_first ((char **) dir, i, dir[i]) >= 0)
|
||||
continue;
|
||||
|
||||
/* We still must load the entire directory while searching for the matching
|
||||
|
@ -400,8 +400,8 @@ nm_vpn_plugin_info_new_search_file (const char *name, const char *service)
|
|||
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))
|
||||
&& (nm_utils_strv_find_first (NM_VPN_PLUGIN_INFO_GET_PRIVATE (p)->aliases,
|
||||
-1, service) < 0))
|
||||
continue;
|
||||
plugin_info = g_object_ref (p);
|
||||
break;
|
||||
|
@ -580,7 +580,7 @@ _list_find_by_service (GSList *list, const char *service)
|
|||
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)
|
||||
|| nm_utils_strv_find_first (priv->aliases, -1, service) >= 0)
|
||||
return list->data;
|
||||
}
|
||||
return NULL;
|
||||
|
@ -667,7 +667,7 @@ nm_vpn_plugin_info_list_find_service_type (GSList *list, const char *name)
|
|||
|
||||
/* check the hard-coded list of short-names. They all have have the same
|
||||
* well-known prefix org.freedesktop.NetworkManager and the name. */
|
||||
if (_nm_utils_strv_find_first ((char **) known_names, G_N_ELEMENTS (known_names), name) >= 0)
|
||||
if (nm_utils_strv_find_first ((char **) known_names, G_N_ELEMENTS (known_names), name) >= 0)
|
||||
return g_strdup_printf ("%s.%s", NM_DBUS_INTERFACE, name);
|
||||
|
||||
/* try, if there exists a plugin with @name under org.freedesktop.NetworkManager.
|
||||
|
|
|
@ -8363,7 +8363,7 @@ _hash_check_invalid_keys_impl (GHashTable *hash, const char *setting_name, GErro
|
|||
|
||||
g_hash_table_iter_init (&iter, hash);
|
||||
while (g_hash_table_iter_next (&iter, (gpointer *) &k, NULL)) {
|
||||
if (_nm_utils_strv_find_first ((char **) argv, -1, k) < 0) {
|
||||
if (nm_utils_strv_find_first ((char **) argv, -1, k) < 0) {
|
||||
first_invalid_key = k;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1634,9 +1634,9 @@ _resolvconf_resolved_managed (void)
|
|||
NULL, NULL);
|
||||
|
||||
if (info && g_file_info_get_is_symlink (info)) {
|
||||
ret = _nm_utils_strv_find_first ((gchar **) resolved_paths,
|
||||
G_N_ELEMENTS (resolved_paths),
|
||||
g_file_info_get_symlink_target (info)) >= 0;
|
||||
ret = nm_utils_strv_find_first ((gchar **) resolved_paths,
|
||||
G_N_ELEMENTS (resolved_paths),
|
||||
g_file_info_get_symlink_target (info)) >= 0;
|
||||
}
|
||||
|
||||
g_clear_object(&info);
|
||||
|
|
|
@ -1472,7 +1472,7 @@ set_property (GObject *object,
|
|||
for (i = 0; value_arr && value_arr[i]; i++) {
|
||||
if ( *value_arr[i]
|
||||
&& nm_utils_hwaddr_valid (value_arr[i], -1)
|
||||
&& _nm_utils_strv_find_first (value_arr, i, value_arr[i]) < 0) {
|
||||
&& nm_utils_strv_find_first (value_arr, i, value_arr[i]) < 0) {
|
||||
priv->no_auto_default.arr[j++] = g_strdup (value_arr[i]);
|
||||
priv->no_auto_default.specs = g_slist_prepend (priv->no_auto_default.specs, g_strdup_printf ("mac:%s", value_arr[i]));
|
||||
}
|
||||
|
|
|
@ -309,7 +309,7 @@ no_auto_default_from_file (const char *no_auto_default_file)
|
|||
for (i = 0; list[i]; i++) {
|
||||
if ( *list[i]
|
||||
&& nm_utils_hwaddr_valid (list[i], -1)
|
||||
&& _nm_utils_strv_find_first (list, i, list[i]) < 0)
|
||||
&& nm_utils_strv_find_first (list, i, list[i]) < 0)
|
||||
g_ptr_array_add (no_auto_default_new, list[i]);
|
||||
else
|
||||
g_free (list[i]);
|
||||
|
@ -369,7 +369,7 @@ nm_config_set_no_auto_default_for_device (NMConfig *self, NMDevice *device)
|
|||
|
||||
no_auto_default_current = nm_config_data_get_no_auto_default (priv->config_data);
|
||||
|
||||
if (_nm_utils_strv_find_first ((char **) no_auto_default_current, -1, hw_address) >= 0) {
|
||||
if (nm_utils_strv_find_first ((char **) no_auto_default_current, -1, hw_address) >= 0) {
|
||||
/* @hw_address is already blocked. We don't have to update our in-memory representation.
|
||||
* Maybe we should write to no_auto_default_file anew, but let's save that too. */
|
||||
return;
|
||||
|
@ -750,13 +750,13 @@ read_config (GKeyFile *keyfile, gboolean is_base_config, const char *dirname, co
|
|||
|
||||
for (iter_val = old_val; iter_val && *iter_val; iter_val++) {
|
||||
if ( last_char != '-'
|
||||
|| _nm_utils_strv_find_first (new_val, -1, *iter_val) < 0)
|
||||
|| nm_utils_strv_find_first (new_val, -1, *iter_val) < 0)
|
||||
g_ptr_array_add (new, g_strdup (*iter_val));
|
||||
}
|
||||
for (iter_val = new_val; iter_val && *iter_val; iter_val++) {
|
||||
/* don't add duplicates. That means an "option=a,b"; "option+=a,c" results in "option=a,b,c" */
|
||||
if ( last_char == '+'
|
||||
&& _nm_utils_strv_find_first (old_val, -1, *iter_val) < 0)
|
||||
&& nm_utils_strv_find_first (old_val, -1, *iter_val) < 0)
|
||||
g_ptr_array_add (new, *iter_val);
|
||||
else
|
||||
g_free (*iter_val);
|
||||
|
@ -953,8 +953,8 @@ read_entire_config (const NMConfigCmdLineOptions *cli,
|
|||
const char *filename = system_confs->pdata[i];
|
||||
|
||||
/* if a same named file exists in config_dir or run_config_dir, skip it. */
|
||||
if (_nm_utils_strv_find_first ((char **) confs->pdata, confs->len, filename) >= 0 ||
|
||||
_nm_utils_strv_find_first ((char **) run_confs->pdata, run_confs->len, filename) >= 0) {
|
||||
if (nm_utils_strv_find_first ((char **) confs->pdata, confs->len, filename) >= 0 ||
|
||||
nm_utils_strv_find_first ((char **) run_confs->pdata, run_confs->len, filename) >= 0) {
|
||||
g_ptr_array_remove_index (system_confs, i);
|
||||
continue;
|
||||
}
|
||||
|
@ -968,7 +968,7 @@ read_entire_config (const NMConfigCmdLineOptions *cli,
|
|||
const char *filename = run_confs->pdata[i];
|
||||
|
||||
/* if a same named file exists in config_dir, skip it. */
|
||||
if (_nm_utils_strv_find_first ((char **) confs->pdata, confs->len, filename) >= 0) {
|
||||
if (nm_utils_strv_find_first ((char **) confs->pdata, confs->len, filename) >= 0) {
|
||||
g_ptr_array_remove_index (run_confs, i);
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -1822,7 +1822,7 @@ nm_ip4_config_add_search (NMIP4Config *config, const char *new)
|
|||
return;
|
||||
}
|
||||
|
||||
if (_nm_utils_strv_find_first ((char **) priv->searches->pdata,
|
||||
if (nm_utils_strv_find_first ((char **) priv->searches->pdata,
|
||||
priv->searches->len, search) >= 0) {
|
||||
g_free (search);
|
||||
return;
|
||||
|
|
|
@ -1742,7 +1742,7 @@ nm_ip6_config_add_search (NMIP6Config *config, const char *new)
|
|||
return;
|
||||
}
|
||||
|
||||
if (_nm_utils_strv_find_first ((char **) priv->searches->pdata,
|
||||
if (nm_utils_strv_find_first ((char **) priv->searches->pdata,
|
||||
priv->searches->len, search) >= 0) {
|
||||
g_free (search);
|
||||
return;
|
||||
|
|
|
@ -809,8 +809,8 @@ load_plugins (NMSettings *self, const char **plugins, GError **error)
|
|||
gboolean has_no_ibft;
|
||||
gssize idx_no_ibft, idx_ibft;
|
||||
|
||||
idx_ibft = _nm_utils_strv_find_first ((char **) plugins, -1, "ibft");
|
||||
idx_no_ibft = _nm_utils_strv_find_first ((char **) plugins, -1, "no-ibft");
|
||||
idx_ibft = nm_utils_strv_find_first ((char **) plugins, -1, "ibft");
|
||||
idx_no_ibft = nm_utils_strv_find_first ((char **) plugins, -1, "no-ibft");
|
||||
has_no_ibft = idx_no_ibft >= 0 && idx_no_ibft > idx_ibft;
|
||||
#if WITH_SETTINGS_PLUGIN_IBFT
|
||||
add_ibft = idx_no_ibft < 0 && idx_ibft < 0;
|
||||
|
@ -844,9 +844,9 @@ load_plugins (NMSettings *self, const char **plugins, GError **error)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (_nm_utils_strv_find_first ((char **) plugins,
|
||||
iter - plugins,
|
||||
pname) >= 0) {
|
||||
if (nm_utils_strv_find_first ((char **) plugins,
|
||||
iter - plugins,
|
||||
pname) >= 0) {
|
||||
/* the plugin is already mentioned in the list previously.
|
||||
* Don't load a duplicate. */
|
||||
continue;
|
||||
|
|
Loading…
Reference in a new issue