all: replace g_strsplit_set() by nm_utils_strsplit_set*()

This commit is contained in:
Thomas Haller 2019-04-04 13:06:00 +02:00
parent 34e60bf228
commit 3e0366a3ff
4 changed files with 40 additions and 47 deletions

View file

@ -2837,12 +2837,12 @@ dcb_parse_uint_array (const char *val,
guint out_array[static 8],
GError **error)
{
gs_strfreev char **items = NULL;
char **iter;
gs_free const char **items = NULL;
const char *const*iter;
gsize i;
items = g_strsplit_set (val, ",", -1);
if (g_strv_length (items) != 8) {
items = nm_utils_strsplit_set_with_empty (val, ",");
if (NM_PTRARRAY_LEN (items) != 8) {
g_set_error_literal (error, 1, 0, _("must contain 8 comma-separated numbers"));
return FALSE;
}
@ -2851,8 +2851,6 @@ dcb_parse_uint_array (const char *val,
for (iter = items; *iter; iter++) {
gint64 num;
*iter = g_strstrip (*iter);
num = _nm_utils_ascii_str_to_int64 (*iter, 10, 0, other ?: max, -1);
/* If number is greater than 'max' it must equal 'other' */

View file

@ -185,20 +185,18 @@ set_arp_targets (NMDevice *device,
const char *delim,
const char *prefix)
{
char **items, **iter, *tmp;
gs_free const char **value_v = NULL;
gsize i;
if (!value || !*value)
value_v = nm_utils_strsplit_set (value, delim);
if (!value_v)
return;
for (i = 0; value_v[i]; i++) {
gs_free char *tmp = NULL;
items = g_strsplit_set (value, delim, 0);
for (iter = items; iter && *iter; iter++) {
if (*iter[0]) {
tmp = g_strdup_printf ("%s%s", prefix, *iter);
set_bond_attr (device, mode, NM_SETTING_BOND_OPTION_ARP_IP_TARGET, tmp);
g_free (tmp);
}
tmp = g_strdup_printf ("%s%s", prefix, value_v[i]);
set_bond_attr (device, mode, NM_SETTING_BOND_OPTION_ARP_IP_TARGET, tmp);
}
g_strfreev (items);
}
static void

View file

@ -302,7 +302,8 @@ nm_logging_setup (const char *level,
NMLogDomain new_log_state[_LOGL_N_REAL];
NMLogLevel cur_log_level;
NMLogLevel new_log_level;
char **tmp, **iter;
gs_free const char **domains_v = NULL;
gsize i_d;
int i;
gboolean had_platform_debug;
gs_free char *domains_free = NULL;
@ -337,28 +338,24 @@ nm_logging_setup (const char *level,
}
}
tmp = g_strsplit_set (domains, ", ", 0);
for (iter = tmp; iter && *iter; iter++) {
domains_v = nm_utils_strsplit_set (domains, ", ");
for (i_d = 0; domains_v && domains_v[i_d]; i_d++) {
const char *s = domains_v[i_d];
const char *p;
const LogDesc *diter;
NMLogLevel domain_log_level;
NMLogDomain bits;
char *p;
/* LOGD_VPN_PLUGIN is protected, that is, when setting ALL or DEFAULT,
* it does not enable the verbose levels DEBUG and TRACE, because that
* may expose sensitive data. */
NMLogDomain protect = LOGD_NONE;
if (!strlen (*iter))
continue;
p = strchr (*iter, ':');
p = strchr (s, ':');
if (p) {
*p = '\0';
if (!match_log_level (p + 1, &domain_log_level, error)) {
g_strfreev (tmp);
*((char *) p) = '\0';
if (!match_log_level (p + 1, &domain_log_level, error))
return FALSE;
}
} else
domain_log_level = new_log_level;
@ -372,26 +369,26 @@ nm_logging_setup (const char *level,
}
/* Check for combined domains */
if (!g_ascii_strcasecmp (*iter, LOGD_ALL_STRING)) {
if (!g_ascii_strcasecmp (s, LOGD_ALL_STRING)) {
bits = LOGD_ALL;
protect = LOGD_VPN_PLUGIN;
} else if (!g_ascii_strcasecmp (*iter, LOGD_DEFAULT_STRING)) {
} else if (!g_ascii_strcasecmp (s, LOGD_DEFAULT_STRING)) {
bits = LOGD_DEFAULT;
protect = LOGD_VPN_PLUGIN;
} else if (!g_ascii_strcasecmp (*iter, LOGD_DHCP_STRING))
} else if (!g_ascii_strcasecmp (s, LOGD_DHCP_STRING))
bits = LOGD_DHCP;
else if (!g_ascii_strcasecmp (*iter, LOGD_IP_STRING))
else if (!g_ascii_strcasecmp (s, LOGD_IP_STRING))
bits = LOGD_IP;
/* Check for compatibility domains */
else if (!g_ascii_strcasecmp (*iter, "HW"))
else if (!g_ascii_strcasecmp (s, "HW"))
bits = LOGD_PLATFORM;
else if (!g_ascii_strcasecmp (*iter, "WIMAX"))
else if (!g_ascii_strcasecmp (s, "WIMAX"))
continue;
else {
for (diter = &domain_desc[0]; diter->name; diter++) {
if (!g_ascii_strcasecmp (diter->name, *iter)) {
if (!g_ascii_strcasecmp (diter->name, s)) {
bits = diter->num;
break;
}
@ -400,7 +397,7 @@ nm_logging_setup (const char *level,
if (!bits) {
if (!bad_domains) {
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_LOG_DOMAIN,
_("Unknown log domain '%s'"), *iter);
_("Unknown log domain '%s'"), s);
return FALSE;
}
@ -408,7 +405,7 @@ nm_logging_setup (const char *level,
g_string_append (unrecognized, ", ");
else
unrecognized = g_string_new (NULL);
g_string_append (unrecognized, *iter);
g_string_append (unrecognized, s);
continue;
}
}
@ -429,7 +426,6 @@ nm_logging_setup (const char *level,
}
}
}
g_strfreev (tmp);
g_clear_pointer (&gl_main.logging_domains_to_string, g_free);

View file

@ -4548,22 +4548,23 @@ make_wired_setting (shvarFile *ifcfg,
value = svGetValueStr_cp (ifcfg, "OPTIONS");
if (value) {
char **options, **iter;
gs_free const char **options = NULL;
gsize i;
iter = options = g_strsplit_set (value, " ", 0);
while (iter && *iter) {
char *equals = strchr (*iter, '=');
options = nm_utils_strsplit_set_with_empty (value, " ");
for (i = 0; options && options[i]; i++) {
const char *line = options[i];
const char *equals;
gboolean valid = FALSE;
equals = strchr (line, '=');
if (equals) {
*equals = '\0';
valid = nm_setting_wired_add_s390_option (s_wired, *iter, equals + 1);
((char *) equals)[0] = '\0';
valid = nm_setting_wired_add_s390_option (s_wired, line, equals + 1);
}
if (!valid)
PARSE_WARNING ("invalid s390 OPTION '%s'", *iter);
iter++;
PARSE_WARNING ("invalid s390 OPTION '%s'", line);
}
g_strfreev (options);
nm_clear_g_free (&value);
}