Blame src/nmcli/utils.h

Packit Service dff8e4
/* SPDX-License-Identifier: GPL-2.0-or-later */
Packit Service dff8e4
/*
Packit Service dff8e4
 * Copyright (C) 2010 - 2018 Red Hat, Inc.
Packit Service dff8e4
 */
Packit Service dff8e4
Packit Service dff8e4
#ifndef NMC_UTILS_H
Packit Service dff8e4
#define NMC_UTILS_H
Packit Service dff8e4
Packit Service dff8e4
#include "nmcli.h"
Packit Service dff8e4
Packit Service dff8e4
/* === Types === */
Packit Service dff8e4
Packit Service dff8e4
typedef struct {
Packit Service dff8e4
    const char * name;
Packit Service dff8e4
    gboolean     has_value;
Packit Service dff8e4
    const char **value;
Packit Service dff8e4
    gboolean     mandatory;
Packit Service dff8e4
    gboolean     found;
Packit Service dff8e4
} nmc_arg_t;
Packit Service dff8e4
Packit Service dff8e4
/* === Functions === */
Packit Service dff8e4
int      next_arg(NmCli *nmc, int *argc, const char *const **argv, ...);
Packit Service dff8e4
gboolean nmc_arg_is_help(const char *arg);
Packit Service dff8e4
gboolean nmc_arg_is_option(const char *arg, const char *opt_name);
Packit Service dff8e4
gboolean nmc_parse_args(nmc_arg_t *         arg_arr,
Packit Service dff8e4
                        gboolean            last,
Packit Service dff8e4
                        int *               argc,
Packit Service dff8e4
                        const char *const **argv,
Packit Service dff8e4
                        GError **           error);
Packit Service dff8e4
char *   ssid_to_hex(const char *str, gsize len);
Packit Service dff8e4
void     nmc_terminal_erase_line(void);
Packit Service dff8e4
void     nmc_terminal_show_progress(const char *str);
Packit Service dff8e4
pid_t    nmc_terminal_spawn_pager(const NmcConfig *nmc_config);
Packit Service dff8e4
char *   nmc_colorize(const NmcConfig *nmc_config, NMMetaColor color, const char *fmt, ...)
Packit Service dff8e4
    _nm_printf(3, 4);
Packit Service dff8e4
void        nmc_filter_out_colors_inplace(char *str);
Packit Service dff8e4
char *      nmc_filter_out_colors(const char *str);
Packit Service dff8e4
char *      nmc_get_user_input(const char *ask_str);
Packit Service dff8e4
int         nmc_string_to_arg_array(const char *line,
Packit Service dff8e4
                                    const char *delim,
Packit Service dff8e4
                                    gboolean    unquote,
Packit Service dff8e4
                                    char ***    argv,
Packit Service dff8e4
                                    int *       argc);
Packit Service dff8e4
const char *nmc_string_is_valid(const char *input, const char **allowed, GError **error);
Packit Service dff8e4
char *      nmc_util_strv_for_display(const char *const *strv, gboolean brackets);
Packit Service dff8e4
int         nmc_string_screen_width(const char *start, const char *end);
Packit Service dff8e4
void        set_val_str(NmcOutputField fields_array[], guint32 index, char *value);
Packit Service dff8e4
void        set_val_strc(NmcOutputField fields_array[], guint32 index, const char *value);
Packit Service dff8e4
void        set_val_arr(NmcOutputField fields_array[], guint32 index, char **value);
Packit Service dff8e4
void        set_val_arrc(NmcOutputField fields_array[], guint32 index, const char **value);
Packit Service dff8e4
void        set_val_color_all(NmcOutputField fields_array[], NMMetaColor color);
Packit Service dff8e4
void        nmc_free_output_field_values(NmcOutputField fields_array[]);
Packit Service dff8e4
Packit Service dff8e4
GArray *        parse_output_fields(const char *                     fields_str,
Packit Service dff8e4
                                    const NMMetaAbstractInfo *const *fields_array,
Packit Service dff8e4
                                    gboolean                         parse_groups,
Packit Service dff8e4
                                    GPtrArray **                     group_fields,
Packit Service dff8e4
                                    GError **                        error);
Packit Service dff8e4
NmcOutputField *nmc_dup_fields_array(const NMMetaAbstractInfo *const *fields, NmcOfFlags flags);
Packit Service dff8e4
void            nmc_empty_output_fields(NmcOutputData *output_data);
Packit Service dff8e4
void            print_required_fields(const NmcConfig *     nmc_config,
Packit Service dff8e4
                                      NmcPagerData *        pager_data,
Packit Service dff8e4
                                      NmcOfFlags            of_flags,
Packit Service dff8e4
                                      const GArray *        indices,
Packit Service dff8e4
                                      const char *          header_name,
Packit Service dff8e4
                                      int                   indent,
Packit Service dff8e4
                                      const NmcOutputField *field_values);
Packit Service dff8e4
void            print_data_prepare_width(GPtrArray *output_data);
Packit Service dff8e4
void            print_data(const NmcConfig *    nmc_config,
Packit Service dff8e4
                           NmcPagerData *       pager_data,
Packit Service dff8e4
                           const GArray *       indices,
Packit Service dff8e4
                           const char *         header_name,
Packit Service dff8e4
                           int                  indent,
Packit Service dff8e4
                           const NmcOutputData *out);
Packit Service dff8e4
Packit Service dff8e4
/*****************************************************************************/
Packit Service dff8e4
Packit Service dff8e4
extern const NMMetaEnvironment *const nmc_meta_environment;
Packit Service dff8e4
extern const NmCli *const             nmc_meta_environment_arg;
Packit Service dff8e4
Packit Service dff8e4
typedef enum {
Packit Service dff8e4
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_RUNNING = 0,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_VERSION,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_STATE,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_STARTUP,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_CONNECTIVITY,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_NETWORKING,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIFI_HW,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIFI,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WWAN_HW,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WWAN,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIMAX_HW,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIMAX,
Packit Service dff8e4
    _NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_NUM,
Packit Service dff8e4
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_PERMISSION = 0,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_VALUE,
Packit Service dff8e4
    _NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_NUM,
Packit Service dff8e4
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_LEVEL = 0,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_DOMAINS,
Packit Service dff8e4
    _NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_NUM,
Packit Service dff8e4
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ADDRESS = 0,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_IP4_CONFIG_GATEWAY,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ROUTE,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DNS,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DOMAIN,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_IP4_CONFIG_WINS,
Packit Service dff8e4
    _NMC_GENERIC_INFO_TYPE_IP4_CONFIG_NUM,
Packit Service dff8e4
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ADDRESS = 0,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_IP6_CONFIG_GATEWAY,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ROUTE,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_IP6_CONFIG_DNS,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_IP6_CONFIG_DOMAIN,
Packit Service dff8e4
    _NMC_GENERIC_INFO_TYPE_IP6_CONFIG_NUM,
Packit Service dff8e4
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DHCP_CONFIG_OPTION = 0,
Packit Service dff8e4
    _NMC_GENERIC_INFO_TYPE_DHCP_CONFIG_NUM,
Packit Service dff8e4
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_SHOW_NAME = 0,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_SHOW_UUID,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_SHOW_TYPE,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP_REAL,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_SHOW_AUTOCONNECT,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_SHOW_AUTOCONNECT_PRIORITY,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_SHOW_READONLY,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_SHOW_DBUS_PATH,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_SHOW_ACTIVE,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_SHOW_DEVICE,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_SHOW_STATE,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_SHOW_ACTIVE_PATH,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_SHOW_SLAVE,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_SHOW_FILENAME,
Packit Service dff8e4
    _NMC_GENERIC_INFO_TYPE_CON_SHOW_NUM,
Packit Service dff8e4
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_NAME = 0,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_UUID,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEVICES,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_IP_IFACE,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_STATE,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEFAULT,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEFAULT6,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_SPEC_OBJECT,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_VPN,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DBUS_PATH,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_CON_PATH,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_ZONE,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_MASTER_PATH,
Packit Service dff8e4
    _NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_NUM,
Packit Service dff8e4
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_VPN_TYPE = 0,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_VPN_USERNAME,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_VPN_GATEWAY,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_VPN_BANNER,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_VPN_VPN_STATE,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_CON_VPN_CFG,
Packit Service dff8e4
    _NMC_GENERIC_INFO_TYPE_CON_ACTIVE_VPN_NUM,
Packit Service dff8e4
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_DEVICE = 0,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_TYPE,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_STATE,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_IP4_CONNECTIVITY,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_IP6_CONNECTIVITY,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_DBUS_PATH,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_CONNECTION,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_CON_UUID,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_CON_PATH,
Packit Service dff8e4
    _NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_NUM,
Packit Service dff8e4
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_DEVICE = 0,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_TYPE,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_NM_TYPE,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_DBUS_PATH,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_VENDOR,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_PRODUCT,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_DRIVER,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_DRIVER_VERSION,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_FIRMWARE_VERSION,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_HWADDR,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_MTU,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_STATE,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_REASON,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IP4_CONNECTIVITY,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IP6_CONNECTIVITY,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_UDI,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_PATH,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IP_IFACE,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IS_SOFTWARE,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_NM_MANAGED,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_AUTOCONNECT,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_FIRMWARE_MISSING,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_NM_PLUGIN_MISSING,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_PHYS_PORT_ID,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_CONNECTION,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_CON_UUID,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_CON_PATH,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_METERED,
Packit Service dff8e4
    _NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_NUM,
Packit Service dff8e4
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CONNECTIONS_AVAILABLE_CONNECTION_PATHS = 0,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CONNECTIONS_AVAILABLE_CONNECTIONS,
Packit Service dff8e4
    _NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CONNECTIONS_NUM,
Packit Service dff8e4
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CAPABILITIES_CARRIER_DETECT = 0,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CAPABILITIES_SPEED,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CAPABILITIES_IS_SOFTWARE,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CAPABILITIES_SRIOV,
Packit Service dff8e4
    _NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CAPABILITIES_NUM,
Packit Service dff8e4
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIRED_PROPERTIES_CARRIER = 0,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIRED_PROPERTIES_S390_SUBCHANNELS,
Packit Service dff8e4
    _NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIRED_PROPERTIES_NUM,
Packit Service dff8e4
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_WEP = 0,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_WPA,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_WPA2,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_TKIP,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_CCMP,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_AP,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_ADHOC,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_2GHZ,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_5GHZ,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_MESH,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_IBSS_RSN,
Packit Service dff8e4
    _NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_NUM,
Packit Service dff8e4
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_UP = 0,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_LOWER_UP,
Packit Service dff8e4
    NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_CARRIER,
Packit Service dff8e4
    _NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_NUM,
Packit Service dff8e4
Packit Service dff8e4
} NmcGenericInfoType;
Packit Service dff8e4
Packit Service dff8e4
#define NMC_HANDLE_COLOR(color)                          \
Packit Service dff8e4
    G_STMT_START                                         \
