nmcli.h 5.99 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* 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.
 *
17
 * (C) Copyright 2010 - 2014 Red Hat, Inc.
18 19 20 21 22
 */

#ifndef NMC_NMCLI_H
#define NMC_NMCLI_H

23
#include <NetworkManager.h>
24 25 26 27 28 29 30

/* nmcli exit codes */
typedef enum {
	/* Indicates successful execution */
	NMC_RESULT_SUCCESS = 0,

	/* Unknown / unspecified error */
31 32 33 34
	NMC_RESULT_ERROR_UNKNOWN = 1,

	/* Wrong invocation of nmcli */
	NMC_RESULT_ERROR_USER_INPUT = 2,
35 36

	/* A timeout expired */
37
	NMC_RESULT_ERROR_TIMEOUT_EXPIRED = 3,
38 39

	/* Error in connection activation */
40
	NMC_RESULT_ERROR_CON_ACTIVATION = 4,
41 42

	/* Error in connection deactivation */
43
	NMC_RESULT_ERROR_CON_DEACTIVATION = 5,
44 45

	/* Error in device disconnect */
46 47
	NMC_RESULT_ERROR_DEV_DISCONNECT = 6,

48 49 50
	/* Error in connection deletion */
	NMC_RESULT_ERROR_CON_DEL = 7,

51
	/* NetworkManager is not running */
52
	NMC_RESULT_ERROR_NM_NOT_RUNNING = 8,
53 54

	/* nmcli and NetworkManager versions mismatch */
55 56 57 58
	NMC_RESULT_ERROR_VERSIONS_MISMATCH = 9,

	/* Connection/Device/AP not found */
	NMC_RESULT_ERROR_NOT_FOUND = 10
59 60 61 62
} NMCResultCode;

typedef enum {
	NMC_PRINT_TERSE = 0,
63 64
	NMC_PRINT_NORMAL = 1,
	NMC_PRINT_PRETTY = 2
65 66
} NMCPrintOutput;

67
/* === Output fields === */
68
/* Flags for NmcOutputField */
69 70 71 72
#define NMC_OF_FLAG_FIELD_NAMES        0x00000001   /* Print field names instead of values */
#define NMC_OF_FLAG_SECTION_PREFIX     0x00000002   /* Use the first value as section prefix for the other field names - just in multiline */
#define NMC_OF_FLAG_MAIN_HEADER_ADD    0x00000004   /* Print main header in addition to values/field names */
#define NMC_OF_FLAG_MAIN_HEADER_ONLY   0x00000008   /* Print main header only */
73

74 75 76 77 78 79 80 81 82
typedef struct _NmcOutputField {
	const char *name;               /* Field's name */
	const char *name_l10n;          /* Field's name for translation */
	int width;                      /* Width in screen columns */
	struct _NmcOutputField *group;  /* Points to an array with available section field names if this is a section (group) field */
	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 */
	guint32 flags;                  /* Flags - whether and how to print values/field names/headers */
83 84 85 86 87 88 89 90
} NmcOutputField;

typedef struct {
	GArray *indices;      /* Array of field indices to the array of allowed fields */
	char *header_name;    /* Name of the output */
	int indent;           /* Indent by this number of spaces */
} NmcPrintFields;

91 92 93 94 95 96 97 98 99 100 101 102
typedef enum {
	NMC_TERM_COLOR_NORMAL  = 0,
	NMC_TERM_COLOR_BLACK   = 1,
	NMC_TERM_COLOR_RED     = 2,
	NMC_TERM_COLOR_GREEN   = 3,
	NMC_TERM_COLOR_YELLOW  = 4,
	NMC_TERM_COLOR_BLUE    = 5,
	NMC_TERM_COLOR_MAGENTA = 6,
	NMC_TERM_COLOR_CYAN    = 7,
	NMC_TERM_COLOR_WHITE   = 8
} NmcTermColor;

103 104
/* NmCli - main structure */
typedef struct _NmCli {
Dan Winship's avatar
Dan Winship committed
105
	NMClient *client;                                 /* Pointer to NMClient of libnm */
106
	NMClient *(*get_client) (struct _NmCli *nmc);     /* Pointer to function for creating NMClient */
107

108 109
	NMCResultCode return_value;                       /* Return code of nmcli */
	GString *return_text;                             /* Reason text */
110

111
	int timeout;                                      /* Operation timeout */
112

113
	NMRemoteSettings *system_settings;                /* System settings */
114 115
	gboolean system_settings_running;                 /* Is system settings service running? */
	GSList *system_connections;                       /* List of system connections */
116

117
	gboolean should_wait;                             /* Indication that nmcli should not end yet */
118
	gboolean nowait_flag;                             /* '--nowait' option; used for passing to callbacks */
119 120
	NMCPrintOutput print_output;                      /* Output mode */
	gboolean multiline_output;                        /* Multiline output instead of default tabular */
121
	gboolean mode_specified;                          /* Whether tabular/multiline mode was specified via '--mode' option */
122 123
	gboolean escape_values;                           /* Whether to escape ':' and '\' in terse tabular mode */
	char *required_fields;                            /* Required fields in output: '--fields' option */
124
	GPtrArray *output_data;                           /* GPtrArray of arrays of NmcOutputField structs - accumulates data for output */
125
	NmcPrintFields print_fields;                      /* Structure with field indices to print */
126
	gboolean nocheck_ver;                             /* Don't check nmcli and NM versions: option '--nocheck' */
127
	gboolean ask;                                     /* Ask for missing parameters: option '--ask' */
128
	gboolean in_editor;                               /* Whether running the editor - nmcli con edit' */
129
	gboolean editor_status_line;                      /* Whether to display status line in connection editor */
130
	gboolean editor_save_confirmation;                /* Whether to ask for confirmation on saving connections with 'autoconnect=yes' */
131
	NmcTermColor editor_prompt_color;                 /* Color of prompt in connection editor */
132 133
} NmCli;

134 135 136 137
/* Error quark for GError domain */
#define NMCLI_ERROR (nmcli_error_quark ())
GQuark nmcli_error_quark (void);

138 139
gboolean nmc_seen_sigint (void);
void     nmc_clear_sigint (void);
140 141
void     nmc_set_sigquit_internal (void);

142

143
#endif /* NMC_NMCLI_H */