summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2018-04-13 17:21:01 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2018-04-13 17:21:01 +0200
commit95340f6c6d4f5b7a2afd3d4f1beadf1e107e1298 (patch)
treeb2bd93e8808dd32844350e5a7a53c77776a8bcd1
parent6fbbb5be7424ed38b6d124a4a95d11a962aa789d (diff)
parentc9a574f12f976fadb5591064fcec35106c957631 (diff)
downloadNetworkManager-95340f6c6d4f5b7a2afd3d4f1beadf1e107e1298.tar.gz
cli: merge branch 'bg/nmcli-overview-rh1434527'
https://bugzilla.redhat.com/show_bug.cgi?id=1434527
-rw-r--r--clients/cli/common.c18
-rw-r--r--clients/cli/general.c3
-rw-r--r--clients/cli/nmcli.c16
-rw-r--r--clients/cli/nmcli.h1
-rw-r--r--clients/cli/settings.c1
-rw-r--r--clients/cli/utils.c15
-rw-r--r--clients/cli/utils.h1
-rw-r--r--clients/common/nm-meta-setting-access.c3
-rw-r--r--clients/common/nm-meta-setting-access.h1
-rw-r--r--clients/common/nm-meta-setting-desc.c291
-rw-r--r--clients/common/nm-meta-setting-desc.h5
-rw-r--r--libnm-core/nm-utils.c2
-rw-r--r--shared/nm-utils/nm-enum-utils.c47
-rw-r--r--shared/nm-utils/nm-enum-utils.h5
-rw-r--r--src/settings/plugins/ifcfg-rh/shvar.c2
15 files changed, 238 insertions, 173 deletions
diff --git a/clients/cli/common.c b/clients/cli/common.c
index 38729a6d08..81a3183d0c 100644
--- a/clients/cli/common.c
+++ b/clients/cli/common.c
@@ -107,6 +107,7 @@ _metagen_ip4_config_get_fcn (const NMMetaEnvironment *environment,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
+ gboolean *out_is_default,
gpointer *out_to_free)
{
NMIPConfig *cfg4 = target;
@@ -114,10 +115,12 @@ _metagen_ip4_config_get_fcn (const NMMetaEnvironment *environment,
char **arr;
const char *const*arrc;
guint i = 0;
+ const char *str;
nm_assert (info->info_type < _NMC_GENERIC_INFO_TYPE_IP4_CONFIG_NUM);
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
+ NM_SET_OUT (out_is_default, TRUE);
switch (info->info_type) {
case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ADDRESS:
@@ -138,7 +141,9 @@ _metagen_ip4_config_get_fcn (const NMMetaEnvironment *environment,
arr = NULL;
goto arr_out;
case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_GATEWAY:
- return nm_ip_config_get_gateway (cfg4);
+ str = nm_ip_config_get_gateway (cfg4);
+ NM_SET_OUT (out_is_default, !str);
+ return str;
case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ROUTE:
if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV))
return NULL;
@@ -166,10 +171,12 @@ _metagen_ip4_config_get_fcn (const NMMetaEnvironment *environment,
g_return_val_if_reached (NULL);
arrc_out:
+ NM_SET_OUT (out_is_default, !arrc || !arrc[0]);
*out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV;
return arrc;
arr_out:
+ NM_SET_OUT (out_is_default, !arr || !arr[0]);
*out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV;
*out_to_free = arr;
return arr;
@@ -183,6 +190,7 @@ _metagen_ip6_config_get_fcn (const NMMetaEnvironment *environment,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
+ gboolean *out_is_default,
gpointer *out_to_free)
{
NMIPConfig *cfg6 = target;
@@ -190,10 +198,12 @@ _metagen_ip6_config_get_fcn (const NMMetaEnvironment *environment,
char **arr;
const char *const*arrc;
guint i = 0;
+ const char *str;
nm_assert (info->info_type < _NMC_GENERIC_INFO_TYPE_IP6_CONFIG_NUM);
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
+ NM_SET_OUT (out_is_default, TRUE);
switch (info->info_type) {
case NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ADDRESS:
@@ -214,7 +224,9 @@ _metagen_ip6_config_get_fcn (const NMMetaEnvironment *environment,
arr = NULL;
goto arr_out;
case NMC_GENERIC_INFO_TYPE_IP6_CONFIG_GATEWAY:
- return nm_ip_config_get_gateway (cfg6);
+ str = nm_ip_config_get_gateway (cfg6);
+ NM_SET_OUT (out_is_default, !str);
+ return str;
case NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ROUTE:
if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV))
return NULL;
@@ -237,10 +249,12 @@ _metagen_ip6_config_get_fcn (const NMMetaEnvironment *environment,
g_return_val_if_reached (NULL);
arrc_out:
+ NM_SET_OUT (out_is_default, !arrc || !arrc[0]);
*out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV;
return arrc;
arr_out:
+ NM_SET_OUT (out_is_default, !arr || !arr[0]);
*out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV;
*out_to_free = arr;
return arr;
diff --git a/clients/cli/general.c b/clients/cli/general.c
index 7ac6b22cc6..647ee5fc0d 100644
--- a/clients/cli/general.c
+++ b/clients/cli/general.c
@@ -175,6 +175,7 @@ _metagen_general_status_get_fcn (const NMMetaEnvironment *environment,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
+ gboolean *out_is_default,
gpointer *out_to_free)
{
NmCli *nmc = target;
@@ -282,6 +283,7 @@ _metagen_general_permissions_get_fcn (const NMMetaEnvironment *environment,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
+ gboolean *out_is_default,
gpointer *out_to_free)
{
NMClientPermission perm = GPOINTER_TO_UINT (target);
@@ -330,6 +332,7 @@ _metagen_general_logging_get_fcn (const NMMetaEnvironment *environment,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
+ gboolean *out_is_default,
gpointer *out_to_free)
{
NmCli *nmc = environment_user_data;
diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c
index 76dda05096..ec23ff431b 100644
--- a/clients/cli/nmcli.c
+++ b/clients/cli/nmcli.c
@@ -184,6 +184,7 @@ usage (void)
g_printerr (_("Usage: nmcli [OPTIONS] OBJECT { COMMAND | help }\n"
"\n"
"OPTIONS\n"
+ " -o[verview] overview mode (hide default values)\n"
" -t[erse] terse output\n"
" -p[retty] pretty output\n"
" -m[ode] tabular|multiline output mode\n"
@@ -295,9 +296,10 @@ process_command_line (NmCli *nmc, int argc, char **argv)
break;
if (argc == 1 && nmc->complete) {
- nmc_complete_strings (argv[0], "--terse", "--pretty", "--mode", "--colors", "--escape",
- "--fields", "--nocheck", "--get-values",
- "--wait", "--version", "--help", NULL);
+ nmc_complete_strings (argv[0], "--terse", "--pretty", "--mode", "--overview",
+ "--colors", "--escape",
+ "--fields", "--nocheck", "--get-values",
+ "--wait", "--version", "--help", NULL);
}
if (argv[0][1] == '-' && argv[0][2] == '\0') {
@@ -306,7 +308,9 @@ process_command_line (NmCli *nmc, int argc, char **argv)
break;
}
- if (matches_arg (nmc, &argc, &argv, "-terse", NULL)) {
+ if (matches_arg (nmc, &argc, &argv, "-overview", NULL)) {
+ nmc->nmc_config_mutable.overview = TRUE;
+ } else if (matches_arg (nmc, &argc, &argv, "-terse", NULL)) {
if (nmc->nmc_config.print_output == NMC_PRINT_TERSE) {
g_string_printf (nmc->return_text, _("Error: Option '--terse' is specified the second time."));
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
@@ -415,6 +419,10 @@ process_command_line (NmCli *nmc, int argc, char **argv)
next_arg (nmc, &argc, &argv, NULL);
}
+ /* Ignore --overview when fields are set explicitly */
+ if (nmc->required_fields)
+ nmc->nmc_config_mutable.overview = FALSE;
+
/* Now run the requested command */
nmc_do_cmd (nmc, nmcli_cmds, *argv, argc, argv);
diff --git a/clients/cli/nmcli.h b/clients/cli/nmcli.h
index cccad8462a..cbde4359f9 100644
--- a/clients/cli/nmcli.h
+++ b/clients/cli/nmcli.h
@@ -116,6 +116,7 @@ typedef struct _NmcConfig {
bool escape_values; /* Whether to escape ':' and '\' in terse tabular mode */
bool in_editor; /* Whether running the editor - nmcli con edit' */
bool show_secrets; /* Whether to display secrets (both input and output): option '--show-secrets' */
+ bool overview; /* Overview mode (hide default values) */
} NmcConfig;
typedef struct _NmcOutputData {
diff --git a/clients/cli/settings.c b/clients/cli/settings.c
index 86035ba4a0..5c3deeadd3 100644
--- a/clients/cli/settings.c
+++ b/clients/cli/settings.c
@@ -474,6 +474,7 @@ get_property_val (NMSetting *setting, const char *prop, NMMetaAccessorGetType ge
get_type,
show_secrets ? NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS : 0,
&out_flags,
+ NULL,
(gpointer *) &to_free);
nm_assert (!out_flags);
return to_free ?: g_strdup (value);
diff --git a/clients/cli/utils.c b/clients/cli/utils.c
index 86a410d3b6..71fdcf308e 100644
--- a/clients/cli/utils.c
+++ b/clients/cli/utils.c
@@ -75,6 +75,7 @@ _meta_type_nmc_generic_info_get_fcn (const NMMetaAbstractInfo *abstract_info,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
+ gboolean *out_is_default,
gpointer *out_to_free)
{
const NmcMetaGenericInfo *info = (const NmcMetaGenericInfo *) abstract_info;
@@ -97,6 +98,7 @@ _meta_type_nmc_generic_info_get_fcn (const NMMetaAbstractInfo *abstract_info,
get_type,
get_flags,
out_flags,
+ out_is_default,
out_to_free);
}
@@ -1002,6 +1004,7 @@ typedef struct {
const PrintDataCol *col;
const char *title;
bool title_to_free:1;
+ bool skip:1;
int width;
} PrintDataHeaderCell;
@@ -1100,6 +1103,7 @@ _print_fill (const NmcConfig *nmc_config,
header_cell->col_idx = col_idx;
header_cell->col = col;
+ header_cell->skip = FALSE;
header_cell->title = nm_meta_abstract_info_get_name (info, TRUE);
if ( nmc_config->multiline_output
@@ -1134,10 +1138,11 @@ _print_fill (const NmcConfig *nmc_config,
for (i_col = 0; i_col < header_row->len; i_col++) {
char *to_free = NULL;
PrintDataCell *cell = &cells_line[i_col];
- const PrintDataHeaderCell *header_cell;
+ PrintDataHeaderCell *header_cell;
const NMMetaAbstractInfo *info;
NMMetaAccessorGetOutFlags text_out_flags, color_out_flags;
gconstpointer value;
+ gboolean is_default;
header_cell = &g_array_index (header_row, PrintDataHeaderCell, i_col);
info = header_cell->col->selection_item->info;
@@ -1152,7 +1157,11 @@ _print_fill (const NmcConfig *nmc_config,
text_get_type,
text_get_flags,
&text_out_flags,
+ &is_default,
(gpointer *) &to_free);
+
+ header_cell->skip = nmc_config->overview && is_default;
+
if (NM_FLAGS_HAS (text_out_flags, NM_META_ACCESSOR_GET_OUT_FLAGS_STRV)) {
if (value) {
if (nmc_config->multiline_output) {
@@ -1178,6 +1187,7 @@ _print_fill (const NmcConfig *nmc_config,
NM_META_ACCESSOR_GET_TYPE_TERMFORMAT,
NM_META_ACCESSOR_GET_FLAGS_NONE,
&color_out_flags,
+ NULL,
NULL),
&cell->term_color,
&cell->term_format);
@@ -1235,6 +1245,9 @@ _print_skip_column (const NmcConfig *nmc_config,
selection_item = header_cell->col->selection_item;
info = selection_item->info;
+ if (header_cell->skip)
+ return TRUE;
+
if (nmc_config->multiline_output) {
if (info->meta_type == &nm_meta_type_setting_info_editor) {
/* we skip the "name" entry for the setting in multiline output. */
diff --git a/clients/cli/utils.h b/clients/cli/utils.h
index 48e96e0126..c92c4e2e83 100644
--- a/clients/cli/utils.h
+++ b/clients/cli/utils.h
@@ -150,6 +150,7 @@ struct _NmcMetaGenericInfo {
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
+ gboolean *out_is_default,
gpointer *out_to_free);
};
diff --git a/clients/common/nm-meta-setting-access.c b/clients/common/nm-meta-setting-access.c
index cd7ef783c4..a1bfed47b7 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 54fc6c84d6..577cad787a 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 52d5f1e390..ede95a10a3 100644
--- a/clients/common/nm-meta-setting-desc.c
+++ b/clients/common/nm-meta-setting-desc.c
@@ -640,7 +640,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
@@ -673,6 +673,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)
{
@@ -681,6 +708,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)
@@ -696,6 +724,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);
}
@@ -703,6 +732,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;
@@ -711,6 +741,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);
@@ -736,13 +767,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;
@@ -755,6 +786,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);
@@ -794,10 +826,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";
@@ -824,9 +857,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;
@@ -837,6 +870,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 ();
@@ -879,25 +913,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);
@@ -907,7 +942,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 (&gtype_prop_class);
}
@@ -931,7 +966,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));
@@ -1173,42 +1210,6 @@ _set_fcn_gobject_mac (ARGS_SET_FCN)
}
static gboolean
-_set_fcn_gobject_secret_flags (ARGS_SET_FCN)
-{
- gs_free char *err_token = NULL;
- gs_free char *str_all = NULL;
- int flags;
-
- nm_assert (!error || !*error);
-
- if (!nm_utils_enum_from_str (nm_setting_secret_flags_get_type (),
- value,
- &flags,
- &err_token)) {
- str_all = nm_utils_enum_to_str (nm_setting_secret_flags_get_type (),
- ALL_SECRET_FLAGS);
- g_set_error (error, 1, 0,
- _("'%s' is not a valid flag; use <0-%d> or a combination of '%s'"),
- err_token,
- ALL_SECRET_FLAGS,
- str_all);
- return FALSE;
- }
-
- /* 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)
{
GType gtype = 0;
@@ -1327,7 +1328,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
@@ -1361,11 +1362,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);
}
@@ -1513,24 +1510,6 @@ vlan_priorities_to_string (NMSettingVlan *s_vlan, NMVlanPriorityMap map)
}
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)
{
GString *flag_str;
@@ -1966,6 +1945,7 @@ _get_fcn_802_1x_ca_cert (ARGS_GET_FCN)
break;
}
+ NM_SET_OUT (out_is_default, !ca_cert_str || !ca_cert_str[0]);
RETURN_STR_TO_FREE (ca_cert_str);
}
@@ -1994,6 +1974,7 @@ _get_fcn_802_1x_client_cert (ARGS_GET_FCN)
break;
}
+ NM_SET_OUT (out_is_default, !cert_str || !cert_str[0]);
RETURN_STR_TO_FREE (cert_str);
}
@@ -2019,6 +2000,7 @@ _get_fcn_802_1x_phase2_ca_cert (ARGS_GET_FCN)
break;
}
+ NM_SET_OUT (out_is_default, !phase2_ca_cert_str || !phase2_ca_cert_str[0]);
RETURN_STR_TO_FREE (phase2_ca_cert_str);
}
@@ -2047,6 +2029,7 @@ _get_fcn_802_1x_phase2_client_cert (ARGS_GET_FCN)
break;
}
+ NM_SET_OUT (out_is_default, !cert_str || !cert_str[0]);
RETURN_STR_TO_FREE (cert_str);
}
@@ -2054,9 +2037,13 @@ static gconstpointer
_get_fcn_802_1x_password_raw (ARGS_GET_FCN)
{
NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting);
+ char *str;
RETURN_UNSUPPORTED_GET_TYPE ();
- RETURN_STR_TO_FREE (bytes_to_string (nm_setting_802_1x_get_password_raw (s_8021X)));
+
+ str = bytes_to_string (nm_setting_802_1x_get_password_raw (s_8021X));
+ NM_SET_OUT (out_is_default, !str || !str[0]);
+ RETURN_STR_TO_FREE (str);
}
static gconstpointer
@@ -2084,6 +2071,7 @@ _get_fcn_802_1x_private_key (ARGS_GET_FCN)
break;
}
+ NM_SET_OUT (out_is_default, !key_str || !key_str[0]);
RETURN_STR_TO_FREE (key_str);
}
@@ -2112,6 +2100,7 @@ _get_fcn_802_1x_phase2_private_key (ARGS_GET_FCN)
break;
}
+ NM_SET_OUT (out_is_default, !key_str || !key_str[0]);
RETURN_STR_TO_FREE (key_str);
}
@@ -2305,6 +2294,7 @@ _get_fcn_bond_options (ARGS_GET_FCN)
}
g_string_truncate (bond_options_s, bond_options_s->len-1); /* chop off trailing ',' */
+ NM_SET_OUT (out_is_default, bond_options_s->len == 0);
RETURN_STR_TO_FREE (g_string_free (bond_options_s, FALSE));
}
@@ -2408,6 +2398,9 @@ _get_fcn_connection_permissions (ARGS_GET_FCN)
if (nm_setting_connection_get_permission (s_con, i, &perm_type, &perm_item, NULL))
g_string_append_printf (perm, "%s:%s,", perm_type, perm_item);
}
+
+ NM_SET_OUT (out_is_default, perm->len == 0);
+
if (perm->len > 0) {
g_string_truncate (perm, perm->len-1); /* remove trailing , */
RETURN_STR_TO_FREE (g_string_free (perm, FALSE));
@@ -2687,9 +2680,11 @@ _get_fcn_connection_metered (ARGS_GET_FCN)
break;
case NM_METERED_UNKNOWN:
default:
+ NM_SET_OUT (out_is_default, TRUE);
s = N_("unknown");
break;
}
+
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
return _(s);
return s;
@@ -3107,12 +3102,14 @@ _get_fcn_infiniband_p_key (ARGS_GET_FCN)
p_key = nm_setting_infiniband_get_p_key (s_infiniband);
if (p_key == -1) {
+ NM_SET_OUT (out_is_default, TRUE);
if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY)
return "default";
else
return _("default");
- } else
- RETURN_STR_TO_FREE (g_strdup_printf ("0x%04x", p_key));
+ }
+
+ RETURN_STR_TO_FREE (g_strdup_printf ("0x%04x", p_key));
}
static gconstpointer
@@ -3139,6 +3136,7 @@ _get_fcn_ip_config_addresses (ARGS_GET_FCN)
nm_ip_address_get_prefix (addr));
}
+ NM_SET_OUT (out_is_default, num_addresses == 0);
RETURN_STR_TO_FREE (g_string_free (printable, FALSE));
}
@@ -3210,6 +3208,7 @@ _get_fcn_ip_config_routes (ARGS_GET_FCN)
}
}
+ NM_SET_OUT (out_is_default, num_routes == 0);
RETURN_STR_TO_FREE (g_string_free (printable, FALSE));
}
@@ -3456,14 +3455,6 @@ DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_ipv4_config_routes,
nm_setting_ip_config_remove_route,
_validate_and_remove_ipv4_route)
-static gconstpointer
-_get_fcn_ip6_config_ip6_privacy (ARGS_GET_FCN)
-{
- NMSettingIP6Config *s_ip6 = NM_SETTING_IP6_CONFIG (setting);
- RETURN_UNSUPPORTED_GET_TYPE ();
- RETURN_STR_TO_FREE (ip6_privacy_to_string (nm_setting_ip6_config_get_ip6_privacy (s_ip6), get_type));
-}
-
static const char *ipv6_valid_methods[] = {
NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
NM_SETTING_IP6_CONFIG_METHOD_AUTO,
@@ -3715,29 +3706,6 @@ DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_ipv6_config_routes,
nm_setting_ip_config_remove_route,
_validate_and_remove_ipv6_route)
-static gboolean
-_set_fcn_ip6_config_ip6_privacy (ARGS_SET_FCN)
-{
- unsigned long val_int;
-
- nm_assert (!error || !*error);
-
- if (!nmc_string_to_uint (value, FALSE, 0, 0, &val_int)) {
- g_set_error (error, 1, 0, _("'%s' is not a number"), value);
- return FALSE;
- }
-
- if ( val_int != NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED
- && val_int != NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR
- && val_int != NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR) {
- g_set_error (error, 1, 0, _("'%s' is not valid; use 0, 1, or 2"), value);
- return FALSE;
- }
-
- g_object_set (setting, property_info->property_name, val_int, NULL);
- return TRUE;
-}
-
static gconstpointer
_get_fcn_olpc_mesh_ssid (ARGS_GET_FCN)
{
@@ -3753,6 +3721,7 @@ _get_fcn_olpc_mesh_ssid (ARGS_GET_FCN)
g_bytes_get_size (ssid));
}
+ NM_SET_OUT (out_is_default, !ssid_str);
RETURN_STR_TO_FREE (ssid_str);
}
@@ -3808,6 +3777,7 @@ _get_fcn_tc_config_qdiscs (ARGS_GET_FCN)
}
}
+ NM_SET_OUT (out_is_default, num_qdiscs == 0);
RETURN_STR_TO_FREE (g_string_free (printable, FALSE));
}
@@ -3884,6 +3854,7 @@ _get_fcn_tc_config_tfilters (ARGS_GET_FCN)
}
}
+ NM_SET_OUT (out_is_default, num_tfilters == 0);
RETURN_STR_TO_FREE (g_string_free (printable, FALSE));
}
@@ -4028,6 +3999,7 @@ _get_fcn_team_link_watchers (ARGS_GET_FCN)
}
}
+ NM_SET_OUT (out_is_default, num_watchers == 0);
RETURN_STR_TO_FREE (g_string_free (printable, FALSE));
}
@@ -4101,6 +4073,7 @@ _get_fcn_team_port_link_watchers (ARGS_GET_FCN)
}
}
+ NM_SET_OUT (out_is_default, num_watchers == 0);
RETURN_STR_TO_FREE (g_string_free (printable, FALSE));
}
@@ -4153,24 +4126,39 @@ static gconstpointer
_get_fcn_vlan_flags (ARGS_GET_FCN)
{
NMSettingVlan *s_vlan = NM_SETTING_VLAN (setting);
+ guint32 flags;
+
RETURN_UNSUPPORTED_GET_TYPE ();
- RETURN_STR_TO_FREE (vlan_flags_to_string (nm_setting_vlan_get_flags (s_vlan), get_type));
+
+ flags = nm_setting_vlan_get_flags (s_vlan);
+ NM_SET_OUT (out_is_default, flags == 0);
+ RETURN_STR_TO_FREE (vlan_flags_to_string (flags, get_type));
}
static gconstpointer
_get_fcn_vlan_ingress_priority_map (ARGS_GET_FCN)
{
NMSettingVlan *s_vlan = NM_SETTING_VLAN (setting);
+ char *str;
+
RETURN_UNSUPPORTED_GET_TYPE ();
- RETURN_STR_TO_FREE (vlan_priorities_to_string (s_vlan, NM_VLAN_INGRESS_MAP));
+
+ str = vlan_priorities_to_string (s_vlan, NM_VLAN_INGRESS_MAP);
+ NM_SET_OUT (out_is_default, !str || !str[0]);
+ RETURN_STR_TO_FREE (str);
}
static gconstpointer
_get_fcn_vlan_egress_priority_map (ARGS_GET_FCN)
{
NMSettingVlan *s_vlan = NM_SETTING_VLAN (setting);
+ char *str;
+
RETURN_UNSUPPORTED_GET_TYPE ();
- RETURN_STR_TO_FREE (vlan_priorities_to_string (s_vlan, NM_VLAN_EGRESS_MAP));
+
+ str = vlan_priorities_to_string (s_vlan, NM_VLAN_EGRESS_MAP);
+ NM_SET_OUT (out_is_default, !str || !str[0]);
+ RETURN_STR_TO_FREE (str);
}
static gboolean
@@ -4293,7 +4281,7 @@ _get_fcn_vpn_data (ARGS_GET_FCN)
data_item_str = g_string_new (NULL);
nm_setting_vpn_foreach_data_item (s_vpn, &vpn_data_item, data_item_str);
-
+ NM_SET_OUT (out_is_default, data_item_str->len == 0);
RETURN_STR_TO_FREE (g_string_free (data_item_str, FALSE));
}
@@ -4307,7 +4295,7 @@ _get_fcn_vpn_secrets (ARGS_GET_FCN)
secret_str = g_string_new (NULL);
nm_setting_vpn_foreach_secret (s_vpn, &vpn_data_item, secret_str);
-
+ NM_SET_OUT (out_is_default, secret_str->len == 0);
RETURN_STR_TO_FREE (g_string_free (secret_str, FALSE));
}
@@ -4449,6 +4437,7 @@ _get_fcn_wireless_ssid (ARGS_GET_FCN)
g_bytes_get_size (ssid));
}
+ NM_SET_OUT (out_is_default, !ssid_str || !ssid_str[0]);
RETURN_STR_TO_FREE (ssid_str);
}
@@ -4503,39 +4492,23 @@ DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_wireless_mac_address_blacklist,
_validate_and_remove_wifi_mac_blacklist_item)
static gconstpointer
-_get_fcn_wireless_security_wep_key0 (ARGS_GET_FCN)
+_get_fcn_wireless_security_wep_key (ARGS_GET_FCN)
{
NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting);
+ char *key;
+ guint index;
RETURN_UNSUPPORTED_GET_TYPE ();
- RETURN_STR_TO_FREE (g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, 0)));
-}
-
-static gconstpointer
-_get_fcn_wireless_security_wep_key1 (ARGS_GET_FCN)
-{
- NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting);
-
- RETURN_UNSUPPORTED_GET_TYPE ();
- RETURN_STR_TO_FREE (g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, 1)));
-}
-static gconstpointer
-_get_fcn_wireless_security_wep_key2 (ARGS_GET_FCN)
-{
- NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting);
-
- RETURN_UNSUPPORTED_GET_TYPE ();
- RETURN_STR_TO_FREE (g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, 2)));
-}
+ nm_assert (g_str_has_prefix (property_info->property_name, "wep-key"));
+ nm_assert (NM_IN_SET (property_info->property_name[7], '0', '1', '2', '3'));
+ nm_assert (property_info->property_name[8] == '\0');
-static gconstpointer
-_get_fcn_wireless_security_wep_key3 (ARGS_GET_FCN)
-{
- NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting);
+ index = property_info->property_name[7] - '0';
- RETURN_UNSUPPORTED_GET_TYPE ();
- RETURN_STR_TO_FREE (g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, 3)));
+ key = g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, index));
+ NM_SET_OUT (out_is_default, !key);
+ RETURN_STR_TO_FREE (key);
}
static const char *wifi_sec_valid_protos[] = { "wpa", "rsn", NULL };
@@ -4886,7 +4859,7 @@ static const NMMetaPropertyType _pt_gobject_mac = {
static const NMMetaPropertyType _pt_gobject_secret_flags = {
.get_fcn = _get_fcn_gobject_secret_flags,
- .set_fcn = _set_fcn_gobject_secret_flags,
+ .set_fcn = _set_fcn_gobject_enum,
.values_fcn = _values_fcn_gobject_enum,
};
@@ -6082,9 +6055,18 @@ static const NMMetaPropertyInfo *const property_infos_IP6_CONFIG[] = {
.property_type = &_pt_gobject_bool,
),
PROPERTY_INFO_WITH_DESC (NM_SETTING_IP6_CONFIG_IP6_PRIVACY,
- .property_type = DEFINE_PROPERTY_TYPE (
- .get_fcn = _get_fcn_ip6_config_ip6_privacy,
- .set_fcn = _set_fcn_ip6_config_ip6_privacy,
+ .property_type = &_pt_gobject_enum,
+ .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_enum,
+ .value_infos_get = ENUM_VALUE_INFOS (
+ {
+ .value = NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR,
+ .nick = "enabled, prefer public IP",
+ },
+ {
+ .value = NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR,
+ .nick = "enabled, prefer temporary IP",
+ }
+ ),
),
),
PROPERTY_INFO_WITH_DESC (NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE,
@@ -7341,28 +7323,28 @@ static const NMMetaPropertyInfo *const property_infos_WIRELESS_SECURITY[] = {
PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_KEY0,
.is_secret = TRUE,
.property_type = DEFINE_PROPERTY_TYPE (
- .get_fcn = _get_fcn_wireless_security_wep_key0,
+ .get_fcn = _get_fcn_wireless_security_wep_key,
.set_fcn = _set_fcn_wireless_wep_key,
),
),
PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_KEY1,
.is_secret = TRUE,
.property_type = DEFINE_PROPERTY_TYPE (
- .get_fcn = _get_fcn_wireless_security_wep_key1,
+ .get_fcn = _get_fcn_wireless_security_wep_key,
.set_fcn = _set_fcn_wireless_wep_key,
),
),
PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_KEY2,
.is_secret = TRUE,
.property_type = DEFINE_PROPERTY_TYPE (
- .get_fcn = _get_fcn_wireless_security_wep_key2,
+ .get_fcn = _get_fcn_wireless_security_wep_key,
.set_fcn = _set_fcn_wireless_wep_key,
),
),
PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_KEY3,
.is_secret = TRUE,
.property_type = DEFINE_PROPERTY_TYPE (
- .get_fcn = _get_fcn_wireless_security_wep_key3,
+ .get_fcn = _get_fcn_wireless_security_wep_key,
.set_fcn = _set_fcn_wireless_wep_key,
),
),
@@ -7912,6 +7894,7 @@ _meta_type_setting_info_editor_get_fcn (const NMMetaAbstractInfo *abstract_info,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
+ gboolean *out_is_default,
gpointer *out_to_free)
{
const NMMetaSettingInfoEditor *info = (const NMMetaSettingInfoEditor *) abstract_info;
@@ -7937,6 +7920,7 @@ _meta_type_property_info_get_fcn (const NMMetaAbstractInfo *abstract_info,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
+ gboolean *out_is_default,
gpointer *out_to_free)
{
const NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info;
@@ -7952,8 +7936,10 @@ _meta_type_property_info_get_fcn (const NMMetaAbstractInfo *abstract_info,
nm_assert (out_to_free);
if ( info->is_secret
- && !NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS))
+ && !NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS)) {
+ NM_SET_OUT (out_is_default, TRUE);
return _get_text_hidden (get_type);
+ }
return info->property_type->get_fcn (info,
environment,
@@ -7962,6 +7948,7 @@ _meta_type_property_info_get_fcn (const NMMetaAbstractInfo *abstract_info,
get_type,
get_flags,
out_flags,
+ out_is_default,
out_to_free);
}
diff --git a/clients/common/nm-meta-setting-desc.h b/clients/common/nm-meta-setting-desc.h
index e61b1fc4a6..bb07515d5e 100644
--- a/clients/common/nm-meta-setting-desc.h
+++ b/clients/common/nm-meta-setting-desc.h
@@ -199,6 +199,7 @@ struct _NMMetaPropertyType {
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
+ gboolean *out_is_default,
gpointer *out_to_free);
gboolean (*set_fcn) (const NMMetaPropertyInfo *property_info,
const NMMetaEnvironment *environment,
@@ -241,7 +242,8 @@ struct _NMMetaPropertyTypData {
GType (*get_gtype) (void);
int min;
int max;
- const struct _NMUtilsEnumValueInfo *value_infos;
+ const struct _NMUtilsEnumValueInfo *value_infos_get; /* nicks for get function */
+ const struct _NMUtilsEnumValueInfo *value_infos; /* nicks for set function */
void (*pre_set_notify) (const NMMetaPropertyInfo *property_info,
const NMMetaEnvironment *environment,
gpointer environment_user_data,
@@ -362,6 +364,7 @@ struct _NMMetaType {
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
+ gboolean *out_is_defalt,
gpointer *out_to_free);
const char *const*(*complete_fcn) (const NMMetaAbstractInfo *info,
const NMMetaEnvironment *environment,
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c
index 050d0c5da5..4e38e35718 100644
--- a/libnm-core/nm-utils.c
+++ b/libnm-core/nm-utils.c
@@ -4805,7 +4805,7 @@ gssize _nm_utils_dns_option_find_idx (GPtrArray *array, const char *option)
char *
nm_utils_enum_to_str (GType type, int value)
{
- return _nm_utils_enum_to_str_full (type, value, ", ");
+ return _nm_utils_enum_to_str_full (type, value, ", ", NULL);
}
/**
diff --git a/shared/nm-utils/nm-enum-utils.c b/shared/nm-utils/nm-enum-utils.c
index 70a8b415dd..b9bc6e88fa 100644
--- a/shared/nm-utils/nm-enum-utils.c
+++ b/shared/nm-utils/nm-enum-utils.c
@@ -64,10 +64,10 @@ _enum_is_valid_flags_nick (const char *str)
char *
_nm_utils_enum_to_str_full (GType type,
int value,
- const char *flags_separator)
+ const char *flags_separator,
+ const NMUtilsEnumValueInfo *value_infos)
{
- GTypeClass *class;
- char *ret;
+ nm_auto_unref_gtypeclass GTypeClass *class = NULL;
if ( flags_separator
&& ( !flags_separator[0]
@@ -79,12 +79,17 @@ _nm_utils_enum_to_str_full (GType type,
if (G_IS_ENUM_CLASS (class)) {
GEnumValue *enum_value;
+ for ( ; value_infos && value_infos->nick; value_infos++) {
+ if (value_infos->value == value)
+ return g_strdup (value_infos->nick);
+ }
+
enum_value = g_enum_get_value (G_ENUM_CLASS (class), value);
if ( !enum_value
|| !_enum_is_valid_enum_nick (enum_value->value_nick))
- ret = g_strdup_printf ("%d", value);
+ return g_strdup_printf ("%d", value);
else
- ret = strdup (enum_value->value_nick);
+ return g_strdup (enum_value->value_nick);
} else if (G_IS_FLAGS_CLASS (class)) {
GFlagsValue *flags_value;
GString *str = g_string_new ("");
@@ -92,6 +97,28 @@ _nm_utils_enum_to_str_full (GType type,
flags_separator = flags_separator ?: " ";
+ for ( ; value_infos && value_infos->nick; value_infos++) {
+
+ nm_assert (_enum_is_valid_flags_nick (value_infos->nick));
+
+ if (uvalue == 0) {
+ if (value_infos->value != 0)
+ continue;
+ } else {
+ if (!NM_FLAGS_ALL (uvalue, (unsigned) value_infos->value))
+ continue;
+ }
+
+ if (str->len)
+ g_string_append (str, flags_separator);
+ g_string_append (str, value_infos->nick);
+ uvalue &= ~((unsigned) value_infos->value);
+ if (uvalue == 0) {
+ /* we printed all flags. Done. */
+ goto flags_done;
+ }
+ }
+
do {
flags_value = g_flags_get_first_value (G_FLAGS_CLASS (class), uvalue);
if (str->len)
@@ -105,12 +132,12 @@ _nm_utils_enum_to_str_full (GType type,
g_string_append (str, flags_value->value_nick);
uvalue &= ~flags_value->value;
} while (uvalue);
- ret = g_string_free (str, FALSE);
- } else
- g_return_val_if_reached (NULL);
- g_type_class_unref (class);
- return ret;
+flags_done:
+ return g_string_free (str, FALSE);
+ }
+
+ g_return_val_if_reached (NULL);
}
static const NMUtilsEnumValueInfo *
diff --git a/shared/nm-utils/nm-enum-utils.h b/shared/nm-utils/nm-enum-utils.h
index b78d919176..d6dae859ad 100644
--- a/shared/nm-utils/nm-enum-utils.h
+++ b/shared/nm-utils/nm-enum-utils.h
@@ -31,7 +31,10 @@ typedef struct _NMUtilsEnumValueInfo {
int value;
} NMUtilsEnumValueInfo;
-char *_nm_utils_enum_to_str_full (GType type, int value, const char *sep);
+char *_nm_utils_enum_to_str_full (GType type,
+ int value,
+ const char *sep,
+ const NMUtilsEnumValueInfo *value_infos);
gboolean _nm_utils_enum_from_str_full (GType type,
const char *str,
int *out_value,
diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c
index 2b64f3fc7f..c0dad6ab27 100644
--- a/src/settings/plugins/ifcfg-rh/shvar.c
+++ b/src/settings/plugins/ifcfg-rh/shvar.c
@@ -1278,7 +1278,7 @@ svSetValueEnum (shvarFile *s, const char *key, GType gtype, int value)
{
gs_free char *v = NULL;
- v = _nm_utils_enum_to_str_full (gtype, value, " ");
+ v = _nm_utils_enum_to_str_full (gtype, value, " ", NULL);
return svSetValueStr (s, key, v);
}