From e29add5f8149265bb201395df1355f3f9416fc7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Sat, 21 Jan 2017 00:17:03 +0100 Subject: [PATCH] cli: move code around to group related functions - no functional change * all getter/setter/describe, ... functions grouped according to properties * sort the settings groups alphabetically (cherry picked from commit 418733f2c14e76d5977a185a7c514747320b8f02) --- clients/cli/settings.c | 7093 ++++++++++++++++++++-------------------- 1 file changed, 3549 insertions(+), 3544 deletions(-) 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