Packit Service dff8e4
    {                                                    \
Packit Service dff8e4
        if (get_type == NM_META_ACCESSOR_GET_TYPE_COLOR) \
Packit Service dff8e4
            return GINT_TO_POINTER(color);               \
Packit Service dff8e4
    }                                                    \
Packit Service dff8e4
    G_STMT_END
Packit Service dff8e4
Packit Service dff8e4
struct _NmcMetaGenericInfo {
Packit Service dff8e4
    union {
Packit Service dff8e4
        NMObjBaseInst     parent;
Packit Service dff8e4
        const NMMetaType *meta_type;
Packit Service dff8e4
    };
Packit Service dff8e4
    NmcGenericInfoType               info_type;
Packit Service dff8e4
    const char *                     name;
Packit Service dff8e4
    const char *                     name_header;
Packit Service dff8e4
    const NmcMetaGenericInfo *const *nested;
Packit Service dff8e4
Packit Service dff8e4
#define NMC_META_GENERIC_INFO_GET_FCN_ARGS                                     \
Packit Service dff8e4
    const NMMetaEnvironment *environment, gpointer environment_user_data,      \
Packit Service dff8e4
        const NmcMetaGenericInfo *info, gpointer target, gpointer target_data, \
Packit Service dff8e4
        NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags,      \
Packit Service dff8e4
        NMMetaAccessorGetOutFlags *out_flags, gboolean *out_is_default, gpointer *out_to_free
Packit Service dff8e4
Packit Service dff8e4
    gconstpointer (*get_fcn)(NMC_META_GENERIC_INFO_GET_FCN_ARGS);
Packit Service dff8e4
};
Packit Service dff8e4
Packit Service dff8e4
#define NMC_META_GENERIC(n, ...) \
Packit Service dff8e4
    (&((NmcMetaGenericInfo){.meta_type = &nmc_meta_type_generic_info, .name = n, __VA_ARGS__}))
Packit Service dff8e4
Packit Service dff8e4
#define NMC_META_GENERIC_WITH_NESTED(n, nest, ...) \
Packit Service dff8e4
    NMC_META_GENERIC(n, .nested = (nest), __VA_ARGS__)
Packit Service dff8e4
Packit Service dff8e4
#define NMC_META_GENERIC_GROUP(_group_name, _nested, _name_header)                       \
Packit Service dff8e4
    ((const NMMetaAbstractInfo *const *) ((const NmcMetaGenericInfo *const[]){           \
Packit Service dff8e4
        NMC_META_GENERIC_WITH_NESTED(_group_name, _nested, .name_header = _name_header), \
Packit Service dff8e4
        NULL,                                                                            \
Packit Service dff8e4
    }))
Packit Service dff8e4
Packit Service dff8e4
static inline const char *
Packit Service dff8e4
nmc_meta_generic_get_str_i18n(const char *s, NMMetaAccessorGetType get_type)
Packit Service dff8e4
{
Packit Service dff8e4
    if (!NM_IN_SET(get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY, NM_META_ACCESSOR_GET_TYPE_PARSABLE))
Packit Service dff8e4
        g_return_val_if_reached(NULL);
Packit Service dff8e4
Packit Service dff8e4
    if (!s)
Packit Service dff8e4
        return NULL;
Packit Service dff8e4
    if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
Packit Service dff8e4
        return gettext(s);
Packit Service dff8e4
    return s;
Packit Service dff8e4
}
Packit Service dff8e4
Packit Service dff8e4
static inline const char *
Packit Service dff8e4
nmc_meta_generic_get_str_i18n_null(const char *s, NMMetaAccessorGetType get_type)
Packit Service dff8e4
{
Packit Service dff8e4
    if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) {
Packit Service dff8e4
        /* in parsable mode, return NULL. That is useful if @s is a pretty string
Packit Service dff8e4
         * to describe a missing value (like "(unknown)"). We don't want to print
Packit Service dff8e4
         * that for parsable mode. */
Packit Service dff8e4
        return NULL;
Packit Service dff8e4
    }
Packit Service dff8e4
    return nmc_meta_generic_get_str_i18n(s, get_type);
