From ee9c73a923909e23a649407be77e25235d769e25 Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Fri, 11 May 2018 22:08:45 +0200 Subject: New upstream version 1.10.8 --- clients/common/meson.build | 81 ---- clients/common/nm-client-utils.c | 106 +---- clients/common/nm-client-utils.h | 8 +- clients/common/nm-meta-setting-access.c | 3 - clients/common/nm-meta-setting-access.h | 1 - clients/common/nm-meta-setting-desc.c | 718 ++++++++++++++++---------------- clients/common/nm-meta-setting-desc.h | 7 +- clients/common/nm-polkit-listener.c | 214 ++++++---- clients/common/nm-polkit-listener.h | 86 +--- clients/common/nm-secret-agent-simple.c | 236 ++++++----- clients/common/nm-secret-agent-simple.h | 21 +- clients/common/nm-vpn-helpers.h | 2 + clients/common/settings-docs.c | 387 +++++++++++++++++ clients/common/settings-docs.c.in | 387 +++++++++++++++++ clients/common/settings-docs.h | 390 ----------------- clients/common/settings-docs.h.in | 390 ----------------- clients/common/tests/meson.build | 23 - clients/common/tests/test-general.c | 10 +- 18 files changed, 1444 insertions(+), 1626 deletions(-) delete mode 100644 clients/common/meson.build create mode 100644 clients/common/settings-docs.c create mode 100644 clients/common/settings-docs.c.in delete mode 100644 clients/common/settings-docs.h delete mode 100644 clients/common/settings-docs.h.in delete mode 100644 clients/common/tests/meson.build (limited to 'clients/common') diff --git a/clients/common/meson.build b/clients/common/meson.build deleted file mode 100644 index ea26bccf..00000000 --- a/clients/common/meson.build +++ /dev/null @@ -1,81 +0,0 @@ -common_inc = include_directories('.') - -nm_polkit_listener = files('nm-polkit-listener.c') - -deps = [ - libnm_dep, - nm_core_dep -] - -cflags = clients_cflags + [ - '-DG_LOG_DOMAIN="libnmc"', -] - -sources = shared_utils + files( - 'nm-client-utils.c', - 'nm-secret-agent-simple.c', - 'nm-vpn-helpers.c' -) - -libnmc_base = static_library( - 'nmc-base', - sources: sources, - dependencies: deps, - c_args: cflags -) - -libnmc_base_dep = declare_dependency( - include_directories: common_inc, - link_with: libnmc_base -) - -sources = shared_meta_setting + files( - 'nm-meta-setting-access.c', - 'nm-meta-setting-desc.c' -) - -settings_docs = 'settings-docs.h' - -if enable_introspection - settings_docs_source = custom_target( - settings_docs, - input: nm_property_docs, - output: settings_docs, - command: [xsltproc, '--output', '@OUTPUT@', join_paths(meson.current_source_dir(), 'settings-docs.xsl'), '@INPUT@'] - ) - - # FIXME: if enabled the check happens even if the settings_docs_source is not set - ''' - if get_option('check_settings_docs') - res = run_command(find_program('cmp'), '-s', settings_docs + '.in', settings_docs_source.full_path()) - if res.returncode() != 0 - message('The generated file ' + settings_docs_source.full_path() + ' differs from the source file ' + settings_docs + '.in' + '. You probably should copy the generated file over to the source file. You can skip this test by setting -Dcheck_settings_docs=false') - endif - endif - ''' -else - settings_docs_source = configure_file( - input: settings_docs + '.in', - output: settings_docs, - configuration: configuration_data() - ) -endif -sources += settings_docs_source - -libnmc = static_library( - 'nmc', - sources: sources, - dependencies: deps, - c_args: cflags, - link_with: libnmc_base, - link_depends: settings_docs_source -) - -libnmc_dep = declare_dependency( - include_directories: common_inc, - link_with: libnmc -) - -if (enable_introspection or enable_nmtui) and enable_tests - subdir('tests') -endif diff --git a/clients/common/nm-client-utils.c b/clients/common/nm-client-utils.c index b4b4c1b9..b6ec92de 100644 --- a/clients/common/nm-client-utils.c +++ b/clients/common/nm-client-utils.c @@ -20,7 +20,6 @@ #include "nm-default.h" #include "nm-client-utils.h" -#include "nm-utils.h" #include "nm-device-bond.h" #include "nm-device-bridge.h" @@ -70,7 +69,7 @@ nmc_string_to_bool (const char *str, gboolean *val_bool, GError **error) if (g_strcmp0 (str, "o") == 0) { g_set_error (error, 1, 0, - /* TRANSLATORS: the first %s is the partial value entered by + /* Translators: the first %s is the partial value entered by * the user, the second %s a list of compatible values. */ _("'%s' is ambiguous (%s)"), str, "on x off"); @@ -101,7 +100,7 @@ nmc_string_to_tristate (const char *str, NMCTriStateValue *val, GError **error) if (g_strcmp0 (str, "o") == 0) { g_set_error (error, 1, 0, - /* TRANSLATORS: the first %s is the partial value entered by + /* Translators: the first %s is the partial value entered by * the user, the second %s a list of compatible values. */ _("'%s' is ambiguous (%s)"), str, "on x off"); @@ -134,7 +133,7 @@ nmc_string_is_valid (const char *input, const char **allowed, GError **error) { const char **p; size_t input_ln, p_len; - gboolean prev_match = FALSE, ambiguous = FALSE; + gboolean prev_match = FALSE; const char *ret = NULL; g_return_val_if_fail (error == NULL || *error == NULL, NULL); @@ -148,21 +147,19 @@ nmc_string_is_valid (const char *input, const char **allowed, GError **error) if (g_ascii_strncasecmp (input, *p, input_ln) == 0) { if (input_ln == p_len) { ret = *p; - ambiguous = FALSE; break; } - if (!prev_match) { + if (!prev_match) ret = *p; - prev_match = TRUE; - } else - ambiguous = TRUE; + else { + g_set_error (error, 1, 1, _("'%s' is ambiguous (%s x %s)"), + input, ret, *p); + return NULL; + } + prev_match = TRUE; } } - if (ambiguous) { - g_set_error (error, 1, 1, _("'%s' is ambiguous (%s x %s)"), - input, ret, *p); - return NULL; - } + finish: if (ret == NULL) { char *valid_vals = g_strjoinv (", ", (char **) allowed); @@ -176,6 +173,18 @@ finish: return ret; } +/* + * Wrapper function for g_strsplit_set() that removes empty strings + * from the vector as they are not useful in most cases. + */ +char ** +nmc_strsplit_set (const char *str, const char *delimiter, int max_tokens) +{ + /* remove empty strings */ + return _nm_utils_strv_cleanup (g_strsplit_set (str, delimiter, max_tokens), + FALSE, TRUE, FALSE); +} + gboolean matches (const char *cmd, const char *pattern) { @@ -509,72 +518,3 @@ nmc_activation_get_effective_state (NMActiveConnection *active, return ac_state; } - -static gboolean -can_show_graphics (void) -{ - static gboolean can_show_graphics_set = FALSE; - gboolean can_show_graphics = TRUE; - char *locale_str; - - if (G_LIKELY (can_show_graphics_set)) - return can_show_graphics; - - if (!g_get_charset (NULL)) { - /* Non-UTF-8 locale */ - locale_str = g_locale_from_utf8 ("\342\226\202\342\226\204\342\226\206\342\226\210", -1, NULL, NULL, NULL); - if (locale_str) - g_free (locale_str); - else - can_show_graphics = FALSE; - } - - /* The linux console font typically doesn't have characters we need */ - if (g_strcmp0 (g_getenv ("TERM"), "linux") == 0) - can_show_graphics = FALSE; - - return can_show_graphics; -} - -/** - * nmc_wifi_strength_bars: - * @strength: the access point strength, from 0 to 100 - * - * Converts @strength into a 4-character-wide graphical representation of - * strength suitable for printing to stdout. If the current locale and terminal - * support it, this will use unicode graphics characters to represent - * "bars". Otherwise it will use 0 to 4 asterisks. - * - * Returns: the graphical representation of the access point strength - */ -const char * -nmc_wifi_strength_bars (guint8 strength) -{ - if (!can_show_graphics ()) - return nm_utils_wifi_strength_bars (strength); - - if (strength > 80) - return /* ▂▄▆█ */ "\342\226\202\342\226\204\342\226\206\342\226\210"; - else if (strength > 55) - return /* ▂▄▆_ */ "\342\226\202\342\226\204\342\226\206_"; - else if (strength > 30) - return /* ▂▄__ */ "\342\226\202\342\226\204__"; - else if (strength > 5) - return /* ▂___ */ "\342\226\202___"; - else - return /* ____ */ "____"; -} - -/** - * nmc_utils_password_subst_char: - * - * Returns: the string substituted when hiding actual password glyphs - */ -const char * -nmc_password_subst_char (void) -{ - if (can_show_graphics ()) - return "\u2022"; /* Bullet */ - else - return "*"; -} diff --git a/clients/common/nm-client-utils.h b/clients/common/nm-client-utils.h index cd662765..ac18fe94 100644 --- a/clients/common/nm-client-utils.h +++ b/clients/common/nm-client-utils.h @@ -32,6 +32,8 @@ typedef enum { const char *nmc_string_is_valid (const char *input, const char **allowed, GError **error); +char **nmc_strsplit_set (const char *str, const char *delimiter, int max_tokens); + gboolean nmc_string_to_uint (const char *str, gboolean range_check, unsigned long int min, @@ -42,7 +44,7 @@ gboolean nmc_string_to_tristate (const char *str, NMCTriStateValue *val, GError gboolean matches (const char *cmd, const char *pattern); -/* FIXME: don't expose this function on its own, at least not from this file. */ +/* FIXME: don't expose this function on it's own, at least not from this file. */ const char *nmc_bond_validate_mode (const char *mode, GError **error); const char *nm_active_connection_state_reason_to_string (NMActiveConnectionStateReason reason); @@ -54,8 +56,4 @@ NMActiveConnectionState nmc_activation_get_effective_state (NMActiveConnection * NMDevice *device, const char **reason); -const char *nmc_wifi_strength_bars (guint8 strength); - -const char *nmc_password_subst_char (void); - #endif /* __NM_CLIENT_UTILS_H__ */ diff --git a/clients/common/nm-meta-setting-access.c b/clients/common/nm-meta-setting-access.c index a1bfed47..cd7ef783 100644 --- a/clients/common/nm-meta-setting-access.c +++ b/clients/common/nm-meta-setting-access.c @@ -232,7 +232,6 @@ nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, - gboolean *out_is_default, gpointer *out_to_free) { nm_assert (abstract_info); @@ -241,7 +240,6 @@ nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info, nm_assert (out_flags); *out_flags = NM_META_ACCESSOR_GET_OUT_FLAGS_NONE; - NM_SET_OUT (out_is_default, FALSE); if (!abstract_info->meta_type->get_fcn) g_return_val_if_reached (NULL); @@ -253,7 +251,6 @@ nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info, get_type, get_flags, out_flags, - out_is_default, out_to_free); } diff --git a/clients/common/nm-meta-setting-access.h b/clients/common/nm-meta-setting-access.h index 577cad78..54fc6c84 100644 --- a/clients/common/nm-meta-setting-access.h +++ b/clients/common/nm-meta-setting-access.h @@ -58,7 +58,6 @@ gconstpointer nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, - gboolean *out_is_default, gpointer *out_to_free); const char *const*nm_meta_abstract_info_complete (const NMMetaAbstractInfo *abstract_info, diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index ede95a10..94404e90 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -25,8 +25,10 @@ #include #include "nm-common-macros.h" +#include "nm-utils/nm-hash-utils.h" #include "nm-utils/nm-enum-utils.h" +#include "NetworkManager.h" #include "nm-vpn-helpers.h" #include "nm-client-utils.h" #include "nm-meta-setting-access.h" @@ -116,6 +118,7 @@ _parse_ip_route (int family, GError **error) { const int MAX_PREFIX = (family == AF_INET) ? 32 : 128; + char *plen = NULL; const char *next_hop = NULL; const char *canon_dest; int prefix; @@ -123,11 +126,9 @@ _parse_ip_route (int family, GError *local = NULL; gint64 metric = -1; guint i; - gs_free const char **routev = NULL; + gs_strfreev char **routev = NULL; gs_free char *str_clean = NULL; - gs_free char *dest_clone = NULL; - const char *dest; - const char *plen; + char *dest; gs_unref_hashtable GHashTable *attrs = NULL; GHashTable *tmp_attrs; #define ROUTE_SYNTAX _("The valid syntax is: 'ip[/prefix] [next-hop] [metric] [attribute=val]... [,ip[/prefix] ...]'") @@ -137,8 +138,8 @@ _parse_ip_route (int family, nm_assert (!error || !*error); str_clean = g_strstrip (g_strdup (str)); - routev = nm_utils_strsplit_set (str_clean, " \t"); - if (!routev) { + routev = nmc_strsplit_set (str_clean, " \t", 0); + if (!routev || !routev[0]) { g_set_error (error, 1, 0, "'%s' is not valid. %s", str, ROUTE_SYNTAX); @@ -147,13 +148,8 @@ _parse_ip_route (int family, dest = routev[0]; plen = strchr (dest, '/'); /* prefix delimiter */ - if (plen) { - dest_clone = g_strdup (dest); - plen = &dest_clone[plen - dest]; - dest = dest_clone; - *((char *) plen) = '\0'; - plen++; - } + if (plen) + *plen++ = '\0'; prefix = MAX_PREFIX; if (plen) { if ((prefix = _nm_utils_ascii_str_to_int64 (plen, 10, 1, MAX_PREFIX, -1)) == -1) { @@ -300,7 +296,7 @@ static NMTeamLinkWatcher * _parse_team_link_watcher (const char *str, GError **error) { - gs_free const char **watcherv = NULL; + gs_strfreev char **watcherv = NULL; gs_free char *str_clean = NULL; guint i; gs_free const char *name = NULL; @@ -313,17 +309,17 @@ _parse_team_link_watcher (const char *str, nm_assert (!error || !*error); str_clean = g_strstrip (g_strdup (str)); - watcherv = nm_utils_strsplit_set (str_clean, " \t"); - if (!watcherv) { + watcherv = nmc_strsplit_set (str_clean, " \t", 0); + if (!watcherv || !watcherv[0]) { g_set_error (error, 1, 0, "'%s' is not valid", str); return NULL; } for (i = 0; watcherv[i]; i++) { - gs_free const char **pair = NULL; + gs_strfreev char **pair = NULL; - pair = nm_utils_strsplit_set (watcherv[i], "="); - if (!pair) { + pair = nmc_strsplit_set (watcherv[i], "=", 0); + if (!pair[0]) { g_set_error (error, 1, 0, "'%s' is not valid: %s", watcherv[i], "properties should be specified as 'key=value'"); return NULL; @@ -640,7 +636,7 @@ _env_warn_fcn (const NMMetaEnvironment *environment, const NMMetaPropertyInfo *property_info, char **out_to_free #define ARGS_GET_FCN \ - const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, gpointer environment_user_data, NMSetting *setting, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, gboolean *out_is_default, gpointer *out_to_free + const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, gpointer environment_user_data, NMSetting *setting, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, gpointer *out_to_free #define ARGS_SET_FCN \ const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, gpointer environment_user_data, NMSetting *setting, const char *value, GError **error @@ -673,33 +669,6 @@ _env_warn_fcn (const NMMetaEnvironment *environment, return ((*(out_to_free)) = _val); \ } G_STMT_END -static gboolean -property_is_default (NMSetting *setting, const char *prop_name) -{ - nm_auto_unset_gvalue GValue v = G_VALUE_INIT; - GParamSpec *pspec; - GHashTable *ht; - char **strv; - - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), - prop_name); - if (!G_IS_PARAM_SPEC (pspec)) - g_return_val_if_reached (FALSE); - - g_value_init (&v, pspec->value_type); - g_object_get_property (G_OBJECT (setting), prop_name, &v); - - if (pspec->value_type == G_TYPE_STRV) { - strv = g_value_get_boxed (&v); - return !strv || !strv[0]; - } else if (pspec->value_type == G_TYPE_HASH_TABLE) { - ht = g_value_get_boxed (&v); - return !ht || !g_hash_table_size (ht); - } - - return g_param_value_defaults (pspec, &v); -} - static gconstpointer _get_fcn_nmc_with_default (ARGS_GET_FCN) { @@ -708,7 +677,6 @@ _get_fcn_nmc_with_default (ARGS_GET_FCN) GValue val = G_VALUE_INIT; RETURN_UNSUPPORTED_GET_TYPE (); - NM_SET_OUT (out_is_default, property_is_default (setting, property_info->property_name)); if (property_info->property_typ_data->subtype.get_with_default.fcn (setting)) { if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) @@ -724,7 +692,6 @@ _get_fcn_nmc_with_default (ARGS_GET_FCN) else s_full = g_strdup (s && *s ? s : " "); g_value_unset (&val); - RETURN_STR_TO_FREE (s_full); } @@ -732,7 +699,6 @@ static gconstpointer _get_fcn_gobject_impl (const NMMetaPropertyInfo *property_info, NMSetting *setting, NMMetaAccessorGetType get_type, - gboolean *out_is_default, gpointer *out_to_free) { char *s; @@ -741,7 +707,6 @@ _get_fcn_gobject_impl (const NMMetaPropertyInfo *property_info, nm_auto_unset_gvalue GValue val = G_VALUE_INIT; RETURN_UNSUPPORTED_GET_TYPE (); - NM_SET_OUT (out_is_default, property_is_default (setting, property_info->property_name)); gtype_prop = _gobject_property_get_gtype (G_OBJECT (setting), property_info->property_name); @@ -767,13 +732,13 @@ _get_fcn_gobject_impl (const NMMetaPropertyInfo *property_info, static gconstpointer _get_fcn_gobject (ARGS_GET_FCN) { - return _get_fcn_gobject_impl (property_info, setting, get_type, out_is_default, out_to_free); + return _get_fcn_gobject_impl (property_info, setting, get_type, out_to_free); } static gconstpointer _get_fcn_gobject_int (ARGS_GET_FCN) { - GParamSpec *pspec; + const GParamSpec *pspec; nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; gint64 v; const NMMetaUtilsIntValueInfo *value_infos; @@ -786,7 +751,6 @@ _get_fcn_gobject_int (ARGS_GET_FCN) g_value_init (&gval, pspec->value_type); g_object_get_property (G_OBJECT (setting), property_info->property_name, &gval); - NM_SET_OUT (out_is_default, g_param_value_defaults (pspec, &gval)); switch (pspec->value_type) { case G_TYPE_INT: v = g_value_get_int (&gval); @@ -826,11 +790,10 @@ _get_fcn_gobject_mtu (ARGS_GET_FCN) if ( !property_info->property_typ_data || !property_info->property_typ_data->subtype.mtu.get_fcn) - return _get_fcn_gobject_impl (property_info, setting, get_type, out_is_default, out_to_free); + return _get_fcn_gobject_impl (property_info, setting, get_type, out_to_free); mtu = property_info->property_typ_data->subtype.mtu.get_fcn (setting); if (mtu == 0) { - NM_SET_OUT (out_is_default, TRUE); if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) return _("auto"); return "auto"; @@ -857,9 +820,9 @@ static gconstpointer _get_fcn_gobject_enum (ARGS_GET_FCN) { GType gtype = 0; + GType gtype_prop; nm_auto_unref_gtypeclass GTypeClass *gtype_class = NULL; nm_auto_unref_gtypeclass GTypeClass *gtype_prop_class = NULL; - const struct _NMUtilsEnumValueInfo *value_infos = NULL; gboolean has_gtype = FALSE; nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; gint64 v; @@ -870,7 +833,6 @@ _get_fcn_gobject_enum (ARGS_GET_FCN) gboolean format_text_l10n = FALSE; gs_free char *s = NULL; char s_numeric[64]; - GParamSpec *pspec; RETURN_UNSUPPORTED_GET_TYPE (); @@ -913,26 +875,25 @@ _get_fcn_gobject_enum (ARGS_GET_FCN) nm_assert (format_text || format_numeric); - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (setting), property_info->property_name); - g_return_val_if_fail (pspec, NULL); + gtype_prop = _gobject_property_get_gtype (G_OBJECT (setting), property_info->property_name); + + g_value_init (&gval, gtype_prop); - g_value_init (&gval, pspec->value_type); g_object_get_property (G_OBJECT (setting), property_info->property_name, &gval); - NM_SET_OUT (out_is_default, g_param_value_defaults (pspec, &gval)); - if ( pspec->value_type == G_TYPE_INT - || ( G_TYPE_IS_CLASSED (pspec->value_type) - && G_IS_ENUM_CLASS ((gtype_prop_class ?: (gtype_prop_class = g_type_class_ref (pspec->value_type)))))) { - if (pspec->value_type == G_TYPE_INT) { + if ( gtype_prop == G_TYPE_INT + || ( G_TYPE_IS_CLASSED (gtype_prop) + && G_IS_ENUM_CLASS ((gtype_prop_class ?: (gtype_prop_class = g_type_class_ref (gtype_prop)))))) { + if (gtype_prop == G_TYPE_INT) { if (!has_gtype) g_return_val_if_reached (NULL); v = g_value_get_int (&gval); } else v = g_value_get_enum (&gval); - } else if ( pspec->value_type == G_TYPE_UINT - || ( G_TYPE_IS_CLASSED (pspec->value_type) - && G_IS_FLAGS_CLASS ((gtype_prop_class ?: (gtype_prop_class = g_type_class_ref (pspec->value_type)))))) { - if (pspec->value_type == G_TYPE_UINT) { + } else if ( gtype_prop == G_TYPE_UINT + || ( G_TYPE_IS_CLASSED (gtype_prop) + && G_IS_FLAGS_CLASS ((gtype_prop_class ?: (gtype_prop_class = g_type_class_ref (gtype_prop)))))) { + if (gtype_prop == G_TYPE_UINT) { if (!has_gtype) g_return_val_if_reached (NULL); v = g_value_get_uint (&gval); @@ -942,7 +903,7 @@ _get_fcn_gobject_enum (ARGS_GET_FCN) g_return_val_if_reached (NULL); if (!has_gtype) { - gtype = pspec->value_type; + gtype = gtype_prop; gtype_class = g_steal_pointer (>ype_prop_class); } @@ -966,9 +927,7 @@ _get_fcn_gobject_enum (ARGS_GET_FCN) /* the gobject_enum.value_infos are currently ignored for the getter. They * only declare additional aliases for the setter. */ - if (property_info->property_typ_data) - value_infos = property_info->property_typ_data->subtype.gobject_enum.value_infos_get; - s = _nm_utils_enum_to_str_full (gtype, (int) v, ", ", value_infos); + s = nm_utils_enum_to_str (gtype, (int) v); if (!format_numeric) RETURN_STR_TO_FREE (g_steal_pointer (&s)); @@ -1209,6 +1168,39 @@ _set_fcn_gobject_mac (ARGS_SET_FCN) return TRUE; } +static gboolean +_set_fcn_gobject_secret_flags (ARGS_SET_FCN) +{ + char **strv = NULL, **iter; + unsigned long flags = 0, val_int; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + strv = nmc_strsplit_set (value, " \t,", 0); + for (iter = strv; iter && *iter; iter++) { + if (!nmc_string_to_uint (*iter, TRUE, 0, ALL_SECRET_FLAGS, &val_int)) { + g_set_error (error, 1, 0, _("'%s' is not a valid flag number; use <0-%d>"), + *iter, ALL_SECRET_FLAGS); + g_strfreev (strv); + return FALSE; + } + flags += val_int; + } + g_strfreev (strv); + + /* Validate the flags number */ + if (flags > ALL_SECRET_FLAGS) { + flags = ALL_SECRET_FLAGS; + _env_warn_fcn (environment, environment_user_data, + NM_META_ENV_WARN_LEVEL_WARN, + N_("'%s' sum is higher than all flags => all flags set"), + value); + } + + g_object_set (setting, property_info->property_name, (guint) flags, NULL); + return TRUE; +} + static gboolean _set_fcn_gobject_enum (ARGS_SET_FCN) { @@ -1328,7 +1320,7 @@ _values_fcn_gobject_enum (ARGS_VALUES_FCN) gboolean has_minmax = FALSE; int min = G_MININT; int max = G_MAXINT; - char **v; + char **v, **w; if (property_info->property_typ_data) { if ( property_info->property_typ_data->subtype.gobject_enum.min @@ -1362,7 +1354,11 @@ _values_fcn_gobject_enum (ARGS_VALUES_FCN) /* the gobject_enum.value_infos are currently ignored for the list of * values. They only declare additional (hidden) aliases for the setter. */ - v = nm_utils_strv_make_deep_copied (nm_utils_enum_get_values (gtype, min, max)); + v = (char **) nm_utils_enum_get_values (gtype, min, max); + if (v) { + for (w = v; *w; w++) + *w = g_strdup (*w); + } return (const char *const*) (*out_to_free = v); } @@ -1509,6 +1505,24 @@ vlan_priorities_to_string (NMSettingVlan *s_vlan, NMVlanPriorityMap map) return g_string_free (priorities, FALSE); } +static char * +ip6_privacy_to_string (NMSettingIP6ConfigPrivacy ip6_privacy, NMMetaAccessorGetType get_type) +{ + if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) + return g_strdup_printf ("%d", ip6_privacy); + + switch (ip6_privacy) { + case NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED: + return g_strdup_printf (_("%d (disabled)"), ip6_privacy); + case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR: + return g_strdup_printf (_("%d (enabled, prefer public IP)"), ip6_privacy); + case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR: + return g_strdup_printf (_("%d (enabled, prefer temporary IP)"), ip6_privacy); + default: + return g_strdup_printf (_("%d (unknown)"), ip6_privacy); + } +} + static char * secret_flags_to_string (guint32 flags, NMMetaAccessorGetType get_type) { @@ -1559,19 +1573,18 @@ vpn_data_item (const char *key, const char *value, gpointer user_data) const char **valid_strv, \ GError **error) \ { \ - gs_free const char **strv = NULL; \ - gsize i; \ + char **strv = NULL, **iter; \ const char *item; \ - nm_assert (!error || !*error); \ - strv = nm_utils_strsplit_set (value, " \t,"); \ - if (strv) { \ - for (i = 0; strv[i]; i++) { \ - if (!(item = nmc_string_is_valid (strv[i], valid_strv, error))) { \ - return FALSE; \ - } \ - set_func (s_macro (setting), item); \ + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); \ + strv = nmc_strsplit_set (value, " \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; \ } @@ -1579,42 +1592,43 @@ vpn_data_item (const char *key, const char *value, gpointer user_data) static gboolean \ def_func (ARGS_SET_FCN) \ { \ - gs_free const char **strv = NULL; \ - const char **iter; \ + 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; \ \ - nm_assert (!error || !*error); \ + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); \ \ - strv = nm_utils_strsplit_set (value, ","); \ + strv = nmc_strsplit_set (value, ",", 0); \ for (iter = strv; iter && *iter; iter++) { \ - gs_free char *left_clone = g_strstrip (g_strdup (*iter)); \ - char *left = left_clone; \ + char *left = g_strstrip (*iter); \ char *right = strchr (left, '='); \ if (!right) { \ g_set_error (error, 1, 0, _("'%s' is not valid; use