diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 07c1cd23c1..95c8d8435d 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -148,11 +148,22 @@ NmcOutputField nmc_fields_con_show[] = { #define NMC_FIELDS_CON_SHOW_COMMON "NAME,UUID,TYPE,DEVICE" /* Helper macro to define fields */ -#define SETTING_FIELD(setting, props) { setting, N_(setting), 0, props, NULL, FALSE, FALSE, 0 } +#define SETTING_FIELD(setting, props) \ + { \ + .name = setting, \ + .name_l10n = N_(setting), \ + .group_list = props, \ + } +#define SETTING_FIELD_TYPE(setting, setting_type) \ + { \ + .name = setting, \ + .name_l10n = N_ (setting), \ + .setting_info = &nmc_setting_infos[setting_type], \ + } /* Available settings for 'connection show ' - profile part */ NmcOutputField nmc_fields_settings_names[] = { - SETTING_FIELD (NM_SETTING_CONNECTION_SETTING_NAME, nmc_fields_setting_connection + 1), /* 0 */ + SETTING_FIELD_TYPE (NM_SETTING_CONNECTION_SETTING_NAME, NM_META_SETTING_TYPE_CONNECTION), SETTING_FIELD (NM_SETTING_WIRED_SETTING_NAME, nmc_fields_setting_wired + 1), /* 1 */ SETTING_FIELD (NM_SETTING_802_1X_SETTING_NAME, nmc_fields_setting_8021X + 1), /* 2 */ SETTING_FIELD (NM_SETTING_WIRELESS_SETTING_NAME, nmc_fields_setting_wireless + 1), /* 3 */ @@ -3179,6 +3190,7 @@ get_valid_properties_string (const NameItem *array, { const NameItem *iter = array; const NmcOutputField *field_iter; + const NmcSettingInfo *setting_info; const char *prop_name = NULL; GString *str; int i, j; @@ -3219,20 +3231,31 @@ get_valid_properties_string (const NameItem *array, g_assert (nmc_fields_settings_names[j].name); j++; } - field_iter = nmc_fields_settings_names[j].group; + field_iter = nmc_fields_settings_names[j].group_list; + setting_info = nmc_fields_settings_names[j].setting_info; j = 0; - while (field_iter[j].name) { + while (TRUE) { gchar *new; - const char *arg_name = field_iter[j].name; + const char *arg_name; + + if (field_iter) { + arg_name = field_iter[j].name; + if (!arg_name) + break; + } else { + if (j + 1 >= setting_info->properties_num) + break; + arg_name = setting_info->properties[j + 1].property_name; + } /* If required, expand the alias too */ if (!postfix && iter->alias) { if (modifier) g_string_append_c (str, modifier); new = g_strdup_printf ("%s.%s\n", - iter->alias, - arg_name); + iter->alias, + arg_name); g_string_append (str, new); g_free (new); } @@ -3245,8 +3268,8 @@ get_valid_properties_string (const NameItem *array, if (modifier) g_string_append_c (str, modifier); new = g_strdup_printf ("%s.%s\n", - prop_name, - arg_name); + prop_name, + arg_name); g_string_append (str, new); g_free (new); j++; diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c index ee3f747b46..630fe871e6 100644 --- a/clients/cli/nmcli.c +++ b/clients/cli/nmcli.c @@ -66,7 +66,23 @@ struct termios termios_orig; NM_CACHED_QUARK_FCN ("nmcli-error-quark", nmcli_error_quark) static void -complete_field (GHashTable *h, const char *setting, NmcOutputField field[]) +complete_field_new (GHashTable *h, const char *setting, NMMetaSettingType setting_type) +{ + const NmcSettingInfo *setting_info = &nmc_setting_infos[setting_type]; + int i; + + for (i = 0; i < setting_info->properties_num; i++) { + const char *n = setting_info->properties[i].property_name; + + if (setting) + g_hash_table_add (h, g_strdup_printf ("%s.%s", setting, n)); + else + g_hash_table_add (h, g_strdup (n)); + } +} + +static void +complete_field (GHashTable *h, const char *setting, const NmcOutputField *field) { int i; @@ -130,7 +146,7 @@ complete_fields (const char *prefix) complete_field (h, NULL, nmc_fields_dev_show_sections); complete_field (h, NULL, nmc_fields_dev_lldp_list); - complete_field (h, "connection", nmc_fields_setting_connection); + complete_field_new (h, "connection", NM_META_SETTING_TYPE_CONNECTION); complete_field (h, "802-3-ethernet", nmc_fields_setting_wired); complete_field (h, "802-1x", nmc_fields_setting_8021X); complete_field (h, "802-11-wireless", nmc_fields_setting_wireless); diff --git a/clients/cli/nmcli.h b/clients/cli/nmcli.h index 7e33e3a70a..8efb09289b 100644 --- a/clients/cli/nmcli.h +++ b/clients/cli/nmcli.h @@ -104,17 +104,27 @@ typedef enum { #define NMC_OF_FLAG_MAIN_HEADER_ADD 0x00000004 /* Print main header in addition to values/field names */ #define NMC_OF_FLAG_MAIN_HEADER_ONLY 0x00000008 /* Print main header only */ +struct _NmcSettingInfo; + typedef struct _NmcOutputField { const char *name; /* Field's name */ const char *name_l10n; /* Field's name for translation */ int width; /* Width in screen columns */ - struct _NmcOutputField *group; /* Points to an array with available section field names if this is a section (group) field */ + const struct _NmcOutputField *group_list; /* Points to an array with available section field names if this is a section (group) field */ void *value; /* Value of current field - char* or char** (NULL-terminated array) */ gboolean value_is_array; /* Whether value is char** instead of char* */ gboolean free_value; /* Whether to free the value */ guint32 flags; /* Flags - whether and how to print values/field names/headers */ NmcTermColor color; /* Use this color to print value */ NmcTermFormat color_fmt; /* Use this terminal format to print value */ + + /* in a very particular case NmcOutputField is used in combination with + * the @group_list above. That list will go away (and the entire NmcOutputField + * should separate formatting-options, setting-metadata and output. + * + * For now, hack around that by alternatively providing a @setting_info instead + * of @group_list. */ + const struct _NmcSettingInfo *setting_info; } NmcOutputField; typedef struct { diff --git a/clients/cli/settings.c b/clients/cli/settings.c index 0d579605cf..7f3869f05f 100644 --- a/clients/cli/settings.c +++ b/clients/cli/settings.c @@ -29,61 +29,76 @@ #include "common.h" #include "nm-vpn-helpers.h" -/* Forward declarations */ -static char *wep_key_type_to_string (NMWepKeyType type); +/*****************************************************************************/ -typedef enum { - NMC_PROPERTY_GET_PRETTY, - NMC_PROPERTY_GET_PARSABLE, -} NmcPropertyGetType; - -/* Helper macro to define fields */ #define SETTING_FIELD(setting) { setting, N_(setting), 0, NULL, FALSE, FALSE, 0 } -/* Available fields for NM_SETTING_CONNECTION_SETTING_NAME */ -NmcOutputField nmc_fields_setting_connection[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_CONNECTION_ID), /* 1 */ - SETTING_FIELD (NM_SETTING_CONNECTION_UUID), /* 2 */ - SETTING_FIELD (NM_SETTING_CONNECTION_STABLE_ID), /* 3 */ - SETTING_FIELD (NM_SETTING_CONNECTION_INTERFACE_NAME), /* 4 */ - SETTING_FIELD (NM_SETTING_CONNECTION_TYPE), /* 5 */ - SETTING_FIELD (NM_SETTING_CONNECTION_AUTOCONNECT), /* 6 */ - SETTING_FIELD (NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY), /* 7 */ - SETTING_FIELD (NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES), /* 8 */ - SETTING_FIELD (NM_SETTING_CONNECTION_TIMESTAMP), /* 9 */ - SETTING_FIELD (NM_SETTING_CONNECTION_READ_ONLY), /* 10 */ - SETTING_FIELD (NM_SETTING_CONNECTION_PERMISSIONS), /* 11 */ - SETTING_FIELD (NM_SETTING_CONNECTION_ZONE), /* 12 */ - SETTING_FIELD (NM_SETTING_CONNECTION_MASTER), /* 13 */ - SETTING_FIELD (NM_SETTING_CONNECTION_SLAVE_TYPE), /* 14 */ - SETTING_FIELD (NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES), /* 15 */ - SETTING_FIELD (NM_SETTING_CONNECTION_SECONDARIES), /* 16 */ - SETTING_FIELD (NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT), /* 17 */ - SETTING_FIELD (NM_SETTING_CONNECTION_METERED), /* 18 */ - SETTING_FIELD (NM_SETTING_CONNECTION_LLDP), /* 19 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_CONNECTION_ALL "name"","\ - NM_SETTING_CONNECTION_ID","\ - NM_SETTING_CONNECTION_UUID","\ - NM_SETTING_CONNECTION_STABLE_ID","\ - NM_SETTING_CONNECTION_INTERFACE_NAME","\ - NM_SETTING_CONNECTION_TYPE","\ - NM_SETTING_CONNECTION_AUTOCONNECT","\ - NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY","\ - NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES","\ - NM_SETTING_CONNECTION_TIMESTAMP","\ - NM_SETTING_CONNECTION_READ_ONLY","\ - NM_SETTING_CONNECTION_PERMISSIONS","\ - NM_SETTING_CONNECTION_ZONE","\ - NM_SETTING_CONNECTION_MASTER","\ - NM_SETTING_CONNECTION_SLAVE_TYPE","\ - NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES","\ - NM_SETTING_CONNECTION_SECONDARIES","\ - NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT","\ - NM_SETTING_CONNECTION_METERED","\ - NM_SETTING_CONNECTION_LLDP +static char *wep_key_type_to_string (NMWepKeyType type); + +/*****************************************************************************/ + +static char * +_get_fcn_direct (const NmcSettingInfo *setting_info, + const NmcPropertyInfo *property_info, + NMSetting *setting, + NmcPropertyGetType get_type) +{ + return g_strdup (property_info->get_data.get_direct (setting)); +} + +static char * +_get_fcn_nmc (const NmcSettingInfo *setting_info, + const NmcPropertyInfo *property_info, + NMSetting *setting, + NmcPropertyGetType get_type) +{ + return property_info->get_data.get_nmc (setting, get_type); +} + +static char * +_get_fcn_gobject (const NmcSettingInfo *setting_info, + const NmcPropertyInfo *property_info, + NMSetting *setting, + NmcPropertyGetType get_type) +{ + char *s; + GValue val = G_VALUE_INIT; + + g_value_init (&val, G_TYPE_STRING); + g_object_get_property (G_OBJECT (setting), property_info->property_name, &val); + s = g_value_dup_string (&val); + g_value_unset (&val); + return s; +} + +/*****************************************************************************/ + +static const NmcOutputField * +_get_nmc_output_fields (const NmcSettingInfo *setting_info) +{ + static NmcOutputField *fields[_NM_META_SETTING_TYPE_NUM + 1] = { }; + NmcOutputField **field; + guint i; + + g_return_val_if_fail (setting_info, NULL); + g_return_val_if_fail (setting_info->general->meta_type < _NM_META_SETTING_TYPE_NUM, NULL); + + field = &fields[setting_info->general->meta_type]; + + if (G_UNLIKELY (!*field)) { + *field = g_new0 (NmcOutputField, setting_info->properties_num + 1); + for (i = 0; i < setting_info->properties_num; i++) { + NmcOutputField *f = &(*field)[i]; + + f->name = setting_info->properties[i].property_name; + f->name_l10n = setting_info->properties[i].property_name; + } + } + + return *field; +} + +/*****************************************************************************/ /* Available fields for NM_SETTING_WIRED_SETTING_NAME */ NmcOutputField nmc_fields_setting_wired[] = { @@ -8654,42 +8669,33 @@ nmc_property_set_gvalue (NMSetting *setting, const char *prop, GValue *value) (show ? func (setting, NMC_PROPERTY_GET_PRETTY) : g_strdup (_(""))) static gboolean -setting_connection_details (const NmcSettingInfo *setting_info, NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean secrets) +_get_setting_details (const NmcSettingInfo *setting_info, NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean secrets) { - NMSettingConnection *s_con = NM_SETTING_CONNECTION (setting); - NmcOutputField *tmpl, *arr; + gs_free NmcOutputField *tmpl = NULL; + NmcOutputField *arr; + guint i; size_t tmpl_len; - g_return_val_if_fail (NM_IS_SETTING_CONNECTION (s_con), FALSE); + g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (setting, setting_info->general->get_setting_gtype ()), FALSE); - tmpl = nmc_fields_setting_connection; - tmpl_len = sizeof (nmc_fields_setting_connection); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_CONNECTION_ALL, + tmpl_len = sizeof (NmcOutputField) * (setting_info->properties_num + 1); + tmpl = g_memdup (_get_nmc_output_fields (setting_info), tmpl_len); + + nmc->print_fields.indices = parse_output_fields (one_prop ?: setting_info->all_properties, tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (nmc->output_data, arr); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_connection_get_id (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 2, nmc_property_connection_get_uuid (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 3, nmc_property_connection_get_stable_id (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 4, nmc_property_connection_get_interface_name (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 5, nmc_property_connection_get_type (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 6, nmc_property_connection_get_autoconnect (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 7, nmc_property_connection_get_autoconnect_priority (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 8, nmc_property_connection_get_autoconnect_retries (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 9, nmc_property_connection_get_timestamp (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 10, nmc_property_connection_get_read_only (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 11, nmc_property_connection_get_permissions (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 12, nmc_property_connection_get_zone (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 13, nmc_property_connection_get_master (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 14, nmc_property_connection_get_slave_type (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 15, nmc_property_connection_get_autoconnect_slaves (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 16, nmc_property_connection_get_secondaries (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 17, nmc_property_connection_get_gateway_ping_timeout (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 18, nmc_property_connection_get_metered (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 19, nmc_property_connection_get_lldp (setting, NMC_PROPERTY_GET_PRETTY)); + for (i = 0; i < setting_info->properties_num; i++) { + const NmcPropertyInfo *property_info = &setting_info->properties[i]; + + set_val_str (arr, i, property_info->get_fcn (setting_info, + property_info, + setting, + NMC_PROPERTY_GET_PRETTY)); + } + g_ptr_array_add (nmc->output_data, arr); print_data (nmc); /* Print all data */ @@ -9729,6 +9735,119 @@ setting_proxy_details (const NmcSettingInfo *setting_info, NMSetting *setting, N return TRUE; } +/*****************************************************************************/ + +static const NmcPropertyInfo properties_setting_connection[] = { + { + .property_name = N_ ("name"), + .is_name = TRUE, + .get_fcn = _get_fcn_direct, + .get_data = { .get_direct = nm_setting_get_name, }, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_ID), + .get_fcn = _get_fcn_gobject, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_UUID), + .get_fcn = _get_fcn_gobject, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_STABLE_ID), + .get_fcn = _get_fcn_gobject, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_INTERFACE_NAME), + .get_fcn = _get_fcn_gobject, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_TYPE), + .get_fcn = _get_fcn_gobject, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_AUTOCONNECT), + .get_fcn = _get_fcn_gobject, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY), + .get_fcn = _get_fcn_gobject, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES), + .get_fcn = _get_fcn_nmc, + .get_data = { .get_nmc = nmc_property_connection_get_autoconnect_retries, }, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_TIMESTAMP), + .get_fcn = _get_fcn_gobject, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_READ_ONLY), + .get_fcn = _get_fcn_gobject, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_PERMISSIONS), + .get_fcn = _get_fcn_nmc, + .get_data = { .get_nmc = nmc_property_connection_get_permissions, }, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_ZONE), + .get_fcn = _get_fcn_gobject, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_MASTER), + .get_fcn = _get_fcn_gobject, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_SLAVE_TYPE), + .get_fcn = _get_fcn_gobject, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES), + .get_fcn = _get_fcn_nmc, + .get_data = { .get_nmc = nmc_property_connection_get_autoconnect_slaves, }, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_SECONDARIES), + .get_fcn = _get_fcn_gobject, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT), + .get_fcn = _get_fcn_gobject, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_METERED), + .get_fcn = _get_fcn_nmc, + .get_data = { .get_nmc = nmc_property_connection_get_metered, }, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_LLDP), + .get_fcn = _get_fcn_nmc, + .get_data = { .get_nmc = nmc_property_connection_get_lldp, }, + }, +}; + +#define NMC_FIELDS_SETTING_CONNECTION_ALL "name"","\ + NM_SETTING_CONNECTION_ID","\ + NM_SETTING_CONNECTION_UUID","\ + NM_SETTING_CONNECTION_STABLE_ID","\ + NM_SETTING_CONNECTION_INTERFACE_NAME","\ + NM_SETTING_CONNECTION_TYPE","\ + NM_SETTING_CONNECTION_AUTOCONNECT","\ + NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY","\ + NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES","\ + NM_SETTING_CONNECTION_TIMESTAMP","\ + NM_SETTING_CONNECTION_READ_ONLY","\ + NM_SETTING_CONNECTION_PERMISSIONS","\ + NM_SETTING_CONNECTION_ZONE","\ + NM_SETTING_CONNECTION_MASTER","\ + NM_SETTING_CONNECTION_SLAVE_TYPE","\ + NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES","\ + NM_SETTING_CONNECTION_SECONDARIES","\ + NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT","\ + NM_SETTING_CONNECTION_METERED","\ + NM_SETTING_CONNECTION_LLDP + const NmcSettingInfo nmc_setting_infos[_NM_META_SETTING_TYPE_NUM] = { [NM_META_SETTING_TYPE_802_1X] = { .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_802_1X], @@ -9760,7 +9879,10 @@ const NmcSettingInfo nmc_setting_infos[_NM_META_SETTING_TYPE_NUM] = { }, [NM_META_SETTING_TYPE_CONNECTION] = { .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_CONNECTION], - .get_setting_details = setting_connection_details, + .get_setting_details = _get_setting_details, + .properties = properties_setting_connection, + .properties_num = G_N_ELEMENTS (properties_setting_connection), + .all_properties = NMC_FIELDS_SETTING_CONNECTION_ALL, }, [NM_META_SETTING_TYPE_DCB] = { .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_DCB], diff --git a/clients/cli/settings.h b/clients/cli/settings.h index 86b7691e09..3735a1f087 100644 --- a/clients/cli/settings.h +++ b/clients/cli/settings.h @@ -27,7 +27,32 @@ /*****************************************************************************/ +typedef enum { + NMC_PROPERTY_GET_PRETTY, + NMC_PROPERTY_GET_PARSABLE, +} NmcPropertyGetType; + typedef struct _NmcSettingInfo NmcSettingInfo; +typedef struct _NmcPropertyInfo NmcPropertyInfo; + +struct _NmcPropertyInfo { + 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; + + char *(*get_fcn) (const NmcSettingInfo *setting_info, + const NmcPropertyInfo *property_info, + NMSetting *setting, + NmcPropertyGetType get_type); + union { + const char *(*get_direct) (NMSetting *setting); + char *(*get_nmc) (NMSetting *setting, NmcPropertyGetType get_type); + } get_data; +}; struct _NmcSettingInfo { const NMMetaSettingInfo *general; @@ -36,6 +61,9 @@ struct _NmcSettingInfo { NmCli *nmc, const char *one_prop, gboolean secrets); + const NmcPropertyInfo *properties; + guint properties_num; + const char *all_properties; }; extern const NmcSettingInfo nmc_setting_infos[_NM_META_SETTING_TYPE_NUM]; @@ -81,7 +109,6 @@ gboolean nmc_property_set_gvalue (NMSetting *setting, const char *prop, GValue * gboolean setting_details (NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean secrets); -extern NmcOutputField nmc_fields_setting_connection[]; extern NmcOutputField nmc_fields_setting_wired[]; extern NmcOutputField nmc_fields_setting_8021X[]; extern NmcOutputField nmc_fields_setting_wireless[]; diff --git a/clients/cli/utils.c b/clients/cli/utils.c index fbd643ffc4..0bdeac87ee 100644 --- a/clients/cli/utils.c +++ b/clients/cli/utils.c @@ -29,6 +29,7 @@ #include "utils.h" #include "common.h" +#include "settings.h" gboolean matches (const char *cmd, const char *pattern) @@ -869,16 +870,27 @@ parse_output_fields (const char *fields_str, for (i = 0; fields_array[i].name; i++) { if (strcasecmp (left, fields_array[i].name) == 0) { - NmcOutputField *valid_names = fields_array[i].group; + const NmcOutputField *valid_names = fields_array[i].group_list; + const NmcSettingInfo *setting_info = fields_array[i].setting_info; + idx = i; - if (!right && !valid_names) { + if (!right && !valid_names && !setting_info) { found = TRUE; break; } - for (j = 0; valid_names && valid_names[j].name; j++) { - if (!right || strcasecmp (right, valid_names[j].name) == 0) { - found = TRUE; - break; + if (valid_names) { + for (j = 0; valid_names[j].name; j++) { + if (!right || strcasecmp (right, valid_names[j].name) == 0) { + found = TRUE; + break; + } + } + } else if (setting_info) { + for (j = 1; j < setting_info->properties_num; j++) { + if (!right || strcasecmp (right, setting_info->properties[j].property_name) == 0) { + found = TRUE; + break; + } } } if (found) @@ -946,11 +958,20 @@ nmc_get_allowed_fields (const NmcOutputField fields_array[], int group_idx) GString *allowed_fields = g_string_sized_new (256); int i; - if (group_idx != -1 && fields_array[group_idx].group) { - NmcOutputField *second_level = fields_array[group_idx].group; - for (i = 0; second_level[i].name; i++) + if (group_idx != -1 && fields_array[group_idx].group_list) { + const NmcOutputField *second_level = fields_array[group_idx].group_list; + + for (i = 0; second_level[i].name; i++) { g_string_append_printf (allowed_fields, "%s.%s,", fields_array[group_idx].name, second_level[i].name); + } + } else if (group_idx != -1 && fields_array[group_idx].setting_info) { + const NmcSettingInfo *second_level = fields_array[group_idx].setting_info; + + for (i = 1; i < second_level->properties_num; i++) { + g_string_append_printf (allowed_fields, "%s.%s,", + fields_array[group_idx].name, second_level->properties[i].property_name); + } } else { for (i = 0; fields_array[i].name; i++) g_string_append_printf (allowed_fields, "%s,", fields_array[i].name);