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.
|
|
|
|
|
*
|
2018-03-28 23:08:12 +02:00
|
|
|
* Copyright 2010 - 2018 Red Hat, Inc.
|
2010-02-25 09:52:30 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef NMC_NMCLI_H
|
|
|
|
|
#define NMC_NMCLI_H
|
|
|
|
|
|
2017-03-09 13:02:20 +01:00
|
|
|
#include "nm-secret-agent-old.h"
|
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
|
|
|
#include "nm-meta-setting-desc.h"
|
2018-04-06 23:54:33 +02:00
|
|
|
|
|
|
|
|
struct _NMPolkitListener;
|
2014-10-30 11:25:55 +01:00
|
|
|
|
2017-04-11 15:48:04 +02:00
|
|
|
typedef char *(*NmcCompEntryFunc) (const char *, int);
|
|
|
|
|
|
2010-02-25 09:52:30 -08:00
|
|
|
/* nmcli exit codes */
|
|
|
|
|
typedef enum {
|
|
|
|
|
/* Indicates successful execution */
|
|
|
|
|
NMC_RESULT_SUCCESS = 0,
|
|
|
|
|
|
|
|
|
|
/* Unknown / unspecified error */
|
2010-03-24 13:42:47 +01:00
|
|
|
NMC_RESULT_ERROR_UNKNOWN = 1,
|
|
|
|
|
|
|
|
|
|
/* Wrong invocation of nmcli */
|
|
|
|
|
NMC_RESULT_ERROR_USER_INPUT = 2,
|
2010-02-25 09:52:30 -08:00
|
|
|
|
|
|
|
|
/* A timeout expired */
|
2010-03-24 13:42:47 +01:00
|
|
|
NMC_RESULT_ERROR_TIMEOUT_EXPIRED = 3,
|
2010-02-25 09:52:30 -08:00
|
|
|
|
|
|
|
|
/* Error in connection activation */
|
2010-03-24 13:42:47 +01:00
|
|
|
NMC_RESULT_ERROR_CON_ACTIVATION = 4,
|
2010-02-25 09:52:30 -08:00
|
|
|
|
|
|
|
|
/* Error in connection deactivation */
|
2010-03-24 13:42:47 +01:00
|
|
|
NMC_RESULT_ERROR_CON_DEACTIVATION = 5,
|
2010-02-25 09:52:30 -08:00
|
|
|
|
|
|
|
|
/* Error in device disconnect */
|
2011-02-10 14:21:18 +01:00
|
|
|
NMC_RESULT_ERROR_DEV_DISCONNECT = 6,
|
|
|
|
|
|
2012-01-10 16:18:27 +01:00
|
|
|
/* Error in connection deletion */
|
|
|
|
|
NMC_RESULT_ERROR_CON_DEL = 7,
|
|
|
|
|
|
2011-02-10 14:21:18 +01:00
|
|
|
/* NetworkManager is not running */
|
2012-01-10 16:18:27 +01:00
|
|
|
NMC_RESULT_ERROR_NM_NOT_RUNNING = 8,
|
2011-02-16 17:36:50 +01:00
|
|
|
|
2016-04-18 18:50:56 +02:00
|
|
|
/* No more used, keep to preserve API */
|
2013-11-21 09:19:18 -05:00
|
|
|
NMC_RESULT_ERROR_VERSIONS_MISMATCH = 9,
|
|
|
|
|
|
|
|
|
|
/* Connection/Device/AP not found */
|
2016-07-12 15:43:56 +02:00
|
|
|
NMC_RESULT_ERROR_NOT_FOUND = 10,
|
|
|
|
|
|
|
|
|
|
/* --complete-args signals a file name may follow */
|
|
|
|
|
NMC_RESULT_COMPLETE_FILE = 65,
|
2010-02-25 09:52:30 -08:00
|
|
|
} NMCResultCode;
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
|
NMC_PRINT_TERSE = 0,
|
2010-03-24 13:42:47 +01:00
|
|
|
NMC_PRINT_NORMAL = 1,
|
|
|
|
|
NMC_PRINT_PRETTY = 2
|
2010-02-25 09:52:30 -08:00
|
|
|
} NMCPrintOutput;
|
|
|
|
|
|
2010-03-18 15:39:15 +01:00
|
|
|
/* === Output fields === */
|
2017-03-31 12:12:21 +02:00
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
|
NMC_OF_FLAG_FIELD_NAMES = 0x00000001, /* Print field names instead of values */
|
|
|
|
|
NMC_OF_FLAG_SECTION_PREFIX = 0x00000002, /* Use the first value as section prefix for the other field names - just in multiline */
|
|
|
|
|
NMC_OF_FLAG_MAIN_HEADER_ADD = 0x00000004, /* Print main header in addition to values/field names */
|
|
|
|
|
NMC_OF_FLAG_MAIN_HEADER_ONLY = 0x00000008, /* Print main header only */
|
|
|
|
|
} NmcOfFlags;
|
2012-01-03 15:07:17 +01:00
|
|
|
|
2017-05-12 14:04:04 +02:00
|
|
|
extern const NMMetaType nmc_meta_type_generic_info;
|
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
|
|
|
|
|
|
|
|
typedef struct _NmcOutputField NmcOutputField;
|
|
|
|
|
typedef struct _NmcMetaGenericInfo NmcMetaGenericInfo;
|
|
|
|
|
|
|
|
|
|
struct _NmcOutputField {
|
|
|
|
|
const NMMetaAbstractInfo *info;
|
2013-12-10 12:00:53 +01:00
|
|
|
int width; /* Width in screen columns */
|
|
|
|
|
void *value; /* Value of current field - char* or char** (NULL-terminated array) */
|
|
|
|
|
gboolean value_is_array; /* Whether value is char** instead of char* */
|
|
|
|
|
gboolean free_value; /* Whether to free the value */
|
2017-03-31 12:12:21 +02:00
|
|
|
NmcOfFlags flags; /* Flags - whether and how to print values/field names/headers */
|
2018-03-29 12:31:33 +02:00
|
|
|
NMMetaColor color; /* Use this color to print value */
|
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
|
|
|
};
|
2010-03-18 15:39:15 +01:00
|
|
|
|
2017-03-30 12:23:26 +02:00
|
|
|
typedef struct _NmcConfig {
|
2017-03-30 12:45:41 +02:00
|
|
|
NMCPrintOutput print_output; /* Output mode */
|
2018-03-29 12:25:14 +02:00
|
|
|
gboolean use_colors; /* Whether to use colors for output: option '--color' */
|
2017-04-06 15:26:23 +02:00
|
|
|
bool multiline_output; /* Multiline output instead of default tabular */
|
|
|
|
|
bool escape_values; /* Whether to escape ':' and '\' in terse tabular mode */
|
|
|
|
|
bool in_editor; /* Whether running the editor - nmcli con edit' */
|
|
|
|
|
bool show_secrets; /* Whether to display secrets (both input and output): option '--show-secrets' */
|
2018-02-27 16:28:28 +01:00
|
|
|
bool overview; /* Overview mode (hide default values) */
|
2018-03-29 12:31:33 +02:00
|
|
|
const char *palette[_NM_META_COLOR_NUM]; /* Color palette */
|
2017-03-30 12:23:26 +02:00
|
|
|
} NmcConfig;
|
|
|
|
|
|
2017-03-30 13:34:35 +02:00
|
|
|
typedef struct _NmcOutputData {
|
|
|
|
|
GPtrArray *output_data; /* GPtrArray of arrays of NmcOutputField structs - accumulates data for output */
|
|
|
|
|
} NmcOutputData;
|
|
|
|
|
|
2010-02-25 09:52:30 -08:00
|
|
|
/* NmCli - main structure */
|
|
|
|
|
typedef struct _NmCli {
|
2014-05-19 13:44:02 -04:00
|
|
|
NMClient *client; /* Pointer to NMClient of libnm */
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2010-03-18 15:39:15 +01:00
|
|
|
NMCResultCode return_value; /* Return code of nmcli */
|
|
|
|
|
GString *return_text; /* Reason text */
|
2017-05-15 17:23:51 +02:00
|
|
|
pid_t pager_pid; /* PID of a pager, if one was spawned */
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2010-03-18 15:39:15 +01:00
|
|
|
int timeout; /* Operation timeout */
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2014-11-20 11:53:19 -05:00
|
|
|
NMSecretAgentOld *secret_agent; /* Secret agent */
|
2014-10-14 15:53:34 +02:00
|
|
|
GHashTable *pwds_hash; /* Hash table with passwords in passwd-file */
|
2018-04-06 23:54:33 +02:00
|
|
|
struct _NMPolkitListener *pk_listener; /* polkit agent listener */
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2015-03-27 12:39:17 +01:00
|
|
|
int should_wait; /* Semaphore indicating whether nmcli should not end or not yet */
|
2010-07-29 16:16:20 +02:00
|
|
|
gboolean nowait_flag; /* '--nowait' option; used for passing to callbacks */
|
2010-04-06 16:22:01 +02:00
|
|
|
gboolean mode_specified; /* Whether tabular/multiline mode was specified via '--mode' option */
|
2017-03-30 12:45:41 +02:00
|
|
|
union {
|
|
|
|
|
const NmcConfig nmc_config;
|
|
|
|
|
NmcConfig nmc_config_mutable;
|
|
|
|
|
};
|
2010-03-18 15:39:15 +01:00
|
|
|
char *required_fields; /* Required fields in output: '--fields' option */
|
2012-11-21 13:10:31 +01:00
|
|
|
gboolean ask; /* Ask for missing parameters: option '--ask' */
|
2016-06-13 18:59:31 +02:00
|
|
|
gboolean complete; /* Autocomplete the command line */
|
2013-04-05 23:42:56 +02:00
|
|
|
gboolean editor_status_line; /* Whether to display status line in connection editor */
|
2013-07-23 14:25:52 +02:00
|
|
|
gboolean editor_save_confirmation; /* Whether to ask for confirmation on saving connections with 'autoconnect=yes' */
|
2018-03-29 12:11:07 +02:00
|
|
|
|
|
|
|
|
char *palette_buffer; /* Buffer with sequences for terminal-colors.d(5)-based coloring. */
|
2010-02-25 09:52:30 -08:00
|
|
|
} NmCli;
|
|
|
|
|
|
2016-04-30 15:02:53 +02:00
|
|
|
extern NmCli nm_cli;
|
|
|
|
|
|
2012-07-25 13:57:45 +02:00
|
|
|
/* Error quark for GError domain */
|
|
|
|
|
#define NMCLI_ERROR (nmcli_error_quark ())
|
|
|
|
|
GQuark nmcli_error_quark (void);
|
|
|
|
|
|
2017-04-06 19:39:36 +02:00
|
|
|
extern GMainLoop *loop;
|
|
|
|
|
|
2014-06-16 08:30:22 +02:00
|
|
|
gboolean nmc_seen_sigint (void);
|
|
|
|
|
void nmc_clear_sigint (void);
|
2014-06-20 14:50:18 +02:00
|
|
|
void nmc_set_sigquit_internal (void);
|
2016-09-02 16:16:34 +02:00
|
|
|
void nmc_exit (void);
|
2014-06-20 14:50:18 +02:00
|
|
|
|
2017-03-30 14:56:19 +02:00
|
|
|
void nmc_empty_output_fields (NmcOutputData *output_data);
|
|
|
|
|
|
|
|
|
|
#define NMC_OUTPUT_DATA_DEFINE_SCOPED(out) \
|
2017-03-31 13:21:47 +02:00
|
|
|
gs_unref_array GArray *out##_indices = NULL; \
|
2017-03-30 14:56:19 +02:00
|
|
|
nm_auto (nmc_empty_output_fields) NmcOutputData out = { \
|
|
|
|
|
.output_data = g_ptr_array_new_full (20, g_free), \
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-25 09:52:30 -08:00
|
|
|
#endif /* NMC_NMCLI_H */
|