cli: merge branch 'th/cli-device-wifi-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/435
This commit is contained in:
@@ -27,9 +27,9 @@
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
ap_wpa_rsn_flags_to_string (NM80211ApSecurityFlags flags)
|
ap_wpa_rsn_flags_to_string (NM80211ApSecurityFlags flags, NMMetaAccessorGetType get_type)
|
||||||
{
|
{
|
||||||
char *flags_str[14];
|
char *flags_str[16];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (flags & NM_802_11_AP_SEC_PAIR_WEP40)
|
if (flags & NM_802_11_AP_SEC_PAIR_WEP40)
|
||||||
@@ -56,13 +56,17 @@ ap_wpa_rsn_flags_to_string (NM80211ApSecurityFlags flags)
|
|||||||
flags_str[i++] = "sae";
|
flags_str[i++] = "sae";
|
||||||
if (flags & NM_802_11_AP_SEC_KEY_MGMT_OWE)
|
if (flags & NM_802_11_AP_SEC_KEY_MGMT_OWE)
|
||||||
flags_str[i++] = "owe";
|
flags_str[i++] = "owe";
|
||||||
/* Make sure you grow flags_str when adding items here. */
|
|
||||||
|
|
||||||
if (i == 0)
|
/* Make sure you grow flags_str when adding items here. */
|
||||||
flags_str[i++] = _("(none)");
|
nm_assert (i < G_N_ELEMENTS (flags_str));
|
||||||
|
|
||||||
|
if (i == 0) {
|
||||||
|
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
|
||||||
|
return g_strdup (_("(none)"));
|
||||||
|
return g_strdup ("(none)");
|
||||||
|
}
|
||||||
|
|
||||||
flags_str[i] = NULL;
|
flags_str[i] = NULL;
|
||||||
|
|
||||||
return g_strjoinv (" ", flags_str);
|
return g_strjoinv (" ", flags_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1101,30 +1105,30 @@ compare_aps (gconstpointer a, gconstpointer b, gpointer user_data)
|
|||||||
{
|
{
|
||||||
NMAccessPoint *apa = *(NMAccessPoint **)a;
|
NMAccessPoint *apa = *(NMAccessPoint **)a;
|
||||||
NMAccessPoint *apb = *(NMAccessPoint **)b;
|
NMAccessPoint *apb = *(NMAccessPoint **)b;
|
||||||
int cmp;
|
|
||||||
|
|
||||||
cmp = nm_access_point_get_strength (apb) - nm_access_point_get_strength (apa);
|
NM_CMP_DIRECT (nm_access_point_get_strength (apb), nm_access_point_get_strength (apa));
|
||||||
if (cmp != 0)
|
NM_CMP_DIRECT (nm_access_point_get_frequency (apa), nm_access_point_get_frequency (apb));
|
||||||
return cmp;
|
NM_CMP_DIRECT (nm_access_point_get_max_bitrate (apb), nm_access_point_get_max_bitrate (apa));
|
||||||
|
|
||||||
cmp = nm_access_point_get_frequency (apa) - nm_access_point_get_frequency (apb);
|
/* as fallback, just give it some stable order and use the D-Bus path (literally). */
|
||||||
if (cmp != 0)
|
NM_CMP_DIRECT_STRCMP0 (nm_object_get_path (NM_OBJECT (apa)),
|
||||||
return cmp;
|
nm_object_get_path (NM_OBJECT (apb)));
|
||||||
|
|
||||||
return nm_access_point_get_max_bitrate (apb) - nm_access_point_get_max_bitrate (apa);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GPtrArray *
|
static GPtrArray *
|
||||||
sort_access_points (const GPtrArray *aps)
|
sort_access_points (const GPtrArray *aps)
|
||||||
{
|
{
|
||||||
GPtrArray *sorted;
|
GPtrArray *sorted;
|
||||||
int i;
|
guint i;
|
||||||
|
|
||||||
g_return_val_if_fail (aps, NULL);
|
g_return_val_if_fail (aps, NULL);
|
||||||
|
|
||||||
sorted = g_ptr_array_sized_new (aps->len);
|
sorted = g_ptr_array_sized_new (aps->len);
|
||||||
|
g_ptr_array_set_free_func (sorted, nm_g_object_unref);
|
||||||
for (i = 0; i < aps->len; i++)
|
for (i = 0; i < aps->len; i++)
|
||||||
g_ptr_array_add (sorted, aps->pdata[i]);
|
g_ptr_array_add (sorted, g_object_ref (aps->pdata[i]));
|
||||||
g_ptr_array_sort_with_data (sorted, compare_aps, NULL);
|
g_ptr_array_sort_with_data (sorted, compare_aps, NULL);
|
||||||
return sorted;
|
return sorted;
|
||||||
}
|
}
|
||||||
@@ -1189,8 +1193,8 @@ fill_output_access_point (gpointer data, gpointer user_data)
|
|||||||
freq_str = g_strdup_printf (_("%u MHz"), freq);
|
freq_str = g_strdup_printf (_("%u MHz"), freq);
|
||||||
bitrate_str = g_strdup_printf (_("%u Mbit/s"), bitrate/1000);
|
bitrate_str = g_strdup_printf (_("%u Mbit/s"), bitrate/1000);
|
||||||
strength_str = g_strdup_printf ("%u", strength);
|
strength_str = g_strdup_printf ("%u", strength);
|
||||||
wpa_flags_str = ap_wpa_rsn_flags_to_string (wpa_flags);
|
wpa_flags_str = ap_wpa_rsn_flags_to_string (wpa_flags, NM_META_ACCESSOR_GET_TYPE_PRETTY);
|
||||||
rsn_flags_str = ap_wpa_rsn_flags_to_string (rsn_flags);
|
rsn_flags_str = ap_wpa_rsn_flags_to_string (rsn_flags, NM_META_ACCESSOR_GET_TYPE_PRETTY);
|
||||||
sig_bars = nmc_wifi_strength_bars (strength);
|
sig_bars = nmc_wifi_strength_bars (strength);
|
||||||
|
|
||||||
security_str = g_string_new (NULL);
|
security_str = g_string_new (NULL);
|
||||||
@@ -1543,7 +1547,6 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||||||
if ((NM_IS_DEVICE_WIFI (device))) {
|
if ((NM_IS_DEVICE_WIFI (device))) {
|
||||||
NMAccessPoint *active_ap = NULL;
|
NMAccessPoint *active_ap = NULL;
|
||||||
const char *active_bssid = NULL;
|
const char *active_bssid = NULL;
|
||||||
GPtrArray *aps;
|
|
||||||
|
|
||||||
/* section AP */
|
/* section AP */
|
||||||
if (!g_ascii_strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[4]->name)) {
|
if (!g_ascii_strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[4]->name)) {
|
||||||
@@ -1561,6 +1564,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||||||
g_ptr_array_add (out.output_data, arr);
|
g_ptr_array_add (out.output_data, arr);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
gs_unref_ptrarray GPtrArray *aps = NULL;
|
||||||
APInfo info = {
|
APInfo info = {
|
||||||
.nmc = nmc,
|
.nmc = nmc,
|
||||||
.index = 1,
|
.index = 1,
|
||||||
@@ -1572,7 +1576,6 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||||||
|
|
||||||
aps = sort_access_points (nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device)));
|
aps = sort_access_points (nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device)));
|
||||||
g_ptr_array_foreach (aps, fill_output_access_point, &info);
|
g_ptr_array_foreach (aps, fill_output_access_point, &info);
|
||||||
g_ptr_array_free (aps, FALSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print_data_prepare_width (out.output_data);
|
print_data_prepare_width (out.output_data);
|
||||||
@@ -2785,7 +2788,6 @@ show_access_point_info (NMDeviceWifi *wifi, NmCli *nmc, NmcOutputData *out)
|
|||||||
{
|
{
|
||||||
NMAccessPoint *active_ap = NULL;
|
NMAccessPoint *active_ap = NULL;
|
||||||
const char *active_bssid = NULL;
|
const char *active_bssid = NULL;
|
||||||
GPtrArray *aps;
|
|
||||||
NmcOutputField *arr;
|
NmcOutputField *arr;
|
||||||
|
|
||||||
if (nm_device_get_state (NM_DEVICE (wifi)) == NM_DEVICE_STATE_ACTIVATED) {
|
if (nm_device_get_state (NM_DEVICE (wifi)) == NM_DEVICE_STATE_ACTIVATED) {
|
||||||
@@ -2798,6 +2800,7 @@ show_access_point_info (NMDeviceWifi *wifi, NmCli *nmc, NmcOutputData *out)
|
|||||||
g_ptr_array_add (out->output_data, arr);
|
g_ptr_array_add (out->output_data, arr);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
gs_unref_ptrarray GPtrArray *aps = NULL;
|
||||||
APInfo info = {
|
APInfo info = {
|
||||||
.nmc = nmc,
|
.nmc = nmc,
|
||||||
.index = 1,
|
.index = 1,
|
||||||
@@ -2809,7 +2812,6 @@ show_access_point_info (NMDeviceWifi *wifi, NmCli *nmc, NmcOutputData *out)
|
|||||||
|
|
||||||
aps = sort_access_points (nm_device_wifi_get_access_points (wifi));
|
aps = sort_access_points (nm_device_wifi_get_access_points (wifi));
|
||||||
g_ptr_array_foreach (aps, fill_output_access_point, &info);
|
g_ptr_array_foreach (aps, fill_output_access_point, &info);
|
||||||
g_ptr_array_free (aps, TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print_data_prepare_width (out->output_data);
|
print_data_prepare_width (out->output_data);
|
||||||
@@ -2923,14 +2925,14 @@ wifi_list_finish (WifiListData *data)
|
|||||||
g_signal_handler_disconnect (data->wifi, data->last_scan_id);
|
g_signal_handler_disconnect (data->wifi, data->last_scan_id);
|
||||||
nm_clear_g_source (&data->timeout_id);
|
nm_clear_g_source (&data->timeout_id);
|
||||||
nm_clear_g_cancellable (&data->scan_cancellable);
|
nm_clear_g_cancellable (&data->scan_cancellable);
|
||||||
g_slice_free (WifiListData, data);
|
nm_g_slice_free (data);
|
||||||
|
|
||||||
if (info->nmc->should_wait == 0) {
|
if (info->nmc->should_wait == 0) {
|
||||||
for (i = 0; info->devices[i]; i++)
|
for (i = 0; info->devices[i]; i++)
|
||||||
g_object_unref (info->devices[i]);
|
g_object_unref (info->devices[i]);
|
||||||
g_free (info->devices);
|
g_free (info->devices);
|
||||||
g_array_unref (info->out_indices);
|
g_array_unref (info->out_indices);
|
||||||
g_free (info);
|
nm_g_slice_free (info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3012,6 +3014,8 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv)
|
|||||||
NMDeviceWifi *wifi;
|
NMDeviceWifi *wifi;
|
||||||
ScanInfo *scan_info = NULL;
|
ScanInfo *scan_info = NULL;
|
||||||
WifiListData *data;
|
WifiListData *data;
|
||||||
|
gboolean ifname_handled;
|
||||||
|
NMDevice *ifname_handled_candidate;
|
||||||
guint i, j;
|
guint i, j;
|
||||||
|
|
||||||
devices = nmc_get_devices_sorted (nmc->client);
|
devices = nmc_get_devices_sorted (nmc->client);
|
||||||
@@ -3060,6 +3064,9 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nmc->complete)
|
||||||
|
return nmc->return_value;
|
||||||
|
|
||||||
if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "common") == 0)
|
if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "common") == 0)
|
||||||
fields_str = NMC_FIELDS_DEV_WIFI_LIST_COMMON;
|
fields_str = NMC_FIELDS_DEV_WIFI_LIST_COMMON;
|
||||||
else if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "all") == 0) {
|
else if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "all") == 0) {
|
||||||
@@ -3075,9 +3082,6 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv)
|
|||||||
return NMC_RESULT_ERROR_USER_INPUT;
|
return NMC_RESULT_ERROR_USER_INPUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nmc->complete)
|
|
||||||
return nmc->return_value;
|
|
||||||
|
|
||||||
if (argc) {
|
if (argc) {
|
||||||
g_string_printf (nmc->return_text, _("Error: invalid extra argument '%s'."), *argv);
|
g_string_printf (nmc->return_text, _("Error: invalid extra argument '%s'."), *argv);
|
||||||
return NMC_RESULT_ERROR_USER_INPUT;
|
return NMC_RESULT_ERROR_USER_INPUT;
|
||||||
@@ -3094,63 +3098,91 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv)
|
|||||||
return NMC_RESULT_ERROR_USER_INPUT;
|
return NMC_RESULT_ERROR_USER_INPUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ifname) {
|
ifname_handled = (ifname == NULL);
|
||||||
device = find_wifi_device_by_iface (devices, ifname, NULL);
|
ifname_handled_candidate = NULL;
|
||||||
if (!device) {
|
|
||||||
g_string_printf (nmc->return_text, _("Error: Device '%s' not found."), ifname);
|
|
||||||
return NMC_RESULT_ERROR_NOT_FOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NM_IS_DEVICE_WIFI (device)) {
|
j = 0;
|
||||||
devices[0] = device;
|
for (i = 0; devices[i]; i++) {
|
||||||
devices[1] = NULL;
|
const char *dev_iface;
|
||||||
} else {
|
|
||||||
if ( nm_device_get_device_type (device) == NM_DEVICE_TYPE_GENERIC
|
device = devices[i];
|
||||||
&& g_strcmp0 (nm_device_get_type_description (device), "wifi") == 0) {
|
dev_iface = nm_device_get_iface (device);
|
||||||
g_string_printf (nmc->return_text,
|
|
||||||
_("Error: Device '%s' was not recognized as a Wi-Fi device, check NetworkManager Wi-Fi plugin."),
|
if (ifname) {
|
||||||
ifname);
|
if (!nm_streq0 (ifname, dev_iface))
|
||||||
} else {
|
continue;
|
||||||
g_string_printf (nmc->return_text,
|
if (!NM_IS_DEVICE_WIFI (device)) {
|
||||||
_("Error: Device '%s' is not a Wi-Fi device."),
|
if ( nm_device_get_device_type (device) == NM_DEVICE_TYPE_GENERIC
|
||||||
ifname);
|
&& nm_streq0 (nm_device_get_type_description (device), "wifi"))
|
||||||
|
ifname_handled_candidate = device;
|
||||||
|
else if (!ifname_handled_candidate)
|
||||||
|
ifname_handled_candidate = device;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
return NMC_RESULT_ERROR_UNKNOWN;
|
ifname_handled = TRUE;
|
||||||
|
} else {
|
||||||
|
if (!NM_IS_DEVICE_WIFI (device))
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Filter out non-wifi devices */
|
devices[j++] = device;
|
||||||
for (i = 0, j = 0; devices[i]; i++) {
|
|
||||||
if (NM_IS_DEVICE_WIFI (devices[i]))
|
|
||||||
devices[j++] = devices[i];
|
|
||||||
}
|
}
|
||||||
devices[j] = NULL;
|
devices[j] = NULL;
|
||||||
|
|
||||||
|
if (!ifname_handled) {
|
||||||
|
if (!ifname_handled_candidate) {
|
||||||
|
g_string_printf (nmc->return_text,
|
||||||
|
_("Error: Device '%s' not found."),
|
||||||
|
ifname);
|
||||||
|
} else if ( nm_device_get_device_type (ifname_handled_candidate) == NM_DEVICE_TYPE_GENERIC
|
||||||
|
&& nm_streq0 (nm_device_get_type_description (ifname_handled_candidate), "wifi")) {
|
||||||
|
g_string_printf (nmc->return_text,
|
||||||
|
_("Error: Device '%s' was not recognized as a Wi-Fi device, check NetworkManager Wi-Fi plugin."),
|
||||||
|
ifname);
|
||||||
|
} else {
|
||||||
|
g_string_printf (nmc->return_text,
|
||||||
|
_("Error: Device '%s' is not a Wi-Fi device."),
|
||||||
|
ifname);
|
||||||
|
}
|
||||||
|
return NMC_RESULT_ERROR_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
/* Start a new scan for devices that need it */
|
/* Start a new scan for devices that need it */
|
||||||
for (i = 0; devices[i]; i++) {
|
for (i = 0; devices[i]; i++) {
|
||||||
wifi = (NMDeviceWifi *) devices[i];
|
wifi = (NMDeviceWifi *) devices[i];
|
||||||
g_object_ref (wifi);
|
g_object_ref (wifi);
|
||||||
|
|
||||||
if ( rescan_cutoff == 0
|
if ( rescan_cutoff == 0
|
||||||
|| (rescan_cutoff > 0 && nm_device_wifi_get_last_scan (wifi) >= rescan_cutoff))
|
|| ( rescan_cutoff > 0
|
||||||
|
&& nm_device_wifi_get_last_scan (wifi) >= rescan_cutoff))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!scan_info) {
|
if (!scan_info) {
|
||||||
scan_info = g_new0 (ScanInfo, 1);
|
scan_info = g_slice_new (ScanInfo);
|
||||||
scan_info->out_indices = g_array_ref (out_indices);
|
*scan_info = (ScanInfo) {
|
||||||
scan_info->tmpl = tmpl;
|
.out_indices = g_array_ref (out_indices),
|
||||||
scan_info->bssid_user = bssid_user;
|
.tmpl = tmpl,
|
||||||
scan_info->nmc = nmc;
|
.bssid_user = bssid_user,
|
||||||
|
.nmc = nmc,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
nmc->should_wait++;
|
nmc->should_wait++;
|
||||||
data = g_slice_new0 (WifiListData);
|
|
||||||
data->wifi = wifi;
|
data = g_slice_new (WifiListData);
|
||||||
data->scan_info = scan_info;
|
*data = (WifiListData) {
|
||||||
data->last_scan_id = g_signal_connect (wifi, "notify::" NM_DEVICE_WIFI_LAST_SCAN,
|
.wifi = wifi,
|
||||||
G_CALLBACK (wifi_last_scan_updated), data);
|
.scan_info = scan_info,
|
||||||
data->scan_cancellable = g_cancellable_new ();
|
.last_scan_id = g_signal_connect (wifi,
|
||||||
data->timeout_id = g_timeout_add_seconds (15, wifi_list_scan_timeout, data);
|
"notify::" NM_DEVICE_WIFI_LAST_SCAN,
|
||||||
|
G_CALLBACK (wifi_last_scan_updated),
|
||||||
|
data),
|
||||||
|
.scan_cancellable = g_cancellable_new (),
|
||||||
|
.timeout_id = g_timeout_add_seconds (15,
|
||||||
|
wifi_list_scan_timeout,
|
||||||
|
data),
|
||||||
|
};
|
||||||
|
|
||||||
nm_device_wifi_request_scan_async (wifi, data->scan_cancellable, wifi_list_rescan_cb, data);
|
nm_device_wifi_request_scan_async (wifi, data->scan_cancellable, wifi_list_rescan_cb, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -321,19 +321,14 @@ nmc_parse_args (nmc_arg_t *arg_arr, gboolean last, int *argc, char ***argv, GErr
|
|||||||
char *
|
char *
|
||||||
ssid_to_hex (const char *str, gsize len)
|
ssid_to_hex (const char *str, gsize len)
|
||||||
{
|
{
|
||||||
GString *printable;
|
if (len == 0)
|
||||||
char *printable_str;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (str == NULL || len == 0)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
printable = g_string_new (NULL);
|
return nm_utils_bin2hexstr_full (str,
|
||||||
for (i = 0; i < len; i++) {
|
len,
|
||||||
g_string_append_printf (printable, "%02X", (unsigned char) str[i]);
|
'\0',
|
||||||
}
|
TRUE,
|
||||||
printable_str = g_string_free (printable, FALSE);
|
NULL);
|
||||||
return printable_str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -667,7 +662,6 @@ _output_selection_append (GArray *cols,
|
|||||||
guint i;
|
guint i;
|
||||||
const NMMetaAbstractInfo *const*nested;
|
const NMMetaAbstractInfo *const*nested;
|
||||||
NMMetaSelectionResultList *selection;
|
NMMetaSelectionResultList *selection;
|
||||||
const NMMetaSelectionItem *si;
|
|
||||||
|
|
||||||
col_idx = cols->len;
|
col_idx = cols->len;
|
||||||
|
|
||||||
@@ -688,6 +682,8 @@ _output_selection_append (GArray *cols,
|
|||||||
gs_free char *allowed_fields = NULL;
|
gs_free char *allowed_fields = NULL;
|
||||||
|
|
||||||
if (parent_idx != PRINT_DATA_COL_PARENT_NIL) {
|
if (parent_idx != PRINT_DATA_COL_PARENT_NIL) {
|
||||||
|
const NMMetaSelectionItem *si;
|
||||||
|
|
||||||
si = g_array_index (cols, PrintDataCol, parent_idx).selection_item;
|
si = g_array_index (cols, PrintDataCol, parent_idx).selection_item;
|
||||||
allowed_fields = nm_meta_abstract_info_get_nested_names_str (si->info, si->self_selection);
|
allowed_fields = nm_meta_abstract_info_get_nested_names_str (si->info, si->self_selection);
|
||||||
}
|
}
|
||||||
@@ -719,10 +715,9 @@ _output_selection_append (GArray *cols,
|
|||||||
g_ptr_array_add (gfree_keeper, selection);
|
g_ptr_array_add (gfree_keeper, selection);
|
||||||
|
|
||||||
for (i = 0; i < selection->num; i++) {
|
for (i = 0; i < selection->num; i++) {
|
||||||
si = &selection->items[i];
|
|
||||||
if (!_output_selection_append (cols,
|
if (!_output_selection_append (cols,
|
||||||
col_idx,
|
col_idx,
|
||||||
si,
|
&selection->items[i],
|
||||||
gfree_keeper,
|
gfree_keeper,
|
||||||
error))
|
error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -778,7 +773,8 @@ _output_selection_complete (GArray *cols)
|
|||||||
static gboolean
|
static gboolean
|
||||||
_output_selection_parse (const NMMetaAbstractInfo *const*fields,
|
_output_selection_parse (const NMMetaAbstractInfo *const*fields,
|
||||||
const char *fields_str,
|
const char *fields_str,
|
||||||
GArray **out_cols,
|
PrintDataCol **out_cols_data,
|
||||||
|
guint *out_cols_len,
|
||||||
GPtrArray **out_gfree_keeper,
|
GPtrArray **out_gfree_keeper,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
@@ -803,16 +799,18 @@ _output_selection_parse (const NMMetaAbstractInfo *const*fields,
|
|||||||
cols = g_array_new (FALSE, TRUE, sizeof (PrintDataCol));
|
cols = g_array_new (FALSE, TRUE, sizeof (PrintDataCol));
|
||||||
|
|
||||||
for (i = 0; i < selection->num; i++) {
|
for (i = 0; i < selection->num; i++) {
|
||||||
const NMMetaSelectionItem *si = &selection->items[i];
|
if (!_output_selection_append (cols,
|
||||||
|
PRINT_DATA_COL_PARENT_NIL,
|
||||||
if (!_output_selection_append (cols, PRINT_DATA_COL_PARENT_NIL,
|
&selection->items[i],
|
||||||
si, gfree_keeper, error))
|
gfree_keeper,
|
||||||
|
error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
_output_selection_complete (cols);
|
_output_selection_complete (cols);
|
||||||
|
|
||||||
*out_cols = g_steal_pointer (&cols);
|
*out_cols_len = cols->len;
|
||||||
|
*out_cols_data = (PrintDataCol *) g_array_free (g_steal_pointer (&cols), FALSE);
|
||||||
*out_gfree_keeper = g_steal_pointer (&gfree_keeper);
|
*out_gfree_keeper = g_steal_pointer (&gfree_keeper);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -1142,7 +1140,8 @@ _print_fill (const NmcConfig *nmc_config,
|
|||||||
header_cell->width = nmc_string_screen_width (header_cell->title, NULL);
|
header_cell->width = nmc_string_screen_width (header_cell->title, NULL);
|
||||||
|
|
||||||
for (i_row = 0; i_row < targets_len; i_row++) {
|
for (i_row = 0; i_row < targets_len; i_row++) {
|
||||||
const PrintDataCell *cell = &g_array_index (cells, PrintDataCell, i_row * cols_len + i_col);
|
const PrintDataCell *cells_line = &g_array_index (cells, PrintDataCell, i_row * header_row->len);
|
||||||
|
const PrintDataCell *cell = &cells_line[i_col];
|
||||||
const char *const*i_strv;
|
const char *const*i_strv;
|
||||||
|
|
||||||
switch (cell->text_format) {
|
switch (cell->text_format) {
|
||||||
@@ -1379,20 +1378,24 @@ nmc_print (const NmcConfig *nmc_config,
|
|||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gs_unref_ptrarray GPtrArray *gfree_keeper = NULL;
|
gs_unref_ptrarray GPtrArray *gfree_keeper = NULL;
|
||||||
gs_unref_array GArray *cols = NULL;
|
gs_free PrintDataCol *cols_data = NULL;
|
||||||
|
guint cols_len;
|
||||||
gs_unref_array GArray *header_row = NULL;
|
gs_unref_array GArray *header_row = NULL;
|
||||||
gs_unref_array GArray *cells = NULL;
|
gs_unref_array GArray *cells = NULL;
|
||||||
|
|
||||||
if (!_output_selection_parse (fields, fields_str,
|
if (!_output_selection_parse (fields,
|
||||||
&cols, &gfree_keeper,
|
fields_str,
|
||||||
|
&cols_data,
|
||||||
|
&cols_len,
|
||||||
|
&gfree_keeper,
|
||||||
error))
|
error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
_print_fill (nmc_config,
|
_print_fill (nmc_config,
|
||||||
targets,
|
targets,
|
||||||
targets_data,
|
targets_data,
|
||||||
&g_array_index (cols, PrintDataCol, 0),
|
cols_data,
|
||||||
cols->len,
|
cols_len,
|
||||||
&header_row,
|
&header_row,
|
||||||
&cells);
|
&cells);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user