summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-03-19 14:12:53 +0100
committerThomas Haller <thaller@redhat.com>2019-03-25 09:12:33 +0100
commit1b1ef52ff8de8812105d1c132ec08b6dab892695 (patch)
tree6758ae77a6e92a2cd19728457fae0145028458c5
parente3fa570c1bcfec695db12194c472a6ee9a3cce48 (diff)
cli: implement match:interface-names as multilist property
-rw-r--r--clients/common/nm-meta-setting-desc.c58
-rw-r--r--clients/common/nm-meta-setting-desc.h5
2 files changed, 32 insertions, 31 deletions
diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c
index 1009908ba..0b1233d04 100644
--- a/clients/common/nm-meta-setting-desc.c
+++ b/clients/common/nm-meta-setting-desc.c
@@ -1672,7 +1672,11 @@ _set_fcn_multilist (ARGS_SET_FCN)
if (_SET_FCN_DO_RESET_DEFAULT (value))
return _gobject_property_reset_default (setting, property_info->property_name);
- strv = nm_utils_strsplit_set (value, " \t,", FALSE);
+ if (property_info->property_typ_data->subtype.multilist.with_escaped_spaces)
+ strv = nm_utils_strsplit_set (value, " \t", TRUE);
+ else
+ strv = nm_utils_strsplit_set (value, " \t,", FALSE);
+
if (strv) {
j = 0;
@@ -1683,7 +1687,10 @@ _set_fcn_multilist (ARGS_SET_FCN)
if (item[0] == '\0')
continue;
- g_strchomp ((char *) item);
+ if (property_info->property_typ_data->subtype.multilist.with_escaped_spaces)
+ _nm_utils_unescape_spaces ((char *) item, TRUE);
+ else
+ g_strchomp ((char *) item);
item = _multilist_do_validate (property_info, TRUE, setting, item, error);
if (!item)
@@ -1693,8 +1700,12 @@ _set_fcn_multilist (ARGS_SET_FCN)
}
strv[j] = NULL;
- for (i = 0; strv[i]; i++)
- property_info->property_typ_data->subtype.multilist.add_fcn (setting, strv[i]);
+ for (i = 0; strv[i]; i++) {
+ if (property_info->property_typ_data->subtype.multilist.add2_fcn)
+ property_info->property_typ_data->subtype.multilist.add2_fcn (setting, strv[i]);
+ else
+ property_info->property_typ_data->subtype.multilist.add_fcn (setting, strv[i]);
+ }
}
return TRUE;
}
@@ -3216,31 +3227,6 @@ _get_fcn_match_interface_name (ARGS_GET_FCN)
RETURN_STR_TO_FREE (g_string_free (str, FALSE));
}
-static gboolean
-_set_fcn_match_interface_name (ARGS_SET_FCN)
-{
- gs_free const char **strv = NULL;
- gsize i;
-
- if (_SET_FCN_DO_RESET_DEFAULT (value))
- return _gobject_property_reset_default (setting, property_info->property_name);
-
- strv = nm_utils_strsplit_set (value, " \t", TRUE);
- if (strv) {
- for (i = 0; strv[i]; i++) {
- nm_setting_match_add_interface_name (NM_SETTING_MATCH (setting),
- _nm_utils_unescape_spaces ((char *) strv[i], TRUE));
- }
- }
- return TRUE;
-}
-
-DEFINE_REMOVER_INDEX_OR_VALUE_DIRECT (_remove_fcn_match_interface_name,
- NM_SETTING_MATCH,
- nm_setting_match_get_num_interface_names,
- nm_setting_match_remove_interface_name,
- nm_setting_match_remove_interface_name_by_value)
-
static gconstpointer
_get_fcn_olpc_mesh_ssid (ARGS_GET_FCN)
{
@@ -4364,6 +4350,7 @@ static const NMMetaPropertyType _pt_ethtool = {
#define MULTILIST_GET_NUM_FCN_U32(type, func) (((func) == ((guint32 (*) (type * )) (func))) ? ((guint32 (*) (NMSetting * )) (func)) : NULL)
#define MULTILIST_GET_NUM_FCN_U(type, func) (((func) == ((guint (*) (type * )) (func))) ? ((guint (*) (NMSetting * )) (func)) : NULL)
#define MULTILIST_ADD_FCN(type, func) (((func) == ((gboolean (*) (type *, const char *)) (func))) ? ((gboolean (*) (NMSetting *, const char *)) (func)) : NULL)
+#define MULTILIST_ADD2_FCN(type, func) (((func) == ((void (*) (type *, const char *)) (func))) ? ((void (*) (NMSetting *, const char *)) (func)) : NULL)
#define MULTILIST_REMOVE_BY_IDX_FCN_U32(type, func) (((func) == ((void (*) (type *, guint32 )) (func))) ? ((void (*) (NMSetting *, guint32 )) (func)) : NULL)
#define MULTILIST_REMOVE_BY_IDX_FCN_S(type, func) (((func) == ((void (*) (type *, int )) (func))) ? ((void (*) (NMSetting *, int )) (func)) : NULL)
#define MULTILIST_REMOVE_BY_VALUE_FCN(type, func) (((func) == ((gboolean (*) (type *, const char *)) (func))) ? ((gboolean (*) (NMSetting *, const char *)) (func)) : NULL)
@@ -5928,8 +5915,17 @@ static const NMMetaPropertyInfo *const property_infos_MATCH[] = {
PROPERTY_INFO_WITH_DESC (NM_SETTING_MATCH_INTERFACE_NAME,
.property_type = DEFINE_PROPERTY_TYPE (
.get_fcn = _get_fcn_match_interface_name,
- .set_fcn = _set_fcn_match_interface_name,
- .remove_fcn = _remove_fcn_match_interface_name,
+ .set_fcn = _set_fcn_multilist,
+ .remove_fcn = _remove_fcn_multilist,
+ ),
+ .property_typ_data = DEFINE_PROPERTY_TYP_DATA (
+ PROPERTY_TYP_DATA_SUBTYPE (multilist,
+ .get_num_fcn_u = MULTILIST_GET_NUM_FCN_U (NMSettingMatch, nm_setting_match_get_num_interface_names),
+ .add2_fcn = MULTILIST_ADD2_FCN (NMSettingMatch, nm_setting_match_add_interface_name),
+ .remove_by_idx_fcn_s = MULTILIST_REMOVE_BY_IDX_FCN_S (NMSettingMatch, nm_setting_match_remove_interface_name),
+ .remove_by_value_fcn = MULTILIST_REMOVE_BY_VALUE_FCN (NMSettingMatch, nm_setting_match_remove_interface_name_by_value),
+ .with_escaped_spaces = TRUE,
+ ),
),
),
NULL
diff --git a/clients/common/nm-meta-setting-desc.h b/clients/common/nm-meta-setting-desc.h
index 7f4dc2ed4..42ae5c049 100644
--- a/clients/common/nm-meta-setting-desc.h
+++ b/clients/common/nm-meta-setting-desc.h
@@ -272,6 +272,8 @@ struct _NMMetaPropertyTypData {
guint (*get_num_fcn_u) (NMSetting *setting);
gboolean (*add_fcn) (NMSetting *setting,
const char *item);
+ void (*add2_fcn) (NMSetting *setting,
+ const char *item);
const char *(*validate_fcn) (const char *item, GError **error);
const char *(*validate2_fcn) (NMSetting *setting, const char *item, GError **error);
void (*remove_by_idx_fcn_u32) (NMSetting *setting, guint32 idx);
@@ -283,6 +285,9 @@ struct _NMMetaPropertyTypData {
/* if TRUE, validate_fcn() is ignored for remove_by_value(). */
bool no_validate_remove_by_value:1;
+
+ /* if true, separate the list by space and allow backslash escaping. */
+ bool with_escaped_spaces:1;
} multilist;
struct {
gboolean (*add_fcn) (NMSetting *setting,