2019-09-10 11:19:01 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2019-09-25 13:13:40 +02:00
|
|
|
/*
|
2019-10-01 09:20:35 +02:00
|
|
|
* Copyright (C) 2010 - 2018 Red Hat, Inc.
|
2010-02-25 09:52:30 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef NMC_UTILS_H
|
|
|
|
|
#define NMC_UTILS_H
|
|
|
|
|
|
2010-03-18 15:39:15 +01:00
|
|
|
#include "nmcli.h"
|
|
|
|
|
|
2013-01-16 12:26:45 +01:00
|
|
|
/* === Types === */
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
const char *name;
|
|
|
|
|
gboolean has_value;
|
|
|
|
|
const char **value;
|
|
|
|
|
gboolean mandatory;
|
|
|
|
|
gboolean found;
|
|
|
|
|
} nmc_arg_t;
|
|
|
|
|
|
2010-03-18 15:39:15 +01:00
|
|
|
/* === Functions === */
|
2020-04-05 13:05:58 +02:00
|
|
|
int next_arg (NmCli *nmc, int *argc, const char *const**argv, ...);
|
2013-04-18 11:25:49 +02:00
|
|
|
gboolean nmc_arg_is_help (const char *arg);
|
2013-11-07 14:47:12 +01:00
|
|
|
gboolean nmc_arg_is_option (const char *arg, const char *opt_name);
|
2020-04-05 13:05:58 +02:00
|
|
|
gboolean nmc_parse_args (nmc_arg_t *arg_arr, gboolean last, int *argc, const char *const**argv, GError **error);
|
2013-05-16 16:26:15 +02:00
|
|
|
char *ssid_to_hex (const char *str, gsize len);
|
2012-04-28 22:32:21 +01:00
|
|
|
void nmc_terminal_erase_line (void);
|
|
|
|
|
void nmc_terminal_show_progress (const char *str);
|
2018-10-09 13:08:24 +02:00
|
|
|
pid_t nmc_terminal_spawn_pager (const NmcConfig *nmc_config);
|
2018-03-29 12:31:33 +02:00
|
|
|
char *nmc_colorize (const NmcConfig *nmc_config, NMMetaColor color, const char * fmt, ...) _nm_printf (3, 4);
|
2015-02-13 13:25:16 +01:00
|
|
|
void nmc_filter_out_colors_inplace (char *str);
|
|
|
|
|
char *nmc_filter_out_colors (const char *str);
|
2012-11-21 16:53:23 +01:00
|
|
|
char *nmc_get_user_input (const char *ask_str);
|
2015-03-12 14:11:18 +01:00
|
|
|
int nmc_string_to_arg_array (const char *line, const char *delim, gboolean unquote,
|
|
|
|
|
char ***argv, int *argc);
|
2013-04-08 09:25:44 +02:00
|
|
|
const char *nmc_string_is_valid (const char *input, const char **allowed, GError **error);
|
2017-03-25 13:20:11 +01:00
|
|
|
char * nmc_util_strv_for_display (const char *const*strv, gboolean brackets);
|
2010-04-26 17:32:18 +02:00
|
|
|
int nmc_string_screen_width (const char *start, const char *end);
|
2013-05-22 08:36:09 +02:00
|
|
|
void set_val_str (NmcOutputField fields_array[], guint32 index, char *value);
|
|
|
|
|
void set_val_strc (NmcOutputField fields_array[], guint32 index, const char *value);
|
|
|
|
|
void set_val_arr (NmcOutputField fields_array[], guint32 index, char **value);
|
|
|
|
|
void set_val_arrc (NmcOutputField fields_array[], guint32 index, const char **value);
|
2018-03-29 12:31:33 +02:00
|
|
|
void set_val_color_all (NmcOutputField fields_array[], NMMetaColor color);
|
2013-03-25 10:44:15 -04:00
|
|
|
void nmc_free_output_field_values (NmcOutputField fields_array[]);
|
2017-04-03 14:04:28 +02:00
|
|
|
|
2013-12-10 12:00:53 +01:00
|
|
|
GArray *parse_output_fields (const char *fields_str,
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
const NMMetaAbstractInfo *const* fields_array,
|
2013-12-10 12:00:53 +01:00
|
|
|
gboolean parse_groups,
|
|
|
|
|
GPtrArray **group_fields,
|
|
|
|
|
GError **error);
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
NmcOutputField *nmc_dup_fields_array (const NMMetaAbstractInfo *const*fields, NmcOfFlags flags);
|
2017-03-30 13:34:35 +02:00
|
|
|
void nmc_empty_output_fields (NmcOutputData *output_data);
|
2017-03-31 12:55:43 +02:00
|
|
|
void print_required_fields (const NmcConfig *nmc_config,
|
2020-04-02 19:10:15 +02:00
|
|
|
NmcPagerData *pager_data,
|
2017-03-31 12:55:43 +02:00
|
|
|
NmcOfFlags of_flags,
|
|
|
|
|
const GArray *indices,
|
|
|
|
|
const char *header_name,
|
|
|
|
|
int indent,
|
|
|
|
|
const NmcOutputField *field_values);
|
2017-03-30 13:46:09 +02:00
|
|
|
void print_data_prepare_width (GPtrArray *output_data);
|
2017-03-31 13:21:47 +02:00
|
|
|
void print_data (const NmcConfig *nmc_config,
|
2020-04-02 19:10:15 +02:00
|
|
|
NmcPagerData *pager_data,
|
2017-03-31 13:21:47 +02:00
|
|
|
const GArray *indices,
|
|
|
|
|
const char *header_name,
|
|
|
|
|
int indent,
|
|
|
|
|
const NmcOutputData *out);
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2017-04-04 13:52:13 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2017-04-07 12:58:13 +02:00
|
|
|
extern const NMMetaEnvironment *const nmc_meta_environment;
|
2020-04-02 13:39:39 +02:00
|
|
|
extern const NmCli *const nmc_meta_environment_arg;
|
2017-04-07 12:58:13 +02:00
|
|
|
|
2017-04-04 15:23:39 +02:00
|
|
|
typedef enum {
|
2017-04-06 15:14:23 +02:00
|
|
|
|
2017-04-04 15:23:39 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_RUNNING = 0,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_VERSION,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_STATE,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_STARTUP,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_CONNECTIVITY,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_NETWORKING,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIFI_HW,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIFI,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WWAN_HW,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WWAN,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIMAX_HW,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIMAX,
|
|
|
|
|
_NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_NUM,
|
2017-04-06 15:14:23 +02:00
|
|
|
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_PERMISSION = 0,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_VALUE,
|
|
|
|
|
_NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_NUM,
|
|
|
|
|
|
2017-04-06 15:14:23 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_LEVEL = 0,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_DOMAINS,
|
|
|
|
|
_NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_NUM,
|
|
|
|
|
|
2017-04-06 15:14:23 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ADDRESS = 0,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_GATEWAY,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ROUTE,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DNS,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DOMAIN,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_WINS,
|
|
|
|
|
_NMC_GENERIC_INFO_TYPE_IP4_CONFIG_NUM,
|
|
|
|
|
|
2017-09-18 12:29:06 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ADDRESS = 0,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_IP6_CONFIG_GATEWAY,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ROUTE,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_IP6_CONFIG_DNS,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_IP6_CONFIG_DOMAIN,
|
|
|
|
|
_NMC_GENERIC_INFO_TYPE_IP6_CONFIG_NUM,
|
|
|
|
|
|
2018-04-26 17:43:13 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_DHCP_CONFIG_OPTION = 0,
|
|
|
|
|
_NMC_GENERIC_INFO_TYPE_DHCP_CONFIG_NUM,
|
|
|
|
|
|
cli: rework printing of `nmcli connection` for multiple active connections
The output of `nmcli connection show` contains also information about
whether the profile is currently active, for example the device and
the current (activation) state.
Even when a profile can be activated only once (without supporting
mutiple activations at the same time), there are moments when a
connection is activating and still deactivating on another device.
NetworkManager ensures in the case with single activations that
a profile cannot be in state "activated" multiple times. But that
doesn't mean, that one profile cannot have multiple active connection
which reference it. That was already handled wrongly before, because
`nmcli connection show` would only search the first matching
active-connection. That is, it would arbitrarily pick an active
connection in case there were multiple and only show activation
state about one.
Furthermore, we will soon also add the possibility, that a profile can be
active multiple times (at the same time). Especially then, we need to
extend the output format to show all the devices on which the profile is
currently active.
Rework printing the connection list to use nmc_print(), and fix various
issues.
- as discussed, a profile may have multiple active connections at each time.
There are only two possibilities: if a profile is active multiple
times, show a line for each activation, or otherwise, show the
information about multiple activations combined in one line, e.g. by
printing "DEVICE eth0,eth1". This patch, does the former.
We will now print a line for each active connection, to show
all the devices and activation states in multiple lines.
Yes, this may result in the same profile being printed multiple times.
That is a change in behavior, and inconvenient if you do something
like
for UUID in $(nmcli connection show | awk '{print$2}'); do ...
However, above is anyway wrong because it assumes that there are no
spaces in the connection name. The proper way to do this is like
for UUID in $(nmcli -g UUID connection show); do ...
In the latter case, whenever a user selects a subset of fields
(--fields, --get) which don't print information about active connections,
these multiple lines are combined. So, above still works as expected,
never returning duplicate UUIDs.
- if a user has no permissions to see a connection, we previously
would print "<invisible> $NAME". No longer do this but just print
the ID was it is reported by the active-connection. If the goal
of this was to prevent users from accidentally access the non-existing
connection by $NAME, then this was a bad solution, because a script
would instead try to access "<invisible> $NAME". This is now solved
better by hiding the active connection if the user selects "-g NAME".
- the --order option now sorts according to how the fields are shown.
For example, with --terse mode, it will evaluate type "802-11-wireless"
but with pretty mode it will consider "wifi". This may change the
ordering in which connections are shown. Also, for sorting the name,
we use g_utf8_collate() because it's unicode.
2018-04-25 10:00:40 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_CON_SHOW_NAME = 0,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_SHOW_UUID,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_SHOW_TYPE,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP_REAL,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_SHOW_AUTOCONNECT,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_SHOW_AUTOCONNECT_PRIORITY,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_SHOW_READONLY,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_SHOW_DBUS_PATH,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_SHOW_ACTIVE,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_SHOW_DEVICE,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_SHOW_STATE,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_SHOW_ACTIVE_PATH,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_SHOW_SLAVE,
|
2018-05-28 09:34:24 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_CON_SHOW_FILENAME,
|
cli: rework printing of `nmcli connection` for multiple active connections
The output of `nmcli connection show` contains also information about
whether the profile is currently active, for example the device and
the current (activation) state.
Even when a profile can be activated only once (without supporting
mutiple activations at the same time), there are moments when a
connection is activating and still deactivating on another device.
NetworkManager ensures in the case with single activations that
a profile cannot be in state "activated" multiple times. But that
doesn't mean, that one profile cannot have multiple active connection
which reference it. That was already handled wrongly before, because
`nmcli connection show` would only search the first matching
active-connection. That is, it would arbitrarily pick an active
connection in case there were multiple and only show activation
state about one.
Furthermore, we will soon also add the possibility, that a profile can be
active multiple times (at the same time). Especially then, we need to
extend the output format to show all the devices on which the profile is
currently active.
Rework printing the connection list to use nmc_print(), and fix various
issues.
- as discussed, a profile may have multiple active connections at each time.
There are only two possibilities: if a profile is active multiple
times, show a line for each activation, or otherwise, show the
information about multiple activations combined in one line, e.g. by
printing "DEVICE eth0,eth1". This patch, does the former.
We will now print a line for each active connection, to show
all the devices and activation states in multiple lines.
Yes, this may result in the same profile being printed multiple times.
That is a change in behavior, and inconvenient if you do something
like
for UUID in $(nmcli connection show | awk '{print$2}'); do ...
However, above is anyway wrong because it assumes that there are no
spaces in the connection name. The proper way to do this is like
for UUID in $(nmcli -g UUID connection show); do ...
In the latter case, whenever a user selects a subset of fields
(--fields, --get) which don't print information about active connections,
these multiple lines are combined. So, above still works as expected,
never returning duplicate UUIDs.
- if a user has no permissions to see a connection, we previously
would print "<invisible> $NAME". No longer do this but just print
the ID was it is reported by the active-connection. If the goal
of this was to prevent users from accidentally access the non-existing
connection by $NAME, then this was a bad solution, because a script
would instead try to access "<invisible> $NAME". This is now solved
better by hiding the active connection if the user selects "-g NAME".
- the --order option now sorts according to how the fields are shown.
For example, with --terse mode, it will evaluate type "802-11-wireless"
but with pretty mode it will consider "wifi". This may change the
ordering in which connections are shown. Also, for sorting the name,
we use g_utf8_collate() because it's unicode.
2018-04-25 10:00:40 +02:00
|
|
|
_NMC_GENERIC_INFO_TYPE_CON_SHOW_NUM,
|
|
|
|
|
|
2018-04-26 13:19:20 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_NAME = 0,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_UUID,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEVICES,
|
2019-10-27 14:31:09 +01:00
|
|
|
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_IP_IFACE,
|
2018-04-26 13:19:20 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_STATE,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEFAULT,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEFAULT6,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_SPEC_OBJECT,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_VPN,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DBUS_PATH,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_CON_PATH,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_ZONE,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_MASTER_PATH,
|
|
|
|
|
_NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_NUM,
|
|
|
|
|
|
2018-04-26 14:41:13 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_CON_VPN_TYPE = 0,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_VPN_USERNAME,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_VPN_GATEWAY,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_VPN_BANNER,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_VPN_VPN_STATE,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_CON_VPN_CFG,
|
|
|
|
|
_NMC_GENERIC_INFO_TYPE_CON_ACTIVE_VPN_NUM,
|
|
|
|
|
|
2018-04-26 20:28:02 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_DEVICE = 0,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_TYPE,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_STATE,
|
2018-07-03 20:57:28 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_IP4_CONNECTIVITY,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_IP6_CONNECTIVITY,
|
2018-04-26 20:28:02 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_DBUS_PATH,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_CONNECTION,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_CON_UUID,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_CON_PATH,
|
|
|
|
|
_NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_NUM,
|
|
|
|
|
|
2018-04-26 21:28:14 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_DEVICE = 0,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_TYPE,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_NM_TYPE,
|
2019-08-29 10:55:26 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_DBUS_PATH,
|
2018-04-26 21:28:14 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_VENDOR,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_PRODUCT,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_DRIVER,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_DRIVER_VERSION,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_FIRMWARE_VERSION,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_HWADDR,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_MTU,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_STATE,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_REASON,
|
2018-07-03 20:57:28 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IP4_CONNECTIVITY,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IP6_CONNECTIVITY,
|
2018-04-26 21:28:14 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_UDI,
|
2020-06-10 15:17:39 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_PATH,
|
2018-04-26 21:28:14 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IP_IFACE,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IS_SOFTWARE,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_NM_MANAGED,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_AUTOCONNECT,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_FIRMWARE_MISSING,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_NM_PLUGIN_MISSING,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_PHYS_PORT_ID,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_CONNECTION,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_CON_UUID,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_CON_PATH,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_METERED,
|
|
|
|
|
_NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_NUM,
|
|
|
|
|
|
2018-04-27 17:28:43 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CONNECTIONS_AVAILABLE_CONNECTION_PATHS = 0,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CONNECTIONS_AVAILABLE_CONNECTIONS,
|
|
|
|
|
_NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CONNECTIONS_NUM,
|
|
|
|
|
|
2018-04-29 19:13:57 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CAPABILITIES_CARRIER_DETECT = 0,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CAPABILITIES_SPEED,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CAPABILITIES_IS_SOFTWARE,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CAPABILITIES_SRIOV,
|
|
|
|
|
_NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CAPABILITIES_NUM,
|
|
|
|
|
|
2018-04-30 09:00:08 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIRED_PROPERTIES_CARRIER = 0,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIRED_PROPERTIES_S390_SUBCHANNELS,
|
|
|
|
|
_NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIRED_PROPERTIES_NUM,
|
|
|
|
|
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_WEP = 0,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_WPA,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_WPA2,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_TKIP,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_CCMP,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_AP,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_ADHOC,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_2GHZ,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_5GHZ,
|
2019-01-24 15:33:41 +01:00
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_MESH,
|
2019-08-19 15:51:31 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_IBSS_RSN,
|
2018-04-30 09:00:08 +02:00
|
|
|
_NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_NUM,
|
|
|
|
|
|
2019-10-10 10:45:36 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_UP = 0,
|
|
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_LOWER_UP,
|
2019-10-12 17:14:38 +02:00
|
|
|
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_CARRIER,
|
2019-10-10 10:45:36 +02:00
|
|
|
_NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_NUM,
|
|
|
|
|
|
2017-04-04 15:23:39 +02:00
|
|
|
} NmcGenericInfoType;
|
|
|
|
|
|
2018-03-29 12:31:33 +02:00
|
|
|
#define NMC_HANDLE_COLOR(color) \
|
2017-04-06 15:14:23 +02:00
|
|
|
G_STMT_START { \
|
2018-03-29 12:31:33 +02:00
|
|
|
if (get_type == NM_META_ACCESSOR_GET_TYPE_COLOR) \
|
|
|
|
|
return GINT_TO_POINTER (color); \
|
2017-04-06 15:14:23 +02:00
|
|
|
} G_STMT_END
|
|
|
|
|
|
2017-04-04 13:52:13 +02:00
|
|
|
struct _NmcMetaGenericInfo {
|
2017-06-07 14:43:58 +02:00
|
|
|
union {
|
|
|
|
|
NMObjBaseInst parent;
|
|
|
|
|
const NMMetaType *meta_type;
|
|
|
|
|
};
|
2017-04-04 15:23:39 +02:00
|
|
|
NmcGenericInfoType info_type;
|
2017-04-04 13:52:13 +02:00
|
|
|
const char *name;
|
2017-04-06 15:14:23 +02:00
|
|
|
const char *name_header;
|
2017-04-04 13:52:13 +02:00
|
|
|
const NmcMetaGenericInfo *const*nested;
|
2018-04-27 11:10:13 +02:00
|
|
|
|
|
|
|
|
#define NMC_META_GENERIC_INFO_GET_FCN_ARGS \
|
|
|
|
|
const NMMetaEnvironment *environment, \
|
|
|
|
|
gpointer environment_user_data, \
|
|
|
|
|
const NmcMetaGenericInfo *info, \
|
|
|
|
|
gpointer target, \
|
2018-04-30 13:01:20 +02:00
|
|
|
gpointer target_data, \
|
2018-04-27 11:10:13 +02:00
|
|
|
NMMetaAccessorGetType get_type, \
|
|
|
|
|
NMMetaAccessorGetFlags get_flags, \
|
|
|
|
|
NMMetaAccessorGetOutFlags *out_flags, \
|
|
|
|
|
gboolean *out_is_default, \
|
|
|
|
|
gpointer *out_to_free
|
|
|
|
|
|
|
|
|
|
gconstpointer (*get_fcn) (NMC_META_GENERIC_INFO_GET_FCN_ARGS);
|
2017-04-04 13:52:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define NMC_META_GENERIC(n, ...) \
|
|
|
|
|
(&((NmcMetaGenericInfo) { \
|
|
|
|
|
.meta_type = &nmc_meta_type_generic_info, \
|
2017-04-20 10:22:52 +02:00
|
|
|
.name = n, \
|
2017-04-04 13:52:13 +02:00
|
|
|
__VA_ARGS__ \
|
|
|
|
|
}))
|
|
|
|
|
|
2017-04-06 15:14:23 +02:00
|
|
|
#define NMC_META_GENERIC_WITH_NESTED(n, nest, ...) \
|
|
|
|
|
NMC_META_GENERIC (n, .nested = (nest), __VA_ARGS__)
|
2017-04-04 13:52:13 +02:00
|
|
|
|
2018-04-26 17:26:52 +02:00
|
|
|
#define NMC_META_GENERIC_GROUP(_group_name, _nested, _name_header) \
|
|
|
|
|
((const NMMetaAbstractInfo *const*) ((const NmcMetaGenericInfo *const[]) { \
|
|
|
|
|
NMC_META_GENERIC_WITH_NESTED (_group_name,_nested, .name_header = _name_header), \
|
|
|
|
|
NULL, \
|
|
|
|
|
}))
|
|
|
|
|
|
2018-04-27 11:26:47 +02:00
|
|
|
static inline const char *
|
|
|
|
|
nmc_meta_generic_get_str_i18n (const char *s, NMMetaAccessorGetType get_type)
|
|
|
|
|
{
|
|
|
|
|
if (!NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY,
|
|
|
|
|
NM_META_ACCESSOR_GET_TYPE_PARSABLE))
|
|
|
|
|
g_return_val_if_reached (NULL);
|
|
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
|
return NULL;
|
|
|
|
|
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
|
|
|
|
|
return gettext (s);
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-03 11:33:12 +02:00
|
|
|
static inline const char *
|
|
|
|
|
nmc_meta_generic_get_str_i18n_null (const char *s, NMMetaAccessorGetType get_type)
|
|
|
|
|
{
|
|
|
|
|
if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) {
|
|
|
|
|
/* in parsable mode, return NULL. That is useful if @s is a pretty string
|
|
|
|
|
* to describe a missing value (like "(unknown)"). We don't want to print
|
|
|
|
|
* that for parsable mode. */
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
return nmc_meta_generic_get_str_i18n (s, get_type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline const char *
|
|
|
|
|
nmc_meta_generic_get_unknown (NMMetaAccessorGetType get_type)
|
|
|
|
|
{
|
|
|
|
|
return nmc_meta_generic_get_str_i18n_null (N_("(unknown)"), get_type);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-27 11:26:47 +02:00
|
|
|
static inline const char *
|
|
|
|
|
nmc_meta_generic_get_bool (gboolean val, NMMetaAccessorGetType get_type)
|
|
|
|
|
{
|
|
|
|
|
return nmc_meta_generic_get_str_i18n (val ? N_("yes") : N_("no"), get_type);
|
2018-04-30 09:00:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline const char *
|
|
|
|
|
nmc_meta_generic_get_bool_onoff (gboolean val, NMMetaAccessorGetType get_type)
|
|
|
|
|
{
|
|
|
|
|
return nmc_meta_generic_get_str_i18n (val ? N_("on") : N_("off"), get_type);
|
2018-04-27 11:26:47 +02:00
|
|
|
}
|
|
|
|
|
|
2018-04-26 14:41:13 +02:00
|
|
|
typedef enum {
|
|
|
|
|
NMC_META_GENERIC_GET_ENUM_TYPE_PARENTHESES,
|
|
|
|
|
NMC_META_GENERIC_GET_ENUM_TYPE_DASH,
|
|
|
|
|
} NmcMetaGenericGetEnumType;
|
|
|
|
|
|
2018-04-27 11:26:47 +02:00
|
|
|
static inline char *
|
2018-04-26 14:41:13 +02:00
|
|
|
nmc_meta_generic_get_enum_with_detail (NmcMetaGenericGetEnumType get_enum_type, gint64 enum_val, const char *str_val, NMMetaAccessorGetType get_type)
|
2018-04-27 11:26:47 +02:00
|
|
|
{
|
|
|
|
|
if (!NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY,
|
|
|
|
|
NM_META_ACCESSOR_GET_TYPE_PARSABLE))
|
|
|
|
|
g_return_val_if_reached (NULL);
|
|
|
|
|
|
|
|
|
|
if (!str_val) {
|
|
|
|
|
/* Pass %NULL for only printing the numeric value. */
|
|
|
|
|
return g_strdup_printf ("%lld", (long long) enum_val);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-26 14:41:13 +02:00
|
|
|
switch (get_enum_type) {
|
|
|
|
|
case NMC_META_GENERIC_GET_ENUM_TYPE_PARENTHESES:
|
|
|
|
|
/* note that this function will always print "$NUM ($NICK)", also in PARSABLE
|
|
|
|
|
* mode. That might not be desired, but it's done for certain properties to preserve
|
|
|
|
|
* previous behavior. */
|
|
|
|
|
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
|
|
|
|
|
return g_strdup_printf (_("%lld (%s)"), (long long) enum_val, gettext (str_val));
|
|
|
|
|
return g_strdup_printf ("%lld (%s)", (long long) enum_val, str_val);
|
|
|
|
|
case NMC_META_GENERIC_GET_ENUM_TYPE_DASH:
|
|
|
|
|
/* note that this function will always print "$NUM ($NICK)", also in PARSABLE
|
|
|
|
|
* mode. That might not be desired, but it's done for certain properties to preserve
|
|
|
|
|
* previous behavior. */
|
|
|
|
|
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
|
|
|
|
|
return g_strdup_printf (_("%lld - %s"), (long long) enum_val, gettext (str_val));
|
|
|
|
|
return g_strdup_printf ("%lld - %s", (long long) enum_val, str_val);
|
|
|
|
|
}
|
|
|
|
|
g_return_val_if_reached (NULL);
|
2018-04-27 11:26:47 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-04 13:52:13 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2017-04-04 15:23:39 +02:00
|
|
|
gboolean nmc_print (const NmcConfig *nmc_config,
|
|
|
|
|
gpointer const *targets,
|
2018-04-30 13:01:20 +02:00
|
|
|
gpointer targets_data,
|
2017-04-04 15:23:39 +02:00
|
|
|
const char *header_name_no_l10n,
|
|
|
|
|
const NMMetaAbstractInfo *const*fields,
|
|
|
|
|
const char *fields_str,
|
|
|
|
|
GError **error);
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2010-02-25 09:52:30 -08:00
|
|
|
#endif /* NMC_UTILS_H */
|