Commit 8c3fc3c5 authored by Thomas Haller's avatar Thomas Haller

all: merge branch 'th/strsplit-pt2'

!105
parents 246c2dbe afc25851
Pipeline #30210 passed with stages
in 80 minutes and 41 seconds
......@@ -3849,8 +3849,9 @@ dispatcher_tests_test_dispatcher_envp_LDFLAGS = \
$(SANITIZER_EXEC_LDFLAGS)
dispatcher_tests_test_dispatcher_envp_LDADD = \
libnm/libnm.la \
dispatcher/libnm-dispatcher-core.la \
libnm/libnm.la \
shared/nm-utils/libnm-utils-base.la \
$(GLIB_LIBS)
$(dispatcher_tests_test_dispatcher_envp_OBJECTS): $(libnm_core_lib_h_pub_mkenums)
......
This diff is collapsed.
......@@ -205,7 +205,8 @@ struct NMIPAddress {
**/
NMIPAddress *
nm_ip_address_new (int family,
const char *addr, guint prefix,
const char *addr,
guint prefix,
GError **error)
{
NMIPAddress *address;
......@@ -243,7 +244,8 @@ nm_ip_address_new (int family,
**/
NMIPAddress *
nm_ip_address_new_binary (int family,
gconstpointer addr, guint prefix,
gconstpointer addr,
guint prefix,
GError **error)
{
NMIPAddress *address;
......
......@@ -267,6 +267,8 @@ NM_AUTO_DEFINE_FCN0 (GVariantIter *, _nm_auto_free_variant_iter, g_variant_iter_
NM_AUTO_DEFINE_FCN0 (GVariantBuilder *, _nm_auto_unref_variant_builder, g_variant_builder_unref)
#define nm_auto_unref_variant_builder nm_auto(_nm_auto_unref_variant_builder)
#define nm_auto_clear_variant_builder nm_auto(g_variant_builder_clear)
NM_AUTO_DEFINE_FCN0 (GList *, _nm_auto_free_list, g_list_free)
#define nm_auto_free_list nm_auto(_nm_auto_free_list)
......
......@@ -206,7 +206,7 @@ _cert_get_cert_bytes (const char *ifcfg_path,
{
gs_free char *path = NULL;
if (g_str_has_prefix (value, "pkcs11:"))
if (NM_STR_HAS_PREFIX (value, "pkcs11:"))
return _nm_setting_802_1x_cert_value_to_bytes (NM_SETTING_802_1X_CK_SCHEME_PKCS11, (guint8 *) value, -1, error);
path = get_full_file_path (ifcfg_path, value);
......@@ -560,7 +560,6 @@ make_connection_setting (const char *file,
return NM_SETTING (s_con);
}
/* Returns TRUE on missing address or valid address */
static gboolean
read_ip4_address (shvarFile *ifcfg,
const char *tag,
......@@ -570,7 +569,7 @@ read_ip4_address (shvarFile *ifcfg,
{
gs_free char *value_to_free = NULL;
const char *value;
guint32 a;
in_addr_t a;
nm_assert (ifcfg);
nm_assert (tag);
......@@ -1341,46 +1340,33 @@ parse_full_ip6_address (shvarFile *ifcfg,
NMIPAddress **out_address,
GError **error)
{
char **list;
char *ip_val, *prefix_val;
NMIPAddress *addr;
NMIPAddr addr_bin;
int prefix;
gboolean success = FALSE;
g_return_val_if_fail (addr_str != NULL, FALSE);
g_return_val_if_fail (out_address != NULL, FALSE);
g_return_val_if_fail (*out_address == NULL, FALSE);
g_return_val_if_fail (!error || !*error, FALSE);
nm_assert (addr_str);
nm_assert (out_address && !*out_address);
nm_assert (!error || !*error);
/* Split the address and prefix */
list = g_strsplit_set (addr_str, "/", 2);
if (g_strv_length (list) < 1) {
if (!nm_utils_parse_inaddr_prefix_bin (AF_INET6,
addr_str,
NULL,
&addr_bin,
&prefix)) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IP6 address '%s'", addr_str);
goto error;
return FALSE;
}
ip_val = list[0];
prefix_val = list[1];
if (prefix_val) {
prefix = _nm_utils_ascii_str_to_int64 (prefix_val, 10, 0, 128, -1);
if (prefix < 0) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IP6 prefix '%s'", prefix_val);
goto error;
}
} else {
/* Missing prefix is treated as prefix of 64 */
if (prefix < 0)
prefix = 64;
}
*out_address = nm_ip_address_new (AF_INET6, ip_val, prefix, error);
if (*out_address)
success = TRUE;
addr = nm_ip_address_new_binary (AF_INET6, &addr_bin, prefix, error);
if (!addr)
return FALSE;
error:
g_strfreev (list);
return success;
*out_address = addr;
return TRUE;
}
static NMSetting *
......@@ -4816,16 +4802,16 @@ make_bond_setting (shvarFile *ifcfg,
items = nm_utils_strsplit_set (v, " ");
for (iter = items; iter && *iter; iter++) {
gs_strfreev char **keys = NULL;
const char *key, *val;
keys = g_strsplit_set (*iter, "=", 2);
if (keys && *keys) {
key = *keys;
val = *(keys + 1);
if (val && key[0] && val[0])
handle_bond_option (s_bond, key, val);
}
gs_free char *key = NULL;
const char *val;
val = strchr (*iter, '=');
if (!val)
continue;
key = g_strndup (*iter, val - *iter);
val++;
if (key[0] && val[0])
handle_bond_option (s_bond, key, val);
}
}
......@@ -5096,16 +5082,16 @@ handle_bridging_opts (NMSetting *setting,
items = nm_utils_strsplit_set (value, " ");
for (iter = items; iter && *iter; iter++) {
gs_strfreev char **keys = NULL;
const char *key, *val;
keys = g_strsplit_set (*iter, "=", 2);
if (keys && *keys) {
key = *keys;
val = *(keys + 1);
if (val && key[0] && val[0])
func (setting, stp, key, val, opt_type);
}
gs_free char *key = NULL;
const char *val;
val = strchr (*iter, '=');
if (!val)
continue;
key = g_strndup (*iter, val - *iter);
val++;
if (key[0] && val[0])
func (setting, stp, key, val, opt_type);
}
}
......
......@@ -419,17 +419,15 @@ update_wired_setting_from_if_block (NMConnection *connection,
static void
ifupdown_ip4_add_dns (NMSettingIPConfig *s_ip4, const char *dns)
{
gs_free const char **list = NULL;
const char **iter;
guint32 addr;
gs_strfreev char **list = NULL;
char **iter;
if (dns == NULL)
return;
list = g_strsplit_set (dns, " \t", -1);
list = nm_utils_strsplit_set (dns, " \t");
for (iter = list; iter && *iter; iter++) {
if ((*iter)[0] == '\0')
continue;
if (!inet_pton (AF_INET, *iter, &addr)) {
_LOGW (" ignoring invalid nameserver '%s'", *iter);
continue;
......@@ -524,13 +522,11 @@ update_ip4_setting_from_if_block (NMConnection *connection,
/* DNS searches */
search_v = ifparser_getkey (block, "dns-search");
if (search_v) {
gs_strfreev char **list = NULL;
char **iter;
gs_free const char **list = NULL;
const char **iter;
list = g_strsplit_set (search_v, " \t", -1);
list = nm_utils_strsplit_set (search_v, " \t");
for (iter = list; iter && *iter; iter++) {
if ((*iter)[0] == '\0')
continue;
if (!nm_setting_ip_config_add_dns_search (s_ip4, *iter))
_LOGW (" duplicate DNS domain '%s'", *iter);
}
......@@ -546,17 +542,15 @@ update_ip4_setting_from_if_block (NMConnection *connection,
static void
ifupdown_ip6_add_dns (NMSettingIPConfig *s_ip6, const char *dns)
{
gs_free const char **list = NULL;
const char **iter;
struct in6_addr addr;
gs_strfreev char **list = NULL;
char **iter;
if (dns == NULL)
return;
list = g_strsplit_set (dns, " \t", -1);
list = nm_utils_strsplit_set (dns, " \t");
for (iter = list; iter && *iter; iter++) {
if ((*iter)[0] == '\0')
continue;
if (!inet_pton (AF_INET6, *iter, &addr)) {
_LOGW (" ignoring invalid nameserver '%s'", *iter);
continue;
......@@ -640,13 +634,11 @@ update_ip6_setting_from_if_block (NMConnection *connection,
/* DNS searches */
search_v = ifparser_getkey (block, "dns-search");
if (search_v) {
gs_strfreev char **list = NULL;
char **iter;
gs_free const char **list = NULL;
const char **iter;
list = g_strsplit_set (search_v, " \t", -1);
list = nm_utils_strsplit_set (search_v, " \t");
for (iter = list; iter && *iter; iter++) {
if ((*iter)[0] == '\0')
continue;
if (!nm_setting_ip_config_add_dns_search (s_ip6, *iter))
_LOGW (" duplicate DNS domain '%s'", *iter);
}
......
......@@ -175,14 +175,14 @@ initialize (NMSettingsPlugin *plugin)
const char *ports = ifparser_getkey (block, "bridge-ports");
if (ports) {
guint i;
int state = 0;
gs_strfreev char **port_ifaces = NULL;
gs_free const char **port_ifaces = NULL;
gsize i;
_LOGD ("parse: found bridge ports %s for %s", ports, block->name);
port_ifaces = g_strsplit_set (ports, " \t", -1);
for (i = 0; port_ifaces[i]; i++) {
port_ifaces = nm_utils_strsplit_set (ports, " \t");
for (i = 0; port_ifaces && port_ifaces[i]; i++) {
const char *token = port_ifaces[i];
/* Skip crazy stuff like regex or all */
......@@ -200,7 +200,7 @@ initialize (NMSettingsPlugin *plugin)
}
if (nm_streq (token, "none"))
continue;
if (state == 0 && strlen (token) > 0) {
if (state == 0) {
conn = g_hash_table_lookup (priv->eni_ifaces, block->name);
if (!conn) {
_LOGD ("parse: adding bridge port \"%s\"", token);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment