diff options
author | Thomas Haller <thaller@redhat.com> | 2017-04-06 15:14:23 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-04-12 11:24:04 +0200 |
commit | 3045daf1276df4e629f3478c3b0302370a926b5c (patch) | |
tree | fb099eed3c6be0405d810f746fadeffeb955b14c | |
parent | fdd758112f19a0e29bd1540604d36c1ffe2de1c1 (diff) | |
download | NetworkManager-3045daf1276df4e629f3478c3b0302370a926b5c.tar.gz |
cli: use nmc_print() to output setting data
-rw-r--r-- | clients/cli/connections.c | 24 | ||||
-rw-r--r-- | clients/cli/nmcli.c | 2 | ||||
-rw-r--r-- | clients/cli/settings.c | 93 | ||||
-rw-r--r-- | clients/cli/settings.h | 2 | ||||
-rw-r--r-- | clients/cli/utils.c | 72 | ||||
-rw-r--r-- | clients/common/nm-meta-setting-desc.c | 102 | ||||
-rw-r--r-- | clients/common/nm-meta-setting-desc.h | 6 | ||||
-rw-r--r-- | clients/common/tests/test-general.c | 5 |
8 files changed, 127 insertions, 179 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c index ff8c4e97a5..72eb0f8fd3 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -709,7 +709,7 @@ update_secrets_in_connection (NMRemoteConnection *remote, NMConnection *local) } static gboolean -nmc_connection_profile_details (NMConnection *connection, NmCli *nmc, gboolean secrets) +nmc_connection_profile_details (NMConnection *connection, NmCli *nmc) { GError *error = NULL; GArray *print_settings_array; @@ -771,7 +771,7 @@ nmc_connection_profile_details (NMConnection *connection, NmCli *nmc, gboolean s setting = nm_connection_get_setting_by_name (connection, nm_meta_setting_infos_editor[section_idx].general->setting_name); if (setting) { - setting_details (&nmc->nmc_config, setting, prop_name, secrets); + setting_details (&nmc->nmc_config, setting, prop_name); was_output = TRUE; } } @@ -1875,7 +1875,7 @@ do_connections_show (NmCli *nmc, int argc, char **argv) nmc->required_fields = profile_flds; if (nmc->nmc_config.show_secrets) update_secrets_in_connection (NM_REMOTE_CONNECTION (con), con); - res = nmc_connection_profile_details (con, nmc, nmc->nmc_config.show_secrets); + res = nmc_connection_profile_details (con, nmc); nmc->required_fields = NULL; if (!res) goto finish; @@ -1893,7 +1893,7 @@ do_connections_show (NmCli *nmc, int argc, char **argv) } } new_line = TRUE; - + /* Take next argument. * But for pos != NULL we have more connections of the same name, * so process the same argument again. @@ -3187,14 +3187,11 @@ get_valid_properties_string (const NameItem *array, /* Search the array with the arguments of the current property */ setting_info = nm_meta_setting_info_editor_find_by_name (iter->name); - j = 0; - while (TRUE) { + for (j = 0; j < setting_info->properties_num; j++) { gchar *new; const char *arg_name; - if (j + 1 >= setting_info->properties_num) - break; - arg_name = setting_info->properties[j + 1].property_name; + arg_name = setting_info->properties[j].property_name; /* If required, expand the alias too */ if (!postfix && iter->alias) { @@ -3207,10 +3204,8 @@ get_valid_properties_string (const NameItem *array, g_free (new); } - if (postfix && !g_str_has_prefix (arg_name, postfix)) { - j++; + if (postfix && !g_str_has_prefix (arg_name, postfix)) continue; - } if (modifier) g_string_append_c (str, modifier); @@ -3219,7 +3214,6 @@ get_valid_properties_string (const NameItem *array, arg_name); g_string_append (str, new); g_free (new); - j++; } iter++; } @@ -5969,7 +5963,7 @@ editor_show_connection (NMConnection *connection, NmCli *nmc) nmc->nmc_config_mutable.multiline_output = TRUE; nmc->nmc_config_mutable.escape_values = 0; - nmc_connection_profile_details (connection, nmc, nmc->nmc_config.show_secrets); + nmc_connection_profile_details (connection, nmc); } static void @@ -5982,7 +5976,7 @@ editor_show_setting (NMSetting *setting, NmCli *nmc) nmc->nmc_config_mutable.multiline_output = TRUE; nmc->nmc_config_mutable.escape_values = 0; - setting_details (&nmc->nmc_config, setting, NULL, nmc->nmc_config.show_secrets); + setting_details (&nmc->nmc_config, setting, NULL); } typedef enum { diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c index 2d224cf777..df1c59810c 100644 --- a/clients/cli/nmcli.c +++ b/clients/cli/nmcli.c @@ -75,8 +75,6 @@ complete_field_setting (GHashTable *h, NMMetaSettingType setting_type) guint i; for (i = 0; i < setting_info->properties_num; i++) { - if (setting_info->properties[i].is_name) - continue; g_hash_table_add (h, g_strdup_printf ("%s.%s", setting_info->general->setting_name, setting_info->properties[i].property_name)); diff --git a/clients/cli/settings.c b/clients/cli/settings.c index 99eaa4f700..9792f60c08 100644 --- a/clients/cli/settings.c +++ b/clients/cli/settings.c @@ -471,10 +471,7 @@ get_property_val (NMSetting *setting, const char *prop, NMMetaAccessorGetType ge g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if ((property_info = nm_meta_property_info_find_by_setting (setting, prop))) { - if (property_info->is_name) { - /* Traditionally, the "name" property was not handled here. - * For the moment, skip it from get_property_val(). */ - } else if (property_info->property_type->get_fcn) { + if (property_info->property_type->get_fcn) { return property_info->property_type->get_fcn (&meta_environment, NULL, property_info, @@ -549,10 +546,7 @@ nmc_setting_set_property (NMSetting *setting, const char *prop, const char *valu return TRUE; } - if (property_info->is_name) { - /* Traditionally, the "name" property was not handled here. - * For the moment, skip it from get_property_val(). */ - } else if (property_info->property_type->set_fcn) { + if (property_info->property_type->set_fcn) { switch (property_info->setting_info->general->meta_type) { case NM_META_SETTING_TYPE_CONNECTION: if (nm_streq (property_info->property_name, NM_SETTING_CONNECTION_SECONDARIES)) { @@ -613,10 +607,7 @@ nmc_setting_reset_property (NMSetting *setting, const char *prop, GError **error g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if ((property_info = nm_meta_property_info_find_by_setting (setting, prop))) { - if (property_info->is_name) { - /* Traditionally, the "name" property was not handled here. - * For the moment, skip it from get_property_val(). */ - } else if (property_info->property_type->set_fcn) { + if (property_info->property_type->set_fcn) { nmc_property_set_default_value (setting, prop); return TRUE; } @@ -648,10 +639,7 @@ nmc_setting_remove_property_option (NMSetting *setting, g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if ((property_info = nm_meta_property_info_find_by_setting (setting, prop))) { - if (property_info->is_name) { - /* Traditionally, the "name" property was not handled here. - * For the moment, skip it from get_property_val(). */ - } else if (property_info->property_type->remove_fcn) { + if (property_info->property_type->remove_fcn) { return property_info->property_type->remove_fcn (&meta_environment, NULL, property_info, @@ -707,10 +695,7 @@ nmc_setting_get_property_allowed_values (NMSetting *setting, const char *prop, c *out_to_free = NULL; if ((property_info = nm_meta_property_info_find_by_setting (setting, prop))) { - if (property_info->is_name) { - /* Traditionally, the "name" property was not handled here. - * For the moment, skip it from get_property_val(). */ - } else if (property_info->property_type->values_fcn) { + if (property_info->property_type->values_fcn) { return property_info->property_type->values_fcn (property_info, out_to_free); } else if (property_info->property_typ_data && property_info->property_typ_data->values_static) @@ -751,10 +736,7 @@ nmc_setting_get_property_desc (NMSetting *setting, const char *prop) setting_desc_title = _("[NM property description]"); } - if (property_info->is_name) { - /* Traditionally, the "name" property was not handled here. - * For the moment, skip it from get_property_val(). */ - } else if (property_info->property_type->describe_fcn) { + if (property_info->property_type->describe_fcn) { desc = property_info->property_type->describe_fcn (property_info, &desc_to_free); } else desc = property_info->describe_message; @@ -809,29 +791,12 @@ nmc_property_set_gvalue (NMSetting *setting, const char *prop, GValue *value) /*****************************************************************************/ -static NmcOutputField * -_dup_fields_array (const NMMetaSettingInfoEditor *setting_info, NmcOfFlags flags) -{ - NmcOutputField *row; - gsize l; - - l = setting_info->properties_num; - - row = g_malloc0 ((l + 1) * sizeof (NmcOutputField)); - for (l = 0; l < setting_info->properties_num; l++) - row[l].info = (const NMMetaAbstractInfo *) &setting_info->properties[l]; - row[0].flags = flags; - return row; -} - gboolean -setting_details (const NmcConfig *nmc_config, NMSetting *setting, const char *one_prop, gboolean show_secrets) +setting_details (const NmcConfig *nmc_config, NMSetting *setting, const char *one_prop) { const NMMetaSettingInfoEditor *setting_info; - NmcOutputField *arr; - guint i; - NMMetaAccessorGetType type = NM_META_ACCESSOR_GET_TYPE_PRETTY; - NMC_OUTPUT_DATA_DEFINE_SCOPED (out); + gs_free_error GError *error = NULL; + gs_free char *fields_str = NULL; g_return_val_if_fail (NM_IS_SETTING (setting), FALSE); @@ -839,36 +804,20 @@ setting_details (const NmcConfig *nmc_config, NMSetting *setting, const char *on if (!setting_info) return FALSE; - if (nmc_config->print_output == NMC_PRINT_TERSE) - type = NM_META_ACCESSOR_GET_TYPE_PARSABLE; - - out_indices = parse_output_fields (one_prop, - (const NMMetaAbstractInfo *const*) nm_property_infos_for_setting_type (setting_info->general->meta_type), - FALSE, NULL, NULL); - arr = _dup_fields_array (setting_info, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (out.output_data, arr); - - arr = _dup_fields_array (setting_info, NMC_OF_FLAG_SECTION_PREFIX); - for (i = 0; i < setting_info->properties_num; i++) { - const NMMetaPropertyInfo *property_info = &setting_info->properties[i]; - - nm_assert (property_info->setting_info == setting_info); - - if (!property_info->is_secret || show_secrets) { - set_val_str (arr, i, property_info->property_type->get_fcn (&meta_environment, - NULL, - property_info, - setting, - type, - show_secrets ? NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS : 0)); - } else - set_val_str (arr, i, g_strdup (_(NM_META_TEXT_HIDDEN))); + if (one_prop) { + /* hack around setting-details being called for one setting. Must prefix the + * property name with the setting name. Later we should remove setting_details() + * and merge it into the caller. */ + fields_str = g_strdup_printf ("%s.%s", nm_setting_get_name (setting), one_prop); } - g_ptr_array_add (out.output_data, arr); - - print_data_prepare_width (out.output_data); - print_data (nmc_config, out_indices, NULL, 0, &out); + if (!nmc_print (nmc_config, + (gpointer[]) { setting, NULL }, + NULL, + (const NMMetaAbstractInfo *const[]) { (const NMMetaAbstractInfo *) setting_info, NULL }, + fields_str, + &error)) + return FALSE; return TRUE; } diff --git a/clients/cli/settings.h b/clients/cli/settings.h index 2a90753057..0125a78269 100644 --- a/clients/cli/settings.h +++ b/clients/cli/settings.h @@ -60,6 +60,6 @@ void nmc_property_set_default_value (NMSetting *setting, const char *prop); gboolean nmc_property_get_gvalue (NMSetting *setting, const char *prop, GValue *value); gboolean nmc_property_set_gvalue (NMSetting *setting, const char *prop, GValue *value); -gboolean setting_details (const NmcConfig *nmc_config, NMSetting *setting, const char *one_prop, gboolean secrets); +gboolean setting_details (const NmcConfig *nmc_config, NMSetting *setting, const char *one_prop); #endif /* NMC_SETTINGS_H */ diff --git a/clients/cli/utils.c b/clients/cli/utils.c index 4368267dc6..84b90c0a10 100644 --- a/clients/cli/utils.c +++ b/clients/cli/utils.c @@ -834,7 +834,7 @@ _output_selection_select_one (const NMMetaAbstractInfo *const* fields_array, if (fi->meta_type == &nm_meta_type_setting_info_editor) { const NMMetaSettingInfoEditor *fi_s = &fi->as.setting_info; - for (j = 1; j < fi_s->properties_num; j++) { + for (j = 0; j < fi_s->properties_num; j++) { if (g_ascii_strcasecmp (right, fi_s->properties[j].property_name) == 0) { found = TRUE; break; @@ -1037,7 +1037,9 @@ _output_selection_append (GArray *cols, si, gfree_keeper, error)) return FALSE; } - g_array_index (cols, PrintDataCol, col_idx).is_leaf = FALSE; + + if (selection_item->info->meta_type != &nm_meta_type_setting_info_editor) + g_array_index (cols, PrintDataCol, col_idx).is_leaf = FALSE; } return TRUE; @@ -1282,6 +1284,7 @@ typedef struct { const PrintDataCol *col; bool is_nested; const char *title; + bool title_to_free:1; int width; } PrintDataHeaderCell; @@ -1297,6 +1300,13 @@ typedef struct { static void _print_data_header_cell_clear (gpointer cell_p) { + PrintDataHeaderCell *cell = cell_p; + + if (cell->title_to_free) { + g_free ((char *) cell->title); + cell->title_to_free = FALSE; + } + cell->title = NULL; } static void @@ -1331,6 +1341,7 @@ _print_fill (const NmcConfig *nmc_config, guint targets_len; gboolean pretty; NMMetaAccessorGetType text_get_type; + NMMetaAccessorGetFlags text_get_flags; pretty = (nmc_config->print_output != NMC_PRINT_TERSE); @@ -1341,11 +1352,15 @@ _print_fill (const NmcConfig *nmc_config, const PrintDataCol *col; PrintDataHeaderCell *header_cell; guint col_idx; + const NMMetaAbstractInfo *info; + gboolean translate_title; col = &cols[i_col]; if (!col->is_leaf) continue; + info = col->selection_item->info; + col_idx = header_row->len; g_array_set_size (header_row, col_idx + 1); @@ -1354,8 +1369,23 @@ _print_fill (const NmcConfig *nmc_config, header_cell->col_idx = col_idx; header_cell->col = col; header_cell->is_nested = FALSE; - header_cell->title = nm_meta_abstract_info_get_name (col->selection_item->info); - if (pretty) + + translate_title = pretty; + + if (info->meta_type == &nm_meta_type_property_info) { + header_cell->title = nm_meta_abstract_info_get_name (info); + if (nmc_config->multiline_output) { + header_cell->title = g_strdup_printf ("%s.%s", + ((const NMMetaPropertyInfo *) info)->setting_info->general->setting_name, + header_cell->title); + header_cell->title_to_free = TRUE; + } + } else if (info->meta_type == &nm_meta_type_setting_info_editor) + header_cell->title = N_("name"); + else + header_cell->title = nm_meta_abstract_info_get_name (info); + + if (translate_title) header_cell->title = _(header_cell->title); } @@ -1368,6 +1398,9 @@ _print_fill (const NmcConfig *nmc_config, text_get_type = pretty ? NM_META_ACCESSOR_GET_TYPE_PRETTY : NM_META_ACCESSOR_GET_TYPE_PARSABLE; + text_get_flags = NM_META_ACCESSOR_GET_FLAGS_NONE; + if (nmc_config->show_secrets) + text_get_flags |= NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS; for (i_row = 0; i_row < targets_len; i_row++) { gpointer target = targets[i_row]; @@ -1389,7 +1422,7 @@ _print_fill (const NmcConfig *nmc_config, NULL, target, text_get_type, - NM_META_ACCESSOR_GET_FLAGS_NONE, + text_get_flags, (gpointer *) &to_free); cell->text_to_free = !!to_free; @@ -1434,6 +1467,26 @@ _print_fill (const NmcConfig *nmc_config, *out_cells = cells; } +static gboolean +_print_skip_column (const NmcConfig *nmc_config, + const PrintDataHeaderCell *header_cell) +{ + if (nmc_config->multiline_output) { + if (header_cell->col->selection_item->info->meta_type == &nm_meta_type_setting_info_editor) { + /* we skip the "name" entry for the setting in multiline output. */ + return TRUE; + } + } else { + if ( header_cell->col->selection_item->info->meta_type == &nm_meta_type_setting_info_editor + && header_cell->col->selection_item->sub_selection) { + /* in tabular form, we skip the "name" entry for sections that have sub-selections. + * That is, for "ipv4.may-fail", but not for "ipv4". */ + return TRUE; + } + } + return FALSE; +} + static void _print_do (const NmcConfig *nmc_config, const char *header_name_no_l10n, @@ -1453,7 +1506,7 @@ _print_do (const NmcConfig *nmc_config, g_assert (col_len && row_len); /* Main header */ - if (pretty) { + if (pretty && header_name_no_l10n) { gs_free char *line = NULL; int header_width; const char *header_name = _(header_name_no_l10n); @@ -1485,6 +1538,9 @@ _print_do (const NmcConfig *nmc_config, const PrintDataHeaderCell *header_cell = &header_row[i_col]; const char *title; + if (_print_skip_column (nmc_config, header_cell)) + continue; + title = header_cell->title; width1 = strlen (title); @@ -1515,6 +1571,9 @@ _print_do (const NmcConfig *nmc_config, gs_free char *text_to_free = NULL; const char *text; + if (_print_skip_column (nmc_config, cell->header_cell)) + continue; + if (cell->header_cell->is_nested) { g_assert_not_reached (/*TODO*/); } else { @@ -1522,7 +1581,6 @@ _print_do (const NmcConfig *nmc_config, cell->term_color, cell->term_format, cell->text, &text_to_free); } - if (multiline) { gs_free char *prefix = NULL; diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index 1af0dbad8d..1ba417a4e0 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -519,13 +519,6 @@ _env_warn_fcn (const NMMetaEnvironment *environment, const NMMetaPropertyInfo *property_info, char ***out_to_free static char * -_get_fcn_name (ARGS_GET_FCN) -{ - nm_assert (nm_streq0 (nm_setting_get_name (setting), property_info->setting_info->general->setting_name)); - return g_strdup (property_info->setting_info->general->setting_name); -} - -static char * _get_fcn_nmc_with_default (ARGS_GET_FCN) { const char *s; @@ -4473,10 +4466,6 @@ _set_fcn_wireless_security_psk (ARGS_SET_FCN) PROPERTY_TYP_DATA_SUBTYPE (stype, __VA_ARGS__), \ ) -static const NMMetaPropertyType _pt_name = { - .get_fcn = _get_fcn_name, -}; - static const NMMetaPropertyType _pt_gobject_readonly = { .get_fcn = _get_fcn_gobject, }; @@ -4533,18 +4522,6 @@ static const NMMetaPropertyType _pt_gobject_enum = { /*****************************************************************************/ -/* FIXME: it is wrong to have a property-type "name". The name is a regular - * "property" of the setting. Also, this is redundant to the setting_name - * in NMMetaSettingInfo. */ -#define PROPERTY_INFO_NAME() \ - { \ - .meta_type = &nm_meta_type_property_info, \ - .setting_info = &nm_meta_setting_infos_editor[_CURRENT_NM_META_SETTING_TYPE], \ - .property_name = N_ ("name"), \ - .is_name = TRUE, \ - .property_type = &_pt_name, \ - } - #define PROPERTY_INFO(name, doc) \ .meta_type = &nm_meta_type_property_info, \ .setting_info = &nm_meta_setting_infos_editor[_CURRENT_NM_META_SETTING_TYPE], \ @@ -4578,7 +4555,6 @@ static const NMMetaPropertyType _pt_gobject_enum = { #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_802_1X static const NMMetaPropertyInfo property_infos_802_1X[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_EAP), .property_type = DEFINE_PROPERTY_TYPE ( @@ -4866,7 +4842,6 @@ static const NMMetaPropertyInfo property_infos_802_1X[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_ADSL static const NMMetaPropertyInfo property_infos_ADSL[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_ADSL_USERNAME), .property_type = &_pt_gobject_string, @@ -4910,7 +4885,6 @@ static const NMMetaPropertyInfo property_infos_ADSL[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_BLUETOOTH static const NMMetaPropertyInfo property_infos_BLUETOOTH[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_BLUETOOTH_BDADDR), .property_type = &_pt_gobject_mac, @@ -4928,7 +4902,6 @@ static const NMMetaPropertyInfo property_infos_BLUETOOTH[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_BOND static const NMMetaPropertyInfo property_infos_BOND[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_BOND_OPTIONS), .property_type = DEFINE_PROPERTY_TYPE ( @@ -4944,7 +4917,6 @@ static const NMMetaPropertyInfo property_infos_BOND[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_BRIDGE static const NMMetaPropertyInfo property_infos_BRIDGE[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MAC_ADDRESS), .property_type = &_pt_gobject_mac, @@ -4982,7 +4954,6 @@ static const NMMetaPropertyInfo property_infos_BRIDGE[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_BRIDGE_PORT static const NMMetaPropertyInfo property_infos_BRIDGE_PORT[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_PORT_PRIORITY), .property_type = &_pt_gobject_uint, @@ -5000,7 +4971,6 @@ static const NMMetaPropertyInfo property_infos_BRIDGE_PORT[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_CDMA static const NMMetaPropertyInfo property_infos_CDMA[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_CDMA_NUMBER), .property_type = &_pt_gobject_string, @@ -5030,7 +5000,6 @@ static const NMMetaPropertyInfo property_infos_CDMA[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_CONNECTION static const NMMetaPropertyInfo property_infos_CONNECTION[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_ID), .property_type = &_pt_gobject_string, @@ -5177,7 +5146,6 @@ static const NMMetaPropertyInfo property_infos_CONNECTION[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_DCB static const NMMetaPropertyInfo property_infos_DCB[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_APP_FCOE_FLAGS), .property_type = DEFINE_PROPERTY_TYPE ( @@ -5287,15 +5255,8 @@ static const NMMetaPropertyInfo property_infos_DCB[] = { }; #undef _CURRENT_NM_META_SETTING_TYPE -#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_DUMMY -static const NMMetaPropertyInfo property_infos_DUMMY[] = { - PROPERTY_INFO_NAME(), -}; - -#undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_GSM static const NMMetaPropertyInfo property_infos_GSM[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_NUMBER), .property_type = &_pt_gobject_string, @@ -5361,7 +5322,6 @@ static const NMMetaPropertyInfo property_infos_GSM[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_INFINIBAND static const NMMetaPropertyInfo property_infos_INFINIBAND[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_INFINIBAND_MAC_ADDRESS), .property_type = &_pt_gobject_mac, @@ -5402,7 +5362,6 @@ static const NMMetaPropertyInfo property_infos_INFINIBAND[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_IP4_CONFIG static const NMMetaPropertyInfo property_infos_IP4_CONFIG[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO (NM_SETTING_IP_CONFIG_METHOD, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_METHOD), .property_type = DEFINE_PROPERTY_TYPE ( @@ -5535,7 +5494,6 @@ static const NMMetaPropertyInfo property_infos_IP4_CONFIG[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_IP6_CONFIG static const NMMetaPropertyInfo property_infos_IP6_CONFIG[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO (NM_SETTING_IP_CONFIG_METHOD, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_METHOD), .property_type = DEFINE_PROPERTY_TYPE ( @@ -5677,7 +5635,6 @@ static const NMMetaPropertyInfo property_infos_IP6_CONFIG[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_IP_TUNNEL static const NMMetaPropertyInfo property_infos_IP_TUNNEL[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_MODE), .property_type = DEFINE_PROPERTY_TYPE ( @@ -5740,7 +5697,6 @@ static const NMMetaPropertyInfo property_infos_IP_TUNNEL[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_MACSEC static const NMMetaPropertyInfo property_infos_MACSEC[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_MACSEC_PARENT), .property_type = &_pt_gobject_string, @@ -5793,7 +5749,6 @@ static const NMMetaPropertyInfo property_infos_MACSEC[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_MACVLAN static const NMMetaPropertyInfo property_infos_MACVLAN[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_MACVLAN_PARENT), .property_type = &_pt_gobject_string, @@ -5824,7 +5779,6 @@ static const NMMetaPropertyInfo property_infos_MACVLAN[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_OLPC_MESH static const NMMetaPropertyInfo property_infos_OLPC_MESH[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_OLPC_MESH_SSID), .property_type = DEFINE_PROPERTY_TYPE ( @@ -5848,7 +5802,6 @@ static const NMMetaPropertyInfo property_infos_OLPC_MESH[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_PPPOE static const NMMetaPropertyInfo property_infos_PPPOE[] = { - PROPERTY_INFO_NAME (), { PROPERTY_INFO_WITH_DESC (NM_SETTING_PPPOE_SERVICE), .property_type = &_pt_gobject_string, @@ -5871,7 +5824,6 @@ static const NMMetaPropertyInfo property_infos_PPPOE[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_PPP static const NMMetaPropertyInfo property_infos_PPP[] = { - PROPERTY_INFO_NAME (), { PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_NOAUTH), .property_type = &_pt_gobject_bool, @@ -5952,7 +5904,6 @@ static const NMMetaPropertyInfo property_infos_PPP[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_PROXY static const NMMetaPropertyInfo property_infos_PROXY[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_PROXY_METHOD), .property_type = DEFINE_PROPERTY_TYPE ( @@ -5986,7 +5937,6 @@ static const NMMetaPropertyInfo property_infos_PROXY[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_TEAM static const NMMetaPropertyInfo property_infos_TEAM[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_CONFIG), .describe_message = N_ (TEAM_DESCRIBE_MESSAGE), @@ -6000,7 +5950,6 @@ static const NMMetaPropertyInfo property_infos_TEAM[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_TEAM_PORT static const NMMetaPropertyInfo property_infos_TEAM_PORT[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_PORT_CONFIG), .describe_message = N_ (TEAM_DESCRIBE_MESSAGE), @@ -6014,7 +5963,6 @@ static const NMMetaPropertyInfo property_infos_TEAM_PORT[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_SERIAL static const NMMetaPropertyInfo property_infos_SERIAL[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_SERIAL_BAUD), .property_type = &_pt_gobject_uint, @@ -6043,7 +5991,6 @@ static const NMMetaPropertyInfo property_infos_SERIAL[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_TUN static const NMMetaPropertyInfo property_infos_TUN[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_TUN_MODE), .property_type = DEFINE_PROPERTY_TYPE ( @@ -6077,15 +6024,8 @@ static const NMMetaPropertyInfo property_infos_TUN[] = { }; #undef _CURRENT_NM_META_SETTING_TYPE -#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_USER -static const NMMetaPropertyInfo property_infos_USER[] = { - PROPERTY_INFO_NAME(), -}; - -#undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_VLAN static const NMMetaPropertyInfo property_infos_VLAN[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_VLAN_PARENT), .property_type = &_pt_gobject_string, @@ -6122,7 +6062,6 @@ static const NMMetaPropertyInfo property_infos_VLAN[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_VPN static const NMMetaPropertyInfo property_infos_VPN[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_VPN_SERVICE_TYPE), .property_type = DEFINE_PROPERTY_TYPE ( @@ -6164,7 +6103,6 @@ static const NMMetaPropertyInfo property_infos_VPN[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_VXLAN static const NMMetaPropertyInfo property_infos_VXLAN[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_PARENT), .property_type = &_pt_gobject_string, @@ -6234,7 +6172,6 @@ static const NMMetaPropertyInfo property_infos_VXLAN[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_WIMAX static const NMMetaPropertyInfo property_infos_WIMAX[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_WIMAX_MAC_ADDRESS), .property_type = &_pt_gobject_string, @@ -6248,7 +6185,6 @@ static const NMMetaPropertyInfo property_infos_WIMAX[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_WIRED static const NMMetaPropertyInfo property_infos_WIRED[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_PORT), /* Do not allow setting 'port' for now. It is not implemented in @@ -6345,7 +6281,6 @@ static const NMMetaPropertyInfo property_infos_WIRED[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_WIRELESS static const NMMetaPropertyInfo property_infos_WIRELESS[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SSID), .property_type = DEFINE_PROPERTY_TYPE ( @@ -6450,7 +6385,6 @@ static const NMMetaPropertyInfo property_infos_WIRELESS[] = { #undef _CURRENT_NM_META_SETTING_TYPE #define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_WIRELESS_SECURITY static const NMMetaPropertyInfo property_infos_WIRELESS_SECURITY[] = { - PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), .property_type = &_pt_gobject_string, @@ -6576,6 +6510,11 @@ static const NMMetaPropertyInfo property_infos_WIRELESS_SECURITY[] = { }; const NMMetaSettingInfoEditor nm_meta_setting_infos_editor[] = { +#define SETTING_INFO_EMPTY(type) \ + [NM_META_SETTING_TYPE_##type] = { \ + .meta_type = &nm_meta_type_setting_info_editor, \ + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_##type], \ + } #define SETTING_INFO(type) \ [NM_META_SETTING_TYPE_##type] = { \ .meta_type = &nm_meta_type_setting_info_editor, \ @@ -6592,7 +6531,7 @@ const NMMetaSettingInfoEditor nm_meta_setting_infos_editor[] = { SETTING_INFO (CDMA), SETTING_INFO (CONNECTION), SETTING_INFO (DCB), - SETTING_INFO (DUMMY), + SETTING_INFO_EMPTY (DUMMY), SETTING_INFO (GSM), SETTING_INFO (INFINIBAND), SETTING_INFO (IP4_CONFIG), @@ -6608,7 +6547,7 @@ const NMMetaSettingInfoEditor nm_meta_setting_infos_editor[] = { SETTING_INFO (TEAM), SETTING_INFO (TEAM_PORT), SETTING_INFO (TUN), - SETTING_INFO (USER), + SETTING_INFO_EMPTY (USER), SETTING_INFO (VLAN), SETTING_INFO (VPN), SETTING_INFO (VXLAN), @@ -6641,8 +6580,20 @@ _meta_type_setting_info_editor_get_fcn (const NMMetaEnvironment *environment, NMMetaAccessorGetFlags get_flags, gpointer *out_to_free) { - nm_assert (out_to_free && !*out_to_free); - g_return_val_if_reached (NULL); + const NMMetaSettingInfoEditor *info = (const NMMetaSettingInfoEditor *) abstract_info; + + nm_assert (!out_to_free || !*out_to_free); + + if (!NM_IN_SET (get_type, + NM_META_ACCESSOR_GET_TYPE_PARSABLE, + NM_META_ACCESSOR_GET_TYPE_PRETTY)) + return NULL; + + nm_assert (out_to_free); + + if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) + return _(info->general->setting_name); + return info->general->setting_name; } static gconstpointer @@ -6656,13 +6607,22 @@ _meta_type_property_info_get_fcn (const NMMetaEnvironment *environment, { const NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info; - nm_assert (out_to_free && !*out_to_free); + nm_assert (!out_to_free || !*out_to_free); if (!NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_PARSABLE, NM_META_ACCESSOR_GET_TYPE_PRETTY)) return NULL; + nm_assert (out_to_free); + + if ( info->is_secret + && !NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS)) { + if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) + return _(NM_META_TEXT_HIDDEN); + return NM_META_TEXT_HIDDEN; + } + return (*out_to_free = info->property_type->get_fcn (environment, environment_user_data, info, target, get_type, get_flags)); diff --git a/clients/common/nm-meta-setting-desc.h b/clients/common/nm-meta-setting-desc.h index 73e773b4de..6f582949f7 100644 --- a/clients/common/nm-meta-setting-desc.h +++ b/clients/common/nm-meta-setting-desc.h @@ -167,12 +167,6 @@ struct _NMMetaPropertyInfo { const char *property_name; - /* the property list for now must contain as first field the - * "name", which isn't a regular property. This is required by - * NmcOutputField and this first field is ignored for the - * group_list/setting_info. */ - bool is_name:1; - bool is_secret:1; const char *describe_doc; diff --git a/clients/common/tests/test-general.c b/clients/common/tests/test-general.c index 469dc57a73..b66262e8de 100644 --- a/clients/common/tests/test-general.c +++ b/clients/common/tests/test-general.c @@ -85,11 +85,6 @@ test_client_meta_check (void) g_assert (pi->property_name == pi->meta_type->get_name ((const NMMetaAbstractInfo *) pi)); - if (pi->is_name) - g_assert (p == 0); - else - g_assert (p != 0); - g_assert (pi->property_type); g_assert (pi->property_type->get_fcn); } |