Commit 29bcfc25 authored by Thomas Haller's avatar Thomas Haller

cli: don't track output data in global NmCli structure

We should not violate the global data to track the output data
while it is constructed and printed.

Most of the time, we actually clear the output data anyway --
either before constructing it, or after printing it.
In some cases we didn't, but I think that is a bug. It's really
hard to keep track of this.

The output data should belong to a certain scope and get destroyed
afterwards. Passing it around is very confusing. Don't do that.
parent 85acdd70
...@@ -83,7 +83,7 @@ NmcOutputField nmc_fields_dhcp6_config[] = { ...@@ -83,7 +83,7 @@ NmcOutputField nmc_fields_dhcp6_config[] = {
gboolean gboolean
print_ip4_config (NMIPConfig *cfg4, print_ip4_config (NMIPConfig *cfg4,
NmCli *nmc, const NmcConfig *nmc_config,
const char *group_prefix, const char *group_prefix,
const char *one_field) const char *one_field)
{ {
...@@ -96,16 +96,17 @@ print_ip4_config (NMIPConfig *cfg4, ...@@ -96,16 +96,17 @@ print_ip4_config (NMIPConfig *cfg4,
int i = 0; int i = 0;
NmcOutputField *tmpl, *arr; NmcOutputField *tmpl, *arr;
size_t tmpl_len; size_t tmpl_len;
NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
if (cfg4 == NULL) if (cfg4 == NULL)
return FALSE; return FALSE;
tmpl = nmc_fields_ip4_config; tmpl = nmc_fields_ip4_config;
tmpl_len = sizeof (nmc_fields_ip4_config); tmpl_len = sizeof (nmc_fields_ip4_config);
nmc->out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_IP4_CONFIG_ALL, out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_IP4_CONFIG_ALL,
tmpl, FALSE, NULL, NULL); tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->out.output_data, arr); g_ptr_array_add (out.output_data, arr);
/* addresses */ /* addresses */
ptr_array = nm_ip_config_get_addresses (cfg4); ptr_array = nm_ip_config_get_addresses (cfg4);
...@@ -160,19 +161,17 @@ print_ip4_config (NMIPConfig *cfg4, ...@@ -160,19 +161,17 @@ print_ip4_config (NMIPConfig *cfg4,
set_val_arr (arr, 4, dns_arr); set_val_arr (arr, 4, dns_arr);
set_val_arr (arr, 5, domain_arr); set_val_arr (arr, 5, domain_arr);
set_val_arr (arr, 6, wins_arr); set_val_arr (arr, 6, wins_arr);
g_ptr_array_add (nmc->out.output_data, arr); g_ptr_array_add (out.output_data, arr);
print_data_prepare_width (nmc->out.output_data); print_data_prepare_width (out.output_data);
print_data (&nmc->nmc_config, &nmc->out); print_data (nmc_config, &out);
nmc_empty_output_fields (&nmc->out);
return TRUE; return TRUE;
} }
gboolean gboolean
print_ip6_config (NMIPConfig *cfg6, print_ip6_config (NMIPConfig *cfg6,
NmCli *nmc, const NmcConfig *nmc_config,
const char *group_prefix, const char *group_prefix,
const char *one_field) const char *one_field)
{ {
...@@ -184,16 +183,17 @@ print_ip6_config (NMIPConfig *cfg6, ...@@ -184,16 +183,17 @@ print_ip6_config (NMIPConfig *cfg6,
int i = 0; int i = 0;
NmcOutputField *tmpl, *arr; NmcOutputField *tmpl, *arr;
size_t tmpl_len; size_t tmpl_len;
NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
if (cfg6 == NULL) if (cfg6 == NULL)
return FALSE; return FALSE;
tmpl = nmc_fields_ip6_config; tmpl = nmc_fields_ip6_config;
tmpl_len = sizeof (nmc_fields_ip6_config); tmpl_len = sizeof (nmc_fields_ip6_config);
nmc->out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_IP6_CONFIG_ALL, out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_IP6_CONFIG_ALL,
tmpl, FALSE, NULL, NULL); tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->out.output_data, arr); g_ptr_array_add (out.output_data, arr);
/* addresses */ /* addresses */
ptr_array = nm_ip_config_get_addresses (cfg6); ptr_array = nm_ip_config_get_addresses (cfg6);
...@@ -244,19 +244,17 @@ print_ip6_config (NMIPConfig *cfg6, ...@@ -244,19 +244,17 @@ print_ip6_config (NMIPConfig *cfg6,
set_val_arr (arr, 3, route_arr); set_val_arr (arr, 3, route_arr);
set_val_arr (arr, 4, dns_arr); set_val_arr (arr, 4, dns_arr);
set_val_arr (arr, 5, domain_arr); set_val_arr (arr, 5, domain_arr);
g_ptr_array_add (nmc->out.output_data, arr); g_ptr_array_add (out.output_data, arr);
print_data_prepare_width (nmc->out.output_data);
print_data (&nmc->nmc_config, &nmc->out);
nmc_empty_output_fields (&nmc->out); print_data_prepare_width (out.output_data);
print_data (nmc_config, &out);
return TRUE; return TRUE;
} }
gboolean gboolean
print_dhcp4_config (NMDhcpConfig *dhcp4, print_dhcp4_config (NMDhcpConfig *dhcp4,
NmCli *nmc, const NmcConfig *nmc_config,
const char *group_prefix, const char *group_prefix,
const char *one_field) const char *one_field)
{ {
...@@ -273,13 +271,14 @@ print_dhcp4_config (NMDhcpConfig *dhcp4, ...@@ -273,13 +271,14 @@ print_dhcp4_config (NMDhcpConfig *dhcp4,
gpointer key, value; gpointer key, value;
char **options_arr = NULL; char **options_arr = NULL;
int i = 0; int i = 0;
NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
tmpl = nmc_fields_dhcp4_config; tmpl = nmc_fields_dhcp4_config;
tmpl_len = sizeof (nmc_fields_dhcp4_config); tmpl_len = sizeof (nmc_fields_dhcp4_config);
nmc->out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DHCP4_CONFIG_ALL, out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DHCP4_CONFIG_ALL,
tmpl, FALSE, NULL, NULL); tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->out.output_data, arr); g_ptr_array_add (out.output_data, arr);
options_arr = g_new (char *, g_hash_table_size (table) + 1); options_arr = g_new (char *, g_hash_table_size (table) + 1);
g_hash_table_iter_init (&table_iter, table); g_hash_table_iter_init (&table_iter, table);
...@@ -290,12 +289,10 @@ print_dhcp4_config (NMDhcpConfig *dhcp4, ...@@ -290,12 +289,10 @@ print_dhcp4_config (NMDhcpConfig *dhcp4,
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX);
set_val_strc (arr, 0, group_prefix); set_val_strc (arr, 0, group_prefix);
set_val_arr (arr, 1, options_arr); set_val_arr (arr, 1, options_arr);
g_ptr_array_add (nmc->out.output_data, arr); g_ptr_array_add (out.output_data, arr);
print_data_prepare_width (nmc->out.output_data); print_data_prepare_width (out.output_data);
print_data (&nmc->nmc_config, &nmc->out); print_data (nmc_config, &out);
nmc_empty_output_fields (&nmc->out);
return TRUE; return TRUE;
} }
...@@ -304,7 +301,7 @@ print_dhcp4_config (NMDhcpConfig *dhcp4, ...@@ -304,7 +301,7 @@ print_dhcp4_config (NMDhcpConfig *dhcp4,
gboolean gboolean
print_dhcp6_config (NMDhcpConfig *dhcp6, print_dhcp6_config (NMDhcpConfig *dhcp6,
NmCli *nmc, const NmcConfig *nmc_config,
const char *group_prefix, const char *group_prefix,
const char *one_field) const char *one_field)
{ {
...@@ -321,13 +318,14 @@ print_dhcp6_config (NMDhcpConfig *dhcp6, ...@@ -321,13 +318,14 @@ print_dhcp6_config (NMDhcpConfig *dhcp6,
gpointer key, value; gpointer key, value;
char **options_arr = NULL; char **options_arr = NULL;
int i = 0; int i = 0;
NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
tmpl = nmc_fields_dhcp6_config; tmpl = nmc_fields_dhcp6_config;
tmpl_len = sizeof (nmc_fields_dhcp6_config); tmpl_len = sizeof (nmc_fields_dhcp6_config);
nmc->out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DHCP6_CONFIG_ALL, out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DHCP6_CONFIG_ALL,
tmpl, FALSE, NULL, NULL); tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->out.output_data, arr); g_ptr_array_add (out.output_data, arr);
options_arr = g_new (char *, g_hash_table_size (table) + 1); options_arr = g_new (char *, g_hash_table_size (table) + 1);
g_hash_table_iter_init (&table_iter, table); g_hash_table_iter_init (&table_iter, table);
...@@ -338,12 +336,10 @@ print_dhcp6_config (NMDhcpConfig *dhcp6, ...@@ -338,12 +336,10 @@ print_dhcp6_config (NMDhcpConfig *dhcp6,
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX);
set_val_strc (arr, 0, group_prefix); set_val_strc (arr, 0, group_prefix);
set_val_arr (arr, 1, options_arr); set_val_arr (arr, 1, options_arr);
g_ptr_array_add (nmc->out.output_data, arr); g_ptr_array_add (out.output_data, arr);
print_data_prepare_width (nmc->out.output_data);
print_data (&nmc->nmc_config, &nmc->out);
nmc_empty_output_fields (&nmc->out); print_data_prepare_width (out.output_data);
print_data (nmc_config, &out);
return TRUE; return TRUE;
} }
......
...@@ -25,10 +25,10 @@ ...@@ -25,10 +25,10 @@
#include "nmcli.h" #include "nmcli.h"
#include "nm-secret-agent-simple.h" #include "nm-secret-agent-simple.h"
gboolean print_ip4_config (NMIPConfig *cfg4, NmCli *nmc, const char *group_prefix, const char *one_field); gboolean print_ip4_config (NMIPConfig *cfg4, const NmcConfig *nmc_config, const char *group_prefix, const char *one_field);
gboolean print_ip6_config (NMIPConfig *cfg6, NmCli *nmc, const char *group_prefix, const char *one_field); gboolean print_ip6_config (NMIPConfig *cfg6, const NmcConfig *nmc_config, const char *group_prefix, const char *one_field);
gboolean print_dhcp4_config (NMDhcpConfig *dhcp4, NmCli *nmc, const char *group_prefix, const char *one_field); gboolean print_dhcp4_config (NMDhcpConfig *dhcp4, const NmcConfig *nmc_config, const char *group_prefix, const char *one_field);
gboolean print_dhcp6_config (NMDhcpConfig *dhcp6, NmCli *nmc, const char *group_prefix, const char *one_field); gboolean print_dhcp6_config (NMDhcpConfig *dhcp6, const NmcConfig *nmc_config, const char *group_prefix, const char *one_field);
const char * nmc_device_state_to_string (NMDeviceState state); const char * nmc_device_state_to_string (NMDeviceState state);
const char * nmc_device_reason_to_string (NMDeviceStateReason reason); const char * nmc_device_reason_to_string (NMDeviceStateReason reason);
......
This diff is collapsed.
This diff is collapsed.
...@@ -325,6 +325,7 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl ...@@ -325,6 +325,7 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl
const char *fields_common = print_flds ? print_flds : NMC_FIELDS_NM_STATUS_COMMON; const char *fields_common = print_flds ? print_flds : NMC_FIELDS_NM_STATUS_COMMON;
NmcOutputField *tmpl, *arr; NmcOutputField *tmpl, *arr;
size_t tmpl_len; size_t tmpl_len;
NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0) if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0)
fields_str = fields_common; fields_str = fields_common;
...@@ -335,7 +336,7 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl ...@@ -335,7 +336,7 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl
tmpl = nmc_fields_nm_status; tmpl = nmc_fields_nm_status;
tmpl_len = sizeof (nmc_fields_nm_status); tmpl_len = sizeof (nmc_fields_nm_status);
nmc->out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
if (error) { if (error) {
g_string_printf (nmc->return_text, _("Error: only these fields are allowed: %s"), fields_all); g_string_printf (nmc->return_text, _("Error: only these fields are allowed: %s"), fields_all);
...@@ -353,9 +354,9 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl ...@@ -353,9 +354,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_hw_enabled = nm_client_wwan_hardware_get_enabled (nmc->client);
wwan_enabled = nm_client_wwan_get_enabled (nmc->client); wwan_enabled = nm_client_wwan_get_enabled (nmc->client);
nmc->out.print_fields.header_name = pretty_header_name ? (char *) pretty_header_name : _("NetworkManager status"); 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); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->out.output_data, arr); g_ptr_array_add (out.output_data, arr);
arr = nmc_dup_fields_array (tmpl, tmpl_len, 0); arr = nmc_dup_fields_array (tmpl, tmpl_len, 0);
set_val_strc (arr, 0, _("running")); set_val_strc (arr, 0, _("running"));
...@@ -379,10 +380,10 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl ...@@ -379,10 +380,10 @@ 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[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; arr[9].color = wwan_enabled ? NMC_TERM_COLOR_GREEN : NMC_TERM_COLOR_RED;
g_ptr_array_add (nmc->out.output_data, arr); g_ptr_array_add (out.output_data, arr);
print_data_prepare_width (nmc->out.output_data); print_data_prepare_width (out.output_data);
print_data (&nmc->nmc_config, &nmc->out); print_data (&nmc->nmc_config, &out);
return TRUE; return TRUE;
} }
...@@ -473,6 +474,7 @@ print_permissions (void *user_data) ...@@ -473,6 +474,7 @@ print_permissions (void *user_data)
const char *fields_common = NMC_FIELDS_NM_PERMISSIONS_COMMON; const char *fields_common = NMC_FIELDS_NM_PERMISSIONS_COMMON;
NmcOutputField *tmpl, *arr; NmcOutputField *tmpl, *arr;
size_t tmpl_len; size_t tmpl_len;
NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0) if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0)
fields_str = fields_common; fields_str = fields_common;
...@@ -483,7 +485,7 @@ print_permissions (void *user_data) ...@@ -483,7 +485,7 @@ print_permissions (void *user_data)
tmpl = nmc_fields_nm_permissions; tmpl = nmc_fields_nm_permissions;
tmpl_len = sizeof (nmc_fields_nm_permissions); tmpl_len = sizeof (nmc_fields_nm_permissions);
nmc->out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
if (error) { if (error) {
g_string_printf (nmc->return_text, _("Error: 'general permissions': %s"), error->message); g_string_printf (nmc->return_text, _("Error: 'general permissions': %s"), error->message);
...@@ -492,9 +494,9 @@ print_permissions (void *user_data) ...@@ -492,9 +494,9 @@ print_permissions (void *user_data)
return FALSE; return FALSE;
} }
nmc->out.print_fields.header_name = _("NetworkManager permissions"); 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); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->out.output_data, arr); g_ptr_array_add (out.output_data, arr);
for (perm = NM_CLIENT_PERMISSION_NONE + 1; perm <= NM_CLIENT_PERMISSION_LAST; perm++) { for (perm = NM_CLIENT_PERMISSION_NONE + 1; perm <= NM_CLIENT_PERMISSION_LAST; perm++) {
...@@ -503,10 +505,10 @@ print_permissions (void *user_data) ...@@ -503,10 +505,10 @@ print_permissions (void *user_data)
arr = nmc_dup_fields_array (tmpl, tmpl_len, 0); arr = nmc_dup_fields_array (tmpl, tmpl_len, 0);
set_val_strc (arr, 0, permission_to_string (perm)); set_val_strc (arr, 0, permission_to_string (perm));
set_val_strc (arr, 1, permission_result_to_string (perm_result)); set_val_strc (arr, 1, permission_result_to_string (perm_result));
g_ptr_array_add (nmc->out.output_data, arr); g_ptr_array_add (out.output_data, arr);
} }
print_data_prepare_width (nmc->out.output_data); print_data_prepare_width (out.output_data);
print_data (&nmc->nmc_config, &nmc->out); print_data (&nmc->nmc_config, &out);
quit (); quit ();
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
...@@ -583,6 +585,7 @@ show_general_logging (NmCli *nmc) ...@@ -583,6 +585,7 @@ show_general_logging (NmCli *nmc)
const char *fields_common = NMC_FIELDS_NM_LOGGING_COMMON; const char *fields_common = NMC_FIELDS_NM_LOGGING_COMMON;
NmcOutputField *tmpl, *arr; NmcOutputField *tmpl, *arr;
size_t tmpl_len; size_t tmpl_len;
NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0) if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0)
fields_str = fields_common; fields_str = fields_common;
...@@ -593,7 +596,7 @@ show_general_logging (NmCli *nmc) ...@@ -593,7 +596,7 @@ show_general_logging (NmCli *nmc)
tmpl = nmc_fields_nm_logging; tmpl = nmc_fields_nm_logging;
tmpl_len = sizeof (nmc_fields_nm_logging); tmpl_len = sizeof (nmc_fields_nm_logging);
nmc->out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
if (error) { if (error) {
g_string_printf (nmc->return_text, _("Error: 'general logging': %s"), error->message); g_string_printf (nmc->return_text, _("Error: 'general logging': %s"), error->message);
...@@ -610,17 +613,17 @@ show_general_logging (NmCli *nmc) ...@@ -610,17 +613,17 @@ show_general_logging (NmCli *nmc)
return FALSE; return FALSE;
} }
nmc->out.print_fields.header_name = _("NetworkManager logging"); 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); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->out.output_data, arr); g_ptr_array_add (out.output_data, arr);
arr = nmc_dup_fields_array (tmpl, tmpl_len, 0); arr = nmc_dup_fields_array (tmpl, tmpl_len, 0);
set_val_str (arr, 0, level); set_val_str (arr, 0, level);
set_val_str (arr, 1, domains); set_val_str (arr, 1, domains);
g_ptr_array_add (nmc->out.output_data, arr); g_ptr_array_add (out.output_data, arr);
print_data_prepare_width (nmc->out.output_data); print_data_prepare_width (out.output_data);
print_data (&nmc->nmc_config, &nmc->out); print_data (&nmc->nmc_config, &out);
return TRUE; return TRUE;
} }
......
...@@ -540,8 +540,6 @@ nmc_init (NmCli *nmc) ...@@ -540,8 +540,6 @@ nmc_init (NmCli *nmc)
nmc->mode_specified = FALSE; nmc->mode_specified = FALSE;
nmc->nmc_config_mutable.escape_values = TRUE; nmc->nmc_config_mutable.escape_values = TRUE;
nmc->required_fields = NULL; nmc->required_fields = NULL;
nmc->out.output_data = g_ptr_array_new_full (20, g_free);
memset (&nmc->out.print_fields, '\0', sizeof (NmcPrintFields));
nmc->ask = FALSE; nmc->ask = FALSE;
nmc->complete = FALSE; nmc->complete = FALSE;
nmc->show_secrets = FALSE; nmc->show_secrets = FALSE;
...@@ -569,8 +567,6 @@ nmc_cleanup (NmCli *nmc) ...@@ -569,8 +567,6 @@ nmc_cleanup (NmCli *nmc)
g_hash_table_destroy (nmc->pwds_hash); g_hash_table_destroy (nmc->pwds_hash);
g_free (nmc->required_fields); g_free (nmc->required_fields);
nmc_empty_output_fields (&nmc->out);
g_ptr_array_unref (nmc->out.output_data);
nmc_polkit_agent_fini (nmc); nmc_polkit_agent_fini (nmc);
} }
......
...@@ -172,7 +172,6 @@ typedef struct _NmCli { ...@@ -172,7 +172,6 @@ typedef struct _NmCli {
NmcConfig nmc_config_mutable; NmcConfig nmc_config_mutable;
}; };
char *required_fields; /* Required fields in output: '--fields' option */ char *required_fields; /* Required fields in output: '--fields' option */
NmcOutputData out;
gboolean ask; /* Ask for missing parameters: option '--ask' */ gboolean ask; /* Ask for missing parameters: option '--ask' */
gboolean complete; /* Autocomplete the command line */ gboolean complete; /* Autocomplete the command line */
gboolean show_secrets; /* Whether to display secrets (both input and output): option '--show-secrets' */ gboolean show_secrets; /* Whether to display secrets (both input and output): option '--show-secrets' */
...@@ -193,4 +192,11 @@ void nmc_clear_sigint (void); ...@@ -193,4 +192,11 @@ void nmc_clear_sigint (void);
void nmc_set_sigquit_internal (void); void nmc_set_sigquit_internal (void);
void nmc_exit (void); void nmc_exit (void);
void nmc_empty_output_fields (NmcOutputData *output_data);
#define NMC_OUTPUT_DATA_DEFINE_SCOPED(out) \
nm_auto (nmc_empty_output_fields) NmcOutputData out = { \
.output_data = g_ptr_array_new_full (20, g_free), \
}
#endif /* NMC_NMCLI_H */ #endif /* NMC_NMCLI_H */
...@@ -880,6 +880,7 @@ setting_details (NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean ...@@ -880,6 +880,7 @@ setting_details (NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean
size_t tmpl_len; size_t tmpl_len;
gs_free char *s_all = NULL; gs_free char *s_all = NULL;
NMMetaAccessorGetType type = NM_META_ACCESSOR_GET_TYPE_PRETTY; NMMetaAccessorGetType type = NM_META_ACCESSOR_GET_TYPE_PRETTY;
NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
g_return_val_if_fail (NM_IS_SETTING (setting), FALSE); g_return_val_if_fail (NM_IS_SETTING (setting), FALSE);
...@@ -897,10 +898,10 @@ setting_details (NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean ...@@ -897,10 +898,10 @@ setting_details (NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean
tmpl_len = sizeof (NmcOutputField) * (setting_info->properties_num + 1); tmpl_len = sizeof (NmcOutputField) * (setting_info->properties_num + 1);
tmpl = g_memdup (_get_nmc_output_fields (setting_info), tmpl_len); tmpl = g_memdup (_get_nmc_output_fields (setting_info), tmpl_len);
nmc->out.print_fields.indices = parse_output_fields (one_prop ?: (s_all = _all_properties (setting_info)), out.print_fields.indices = parse_output_fields (one_prop ?: (s_all = _all_properties (setting_info)),
tmpl, FALSE, NULL, NULL); tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (nmc->out.output_data, arr); g_ptr_array_add (out.output_data, arr);
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX);
for (i = 0; i < setting_info->properties_num; i++) { for (i = 0; i < setting_info->properties_num; i++) {
...@@ -916,10 +917,10 @@ setting_details (NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean ...@@ -916,10 +917,10 @@ setting_details (NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean
set_val_str (arr, i, g_strdup (_(NM_META_TEXT_HIDDEN))); set_val_str (arr, i, g_strdup (_(NM_META_TEXT_HIDDEN)));
} }
g_ptr_array_add (nmc->out.output_data, arr); g_ptr_array_add (out.output_data, arr);
print_data_prepare_width (nmc->out.output_data); print_data_prepare_width (out.output_data);
print_data (&nmc->nmc_config, &nmc->out); print_data (&nmc->nmc_config, &out);
return TRUE; return TRUE;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment