2010-02-25 09:52:30 -08:00
|
|
|
/* nmcli - command-line tool to control NetworkManager
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*
|
2017-05-15 17:23:51 +02:00
|
|
|
* Copyright 2010 - 2017 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 === */
|
2017-03-30 16:09:46 +02:00
|
|
|
int next_arg (NmCli *nmc, int *argc, char ***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);
|
2013-01-16 12:26:45 +01:00
|
|
|
gboolean nmc_parse_args (nmc_arg_t *arg_arr, gboolean last, int *argc, char ***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);
|
2017-05-15 17:23:51 +02:00
|
|
|
void nmc_terminal_spawn_pager (const NmcConfig *nmc_config);
|
|
|
|
|
gboolean nmc_term_use_colors (NmcColorOption color_option);
|
2017-04-04 15:12:00 +02:00
|
|
|
const char *nmc_term_color_sequence (NMMetaTermColor color);
|
|
|
|
|
const char *nmc_term_format_sequence (NMMetaTermFormat format);
|
|
|
|
|
NMMetaTermColor nmc_term_color_parse_string (const char *str, GError **error);
|
|
|
|
|
char *nmc_colorize (NmcColorOption color_option, NMMetaTermColor color, NMMetaTermFormat format, const char * fmt, ...) _nm_printf (4, 5);
|
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);
|
2013-01-18 15:21:00 +01:00
|
|
|
char **nmc_strsplit_set (const char *str, const char *delimiter, int max_tokens);
|
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);
|
2017-04-04 15:12:00 +02:00
|
|
|
void set_val_color_all (NmcOutputField fields_array[], NMMetaTermColor color);
|
|
|
|
|
void set_val_color_fmt_all (NmcOutputField fields_array[], NMMetaTermFormat format);
|
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,
|
|
|
|
|
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,
|
|
|
|
|
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;
|
|
|
|
|
extern NmCli *const nmc_meta_environment_arg;
|
|
|
|
|
|
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,
|
|
|
|
|
|
2017-04-04 15:23:39 +02:00
|
|
|
} NmcGenericInfoType;
|
|
|
|
|
|
2017-04-06 15:14:23 +02:00
|
|
|
#define NMC_HANDLE_TERMFORMAT(color) \
|
|
|
|
|
G_STMT_START { \
|
|
|
|
|
if (get_type == NM_META_ACCESSOR_GET_TYPE_TERMFORMAT) \
|
|
|
|
|
return nm_meta_termformat_pack ((color), NM_META_TERM_FORMAT_NORMAL); \
|
|
|
|
|
} 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;
|
2017-04-04 15:07:06 +02:00
|
|
|
gconstpointer (*get_fcn) (const NMMetaEnvironment *environment,
|
|
|
|
|
gpointer environment_user_data,
|
|
|
|
|
const NmcMetaGenericInfo *info,
|
|
|
|
|
gpointer target,
|
|
|
|
|
NMMetaAccessorGetType get_type,
|
|
|
|
|
NMMetaAccessorGetFlags get_flags,
|
2017-04-06 15:14:23 +02:00
|
|
|
NMMetaAccessorGetOutFlags *out_flags,
|
2017-04-04 15:07:06 +02:00
|
|
|
gpointer *out_to_free);
|
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
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2017-04-04 15:23:39 +02:00
|
|
|
gboolean nmc_print (const NmcConfig *nmc_config,
|
|
|
|
|
gpointer const *targets,
|
|
|
|
|
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 */
|