diff --git a/clients/cli/settings.c b/clients/cli/settings.c index d44c9ccc9..df0effa35 100644 --- a/clients/cli/settings.c +++ b/clients/cli/settings.c @@ -996,7 +996,7 @@ vpn_data_item (const char *key, const char *value, gpointer user_data) } -/* === property get functions === */ +/* generic helper macros for property functions */ #define DEFINE_GETTER(func_name, property_name) \ static char * \ func_name (NMSetting *setting, NmcPropertyGetType get_type) \ @@ -1048,6 +1048,141 @@ vpn_data_item (const char *key, const char *value, gpointer user_data) return secret_flags_to_string (v, get_type); \ } +#define DEFINE_SETTER_STR_LIST_MULTI(def_func, s_macro, set_func) \ + static gboolean \ + def_func (NMSetting *setting, \ + const char *prop, \ + const char *val, \ + const char **valid_strv, \ + GError **error) \ + { \ + char **strv = NULL, **iter; \ + const char *item; \ + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); \ + strv = nmc_strsplit_set (val, " \t,", 0); \ + for (iter = strv; iter && *iter; iter++) { \ + if (!(item = nmc_string_is_valid (g_strstrip (*iter), valid_strv, error))) { \ + g_strfreev (strv); \ + return FALSE; \ + } \ + set_func (s_macro (setting), item); \ + } \ + g_strfreev (strv); \ + return TRUE; \ + } + +#define DEFINE_SETTER_OPTIONS(def_func, s_macro, s_type, add_func, valid_func1, valid_func2) \ + static gboolean \ + def_func (NMSetting *setting, const char *prop, const char *val, GError **error) \ + { \ + char **strv = NULL, **iter; \ + const char **(*valid_func1_p) (s_type *) = valid_func1; \ + const char * (*valid_func2_p) (const char *, const char *, GError **) = valid_func2; \ + const char *opt_name, *opt_val; \ + \ + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); \ + \ + strv = nmc_strsplit_set (val, ",", 0); \ + for (iter = strv; iter && *iter; iter++) { \ + char *left = g_strstrip (*iter); \ + char *right = strchr (left, '='); \ + if (!right) { \ + g_set_error (error, 1, 0, _("'%s' is not valid; use