Packit Service dff8e4
}
Packit Service dff8e4
Packit Service dff8e4
static inline const char *
Packit Service dff8e4
nmc_meta_generic_get_unknown(NMMetaAccessorGetType get_type)
Packit Service dff8e4
{
Packit Service dff8e4
    return nmc_meta_generic_get_str_i18n_null(N_("(unknown)"), get_type);
Packit Service dff8e4
}
Packit Service dff8e4
Packit Service dff8e4
static inline const char *
Packit Service dff8e4
nmc_meta_generic_get_bool(gboolean val, NMMetaAccessorGetType get_type)
Packit Service dff8e4
{
Packit Service dff8e4
    return nmc_meta_generic_get_str_i18n(val ? N_("yes") : N_("no"), get_type);
Packit Service dff8e4
}
Packit Service dff8e4
Packit Service dff8e4
static inline const char *
Packit Service dff8e4
nmc_meta_generic_get_bool_onoff(gboolean val, NMMetaAccessorGetType get_type)
Packit Service dff8e4
{
Packit Service dff8e4
    return nmc_meta_generic_get_str_i18n(val ? N_("on") : N_("off"), get_type);
Packit Service dff8e4
}
Packit Service dff8e4
Packit Service dff8e4
typedef enum {
Packit Service dff8e4
    NMC_META_GENERIC_GET_ENUM_TYPE_PARENTHESES,
Packit Service dff8e4
    NMC_META_GENERIC_GET_ENUM_TYPE_DASH,
Packit Service dff8e4
} NmcMetaGenericGetEnumType;
Packit Service dff8e4
Packit Service dff8e4
static inline char *
Packit Service dff8e4
nmc_meta_generic_get_enum_with_detail(NmcMetaGenericGetEnumType get_enum_type,
Packit Service dff8e4
                                      gint64                    enum_val,
Packit Service dff8e4
                                      const char *              str_val,
Packit Service dff8e4
                                      NMMetaAccessorGetType     get_type)
Packit Service dff8e4
{
Packit Service dff8e4
    if (!NM_IN_SET(get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY, NM_META_ACCESSOR_GET_TYPE_PARSABLE))
Packit Service dff8e4
        g_return_val_if_reached(NULL);
Packit Service dff8e4
Packit Service dff8e4
    if (!str_val) {
Packit Service dff8e4
        /* Pass %NULL for only printing the numeric value. */
Packit Service dff8e4
        return g_strdup_printf("%lld", (long long) enum_val);
Packit Service dff8e4
    }
Packit Service dff8e4
Packit Service dff8e4
    switch (get_enum_type) {
Packit Service dff8e4
    case NMC_META_GENERIC_GET_ENUM_TYPE_PARENTHESES:
Packit Service dff8e4
        /* note that this function will always print "$NUM ($NICK)", also in PARSABLE
Packit Service dff8e4
         * mode. That might not be desired, but it's done for certain properties to preserve
Packit Service dff8e4
         * previous behavior. */
Packit Service dff8e4
        if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
Packit Service dff8e4
            return g_strdup_printf(_("%lld (%s)"), (long long) enum_val, gettext(str_val));
Packit Service dff8e4
        return g_strdup_printf("%lld (%s)", (long long) enum_val, str_val);
Packit Service dff8e4
    case NMC_META_GENERIC_GET_ENUM_TYPE_DASH:
Packit Service dff8e4
        /* note that this function will always print "$NUM ($NICK)", also in PARSABLE
Packit Service dff8e4
         * mode. That might not be desired, but it's done for certain properties to preserve
Packit Service dff8e4
         * previous behavior. */
Packit Service dff8e4
        if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
Packit Service dff8e4
            return g_strdup_printf(_("%lld - %s"), (long long) enum_val, gettext(str_val));
Packit Service dff8e4
        return g_strdup_printf("%lld - %s", (long long) enum_val, str_val);
Packit Service dff8e4
    }
Packit Service dff8e4
    g_return_val_if_reached(NULL);
Packit Service dff8e4
}
Packit Service dff8e4
Packit Service dff8e4
/*****************************************************************************/
Packit Service dff8e4
Packit Service dff8e4
gboolean nmc_print(const NmcConfig *                nmc_config,
Packit Service dff8e4
                   gpointer const *                 targets,
Packit Service dff8e4
                   gpointer                         targets_data,
Packit Service dff8e4
                   const char *                     header_name_no_l10n,
Packit Service dff8e4
                   const NMMetaAbstractInfo *const *fields,
Packit Service dff8e4
                   const char *                     fields_str,
Packit Service dff8e4
                   GError **                        error);
Packit Service dff8e4
Packit Service dff8e4
/*****************************************************************************/
Packit Service dff8e4
Packit Service dff8e4
#endif /* NMC_UTILS_H */