Blame clients/cli/nmcli.h

Packit Service a1bd4f
/* SPDX-License-Identifier: GPL-2.0+ */
Packit 5756e2
/*
Packit 5756e2
 * Copyright (C) 2010 - 2018 Red Hat, Inc.
Packit 5756e2
 */
Packit 5756e2
Packit 5756e2
#ifndef NMC_NMCLI_H
Packit 5756e2
#define NMC_NMCLI_H
Packit 5756e2
Packit 5756e2
#include "nm-secret-agent-simple.h"
Packit 5756e2
#include "nm-meta-setting-desc.h"
Packit 5756e2
Packit 5756e2
struct _NMPolkitListener;
Packit 5756e2
Packit Service a1bd4f
typedef char *(*NmcCompEntryFunc)(const char *, int);
Packit 5756e2
Packit 5756e2
/* nmcli exit codes */
Packit 5756e2
typedef enum {
Packit Service a1bd4f
    /* Indicates successful execution */
Packit Service a1bd4f
    NMC_RESULT_SUCCESS = 0,
Packit 5756e2
Packit Service a1bd4f
    /* Unknown / unspecified error */
Packit Service a1bd4f
    NMC_RESULT_ERROR_UNKNOWN = 1,
Packit 5756e2
Packit Service a1bd4f
    /* Wrong invocation of nmcli */
Packit Service a1bd4f
    NMC_RESULT_ERROR_USER_INPUT = 2,
Packit 5756e2
Packit Service a1bd4f
    /* A timeout expired */
Packit Service a1bd4f
    NMC_RESULT_ERROR_TIMEOUT_EXPIRED = 3,
Packit 5756e2
Packit Service a1bd4f
    /* Error in connection activation */
Packit Service a1bd4f
    NMC_RESULT_ERROR_CON_ACTIVATION = 4,
Packit 5756e2
Packit Service a1bd4f
    /* Error in connection deactivation */
Packit Service a1bd4f
    NMC_RESULT_ERROR_CON_DEACTIVATION = 5,
Packit 5756e2
Packit Service a1bd4f
    /* Error in device disconnect */
Packit Service a1bd4f
    NMC_RESULT_ERROR_DEV_DISCONNECT = 6,
Packit 5756e2
Packit Service a1bd4f
    /* Error in connection deletion */
Packit Service a1bd4f
    NMC_RESULT_ERROR_CON_DEL = 7,
Packit 5756e2
Packit Service a1bd4f
    /* NetworkManager is not running */
Packit Service a1bd4f
    NMC_RESULT_ERROR_NM_NOT_RUNNING = 8,
Packit 5756e2
Packit Service a1bd4f
    /* No more used, keep to preserve API */
Packit Service a1bd4f
    NMC_RESULT_ERROR_VERSIONS_MISMATCH = 9,
Packit 5756e2
Packit Service a1bd4f
    /* Connection/Device/AP not found */
Packit Service a1bd4f
    NMC_RESULT_ERROR_NOT_FOUND = 10,
Packit 5756e2
Packit Service a1bd4f
    /* --complete-args signals a file name may follow */
Packit Service a1bd4f
    NMC_RESULT_COMPLETE_FILE = 65,
Packit 5756e2
} NMCResultCode;
Packit 5756e2
Packit Service a1bd4f
typedef enum { NMC_PRINT_TERSE = 0, NMC_PRINT_NORMAL = 1, NMC_PRINT_PRETTY = 2 } NMCPrintOutput;
Packit 5756e2
Packit 5756e2
static inline NMMetaAccessorGetType
Packit Service a1bd4f
nmc_print_output_to_accessor_get_type(NMCPrintOutput print_output)
Packit 5756e2
{
Packit Service a1bd4f
    return NM_IN_SET(print_output, NMC_PRINT_NORMAL, NMC_PRINT_PRETTY)
Packit Service a1bd4f
               ? NM_META_ACCESSOR_GET_TYPE_PRETTY
Packit Service a1bd4f
               : NM_META_ACCESSOR_GET_TYPE_PARSABLE;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/* === Output fields === */
Packit 5756e2
Packit 5756e2
typedef enum {
Packit Service a1bd4f
    NMC_OF_FLAG_FIELD_NAMES = 0x00000001, /* Print field names instead of values */
Packit Service a1bd4f
    NMC_OF_FLAG_SECTION_PREFIX =
Packit Service a1bd4f
        0x00000002, /* Use the first value as section prefix for the other field names - just in multiline */
Packit Service a1bd4f
    NMC_OF_FLAG_MAIN_HEADER_ADD =
Packit Service a1bd4f
        0x00000004, /* Print main header in addition to values/field names */
Packit Service a1bd4f
    NMC_OF_FLAG_MAIN_HEADER_ONLY = 0x00000008, /* Print main header only */
Packit 5756e2
} NmcOfFlags;
Packit 5756e2
Packit Service a1bd4f
typedef struct {
Packit Service a1bd4f
    const char *ansi_seq[_NM_META_COLOR_NUM];
Packit Service a1bd4f
} NmcColorPalette;
Packit Service a1bd4f
Packit 5756e2
extern const NMMetaType nmc_meta_type_generic_info;
Packit 5756e2
Packit Service a1bd4f
typedef struct _NmcOutputField     NmcOutputField;
Packit 5756e2
typedef struct _NmcMetaGenericInfo NmcMetaGenericInfo;
Packit 5756e2
Packit 5756e2
struct _NmcOutputField {
Packit Service a1bd4f
    const NMMetaAbstractInfo *info;
Packit Service a1bd4f
    int                       width; /* Width in screen columns */
Packit Service a1bd4f
    void *      value; /* Value of current field - char* or char** (NULL-terminated array) */
Packit Service a1bd4f
    gboolean    value_is_array; /* Whether value is char** instead of char* */
Packit Service a1bd4f
    gboolean    free_value;     /* Whether to free the value */
Packit Service a1bd4f
    NmcOfFlags  flags;          /* Flags - whether and how to print values/field names/headers */
Packit Service a1bd4f
    NMMetaColor color;          /* Use this color to print value */
Packit 5756e2
};
Packit 5756e2
Packit 5756e2
typedef struct _NmcConfig {
Packit Service a1bd4f
    NMCPrintOutput print_output;     /* Output mode */
Packit Service a1bd4f
    bool           use_colors;       /* Whether to use colors for output: option '--color' */
Packit Service a1bd4f
    bool           multiline_output; /* Multiline output instead of default tabular */
Packit Service a1bd4f
    bool           escape_values;    /* Whether to escape ':' and '\' in terse tabular mode */
Packit Service a1bd4f
    bool           in_editor;        /* Whether running the editor - nmcli con edit' */
Packit Service a1bd4f
    bool
Packit Service a1bd4f
        show_secrets; /* Whether to display secrets (both input and output): option '--show-secrets' */
Packit Service a1bd4f
    bool            overview; /* Overview mode (hide default values) */
Packit Service a1bd4f
    NmcColorPalette palette;
Packit 5756e2
} NmcConfig;
Packit 5756e2
Packit 5756e2
typedef struct {
Packit Service a1bd4f
    pid_t pid;
Packit 5756e2
} NmcPagerData;
Packit 5756e2
Packit 5756e2
typedef struct _NmcOutputData {
Packit Service a1bd4f
    GPtrArray *
Packit Service a1bd4f
        output_data; /* GPtrArray of arrays of NmcOutputField structs - accumulates data for output */
Packit 5756e2
} NmcOutputData;
Packit 5756e2
Packit 5756e2
/* NmCli - main structure */
Packit 5756e2
typedef struct _NmCli {
Packit Service a1bd4f
    NMClient *client; /* Pointer to NMClient of libnm */
Packit Service a1bd4f
Packit Service a1bd4f
    NMCResultCode return_value; /* Return code of nmcli */
Packit Service a1bd4f
    GString *     return_text;  /* Reason text */
Packit Service a1bd4f
Packit Service a1bd4f
    NmcPagerData pager_data;
Packit Service a1bd4f
Packit Service a1bd4f
    int timeout; /* Operation timeout */
Packit Service a1bd4f
Packit Service a1bd4f
    NMSecretAgentSimple *     secret_agent; /* Secret agent */
Packit Service a1bd4f
    GHashTable *              pwds_hash;    /* Hash table with passwords in passwd-file */
Packit Service a1bd4f
    struct _NMPolkitListener *pk_listener;  /* polkit agent listener */
Packit Service a1bd4f
Packit Service a1bd4f
    int      should_wait;    /* Semaphore indicating whether nmcli should not end or not yet */
Packit Service a1bd4f
    gboolean nowait_flag;    /* '--nowait' option; used for passing to callbacks */
Packit Service a1bd4f
    gboolean mode_specified; /* Whether tabular/multiline mode was specified via '--mode' option */
Packit Service a1bd4f
    union {
Packit Service a1bd4f
        const NmcConfig nmc_config;
Packit Service a1bd4f
        NmcConfig       nmc_config_mutable;
Packit Service a1bd4f
    };
Packit Service a1bd4f
    char *   required_fields;    /* Required fields in output: '--fields' option */
Packit Service a1bd4f
    gboolean ask;                /* Ask for missing parameters: option '--ask' */
Packit Service a1bd4f
    gboolean complete;           /* Autocomplete the command line */
Packit Service a1bd4f
    gboolean editor_status_line; /* Whether to display status line in connection editor */
Packit Service a1bd4f
    gboolean
Packit Service a1bd4f
        editor_save_confirmation; /* Whether to ask for confirmation on saving connections with 'autoconnect=yes' */
Packit Service a1bd4f
Packit Service a1bd4f
    char *palette_buffer; /* Buffer with sequences for terminal-colors.d(5)-based coloring. */
Packit 5756e2
} NmCli;
Packit 5756e2
Packit 5756e2
extern const NmCli *const nm_cli_global_readline;
Packit 5756e2
Packit 5756e2
/* Error quark for GError domain */
Packit Service a1bd4f
#define NMCLI_ERROR (nmcli_error_quark())
Packit Service a1bd4f
GQuark nmcli_error_quark(void);
Packit 5756e2
Packit 5756e2
extern GMainLoop *loop;
Packit 5756e2
Packit Service a1bd4f
gboolean nmc_seen_sigint(void);
Packit Service a1bd4f
void     nmc_clear_sigint(void);
Packit Service a1bd4f
void     nmc_set_sigquit_internal(void);
Packit Service a1bd4f
void     nmc_exit(void);
Packit 5756e2
Packit Service a1bd4f
void nm_cli_spawn_pager(const NmcConfig *nmc_config, NmcPagerData *pager_data);
Packit 5756e2
Packit Service a1bd4f
void nmc_empty_output_fields(NmcOutputData *output_data);
Packit 5756e2
Packit Service a1bd4f
#define NMC_OUTPUT_DATA_DEFINE_SCOPED(out)                               \
Packit Service a1bd4f
    gs_unref_array GArray *                        out##_indices = NULL; \
Packit Service a1bd4f
    nm_auto(nmc_empty_output_fields) NmcOutputData out           = {     \
Packit Service a1bd4f
        .output_data = g_ptr_array_new_full(20, g_free),       \
Packit Service a1bd4f
    }
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit 5756e2
struct _NMCCommand;
Packit 5756e2
Packit 5756e2
typedef struct _NMCCommand {
Packit Service a1bd4f
    const char *cmd;
Packit Service a1bd4f
    void (*func)(const struct _NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv);
Packit Service a1bd4f
    void (*usage)(void);
Packit Service a1bd4f
    bool needs_client;
Packit Service a1bd4f
    bool needs_nm_running;
Packit 5756e2
} NMCCommand;
Packit 5756e2
Packit Service a1bd4f
void nmc_command_func_agent(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv);
Packit Service a1bd4f
void nmc_command_func_general(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv);
Packit Service a1bd4f
void
Packit Service a1bd4f
nmc_command_func_networking(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv);
Packit Service a1bd4f
void nmc_command_func_radio(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv);
Packit Service a1bd4f
void nmc_command_func_monitor(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv);
Packit Service a1bd4f
void
Packit Service a1bd4f
nmc_command_func_overview(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv);
Packit Service a1bd4f
void
Packit Service a1bd4f
nmc_command_func_connection(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv);
Packit Service a1bd4f
void nmc_command_func_device(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv);
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit 5756e2
#endif /* NMC_NMCLI_H */