mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-02 00:40:11 +01:00
merge: branch 'lr/nmcli-colors'
https://github.com/NetworkManager/NetworkManager/pull/105
This commit is contained in:
commit
60b6cbff40
73 changed files with 976 additions and 559 deletions
|
|
@ -3514,6 +3514,7 @@ clients_cli_nmcli_CPPFLAGS = \
|
|||
-I$(srcdir)/clients/cli \
|
||||
$(clients_cppflags) \
|
||||
$(SANITIZER_EXEC_CFLAGS) \
|
||||
-DSYSCONFDIR=\"$(sysconfdir)\" \
|
||||
-DG_LOG_DOMAIN=\""nmcli"\" \
|
||||
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_CLIENT \
|
||||
-DNMCLI_LOCALEDIR=\"$(datadir)/locale\"
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright 2012 - 2017 Red Hat, Inc.
|
||||
* Copyright 2012 - 2018 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include "nm-default.h"
|
||||
|
|
@ -119,7 +119,7 @@ _metagen_ip4_config_get_fcn (const NMMetaEnvironment *environment,
|
|||
|
||||
nm_assert (info->info_type < _NMC_GENERIC_INFO_TYPE_IP4_CONFIG_NUM);
|
||||
|
||||
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
|
||||
NMC_HANDLE_COLOR (NM_META_COLOR_NONE);
|
||||
NM_SET_OUT (out_is_default, TRUE);
|
||||
|
||||
switch (info->info_type) {
|
||||
|
|
@ -202,7 +202,7 @@ _metagen_ip6_config_get_fcn (const NMMetaEnvironment *environment,
|
|||
|
||||
nm_assert (info->info_type < _NMC_GENERIC_INFO_TYPE_IP6_CONFIG_NUM);
|
||||
|
||||
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
|
||||
NMC_HANDLE_COLOR (NM_META_COLOR_NONE);
|
||||
NM_SET_OUT (out_is_default, TRUE);
|
||||
|
||||
switch (info->info_type) {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright 2010 - 2017 Red Hat, Inc.
|
||||
* Copyright 2010 - 2018 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include "nm-default.h"
|
||||
|
|
@ -811,17 +811,17 @@ found:
|
|||
return found;
|
||||
}
|
||||
|
||||
void
|
||||
nmc_active_connection_state_to_color (NMActiveConnectionState state, NMMetaTermColor *color)
|
||||
NMMetaColor
|
||||
nmc_active_connection_state_to_color (NMActiveConnectionState state)
|
||||
{
|
||||
*color = NM_META_TERM_COLOR_NORMAL;
|
||||
|
||||
if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATING)
|
||||
*color = NM_META_TERM_COLOR_YELLOW;
|
||||
return NM_META_COLOR_CONNECTION_ACTIVATING;
|
||||
else if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED)
|
||||
*color = NM_META_TERM_COLOR_GREEN;
|
||||
return NM_META_COLOR_CONNECTION_ACTIVATED;
|
||||
else if (state > NM_ACTIVE_CONNECTION_STATE_ACTIVATED)
|
||||
*color = NM_META_TERM_COLOR_RED;
|
||||
return NM_META_COLOR_CONNECTION_DISCONNECTING;
|
||||
else
|
||||
return NM_META_COLOR_CONNECTION_UNKNOWN;
|
||||
}
|
||||
|
||||
/* Essentially a version of nm_setting_connection_get_connection_type() that
|
||||
|
|
@ -864,7 +864,7 @@ fill_output_connection (NMConnection *connection, NMClient *client, NMCPrintOutp
|
|||
const char *ac_state = NULL;
|
||||
NMActiveConnectionState ac_state_int = NM_ACTIVE_CONNECTION_STATE_UNKNOWN;
|
||||
char *ac_dev = NULL;
|
||||
NMMetaTermColor color;
|
||||
NMMetaColor color;
|
||||
|
||||
s_con = nm_connection_get_setting_connection (connection);
|
||||
g_assert (s_con);
|
||||
|
|
@ -893,7 +893,7 @@ fill_output_connection (NMConnection *connection, NMClient *client, NMCPrintOutp
|
|||
arr = nmc_dup_fields_array ((const NMMetaAbstractInfo *const*) nmc_fields_con_show, 0);
|
||||
|
||||
/* Show active connections in color */
|
||||
nmc_active_connection_state_to_color (ac_state_int, &color);
|
||||
color = nmc_active_connection_state_to_color (ac_state_int);
|
||||
set_val_color_all (arr, color);
|
||||
|
||||
set_val_strc (arr, 0, nm_setting_connection_get_id (s_con));
|
||||
|
|
@ -944,7 +944,7 @@ fill_output_connection_for_invisible (NMActiveConnection *ac, NMCPrintOutput pri
|
|||
set_val_strc (arr, 12, ac_path);
|
||||
set_val_strc (arr, 13, NULL);
|
||||
|
||||
set_val_color_fmt_all (arr, NM_META_TERM_FORMAT_DIM);
|
||||
set_val_color_all (arr, NM_META_COLOR_CONNECTION_INVISIBLE);
|
||||
|
||||
g_ptr_array_add (output_data, arr);
|
||||
}
|
||||
|
|
@ -1275,7 +1275,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc)
|
|||
arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_SECTION_PREFIX);
|
||||
set_val_strc (arr, 0, nmc_fields_con_active_details_groups[5]->name);
|
||||
set_val_str (arr, 1, type_str);
|
||||
set_val_strc (arr, 2, username ? username : get_vpn_data_item (con, VPN_DATA_ITEM_USERNAME));
|
||||
set_val_strc (arr, 2, username ?: get_vpn_data_item (con, VPN_DATA_ITEM_USERNAME));
|
||||
set_val_strc (arr, 3, get_vpn_data_item (con, VPN_DATA_ITEM_GATEWAY));
|
||||
set_val_str (arr, 4, banner_str);
|
||||
set_val_str (arr, 5, vpn_state_str);
|
||||
|
|
@ -4248,7 +4248,7 @@ nmc_read_connection_properties (NmCli *nmc,
|
|||
return FALSE;
|
||||
|
||||
if (!*argc && nmc->complete)
|
||||
complete_property (setting, strv[1], value ? value : "", connection);
|
||||
complete_property (setting, strv[1], value ?: "", connection);
|
||||
|
||||
if (!set_property (connection, setting_name, strv[1], value, modifier, error))
|
||||
return FALSE;
|
||||
|
|
@ -4329,7 +4329,7 @@ nmc_read_connection_properties (NmCli *nmc,
|
|||
return FALSE;
|
||||
|
||||
if (!*argc && nmc->complete)
|
||||
complete_option (chosen, value ? value : "", connection);
|
||||
complete_option (chosen, value ?: "", connection);
|
||||
|
||||
if (!set_option (nmc, connection, chosen, value, error))
|
||||
return FALSE;
|
||||
|
|
@ -4945,15 +4945,7 @@ gen_nmcli_cmds_submenu (const char *text, int state)
|
|||
static char *
|
||||
gen_cmd_nmcli (const char *text, int state)
|
||||
{
|
||||
const char *words[] = { "status-line", "save-confirmation", "show-secrets", "prompt-color", NULL };
|
||||
return nmc_rl_gen_func_basic (text, state, words);
|
||||
}
|
||||
|
||||
static char *
|
||||
gen_cmd_nmcli_prompt_color (const char *text, int state)
|
||||
{
|
||||
const char *words[] = { "normal", "black", "red", "green", "yellow",
|
||||
"blue", "magenta", "cyan", "white", NULL };
|
||||
const char *words[] = { "status-line", "save-confirmation", "show-secrets", NULL };
|
||||
return nmc_rl_gen_func_basic (text, state, words);
|
||||
}
|
||||
|
||||
|
|
@ -5269,8 +5261,6 @@ get_gen_func_cmd_nmcli (const char *str)
|
|||
return gen_func_bool_values;
|
||||
if (matches (str, "show-secrets"))
|
||||
return gen_func_bool_values;
|
||||
if (matches (str, "prompt-color"))
|
||||
return gen_cmd_nmcli_prompt_color;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -5884,7 +5874,7 @@ _split_cmd (const char *cmd, char **out_arg0, const char **out_argr)
|
|||
|
||||
if (!cmd)
|
||||
return;
|
||||
while (NM_IN_SET (cmd[0], ' ', '\t'))
|
||||
while (nm_utils_is_separator (cmd[0]))
|
||||
cmd++;
|
||||
if (!cmd[0])
|
||||
return;
|
||||
|
|
@ -5893,7 +5883,7 @@ _split_cmd (const char *cmd, char **out_arg0, const char **out_argr)
|
|||
arg0 = g_strndup (cmd, l);
|
||||
cmd += l;
|
||||
if (cmd[0]) {
|
||||
while (NM_IN_SET (cmd[0], ' ', '\t'))
|
||||
while (nm_utils_is_separator (cmd[0]))
|
||||
cmd++;
|
||||
if (cmd[0])
|
||||
argr = cmd;
|
||||
|
|
@ -6480,8 +6470,7 @@ property_edit_submenu (NmCli *nmc,
|
|||
/* Set global variable for use in TAB completion */
|
||||
nmc_tab_completion.property = prop_name;
|
||||
|
||||
prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NM_META_TERM_FORMAT_NORMAL,
|
||||
"nmcli %s.%s> ",
|
||||
prompt = nmc_colorize (&nmc->nmc_config, NM_META_COLOR_PROMPT, "nmcli %s.%s> ",
|
||||
nm_setting_get_name (curr_setting), prop_name);
|
||||
|
||||
while (cmd_property_loop) {
|
||||
|
|
@ -6811,14 +6800,13 @@ typedef struct {
|
|||
} NmcEditorMenuContext;
|
||||
|
||||
static void
|
||||
menu_switch_to_level0 (NmcColorOption color_option,
|
||||
menu_switch_to_level0 (const NmcConfig *nmc_config,
|
||||
NmcEditorMenuContext *menu_ctx,
|
||||
const char *prompt,
|
||||
NMMetaTermColor prompt_color)
|
||||
const char *prompt)
|
||||
{
|
||||
menu_ctx->level = 0;
|
||||
g_free (menu_ctx->main_prompt);
|
||||
menu_ctx->main_prompt = nmc_colorize (color_option, prompt_color, NM_META_TERM_FORMAT_NORMAL, "%s", prompt);
|
||||
menu_ctx->main_prompt = nmc_colorize (nmc_config, NM_META_COLOR_PROMPT, "%s", prompt);
|
||||
menu_ctx->curr_setting = NULL;
|
||||
g_strfreev (menu_ctx->valid_props);
|
||||
menu_ctx->valid_props = NULL;
|
||||
|
|
@ -6827,16 +6815,14 @@ menu_switch_to_level0 (NmcColorOption color_option,
|
|||
}
|
||||
|
||||
static void
|
||||
menu_switch_to_level1 (NmcColorOption color_option,
|
||||
menu_switch_to_level1 (const NmcConfig *nmc_config,
|
||||
NmcEditorMenuContext *menu_ctx,
|
||||
NMSetting *setting,
|
||||
const char *setting_name,
|
||||
NMMetaTermColor prompt_color)
|
||||
const char *setting_name)
|
||||
{
|
||||
menu_ctx->level = 1;
|
||||
g_free (menu_ctx->main_prompt);
|
||||
menu_ctx->main_prompt = nmc_colorize (color_option, prompt_color, NM_META_TERM_FORMAT_NORMAL,
|
||||
"nmcli %s> ", setting_name);
|
||||
menu_ctx->main_prompt = nmc_colorize (nmc_config, NM_META_COLOR_PROMPT, "nmcli %s> ", setting_name);
|
||||
menu_ctx->curr_setting = setting;
|
||||
g_strfreev (menu_ctx->valid_props);
|
||||
menu_ctx->valid_props = nmc_setting_get_valid_properties (menu_ctx->curr_setting);
|
||||
|
|
@ -6874,8 +6860,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
valid_settings_str = get_valid_options_string (valid_settings_main, valid_settings_slave);
|
||||
g_print (_("You may edit the following settings: %s\n"), valid_settings_str);
|
||||
|
||||
menu_ctx.main_prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NM_META_TERM_FORMAT_NORMAL,
|
||||
BASE_PROMPT);
|
||||
menu_ctx.main_prompt = nmc_colorize (&nmc->nmc_config, NM_META_COLOR_PROMPT, BASE_PROMPT);
|
||||
|
||||
/* Get remote connection */
|
||||
con_tmp = nm_client_get_connection_by_uuid (nmc->client,
|
||||
|
|
@ -7014,7 +6999,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
/* in top level - no setting selected yet */
|
||||
const char *setting_name;
|
||||
NMSetting *setting;
|
||||
const char *user_arg = cmd_arg_s ? cmd_arg_s : cmd_arg_p;
|
||||
const char *user_arg = cmd_arg_s ?: cmd_arg_p;
|
||||
|
||||
setting_name = ask_check_setting (user_arg,
|
||||
valid_settings_main,
|
||||
|
|
@ -7051,7 +7036,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
nmc_tab_completion.setting = setting;
|
||||
|
||||
/* Switch to level 1 */
|
||||
menu_switch_to_level1 (nmc->nmc_config.use_colors, &menu_ctx, setting, setting_name, nmc->editor_prompt_color);
|
||||
menu_switch_to_level1 (&nmc->nmc_config, &menu_ctx, setting, setting_name);
|
||||
|
||||
if (!cmd_arg_s) {
|
||||
g_print (_("You may edit the following properties: %s\n"), menu_ctx.valid_props_str);
|
||||
|
|
@ -7106,7 +7091,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
|
||||
/* cmd_arg_s != NULL means argument is "setting.property" */
|
||||
descr_all = !cmd_arg_s && !menu_ctx.curr_setting;
|
||||
user_s = descr_all ? cmd_arg_p : cmd_arg_s ? cmd_arg_s : NULL;
|
||||
user_s = descr_all ? cmd_arg_p : cmd_arg_s;
|
||||
if (user_s) {
|
||||
ss = is_setting_valid (connection,
|
||||
valid_settings_main,
|
||||
|
|
@ -7133,7 +7118,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
connection_remove_setting (connection, ss);
|
||||
if (ss == menu_ctx.curr_setting) {
|
||||
/* If we removed the setting we are in, go up */
|
||||
menu_switch_to_level0 (nmc->nmc_config.use_colors, &menu_ctx, BASE_PROMPT, nmc->editor_prompt_color);
|
||||
menu_switch_to_level0 (&nmc->nmc_config, &menu_ctx, BASE_PROMPT);
|
||||
nmc_tab_completion.setting = NULL; /* for TAB completion */
|
||||
}
|
||||
} else {
|
||||
|
|
@ -7161,7 +7146,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
/* coverity[copy_paste_error] - suppress Coverity COPY_PASTE_ERROR defect */
|
||||
if (ss == menu_ctx.curr_setting) {
|
||||
/* If we removed the setting we are in, go up */
|
||||
menu_switch_to_level0 (nmc->nmc_config.use_colors, &menu_ctx, BASE_PROMPT, nmc->editor_prompt_color);
|
||||
menu_switch_to_level0 (&nmc->nmc_config, &menu_ctx, BASE_PROMPT);
|
||||
nmc_tab_completion.setting = NULL; /* for TAB completion */
|
||||
}
|
||||
} else
|
||||
|
|
@ -7199,7 +7184,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
|
||||
/* cmd_arg_s != NULL means argument is "setting.property" */
|
||||
descr_all = !cmd_arg_s && !menu_ctx.curr_setting;
|
||||
user_s = descr_all ? cmd_arg_p : cmd_arg_s ? cmd_arg_s : NULL;
|
||||
user_s = descr_all ? cmd_arg_p : cmd_arg_s;
|
||||
if (user_s) {
|
||||
ss = is_setting_valid (connection,
|
||||
valid_settings_main,
|
||||
|
|
@ -7265,7 +7250,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
|
||||
/* cmd_arg_s != NULL means argument is "setting.property" */
|
||||
whole_setting = !cmd_arg_s && !menu_ctx.curr_setting;
|
||||
user_s = whole_setting ? cmd_arg_p : cmd_arg_s ? cmd_arg_s : NULL;
|
||||
user_s = whole_setting ? cmd_arg_p : cmd_arg_s;
|
||||
if (user_s) {
|
||||
const char *s_name;
|
||||
|
||||
|
|
@ -7517,7 +7502,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
case NMC_EDITOR_MAIN_CMD_BACK:
|
||||
/* Go back (up) an the menu */
|
||||
if (menu_ctx.level == 1) {
|
||||
menu_switch_to_level0 (nmc->nmc_config.use_colors, &menu_ctx, BASE_PROMPT, nmc->editor_prompt_color);
|
||||
menu_switch_to_level0 (&nmc->nmc_config, &menu_ctx, BASE_PROMPT);
|
||||
nmc_tab_completion.setting = NULL; /* for TAB completion */
|
||||
}
|
||||
break;
|
||||
|
|
@ -7553,37 +7538,18 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
} else
|
||||
nmc->nmc_config_mutable.show_secrets = bb;
|
||||
} else if (cmd_arg_p && matches (cmd_arg_p, "prompt-color")) {
|
||||
GError *tmp_err = NULL;
|
||||
NMMetaTermColor color;
|
||||
color = nmc_term_color_parse_string (cmd_arg_v ? g_strstrip (cmd_arg_v) : " ", &tmp_err);
|
||||
if (tmp_err) {
|
||||
g_print (_("Error: bad color: %s\n"), tmp_err->message);
|
||||
g_clear_error (&tmp_err);
|
||||
} else {
|
||||
nmc->editor_prompt_color = color;
|
||||
nm_clear_g_free (&menu_ctx.main_prompt);
|
||||
if (menu_ctx.level == 0) {
|
||||
menu_ctx.main_prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NM_META_TERM_FORMAT_NORMAL,
|
||||
BASE_PROMPT);
|
||||
} else {
|
||||
menu_ctx.main_prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NM_META_TERM_FORMAT_NORMAL,
|
||||
"nmcli %s> ",
|
||||
nm_setting_get_name (menu_ctx.curr_setting));
|
||||
}
|
||||
}
|
||||
g_debug ("Ignoring erroneous --prompt-color argument. Use terminal-colors.d(5) to set the prompt color.\n");
|
||||
} else if (!cmd_arg_p) {
|
||||
g_print (_("Current nmcli configuration:\n"));
|
||||
g_print ("status-line: %s\n"
|
||||
"save-confirmation: %s\n"
|
||||
"show-secrets: %s\n"
|
||||
"prompt-color: %d\n",
|
||||
"show-secrets: %s\n",
|
||||
nmc->editor_status_line ? "yes" : "no",
|
||||
nmc->editor_save_confirmation ? "yes" : "no",
|
||||
nmc->nmc_config.show_secrets ? "yes" : "no",
|
||||
nmc->editor_prompt_color);
|
||||
nmc->nmc_config.show_secrets ? "yes" : "no");
|
||||
} else
|
||||
g_print (_("Invalid configuration option '%s'; allowed [%s]\n"),
|
||||
cmd_arg_v ? cmd_arg_v : "", "status-line, save-confirmation, show-secrets, prompt-color");
|
||||
cmd_arg_v ?: "", "status-line, save-confirmation, show-secrets");
|
||||
|
||||
break;
|
||||
|
||||
|
|
@ -7654,7 +7620,7 @@ editor_init_new_connection (NmCli *nmc, NMConnection *connection, const char *sl
|
|||
|
||||
g_object_set (s_con,
|
||||
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
|
||||
NM_SETTING_CONNECTION_MASTER, dev_ifname ? dev_ifname : "eth0",
|
||||
NM_SETTING_CONNECTION_MASTER, dev_ifname ?: "eth0",
|
||||
NM_SETTING_CONNECTION_SLAVE_TYPE, slave_type,
|
||||
NULL);
|
||||
} else {
|
||||
|
|
@ -7675,7 +7641,7 @@ editor_init_new_connection (NmCli *nmc, NMConnection *connection, const char *sl
|
|||
const char *dev_ifname = get_ethernet_device_name (nmc);
|
||||
|
||||
g_object_set (NM_SETTING_VLAN (base_setting),
|
||||
NM_SETTING_VLAN_PARENT, dev_ifname ? dev_ifname : "eth0",
|
||||
NM_SETTING_VLAN_PARENT, dev_ifname ?: "eth0",
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* (C) Copyright 2010 - 2014 Red Hat, Inc.
|
||||
* (C) Copyright 2010 - 2018 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef NMC_CONNECTIONS_H
|
||||
|
|
@ -33,7 +33,7 @@ nmc_read_connection_properties (NmCli *nmc,
|
|||
char ***argv,
|
||||
GError **error);
|
||||
|
||||
void nmc_active_connection_state_to_color (NMActiveConnectionState state, NMMetaTermColor *color);
|
||||
NMMetaColor nmc_active_connection_state_to_color (NMActiveConnectionState state);
|
||||
|
||||
extern const NmcMetaGenericInfo *const nmc_fields_con_show[];
|
||||
extern const NmcMetaGenericInfo *const nmc_fields_con_active_details_general[];
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright 2010 - 2014 Red Hat, Inc.
|
||||
* Copyright 2010 - 2018 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include "nm-default.h"
|
||||
|
|
@ -707,22 +707,19 @@ sort_access_points (const GPtrArray *aps)
|
|||
return sorted;
|
||||
}
|
||||
|
||||
static void
|
||||
wifi_signal_to_color (guint8 strength, NMMetaTermColor *color, NMMetaTermFormat *color_fmt)
|
||||
static NMMetaColor
|
||||
wifi_signal_to_color (guint8 strength)
|
||||
{
|
||||
*color = NM_META_TERM_COLOR_NORMAL;
|
||||
*color_fmt = NM_META_TERM_FORMAT_NORMAL;
|
||||
|
||||
if (strength > 80)
|
||||
*color = NM_META_TERM_COLOR_GREEN;
|
||||
return NM_META_COLOR_WIFI_SIGNAL_EXCELLENT;
|
||||
else if (strength > 55)
|
||||
*color = NM_META_TERM_COLOR_YELLOW;
|
||||
return NM_META_COLOR_WIFI_SIGNAL_GOOD;
|
||||
else if (strength > 30)
|
||||
*color = NM_META_TERM_COLOR_MAGENTA;
|
||||
return NM_META_COLOR_WIFI_SIGNAL_FAIR;
|
||||
else if (strength > 5)
|
||||
*color = NM_META_TERM_COLOR_CYAN;
|
||||
return NM_META_COLOR_WIFI_SIGNAL_POOR;
|
||||
else
|
||||
*color_fmt = NM_META_TERM_FORMAT_DIM;
|
||||
return NM_META_COLOR_WIFI_SIGNAL_UNKNOWN;
|
||||
}
|
||||
|
||||
static char *
|
||||
|
|
@ -795,8 +792,7 @@ fill_output_access_point (gpointer data, gpointer user_data)
|
|||
GString *security_str;
|
||||
char *ap_name;
|
||||
const char *sig_bars;
|
||||
NMMetaTermColor color;
|
||||
NMMetaTermFormat color_fmt;
|
||||
NMMetaColor color;
|
||||
|
||||
if (info->active_bssid) {
|
||||
const char *current_bssid = nm_access_point_get_bssid (ap);
|
||||
|
|
@ -882,11 +878,10 @@ fill_output_access_point (gpointer data, gpointer user_data)
|
|||
set_val_strc (arr, 16, nm_object_get_path (NM_OBJECT (ap)));
|
||||
|
||||
/* Set colors */
|
||||
wifi_signal_to_color (strength, &color, &color_fmt);
|
||||
color = wifi_signal_to_color (strength);
|
||||
set_val_color_all (arr, color);
|
||||
set_val_color_fmt_all (arr, color_fmt);
|
||||
if (active)
|
||||
arr[15].color = NM_META_TERM_COLOR_GREEN;
|
||||
arr[15].color = NM_META_COLOR_CONNECTION_ACTIVATED;
|
||||
|
||||
g_ptr_array_add (info->output_data, arr);
|
||||
|
||||
|
|
@ -1160,7 +1155,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||
set_val_strc (arr, 6, nm_device_get_driver (device) ? nm_device_get_driver (device) : _("(unknown)"));
|
||||
set_val_strc (arr, 7, nm_device_get_driver_version (device));
|
||||
set_val_strc (arr, 8, nm_device_get_firmware_version (device));
|
||||
set_val_strc (arr, 9, hwaddr ? hwaddr : _("(unknown)"));
|
||||
set_val_strc (arr, 9, hwaddr ?: _("(unknown)"));
|
||||
set_val_str (arr, 10, mtu_str);
|
||||
set_val_str (arr, 11, state_str);
|
||||
set_val_str (arr, 12, reason_str);
|
||||
|
|
@ -1268,7 +1263,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||
}
|
||||
|
||||
tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dev_wifi_list;
|
||||
out_indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_WIFI_LIST_FOR_DEV_LIST,
|
||||
out_indices = parse_output_fields (section_fld ?: NMC_FIELDS_DEV_WIFI_LIST_FOR_DEV_LIST,
|
||||
tmpl, FALSE, NULL, NULL);
|
||||
arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_FIELD_NAMES);
|
||||
g_ptr_array_add (out.output_data, arr);
|
||||
|
|
@ -1463,20 +1458,19 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
nmc_device_state_to_color (NMDeviceState state, NMMetaTermColor *color, NMMetaTermFormat *color_fmt)
|
||||
NMMetaColor
|
||||
nmc_device_state_to_color (NMDeviceState state)
|
||||
{
|
||||
*color = NM_META_TERM_COLOR_NORMAL;
|
||||
*color_fmt = NM_META_TERM_FORMAT_NORMAL;
|
||||
|
||||
if (state <= NM_DEVICE_STATE_UNAVAILABLE)
|
||||
*color_fmt= NM_META_TERM_FORMAT_DIM;
|
||||
return NM_META_COLOR_DEVICE_UNAVAILABLE;
|
||||
else if (state == NM_DEVICE_STATE_DISCONNECTED)
|
||||
*color = NM_META_TERM_COLOR_RED;
|
||||
return NM_META_COLOR_DEVICE_DISCONNECTED;
|
||||
else if (state >= NM_DEVICE_STATE_PREPARE && state <= NM_DEVICE_STATE_SECONDARIES)
|
||||
*color = NM_META_TERM_COLOR_YELLOW;
|
||||
return NM_META_COLOR_DEVICE_ACTIVATING;
|
||||
else if (state == NM_DEVICE_STATE_ACTIVATED)
|
||||
*color = NM_META_TERM_COLOR_GREEN;
|
||||
return NM_META_COLOR_DEVICE_ACTIVATED;
|
||||
|
||||
g_return_val_if_reached (NM_META_COLOR_DEVICE_UNKNOWN);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -1484,8 +1478,7 @@ fill_output_device_status (NMDevice *device, GPtrArray *output_data)
|
|||
{
|
||||
NMActiveConnection *ac;
|
||||
NMDeviceState state;
|
||||
NMMetaTermColor color;
|
||||
NMMetaTermFormat color_fmt;
|
||||
NMMetaColor color;
|
||||
NmcOutputField *arr = nmc_dup_fields_array ((const NMMetaAbstractInfo *const*) nmc_fields_dev_status,
|
||||
0);
|
||||
|
||||
|
|
@ -1493,9 +1486,8 @@ fill_output_device_status (NMDevice *device, GPtrArray *output_data)
|
|||
ac = nm_device_get_active_connection (device);
|
||||
|
||||
/* Show devices in color */
|
||||
nmc_device_state_to_color (state, &color, &color_fmt);
|
||||
color = nmc_device_state_to_color (state);
|
||||
set_val_color_all (arr, color);
|
||||
set_val_color_fmt_all (arr, color_fmt);
|
||||
|
||||
set_val_strc (arr, 0, nm_device_get_iface (device));
|
||||
set_val_strc (arr, 1, nm_device_get_type_description (device));
|
||||
|
|
@ -2406,12 +2398,11 @@ static void
|
|||
device_state (NMDevice *device, GParamSpec *pspec, NmCli *nmc)
|
||||
{
|
||||
NMDeviceState state = nm_device_get_state (device);
|
||||
NMMetaTermColor color;
|
||||
NMMetaTermFormat color_fmt;
|
||||
NMMetaColor color;
|
||||
char *str;
|
||||
|
||||
nmc_device_state_to_color (state, &color, &color_fmt);
|
||||
str = nmc_colorize (nmc->nmc_config.use_colors, color, color_fmt, "%s: %s\n",
|
||||
color = nmc_device_state_to_color (state);
|
||||
str = nmc_colorize (&nmc->nmc_config, color, "%s: %s\n",
|
||||
nm_device_get_iface (device),
|
||||
nmc_device_state_to_string (state));
|
||||
|
||||
|
|
@ -2906,7 +2897,7 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv)
|
|||
|
||||
if (nmc->ask) {
|
||||
ssid_ask = nmc_readline (_("SSID or BSSID: "));
|
||||
param_user = ssid_ask ? ssid_ask : "";
|
||||
param_user = ssid_ask ?: "";
|
||||
bssid1_arr = nm_utils_hwaddr_atoba (param_user, ETH_ALEN);
|
||||
}
|
||||
if (!ssid_ask) {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* (C) Copyright 2010 Red Hat, Inc.
|
||||
* (C) Copyright 2010 - 2018 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef NMC_DEVICES_H
|
||||
|
|
@ -32,7 +32,7 @@ void monitor_devices (NmCli *nmc);
|
|||
|
||||
NMDevice ** nmc_get_devices_sorted (NMClient *client);
|
||||
|
||||
void nmc_device_state_to_color (NMDeviceState state, NMMetaTermColor *color, NMMetaTermFormat *color_fmt);
|
||||
NMMetaColor nmc_device_state_to_color (NMDeviceState state);
|
||||
|
||||
extern const NmcMetaGenericInfo *const nmc_fields_dev_status[];
|
||||
extern const NmcMetaGenericInfo *const nmc_fields_dev_show_general[];
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright 2010 - 2017 Red Hat, Inc.
|
||||
* Copyright 2010 - 2018 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include "nm-default.h"
|
||||
|
|
@ -55,23 +55,26 @@ nm_state_to_string (NMState state)
|
|||
return _(nm_state_to_string_no_l10n (state));
|
||||
}
|
||||
|
||||
static NMMetaTermColor
|
||||
static NMMetaColor
|
||||
state_to_color (NMState state)
|
||||
{
|
||||
switch (state) {
|
||||
case NM_STATE_CONNECTING:
|
||||
return NM_META_TERM_COLOR_YELLOW;
|
||||
return NM_META_COLOR_STATE_CONNECTING;
|
||||
case NM_STATE_CONNECTED_LOCAL:
|
||||
return NM_META_COLOR_STATE_CONNECTED_LOCAL;
|
||||
case NM_STATE_CONNECTED_SITE:
|
||||
return NM_META_COLOR_STATE_CONNECTED_SITE;
|
||||
case NM_STATE_CONNECTED_GLOBAL:
|
||||
return NM_META_TERM_COLOR_GREEN;
|
||||
return NM_META_COLOR_STATE_CONNECTED_GLOBAL;
|
||||
case NM_STATE_DISCONNECTING:
|
||||
return NM_META_TERM_COLOR_YELLOW;
|
||||
return NM_META_COLOR_STATE_DISCONNECTING;
|
||||
case NM_STATE_ASLEEP:
|
||||
return NM_META_COLOR_STATE_ASLEEP;
|
||||
case NM_STATE_DISCONNECTED:
|
||||
return NM_META_TERM_COLOR_RED;
|
||||
return NM_META_COLOR_STATE_DISCONNECTED;
|
||||
default:
|
||||
return NM_META_TERM_COLOR_NORMAL;
|
||||
return NM_META_COLOR_STATE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -90,19 +93,20 @@ nm_connectivity_to_string (NMConnectivityState connectivity)
|
|||
return _(nm_connectivity_to_string_no_l10n (connectivity));
|
||||
}
|
||||
|
||||
static NMMetaTermColor
|
||||
static NMMetaColor
|
||||
connectivity_to_color (NMConnectivityState connectivity)
|
||||
{
|
||||
switch (connectivity) {
|
||||
case NM_CONNECTIVITY_NONE:
|
||||
return NM_META_TERM_COLOR_RED;
|
||||
return NM_META_COLOR_CONNECTIVITY_NONE;
|
||||
case NM_CONNECTIVITY_PORTAL:
|
||||
return NM_META_COLOR_CONNECTIVITY_PORTAL;
|
||||
case NM_CONNECTIVITY_LIMITED:
|
||||
return NM_META_TERM_COLOR_YELLOW;
|
||||
return NM_META_COLOR_CONNECTIVITY_LIMITED;
|
||||
case NM_CONNECTIVITY_FULL:
|
||||
return NM_META_TERM_COLOR_GREEN;
|
||||
return NM_META_COLOR_CONNECTIVITY_FULL;
|
||||
default:
|
||||
return NM_META_TERM_COLOR_NORMAL;
|
||||
return NM_META_COLOR_CONNECTIVITY_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -155,11 +159,11 @@ NM_UTILS_LOOKUP_STR_DEFINE_STATIC (permission_result_to_string_no_l10n, NMClient
|
|||
NM_UTILS_LOOKUP_ITEM_IGNORE (NM_CLIENT_PERMISSION_RESULT_UNKNOWN),
|
||||
);
|
||||
|
||||
_NM_UTILS_LOOKUP_DEFINE (static, permission_result_to_color, NMClientPermissionResult, NMMetaTermColor,
|
||||
NM_UTILS_LOOKUP_DEFAULT (NM_META_TERM_COLOR_NORMAL),
|
||||
NM_UTILS_LOOKUP_ITEM (NM_CLIENT_PERMISSION_RESULT_YES, NM_META_TERM_COLOR_GREEN),
|
||||
NM_UTILS_LOOKUP_ITEM (NM_CLIENT_PERMISSION_RESULT_NO, NM_META_TERM_COLOR_RED),
|
||||
NM_UTILS_LOOKUP_ITEM (NM_CLIENT_PERMISSION_RESULT_AUTH, NM_META_TERM_COLOR_YELLOW),
|
||||
_NM_UTILS_LOOKUP_DEFINE (static, permission_result_to_color, NMClientPermissionResult, NMMetaColor,
|
||||
NM_UTILS_LOOKUP_DEFAULT (NM_META_COLOR_PERMISSION_UNKNOWN),
|
||||
NM_UTILS_LOOKUP_ITEM (NM_CLIENT_PERMISSION_RESULT_YES, NM_META_COLOR_PERMISSION_YES),
|
||||
NM_UTILS_LOOKUP_ITEM (NM_CLIENT_PERMISSION_RESULT_NO, NM_META_COLOR_PERMISSION_NO),
|
||||
NM_UTILS_LOOKUP_ITEM (NM_CLIENT_PERMISSION_RESULT_AUTH, NM_META_COLOR_PERMISSION_AUTH),
|
||||
NM_UTILS_LOOKUP_ITEM_IGNORE (NM_CLIENT_PERMISSION_RESULT_UNKNOWN),
|
||||
);
|
||||
|
||||
|
|
@ -186,26 +190,26 @@ _metagen_general_status_get_fcn (const NMMetaEnvironment *environment,
|
|||
|
||||
switch (info->info_type) {
|
||||
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_RUNNING:
|
||||
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
|
||||
NMC_HANDLE_COLOR (NM_META_COLOR_NONE);
|
||||
value = N_("running");
|
||||
goto translate_and_out;
|
||||
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_VERSION:
|
||||
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
|
||||
NMC_HANDLE_COLOR (NM_META_COLOR_NONE);
|
||||
value = nm_client_get_version (nmc->client);
|
||||
goto clone_and_out;
|
||||
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_STATE:
|
||||
state = nm_client_get_state (nmc->client);
|
||||
NMC_HANDLE_TERMFORMAT (state_to_color (state));
|
||||
NMC_HANDLE_COLOR (state_to_color (state));
|
||||
value = nm_state_to_string_no_l10n (state);
|
||||
goto translate_and_out;
|
||||
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_STARTUP:
|
||||
v_bool = nm_client_get_startup (nmc->client);
|
||||
NMC_HANDLE_TERMFORMAT (v_bool ? NM_META_TERM_COLOR_YELLOW : NM_META_TERM_COLOR_GREEN);
|
||||
NMC_HANDLE_COLOR (v_bool ? NM_META_COLOR_MANAGER_STARTING : NM_META_COLOR_MANAGER_RUNNING);
|
||||
value = v_bool ? N_("starting") : N_("started");
|
||||
goto translate_and_out;
|
||||
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_CONNECTIVITY:
|
||||
connectivity = nm_client_get_connectivity (nmc->client);
|
||||
NMC_HANDLE_TERMFORMAT (connectivity_to_color (connectivity));
|
||||
NMC_HANDLE_COLOR (connectivity_to_color (connectivity));
|
||||
value = nm_connectivity_to_string_no_l10n (connectivity);
|
||||
goto translate_and_out;
|
||||
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_NETWORKING:
|
||||
|
|
@ -234,7 +238,7 @@ _metagen_general_status_get_fcn (const NMMetaEnvironment *environment,
|
|||
g_return_val_if_reached (NULL);
|
||||
|
||||
enabled_out:
|
||||
NMC_HANDLE_TERMFORMAT (v_bool ? NM_META_TERM_COLOR_GREEN : NM_META_TERM_COLOR_RED);
|
||||
NMC_HANDLE_COLOR (v_bool ? NM_META_COLOR_ENABLED : NM_META_COLOR_DISABLED);
|
||||
value = v_bool ? N_("enabled") : N_("disabled");
|
||||
goto translate_and_out;
|
||||
|
||||
|
|
@ -293,11 +297,11 @@ _metagen_general_permissions_get_fcn (const NMMetaEnvironment *environment,
|
|||
|
||||
switch (info->info_type) {
|
||||
case NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_PERMISSION:
|
||||
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
|
||||
NMC_HANDLE_COLOR (NM_META_COLOR_NONE);
|
||||
return permission_to_string (perm);
|
||||
case NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_VALUE:
|
||||
perm_result = nm_client_get_permission_result (nmc->client, perm);
|
||||
NMC_HANDLE_TERMFORMAT (permission_result_to_color (perm_result));
|
||||
NMC_HANDLE_COLOR (permission_result_to_color (perm_result));
|
||||
s = permission_result_to_string_no_l10n (perm_result);
|
||||
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
|
||||
return _(s);
|
||||
|
|
@ -340,7 +344,7 @@ _metagen_general_logging_get_fcn (const NMMetaEnvironment *environment,
|
|||
|
||||
nm_assert (info->info_type < _NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_NUM);
|
||||
|
||||
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
|
||||
NMC_HANDLE_COLOR (NM_META_COLOR_NONE);
|
||||
|
||||
if (!d->initialized) {
|
||||
d->initialized = TRUE;
|
||||
|
|
@ -516,8 +520,8 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl
|
|||
{
|
||||
gs_free_error GError *error = NULL;
|
||||
const char *fields_str;
|
||||
const char *fields_all = print_flds ? print_flds : NMC_FIELDS_NM_STATUS_ALL;
|
||||
const char *fields_common = print_flds ? print_flds : NMC_FIELDS_NM_STATUS_COMMON;
|
||||
const char *fields_all = print_flds ?: NMC_FIELDS_NM_STATUS_ALL;
|
||||
const char *fields_common = print_flds ?: NMC_FIELDS_NM_STATUS_COMMON;
|
||||
|
||||
if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0)
|
||||
fields_str = fields_common;
|
||||
|
|
@ -1086,9 +1090,8 @@ networkmanager_running (NMClient *client, GParamSpec *param, NmCli *nmc)
|
|||
char *str;
|
||||
|
||||
running = nm_client_get_nm_running (client);
|
||||
str = nmc_colorize (nmc->nmc_config.use_colors,
|
||||
running ? NM_META_TERM_COLOR_GREEN : NM_META_TERM_COLOR_RED,
|
||||
NM_META_TERM_FORMAT_NORMAL,
|
||||
str = nmc_colorize (&nmc->nmc_config,
|
||||
running ? NM_META_COLOR_MANAGER_RUNNING : NM_META_COLOR_MANAGER_STOPPED,
|
||||
running ? _("NetworkManager has started") : _("NetworkManager has stopped"));
|
||||
g_print ("%s\n", str);
|
||||
g_free (str);
|
||||
|
|
@ -1128,7 +1131,7 @@ client_connectivity (NMClient *client, GParamSpec *param, NmCli *nmc)
|
|||
char *str;
|
||||
|
||||
g_object_get (client, NM_CLIENT_CONNECTIVITY, &connectivity, NULL);
|
||||
str = nmc_colorize (nmc->nmc_config.use_colors, connectivity_to_color (connectivity), NM_META_TERM_FORMAT_NORMAL,
|
||||
str = nmc_colorize (&nmc->nmc_config, connectivity_to_color (connectivity),
|
||||
_("Connectivity is now '%s'\n"), nm_connectivity_to_string (connectivity));
|
||||
g_print ("%s", str);
|
||||
g_free (str);
|
||||
|
|
@ -1141,7 +1144,7 @@ client_state (NMClient *client, GParamSpec *param, NmCli *nmc)
|
|||
char *str;
|
||||
|
||||
g_object_get (client, NM_CLIENT_STATE, &state, NULL);
|
||||
str = nmc_colorize (nmc->nmc_config.use_colors, state_to_color (state), NM_META_TERM_FORMAT_NORMAL,
|
||||
str = nmc_colorize (&nmc->nmc_config, state_to_color (state),
|
||||
_("Networkmanager is now in the '%s' state\n"),
|
||||
nm_state_to_string (state));
|
||||
g_print ("%s", str);
|
||||
|
|
@ -1184,12 +1187,12 @@ device_overview (NmCli *nmc, NMDevice *device)
|
|||
if (!nm_device_get_autoconnect (device))
|
||||
g_string_append_printf (outbuf, "%s, ", _("autoconnect"));
|
||||
if (nm_device_get_firmware_missing (device)) {
|
||||
tmp = nmc_colorize (nmc->nmc_config.use_colors, NM_META_TERM_COLOR_RED, NM_META_TERM_FORMAT_NORMAL, _("fw missing"));
|
||||
tmp = nmc_colorize (&nmc->nmc_config, NM_META_COLOR_DEVICE_FIRMWARE_MISSING, _("fw missing"));
|
||||
g_string_append_printf (outbuf, "%s, ", tmp);
|
||||
g_free (tmp);
|
||||
}
|
||||
if (nm_device_get_nm_plugin_missing (device)) {
|
||||
tmp = nmc_colorize (nmc->nmc_config.use_colors, NM_META_TERM_COLOR_RED, NM_META_TERM_FORMAT_NORMAL, _("plugin missing"));
|
||||
tmp = nmc_colorize (&nmc->nmc_config, NM_META_COLOR_DEVICE_PLUGIN_MISSING, _("plugin missing"));
|
||||
g_string_append_printf (outbuf, "%s, ", tmp);
|
||||
g_free (tmp);
|
||||
}
|
||||
|
|
@ -1290,7 +1293,7 @@ do_overview (NmCli *nmc, int argc, char **argv)
|
|||
NMDevice **devices;
|
||||
const GPtrArray *p;
|
||||
NMActiveConnection *ac;
|
||||
NMMetaTermColor color;
|
||||
NMMetaColor color;
|
||||
NMDnsEntry *dns;
|
||||
char *tmp;
|
||||
int i;
|
||||
|
|
@ -1314,8 +1317,8 @@ do_overview (NmCli *nmc, int argc, char **argv)
|
|||
continue;
|
||||
|
||||
state = nm_active_connection_get_state (ac);
|
||||
nmc_active_connection_state_to_color (state, &color);
|
||||
tmp = nmc_colorize (nmc->nmc_config.use_colors, color, NM_META_TERM_FORMAT_NORMAL, _("%s VPN connection"),
|
||||
color = nmc_active_connection_state_to_color (state);
|
||||
tmp = nmc_colorize (&nmc->nmc_config, color, _("%s VPN connection"),
|
||||
nm_active_connection_get_id (ac));
|
||||
g_print ("%s\n", tmp);
|
||||
g_free (tmp);
|
||||
|
|
@ -1326,14 +1329,13 @@ do_overview (NmCli *nmc, int argc, char **argv)
|
|||
|
||||
devices = nmc_get_devices_sorted (nmc->client);
|
||||
for (i = 0; devices[i]; i++) {
|
||||
NMMetaTermFormat color_fmt;
|
||||
NMDeviceState state;
|
||||
|
||||
ac = nm_device_get_active_connection (devices[i]);
|
||||
|
||||
state = nm_device_get_state (devices[i]);
|
||||
nmc_device_state_to_color (state, &color, &color_fmt);
|
||||
tmp = nmc_colorize (nmc->nmc_config.use_colors, color, color_fmt, "%s: %s%s%s",
|
||||
color = nmc_device_state_to_color (state);
|
||||
tmp = nmc_colorize (&nmc->nmc_config, color, "%s: %s%s%s",
|
||||
nm_device_get_iface (devices[i]),
|
||||
nmc_device_state_to_string (state),
|
||||
ac ? " to " : "",
|
||||
|
|
@ -1416,7 +1418,7 @@ do_monitor (NmCli *nmc, int argc, char **argv)
|
|||
if (!nm_client_get_nm_running (nmc->client)) {
|
||||
char *str;
|
||||
|
||||
str = nmc_colorize (nmc->nmc_config.use_colors, NM_META_TERM_COLOR_RED, NM_META_TERM_FORMAT_NORMAL,
|
||||
str = nmc_colorize (&nmc->nmc_config, NM_META_COLOR_MANAGER_STOPPED,
|
||||
_("Networkmanager is not running (waiting for it)\n"));
|
||||
g_print ("%s", str);
|
||||
g_free (str);
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ deps = [
|
|||
]
|
||||
|
||||
cflags = clients_cflags + [
|
||||
'-DSYSCONFDIR="@0@"'.format(nm_sysconfdir),
|
||||
'-DG_LOG_DOMAIN="@0@"'.format(name),
|
||||
'-DNMCLI_LOCALEDIR="@0@"'.format(nm_localedir)
|
||||
]
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright 2010 - 2017 Red Hat, Inc.
|
||||
* Copyright 2010 - 2018 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include "nm-default.h"
|
||||
|
|
@ -51,8 +51,67 @@
|
|||
# define NMCLI_VERSION VERSION
|
||||
#endif
|
||||
|
||||
/* Global NmCli object */
|
||||
NmCli nm_cli;
|
||||
NmCli nm_cli = {
|
||||
.client = NULL,
|
||||
|
||||
.return_value = NMC_RESULT_SUCCESS,
|
||||
|
||||
.timeout = -1,
|
||||
|
||||
.secret_agent = NULL,
|
||||
.pwds_hash = NULL,
|
||||
.pk_listener = NULL,
|
||||
|
||||
.should_wait = 0,
|
||||
.nowait_flag = TRUE,
|
||||
.nmc_config.print_output = NMC_PRINT_NORMAL,
|
||||
.nmc_config.multiline_output = FALSE,
|
||||
.mode_specified = FALSE,
|
||||
.nmc_config.escape_values = TRUE,
|
||||
.required_fields = NULL,
|
||||
.ask = FALSE,
|
||||
.complete = FALSE,
|
||||
.nmc_config.show_secrets = FALSE,
|
||||
.nmc_config.in_editor = FALSE,
|
||||
.nmc_config.palette = {
|
||||
[NM_META_COLOR_CONNECTION_ACTIVATED] = "32",
|
||||
[NM_META_COLOR_CONNECTION_ACTIVATING] = "33",
|
||||
[NM_META_COLOR_CONNECTION_DISCONNECTING] = "31",
|
||||
[NM_META_COLOR_CONNECTION_INVISIBLE] = "2",
|
||||
[NM_META_COLOR_CONNECTIVITY_FULL] = "32",
|
||||
[NM_META_COLOR_CONNECTIVITY_LIMITED] = "33",
|
||||
[NM_META_COLOR_CONNECTIVITY_NONE] = "31",
|
||||
[NM_META_COLOR_CONNECTIVITY_PORTAL] = "33",
|
||||
[NM_META_COLOR_DEVICE_ACTIVATED] = "32",
|
||||
[NM_META_COLOR_DEVICE_ACTIVATING] = "33",
|
||||
[NM_META_COLOR_DEVICE_DISCONNECTED] = "31",
|
||||
[NM_META_COLOR_DEVICE_FIRMWARE_MISSING] = "31",
|
||||
[NM_META_COLOR_DEVICE_PLUGIN_MISSING] = "31",
|
||||
[NM_META_COLOR_DEVICE_UNAVAILABLE] = "2",
|
||||
[NM_META_COLOR_MANAGER_RUNNING] = "32",
|
||||
[NM_META_COLOR_MANAGER_STARTING] = "33",
|
||||
[NM_META_COLOR_MANAGER_STOPPED] = "31",
|
||||
[NM_META_COLOR_PERMISSION_AUTH] = "33",
|
||||
[NM_META_COLOR_PERMISSION_NO] = "31",
|
||||
[NM_META_COLOR_PERMISSION_YES] = "32",
|
||||
[NM_META_COLOR_STATE_ASLEEP] = "31",
|
||||
[NM_META_COLOR_STATE_CONNECTED_GLOBAL] = "32",
|
||||
[NM_META_COLOR_STATE_CONNECTED_LOCAL] = "32",
|
||||
[NM_META_COLOR_STATE_CONNECTED_SITE] = "32",
|
||||
[NM_META_COLOR_STATE_CONNECTING] = "33",
|
||||
[NM_META_COLOR_STATE_DISCONNECTED] = "31",
|
||||
[NM_META_COLOR_STATE_DISCONNECTING] = "33",
|
||||
[NM_META_COLOR_WIFI_SIGNAL_EXCELLENT] = "32",
|
||||
[NM_META_COLOR_WIFI_SIGNAL_FAIR] = "35",
|
||||
[NM_META_COLOR_WIFI_SIGNAL_GOOD] = "33",
|
||||
[NM_META_COLOR_WIFI_SIGNAL_POOR] = "36",
|
||||
[NM_META_COLOR_WIFI_SIGNAL_UNKNOWN] = "2",
|
||||
[NM_META_COLOR_ENABLED] = "32",
|
||||
[NM_META_COLOR_DISABLED] = "31",
|
||||
},
|
||||
.editor_status_line = FALSE,
|
||||
.editor_save_confirmation = TRUE,
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
@ -270,9 +329,299 @@ matches_arg (NmCli *nmc, int *argc, char ***argv, const char *pattern, char **ar
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/*************************************************************************************/
|
||||
|
||||
typedef enum {
|
||||
NMC_USE_COLOR_AUTO,
|
||||
NMC_USE_COLOR_YES,
|
||||
NMC_USE_COLOR_NO,
|
||||
} NmcColorOption;
|
||||
|
||||
/* Checks whether a particular terminal-colors.d(5) file (.enabled, .disabled or .schem)
|
||||
* exists. If contents is non-NULL, it returns the content. */
|
||||
static gboolean
|
||||
check_colors_file (NmCli *nmc, NmcColorOption *color_option,
|
||||
const char *base_dir, const char *name, const char *term, const char *type,
|
||||
char **contents)
|
||||
{
|
||||
char *filename;
|
||||
gboolean exists;
|
||||
|
||||
filename = g_strdup_printf ("%s/terminal-colors.d/%s%s%s%s%s",
|
||||
base_dir,
|
||||
name ? name : "",
|
||||
term ? "@" : "", term ? term : "",
|
||||
(name || term) ? "." : "",
|
||||
type);
|
||||
if (contents)
|
||||
exists = g_file_get_contents (filename, contents, NULL, NULL);
|
||||
else
|
||||
exists = g_file_test (filename, G_FILE_TEST_EXISTS);
|
||||
g_free (filename);
|
||||
|
||||
return exists;
|
||||
}
|
||||
|
||||
static void
|
||||
check_colors_files_for_term (NmCli *nmc, NmcColorOption *color_option,
|
||||
const char *base_dir, const char *name, const char *term)
|
||||
{
|
||||
if ( *color_option == NMC_USE_COLOR_AUTO
|
||||
&& check_colors_file (nmc, color_option, base_dir, name, term, "enable", NULL)) {
|
||||
*color_option = NMC_USE_COLOR_YES;
|
||||
}
|
||||
|
||||
if ( *color_option == NMC_USE_COLOR_AUTO
|
||||
&& check_colors_file (nmc, color_option, base_dir, name, term, "disable", NULL)) {
|
||||
*color_option = NMC_USE_COLOR_NO;
|
||||
}
|
||||
|
||||
if (*color_option == NMC_USE_COLOR_NO) {
|
||||
/* No need to bother any further. */
|
||||
return;
|
||||
}
|
||||
|
||||
if (nmc->palette_buffer == NULL)
|
||||
check_colors_file (nmc, color_option, base_dir, name, term, "schem", &nmc->palette_buffer);
|
||||
}
|
||||
|
||||
static void
|
||||
check_colors_files_for_name (NmCli *nmc, NmcColorOption *color_option,
|
||||
const char *base_dir, const char *name)
|
||||
{
|
||||
const gchar *term;
|
||||
|
||||
/* Take a shortcut if the directory is not there. */
|
||||
if (!g_file_test (base_dir, G_FILE_TEST_EXISTS))
|
||||
return;
|
||||
|
||||
term = g_getenv ("TERM");
|
||||
if (term)
|
||||
check_colors_files_for_term (nmc, color_option, base_dir, name, term);
|
||||
check_colors_files_for_term (nmc, color_option, base_dir, name, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
check_colors_files_for_base_dir (NmCli *nmc, NmcColorOption *color_option,
|
||||
const char *base_dir)
|
||||
{
|
||||
check_colors_files_for_name (nmc, color_option, base_dir, "nmcli");
|
||||
check_colors_files_for_name (nmc, color_option, base_dir, NULL);
|
||||
}
|
||||
|
||||
static const char *
|
||||
resolve_color_alias (const char *color)
|
||||
{
|
||||
static const struct {
|
||||
const char *name;
|
||||
const char *alias;
|
||||
} aliases[] = {
|
||||
{ "reset", "0" },
|
||||
{ "bold", "1" },
|
||||
{ "white", "1;37" },
|
||||
{ "halfbright", "2" },
|
||||
{ "underscore", "4" },
|
||||
{ "blink", "5" },
|
||||
{ "reverse", "7" },
|
||||
{ "black", "30" },
|
||||
{ "red", "31" },
|
||||
{ "green", "32" },
|
||||
{ "brown", "33" },
|
||||
{ "yellow", "33" }, /* well, yellow */
|
||||
{ "blue", "34" },
|
||||
{ "magenta", "35" },
|
||||
{ "cyan", "36" },
|
||||
{ "gray", "37" },
|
||||
{ "darkgray", "90" },
|
||||
{ "lightred", "91" },
|
||||
{ "lightgreen", "92" },
|
||||
{ "lightblue", "94" },
|
||||
{ "lightmagenta", "95" },
|
||||
{ "lightcyan", "96" },
|
||||
{ "lightgray", "97" },
|
||||
};
|
||||
int i;
|
||||
|
||||
/* Shortcut literal sequences. */
|
||||
if (g_ascii_isdigit (*color))
|
||||
return color;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (aliases); i++) {
|
||||
if (strcmp (color, aliases[i].name) == 0)
|
||||
return aliases[i].alias;
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
parse_color_scheme (NmCli *nmc, GError **error)
|
||||
{
|
||||
char *p = nmc->palette_buffer;
|
||||
const char *name;
|
||||
const char *color;
|
||||
const char *map[_NM_META_COLOR_NUM] = {
|
||||
[NM_META_COLOR_NONE] = NULL,
|
||||
[NM_META_COLOR_CONNECTION_ACTIVATED] = "connection-activated",
|
||||
[NM_META_COLOR_CONNECTION_ACTIVATING] = "connection-activating",
|
||||
[NM_META_COLOR_CONNECTION_DISCONNECTING] = "connection-disconnecting",
|
||||
[NM_META_COLOR_CONNECTION_INVISIBLE] = "connection-invisible",
|
||||
[NM_META_COLOR_CONNECTION_UNKNOWN] = "connection-unknown",
|
||||
[NM_META_COLOR_CONNECTIVITY_FULL] = "connectivity-full",
|
||||
[NM_META_COLOR_CONNECTIVITY_LIMITED] = "connectivity-limited",
|
||||
[NM_META_COLOR_CONNECTIVITY_NONE] = "connectivity-none",
|
||||
[NM_META_COLOR_CONNECTIVITY_PORTAL] = "connectivity-portal",
|
||||
[NM_META_COLOR_CONNECTIVITY_UNKNOWN] = "connectivity-unknown",
|
||||
[NM_META_COLOR_DEVICE_ACTIVATED] = "device-activated",
|
||||
[NM_META_COLOR_DEVICE_ACTIVATING] = "device-activating",
|
||||
[NM_META_COLOR_DEVICE_DISCONNECTED] = "device-disconnected",
|
||||
[NM_META_COLOR_DEVICE_FIRMWARE_MISSING] = "device-firmware-missing",
|
||||
[NM_META_COLOR_DEVICE_PLUGIN_MISSING] = "device-plugin-missing",
|
||||
[NM_META_COLOR_DEVICE_UNAVAILABLE] = "device-unavailable",
|
||||
[NM_META_COLOR_DEVICE_UNKNOWN] = "device-unknown",
|
||||
[NM_META_COLOR_MANAGER_RUNNING] = "manager-running",
|
||||
[NM_META_COLOR_MANAGER_STARTING] = "manager-starting",
|
||||
[NM_META_COLOR_MANAGER_STOPPED] = "manager-stopped",
|
||||
[NM_META_COLOR_PERMISSION_AUTH] = "permission-auth",
|
||||
[NM_META_COLOR_PERMISSION_NO] = "permission-no",
|
||||
[NM_META_COLOR_PERMISSION_UNKNOWN] = "permission-unknown",
|
||||
[NM_META_COLOR_PERMISSION_YES] = "permission-yes",
|
||||
[NM_META_COLOR_PROMPT] = "prompt",
|
||||
[NM_META_COLOR_STATE_ASLEEP] = "state-asleep",
|
||||
[NM_META_COLOR_STATE_CONNECTED_GLOBAL] = "state-connected-global",
|
||||
[NM_META_COLOR_STATE_CONNECTED_LOCAL] = "state-connected-local",
|
||||
[NM_META_COLOR_STATE_CONNECTED_SITE] = "state-connected-site",
|
||||
[NM_META_COLOR_STATE_CONNECTING] = "state-connecting",
|
||||
[NM_META_COLOR_STATE_DISCONNECTED] = "state-disconnected",
|
||||
[NM_META_COLOR_STATE_DISCONNECTING] = "state-disconnecting",
|
||||
[NM_META_COLOR_STATE_UNKNOWN] = "state-unknown",
|
||||
[NM_META_COLOR_WIFI_SIGNAL_EXCELLENT] = "wifi-signal-excellent",
|
||||
[NM_META_COLOR_WIFI_SIGNAL_FAIR] = "wifi-signal-fair",
|
||||
[NM_META_COLOR_WIFI_SIGNAL_GOOD] = "wifi-signal-good",
|
||||
[NM_META_COLOR_WIFI_SIGNAL_POOR] = "wifi-signal-poor",
|
||||
[NM_META_COLOR_WIFI_SIGNAL_UNKNOWN] = "wifi-signal-unknown",
|
||||
[NM_META_COLOR_DISABLED] = "disabled",
|
||||
[NM_META_COLOR_ENABLED] = "enabled",
|
||||
};
|
||||
int i;
|
||||
|
||||
/* This reads through the raw color scheme file contents, identifying the
|
||||
* color names and sequences, putting in terminating NULs in place, so that
|
||||
* pointers into the buffer can readily be used as strings in the palette. */
|
||||
while (1) {
|
||||
/* Leading whitespace. */
|
||||
while (nm_utils_is_separator (*p) || *p == '\n')
|
||||
p++;
|
||||
|
||||
if (*p == '\0')
|
||||
break;
|
||||
|
||||
/* Comments. */
|
||||
if (*p == '#') {
|
||||
while (*p != '\n' && *p != '\0')
|
||||
p++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Color name. */
|
||||
name = p;
|
||||
while (g_ascii_isgraph (*p))
|
||||
p++;
|
||||
if (*p == '\0') {
|
||||
g_set_error (error, NMCLI_ERROR, 0,
|
||||
_("Unexpected end of file following '%s'\n"), name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Separating whitespace. */
|
||||
if (!nm_utils_is_separator (*p)) {
|
||||
*p = '\0';
|
||||
g_set_error (error, NMCLI_ERROR, 0,
|
||||
_("Expected whitespace following '%s'\n"), name);
|
||||
return FALSE;
|
||||
}
|
||||
while (nm_utils_is_separator (*p)) {
|
||||
*p = '\0';
|
||||
p++;
|
||||
}
|
||||
|
||||
/* Color sequence. */
|
||||
color = p;
|
||||
if (!g_ascii_isgraph (*p)) {
|
||||
g_set_error (error, NMCLI_ERROR, 0,
|
||||
_("Expected a value for '%s'\n"), name);
|
||||
return FALSE;
|
||||
}
|
||||
while (g_ascii_isgraph (*p))
|
||||
p++;
|
||||
|
||||
/* Trailing whitespace. */
|
||||
while (nm_utils_is_separator (*p)) {
|
||||
*p = '\0';
|
||||
p++;
|
||||
}
|
||||
if (*p != '\0') {
|
||||
if (*p != '\n') {
|
||||
g_set_error (error, NMCLI_ERROR, 0,
|
||||
_("Expected a line break following '%s'\n"), color);
|
||||
return FALSE;
|
||||
}
|
||||
*p = '\0';
|
||||
p++;
|
||||
}
|
||||
|
||||
/* All good, set the palette entry. */
|
||||
for (i = NM_META_COLOR_NONE + 1; i < _NM_META_COLOR_NUM; i++) {
|
||||
if (strcmp (map[i], name) == 0) {
|
||||
nmc->nmc_config_mutable.palette[i] = resolve_color_alias (color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == _NM_META_COLOR_NUM)
|
||||
g_debug ("Ignoring an unrecognized color: '%s'\n", name);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
set_colors (NmCli *nmc, NmcColorOption color_option)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
if (color_option == NMC_USE_COLOR_AUTO) {
|
||||
if ( g_strcmp0 (g_getenv ("TERM"), "dumb") == 0
|
||||
|| !isatty (STDOUT_FILENO))
|
||||
color_option = NMC_USE_COLOR_NO;
|
||||
}
|
||||
|
||||
check_colors_files_for_base_dir (nmc, &color_option, g_get_user_config_dir ());
|
||||
check_colors_files_for_base_dir (nmc, &color_option, SYSCONFDIR);
|
||||
|
||||
switch (color_option) {
|
||||
case NMC_USE_COLOR_YES:
|
||||
case NMC_USE_COLOR_AUTO:
|
||||
nmc->nmc_config_mutable.use_colors = TRUE;
|
||||
break;
|
||||
case NMC_USE_COLOR_NO:
|
||||
nmc->nmc_config_mutable.use_colors = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (nmc->nmc_config_mutable.use_colors && nmc->palette_buffer) {
|
||||
if (!parse_color_scheme (nmc, &error)) {
|
||||
g_debug ("Error parsing color scheme: %s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************/
|
||||
|
||||
static gboolean
|
||||
process_command_line (NmCli *nmc, int argc, char **argv)
|
||||
{
|
||||
NmcColorOption colors = NMC_USE_COLOR_AUTO;
|
||||
char *base;
|
||||
|
||||
base = strrchr (argv[0], '/');
|
||||
|
|
@ -352,11 +701,11 @@ process_command_line (NmCli *nmc, int argc, char **argv)
|
|||
if (argc == 1 && nmc->complete)
|
||||
complete_option_with_value (argv[0], value, "yes", "no", "auto", NULL);
|
||||
if (matches (value, "auto"))
|
||||
nmc->nmc_config_mutable.use_colors = NMC_USE_COLOR_AUTO;
|
||||
colors = NMC_USE_COLOR_AUTO;
|
||||
else if (matches (value, "yes"))
|
||||
nmc->nmc_config_mutable.use_colors = NMC_USE_COLOR_YES;
|
||||
colors = NMC_USE_COLOR_YES;
|
||||
else if (matches (value, "no"))
|
||||
nmc->nmc_config_mutable.use_colors = NMC_USE_COLOR_NO;
|
||||
colors = NMC_USE_COLOR_NO;
|
||||
else {
|
||||
g_string_printf (nmc->return_text, _("Error: '%s' is not valid argument for '%s' option."), value, argv[0]);
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
|
|
@ -383,8 +732,8 @@ process_command_line (NmCli *nmc, int argc, char **argv)
|
|||
complete_fields (argv[0], value);
|
||||
nmc->required_fields = g_strdup (value);
|
||||
nmc->nmc_config_mutable.print_output = NMC_PRINT_TERSE;
|
||||
/* We want fixed tabular mode here, but just set the mode specified and rely on the initialization
|
||||
* in nmc_init: in this way we allow use of "-m multiline" to swap the output mode also if placed
|
||||
/* We want fixed tabular mode here, but just set the mode specified and rely on defaults:
|
||||
* in this way we allow use of "-m multiline" to swap the output mode also if placed
|
||||
* before the "-g <field>" option (-g may be still more practical and easy to remember than -t -f).
|
||||
*/
|
||||
nmc->mode_specified = TRUE;
|
||||
|
|
@ -422,6 +771,8 @@ process_command_line (NmCli *nmc, int argc, char **argv)
|
|||
if (nmc->required_fields)
|
||||
nmc->nmc_config_mutable.overview = FALSE;
|
||||
|
||||
set_colors (nmc, colors);
|
||||
|
||||
/* Now run the requested command */
|
||||
nmc_do_cmd (nmc, nmcli_cmds, *argv, argc, argv);
|
||||
|
||||
|
|
@ -558,38 +909,6 @@ nmc_value_transforms_register (void)
|
|||
nmc_convert_bytes_to_string);
|
||||
}
|
||||
|
||||
/* Initialize NmCli structure - set default values */
|
||||
static void
|
||||
nmc_init (NmCli *nmc)
|
||||
{
|
||||
nmc->client = NULL;
|
||||
|
||||
nmc->return_value = NMC_RESULT_SUCCESS;
|
||||
nmc->return_text = g_string_new (_("Success"));
|
||||
|
||||
nmc->timeout = -1;
|
||||
|
||||
nmc->secret_agent = NULL;
|
||||
nmc->pwds_hash = NULL;
|
||||
nmc->pk_listener = NULL;
|
||||
|
||||
nmc->should_wait = 0;
|
||||
nmc->nowait_flag = TRUE;
|
||||
nmc->nmc_config_mutable.print_output = NMC_PRINT_NORMAL;
|
||||
nmc->nmc_config_mutable.multiline_output = FALSE;
|
||||
nmc->mode_specified = FALSE;
|
||||
nmc->nmc_config_mutable.escape_values = TRUE;
|
||||
nmc->required_fields = NULL;
|
||||
nmc->ask = FALSE;
|
||||
nmc->complete = FALSE;
|
||||
nmc->nmc_config_mutable.show_secrets = FALSE;
|
||||
nmc->nmc_config_mutable.use_colors = NMC_USE_COLOR_AUTO;
|
||||
nmc->nmc_config_mutable.in_editor = FALSE;
|
||||
nmc->editor_status_line = FALSE;
|
||||
nmc->editor_save_confirmation = TRUE;
|
||||
nmc->editor_prompt_color = NM_META_TERM_COLOR_NORMAL;
|
||||
}
|
||||
|
||||
static void
|
||||
nmc_cleanup (NmCli *nmc)
|
||||
{
|
||||
|
|
@ -607,7 +926,7 @@ nmc_cleanup (NmCli *nmc)
|
|||
if (nmc->pwds_hash)
|
||||
g_hash_table_destroy (nmc->pwds_hash);
|
||||
|
||||
g_free (nmc->required_fields);
|
||||
nm_clear_g_free (&nmc->required_fields);
|
||||
|
||||
if (nmc->pager_pid > 0) {
|
||||
fclose (stdout);
|
||||
|
|
@ -618,6 +937,8 @@ nmc_cleanup (NmCli *nmc)
|
|||
nmc->pager_pid = 0;
|
||||
}
|
||||
|
||||
nm_clear_g_free (&nmc->palette_buffer);
|
||||
|
||||
nmc_polkit_agent_fini (nmc);
|
||||
}
|
||||
|
||||
|
|
@ -639,7 +960,7 @@ main (int argc, char *argv[])
|
|||
|
||||
nmc_value_transforms_register ();
|
||||
|
||||
nmc_init (&nm_cli);
|
||||
nm_cli.return_text = g_string_new (_("Success"));
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
|
||||
g_unix_signal_add (SIGTERM, signal_handler, GINT_TO_POINTER (SIGTERM));
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright 2010 - 2017 Red Hat, Inc.
|
||||
* Copyright 2010 - 2018 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef NMC_NMCLI_H
|
||||
|
|
@ -93,24 +93,18 @@ struct _NmcOutputField {
|
|||
gboolean value_is_array; /* Whether value is char** instead of char* */
|
||||
gboolean free_value; /* Whether to free the value */
|
||||
NmcOfFlags flags; /* Flags - whether and how to print values/field names/headers */
|
||||
NMMetaTermColor color; /* Use this color to print value */
|
||||
NMMetaTermFormat color_fmt; /* Use this terminal format to print value */
|
||||
NMMetaColor color; /* Use this color to print value */
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
NMC_USE_COLOR_AUTO,
|
||||
NMC_USE_COLOR_YES,
|
||||
NMC_USE_COLOR_NO,
|
||||
} NmcColorOption;
|
||||
|
||||
typedef struct _NmcConfig {
|
||||
NMCPrintOutput print_output; /* Output mode */
|
||||
NmcColorOption use_colors; /* Whether to use colors for output: option '--color' */
|
||||
gboolean use_colors; /* Whether to use colors for output: option '--color' */
|
||||
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' */
|
||||
bool overview; /* Overview mode (hide default values) */
|
||||
const char *palette[_NM_META_COLOR_NUM]; /* Color palette */
|
||||
} NmcConfig;
|
||||
|
||||
typedef struct _NmcOutputData {
|
||||
|
|
@ -143,7 +137,8 @@ typedef struct _NmCli {
|
|||
gboolean complete; /* Autocomplete the command line */
|
||||
gboolean editor_status_line; /* Whether to display status line in connection editor */
|
||||
gboolean editor_save_confirmation; /* Whether to ask for confirmation on saving connections with 'autoconnect=yes' */
|
||||
NMMetaTermColor editor_prompt_color; /* Color of prompt in connection editor */
|
||||
|
||||
char *palette_buffer; /* Buffer with sequences for terminal-colors.d(5)-based coloring. */
|
||||
} NmCli;
|
||||
|
||||
extern NmCli nm_cli;
|
||||
|
|
|
|||
|
|
@ -749,9 +749,9 @@ nmc_setting_get_property_desc (NMSetting *setting, const char *prop)
|
|||
|
||||
return g_strdup_printf ("%s\n%s\n%s%s%s%s",
|
||||
setting_desc_title,
|
||||
setting_desc ? setting_desc : "",
|
||||
setting_desc ?: "",
|
||||
nmcli_nl, nmcli_desc_title, nmcli_nl,
|
||||
nmcli_desc ? nmcli_desc : "");
|
||||
nmcli_desc ?: "");
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright 2010 Lennart Poettering
|
||||
* Copyright 2010 - 2017 Red Hat, Inc.
|
||||
* Copyright 2010 - 2018 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include "nm-default.h"
|
||||
|
|
@ -86,11 +86,11 @@ _meta_type_nmc_generic_info_get_fcn (const NMMetaAbstractInfo *abstract_info,
|
|||
if (!NM_IN_SET (get_type,
|
||||
NM_META_ACCESSOR_GET_TYPE_PARSABLE,
|
||||
NM_META_ACCESSOR_GET_TYPE_PRETTY,
|
||||
NM_META_ACCESSOR_GET_TYPE_TERMFORMAT))
|
||||
NM_META_ACCESSOR_GET_TYPE_COLOR))
|
||||
g_return_val_if_reached (NULL);
|
||||
|
||||
/* omitting the out_to_free value is only allowed for TERMFORMAT. */
|
||||
nm_assert (out_to_free || NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_TERMFORMAT));
|
||||
/* omitting the out_to_free value is only allowed for COLOR. */
|
||||
nm_assert (out_to_free || NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_COLOR));
|
||||
|
||||
if (info->get_fcn) {
|
||||
return info->get_fcn (environment, environment_user_data,
|
||||
|
|
@ -103,7 +103,7 @@ _meta_type_nmc_generic_info_get_fcn (const NMMetaAbstractInfo *abstract_info,
|
|||
}
|
||||
|
||||
if (info->nested) {
|
||||
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
|
||||
NMC_HANDLE_COLOR (NM_META_COLOR_NONE);
|
||||
return info->name;
|
||||
}
|
||||
|
||||
|
|
@ -119,37 +119,16 @@ const NMMetaType nmc_meta_type_generic_info = {
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gboolean
|
||||
use_colors (NmcColorOption color_option)
|
||||
{
|
||||
if (color_option == NMC_USE_COLOR_AUTO) {
|
||||
static NmcColorOption cached = NMC_USE_COLOR_AUTO;
|
||||
|
||||
if (G_UNLIKELY (cached == NMC_USE_COLOR_AUTO)) {
|
||||
if ( g_strcmp0 (g_getenv ("TERM"), "dumb") == 0
|
||||
|| !isatty (STDOUT_FILENO))
|
||||
cached = NMC_USE_COLOR_NO;
|
||||
else
|
||||
cached = NMC_USE_COLOR_YES;
|
||||
}
|
||||
return cached == NMC_USE_COLOR_YES;
|
||||
}
|
||||
|
||||
return color_option == NMC_USE_COLOR_YES;
|
||||
}
|
||||
|
||||
static const char *
|
||||
colorize_string (NmcColorOption color_option,
|
||||
NMMetaTermColor color,
|
||||
NMMetaTermFormat color_fmt,
|
||||
colorize_string (const NmcConfig *nmc_config,
|
||||
NMMetaColor color,
|
||||
const char *str,
|
||||
char **out_to_free)
|
||||
{
|
||||
const char *out = str;
|
||||
|
||||
if ( use_colors (color_option)
|
||||
&& (color != NM_META_TERM_COLOR_NORMAL || color_fmt != NM_META_TERM_FORMAT_NORMAL)) {
|
||||
*out_to_free = nmc_colorize (color_option, color, color_fmt, "%s", str);
|
||||
if (nmc_config && nmc_config->use_colors) {
|
||||
*out_to_free = nmc_colorize (nmc_config, color, "%s", str);
|
||||
out = *out_to_free;
|
||||
}
|
||||
|
||||
|
|
@ -390,118 +369,30 @@ nmc_terminal_show_progress (const char *str)
|
|||
const char slashes[4] = {'|', '/', '-', '\\'};
|
||||
|
||||
nmc_terminal_erase_line ();
|
||||
g_print ("%c %s", slashes[idx++], str ? str : "");
|
||||
g_print ("%c %s", slashes[idx++], str ?: "");
|
||||
fflush (stdout);
|
||||
if (idx == 4)
|
||||
idx = 0;
|
||||
}
|
||||
|
||||
const char *
|
||||
nmc_term_color_sequence (NMMetaTermColor color)
|
||||
{
|
||||
switch (color) {
|
||||
case NM_META_TERM_COLOR_BLACK:
|
||||
return "\33[30m";
|
||||
break;
|
||||
case NM_META_TERM_COLOR_RED:
|
||||
return "\33[31m";
|
||||
break;
|
||||
case NM_META_TERM_COLOR_GREEN:
|
||||
return "\33[32m";
|
||||
break;
|
||||
case NM_META_TERM_COLOR_YELLOW:
|
||||
return "\33[33m";
|
||||
break;
|
||||
case NM_META_TERM_COLOR_BLUE:
|
||||
return "\33[34m";
|
||||
break;
|
||||
case NM_META_TERM_COLOR_MAGENTA:
|
||||
return "\33[35m";
|
||||
break;
|
||||
case NM_META_TERM_COLOR_CYAN:
|
||||
return "\33[36m";
|
||||
break;
|
||||
case NM_META_TERM_COLOR_WHITE:
|
||||
return "\33[37m";
|
||||
break;
|
||||
default:
|
||||
return "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Parses @str for color as string or number */
|
||||
NMMetaTermColor
|
||||
nmc_term_color_parse_string (const char *str, GError **error)
|
||||
{
|
||||
unsigned long color_int;
|
||||
static const char *colors[] = { "normal", "black", "red", "green", "yellow",
|
||||
"blue", "magenta", "cyan", "white", NULL };
|
||||
|
||||
if (nmc_string_to_uint (str, TRUE, 0, 8, &color_int)) {
|
||||
return (NMMetaTermColor) color_int;
|
||||
} else {
|
||||
const char *color, **p;
|
||||
int i;
|
||||
|
||||
color = nmc_string_is_valid (str, colors, error);
|
||||
for (p = colors, i = 0; *p != NULL; p++, i++) {
|
||||
if (*p == color)
|
||||
return (NMMetaTermColor) i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
nmc_term_format_sequence (NMMetaTermFormat format)
|
||||
{
|
||||
switch (format) {
|
||||
case NM_META_TERM_FORMAT_BOLD:
|
||||
return "\33[1m";
|
||||
break;
|
||||
case NM_META_TERM_FORMAT_DIM:
|
||||
return "\33[2m";
|
||||
break;
|
||||
case NM_META_TERM_FORMAT_UNDERLINE:
|
||||
return "\33[4m";
|
||||
break;
|
||||
case NM_META_TERM_FORMAT_BLINK:
|
||||
return "\33[5m";
|
||||
break;
|
||||
case NM_META_TERM_FORMAT_REVERSE:
|
||||
return "\33[7m";
|
||||
break;
|
||||
case NM_META_TERM_FORMAT_HIDDEN:
|
||||
return "\33[8m";
|
||||
break;
|
||||
default:
|
||||
return "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
char *
|
||||
nmc_colorize (NmcColorOption color_option, NMMetaTermColor color, NMMetaTermFormat format, const char *fmt, ...)
|
||||
nmc_colorize (const NmcConfig *nmc_config, NMMetaColor color, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
char *str, *colored;
|
||||
const char *ansi_color, *color_end, *ansi_fmt, *format_end;
|
||||
static const char *end_seq = "\33[0m";
|
||||
const char *ansi_seq = NULL;
|
||||
|
||||
va_start (args, fmt);
|
||||
str = g_strdup_vprintf (fmt, args);
|
||||
va_end (args);
|
||||
|
||||
if (!use_colors (color_option))
|
||||
if (nmc_config->use_colors)
|
||||
ansi_seq = nmc_config->palette[color];
|
||||
|
||||
if (ansi_seq == NULL)
|
||||
return str;
|
||||
|
||||
ansi_color = nmc_term_color_sequence (color);
|
||||
ansi_fmt = nmc_term_format_sequence (format);
|
||||
color_end = *ansi_color ? end_seq : "";
|
||||
format_end = *ansi_fmt ? end_seq : "";
|
||||
|
||||
colored = g_strdup_printf ("%s%s%s%s%s", ansi_fmt, ansi_color, str, color_end, format_end);
|
||||
colored = g_strdup_printf ("\33[%sm%s\33[0m", ansi_seq, str);
|
||||
g_free (str);
|
||||
return colored;
|
||||
}
|
||||
|
|
@ -718,7 +609,7 @@ set_val_arrc (NmcOutputField fields_array[], guint32 idx, const char **value)
|
|||
}
|
||||
|
||||
void
|
||||
set_val_color_all (NmcOutputField fields_array[], NMMetaTermColor color)
|
||||
set_val_color_all (NmcOutputField fields_array[], NMMetaColor color)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
|
@ -727,16 +618,6 @@ set_val_color_all (NmcOutputField fields_array[], NMMetaTermColor color)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
set_val_color_fmt_all (NmcOutputField fields_array[], NMMetaTermFormat format)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; fields_array[i].info; i++) {
|
||||
fields_array[i].color_fmt = format;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Free 'value' members in array of NmcOutputField
|
||||
*/
|
||||
|
|
@ -1015,8 +896,7 @@ typedef enum {
|
|||
typedef struct {
|
||||
guint row_idx;
|
||||
const PrintDataHeaderCell *header_cell;
|
||||
NMMetaTermColor term_color;
|
||||
NMMetaTermFormat term_format;
|
||||
NMMetaColor color;
|
||||
union {
|
||||
const char *plain;
|
||||
const char *const*strv;
|
||||
|
|
@ -1179,17 +1059,15 @@ _print_fill (const NmcConfig *nmc_config,
|
|||
cell->text_to_free = !!to_free;
|
||||
}
|
||||
|
||||
nm_meta_termformat_unpack (nm_meta_abstract_info_get (info,
|
||||
nmc_meta_environment,
|
||||
nmc_meta_environment_arg,
|
||||
target,
|
||||
NM_META_ACCESSOR_GET_TYPE_TERMFORMAT,
|
||||
NM_META_ACCESSOR_GET_FLAGS_NONE,
|
||||
&color_out_flags,
|
||||
NULL,
|
||||
NULL),
|
||||
&cell->term_color,
|
||||
&cell->term_format);
|
||||
cell->color = GPOINTER_TO_INT (nm_meta_abstract_info_get (info,
|
||||
nmc_meta_environment,
|
||||
nmc_meta_environment_arg,
|
||||
target,
|
||||
NM_META_ACCESSOR_GET_TYPE_COLOR,
|
||||
NM_META_ACCESSOR_GET_FLAGS_NONE,
|
||||
&color_out_flags,
|
||||
NULL,
|
||||
NULL));
|
||||
|
||||
if (cell->text_format == PRINT_DATA_CELL_FORMAT_TYPE_PLAIN) {
|
||||
if (pretty && (!cell->text.plain|| !cell->text.plain[0])) {
|
||||
|
|
@ -1374,9 +1252,7 @@ _print_do (const NmcConfig *nmc_config,
|
|||
gs_free char *text_to_free = NULL;
|
||||
const char *text;
|
||||
|
||||
text = colorize_string (nmc_config->use_colors,
|
||||
cell->term_color, cell->term_format,
|
||||
lines[i_lines], &text_to_free);
|
||||
text = colorize_string (nmc_config, cell->color, lines[i_lines], &text_to_free);
|
||||
if (multiline) {
|
||||
gs_free char *prefix = NULL;
|
||||
|
||||
|
|
@ -1505,7 +1381,7 @@ nmc_terminal_spawn_pager (const NmcConfig *nmc_config)
|
|||
if ( nm_cli.nmc_config.in_editor
|
||||
|| nm_cli.pager_pid > 0
|
||||
|| nmc_config->print_output == NMC_PRINT_TERSE
|
||||
|| !use_colors (nmc_config->use_colors)
|
||||
|| !nmc_config->use_colors
|
||||
|| g_strcmp0 (pager, "") == 0
|
||||
|| getauxval (AT_SECURE))
|
||||
return;
|
||||
|
|
@ -1576,7 +1452,7 @@ nmc_terminal_spawn_pager (const NmcConfig *nmc_config)
|
|||
/*****************************************************************************/
|
||||
|
||||
static const char *
|
||||
get_value_to_print (NmcColorOption color_option,
|
||||
get_value_to_print (const NmcConfig *nmc_config,
|
||||
const NmcOutputField *field,
|
||||
gboolean field_name,
|
||||
const char *not_set_str,
|
||||
|
|
@ -1602,7 +1478,7 @@ get_value_to_print (NmcColorOption color_option,
|
|||
}
|
||||
|
||||
/* colorize the value */
|
||||
out = colorize_string (color_option, field->color, field->color_fmt, value, out_to_free);
|
||||
out = colorize_string (nmc_config, field->color, value, out_to_free);
|
||||
|
||||
if (out && out == free_value) {
|
||||
nm_assert (!*out_to_free);
|
||||
|
|
@ -1696,7 +1572,7 @@ print_required_fields (const NmcConfig *nmc_config,
|
|||
gs_free char *tmp = NULL;
|
||||
|
||||
val = *p ?: not_set_str;
|
||||
print_val = colorize_string (nmc_config->use_colors, field_values[idx].color, field_values[idx].color_fmt,
|
||||
print_val = colorize_string (nmc_config, field_values[idx].color,
|
||||
val, &val_to_free);
|
||||
tmp = g_strdup_printf ("%s%s%s[%d]:",
|
||||
section_prefix ? (const char*) field_values[0].value : "",
|
||||
|
|
@ -1717,7 +1593,7 @@ print_required_fields (const NmcConfig *nmc_config,
|
|||
/* value is a string */
|
||||
|
||||
val = val && *val ? val : not_set_str;
|
||||
print_val = colorize_string (nmc_config->use_colors, field_values[idx].color, field_values[idx].color_fmt,
|
||||
print_val = colorize_string (nmc_config, field_values[idx].color,
|
||||
val, &val_to_free);
|
||||
tmp = g_strdup_printf ("%s%s%s:",
|
||||
section_prefix ? hdr_name : "",
|
||||
|
|
@ -1748,7 +1624,7 @@ print_required_fields (const NmcConfig *nmc_config,
|
|||
|
||||
idx = g_array_index (indices, int, i);
|
||||
|
||||
value = get_value_to_print (nmc_config->use_colors, (NmcOutputField *) field_values+idx, field_names,
|
||||
value = get_value_to_print (nmc_config, (NmcOutputField *) field_values+idx, field_names,
|
||||
not_set_str, &val_to_free);
|
||||
|
||||
if (terse) {
|
||||
|
|
@ -1821,7 +1697,7 @@ print_data_prepare_width (GPtrArray *output_data)
|
|||
|
||||
row = g_ptr_array_index (output_data, j);
|
||||
field_names = row[0].flags & NMC_OF_FLAG_FIELD_NAMES;
|
||||
value = get_value_to_print (NMC_USE_COLOR_NO, row+i, field_names, "--", &val_to_free);
|
||||
value = get_value_to_print (NULL, row+i, field_names, "--", &val_to_free);
|
||||
len = nmc_string_screen_width (value, NULL);
|
||||
max_width = len > max_width ? len : max_width;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright 2010 - 2017 Red Hat, Inc.
|
||||
* Copyright 2010 - 2018 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef NMC_UTILS_H
|
||||
|
|
@ -41,11 +41,7 @@ char *ssid_to_hex (const char *str, gsize len);
|
|||
void nmc_terminal_erase_line (void);
|
||||
void nmc_terminal_show_progress (const char *str);
|
||||
void nmc_terminal_spawn_pager (const NmcConfig *nmc_config);
|
||||
gboolean nmc_term_use_colors (NmcColorOption color_option);
|
||||
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);
|
||||
char *nmc_colorize (const NmcConfig *nmc_config, NMMetaColor color, const char * fmt, ...) _nm_printf (3, 4);
|
||||
void nmc_filter_out_colors_inplace (char *str);
|
||||
char *nmc_filter_out_colors (const char *str);
|
||||
char *nmc_get_user_input (const char *ask_str);
|
||||
|
|
@ -58,8 +54,7 @@ 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);
|
||||
void set_val_color_all (NmcOutputField fields_array[], NMMetaTermColor color);
|
||||
void set_val_color_fmt_all (NmcOutputField fields_array[], NMMetaTermFormat format);
|
||||
void set_val_color_all (NmcOutputField fields_array[], NMMetaColor color);
|
||||
void nmc_free_output_field_values (NmcOutputField fields_array[]);
|
||||
|
||||
GArray *parse_output_fields (const char *fields_str,
|
||||
|
|
@ -128,10 +123,10 @@ typedef enum {
|
|||
|
||||
} NmcGenericInfoType;
|
||||
|
||||
#define NMC_HANDLE_TERMFORMAT(color) \
|
||||
#define NMC_HANDLE_COLOR(color) \
|
||||
G_STMT_START { \
|
||||
if (get_type == NM_META_ACCESSOR_GET_TYPE_TERMFORMAT) \
|
||||
return nm_meta_termformat_pack ((color), NM_META_TERM_FORMAT_NORMAL); \
|
||||
if (get_type == NM_META_ACCESSOR_GET_TYPE_COLOR) \
|
||||
return GINT_TO_POINTER (color); \
|
||||
} G_STMT_END
|
||||
|
||||
struct _NmcMetaGenericInfo {
|
||||
|
|
|
|||
|
|
@ -2157,7 +2157,7 @@ _get_fcn_802_1x_phase2_private_key (ARGS_GET_FCN)
|
|||
password = path + strcspn (path, " \t"); \
|
||||
if (password[0] != '\0') { \
|
||||
password[0] = '\0'; \
|
||||
while (NM_IN_SET (password[0], ' ', '\t')) \
|
||||
while (nm_utils_is_separator (password[0])) \
|
||||
password++; \
|
||||
} else \
|
||||
password = password_free = g_strdup (pwd_func (NM_SETTING_802_1X (setting))); \
|
||||
|
|
@ -2891,7 +2891,7 @@ dcb_parse_uint_array (const char *val,
|
|||
|
||||
*iter = g_strstrip (*iter);
|
||||
|
||||
num = _nm_utils_ascii_str_to_int64 (*iter, 10, 0, other ? other : max, -1);
|
||||
num = _nm_utils_ascii_str_to_int64 (*iter, 10, 0, other ?: max, -1);
|
||||
|
||||
/* If number is greater than 'max' it must equal 'other' */
|
||||
if ( num == -1
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright 2010 - 2017 Red Hat, Inc.
|
||||
* Copyright 2010 - 2018 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef __NM_META_SETTING_DESC_H__
|
||||
|
|
@ -83,31 +83,54 @@ struct _NMDevice;
|
|||
#define NM_META_TEXT_PROMPT_PROXY_METHOD_CHOICES "(" NM_META_TEXT_WORD_NONE "/" NM_META_TEXT_WORD_AUTO ") [" NM_META_TEXT_WORD_NONE "]"
|
||||
|
||||
typedef enum {
|
||||
NM_META_TERM_COLOR_NORMAL = 0,
|
||||
NM_META_TERM_COLOR_BLACK = 1,
|
||||
NM_META_TERM_COLOR_RED = 2,
|
||||
NM_META_TERM_COLOR_GREEN = 3,
|
||||
NM_META_TERM_COLOR_YELLOW = 4,
|
||||
NM_META_TERM_COLOR_BLUE = 5,
|
||||
NM_META_TERM_COLOR_MAGENTA = 6,
|
||||
NM_META_TERM_COLOR_CYAN = 7,
|
||||
NM_META_TERM_COLOR_WHITE = 8,
|
||||
} NMMetaTermColor;
|
||||
|
||||
typedef enum {
|
||||
NM_META_TERM_FORMAT_NORMAL = 0,
|
||||
NM_META_TERM_FORMAT_BOLD = 1,
|
||||
NM_META_TERM_FORMAT_DIM = 2,
|
||||
NM_META_TERM_FORMAT_UNDERLINE = 3,
|
||||
NM_META_TERM_FORMAT_BLINK = 4,
|
||||
NM_META_TERM_FORMAT_REVERSE = 5,
|
||||
NM_META_TERM_FORMAT_HIDDEN = 6,
|
||||
} NMMetaTermFormat;
|
||||
NM_META_COLOR_NONE = 0,
|
||||
NM_META_COLOR_CONNECTION_ACTIVATED,
|
||||
NM_META_COLOR_CONNECTION_ACTIVATING,
|
||||
NM_META_COLOR_CONNECTION_DISCONNECTING,
|
||||
NM_META_COLOR_CONNECTION_INVISIBLE,
|
||||
NM_META_COLOR_CONNECTION_UNKNOWN,
|
||||
NM_META_COLOR_CONNECTIVITY_FULL,
|
||||
NM_META_COLOR_CONNECTIVITY_LIMITED,
|
||||
NM_META_COLOR_CONNECTIVITY_NONE,
|
||||
NM_META_COLOR_CONNECTIVITY_PORTAL,
|
||||
NM_META_COLOR_CONNECTIVITY_UNKNOWN,
|
||||
NM_META_COLOR_DEVICE_ACTIVATED,
|
||||
NM_META_COLOR_DEVICE_ACTIVATING,
|
||||
NM_META_COLOR_DEVICE_DISCONNECTED,
|
||||
NM_META_COLOR_DEVICE_FIRMWARE_MISSING,
|
||||
NM_META_COLOR_DEVICE_PLUGIN_MISSING,
|
||||
NM_META_COLOR_DEVICE_UNAVAILABLE,
|
||||
NM_META_COLOR_DEVICE_UNKNOWN,
|
||||
NM_META_COLOR_MANAGER_RUNNING,
|
||||
NM_META_COLOR_MANAGER_STARTING,
|
||||
NM_META_COLOR_MANAGER_STOPPED,
|
||||
NM_META_COLOR_PERMISSION_AUTH,
|
||||
NM_META_COLOR_PERMISSION_NO,
|
||||
NM_META_COLOR_PERMISSION_UNKNOWN,
|
||||
NM_META_COLOR_PERMISSION_YES,
|
||||
NM_META_COLOR_PROMPT,
|
||||
NM_META_COLOR_STATE_ASLEEP,
|
||||
NM_META_COLOR_STATE_CONNECTED_GLOBAL,
|
||||
NM_META_COLOR_STATE_CONNECTED_LOCAL,
|
||||
NM_META_COLOR_STATE_CONNECTED_SITE,
|
||||
NM_META_COLOR_STATE_CONNECTING,
|
||||
NM_META_COLOR_STATE_DISCONNECTED,
|
||||
NM_META_COLOR_STATE_DISCONNECTING,
|
||||
NM_META_COLOR_STATE_UNKNOWN,
|
||||
NM_META_COLOR_WIFI_SIGNAL_EXCELLENT,
|
||||
NM_META_COLOR_WIFI_SIGNAL_FAIR,
|
||||
NM_META_COLOR_WIFI_SIGNAL_GOOD,
|
||||
NM_META_COLOR_WIFI_SIGNAL_POOR,
|
||||
NM_META_COLOR_WIFI_SIGNAL_UNKNOWN,
|
||||
NM_META_COLOR_DISABLED,
|
||||
NM_META_COLOR_ENABLED,
|
||||
_NM_META_COLOR_NUM
|
||||
} NMMetaColor;
|
||||
|
||||
typedef enum {
|
||||
NM_META_ACCESSOR_GET_TYPE_PRETTY,
|
||||
NM_META_ACCESSOR_GET_TYPE_PARSABLE,
|
||||
NM_META_ACCESSOR_GET_TYPE_TERMFORMAT,
|
||||
NM_META_ACCESSOR_GET_TYPE_COLOR,
|
||||
} NMMetaAccessorGetType;
|
||||
|
||||
typedef enum {
|
||||
|
|
@ -115,32 +138,6 @@ typedef enum {
|
|||
NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI,
|
||||
} NMMetaAccessorSettingInitType;
|
||||
|
||||
static inline void
|
||||
nm_meta_termformat_unpack (gconstpointer value, NMMetaTermColor *out_color, NMMetaTermFormat *out_format)
|
||||
{
|
||||
/* get_fcn() with NM_META_ACCESSOR_GET_TYPE_TERMFORMAT returns a pointer
|
||||
* that encodes NMMetaTermColor and NMMetaTermFormat. Unpack it. */
|
||||
if (!value) {
|
||||
/* by default, objects that don't support NM_META_ACCESSOR_GET_TYPE_TERMFORMAT
|
||||
* return NULL. This allows for an explicit fallback value here... */
|
||||
NM_SET_OUT (out_color, NM_META_TERM_COLOR_NORMAL);
|
||||
NM_SET_OUT (out_format, NM_META_TERM_FORMAT_NORMAL);
|
||||
} else {
|
||||
NM_SET_OUT (out_color, GPOINTER_TO_UINT (value) & 0xFF);
|
||||
NM_SET_OUT (out_format, (GPOINTER_TO_UINT (value) & 0xFF00) >> 8);
|
||||
}
|
||||
}
|
||||
|
||||
static inline gconstpointer
|
||||
nm_meta_termformat_pack (NMMetaTermColor color, NMMetaTermFormat format)
|
||||
{
|
||||
/* get_fcn() with NM_META_ACCESSOR_GET_TYPE_TERMFORMAT returns a pointer
|
||||
* that encodes NMMetaTermColor and NMMetaTermFormat. Pack it. */
|
||||
return GUINT_TO_POINTER (((guint) 0x10000) | (((guint) color) & 0xFFu) | ((((guint) format) & 0xFFu) << 8));
|
||||
}
|
||||
|
||||
#define NM_META_TERMFORMAT_DEFAULT() (nm_meta_termformat_pack (NM_META_TERM_COLOR_NORMAL, NM_META_TERM_FORMAT_NORMAL))
|
||||
|
||||
typedef enum {
|
||||
NM_META_ACCESSOR_GET_FLAGS_NONE = 0,
|
||||
NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV = (1LL << 0),
|
||||
|
|
|
|||
|
|
@ -238,7 +238,7 @@ nm_vpn_openconnect_authenticate_helper (const char *host,
|
|||
* HOST='1.2.3.4'
|
||||
* FINGERPRINT='sha1:32bac90cf09a722e10ecc1942c67fe2ac8c21e2e'
|
||||
*/
|
||||
strv = g_strsplit_set (output ? output : "", "\r\n", 0);
|
||||
strv = g_strsplit_set (output ?: "", "\r\n", 0);
|
||||
for (iter = strv; iter && *iter; iter++) {
|
||||
_extract_variable_value (*iter, "COOKIE=", cookie);
|
||||
_extract_variable_value (*iter, "HOST=", gateway);
|
||||
|
|
|
|||
|
|
@ -65,9 +65,9 @@ nmt_newt_dialog_g_log_handler (const char *log_domain,
|
|||
}
|
||||
|
||||
full_message = g_strdup_printf ("%s%s%s%s%s",
|
||||
log_domain ? log_domain : "",
|
||||
log_domain ?: "",
|
||||
log_domain && level_name ? " " : "",
|
||||
level_name ? level_name : "",
|
||||
level_name ?: "",
|
||||
log_domain || level_name ? ": " : "",
|
||||
message);
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ nmt_newt_dialog_g_log_handler (const char *log_domain,
|
|||
newtGridSetField (grid, 0, 1, NEWT_GRID_COMPONENT, ok, 0, 1, 0, 0,
|
||||
NEWT_ANCHOR_RIGHT, 0);
|
||||
|
||||
newtGridWrappedWindow (grid, (char *) (level_name ? level_name : ""));
|
||||
newtGridWrappedWindow (grid, (char *) (level_name ?: ""));
|
||||
newtGridFree (grid, TRUE);
|
||||
|
||||
form = newtForm (NULL, NULL, 0);
|
||||
|
|
|
|||
|
|
@ -307,7 +307,7 @@ add_connections_for_aps (NmtConnectDevice *nmtdev,
|
|||
}
|
||||
|
||||
if (!nmtconn->name)
|
||||
nmtconn->name = nmtconn->ssid ? nmtconn->ssid : "<unknown>";
|
||||
nmtconn->name = nmtconn->ssid ?: "<unknown>";
|
||||
|
||||
nmtdev->conns = g_slist_prepend (nmtdev->conns, nmtconn);
|
||||
}
|
||||
|
|
@ -376,7 +376,7 @@ append_nmt_devices_for_virtual_devices (GSList *nmt_devices,
|
|||
g_free (name);
|
||||
else {
|
||||
nmtdev = g_slice_new0 (NmtConnectDevice);
|
||||
nmtdev->name = name ? name : g_strdup ("Unknown");
|
||||
nmtdev->name = name ?: g_strdup("Unknown");
|
||||
nmtdev->sort_order = sort_order;
|
||||
|
||||
g_hash_table_insert (devices_by_name, nmtdev->name, nmtdev);
|
||||
|
|
@ -533,7 +533,7 @@ nmt_connect_connection_list_rebuild (NmtConnectConnectionList *list)
|
|||
nmtconn->name,
|
||||
(int)(max_width - nmt_newt_text_width (nmtconn->name)), "",
|
||||
strength_col ? " " : "",
|
||||
strength_col ? strength_col : "");
|
||||
strength_col ?: "");
|
||||
|
||||
nmt_newt_listbox_append (listbox, row, nmtconn);
|
||||
g_free (row);
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ struct Request {
|
|||
(_request)->request_id, \
|
||||
(_request)->action, \
|
||||
(_request)->iface ? " [" : "", \
|
||||
(_request)->iface ? (_request)->iface : "", \
|
||||
(_request)->iface ?: "", \
|
||||
(_request)->iface ? "]" : "", \
|
||||
(_script) ? ", \"" : "", \
|
||||
(_script) ? (_script)->script : "", \
|
||||
|
|
@ -297,7 +297,7 @@ complete_request (Request *request)
|
|||
g_variant_builder_add (&results, "(sus)",
|
||||
script->script,
|
||||
script->result,
|
||||
script->error ? script->error : "");
|
||||
script->error ?: "");
|
||||
}
|
||||
|
||||
ret = g_variant_new ("(a(sus))", &results);
|
||||
|
|
@ -537,9 +537,7 @@ script_dispatch (ScriptInfo *script)
|
|||
script->dispatched = TRUE;
|
||||
|
||||
argv[0] = script->script;
|
||||
argv[1] = request->iface
|
||||
? request->iface
|
||||
: (!strcmp (request->action, NMD_ACTION_HOSTNAME) ? "none" : "");
|
||||
argv[1] = request->iface ?: (!strcmp(request->action, NMD_ACTION_HOSTNAME) ? "none" : "");
|
||||
argv[2] = request->action;
|
||||
argv[3] = NULL;
|
||||
|
||||
|
|
|
|||
|
|
@ -543,7 +543,7 @@ test_generic (const char *file, const char *override_vpn_ip_iface)
|
|||
device_dhcp4_props,
|
||||
device_dhcp6_props,
|
||||
connectivity_change,
|
||||
override_vpn_ip_iface ? override_vpn_ip_iface : vpn_ip_iface,
|
||||
override_vpn_ip_iface ?: vpn_ip_iface,
|
||||
vpn_proxy_props,
|
||||
vpn_ip4_props,
|
||||
vpn_ip6_props,
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ show_wifi_device_info (NMDevice *device)
|
|||
speed /= 1000;
|
||||
|
||||
printf ("Device: %s ---- Driver: %s ---- Speed: %d Mbit/s ---- Active AP: %s\n",
|
||||
iface, driver, speed, active_ssid_str ? active_ssid_str : "none");
|
||||
iface, driver, speed, active_ssid_str ?: "none");
|
||||
printf ("=================================================================================\n");
|
||||
g_free (active_ssid_str);
|
||||
|
||||
|
|
|
|||
|
|
@ -1530,7 +1530,7 @@ nm_connection_update_secrets (NMConnection *connection,
|
|||
|
||||
g_signal_handlers_block_by_func (setting, (GCallback) setting_changed_cb, connection);
|
||||
success_detail = _nm_setting_update_secrets (setting,
|
||||
setting_dict ? setting_dict : secrets,
|
||||
setting_dict ?: secrets,
|
||||
error);
|
||||
g_signal_handlers_unblock_by_func (setting, (GCallback) setting_changed_cb, connection);
|
||||
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ nm_keyfile_plugin_kf_set_##stype##_list (GKeyFile *kf, \
|
|||
const char *alias; \
|
||||
\
|
||||
alias = nm_keyfile_plugin_get_alias_for_setting_name (group); \
|
||||
g_key_file_set_##stype##_list (kf, alias ? alias : group, key, list, length); \
|
||||
g_key_file_set_##stype##_list (kf, alias ?: group, key, list, length); \
|
||||
}
|
||||
|
||||
DEFINE_KF_LIST_WRAPPER(integer, gint*, gint);
|
||||
|
|
@ -170,7 +170,7 @@ nm_keyfile_plugin_kf_set_##stype (GKeyFile *kf, \
|
|||
const char *alias; \
|
||||
\
|
||||
alias = nm_keyfile_plugin_get_alias_for_setting_name (group); \
|
||||
g_key_file_set_##stype (kf, alias ? alias : group, key, value); \
|
||||
g_key_file_set_##stype (kf, alias ?: group, key, value); \
|
||||
}
|
||||
|
||||
DEFINE_KF_WRAPPER(string, gchar*, const gchar*);
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ setting_alias_parser (KeyfileReaderInfo *info, NMSetting *setting, const char *k
|
|||
if (s) {
|
||||
key_setting_name = nm_keyfile_plugin_get_setting_name_for_alias (s);
|
||||
g_object_set (G_OBJECT (setting),
|
||||
key, key_setting_name ? key_setting_name : s,
|
||||
key, key_setting_name ?: s,
|
||||
NULL);
|
||||
g_free (s);
|
||||
}
|
||||
|
|
@ -358,7 +358,7 @@ read_one_ip_address_or_route (KeyfileReaderInfo *info,
|
|||
gs_free char *value = NULL;
|
||||
gs_free char *value_orig = NULL;
|
||||
|
||||
#define VALUE_ORIG() (value_orig ? value_orig : (value_orig = nm_keyfile_plugin_kf_get_string (info->keyfile, setting_name, key_name, NULL)))
|
||||
#define VALUE_ORIG() (value_orig ?: (value_orig = nm_keyfile_plugin_kf_get_string (info->keyfile, setting_name, key_name, NULL)))
|
||||
|
||||
value = nm_keyfile_plugin_kf_get_string (info->keyfile, setting_name, key_name, NULL);
|
||||
if (!value)
|
||||
|
|
@ -1363,7 +1363,7 @@ parity_parser (KeyfileReaderInfo *info, NMSetting *setting, const char *key)
|
|||
default:
|
||||
handle_warn (info, key, NM_KEYFILE_WARN_SEVERITY_WARN,
|
||||
_("invalid parity value '%s'"),
|
||||
str_val ? str_val : "");
|
||||
str_val ?: "");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1506,7 +1506,7 @@ setting_alias_writer (KeyfileWriterInfo *info,
|
|||
nm_keyfile_plugin_kf_set_string (info->keyfile,
|
||||
nm_setting_get_name (setting),
|
||||
key,
|
||||
alias ? alias : str);
|
||||
alias ?: str);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
|
|||
NM_CONNECTION_ERROR,
|
||||
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
||||
_("'%s' is not a valid value for the property"),
|
||||
priv->protocol ? priv->protocol : "(null)");
|
||||
priv->protocol ?: "(null)");
|
||||
g_prefix_error (error, "%s.%s: ", NM_SETTING_ADSL_SETTING_NAME, NM_SETTING_ADSL_PROTOCOL);
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4318,7 +4318,7 @@ nm_utils_inet_ntop (int addr_family, gconstpointer addr, char *dst)
|
|||
|
||||
s = inet_ntop (addr_family,
|
||||
addr,
|
||||
dst ? dst : _nm_utils_inet_ntop_buffer,
|
||||
dst ?: _nm_utils_inet_ntop_buffer,
|
||||
addr_family == AF_INET6 ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN);
|
||||
nm_assert (s);
|
||||
return s;
|
||||
|
|
@ -4344,7 +4344,7 @@ nm_utils_inet_ntop (int addr_family, gconstpointer addr, char *dst)
|
|||
const char *
|
||||
nm_utils_inet4_ntop (in_addr_t inaddr, char *dst)
|
||||
{
|
||||
return inet_ntop (AF_INET, &inaddr, dst ? dst : _nm_utils_inet_ntop_buffer,
|
||||
return inet_ntop (AF_INET, &inaddr, dst ?: _nm_utils_inet_ntop_buffer,
|
||||
INET_ADDRSTRLEN);
|
||||
}
|
||||
|
||||
|
|
@ -4370,7 +4370,7 @@ const char *
|
|||
nm_utils_inet6_ntop (const struct in6_addr *in6addr, char *dst)
|
||||
{
|
||||
g_return_val_if_fail (in6addr, NULL);
|
||||
return inet_ntop (AF_INET6, in6addr, dst ? dst : _nm_utils_inet_ntop_buffer,
|
||||
return inet_ntop (AF_INET6, in6addr, dst ?: _nm_utils_inet_ntop_buffer,
|
||||
INET6_ADDRSTRLEN);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -674,7 +674,7 @@ nm_client_activate_connection (NMClient *client,
|
|||
activate_cb, info, NULL,
|
||||
DBUS_TYPE_G_OBJECT_PATH, connection ? nm_connection_get_path (connection) : "/",
|
||||
DBUS_TYPE_G_OBJECT_PATH, device ? nm_object_get_path (NM_OBJECT (device)) : "/",
|
||||
DBUS_TYPE_G_OBJECT_PATH, specific_object ? specific_object : "/",
|
||||
DBUS_TYPE_G_OBJECT_PATH, specific_object ?: "/",
|
||||
G_TYPE_INVALID);
|
||||
}
|
||||
|
||||
|
|
@ -762,7 +762,7 @@ nm_client_add_and_activate_connection (NMClient *client,
|
|||
add_activate_cb, info, NULL,
|
||||
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash,
|
||||
DBUS_TYPE_G_OBJECT_PATH, nm_object_get_path (NM_OBJECT (device)),
|
||||
DBUS_TYPE_G_OBJECT_PATH, specific_object ? specific_object : "/",
|
||||
DBUS_TYPE_G_OBJECT_PATH, specific_object ?: "/",
|
||||
G_TYPE_INVALID);
|
||||
} else
|
||||
info->idle_id = g_idle_add (activate_nm_not_running, info);
|
||||
|
|
@ -1257,8 +1257,8 @@ nm_client_set_logging (NMClient *client, const char *level, const char *domains,
|
|||
return TRUE;
|
||||
|
||||
return dbus_g_proxy_call (priv->client_proxy, "SetLogging", error,
|
||||
G_TYPE_STRING, level ? level : "",
|
||||
G_TYPE_STRING, domains ? domains : "",
|
||||
G_TYPE_STRING, level ?: "",
|
||||
G_TYPE_STRING, domains ?: "",
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_INVALID);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1328,7 +1328,7 @@ _nm_object_register_properties (NMObject *object,
|
|||
}
|
||||
|
||||
pi = g_malloc0 (sizeof (PropertyInfo));
|
||||
pi->func = tmp->func ? tmp->func : demarshal_generic;
|
||||
pi->func = tmp->func ?: demarshal_generic;
|
||||
pi->object_type = tmp->object_type;
|
||||
pi->field = tmp->field;
|
||||
pi->signal_prefix = tmp->signal_prefix;
|
||||
|
|
@ -1572,5 +1572,5 @@ _nm_object_new_proxy (NMObject *self, const char *path, const char *interface)
|
|||
{
|
||||
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
|
||||
|
||||
return _nm_dbus_new_proxy_for_connection (priv->connection, path ? path : priv->path, interface);
|
||||
return _nm_dbus_new_proxy_for_connection (priv->connection, path ?: priv->path, interface);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -576,7 +576,7 @@ fetch_connections_done (DBusGProxy *proxy,
|
|||
&& priv->service_running) {
|
||||
g_warning ("%s: error fetching connections: %s.",
|
||||
__func__,
|
||||
error->message ? error->message : "(unknown)");
|
||||
error->message ?: "(unknown)");
|
||||
}
|
||||
g_clear_error (&error);
|
||||
|
||||
|
|
@ -964,7 +964,7 @@ nm_remote_settings_save_hostname (NMRemoteSettings *settings,
|
|||
save_hostname_cb,
|
||||
info,
|
||||
g_free,
|
||||
G_TYPE_STRING, hostname ? hostname : "",
|
||||
G_TYPE_STRING, hostname ?: "",
|
||||
G_TYPE_INVALID);
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1020,7 +1020,7 @@ nm_connection_update_secrets (NMConnection *connection,
|
|||
|
||||
g_signal_handlers_block_by_func (setting, (GCallback) setting_changed_cb, connection);
|
||||
success_detail = _nm_setting_update_secrets (setting,
|
||||
setting_hash ? setting_hash : secrets,
|
||||
setting_hash ?: secrets,
|
||||
error);
|
||||
g_signal_handlers_unblock_by_func (setting, (GCallback) setting_changed_cb, connection);
|
||||
|
||||
|
|
|
|||
|
|
@ -226,7 +226,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
|
|||
NM_SETTING_ADSL_ERROR,
|
||||
NM_SETTING_ADSL_ERROR_INVALID_PROPERTY,
|
||||
_("'%s' is not a valid value for the property"),
|
||||
priv->protocol ? priv->protocol : "(null)");
|
||||
priv->protocol ?: "(null)");
|
||||
g_prefix_error (error, "%s.%s: ", NM_SETTING_ADSL_SETTING_NAME, NM_SETTING_ADSL_PROTOCOL);
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2474,7 +2474,7 @@ static char _nm_utils_inet_ntop_buffer[NM_UTILS_INET_ADDRSTRLEN];
|
|||
const char *
|
||||
nm_utils_inet4_ntop (in_addr_t inaddr, char *dst)
|
||||
{
|
||||
return inet_ntop (AF_INET, &inaddr, dst ? dst : _nm_utils_inet_ntop_buffer,
|
||||
return inet_ntop (AF_INET, &inaddr, dst ?: _nm_utils_inet_ntop_buffer,
|
||||
INET_ADDRSTRLEN);
|
||||
}
|
||||
|
||||
|
|
@ -2502,7 +2502,7 @@ const char *
|
|||
nm_utils_inet6_ntop (const struct in6_addr *in6addr, char *dst)
|
||||
{
|
||||
g_return_val_if_fail (in6addr, NULL);
|
||||
return inet_ntop (AF_INET6, in6addr, dst ? dst : _nm_utils_inet_ntop_buffer,
|
||||
return inet_ntop (AF_INET6, in6addr, dst ?: _nm_utils_inet_ntop_buffer,
|
||||
INET6_ADDRSTRLEN);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ _nm_utils_convert_string_list_to_string (const GValue *src_value, GValue *dest_v
|
|||
for (iter = strings; iter; iter = iter->next) {
|
||||
if (iter != strings)
|
||||
g_string_append_c (printable, ',');
|
||||
g_string_append (printable, iter->data ? iter->data : "(null)");
|
||||
g_string_append (printable, iter->data ?: "(null)");
|
||||
}
|
||||
|
||||
g_value_take_string (dest_value, g_string_free (printable, FALSE));
|
||||
|
|
|
|||
|
|
@ -1049,7 +1049,7 @@ nm_manager_activate_connection_async (NMManager *manager,
|
|||
nmdbus_manager_call_activate_connection (priv->proxy,
|
||||
connection ? nm_connection_get_path (connection) : "/",
|
||||
device ? nm_object_get_path (NM_OBJECT (device)) : "/",
|
||||
specific_object ? specific_object : "/",
|
||||
specific_object ?: "/",
|
||||
cancellable,
|
||||
activate_cb, info);
|
||||
}
|
||||
|
|
@ -1133,7 +1133,7 @@ nm_manager_add_and_activate_connection_async (NMManager *manager,
|
|||
nmdbus_manager_call_add_and_activate_connection (priv->proxy,
|
||||
dict,
|
||||
nm_object_get_path (NM_OBJECT (device)),
|
||||
specific_object ? specific_object : "/",
|
||||
specific_object ?: "/",
|
||||
cancellable,
|
||||
add_activate_cb, info);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -968,7 +968,7 @@ _nm_object_register_properties (NMObject *object,
|
|||
}
|
||||
|
||||
pi = g_malloc0 (sizeof (PropertyInfo));
|
||||
pi->func = tmp->func ? tmp->func : demarshal_generic;
|
||||
pi->func = tmp->func ?: demarshal_generic;
|
||||
pi->object_type = tmp->object_type;
|
||||
pi->field = tmp->field;
|
||||
pi->signal_prefix = tmp->signal_prefix;
|
||||
|
|
|
|||
|
|
@ -538,7 +538,7 @@ nm_remote_settings_save_hostname (NMRemoteSettings *settings,
|
|||
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
|
||||
|
||||
ret = nmdbus_settings_call_save_hostname_sync (priv->proxy,
|
||||
hostname ? hostname : "",
|
||||
hostname ?: "",
|
||||
cancellable, error);
|
||||
if (error && *error)
|
||||
g_dbus_error_strip_remote_error (*error);
|
||||
|
|
@ -583,7 +583,7 @@ nm_remote_settings_save_hostname_async (NMRemoteSettings *settings,
|
|||
g_simple_async_result_set_check_cancellable (simple, cancellable);
|
||||
|
||||
nmdbus_settings_call_save_hostname (priv->proxy,
|
||||
hostname ? hostname : "",
|
||||
hostname ?: "",
|
||||
cancellable, save_hostname_cb, simple);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -224,7 +224,7 @@ verify_sender (NMSecretAgentOld *self,
|
|||
NM_SECRET_AGENT_ERROR,
|
||||
NM_SECRET_AGENT_ERROR_PERMISSION_DENIED,
|
||||
"Failed to request unix user: (%s) %s.",
|
||||
remote_error ? remote_error : "",
|
||||
remote_error ?: "",
|
||||
local->message);
|
||||
g_free (remote_error);
|
||||
g_error_free (local);
|
||||
|
|
|
|||
272
man/nmcli.xml
272
man/nmcli.xml
|
|
@ -9,7 +9,7 @@
|
|||
<!--
|
||||
nmcli(1) manual page
|
||||
|
||||
Copyright 2010 - 2016 Red Hat, Inc.
|
||||
Copyright 2010 - 2018 Red Hat, Inc.
|
||||
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.1
|
||||
|
|
@ -183,6 +183,10 @@
|
|||
<literal>yes</literal> enables colors, <literal>no</literal> disables them,
|
||||
<literal>auto</literal> only produces colors when standard output is directed
|
||||
to a terminal. The default value is <literal>auto</literal>.</para>
|
||||
<para>The actual colors used are configured as described in
|
||||
<citerefentry><refentrytitle>terminal-colors.d</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
|
||||
Please refer to the <link linkend='colors' endterm='colors.title' /> section for a
|
||||
list of color names supported by <command>nmcli</command>.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
|
|
@ -2035,6 +2039,269 @@ It's equivalent to the <literal>+bond.options 'option=value'</literal> syntax.</
|
|||
|
||||
</refsect1>
|
||||
|
||||
<refsect1 id='colors'><title id='colors.title'>Colors</title>
|
||||
<para>Implicit coloring can be disabled by an empty file
|
||||
<filename>/etc/terminal-colors.d/nmcli.disable</filename>.</para>
|
||||
|
||||
<para>See <citerefentry><refentrytitle>terminal-colors.d</refentrytitle><manvolnum>5</manvolnum></citerefentry>
|
||||
for more details about colorization configuration.
|
||||
The logical color names supported by <command>nmcli</command> are:</para>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><option>connection-activated</option></term>
|
||||
<listitem>
|
||||
<para>A connection that is active.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>connection-activating</option></term>
|
||||
<listitem>
|
||||
<para>Connection that is being activated.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>connection-disconnecting</option></term>
|
||||
<listitem>
|
||||
<para>Connection that is being disconnected.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>connection-invisible</option></term>
|
||||
<listitem>
|
||||
<para>Connection whose details is the user not permitted to see.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>connectivity-full</option></term>
|
||||
<listitem>
|
||||
<para>Conectivity state when Internet is reachable.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>connectivity-limited</option></term>
|
||||
<listitem>
|
||||
<para>Conectivity state when only a local network reachable.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>connectivity-none</option></term>
|
||||
<listitem>
|
||||
<para>Conectivity state when the network is disconnected.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>connectivity-portal</option></term>
|
||||
<listitem>
|
||||
<para>Conectivity state when a captive portal hijacked the connection.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>connectivity-unknown</option></term>
|
||||
<listitem>
|
||||
<para>Conectivity state when a connectivity check didn't run.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>device-activated</option></term>
|
||||
<listitem>
|
||||
<para>Device that is connected.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>device-activating</option></term>
|
||||
<listitem>
|
||||
<para>Device that is being configured.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>device-disconnected</option></term>
|
||||
<listitem>
|
||||
<para>Device that is not connected.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>device-firmware-missing</option></term>
|
||||
<listitem>
|
||||
<para>Warning of a missing device firmware.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>device-plugin-missing</option></term>
|
||||
<listitem>
|
||||
<para>Warning of a missing device plugin.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>device-unavailable</option></term>
|
||||
<listitem>
|
||||
<para>Device that is not available for activation.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>manager-running</option></term>
|
||||
<listitem>
|
||||
<para>Notice that the NetworkManager daemon is available.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>manager-starting</option></term>
|
||||
<listitem>
|
||||
<para>Notice that the NetworkManager daemon is being initially connected.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>manager-stopped</option></term>
|
||||
<listitem>
|
||||
<para>Notice that the NetworkManager daemon is not available.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>permission-auth</option></term>
|
||||
<listitem>
|
||||
<para>An action that requires user authentication to get permission.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>permission-no</option></term>
|
||||
<listitem>
|
||||
<para>An action that is not permitted.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>permission-yes</option></term>
|
||||
<listitem>
|
||||
<para>An action that is permitted.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>prompt</option></term>
|
||||
<listitem>
|
||||
<para>Prompt in interactive mode.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>state-asleep</option></term>
|
||||
<listitem>
|
||||
<para>Indication that NetworkManager in suspended state.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>state-connected-global</option></term>
|
||||
<listitem>
|
||||
<para>Indication that NetworkManager in connected to Internet.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>state-connected-local</option></term>
|
||||
<listitem>
|
||||
<para>Indication that NetworkManager in local network.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>state-connected-site</option></term>
|
||||
<listitem>
|
||||
<para>Indication that NetworkManager in connected to networks other than Internet.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>state-connecting</option></term>
|
||||
<listitem>
|
||||
<para>Indication that NetworkManager is establishing a network connection.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>state-disconnected</option></term>
|
||||
<listitem>
|
||||
<para>Indication that NetworkManager is disconnected from a network.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>state-disconnecting</option></term>
|
||||
<listitem>
|
||||
<para>Indication that NetworkManager is being disconnected from a network.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>wifi-signal-excellent</option></term>
|
||||
<listitem>
|
||||
<para>Wi-Fi network with an excellent signal level.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>wifi-signal-fair</option></term>
|
||||
<listitem>
|
||||
<para>Wi-Fi network with a fair signal level.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>wifi-signal-good</option></term>
|
||||
<listitem>
|
||||
<para>Wi-Fi network with a good signal level.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>wifi-signal-poor</option></term>
|
||||
<listitem>
|
||||
<para>Wi-Fi network with a poor signal level.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>wifi-signal-unknown</option></term>
|
||||
<listitem>
|
||||
<para>Wi-Fi network that hasn't been actually seen (a hidden AP).</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>disabled</option></term>
|
||||
<listitem>
|
||||
<para>A property that is turned off.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>enabled</option></term>
|
||||
<listitem>
|
||||
<para>A property that is turned on.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 id='environment_variables'><title>Environment Variables</title>
|
||||
|
||||
<para><command>nmcli</command>'s behavior is affected by the following
|
||||
|
|
@ -2465,7 +2732,8 @@ It's equivalent to the <literal>+bond.options 'option=value'</literal> syntax.</
|
|||
<link linkend='NetworkManager.conf'><citerefentry><refentrytitle>NetworkManager.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry></link>,
|
||||
<link linkend='nm-settings'><citerefentry><refentrytitle>nm-settings</refentrytitle><manvolnum>5</manvolnum></citerefentry></link>,
|
||||
<citerefentry><refentrytitle>nm-applet</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>nm-connection-editor</refentrytitle><manvolnum>1</manvolnum></citerefentry>.</para>
|
||||
<citerefentry><refentrytitle>nm-connection-editor</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>terminal-colors.d</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
|
||||
</refsect1>
|
||||
|
||||
</refentry>
|
||||
|
|
|
|||
|
|
@ -191,6 +191,12 @@ void nm_utils_strbuf_append_str (char **buf, gsize *len, const char *str);
|
|||
|
||||
const char *nm_strquote (char *buf, gsize buf_len, const char *str);
|
||||
|
||||
static inline gboolean
|
||||
nm_utils_is_separator (const char c)
|
||||
{
|
||||
return NM_IN_SET (c, ' ', '\t');
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
const char **nm_utils_strsplit_set (const char *str, const char *delimiters);
|
||||
|
|
|
|||
|
|
@ -1138,7 +1138,7 @@ _nmtst_assert_ip4_address (const char *file, int line, in_addr_t addr, const cha
|
|||
char buf[100];
|
||||
|
||||
g_error ("%s:%d: Unexpected IPv4 address: expected %s, got %s",
|
||||
file, line, str_expected ? str_expected : "0.0.0.0",
|
||||
file, line, str_expected ?: "0.0.0.0",
|
||||
inet_ntop (AF_INET, &addr, buf, sizeof (buf)));
|
||||
}
|
||||
}
|
||||
|
|
@ -1156,7 +1156,7 @@ _nmtst_assert_ip6_address (const char *file, int line, const struct in6_addr *ad
|
|||
char buf[100];
|
||||
|
||||
g_error ("%s:%d: Unexpected IPv6 address: expected %s, got %s",
|
||||
file, line, str_expected ? str_expected : "::",
|
||||
file, line, str_expected ?: "::",
|
||||
inet_ntop (AF_INET6, addr, buf, sizeof (buf)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ handle_uevent (NMUdevClient *client,
|
|||
ifindex = udev_device_get_property_value (device, "IFINDEX");
|
||||
seqnum = udev_device_get_seqnum (device);
|
||||
nm_log_dbg (LOGD_PLATFORM, "UDEV event: action '%s' subsys '%s' device '%s' (%s); seqnum=%" G_GUINT64_FORMAT,
|
||||
action, subsys, udev_device_get_sysname (device), ifindex ? ifindex : "unknown", seqnum);
|
||||
action, subsys, udev_device_get_sysname (device), ifindex ?: "unknown", seqnum);
|
||||
|
||||
if (!strcmp (action, "add"))
|
||||
adsl_add (self, device);
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ br2684_assign_vcc (NMDeviceAdsl *self, NMSettingAdsl *s_adsl)
|
|||
|
||||
_LOGD (LOGD_ADSL, "assigning address %d.%d.%d encapsulation %s",
|
||||
priv->atm_index, addr.sap_addr.vpi, addr.sap_addr.vci,
|
||||
encapsulation ? encapsulation : "(none)");
|
||||
encapsulation ?: "(none)");
|
||||
|
||||
err = connect (priv->brfd, (struct sockaddr*) &addr, sizeof (addr));
|
||||
if (err != 0) {
|
||||
|
|
|
|||
|
|
@ -494,7 +494,7 @@ nm_bluez_device_disconnect (NMBluezDevice *self)
|
|||
priv->path,
|
||||
dbus_iface,
|
||||
"Disconnect",
|
||||
args ? args : g_variant_new ("()"),
|
||||
args ?: g_variant_new("()"),
|
||||
NULL,
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
10000,
|
||||
|
|
|
|||
|
|
@ -314,7 +314,7 @@ apply_bonding_config (NMDevice *device)
|
|||
|
||||
/* Primary */
|
||||
value = nm_setting_bond_get_option_by_name (s_bond, NM_SETTING_BOND_OPTION_PRIMARY);
|
||||
set_bond_attr (device, mode, NM_SETTING_BOND_OPTION_PRIMARY, value ? value : "");
|
||||
set_bond_attr (device, mode, NM_SETTING_BOND_OPTION_PRIMARY, value ?: "");
|
||||
|
||||
/* ARP targets: clear and initialize the list */
|
||||
contents = nm_platform_sysctl_master_get_option (nm_device_get_platform (device), ifindex,
|
||||
|
|
@ -591,7 +591,7 @@ reapply_connection (NMDevice *device, NMConnection *con_old, NMConnection *con_n
|
|||
|
||||
/* Primary */
|
||||
value = nm_setting_bond_get_option_by_name (s_bond, NM_SETTING_BOND_OPTION_PRIMARY);
|
||||
set_bond_attr (device, mode, NM_SETTING_BOND_OPTION_PRIMARY, value ? value : "");
|
||||
set_bond_attr (device, mode, NM_SETTING_BOND_OPTION_PRIMARY, value ?: "");
|
||||
|
||||
/* Active slave */
|
||||
set_simple_option (device, mode, s_bond, NM_SETTING_BOND_OPTION_ACTIVE_SLAVE);
|
||||
|
|
|
|||
|
|
@ -1357,7 +1357,7 @@ nm_device_get_ip_iface (NMDevice *self)
|
|||
|
||||
priv = NM_DEVICE_GET_PRIVATE (self);
|
||||
/* If it's not set, default to iface */
|
||||
return priv->ip_iface ? priv->ip_iface : priv->iface;
|
||||
return priv->ip_iface ?: priv->iface;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
|||
|
|
@ -363,7 +363,7 @@ _insert_interface (json_t *params, NMConnection *interface)
|
|||
json_pack ("{s:s, s:s, s:{s:s, s:s, s:o, s:[s, [[s, s]]]}, s:s}",
|
||||
"op", "insert", "table", "Interface", "row",
|
||||
"name", nm_connection_get_interface_name (interface),
|
||||
"type", type ? type : "",
|
||||
"type", type ?: "",
|
||||
"options", options,
|
||||
"external_ids", "map", "NM.connection.uuid", nm_connection_get_uuid (interface),
|
||||
"uuid-name", "rowInterface"));
|
||||
|
|
@ -891,7 +891,7 @@ ovsdb_got_update (NMOvsdb *self, json_t *msg)
|
|||
_LOGT ("removed an '%s' interface: %s%s%s",
|
||||
ovs_interface->type, ovs_interface->name,
|
||||
ovs_interface->connection_uuid ? ", " : "",
|
||||
ovs_interface->connection_uuid ? ovs_interface->connection_uuid : "");
|
||||
ovs_interface->connection_uuid ?: "");
|
||||
if (g_strcmp0 (ovs_interface->type, "internal") == 0) {
|
||||
/* Currently the factory only creates NMDevices for
|
||||
* internal interfaces. Ignore the rest. */
|
||||
|
|
@ -910,14 +910,14 @@ ovsdb_got_update (NMOvsdb *self, json_t *msg)
|
|||
if (old) {
|
||||
_LOGT ("changed an '%s' interface: %s%s%s", type, ovs_interface->name,
|
||||
ovs_interface->connection_uuid ? ", " : "",
|
||||
ovs_interface->connection_uuid ? ovs_interface->connection_uuid : "");
|
||||
ovs_interface->connection_uuid ?: "");
|
||||
g_signal_emit (self, signals[DEVICE_CHANGED], 0,
|
||||
"ovs-interface", ovs_interface->name);
|
||||
} else {
|
||||
_LOGT ("added an '%s' interface: %s%s%s",
|
||||
ovs_interface->type, ovs_interface->name,
|
||||
ovs_interface->connection_uuid ? ", " : "",
|
||||
ovs_interface->connection_uuid ? ovs_interface->connection_uuid : "");
|
||||
ovs_interface->connection_uuid ?: "");
|
||||
if (g_strcmp0 (ovs_interface->type, "internal") == 0) {
|
||||
/* Currently the factory only creates NMDevices for
|
||||
* internal interfaces. Ignore the rest. */
|
||||
|
|
@ -949,7 +949,7 @@ ovsdb_got_update (NMOvsdb *self, json_t *msg)
|
|||
old = FALSE;
|
||||
_LOGT ("removed a port: %s%s%s", ovs_port->name,
|
||||
ovs_port->connection_uuid ? ", " : "",
|
||||
ovs_port->connection_uuid ? ovs_port->connection_uuid : "");
|
||||
ovs_port->connection_uuid ?: "");
|
||||
g_signal_emit (self, signals[DEVICE_REMOVED], 0,
|
||||
ovs_port->name, NM_DEVICE_TYPE_OVS_PORT);
|
||||
}
|
||||
|
|
@ -965,13 +965,13 @@ ovsdb_got_update (NMOvsdb *self, json_t *msg)
|
|||
if (old) {
|
||||
_LOGT ("changed a port: %s%s%s", ovs_port->name,
|
||||
ovs_port->connection_uuid ? ", " : "",
|
||||
ovs_port->connection_uuid ? ovs_port->connection_uuid : "");
|
||||
ovs_port->connection_uuid ?: "");
|
||||
g_signal_emit (self, signals[DEVICE_CHANGED], 0,
|
||||
NM_SETTING_OVS_PORT_SETTING_NAME, ovs_port->name);
|
||||
} else {
|
||||
_LOGT ("added a port: %s%s%s", ovs_port->name,
|
||||
ovs_port->connection_uuid ? ", " : "",
|
||||
ovs_port->connection_uuid ? ovs_port->connection_uuid : "");
|
||||
ovs_port->connection_uuid ?: "");
|
||||
g_signal_emit (self, signals[DEVICE_ADDED], 0,
|
||||
ovs_port->name, NM_DEVICE_TYPE_OVS_PORT);
|
||||
}
|
||||
|
|
@ -999,7 +999,7 @@ ovsdb_got_update (NMOvsdb *self, json_t *msg)
|
|||
old = FALSE;
|
||||
_LOGT ("removed a bridge: %s%s%s", ovs_bridge->name,
|
||||
ovs_bridge->connection_uuid ? ", " : "",
|
||||
ovs_bridge->connection_uuid ? ovs_bridge->connection_uuid : "");
|
||||
ovs_bridge->connection_uuid ?: "");
|
||||
g_signal_emit (self, signals[DEVICE_REMOVED], 0,
|
||||
ovs_bridge->name, NM_DEVICE_TYPE_OVS_BRIDGE);
|
||||
}
|
||||
|
|
@ -1015,13 +1015,13 @@ ovsdb_got_update (NMOvsdb *self, json_t *msg)
|
|||
if (old) {
|
||||
_LOGT ("changed a bridge: %s%s%s", ovs_bridge->name,
|
||||
ovs_bridge->connection_uuid ? ", " : "",
|
||||
ovs_bridge->connection_uuid ? ovs_bridge->connection_uuid : "");
|
||||
ovs_bridge->connection_uuid ?: "");
|
||||
g_signal_emit (self, signals[DEVICE_CHANGED], 0,
|
||||
NM_SETTING_OVS_BRIDGE_SETTING_NAME, ovs_bridge->name);
|
||||
} else {
|
||||
_LOGT ("added a bridge: %s%s%s", ovs_bridge->name,
|
||||
ovs_bridge->connection_uuid ? ", " : "",
|
||||
ovs_bridge->connection_uuid ? ovs_bridge->connection_uuid : "");
|
||||
ovs_bridge->connection_uuid ?: "");
|
||||
g_signal_emit (self, signals[DEVICE_ADDED], 0,
|
||||
ovs_bridge->name, NM_DEVICE_TYPE_OVS_BRIDGE);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2147,9 +2147,9 @@ supplicant_iface_notify_current_bss (NMSupplicantInterface *iface,
|
|||
}
|
||||
|
||||
_LOGD (LOGD_WIFI, "roamed from BSSID %s (%s) to %s (%s)",
|
||||
old_bssid ? old_bssid : "(none)",
|
||||
old_bssid ?: "(none)",
|
||||
old_ssid ? nm_utils_escape_ssid (old_ssid->data, old_ssid->len) : "(none)",
|
||||
new_bssid ? new_bssid : "(none)",
|
||||
new_bssid ?: "(none)",
|
||||
new_ssid ? nm_utils_escape_ssid (new_ssid->data, new_ssid->len) : "(none)");
|
||||
|
||||
set_current_ap (self, new_ap, TRUE);
|
||||
|
|
|
|||
|
|
@ -286,7 +286,7 @@ create_gsm_connect_properties (NMConnection *connection)
|
|||
|
||||
/* Blank APN ("") means the default subscription APN */
|
||||
str = nm_setting_gsm_get_apn (setting);
|
||||
mm_simple_connect_properties_set_apn (properties, str ? str : "");
|
||||
mm_simple_connect_properties_set_apn (properties, str ?: "");
|
||||
|
||||
str = nm_setting_gsm_get_network_id (setting);
|
||||
if (str)
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ nm_modem_set_state (NMModem *self,
|
|||
_LOGI ("modem state changed, '%s' --> '%s' (reason: %s)",
|
||||
nm_modem_state_to_string (old_state),
|
||||
nm_modem_state_to_string (new_state),
|
||||
reason ? reason : "none");
|
||||
reason ?: "none");
|
||||
|
||||
priv->state = new_state;
|
||||
_notify (self, PROP_STATE);
|
||||
|
|
|
|||
|
|
@ -334,7 +334,7 @@ nm_dhcp_client_stop_pid (pid_t pid, const char *iface)
|
|||
|
||||
g_return_if_fail (pid > 1);
|
||||
|
||||
nm_utils_kill_child_sync (pid, SIGTERM, LOGD_DHCP, name ? name : "dhcp-client", NULL,
|
||||
nm_utils_kill_child_sync (pid, SIGTERM, LOGD_DHCP, name ?: "dhcp-client", NULL,
|
||||
1000 / 2, 1000 / 20);
|
||||
g_free (name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ _method_call_handle (NMDhcpListener *self,
|
|||
pid_str = get_option (options, "pid");
|
||||
pid = _nm_utils_ascii_str_to_int64 (pid_str, 10, 0, G_MAXINT32, -1);
|
||||
if (pid == -1) {
|
||||
_LOGW ("dhcp-event: couldn't convert PID '%s' to an integer", pid_str ? pid_str : "(null)");
|
||||
_LOGW ("dhcp-event: couldn't convert PID '%s' to an integer", pid_str ?: "(null)");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -311,7 +311,7 @@ nm_dhcp_manager_start_ip6 (NMDhcpManager *self,
|
|||
|
||||
if (send_hostname) {
|
||||
/* Always prefer the explicit dhcp-hostname if given */
|
||||
hostname = dhcp_hostname ? dhcp_hostname : priv->default_hostname;
|
||||
hostname = dhcp_hostname ?: priv->default_hostname;
|
||||
}
|
||||
return client_start (self, AF_INET6, multi_idx, iface, ifindex, hwaddr, uuid,
|
||||
route_table, route_metric, ll_addr,
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ do_early_setup (int *argc, char **argv[], NMConfigCmdLineOptions *config_cli)
|
|||
_("NetworkManager monitors all network connections and automatically\nchooses the best connection to use. It also allows the user to\nspecify wireless access points which wireless cards in the computer\nshould associate with.")))
|
||||
exit (1);
|
||||
|
||||
global_opt.pidfile = global_opt.pidfile ? global_opt.pidfile : g_strdup (NM_DEFAULT_PID_FILE);
|
||||
global_opt.pidfile = global_opt.pidfile ?: g_strdup(NM_DEFAULT_PID_FILE);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -579,7 +579,7 @@ ignore_config_snippet (GKeyFile *keyfile, gboolean is_base_config)
|
|||
const char *e;
|
||||
|
||||
e = g_getenv ("NM_CONFIG_ENABLE_TAG");
|
||||
_nm_config_match_env = g_strdup (e ? e : "");
|
||||
_nm_config_match_env = g_strdup (e ?: "");
|
||||
}
|
||||
|
||||
/* second, interpret the value as match-spec. */
|
||||
|
|
@ -2407,7 +2407,7 @@ _set_config_data (NMConfig *self, NMConfigData *new_data, NMConfigChangeFlags re
|
|||
else
|
||||
_LOGI ("signal: %s", nm_config_change_flags_to_string (changes, NULL, 0));
|
||||
g_signal_emit (self, signals[SIGNAL_CONFIG_CHANGED], 0,
|
||||
new_data ? new_data : old_data,
|
||||
new_data ?: old_data,
|
||||
changes, old_data);
|
||||
if (new_data)
|
||||
g_object_unref (old_data);
|
||||
|
|
|
|||
|
|
@ -2044,8 +2044,8 @@ _log_connection_sort_hashes_fcn (gconstpointer a, gconstpointer b)
|
|||
NMSettingPriority p1, p2;
|
||||
NMSetting *s1, *s2;
|
||||
|
||||
s1 = v1->setting ? v1->setting : v1->diff_base_setting;
|
||||
s2 = v2->setting ? v2->setting : v2->diff_base_setting;
|
||||
s1 = v1->setting ?: v1->diff_base_setting;
|
||||
s2 = v2->setting ?: v2->diff_base_setting;
|
||||
|
||||
g_assert (s1 && s2);
|
||||
|
||||
|
|
@ -2279,13 +2279,13 @@ nm_utils_log_connection_diff (NMConnection *connection,
|
|||
g_string_printf (str1, "%s.%s", setting_data->name, item->item_name);
|
||||
switch (item->diff_result & (NM_SETTING_DIFF_RESULT_IN_A | NM_SETTING_DIFF_RESULT_IN_B)) {
|
||||
case NM_SETTING_DIFF_RESULT_IN_B:
|
||||
nm_log (level, domain, NULL, NULL, "%s%"_NM_LOG_ALIGN"s < %s", prefix, str1->str, str_diff ? str_diff : "NULL");
|
||||
nm_log (level, domain, NULL, NULL, "%s%"_NM_LOG_ALIGN"s < %s", prefix, str1->str, str_diff ?: "NULL");
|
||||
break;
|
||||
case NM_SETTING_DIFF_RESULT_IN_A:
|
||||
nm_log (level, domain, NULL, NULL, "%s%"_NM_LOG_ALIGN"s = %s", prefix, str1->str, str_conn ? str_conn : "NULL");
|
||||
nm_log (level, domain, NULL, NULL, "%s%"_NM_LOG_ALIGN"s = %s", prefix, str1->str, str_conn ?: "NULL");
|
||||
break;
|
||||
default:
|
||||
nm_log (level, domain, NULL, NULL, "%s%"_NM_LOG_ALIGN"s = %s < %s", prefix, str1->str, str_conn ? str_conn : "NULL", str_diff ? str_diff : "NULL");
|
||||
nm_log (level, domain, NULL, NULL, "%s%"_NM_LOG_ALIGN"s = %s < %s", prefix, str1->str, str_conn ?: "NULL", str_diff ?: "NULL");
|
||||
break;
|
||||
#undef _NM_LOG_ALIGN
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ double nm_utils_exp10 (gint16 e);
|
|||
static inline guint32
|
||||
nm_utils_ip6_route_metric_normalize (guint32 metric)
|
||||
{
|
||||
return metric ? metric : 1024 /*NM_PLATFORM_ROUTE_METRIC_DEFAULT_IP6*/;
|
||||
return metric ?: 1024 /*NM_PLATFORM_ROUTE_METRIC_DEFAULT_IP6*/;
|
||||
}
|
||||
|
||||
static inline guint32
|
||||
|
|
|
|||
|
|
@ -547,7 +547,7 @@ _dispatcher_call (NMDispatcherAction action,
|
|||
|
||||
_LOGD ("(%u) (%s) dispatching action '%s'%s",
|
||||
reqid,
|
||||
vpn_iface ? vpn_iface : nm_device_get_iface (device),
|
||||
vpn_iface ?: nm_device_get_iface(device),
|
||||
action_to_string (action),
|
||||
blocking
|
||||
? " (blocking)"
|
||||
|
|
@ -650,7 +650,7 @@ _dispatcher_call (NMDispatcherAction action,
|
|||
device_dhcp4_props,
|
||||
device_dhcp6_props,
|
||||
connectivity_state_string,
|
||||
vpn_iface ? vpn_iface : "",
|
||||
vpn_iface ?: "",
|
||||
&vpn_proxy_props,
|
||||
&vpn_ip4_props,
|
||||
&vpn_ip6_props,
|
||||
|
|
@ -688,7 +688,7 @@ _dispatcher_call (NMDispatcherAction action,
|
|||
device_dhcp4_props,
|
||||
device_dhcp6_props,
|
||||
connectivity_state_string,
|
||||
vpn_iface ? vpn_iface : "",
|
||||
vpn_iface ?: "",
|
||||
&vpn_proxy_props,
|
||||
&vpn_ip4_props,
|
||||
&vpn_ip6_props,
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ _cb_info_create (NMFirewallManager *self,
|
|||
|
||||
if (priv->running || priv->proxy_cancellable) {
|
||||
info->mode_mutable = CB_INFO_MODE_DBUS_WAITING;
|
||||
info->dbus.arg = g_variant_new ("(ss)", zone ? zone : "", iface);
|
||||
info->dbus.arg = g_variant_new ("(ss)", zone ?: "", iface);
|
||||
} else
|
||||
info->mode_mutable = CB_INFO_MODE_IDLE;
|
||||
|
||||
|
|
|
|||
|
|
@ -6977,7 +6977,7 @@ get_property (GObject *object, guint prop_id,
|
|||
if (con)
|
||||
type = nm_connection_get_connection_type (con);
|
||||
}
|
||||
g_value_set_string (value, type ? type : "");
|
||||
g_value_set_string (value, type ?: "");
|
||||
break;
|
||||
case PROP_ACTIVATING_CONNECTION:
|
||||
nm_dbus_utils_g_value_set_object_path (value, priv->activating_connection);
|
||||
|
|
|
|||
|
|
@ -2119,7 +2119,7 @@ vpn_connection_retry_after_failure (NMVpnConnection *vpn, NMPolicy *self)
|
|||
&error)) {
|
||||
_LOGW (LOGD_DEVICE, "VPN '%s' reconnect failed: %s",
|
||||
nm_settings_connection_get_id (connection),
|
||||
error->message ? error->message : "unknown");
|
||||
error->message ?: "unknown");
|
||||
g_clear_error (&error);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -296,7 +296,7 @@ add_one_killswitch (NMRfkillManager *self, struct udev_device *device)
|
|||
rfkill_type_to_desc (rtype),
|
||||
ks->path,
|
||||
ks->platform ? "platform " : "",
|
||||
ks->driver ? ks->driver : "<unknown>");
|
||||
ks->driver ?: "<unknown>");
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -6980,7 +6980,7 @@ handle_udev_event (NMUdevClient *udev_client,
|
|||
seqnum = udev_device_get_seqnum (udevice);
|
||||
_LOGD ("UDEV event: action '%s' subsys '%s' device '%s' (%s); seqnum=%" G_GUINT64_FORMAT,
|
||||
action, subsys, udev_device_get_sysname (udevice),
|
||||
ifindex ? ifindex : "unknown", seqnum);
|
||||
ifindex ?: "unknown", seqnum);
|
||||
|
||||
if (NM_IN_STRSET (action, "add", "move"))
|
||||
udev_device_added (platform, udevice);
|
||||
|
|
|
|||
|
|
@ -4882,11 +4882,11 @@ nm_platform_link_to_string (const NMPlatformLink *link, char *buf, gsize len)
|
|||
link->inet6_addr_gen_mode_inv ? " addrgenmode " : "",
|
||||
link->inet6_addr_gen_mode_inv ? nm_platform_link_inet6_addrgenmode2str (_nm_platform_uint8_inv (link->inet6_addr_gen_mode_inv), str_addrmode, sizeof (str_addrmode)) : "",
|
||||
str_addr ? " addr " : "",
|
||||
str_addr ? str_addr : "",
|
||||
str_addr ?: "",
|
||||
link->inet6_token.id ? " inet6token " : "",
|
||||
link->inet6_token.id ? nm_utils_inet6_interface_identifier_to_token (link->inet6_token, str_inet6_token) : "",
|
||||
link->driver ? " driver " : "",
|
||||
link->driver ? link->driver : "",
|
||||
link->driver ?: "",
|
||||
link->rx_packets, link->rx_bytes,
|
||||
link->tx_packets, link->tx_bytes);
|
||||
g_string_free (str_flags, TRUE);
|
||||
|
|
@ -5298,7 +5298,7 @@ nm_platform_ip4_address_to_string (const NMPlatformIP4Address *address, char *bu
|
|||
str_label[0] = 0;
|
||||
|
||||
str_lft_p = _lifetime_to_string (address->timestamp,
|
||||
address->lifetime ? address->lifetime : NM_PLATFORM_LIFETIME_PERMANENT,
|
||||
address->lifetime ?: NM_PLATFORM_LIFETIME_PERMANENT,
|
||||
now, str_lft, sizeof (str_lft)),
|
||||
str_pref_p = (address->lifetime == address->preferred)
|
||||
? str_lft_p
|
||||
|
|
@ -5310,7 +5310,7 @@ nm_platform_ip4_address_to_string (const NMPlatformIP4Address *address, char *bu
|
|||
g_snprintf (buf, len,
|
||||
"%s/%d lft %s pref %s%s%s%s%s%s src %s",
|
||||
s_address, address->plen, str_lft_p, str_pref_p, str_time_p,
|
||||
str_peer ? str_peer : "",
|
||||
str_peer ?: "",
|
||||
str_dev,
|
||||
_to_string_ifa_flags (address->n_ifa_flags, s_flags, sizeof (s_flags)),
|
||||
str_label,
|
||||
|
|
@ -5405,7 +5405,7 @@ nm_platform_ip6_address_to_string (const NMPlatformIP6Address *address, char *bu
|
|||
_to_string_dev (NULL, address->ifindex, str_dev, sizeof (str_dev));
|
||||
|
||||
str_lft_p = _lifetime_to_string (address->timestamp,
|
||||
address->lifetime ? address->lifetime : NM_PLATFORM_LIFETIME_PERMANENT,
|
||||
address->lifetime ?: NM_PLATFORM_LIFETIME_PERMANENT,
|
||||
now, str_lft, sizeof (str_lft)),
|
||||
str_pref_p = (address->lifetime == address->preferred)
|
||||
? str_lft_p
|
||||
|
|
@ -5417,7 +5417,7 @@ nm_platform_ip6_address_to_string (const NMPlatformIP6Address *address, char *bu
|
|||
g_snprintf (buf, len,
|
||||
"%s/%d lft %s pref %s%s%s%s%s src %s",
|
||||
s_address, address->plen, str_lft_p, str_pref_p, str_time_p,
|
||||
str_peer ? str_peer : "",
|
||||
str_peer ?: "",
|
||||
str_dev,
|
||||
_to_string_ifa_flags (address->n_ifa_flags, s_flags, sizeof (s_flags)),
|
||||
nmp_utils_ip_config_source_to_string (address->addr_source, s_source, sizeof (s_source)));
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
#include "test-common.h"
|
||||
|
||||
#define SIGNAL_DATA_FMT "'%s-%s' ifindex %d%s%s%s (%d times received)"
|
||||
#define SIGNAL_DATA_ARG(data) (data)->name, nm_platform_signal_change_type_to_string ((data)->change_type), (data)->ifindex, (data)->ifname ? " ifname '" : "", (data)->ifname ? (data)->ifname : "", (data)->ifname ? "'" : "", (data)->received_count
|
||||
#define SIGNAL_DATA_ARG(data) (data)->name, nm_platform_signal_change_type_to_string ((data)->change_type), (data)->ifindex, (data)->ifname ? " ifname '" : "", (data)->ifname ?: "", (data)->ifname ? "'" : "", (data)->received_count
|
||||
|
||||
int NMTSTP_ENV1_IFINDEX = -1;
|
||||
int NMTSTP_ENV1_EX = -1;
|
||||
|
|
@ -1258,7 +1258,7 @@ nmtstp_link_gre_add (NMPlatform *platform,
|
|||
|
||||
success = !nmtstp_run_command ("ip tunnel add %s mode gre %s local %s remote %s ttl %u tos %02x %s",
|
||||
name,
|
||||
dev ? dev : "",
|
||||
dev ?: "",
|
||||
nm_utils_inet4_ntop (lnk->local, NULL),
|
||||
nm_utils_inet4_ntop (lnk->remote, buffer),
|
||||
lnk->ttl,
|
||||
|
|
@ -1568,7 +1568,7 @@ nmtstp_link_vxlan_add (NMPlatform *platform,
|
|||
err = nmtstp_run_command ("ip link add %s type vxlan id %u %s local %s group %s ttl %u tos %02x dstport %u srcport %u %u ageing %u",
|
||||
name,
|
||||
lnk->id,
|
||||
dev ? dev : "",
|
||||
dev ?: "",
|
||||
local,
|
||||
remote,
|
||||
lnk->ttl,
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ G_DEFINE_TYPE_WITH_CODE (NMSettingsConnection, nm_settings_connection, NM_TYPE_D
|
|||
const char *__uuid = (self) ? nm_settings_connection_get_uuid (self) : NULL; \
|
||||
\
|
||||
if (self) { \
|
||||
g_snprintf (__prefix, sizeof (__prefix), "%s[%p%s%s]", _NMLOG_PREFIX_NAME, self, __uuid ? "," : "", __uuid ? __uuid : ""); \
|
||||
g_snprintf (__prefix, sizeof (__prefix), "%s[%p%s%s]", _NMLOG_PREFIX_NAME, self, __uuid ? "," : "", __uuid ?: ""); \
|
||||
__p_prefix = __prefix; \
|
||||
} \
|
||||
_nm_log (__level, _NMLOG_DOMAIN, 0, NULL, __uuid, \
|
||||
|
|
@ -463,7 +463,7 @@ update_agent_secrets_cache (NMSettingsConnection *self, NMConnection *new)
|
|||
|
||||
if (priv->agent_secrets)
|
||||
g_object_unref (priv->agent_secrets);
|
||||
priv->agent_secrets = nm_simple_connection_new_clone (new ? new : NM_CONNECTION (self));
|
||||
priv->agent_secrets = nm_simple_connection_new_clone (new ?: NM_CONNECTION(self));
|
||||
|
||||
/* Clear out non-system-owned secrets */
|
||||
nm_connection_clear_secrets_with_flags (priv->agent_secrets,
|
||||
|
|
@ -1883,7 +1883,7 @@ settings_connection_update (NMSettingsConnection *self,
|
|||
* that's sending the update request. You can't make a connection
|
||||
* invisible to yourself.
|
||||
*/
|
||||
if (!nm_auth_is_subject_in_acl_set_error (tmp ? tmp : NM_CONNECTION (self),
|
||||
if (!nm_auth_is_subject_in_acl_set_error (tmp ?: NM_CONNECTION(self),
|
||||
subject,
|
||||
NM_SETTINGS_ERROR,
|
||||
NM_SETTINGS_ERROR_PERMISSION_DENIED,
|
||||
|
|
@ -1899,7 +1899,7 @@ settings_connection_update (NMSettingsConnection *self,
|
|||
info->new_settings = tmp;
|
||||
|
||||
permission = get_update_modify_permission (NM_CONNECTION (self),
|
||||
tmp ? tmp : NM_CONNECTION (self));
|
||||
tmp ?: NM_CONNECTION(self));
|
||||
auth_start (self, context, subject, permission, update_auth_cb, info);
|
||||
return;
|
||||
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ nms_ibft_reader_load_blocks (const char *iscsiadm_path,
|
|||
}
|
||||
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED,
|
||||
"iBFT: %s exited with error %d. Message: '%s'",
|
||||
iscsiadm_path, WEXITSTATUS (status), err ? err : "(none)");
|
||||
iscsiadm_path, WEXITSTATUS (status), err ?: "(none)");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -392,15 +392,15 @@ connection_setting_add (const GPtrArray *block,
|
|||
|
||||
id = g_strdup_printf ("iBFT%s%s %s",
|
||||
prefix ? " " : "",
|
||||
prefix ? prefix : "",
|
||||
prefix ?: "",
|
||||
iface);
|
||||
|
||||
uuid = _nm_utils_uuid_generate_from_strings ("ibft",
|
||||
s_hwaddr,
|
||||
s_vlanid ? "V" : "v",
|
||||
s_vlanid ? s_vlanid : "",
|
||||
s_vlanid ?: "",
|
||||
s_ip4addr ? "A" : "DHCP",
|
||||
s_ip4addr ? s_ip4addr : "",
|
||||
s_ip4addr ?: "",
|
||||
NULL);
|
||||
|
||||
s_con = nm_setting_connection_new ();
|
||||
|
|
|
|||
|
|
@ -418,7 +418,7 @@ ifcfg_dir_changed (GFileMonitor *monitor,
|
|||
path = g_file_get_path (file);
|
||||
|
||||
ifcfg_path = utils_detect_ifcfg_path (path, FALSE);
|
||||
_LOGD ("ifcfg_dir_changed(%s) = %d // %s", path, event_type, ifcfg_path ? ifcfg_path : "(none)");
|
||||
_LOGD ("ifcfg_dir_changed(%s) = %d // %s", path, event_type, ifcfg_path ?: "(none)");
|
||||
if (ifcfg_path) {
|
||||
connection = find_by_path (plugin, ifcfg_path);
|
||||
switch (event_type) {
|
||||
|
|
|
|||
|
|
@ -386,7 +386,7 @@ is_any_ip4_address_defined (shvarFile *ifcfg, int *idx)
|
|||
{
|
||||
int i, ignore, *ret_idx;
|
||||
|
||||
ret_idx = idx ? idx : &ignore;
|
||||
ret_idx = idx ?: &ignore;
|
||||
|
||||
for (i = -1; i <= 2; i++) {
|
||||
gs_free char *value = NULL;
|
||||
|
|
@ -502,7 +502,7 @@ parse_route_line_is_comment (const char *line)
|
|||
*
|
||||
* initscripts compares: "$line" =~ '^[[:space:]]*(\#.*)?$'
|
||||
*/
|
||||
while (NM_IN_SET (line[0], ' ', '\t'))
|
||||
while (nm_utils_is_separator (line[0]))
|
||||
line++;
|
||||
if (NM_IN_SET (line[0], '\0', '#'))
|
||||
return TRUE;
|
||||
|
|
@ -1847,8 +1847,8 @@ make_ip6_setting (shvarFile *ifcfg,
|
|||
ipv6addr_secondaries = svGetValueStr_cp (ifcfg, "IPV6ADDR_SECONDARIES");
|
||||
|
||||
value = g_strjoin (ipv6addr && ipv6addr_secondaries ? " " : NULL,
|
||||
ipv6addr ? ipv6addr : "",
|
||||
ipv6addr_secondaries ? ipv6addr_secondaries : "",
|
||||
ipv6addr ?: "",
|
||||
ipv6addr_secondaries ?: "",
|
||||
NULL);
|
||||
g_free (ipv6addr);
|
||||
g_free (ipv6addr_secondaries);
|
||||
|
|
@ -4524,9 +4524,9 @@ handle_bond_option (NMSettingBond *s_bond,
|
|||
}
|
||||
}
|
||||
|
||||
if (!nm_setting_bond_add_option (s_bond, key, sanitized ? sanitized : value))
|
||||
if (!nm_setting_bond_add_option (s_bond, key, sanitized ?: value))
|
||||
PARSE_WARNING ("invalid bonding option '%s' = %s",
|
||||
key, sanitized ? sanitized : value);
|
||||
key, sanitized ?: value);
|
||||
g_free (sanitized);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4590,7 +4590,7 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data)
|
|||
s_con = (NMSettingConnection *) nm_setting_connection_new ();
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_con));
|
||||
|
||||
id = g_strdup_printf ("Test Write Wired Static IP6 Only With Gateway %s", gateway6 ? gateway6 : "NULL");
|
||||
id = g_strdup_printf ("Test Write Wired Static IP6 Only With Gateway %s", gateway6 ?: "NULL");
|
||||
g_object_set (s_con,
|
||||
NM_SETTING_CONNECTION_ID, id,
|
||||
NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (),
|
||||
|
|
|
|||
|
|
@ -338,7 +338,7 @@ update_wireless_security_setting_from_if_block(NMConnection *connection,
|
|||
}
|
||||
|
||||
g_object_set(wireless_security_setting,
|
||||
newkey, typed_property_value ? typed_property_value : property_value,
|
||||
newkey, typed_property_value ?: property_value,
|
||||
NULL);
|
||||
security = TRUE;
|
||||
|
||||
|
|
@ -386,7 +386,7 @@ update_wireless_security_setting_from_if_block(NMConnection *connection,
|
|||
}
|
||||
|
||||
g_object_set(wireless_security_setting,
|
||||
newkey, typed_property_value ? typed_property_value : property_value,
|
||||
newkey, typed_property_value ?: property_value,
|
||||
NULL);
|
||||
security = TRUE;
|
||||
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ nm_supplicant_config_add_option_with_type (NMSupplicantConfig *self,
|
|||
memset (&buf[0], 0, sizeof (buf));
|
||||
memcpy (&buf[0], value, len > 254 ? 254 : len);
|
||||
g_set_error (error, NM_SUPPLICANT_ERROR, NM_SUPPLICANT_ERROR_CONFIG,
|
||||
"key '%s' and/or value '%s' invalid", key, hidden ? hidden : buf);
|
||||
"key '%s' and/or value '%s' invalid", key, hidden ?: buf);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
|
@ -168,7 +168,7 @@ nm_supplicant_config_add_option_with_type (NMSupplicantConfig *self,
|
|||
char buf[255];
|
||||
memset (&buf[0], 0, sizeof (buf));
|
||||
memcpy (&buf[0], opt->value, opt->len > 254 ? 254 : opt->len);
|
||||
nm_log_info (LOGD_SUPPLICANT, "Config: added '%s' value '%s'", key, hidden ? hidden : &buf[0]);
|
||||
nm_log_info (LOGD_SUPPLICANT, "Config: added '%s' value '%s'", key, hidden ?: &buf[0]);
|
||||
}
|
||||
|
||||
g_hash_table_insert (priv->config, g_strdup (key), opt);
|
||||
|
|
@ -979,7 +979,7 @@ add_pkcs11_uri_with_pin (NMSupplicantConfig *self,
|
|||
|
||||
tmp = g_strdup_printf ("%s%s%s", split[0],
|
||||
(pin_qattr ? "?" : ""),
|
||||
(pin_qattr ? pin_qattr : ""));
|
||||
(pin_qattr ?: ""));
|
||||
|
||||
tmp_log = g_strdup_printf ("%s%s%s", split[0],
|
||||
(pin_qattr ? "?" : ""),
|
||||
|
|
@ -1171,7 +1171,7 @@ nm_supplicant_config_add_setting_8021x (NMSupplicantConfig *self,
|
|||
|
||||
/* CA path */
|
||||
path = nm_setting_802_1x_get_ca_path (setting);
|
||||
path = ca_path_override ? ca_path_override : path;
|
||||
path = ca_path_override ?: path;
|
||||
if (path) {
|
||||
if (!add_string_val (self, path, "ca_path", FALSE, NULL, error))
|
||||
return FALSE;
|
||||
|
|
@ -1179,7 +1179,7 @@ nm_supplicant_config_add_setting_8021x (NMSupplicantConfig *self,
|
|||
|
||||
/* Phase2 CA path */
|
||||
path = nm_setting_802_1x_get_phase2_ca_path (setting);
|
||||
path = ca_path_override ? ca_path_override : path;
|
||||
path = ca_path_override ?: path;
|
||||
if (path) {
|
||||
if (!add_string_val (self, path, "ca_path2", FALSE, NULL, error))
|
||||
return FALSE;
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ validate_type_bytes (const struct Opt * opt,
|
|||
g_return_val_if_fail (opt != NULL, FALSE);
|
||||
g_return_val_if_fail (value != NULL, FALSE);
|
||||
|
||||
check_len = opt->int_high ? opt->int_high : 255;
|
||||
check_len = opt->int_high ?: 255;
|
||||
if (len > check_len)
|
||||
return FALSE;
|
||||
|
||||
|
|
@ -204,7 +204,7 @@ validate_type_utf8 (const struct Opt *opt,
|
|||
g_return_val_if_fail (opt != NULL, FALSE);
|
||||
g_return_val_if_fail (value != NULL, FALSE);
|
||||
|
||||
check_len = opt->int_high ? opt->int_high : 255;
|
||||
check_len = opt->int_high ?: 255;
|
||||
/* Note that we deliberately don't validate the UTF-8, because
|
||||
some "UTF-8" fields, such as 8021x.password, do not actually
|
||||
have to be valid UTF-8 */
|
||||
|
|
|
|||
|
|
@ -1022,7 +1022,7 @@ print_vpn_config (NMVpnConnection *self)
|
|||
if (nm_ip4_config_get_num_domains (priv->ip4_config) > 0)
|
||||
dns_domain = (char *) nm_ip4_config_get_domain (priv->ip4_config, 0);
|
||||
|
||||
_LOGI ("Data: DNS Domain: '%s'", dns_domain ? dns_domain : "(none)");
|
||||
_LOGI ("Data: DNS Domain: '%s'", dns_domain ?: "(none)");
|
||||
} else
|
||||
_LOGI ("Data: No IPv4 configuration");
|
||||
|
||||
|
|
@ -1056,7 +1056,7 @@ print_vpn_config (NMVpnConnection *self)
|
|||
if (nm_ip6_config_get_num_domains (priv->ip6_config) > 0)
|
||||
dns_domain = (char *) nm_ip6_config_get_domain (priv->ip6_config, 0);
|
||||
|
||||
_LOGI ("Data: DNS Domain: '%s'", dns_domain ? dns_domain : "(none)");
|
||||
_LOGI ("Data: DNS Domain: '%s'", dns_domain ?: "(none)");
|
||||
} else
|
||||
_LOGI ("Data: No IPv6 configuration");
|
||||
|
||||
|
|
@ -2821,7 +2821,7 @@ get_property (GObject *object, guint prop_id,
|
|||
g_value_set_uint (value, _state_to_nm_vpn_state (priv->vpn_state));
|
||||
break;
|
||||
case PROP_BANNER:
|
||||
g_value_set_string (value, priv->banner ? priv->banner : "");
|
||||
g_value_set_string (value, priv->banner ?: "");
|
||||
break;
|
||||
case PROP_IP4_CONFIG:
|
||||
nm_dbus_utils_g_value_set_object_path (value, ip_config_valid (priv->vpn_state) ? priv->ip4_config : NULL);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue