all: replace _nm_utils_string_in_list() with g_strv_contains()

This commit is contained in:
Thomas Haller 2016-06-17 11:40:50 +02:00
parent caeaa78918
commit bc1014a93d
18 changed files with 60 additions and 77 deletions

View file

@ -145,9 +145,6 @@ gssize _nm_utils_ptrarray_find_first (gpointer *list, gssize len, gconstpointer
gssize _nm_utils_ptrarray_find_binary_search (gpointer *list, gsize len, gpointer needle, GCompareDataFunc cmpfcn, gpointer user_data);
gboolean _nm_utils_string_in_list (const char *str,
const char **valid_strings);
gssize _nm_utils_strv_find_first (char **list, gssize len, const char *needle);
char **_nm_utils_strv_cleanup (char **strv,

View file

@ -2776,7 +2776,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
}
}
if (priv->phase1_peapver && !_nm_utils_string_in_list (priv->phase1_peapver, valid_phase1_peapver)) {
if (priv->phase1_peapver && !g_strv_contains (valid_phase1_peapver, priv->phase1_peapver)) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
@ -2786,7 +2786,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
return FALSE;
}
if (priv->phase1_peaplabel && !_nm_utils_string_in_list (priv->phase1_peaplabel, valid_phase1_peaplabel)) {
if (priv->phase1_peaplabel && !g_strv_contains (valid_phase1_peaplabel, priv->phase1_peaplabel)) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
@ -2796,7 +2796,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
return FALSE;
}
if (priv->phase1_fast_provisioning && !_nm_utils_string_in_list (priv->phase1_fast_provisioning, valid_phase1_fast_pac)) {
if (priv->phase1_fast_provisioning && !g_strv_contains (valid_phase1_fast_pac, priv->phase1_fast_provisioning)) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
@ -2806,7 +2806,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
return FALSE;
}
if (priv->phase2_auth && !_nm_utils_string_in_list (priv->phase2_auth, valid_phase2_auth)) {
if (priv->phase2_auth && !g_strv_contains (valid_phase2_auth, priv->phase2_auth)) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
@ -2816,7 +2816,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
return FALSE;
}
if (priv->phase2_autheap && !_nm_utils_string_in_list (priv->phase2_autheap, valid_phase2_autheap)) {
if (priv->phase2_autheap && !g_strv_contains (valid_phase2_autheap, priv->phase2_autheap)) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,

View file

@ -504,7 +504,7 @@ nm_setting_wired_add_s390_option (NMSettingWired *setting,
g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), FALSE);
g_return_val_if_fail (key != NULL, FALSE);
g_return_val_if_fail (strlen (key), FALSE);
g_return_val_if_fail (_nm_utils_string_in_list (key, valid_s390_opts), FALSE);
g_return_val_if_fail (g_strv_contains (valid_s390_opts, key), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
value_len = strlen (value);
@ -612,7 +612,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
const char *key, *value;
int i;
if (priv->port && !_nm_utils_string_in_list (priv->port, valid_ports)) {
if (priv->port && !g_strv_contains (valid_ports, priv->port)) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
@ -622,7 +622,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
return FALSE;
}
if (priv->duplex && !_nm_utils_string_in_list (priv->duplex, valid_duplex)) {
if (priv->duplex && !g_strv_contains (valid_duplex, priv->duplex)) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
@ -668,7 +668,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
}
}
if (priv->s390_nettype && !_nm_utils_string_in_list (priv->s390_nettype, valid_nettype)) {
if (priv->s390_nettype && !g_strv_contains (valid_nettype, priv->s390_nettype)) {
g_set_error_literal (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
@ -679,7 +679,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
g_hash_table_iter_init (&iter, priv->s390_options);
while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value)) {
if ( !_nm_utils_string_in_list (key, valid_s390_opts)
if ( !g_strv_contains (valid_s390_opts, key)
|| !strlen (value)
|| (strlen (value) > 200)) {
g_set_error (error,

View file

@ -863,7 +863,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
return FALSE;
}
if (!_nm_utils_string_in_list (priv->key_mgmt, valid_key_mgmt)) {
if (!g_strv_contains (valid_key_mgmt, priv->key_mgmt)) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
@ -936,7 +936,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
return FALSE;
}
if (priv->auth_alg && !_nm_utils_string_in_list (priv->auth_alg, valid_auth_algs)) {
if (priv->auth_alg && !g_strv_contains (valid_auth_algs, priv->auth_alg)) {
g_set_error_literal (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
@ -958,7 +958,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
const char *wpa_none[] = { "wpa-none", NULL };
/* For ad-hoc connections, pairwise must be "none" */
if (_nm_utils_string_in_list (priv->key_mgmt, wpa_none)) {
if (g_strv_contains (wpa_none, priv->key_mgmt)) {
GSList *iter;
gboolean found = FALSE;

View file

@ -741,7 +741,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
return FALSE;
}
if (priv->mode && !_nm_utils_string_in_list (priv->mode, valid_modes)) {
if (priv->mode && !g_strv_contains (valid_modes, priv->mode)) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
@ -751,7 +751,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
return FALSE;
}
if (priv->band && !_nm_utils_string_in_list (priv->band, valid_bands)) {
if (priv->band && !g_strv_contains (valid_bands, priv->band)) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,

View file

@ -442,12 +442,6 @@ nm_utils_same_ssid (const guint8 *ssid1, gsize len1,
return memcmp (ssid1, ssid2, len1) == 0 ? TRUE : FALSE;
}
gboolean
_nm_utils_string_in_list (const char *str, const char **valid_strings)
{
return _nm_utils_strv_find_first ((char **) valid_strings, -1, str) >= 0;
}
/**
* _nm_utils_strv_find_first:
* @list: the strv list to search
@ -530,7 +524,7 @@ _nm_utils_string_slist_validate (GSList *list, const char **valid_values)
GSList *iter;
for (iter = list; iter; iter = iter->next) {
if (!_nm_utils_string_in_list ((char *) iter->data, valid_values))
if (!g_strv_contains (valid_values, (char *) iter->data))
return FALSE;
}

View file

@ -2707,7 +2707,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
}
}
if (priv->phase1_peapver && !_nm_utils_string_in_list (priv->phase1_peapver, valid_phase1_peapver)) {
if (priv->phase1_peapver && !g_strv_contains (valid_phase1_peapver, priv->phase1_peapver)) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
@ -2717,7 +2717,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
if (priv->phase1_peaplabel && !_nm_utils_string_in_list (priv->phase1_peaplabel, valid_phase1_peaplabel)) {
if (priv->phase1_peaplabel && !g_strv_contains (valid_phase1_peaplabel, priv->phase1_peaplabel)) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
@ -2727,7 +2727,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
if (priv->phase1_fast_provisioning && !_nm_utils_string_in_list (priv->phase1_fast_provisioning, valid_phase1_fast_pac)) {
if (priv->phase1_fast_provisioning && !g_strv_contains (valid_phase1_fast_pac, priv->phase1_fast_provisioning)) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
@ -2737,7 +2737,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
if (priv->phase2_auth && !_nm_utils_string_in_list (priv->phase2_auth, valid_phase2_auth)) {
if (priv->phase2_auth && !g_strv_contains (valid_phase2_auth, priv->phase2_auth)) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
@ -2747,7 +2747,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
if (priv->phase2_autheap && !_nm_utils_string_in_list (priv->phase2_autheap, valid_phase2_autheap)) {
if (priv->phase2_autheap && !g_strv_contains (valid_phase2_autheap, priv->phase2_autheap)) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,

View file

@ -534,7 +534,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
return FALSE;
}
if (!_nm_utils_string_in_list (value, valid_modes)) {
if (!g_strv_contains (valid_modes, value)) {
g_set_error (error,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_INVALID_OPTION,

View file

@ -539,7 +539,7 @@ nm_setting_wired_add_s390_option (NMSettingWired *setting,
g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), FALSE);
g_return_val_if_fail (key != NULL, FALSE);
g_return_val_if_fail (strlen (key), FALSE);
g_return_val_if_fail (_nm_utils_string_in_list (key, valid_s390_opts), FALSE);
g_return_val_if_fail (g_strv_contains (valid_s390_opts, key), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
value_len = strlen (value);
@ -606,7 +606,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
GSList* mac_blacklist_iter;
const char *key, *value;
if (priv->port && !_nm_utils_string_in_list (priv->port, valid_ports)) {
if (priv->port && !g_strv_contains (valid_ports, priv->port)) {
g_set_error (error,
NM_SETTING_WIRED_ERROR,
NM_SETTING_WIRED_ERROR_INVALID_PROPERTY,
@ -616,7 +616,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
if (priv->duplex && !_nm_utils_string_in_list (priv->duplex, valid_duplex)) {
if (priv->duplex && !g_strv_contains (valid_duplex, priv->duplex)) {
g_set_error (error,
NM_SETTING_WIRED_ERROR,
NM_SETTING_WIRED_ERROR_INVALID_PROPERTY,
@ -660,7 +660,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
if (priv->s390_nettype && !_nm_utils_string_in_list (priv->s390_nettype, valid_nettype)) {
if (priv->s390_nettype && !g_strv_contains (valid_nettype, priv->s390_nettype)) {
g_set_error_literal (error,
NM_SETTING_WIRED_ERROR,
NM_SETTING_WIRED_ERROR_INVALID_PROPERTY,
@ -671,7 +671,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
g_hash_table_iter_init (&iter, priv->s390_options);
while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value)) {
if ( !_nm_utils_string_in_list (key, valid_s390_opts)
if ( !g_strv_contains (valid_s390_opts, key)
|| !strlen (value)
|| (strlen (value) > 200)) {
g_set_error (error,

View file

@ -893,7 +893,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
if (!_nm_utils_string_in_list (priv->key_mgmt, valid_key_mgmt)) {
if (!g_strv_contains (valid_key_mgmt, priv->key_mgmt)) {
g_set_error (error,
NM_SETTING_WIRELESS_SECURITY_ERROR,
NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY,
@ -966,7 +966,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
if (priv->auth_alg && !_nm_utils_string_in_list (priv->auth_alg, valid_auth_algs)) {
if (priv->auth_alg && !g_strv_contains (valid_auth_algs, priv->auth_alg)) {
g_set_error_literal (error,
NM_SETTING_WIRELESS_SECURITY_ERROR,
NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY,
@ -988,7 +988,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
const char *wpa_none[] = { "wpa-none", NULL };
/* For ad-hoc connections, pairwise must be "none" */
if (_nm_utils_string_in_list (priv->key_mgmt, wpa_none)) {
if (g_strv_contains (wpa_none, priv->key_mgmt)) {
GSList *iter;
gboolean found = FALSE;

View file

@ -780,7 +780,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
if (priv->mode && !_nm_utils_string_in_list (priv->mode, valid_modes)) {
if (priv->mode && !g_strv_contains (valid_modes, priv->mode)) {
g_set_error (error,
NM_SETTING_WIRELESS_ERROR,
NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY,
@ -790,7 +790,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
if (priv->band && !_nm_utils_string_in_list (priv->band, valid_bands)) {
if (priv->band && !g_strv_contains (valid_bands, priv->band)) {
g_set_error (error,
NM_SETTING_WIRELESS_ERROR,
NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY,

View file

@ -23,9 +23,6 @@
#include "nm-setting-private.h"
gboolean _nm_utils_string_in_list (const char *str,
const char **valid_strings);
gboolean _nm_utils_string_slist_validate (GSList *list,
const char **valid_values);

View file

@ -516,25 +516,13 @@ nm_utils_slist_free (GSList *list, GDestroyNotify elem_destroy_fn)
g_slist_free_full (list, elem_destroy_fn);
}
gboolean
_nm_utils_string_in_list (const char *str, const char **valid_strings)
{
int i;
for (i = 0; valid_strings[i]; i++)
if (strcmp (str, valid_strings[i]) == 0)
break;
return valid_strings[i] != NULL;
}
gboolean
_nm_utils_string_slist_validate (GSList *list, const char **valid_values)
{
GSList *iter;
for (iter = list; iter; iter = iter->next) {
if (!_nm_utils_string_in_list ((char *) iter->data, valid_values))
if (!g_strv_contains (valid_values, (char *) iter->data))
return FALSE;
}

View file

@ -182,7 +182,7 @@ object_manager_interfaces_removed (GDBusProxy *proxy,
const char **ifaces,
NMBluez5Manager *self)
{
if (_nm_utils_string_in_list (BLUEZ5_DEVICE_INTERFACE, ifaces))
if (ifaces && g_strv_contains (ifaces, BLUEZ5_DEVICE_INTERFACE))
device_removed (proxy, path, self);
}

View file

@ -3361,11 +3361,11 @@ nm_device_can_assume_active_connection (NMDevice *self)
return FALSE;
method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP6_CONFIG);
if (!_nm_utils_string_in_list (method, assumable_ip6_methods))
if (!g_strv_contains (assumable_ip6_methods, method))
return FALSE;
method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
if (!_nm_utils_string_in_list (method, assumable_ip4_methods))
if (!g_strv_contains (assumable_ip4_methods, method))
return FALSE;
return TRUE;
@ -5021,7 +5021,7 @@ connection_ip4_method_requires_carrier (NMConnection *connection,
if (out_ip4_enabled)
*out_ip4_enabled = !!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED);
return _nm_utils_string_in_list (method, ip4_carrier_methods);
return g_strv_contains (ip4_carrier_methods, method);
}
static gboolean
@ -5038,7 +5038,7 @@ connection_ip6_method_requires_carrier (NMConnection *connection,
if (out_ip6_enabled)
*out_ip6_enabled = !!strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE);
return _nm_utils_string_in_list (method, ip6_carrier_methods);
return g_strv_contains (ip6_carrier_methods, method);
}
static gboolean

View file

@ -365,18 +365,20 @@ security_from_vardict (GVariant *security)
g_return_val_if_fail (g_variant_is_of_type (security, G_VARIANT_TYPE_VARDICT), NM_802_11_AP_SEC_NONE);
if (g_variant_lookup (security, "KeyMgmt", "^a&s", &array)) {
if (_nm_utils_string_in_list ("wpa-psk", array))
if ( g_variant_lookup (security, "KeyMgmt", "^a&s", &array)
&& array) {
if (g_strv_contains (array, "wpa-psk"))
flags |= NM_802_11_AP_SEC_KEY_MGMT_PSK;
if (_nm_utils_string_in_list ("wpa-eap", array))
if (g_strv_contains (array, "wpa-eap"))
flags |= NM_802_11_AP_SEC_KEY_MGMT_802_1X;
g_free (array);
}
if (g_variant_lookup (security, "Pairwise", "^a&s", &array)) {
if (_nm_utils_string_in_list ("tkip", array))
if ( g_variant_lookup (security, "Pairwise", "^a&s", &array)
&& array) {
if (g_strv_contains (array, "tkip"))
flags |= NM_802_11_AP_SEC_PAIR_TKIP;
if (_nm_utils_string_in_list ("ccmp", array))
if (g_strv_contains (array, "ccmp"))
flags |= NM_802_11_AP_SEC_PAIR_CCMP;
g_free (array);
}

View file

@ -385,10 +385,11 @@ parse_capabilities (NMSupplicantInterface *self, GVariant *capabilities)
g_return_if_fail (capabilities && g_variant_is_of_type (capabilities, G_VARIANT_TYPE_VARDICT));
if (g_variant_lookup (capabilities, "Scan", "^a&s", &array)) {
if (_nm_utils_string_in_list ("active", array))
if ( g_variant_lookup (capabilities, "Scan", "^a&s", &array)
&& array) {
if (g_strv_contains (array, "active"))
have_active = TRUE;
if (_nm_utils_string_in_list ("ssid", array))
if (g_strv_contains (array, "ssid"))
have_ssid = TRUE;
g_free (array);
}

View file

@ -194,9 +194,11 @@ update_capabilities (NMSupplicantManager *self)
if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING_ARRAY)) {
array = g_variant_get_strv (value, NULL);
priv->ap_support = NM_SUPPLICANT_FEATURE_NO;
if (_nm_utils_string_in_list ("ap", array))
priv->ap_support = NM_SUPPLICANT_FEATURE_YES;
g_free (array);
if (array) {
if (g_strv_contains (array, "ap"))
priv->ap_support = NM_SUPPLICANT_FEATURE_YES;
g_free (array);
}
}
g_variant_unref (value);
}
@ -215,9 +217,11 @@ update_capabilities (NMSupplicantManager *self)
if (value) {
if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING_ARRAY)) {
array = g_variant_get_strv (value, NULL);
if (_nm_utils_string_in_list ("fast", array))
priv->fast_supported = TRUE;
g_free (array);
if (array) {
if (g_strv_contains (array, "fast"))
priv->fast_supported = TRUE;
g_free (array);
}
}
g_variant_unref (value);
}