mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-04 16:50:17 +01:00
cli: split output data from NmCli to a separate field
This commit is contained in:
parent
d0ce5fc550
commit
2ea670ab96
9 changed files with 168 additions and 174 deletions
|
|
@ -102,10 +102,10 @@ print_ip4_config (NMIPConfig *cfg4,
|
|||
|
||||
tmpl = nmc_fields_ip4_config;
|
||||
tmpl_len = sizeof (nmc_fields_ip4_config);
|
||||
nmc->print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_IP4_CONFIG_ALL,
|
||||
nmc->out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_IP4_CONFIG_ALL,
|
||||
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);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
/* addresses */
|
||||
ptr_array = nm_ip_config_get_addresses (cfg4);
|
||||
|
|
@ -160,12 +160,11 @@ print_ip4_config (NMIPConfig *cfg4,
|
|||
set_val_arr (arr, 4, dns_arr);
|
||||
set_val_arr (arr, 5, domain_arr);
|
||||
set_val_arr (arr, 6, wins_arr);
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
|
||||
/* Remove any previous data */
|
||||
nmc_empty_output_fields (nmc);
|
||||
nmc_empty_output_fields (&nmc->out);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -190,10 +189,10 @@ print_ip6_config (NMIPConfig *cfg6,
|
|||
|
||||
tmpl = nmc_fields_ip6_config;
|
||||
tmpl_len = sizeof (nmc_fields_ip6_config);
|
||||
nmc->print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_IP6_CONFIG_ALL,
|
||||
nmc->out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_IP6_CONFIG_ALL,
|
||||
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);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
/* addresses */
|
||||
ptr_array = nm_ip_config_get_addresses (cfg6);
|
||||
|
|
@ -244,12 +243,11 @@ print_ip6_config (NMIPConfig *cfg6,
|
|||
set_val_arr (arr, 3, route_arr);
|
||||
set_val_arr (arr, 4, dns_arr);
|
||||
set_val_arr (arr, 5, domain_arr);
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
|
||||
/* Remove any previous data */
|
||||
nmc_empty_output_fields (nmc);
|
||||
nmc_empty_output_fields (&nmc->out);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -276,10 +274,10 @@ print_dhcp4_config (NMDhcpConfig *dhcp4,
|
|||
|
||||
tmpl = nmc_fields_dhcp4_config;
|
||||
tmpl_len = sizeof (nmc_fields_dhcp4_config);
|
||||
nmc->print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DHCP4_CONFIG_ALL,
|
||||
nmc->out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DHCP4_CONFIG_ALL,
|
||||
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);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
options_arr = g_new (char *, g_hash_table_size (table) + 1);
|
||||
g_hash_table_iter_init (&table_iter, table);
|
||||
|
|
@ -290,12 +288,11 @@ print_dhcp4_config (NMDhcpConfig *dhcp4,
|
|||
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX);
|
||||
set_val_strc (arr, 0, group_prefix);
|
||||
set_val_arr (arr, 1, options_arr);
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
|
||||
/* Remove any previous data */
|
||||
nmc_empty_output_fields (nmc);
|
||||
nmc_empty_output_fields (&nmc->out);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -324,10 +321,10 @@ print_dhcp6_config (NMDhcpConfig *dhcp6,
|
|||
|
||||
tmpl = nmc_fields_dhcp6_config;
|
||||
tmpl_len = sizeof (nmc_fields_dhcp6_config);
|
||||
nmc->print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DHCP6_CONFIG_ALL,
|
||||
nmc->out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DHCP6_CONFIG_ALL,
|
||||
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);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
options_arr = g_new (char *, g_hash_table_size (table) + 1);
|
||||
g_hash_table_iter_init (&table_iter, table);
|
||||
|
|
@ -338,12 +335,11 @@ print_dhcp6_config (NMDhcpConfig *dhcp6,
|
|||
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX);
|
||||
set_val_strc (arr, 0, group_prefix);
|
||||
set_val_arr (arr, 1, options_arr);
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
|
||||
/* Remove any previous data */
|
||||
nmc_empty_output_fields (nmc);
|
||||
nmc_empty_output_fields (&nmc->out);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -790,12 +790,12 @@ nmc_connection_profile_details (NMConnection *connection, NmCli *nmc, gboolean s
|
|||
g_assert (print_settings_array);
|
||||
|
||||
/* Main header */
|
||||
nmc->print_fields.header_name = (char *) construct_header_name (base_hdr, nm_connection_get_id (connection));
|
||||
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_SETTINGS_NAMES_ALL,
|
||||
nmc->out.print_fields.header_name = (char *) construct_header_name (base_hdr, nm_connection_get_id (connection));
|
||||
nmc->out.print_fields.indices = parse_output_fields (NMC_FIELDS_SETTINGS_NAMES_ALL,
|
||||
nmc_fields_settings_names, FALSE, NULL, NULL);
|
||||
|
||||
nmc_fields_settings_names[0].flags = NMC_OF_FLAG_MAIN_HEADER_ONLY;
|
||||
print_required_fields (&nmc->nmc_config, &nmc->print_fields, nmc_fields_settings_names);
|
||||
print_required_fields (&nmc->nmc_config, &nmc->out.print_fields, nmc_fields_settings_names);
|
||||
|
||||
/* Loop through the required settings and print them. */
|
||||
for (i = 0; i < print_settings_array->len; i++) {
|
||||
|
|
@ -808,8 +808,7 @@ nmc_connection_profile_details (NMConnection *connection, NmCli *nmc, gboolean s
|
|||
|
||||
was_output = FALSE;
|
||||
|
||||
/* Remove any previous data */
|
||||
nmc_empty_output_fields (nmc);
|
||||
nmc_empty_output_fields (&nmc->out);
|
||||
|
||||
setting = nm_connection_get_setting_by_name (connection, nmc_fields_settings_names[section_idx].name);
|
||||
if (setting) {
|
||||
|
|
@ -980,7 +979,7 @@ fill_output_connection (NMConnection *connection, NmCli *nmc, gboolean active_on
|
|||
set_val_strc (arr, 12, ac_path);
|
||||
set_val_strc (arr, 13, nm_setting_connection_get_slave_type (s_con));
|
||||
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -1017,7 +1016,7 @@ fill_output_connection_for_invisible (NMActiveConnection *ac, NmCli *nmc)
|
|||
|
||||
set_val_color_fmt_all (arr, NMC_TERM_FORMAT_DIM);
|
||||
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -1089,7 +1088,7 @@ fill_output_active_connection (NMActiveConnection *active,
|
|||
set_val_strc (arr, 12-idx_start, master ? nm_object_get_path (NM_OBJECT (master)) : NULL);
|
||||
set_val_strc (arr, 13-idx_start, s_con ? nm_setting_connection_get_slave_type (s_con) : NULL);
|
||||
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
g_string_free (dev_str, FALSE);
|
||||
}
|
||||
|
|
@ -1217,12 +1216,12 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc)
|
|||
g_assert (print_groups);
|
||||
|
||||
/* Main header */
|
||||
nmc->print_fields.header_name = (char *) construct_header_name (base_hdr, nm_active_connection_get_uuid (acon));
|
||||
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_CON_ACTIVE_DETAILS_ALL,
|
||||
nmc->out.print_fields.header_name = (char *) construct_header_name (base_hdr, nm_active_connection_get_uuid (acon));
|
||||
nmc->out.print_fields.indices = parse_output_fields (NMC_FIELDS_CON_ACTIVE_DETAILS_ALL,
|
||||
nmc_fields_con_active_details_groups, FALSE, NULL, NULL);
|
||||
|
||||
nmc_fields_con_active_details_groups[0].flags = NMC_OF_FLAG_MAIN_HEADER_ONLY;
|
||||
print_required_fields (&nmc->nmc_config, &nmc->print_fields, nmc_fields_con_active_details_groups);
|
||||
print_required_fields (&nmc->nmc_config, &nmc->out.print_fields, nmc_fields_con_active_details_groups);
|
||||
|
||||
/* Loop through the groups and print them. */
|
||||
for (i = 0; i < print_groups->len; i++) {
|
||||
|
|
@ -1234,23 +1233,22 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc)
|
|||
|
||||
was_output = FALSE;
|
||||
|
||||
/* Remove any previous data */
|
||||
nmc_empty_output_fields (nmc);
|
||||
nmc_empty_output_fields (&nmc->out);
|
||||
|
||||
/* GENERAL */
|
||||
if (strcasecmp (nmc_fields_con_active_details_groups[group_idx].name, nmc_fields_con_active_details_groups[0].name) == 0) {
|
||||
/* Add field names */
|
||||
tmpl = nmc_fields_con_active_details_general;
|
||||
tmpl_len = sizeof (nmc_fields_con_active_details_general);
|
||||
nmc->print_fields.indices = parse_output_fields (group_fld ? group_fld : NMC_FIELDS_CON_ACTIVE_DETAILS_GENERAL_ALL,
|
||||
nmc->out.print_fields.indices = parse_output_fields (group_fld ? group_fld : NMC_FIELDS_CON_ACTIVE_DETAILS_GENERAL_ALL,
|
||||
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);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
/* Fill in values */
|
||||
fill_output_active_connection (acon, nmc, TRUE, NMC_OF_FLAG_SECTION_PREFIX);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
|
||||
was_output = TRUE;
|
||||
}
|
||||
|
|
@ -1311,10 +1309,10 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc)
|
|||
|
||||
tmpl = nmc_fields_con_active_details_vpn;
|
||||
tmpl_len = sizeof (nmc_fields_con_active_details_vpn);
|
||||
nmc->print_fields.indices = parse_output_fields (group_fld ? group_fld : NMC_FIELDS_CON_ACTIVE_DETAILS_VPN_ALL,
|
||||
nmc->out.print_fields.indices = parse_output_fields (group_fld ? group_fld : NMC_FIELDS_CON_ACTIVE_DETAILS_VPN_ALL,
|
||||
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);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
s_vpn = nm_connection_get_setting_vpn (con);
|
||||
if (s_vpn) {
|
||||
|
|
@ -1347,9 +1345,9 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc)
|
|||
set_val_str (arr, 4, banner_str);
|
||||
set_val_str (arr, 5, vpn_state_str);
|
||||
set_val_arr (arr, 6, vpn_data_array);
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
was_output = TRUE;
|
||||
}
|
||||
}
|
||||
|
|
@ -1807,15 +1805,15 @@ do_connections_show (NmCli *nmc, int argc, char **argv)
|
|||
|
||||
tmpl = nmc_fields_con_show;
|
||||
tmpl_len = sizeof (nmc_fields_con_show);
|
||||
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &err);
|
||||
nmc->out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &err);
|
||||
if (err)
|
||||
goto finish;
|
||||
|
||||
/* Add headers */
|
||||
nmc->print_fields.header_name = active_only ? _("NetworkManager active profiles") :
|
||||
nmc->out.print_fields.header_name = active_only ? _("NetworkManager active profiles") :
|
||||
_("NetworkManager connection profiles");
|
||||
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES);
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
/* There might be active connections not present in connection list
|
||||
* (e.g. private connections of a different user). Show them as well. */
|
||||
|
|
@ -1831,7 +1829,7 @@ do_connections_show (NmCli *nmc, int argc, char **argv)
|
|||
fill_output_connection (sorted_cons->pdata[i], nmc, active_only);
|
||||
g_ptr_array_free (sorted_cons, TRUE);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
} else {
|
||||
gboolean new_line = FALSE;
|
||||
gboolean without_fields = (nmc->required_fields == NULL);
|
||||
|
|
@ -6019,8 +6017,7 @@ editor_show_connection (NMConnection *connection, NmCli *nmc)
|
|||
nmc->nmc_config_mutable.multiline_output = TRUE;
|
||||
nmc->nmc_config_mutable.escape_values = 0;
|
||||
|
||||
/* Remove any previous data */
|
||||
nmc_empty_output_fields (nmc);
|
||||
nmc_empty_output_fields (&nmc->out);
|
||||
|
||||
nmc_connection_profile_details (connection, nmc, nmc->editor_show_secrets);
|
||||
}
|
||||
|
|
@ -6035,8 +6032,7 @@ editor_show_setting (NMSetting *setting, NmCli *nmc)
|
|||
nmc->nmc_config_mutable.multiline_output = TRUE;
|
||||
nmc->nmc_config_mutable.escape_values = 0;
|
||||
|
||||
/* Remove any previous data */
|
||||
nmc_empty_output_fields (nmc);
|
||||
nmc_empty_output_fields (&nmc->out);
|
||||
|
||||
setting_details (setting, nmc, NULL, nmc->editor_show_secrets);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -881,7 +881,7 @@ fill_output_access_point (gpointer data, gpointer user_data)
|
|||
if (active)
|
||||
arr[15].color = NMC_TERM_COLOR_GREEN;
|
||||
|
||||
g_ptr_array_add (info->nmc->output_data, arr);
|
||||
g_ptr_array_add (info->nmc->out.output_data, arr);
|
||||
|
||||
g_string_free (security_str, FALSE);
|
||||
}
|
||||
|
|
@ -974,20 +974,20 @@ print_bond_bridge_info (NMDevice *device,
|
|||
|
||||
tmpl = nmc_fields_dev_show_master_prop;
|
||||
tmpl_len = sizeof (nmc_fields_dev_show_master_prop);
|
||||
nmc->print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DEV_SHOW_MASTER_PROP_ALL,
|
||||
nmc->out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DEV_SHOW_MASTER_PROP_ALL,
|
||||
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);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX);
|
||||
set_val_strc (arr, 0, group_prefix); /* i.e. BOND, TEAM, BRIDGE */
|
||||
set_val_str (arr, 1, slaves_str->str);
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
|
||||
g_string_free (slaves_str, FALSE);
|
||||
nmc_empty_output_fields (nmc);
|
||||
nmc_empty_output_fields (&nmc->out);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -1043,21 +1043,21 @@ print_team_info (NMDevice *device,
|
|||
|
||||
tmpl = nmc_fields_dev_show_team_prop;
|
||||
tmpl_len = sizeof (nmc_fields_dev_show_team_prop);
|
||||
nmc->print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DEV_SHOW_TEAM_PROP_ALL,
|
||||
nmc->out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DEV_SHOW_TEAM_PROP_ALL,
|
||||
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);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX);
|
||||
set_val_strc (arr, 0, group_prefix); /* TEAM */
|
||||
set_val_str (arr, 1, slaves_str->str);
|
||||
set_val_str (arr, 2, sanitize_team_config (nm_device_team_get_config (NM_DEVICE_TEAM (device))));
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
|
||||
g_string_free (slaves_str, FALSE);
|
||||
nmc_empty_output_fields (nmc);
|
||||
nmc_empty_output_fields (&nmc->out);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -1103,14 +1103,14 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||
}
|
||||
|
||||
/* Main header (pretty only) */
|
||||
nmc->print_fields.header_name = (char *) construct_header_name (base_hdr, nm_device_get_iface (device));
|
||||
nmc->out.print_fields.header_name = (char *) construct_header_name (base_hdr, nm_device_get_iface (device));
|
||||
|
||||
/* Lazy way to retrieve sorted array from 0 to the number of dev fields */
|
||||
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_GENERAL_ALL,
|
||||
nmc->out.print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_GENERAL_ALL,
|
||||
nmc_fields_dev_show_general, FALSE, NULL, NULL);
|
||||
|
||||
nmc_fields_dev_show_general[0].flags = NMC_OF_FLAG_MAIN_HEADER_ONLY;
|
||||
print_required_fields (&nmc->nmc_config, &nmc->print_fields, nmc_fields_dev_show_general);
|
||||
print_required_fields (&nmc->nmc_config, &nmc->out.print_fields, nmc_fields_dev_show_general);
|
||||
|
||||
/* Loop through the required sections and print them. */
|
||||
for (k = 0; k < sections_array->len; k++) {
|
||||
|
|
@ -1122,8 +1122,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||
|
||||
was_output = FALSE;
|
||||
|
||||
/* Remove any previous data */
|
||||
nmc_empty_output_fields (nmc);
|
||||
nmc_empty_output_fields (&nmc->out);
|
||||
|
||||
state = nm_device_get_state (device);
|
||||
reason = nm_device_get_state_reason (device);
|
||||
|
|
@ -1132,10 +1131,10 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[0].name)) {
|
||||
tmpl = nmc_fields_dev_show_general;
|
||||
tmpl_len = sizeof (nmc_fields_dev_show_general);
|
||||
nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_GENERAL_ALL,
|
||||
nmc->out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_GENERAL_ALL,
|
||||
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);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
state_str = g_strdup_printf ("%d (%s)", state, nmc_device_state_to_string (state));
|
||||
reason_str = g_strdup_printf ("%d (%s)", reason, nmc_device_reason_to_string (reason));
|
||||
|
|
@ -1169,9 +1168,9 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||
set_val_strc (arr, 22, acon ? nm_active_connection_get_uuid (acon) : NULL);
|
||||
set_val_strc (arr, 23, acon ? nm_object_get_path (NM_OBJECT (acon)) : NULL);
|
||||
set_val_strc (arr, 24, nmc_device_metered_to_string (nm_device_get_metered (device)));
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
was_output = TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -1179,10 +1178,10 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[1].name)) {
|
||||
tmpl = nmc_fields_dev_show_cap;
|
||||
tmpl_len = sizeof (nmc_fields_dev_show_cap);
|
||||
nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_CAP_ALL,
|
||||
nmc->out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_CAP_ALL,
|
||||
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);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
caps = nm_device_get_capabilities (device);
|
||||
speed = 0;
|
||||
|
|
@ -1201,9 +1200,9 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||
set_val_strc (arr, 1, (caps & NM_DEVICE_CAP_CARRIER_DETECT) ? _("yes") : _("no"));
|
||||
set_val_str (arr, 2, speed_str);
|
||||
set_val_strc (arr, 3, (caps & NM_DEVICE_CAP_IS_SOFTWARE) ? _("yes") : _("no"));
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
was_output = TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -1220,10 +1219,10 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||
|
||||
tmpl = nmc_fields_dev_show_wifi_prop;
|
||||
tmpl_len = sizeof (nmc_fields_dev_show_wifi_prop);
|
||||
nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_WIFI_PROP_ALL,
|
||||
nmc->out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_WIFI_PROP_ALL,
|
||||
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);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX);
|
||||
set_val_strc (arr, 0, nmc_fields_dev_show_sections[2].name); /* "WIFI-PROPERTIES" */
|
||||
|
|
@ -1239,9 +1238,9 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||
((wcaps & NM_WIFI_DEVICE_CAP_FREQ_2GHZ) ? _("yes") : _("no")));
|
||||
set_val_strc (arr, 9, !(wcaps & NM_WIFI_DEVICE_CAP_FREQ_VALID) ? _("unknown") :
|
||||
((wcaps & NM_WIFI_DEVICE_CAP_FREQ_5GHZ) ? _("yes") : _("no")));
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
was_output = TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -1254,10 +1253,10 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||
|
||||
tmpl = nmc_fields_dev_wifi_list;
|
||||
tmpl_len = sizeof (nmc_fields_dev_wifi_list);
|
||||
nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_WIFI_LIST_FOR_DEV_LIST,
|
||||
nmc->out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_WIFI_LIST_FOR_DEV_LIST,
|
||||
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);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
info = g_malloc0 (sizeof (APInfo));
|
||||
info->nmc = nmc;
|
||||
|
|
@ -1269,7 +1268,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||
g_ptr_array_foreach ((GPtrArray *) aps, fill_output_access_point, (gpointer) info);
|
||||
g_ptr_array_free (aps, FALSE);
|
||||
g_free (info);
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
was_output = TRUE;
|
||||
}
|
||||
} else if (NM_IS_DEVICE_ETHERNET (device)) {
|
||||
|
|
@ -1277,19 +1276,19 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[4].name)) {
|
||||
tmpl = nmc_fields_dev_show_wired_prop;
|
||||
tmpl_len = sizeof (nmc_fields_dev_show_wired_prop);
|
||||
nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_WIRED_PROP_ALL,
|
||||
nmc->out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_WIRED_PROP_ALL,
|
||||
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);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX);
|
||||
set_val_strc (arr, 0, nmc_fields_dev_show_sections[4].name); /* "WIRED-PROPERTIES" */
|
||||
set_val_strc (arr, 1, (nm_device_ethernet_get_carrier (NM_DEVICE_ETHERNET (device))) ?
|
||||
_("on") : _("off"));
|
||||
set_val_arrc (arr, 2, ((const char **) nm_device_ethernet_get_s390_subchannels (NM_DEVICE_ETHERNET (device))));
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
was_output = TRUE;
|
||||
}
|
||||
}
|
||||
|
|
@ -1342,18 +1341,18 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||
|
||||
tmpl = nmc_fields_dev_show_vlan_prop;
|
||||
tmpl_len = sizeof (nmc_fields_dev_show_vlan_prop);
|
||||
nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_VLAN_PROP_ALL,
|
||||
nmc->out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_VLAN_PROP_ALL,
|
||||
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);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX);
|
||||
set_val_strc (arr, 0, nmc_fields_dev_show_sections[14].name); /* "VLAN" */
|
||||
set_val_strc (arr, 1, parent ? nm_device_get_iface (parent) : NULL);
|
||||
set_val_str (arr, 2, vlan_id_str);
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
|
||||
was_output = TRUE;
|
||||
}
|
||||
|
|
@ -1363,17 +1362,17 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[15].name)) {
|
||||
tmpl = nmc_fields_dev_show_bluetooth;
|
||||
tmpl_len = sizeof (nmc_fields_dev_show_bluetooth);
|
||||
nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_BLUETOOTH_ALL,
|
||||
nmc->out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_BLUETOOTH_ALL,
|
||||
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);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX);
|
||||
set_val_strc (arr, 0, nmc_fields_dev_show_sections[15].name); /* "BLUETOOTH" */
|
||||
set_val_str (arr, 1, bluetooth_caps_to_string (nm_device_bt_get_capabilities (NM_DEVICE_BT (device))));
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
was_output = TRUE;
|
||||
}
|
||||
}
|
||||
|
|
@ -1387,10 +1386,10 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||
|
||||
tmpl = nmc_fields_dev_show_connections;
|
||||
tmpl_len = sizeof (nmc_fields_dev_show_connections);
|
||||
nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_CONNECTIONS_ALL,
|
||||
nmc->out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_CONNECTIONS_ALL,
|
||||
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);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
/* available-connections */
|
||||
avail_cons = nm_device_get_available_connections (device);
|
||||
|
|
@ -1420,9 +1419,9 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||
set_val_strc (arr, 0, nmc_fields_dev_show_sections[16].name); /* "CONNECTIONS" */
|
||||
set_val_str (arr, 1, ac_paths_str->str);
|
||||
set_val_arr (arr, 2, (ac_arr));
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
|
||||
g_string_free (ac_paths_str, FALSE);
|
||||
was_output = TRUE;
|
||||
|
|
@ -1480,7 +1479,7 @@ fill_output_device_status (NMDevice *device, NmCli *nmc)
|
|||
set_val_strc (arr, 5, ac ? nm_active_connection_get_uuid (ac) : NULL);
|
||||
set_val_strc (arr, 6, ac ? nm_object_get_path (NM_OBJECT (ac)) : NULL);
|
||||
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
}
|
||||
|
||||
static NMCResultCode
|
||||
|
|
@ -1513,7 +1512,7 @@ do_devices_status (NmCli *nmc, int argc, char **argv)
|
|||
|
||||
tmpl = nmc_fields_dev_status;
|
||||
tmpl_len = sizeof (nmc_fields_dev_status);
|
||||
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
|
||||
nmc->out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
|
||||
|
||||
if (error) {
|
||||
g_string_printf (nmc->return_text, _("Error: 'device status': %s"), error->message);
|
||||
|
|
@ -1522,15 +1521,15 @@ do_devices_status (NmCli *nmc, int argc, char **argv)
|
|||
}
|
||||
|
||||
/* Add headers */
|
||||
nmc->print_fields.header_name = _("Status of devices");
|
||||
nmc->out.print_fields.header_name = _("Status of devices");
|
||||
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES);
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
devices = nmc_get_devices_sorted (nmc->client);
|
||||
for (i = 0; devices[i]; i++)
|
||||
fill_output_device_status (devices[i], nmc);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
|
||||
g_free (devices);
|
||||
|
||||
|
|
@ -1572,7 +1571,7 @@ do_device_show (NmCli *nmc, int argc, char **argv)
|
|||
|
||||
/* Show details for all devices */
|
||||
for (i = 0; devices[i]; i++) {
|
||||
nmc_empty_output_fields (nmc);
|
||||
nmc_empty_output_fields (&nmc->out);
|
||||
if (!show_device_info (devices[i], nmc))
|
||||
break;
|
||||
if (devices[i + 1])
|
||||
|
|
@ -2483,7 +2482,7 @@ show_access_point_info (NMDevice *device, NmCli *nmc)
|
|||
|
||||
arr = nmc_dup_fields_array (nmc_fields_dev_wifi_list, sizeof (nmc_fields_dev_wifi_list),
|
||||
NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES);
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
info = g_malloc0 (sizeof (APInfo));
|
||||
info->nmc = nmc;
|
||||
|
|
@ -2495,8 +2494,8 @@ show_access_point_info (NMDevice *device, NmCli *nmc)
|
|||
g_ptr_array_foreach ((GPtrArray *) aps, fill_output_access_point, (gpointer) info);
|
||||
g_ptr_array_free (aps, FALSE);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
nmc_empty_output_fields (nmc);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
nmc_empty_output_fields (&nmc->out);
|
||||
g_free (info);
|
||||
}
|
||||
|
||||
|
|
@ -2673,7 +2672,7 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv)
|
|||
|
||||
tmpl = nmc_fields_dev_wifi_list;
|
||||
tmpl_len = sizeof (nmc_fields_dev_wifi_list);
|
||||
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
|
||||
nmc->out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
|
||||
|
||||
if (error) {
|
||||
g_string_printf (nmc->return_text, _("Error: 'device wifi': %s"), error->message);
|
||||
|
|
@ -2691,7 +2690,7 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv)
|
|||
return NMC_RESULT_ERROR_NOT_FOUND;
|
||||
}
|
||||
/* Main header name */
|
||||
nmc->print_fields.header_name = (char *) construct_header_name (base_hdr, ifname);
|
||||
nmc->out.print_fields.header_name = (char *) construct_header_name (base_hdr, ifname);
|
||||
|
||||
if (NM_IS_DEVICE_WIFI (device)) {
|
||||
if (bssid_user) {
|
||||
|
|
@ -2714,7 +2713,7 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv)
|
|||
}
|
||||
/* Add headers (field names) */
|
||||
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES);
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
info = g_malloc0 (sizeof (APInfo));
|
||||
info->nmc = nmc;
|
||||
|
|
@ -2725,7 +2724,7 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv)
|
|||
|
||||
fill_output_access_point (ap, info);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
g_free (info);
|
||||
} else {
|
||||
show_access_point_info (device, nmc);
|
||||
|
|
@ -2756,11 +2755,11 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv)
|
|||
continue;
|
||||
|
||||
/* Main header name */
|
||||
nmc->print_fields.header_name = (char *) construct_header_name (base_hdr, nm_device_get_iface (dev));
|
||||
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, NULL);
|
||||
nmc->out.print_fields.header_name = (char *) construct_header_name (base_hdr, nm_device_get_iface (dev));
|
||||
nmc->out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, NULL);
|
||||
|
||||
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES);
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (dev));
|
||||
for (j = 0; j < aps->len; j++) {
|
||||
|
|
@ -2785,8 +2784,8 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv)
|
|||
}
|
||||
if (empty_line)
|
||||
g_print ("\n"); /* Empty line between devices' APs */
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
nmc_empty_output_fields (nmc);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
nmc_empty_output_fields (&nmc->out);
|
||||
empty_line = TRUE;
|
||||
}
|
||||
if (!ap) {
|
||||
|
|
@ -2799,9 +2798,9 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv)
|
|||
NMDevice *dev = devices[i];
|
||||
|
||||
/* Main header name */
|
||||
nmc->print_fields.header_name = (char *) construct_header_name (base_hdr,
|
||||
nmc->out.print_fields.header_name = (char *) construct_header_name (base_hdr,
|
||||
nm_device_get_iface (dev));
|
||||
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, NULL);
|
||||
nmc->out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, NULL);
|
||||
|
||||
if (NM_IS_DEVICE_WIFI (dev)) {
|
||||
if (empty_line)
|
||||
|
|
@ -3673,11 +3672,11 @@ show_device_lldp_list (NMDevice *device, NmCli *nmc, char *fields_str, int *coun
|
|||
tmpl_len = sizeof (nmc_fields_dev_lldp_list);
|
||||
|
||||
/* Main header name */
|
||||
nmc->print_fields.header_name = (char *) construct_header_name (_("Device LLDP neighbors"),
|
||||
nmc->out.print_fields.header_name = (char *) construct_header_name (_("Device LLDP neighbors"),
|
||||
nm_device_get_iface (device));
|
||||
nmc->print_fields.indices = parse_output_fields (fields_str, nmc_fields_dev_lldp_list, FALSE, NULL, NULL);
|
||||
nmc->out.print_fields.indices = parse_output_fields (fields_str, nmc_fields_dev_lldp_list, FALSE, NULL, NULL);
|
||||
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES);
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
for (i = 0; i < neighbors->len; i++) {
|
||||
NMLldpNeighbor *neighbor = neighbors->pdata[i];
|
||||
|
|
@ -3730,11 +3729,11 @@ show_device_lldp_list (NMDevice *device, NmCli *nmc, char *fields_str, int *coun
|
|||
if (nm_lldp_neighbor_get_attr_uint_value (neighbor, NM_LLDP_ATTR_PORT_ID_TYPE, &value))
|
||||
set_val_strc (arr, 15, g_strdup_printf ("%u", value));
|
||||
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
}
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
nmc_empty_output_fields (nmc);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
nmc_empty_output_fields (&nmc->out);
|
||||
|
||||
return neighbors->len;
|
||||
}
|
||||
|
|
@ -3779,7 +3778,7 @@ do_device_lldp_list (NmCli *nmc, int argc, char **argv)
|
|||
else
|
||||
fields_str = nmc->required_fields;
|
||||
|
||||
nmc->print_fields.indices = parse_output_fields (fields_str, nmc_fields_dev_lldp_list, FALSE, NULL, &error);
|
||||
nmc->out.print_fields.indices = parse_output_fields (fields_str, nmc_fields_dev_lldp_list, FALSE, NULL, &error);
|
||||
|
||||
if (error) {
|
||||
g_string_printf (nmc->return_text, _("Error: 'device lldp list': %s"), error->message);
|
||||
|
|
@ -3790,14 +3789,14 @@ do_device_lldp_list (NmCli *nmc, int argc, char **argv)
|
|||
return nmc->return_value;
|
||||
|
||||
if (device) {
|
||||
nmc_empty_output_fields (nmc);
|
||||
nmc_empty_output_fields (&nmc->out);
|
||||
show_device_lldp_list (device, nmc, fields_str, &counter);
|
||||
} else {
|
||||
NMDevice **devices = nmc_get_devices_sorted (nmc->client);
|
||||
int i;
|
||||
|
||||
for (i = 0; devices[i]; i++) {
|
||||
nmc_empty_output_fields (nmc);
|
||||
nmc_empty_output_fields (&nmc->out);
|
||||
show_device_lldp_list (devices[i], nmc, fields_str, &counter);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -335,7 +335,7 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl
|
|||
|
||||
tmpl = nmc_fields_nm_status;
|
||||
tmpl_len = sizeof (nmc_fields_nm_status);
|
||||
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
|
||||
nmc->out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
|
||||
|
||||
if (error) {
|
||||
g_string_printf (nmc->return_text, _("Error: only these fields are allowed: %s"), fields_all);
|
||||
|
|
@ -353,9 +353,9 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl
|
|||
wwan_hw_enabled = nm_client_wwan_hardware_get_enabled (nmc->client);
|
||||
wwan_enabled = nm_client_wwan_get_enabled (nmc->client);
|
||||
|
||||
nmc->print_fields.header_name = pretty_header_name ? (char *) pretty_header_name : _("NetworkManager status");
|
||||
nmc->out.print_fields.header_name = pretty_header_name ? (char *) pretty_header_name : _("NetworkManager status");
|
||||
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES);
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
arr = nmc_dup_fields_array (tmpl, tmpl_len, 0);
|
||||
set_val_strc (arr, 0, _("running"));
|
||||
|
|
@ -379,9 +379,9 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl
|
|||
arr[8].color = wwan_hw_enabled ? NMC_TERM_COLOR_GREEN : NMC_TERM_COLOR_RED;
|
||||
arr[9].color = wwan_enabled ? NMC_TERM_COLOR_GREEN : NMC_TERM_COLOR_RED;
|
||||
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -482,7 +482,7 @@ print_permissions (void *user_data)
|
|||
|
||||
tmpl = nmc_fields_nm_permissions;
|
||||
tmpl_len = sizeof (nmc_fields_nm_permissions);
|
||||
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
|
||||
nmc->out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
|
||||
|
||||
if (error) {
|
||||
g_string_printf (nmc->return_text, _("Error: 'general permissions': %s"), error->message);
|
||||
|
|
@ -491,9 +491,9 @@ print_permissions (void *user_data)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
nmc->print_fields.header_name = _("NetworkManager permissions");
|
||||
nmc->out.print_fields.header_name = _("NetworkManager permissions");
|
||||
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES);
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
|
||||
for (perm = NM_CLIENT_PERMISSION_NONE + 1; perm <= NM_CLIENT_PERMISSION_LAST; perm++) {
|
||||
|
|
@ -502,9 +502,9 @@ print_permissions (void *user_data)
|
|||
arr = nmc_dup_fields_array (tmpl, tmpl_len, 0);
|
||||
set_val_strc (arr, 0, permission_to_string (perm));
|
||||
set_val_strc (arr, 1, permission_result_to_string (perm_result));
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
}
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
|
||||
quit ();
|
||||
return G_SOURCE_REMOVE;
|
||||
|
|
@ -591,7 +591,7 @@ show_general_logging (NmCli *nmc)
|
|||
|
||||
tmpl = nmc_fields_nm_logging;
|
||||
tmpl_len = sizeof (nmc_fields_nm_logging);
|
||||
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
|
||||
nmc->out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
|
||||
|
||||
if (error) {
|
||||
g_string_printf (nmc->return_text, _("Error: 'general logging': %s"), error->message);
|
||||
|
|
@ -608,16 +608,16 @@ show_general_logging (NmCli *nmc)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
nmc->print_fields.header_name = _("NetworkManager logging");
|
||||
nmc->out.print_fields.header_name = _("NetworkManager logging");
|
||||
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES);
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
arr = nmc_dup_fields_array (tmpl, tmpl_len, 0);
|
||||
set_val_str (arr, 0, level);
|
||||
set_val_str (arr, 1, domains);
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -540,8 +540,8 @@ nmc_init (NmCli *nmc)
|
|||
nmc->mode_specified = FALSE;
|
||||
nmc->nmc_config_mutable.escape_values = TRUE;
|
||||
nmc->required_fields = NULL;
|
||||
nmc->output_data = g_ptr_array_new_full (20, g_free);
|
||||
memset (&nmc->print_fields, '\0', sizeof (NmcPrintFields));
|
||||
nmc->out.output_data = g_ptr_array_new_full (20, g_free);
|
||||
memset (&nmc->out.print_fields, '\0', sizeof (NmcPrintFields));
|
||||
nmc->ask = FALSE;
|
||||
nmc->complete = FALSE;
|
||||
nmc->show_secrets = FALSE;
|
||||
|
|
@ -569,8 +569,8 @@ nmc_cleanup (NmCli *nmc)
|
|||
g_hash_table_destroy (nmc->pwds_hash);
|
||||
|
||||
g_free (nmc->required_fields);
|
||||
nmc_empty_output_fields (nmc);
|
||||
g_ptr_array_unref (nmc->output_data);
|
||||
nmc_empty_output_fields (&nmc->out);
|
||||
g_ptr_array_unref (nmc->out.output_data);
|
||||
|
||||
nmc_polkit_agent_fini (nmc);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,6 +146,11 @@ typedef struct _NmcConfig {
|
|||
gboolean in_editor; /* Whether running the editor - nmcli con edit' */
|
||||
} NmcConfig;
|
||||
|
||||
typedef struct _NmcOutputData {
|
||||
GPtrArray *output_data; /* GPtrArray of arrays of NmcOutputField structs - accumulates data for output */
|
||||
NmcPrintFields print_fields; /* Structure with field indices to print */
|
||||
} NmcOutputData;
|
||||
|
||||
/* NmCli - main structure */
|
||||
typedef struct _NmCli {
|
||||
NMClient *client; /* Pointer to NMClient of libnm */
|
||||
|
|
@ -167,8 +172,7 @@ typedef struct _NmCli {
|
|||
NmcConfig nmc_config_mutable;
|
||||
};
|
||||
char *required_fields; /* Required fields in output: '--fields' option */
|
||||
GPtrArray *output_data; /* GPtrArray of arrays of NmcOutputField structs - accumulates data for output */
|
||||
NmcPrintFields print_fields; /* Structure with field indices to print */
|
||||
NmcOutputData out;
|
||||
gboolean ask; /* Ask for missing parameters: option '--ask' */
|
||||
gboolean complete; /* Autocomplete the command line */
|
||||
gboolean show_secrets; /* Whether to display secrets (both input and output): option '--show-secrets' */
|
||||
|
|
|
|||
|
|
@ -897,10 +897,10 @@ setting_details (NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean
|
|||
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 ?: (s_all = _all_properties (setting_info)),
|
||||
nmc->out.print_fields.indices = parse_output_fields (one_prop ?: (s_all = _all_properties (setting_info)),
|
||||
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);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX);
|
||||
for (i = 0; i < setting_info->properties_num; i++) {
|
||||
|
|
@ -916,9 +916,9 @@ setting_details (NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean
|
|||
set_val_str (arr, i, g_strdup (_(NM_META_TEXT_HIDDEN)));
|
||||
}
|
||||
|
||||
g_ptr_array_add (nmc->output_data, arr);
|
||||
g_ptr_array_add (nmc->out.output_data, arr);
|
||||
|
||||
print_data (&nmc->nmc_config, &nmc->print_fields, nmc->output_data);
|
||||
print_data (&nmc->nmc_config, &nmc->out.print_fields, nmc->out.output_data);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -782,23 +782,23 @@ nmc_dup_fields_array (NmcOutputField fields[], size_t size, guint32 flags)
|
|||
}
|
||||
|
||||
void
|
||||
nmc_empty_output_fields (NmCli *nmc)
|
||||
nmc_empty_output_fields (NmcOutputData *output_data)
|
||||
{
|
||||
guint i;
|
||||
|
||||
/* Free values in field structure */
|
||||
for (i = 0; i < nmc->output_data->len; i++) {
|
||||
NmcOutputField *fld_arr = g_ptr_array_index (nmc->output_data, i);
|
||||
for (i = 0; i < output_data->output_data->len; i++) {
|
||||
NmcOutputField *fld_arr = g_ptr_array_index (output_data->output_data, i);
|
||||
nmc_free_output_field_values (fld_arr);
|
||||
}
|
||||
|
||||
/* Empty output_data array */
|
||||
if (nmc->output_data->len > 0)
|
||||
g_ptr_array_remove_range (nmc->output_data, 0, nmc->output_data->len);
|
||||
if (output_data->output_data->len > 0)
|
||||
g_ptr_array_remove_range (output_data->output_data, 0, output_data->output_data->len);
|
||||
|
||||
if (nmc->print_fields.indices) {
|
||||
g_array_free (nmc->print_fields.indices, TRUE);
|
||||
nmc->print_fields.indices = NULL;
|
||||
if (output_data->print_fields.indices) {
|
||||
g_array_free (output_data->print_fields.indices, TRUE);
|
||||
output_data->print_fields.indices = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -865,7 +865,7 @@ get_value_to_print (NmcColorOption color_option,
|
|||
* of 'field_values' array.
|
||||
*/
|
||||
void
|
||||
print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_fields, const NmcOutputField field_values[])
|
||||
print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_fields, const NmcOutputField *field_values)
|
||||
{
|
||||
GString *str;
|
||||
int width1, width2;
|
||||
|
|
@ -874,7 +874,6 @@ print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_
|
|||
char *indent_str;
|
||||
const char *not_set_str = "--";
|
||||
int i;
|
||||
const NmcPrintFields fields = *print_fields;
|
||||
gboolean multiline = nmc_config->multiline_output;
|
||||
gboolean terse = (nmc_config->print_output == NMC_PRINT_TERSE);
|
||||
gboolean pretty = (nmc_config->print_output == NMC_PRINT_PRETTY);
|
||||
|
|
@ -891,7 +890,7 @@ print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_
|
|||
|
||||
/* --- Main header --- */
|
||||
if (main_header && pretty) {
|
||||
int header_width = nmc_string_screen_width (fields.header_name, NULL) + 4;
|
||||
int header_width = nmc_string_screen_width (print_fields->header_name, NULL) + 4;
|
||||
|
||||
if (multiline) {
|
||||
table_width = header_width < ML_HEADER_WIDTH ? ML_HEADER_WIDTH : header_width;
|
||||
|
|
@ -901,10 +900,10 @@ print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_
|
|||
line = g_strnfill (table_width, '=');
|
||||
}
|
||||
|
||||
width1 = strlen (fields.header_name);
|
||||
width2 = nmc_string_screen_width (fields.header_name, NULL);
|
||||
width1 = strlen (print_fields->header_name);
|
||||
width2 = nmc_string_screen_width (print_fields->header_name, NULL);
|
||||
g_print ("%s\n", line);
|
||||
g_print ("%*s\n", (table_width + width2)/2 + width1 - width2, fields.header_name);
|
||||
g_print ("%*s\n", (table_width + width2)/2 + width1 - width2, print_fields->header_name);
|
||||
g_print ("%s\n", line);
|
||||
g_free (line);
|
||||
}
|
||||
|
|
@ -921,9 +920,9 @@ print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_
|
|||
|
||||
|
||||
if (multiline) {
|
||||
for (i = 0; i < fields.indices->len; i++) {
|
||||
for (i = 0; i < print_fields->indices->len; i++) {
|
||||
char *tmp;
|
||||
int idx = g_array_index (fields.indices, int, i);
|
||||
int idx = g_array_index (print_fields->indices, int, i);
|
||||
gboolean is_array = field_values[idx].value_is_array;
|
||||
|
||||
/* section prefix can't be an array */
|
||||
|
|
@ -985,8 +984,8 @@ print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_
|
|||
|
||||
str = g_string_new (NULL);
|
||||
|
||||
for (i = 0; i < fields.indices->len; i++) {
|
||||
int idx = g_array_index (fields.indices, int, i);
|
||||
for (i = 0; i < print_fields->indices->len; i++) {
|
||||
int idx = g_array_index (print_fields->indices, int, i);
|
||||
gs_free char *val_to_free = NULL;
|
||||
const char *value = get_value_to_print (nmc_config->use_colors, (NmcOutputField *) field_values+idx, field_names,
|
||||
not_set_str, &val_to_free);
|
||||
|
|
@ -1016,8 +1015,8 @@ print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_
|
|||
/* Print actual values */
|
||||
if (str->len > 0) {
|
||||
g_string_truncate (str, str->len-1); /* Chop off last column separator */
|
||||
if (fields.indent > 0) {
|
||||
indent_str = g_strnfill (fields.indent, ' ');
|
||||
if (print_fields->indent > 0) {
|
||||
indent_str = g_strnfill (print_fields->indent, ' ');
|
||||
g_string_prepend (str, indent_str);
|
||||
g_free (indent_str);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ GArray *parse_output_fields (const char *fields_str,
|
|||
GError **error);
|
||||
char *nmc_get_allowed_fields (const NmcOutputField fields_array[], int group_idx);
|
||||
NmcOutputField *nmc_dup_fields_array (NmcOutputField fields[], size_t size, guint32 flags);
|
||||
void nmc_empty_output_fields (NmCli *nmc);
|
||||
void nmc_empty_output_fields (NmcOutputData *output_data);
|
||||
void print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_fields, const NmcOutputField field_values[]);
|
||||
void print_data (const NmcConfig *nmc_config, const NmcPrintFields *print_fields, GPtrArray *output_data);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue