From e152ec7bf4ba252ff9d3eb13eabd417b931dac9a Mon Sep 17 00:00:00 2001 From: Iain Lane Date: Mon, 24 Sep 2018 09:29:55 +0100 Subject: Import Upstream version 1.12.2 --- clients/common/meson.build | 76 ++++ clients/common/nm-client-utils.c | 170 ++++++-- clients/common/nm-client-utils.h | 10 +- clients/common/nm-meta-setting-access.c | 3 + clients/common/nm-meta-setting-access.h | 1 + clients/common/nm-meta-setting-desc.c | 746 ++++++++++++++++---------------- clients/common/nm-meta-setting-desc.h | 100 ++--- clients/common/nm-polkit-listener.c | 214 ++++----- clients/common/nm-polkit-listener.h | 87 +++- clients/common/nm-secret-agent-simple.c | 252 +++++------ clients/common/nm-secret-agent-simple.h | 21 +- clients/common/nm-vpn-helpers.c | 2 +- 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 | 393 +++++++++++++++++ clients/common/settings-docs.h.in | 393 +++++++++++++++++ clients/common/tests/meson.build | 23 + clients/common/tests/test-general.c | 10 +- 19 files changed, 1769 insertions(+), 1508 deletions(-) create mode 100644 clients/common/meson.build delete mode 100644 clients/common/settings-docs.c delete mode 100644 clients/common/settings-docs.c.in create mode 100644 clients/common/settings-docs.h create mode 100644 clients/common/settings-docs.h.in create mode 100644 clients/common/tests/meson.build (limited to 'clients/common') diff --git a/clients/common/meson.build b/clients/common/meson.build new file mode 100644 index 00000000..f0c81600 --- /dev/null +++ b/clients/common/meson.build @@ -0,0 +1,76 @@ +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"', +] + +libnmc_base = static_library( + 'nmc-base', + sources: shared_files_clients_common + files( + 'nm-client-utils.c', + 'nm-secret-agent-simple.c', + 'nm-vpn-helpers.c', + ), + dependencies: deps, + c_args: cflags +) + +libnmc_base_dep = declare_dependency( + include_directories: common_inc, + link_with: libnmc_base +) + +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 + +libnmc = static_library( + 'nmc', + sources: files( + 'nm-meta-setting-access.c', + 'nm-meta-setting-desc.c' + ) + shared_nm_utils_nm_meta_setting_c + [settings_docs_source], + 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 b6ec92de..fec6e33b 100644 --- a/clients/common/nm-client-utils.c +++ b/clients/common/nm-client-utils.c @@ -20,11 +20,53 @@ #include "nm-default.h" #include "nm-client-utils.h" +#include "nm-utils.h" #include "nm-device-bond.h" #include "nm-device-bridge.h" #include "nm-device-team.h" +/*****************************************************************************/ + +static int +_nmc_objects_sort_by_path_cmp (gconstpointer pa, gconstpointer pb, gpointer user_data) +{ + NMObject *a = *((NMObject **) pa); + NMObject *b = *((NMObject **) pb); + + NM_CMP_SELF (a, b); + NM_CMP_RETURN (nm_utils_dbus_path_cmp (nm_object_get_path (a), + nm_object_get_path (b))); + return 0; +} + +const NMObject ** +nmc_objects_sort_by_path (const NMObject *const* objs, gssize len) +{ + const NMObject **arr; + gsize i, l; + + if (len < 0) + l = NM_PTRARRAY_LEN (objs); + else + l = len; + + arr = g_new (const NMObject *, l + 1); + for (i = 0; i < l; i++) + arr[i] = objs[i]; + arr[l] = NULL; + + if (l > 1) { + g_qsort_with_data (arr, + l, + sizeof (gpointer), + _nmc_objects_sort_by_path_cmp, + NULL); + } + return arr; +} + +/*****************************************************************************/ /* * Convert string to unsigned integer. * If required, the resulting number is checked to be in the range. @@ -69,7 +111,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"); @@ -100,7 +142,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"); @@ -133,10 +175,10 @@ 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; - const char *ret = NULL; + const char *partial_match = NULL; + gboolean ambiguous = FALSE; - g_return_val_if_fail (error == NULL || *error == NULL, NULL); + g_return_val_if_fail (!error || !*error, NULL); if (!input || !*input) goto finish; @@ -145,24 +187,34 @@ nmc_string_is_valid (const char *input, const char **allowed, GError **error) for (p = allowed; p && *p; p++) { p_len = strlen (*p); if (g_ascii_strncasecmp (input, *p, input_ln) == 0) { - if (input_ln == p_len) { - ret = *p; - break; - } - if (!prev_match) - ret = *p; - else { - g_set_error (error, 1, 1, _("'%s' is ambiguous (%s x %s)"), - input, ret, *p); - return NULL; - } - prev_match = TRUE; + if (input_ln == p_len) + return *p; + if (!partial_match) + partial_match = *p; + else + ambiguous = TRUE; } } + if (ambiguous) { + GString *candidates = g_string_new (""); + + for (p = allowed; *p; p++) { + if (g_ascii_strncasecmp (input, *p, input_ln) == 0) { + if (candidates->len > 0) + g_string_append (candidates, ", "); + g_string_append (candidates, *p); + } + } + g_set_error (error, 1, 1, _("'%s' is ambiguous: %s"), + input, candidates->str); + g_string_free (candidates, TRUE); + return NULL; + } finish: - if (ret == NULL) { + if (!partial_match) { char *valid_vals = g_strjoinv (", ", (char **) allowed); + if (!input || !*input) g_set_error (error, 1, 0, _("missing name, try one of [%s]"), valid_vals); else @@ -170,19 +222,8 @@ finish: g_free (valid_vals); } - 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); + return partial_match; } gboolean @@ -518,3 +559,72 @@ 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 ac18fe94..cc0b7330 100644 --- a/clients/common/nm-client-utils.h +++ b/clients/common/nm-client-utils.h @@ -30,9 +30,9 @@ typedef enum { NMC_TRI_STATE_UNKNOWN, } NMCTriStateValue; -const char *nmc_string_is_valid (const char *input, const char **allowed, GError **error); +const NMObject **nmc_objects_sort_by_path (const NMObject *const*objs, gssize len); -char **nmc_strsplit_set (const char *str, const char *delimiter, int max_tokens); +const char *nmc_string_is_valid (const char *input, const char **allowed, GError **error); gboolean nmc_string_to_uint (const char *str, gboolean range_check, @@ -44,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 it's own, at least not from this file. */ +/* FIXME: don't expose this function on its 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); @@ -56,4 +56,8 @@ 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 cd7ef783..a1bfed47 100644 --- a/clients/common/nm-meta-setting-access.c +++ b/clients/common/nm-meta-setting-access.c @@ -232,6 +232,7 @@ 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); @@ -240,6 +241,7 @@ 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); @@ -251,6 +253,7 @@ 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 54fc6c84..577cad78 100644 --- a/clients/common/nm-meta-setting-access.h +++ b/clients/common/nm-meta-setting-access.h @@ -58,6 +58,7 @@ 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 94404e90..3e4bd1bb 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -25,10 +25,8 @@ #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" @@ -118,7 +116,6 @@ _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; @@ -126,9 +123,11 @@ _parse_ip_route (int family, GError *local = NULL; gint64 metric = -1; guint i; - gs_strfreev char **routev = NULL; + gs_free const char **routev = NULL; gs_free char *str_clean = NULL; - char *dest; + gs_free char *dest_clone = NULL; + const char *dest; + const char *plen; 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] ...]'") @@ -138,8 +137,8 @@ _parse_ip_route (int family, nm_assert (!error || !*error); str_clean = g_strstrip (g_strdup (str)); - routev = nmc_strsplit_set (str_clean, " \t", 0); - if (!routev || !routev[0]) { + routev = nm_utils_strsplit_set (str_clean, " \t"); + if (!routev) { g_set_error (error, 1, 0, "'%s' is not valid. %s", str, ROUTE_SYNTAX); @@ -148,8 +147,13 @@ _parse_ip_route (int family, dest = routev[0]; plen = strchr (dest, '/'); /* prefix delimiter */ - if (plen) - *plen++ = '\0'; + if (plen) { + dest_clone = g_strdup (dest); + plen = &dest_clone[plen - dest]; + dest = dest_clone; + *((char *) plen) = '\0'; + plen++; + } prefix = MAX_PREFIX; if (plen) { if ((prefix = _nm_utils_ascii_str_to_int64 (plen, 10, 1, MAX_PREFIX, -1)) == -1) { @@ -296,7 +300,7 @@ static NMTeamLinkWatcher * _parse_team_link_watcher (const char *str, GError **error) { - gs_strfreev char **watcherv = NULL; + gs_free const char **watcherv = NULL; gs_free char *str_clean = NULL; guint i; gs_free const char *name = NULL; @@ -309,17 +313,17 @@ _parse_team_link_watcher (const char *str, nm_assert (!error || !*error); str_clean = g_strstrip (g_strdup (str)); - watcherv = nmc_strsplit_set (str_clean, " \t", 0); - if (!watcherv || !watcherv[0]) { + watcherv = nm_utils_strsplit_set (str_clean, " \t"); + if (!watcherv) { g_set_error (error, 1, 0, "'%s' is not valid", str); return NULL; } for (i = 0; watcherv[i]; i++) { - gs_strfreev char **pair = NULL; + gs_free const char **pair = NULL; - pair = nmc_strsplit_set (watcherv[i], "=", 0); - if (!pair[0]) { + pair = nm_utils_strsplit_set (watcherv[i], "="); + if (!pair) { g_set_error (error, 1, 0, "'%s' is not valid: %s", watcherv[i], "properties should be specified as 'key=value'"); return NULL; @@ -605,7 +609,6 @@ _get_text_hidden (NMMetaAccessorGetType get_type) return NM_META_TEXT_HIDDEN; } - /*****************************************************************************/ G_GNUC_PRINTF (4, 5) @@ -636,7 +639,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, 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, gboolean *out_is_default, 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 @@ -669,6 +672,33 @@ _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) { @@ -677,6 +707,7 @@ _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) @@ -692,6 +723,7 @@ _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); } @@ -699,6 +731,7 @@ 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; @@ -707,6 +740,7 @@ _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); @@ -732,13 +766,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_to_free); + return _get_fcn_gobject_impl (property_info, setting, get_type, out_is_default, out_to_free); } static gconstpointer _get_fcn_gobject_int (ARGS_GET_FCN) { - const GParamSpec *pspec; + GParamSpec *pspec; nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; gint64 v; const NMMetaUtilsIntValueInfo *value_infos; @@ -751,6 +785,7 @@ _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); @@ -790,10 +825,11 @@ _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_to_free); + return _get_fcn_gobject_impl (property_info, setting, get_type, out_is_default, 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"; @@ -820,9 +856,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; @@ -833,6 +869,7 @@ _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 (); @@ -875,25 +912,26 @@ _get_fcn_gobject_enum (ARGS_GET_FCN) nm_assert (format_text || format_numeric); - gtype_prop = _gobject_property_get_gtype (G_OBJECT (setting), property_info->property_name); - - g_value_init (&gval, gtype_prop); + pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (setting), property_info->property_name); + g_return_val_if_fail (pspec, NULL); + 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 ( 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 ( 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 (!has_gtype) g_return_val_if_reached (NULL); v = g_value_get_int (&gval); } else v = g_value_get_enum (&gval); - } 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) { + } 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) { if (!has_gtype) g_return_val_if_reached (NULL); v = g_value_get_uint (&gval); @@ -903,7 +941,7 @@ _get_fcn_gobject_enum (ARGS_GET_FCN) g_return_val_if_reached (NULL); if (!has_gtype) { - gtype = gtype_prop; + gtype = pspec->value_type; gtype_class = g_steal_pointer (>ype_prop_class); } @@ -927,7 +965,9 @@ _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. */ - s = nm_utils_enum_to_str (gtype, (int) v); + 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); if (!format_numeric) RETURN_STR_TO_FREE (g_steal_pointer (&s)); @@ -1150,7 +1190,6 @@ _set_fcn_gobject_mac (ARGS_SET_FCN) else mode = NM_META_PROPERTY_TYPE_MAC_MODE_DEFAULT; - if (mode == NM_META_PROPERTY_TYPE_MAC_MODE_INFINIBAND) valid = nm_utils_hwaddr_valid (value, INFINIBAND_ALEN); else { @@ -1168,39 +1207,6 @@ _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) { @@ -1320,7 +1326,7 @@ _values_fcn_gobject_enum (ARGS_VALUES_FCN) gboolean has_minmax = FALSE; int min = G_MININT; int max = G_MAXINT; - char **v, **w; + char **v; if (property_info->property_typ_data) { if ( property_info->property_typ_data->subtype.gobject_enum.min @@ -1354,11 +1360,7 @@ _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 = (char **) nm_utils_enum_get_values (gtype, min, max); - if (v) { - for (w = v; *w; w++) - *w = g_strdup (*w); - } + v = nm_utils_strv_make_deep_copied (nm_utils_enum_get_values (gtype, min, max)); return (const char *const*) (*out_to_free = v); } @@ -1505,24 +1507,6 @@ 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) { @@ -1573,18 +1557,19 @@ vpn_data_item (const char *key, const char *value, gpointer user_data) const char **valid_strv, \ GError **error) \ { \ - char **strv = NULL, **iter; \ + gs_free const char **strv = NULL; \ + gsize i; \ const char *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; \ + 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); \ } \ - set_func (s_macro (setting), item); \ } \ - g_strfreev (strv); \ return TRUE; \ } @@ -1592,43 +1577,42 @@ vpn_data_item (const char *key, const char *value, gpointer user_data) static gboolean \ def_func (ARGS_SET_FCN) \ { \ - char **strv = NULL, **iter; \ + gs_free const char **strv = NULL; \ + const char **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); \ + nm_assert (!error || !*error); \ \ - strv = nmc_strsplit_set (value, ",", 0); \ + strv = nm_utils_strsplit_set (value, ","); \ for (iter = strv; iter && *iter; iter++) { \ - char *left = g_strstrip (*iter); \ + gs_free char *left_clone = g_strstrip (g_strdup (*iter)); \ + char *left = left_clone; \ char *right = strchr (left, '='); \ if (!right) { \ g_set_error (error, 1, 0, _("'%s' is not valid; use