mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-31 23:00:11 +01:00
cli: merge branch 'th/cli-meta-2'
This commit is contained in:
commit
8acb2b1151
23 changed files with 4504 additions and 2316 deletions
|
|
@ -36,19 +36,122 @@
|
|||
|
||||
#include "utils.h"
|
||||
|
||||
extern GMainLoop *loop;
|
||||
/*****************************************************************************/
|
||||
|
||||
const NmcMetaGenericInfo *const nmc_fields_ip4_config[] = {
|
||||
NMC_META_GENERIC ("GROUP"), /* 0 */
|
||||
NMC_META_GENERIC ("ADDRESS"), /* 1 */
|
||||
NMC_META_GENERIC ("GATEWAY"), /* 2 */
|
||||
NMC_META_GENERIC ("ROUTE"), /* 3 */
|
||||
NMC_META_GENERIC ("DNS"), /* 4 */
|
||||
NMC_META_GENERIC ("DOMAIN"), /* 5 */
|
||||
NMC_META_GENERIC ("WINS"), /* 6 */
|
||||
static gconstpointer
|
||||
_metagen_ip4_config_get_fcn (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NmcMetaGenericInfo *info,
|
||||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gpointer *out_to_free)
|
||||
{
|
||||
NMIPConfig *cfg4 = target;
|
||||
GPtrArray *ptr_array;
|
||||
char **arr;
|
||||
const char *const*arrc;
|
||||
guint i = 0;
|
||||
|
||||
nm_assert (info->info_type < _NMC_GENERIC_INFO_TYPE_IP4_CONFIG_NUM);
|
||||
|
||||
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
|
||||
|
||||
switch (info->info_type) {
|
||||
case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ADDRESS:
|
||||
if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV))
|
||||
return NULL;
|
||||
ptr_array = nm_ip_config_get_addresses (cfg4);
|
||||
if (ptr_array) {
|
||||
arr = g_new (char *, ptr_array->len + 1);
|
||||
for (i = 0; i < ptr_array->len; i++) {
|
||||
NMIPAddress *addr = g_ptr_array_index (ptr_array, i);
|
||||
|
||||
arr[i] = g_strdup_printf ("%s/%u",
|
||||
nm_ip_address_get_address (addr),
|
||||
nm_ip_address_get_prefix (addr));
|
||||
}
|
||||
arr[i] = NULL;
|
||||
} else
|
||||
arr = NULL;
|
||||
goto arr_out;
|
||||
case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_GATEWAY:
|
||||
return nm_ip_config_get_gateway (cfg4);
|
||||
case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ROUTE:
|
||||
if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV))
|
||||
return NULL;
|
||||
ptr_array = nm_ip_config_get_routes (cfg4);
|
||||
if (ptr_array) {
|
||||
arr = g_new (char *, ptr_array->len + 1);
|
||||
for (i = 0; i < ptr_array->len; i++) {
|
||||
NMIPRoute *route = g_ptr_array_index (ptr_array, i);
|
||||
const char *next_hop;
|
||||
|
||||
next_hop = nm_ip_route_get_next_hop (route);
|
||||
if (!next_hop)
|
||||
next_hop = "0.0.0.0";
|
||||
|
||||
arr[i] = g_strdup_printf ("dst = %s/%u, nh = %s%c mt = %u",
|
||||
nm_ip_route_get_dest (route),
|
||||
nm_ip_route_get_prefix (route),
|
||||
next_hop,
|
||||
nm_ip_route_get_metric (route) == -1 ? '\0' : ',',
|
||||
(guint32) nm_ip_route_get_metric (route));
|
||||
}
|
||||
arr[i] = NULL;
|
||||
} else
|
||||
arr = NULL;
|
||||
goto arr_out;
|
||||
case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DNS:
|
||||
if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV))
|
||||
return NULL;
|
||||
arrc = nm_ip_config_get_nameservers (cfg4);
|
||||
goto arrc_out;
|
||||
case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DOMAIN:
|
||||
if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV))
|
||||
return NULL;
|
||||
arrc = nm_ip_config_get_domains (cfg4);
|
||||
goto arrc_out;
|
||||
case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_WINS:
|
||||
if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV))
|
||||
return NULL;
|
||||
arrc = nm_ip_config_get_wins_servers (cfg4);
|
||||
goto arrc_out;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
g_return_val_if_reached (NULL);
|
||||
|
||||
arrc_out:
|
||||
*out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV;
|
||||
return arrc;
|
||||
|
||||
arr_out:
|
||||
*out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV;
|
||||
*out_to_free = arr;
|
||||
return arr;
|
||||
}
|
||||
|
||||
const NmcMetaGenericInfo *const metagen_ip4_config[_NMC_GENERIC_INFO_TYPE_IP4_CONFIG_NUM + 1] = {
|
||||
#define _METAGEN_IP4_CONFIG(type, name) \
|
||||
[type] = NMC_META_GENERIC(name, .info_type = type, .get_fcn = _metagen_ip4_config_get_fcn)
|
||||
_METAGEN_IP4_CONFIG (NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ADDRESS, "ADDRESS"),
|
||||
_METAGEN_IP4_CONFIG (NMC_GENERIC_INFO_TYPE_IP4_CONFIG_GATEWAY, "GATEWAY"),
|
||||
_METAGEN_IP4_CONFIG (NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ROUTE, "ROUTE"),
|
||||
_METAGEN_IP4_CONFIG (NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DNS, "DNS"),
|
||||
_METAGEN_IP4_CONFIG (NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DOMAIN, "DOMAIN"),
|
||||
_METAGEN_IP4_CONFIG (NMC_GENERIC_INFO_TYPE_IP4_CONFIG_WINS, "WINS"),
|
||||
};
|
||||
|
||||
static const NmcMetaGenericInfo *const metagen_ip4_config_group[] = {
|
||||
NMC_META_GENERIC_WITH_NESTED ("IP4", metagen_ip4_config, .name_header = N_("GROUP")),
|
||||
NULL,
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
const NmcMetaGenericInfo *const nmc_fields_dhcp4_config[] = {
|
||||
NMC_META_GENERIC ("GROUP"), /* 0 */
|
||||
NMC_META_GENERIC ("OPTION"), /* 1 */
|
||||
|
|
@ -74,87 +177,25 @@ const NmcMetaGenericInfo *const nmc_fields_dhcp6_config[] = {
|
|||
gboolean
|
||||
print_ip4_config (NMIPConfig *cfg4,
|
||||
const NmcConfig *nmc_config,
|
||||
const char *group_prefix,
|
||||
const char *one_field)
|
||||
{
|
||||
GPtrArray *ptr_array;
|
||||
char **addr_arr = NULL;
|
||||
char **route_arr = NULL;
|
||||
char **dns_arr = NULL;
|
||||
char **domain_arr = NULL;
|
||||
char **wins_arr = NULL;
|
||||
int i = 0;
|
||||
const NMMetaAbstractInfo *const*tmpl;
|
||||
NmcOutputField *arr;
|
||||
NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
|
||||
gs_free_error GError *error = NULL;
|
||||
gs_free char *field_str = NULL;
|
||||
|
||||
if (cfg4 == NULL)
|
||||
return FALSE;
|
||||
|
||||
tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_ip4_config;
|
||||
out_indices = parse_output_fields (one_field,
|
||||
tmpl, FALSE, NULL, NULL);
|
||||
arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_FIELD_NAMES);
|
||||
g_ptr_array_add (out.output_data, arr);
|
||||
if (one_field)
|
||||
field_str = g_strdup_printf ("IP4.%s", one_field);
|
||||
|
||||
/* addresses */
|
||||
ptr_array = nm_ip_config_get_addresses (cfg4);
|
||||
if (ptr_array) {
|
||||
addr_arr = g_new (char *, ptr_array->len + 1);
|
||||
for (i = 0; i < ptr_array->len; i++) {
|
||||
NMIPAddress *addr = (NMIPAddress *) g_ptr_array_index (ptr_array, i);
|
||||
|
||||
addr_arr[i] = g_strdup_printf ("%s/%u",
|
||||
nm_ip_address_get_address (addr),
|
||||
nm_ip_address_get_prefix (addr));
|
||||
}
|
||||
addr_arr[i] = NULL;
|
||||
if (!nmc_print (nmc_config,
|
||||
(gpointer[]) { cfg4, NULL },
|
||||
NULL,
|
||||
(const NMMetaAbstractInfo *const*) metagen_ip4_config_group,
|
||||
field_str,
|
||||
&error)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* routes */
|
||||
ptr_array = nm_ip_config_get_routes (cfg4);
|
||||
if (ptr_array) {
|
||||
route_arr = g_new (char *, ptr_array->len + 1);
|
||||
for (i = 0; i < ptr_array->len; i++) {
|
||||
NMIPRoute *route = (NMIPRoute *) g_ptr_array_index (ptr_array, i);
|
||||
const char *next_hop;
|
||||
|
||||
next_hop = nm_ip_route_get_next_hop (route);
|
||||
if (!next_hop)
|
||||
next_hop = "0.0.0.0";
|
||||
|
||||
route_arr[i] = g_strdup_printf ("dst = %s/%u, nh = %s%c mt = %u",
|
||||
nm_ip_route_get_dest (route),
|
||||
nm_ip_route_get_prefix (route),
|
||||
next_hop,
|
||||
nm_ip_route_get_metric (route) == -1 ? '\0' : ',',
|
||||
(guint32) nm_ip_route_get_metric (route));
|
||||
}
|
||||
route_arr[i] = NULL;
|
||||
}
|
||||
|
||||
/* DNS */
|
||||
dns_arr = g_strdupv ((char **) nm_ip_config_get_nameservers (cfg4));
|
||||
|
||||
/* domains */
|
||||
domain_arr = g_strdupv ((char **) nm_ip_config_get_domains (cfg4));
|
||||
|
||||
/* WINS */
|
||||
wins_arr = g_strdupv ((char **) nm_ip_config_get_wins_servers (cfg4));
|
||||
|
||||
arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_SECTION_PREFIX);
|
||||
set_val_strc (arr, 0, group_prefix);
|
||||
set_val_arr (arr, 1, addr_arr);
|
||||
set_val_strc (arr, 2, nm_ip_config_get_gateway (cfg4));
|
||||
set_val_arr (arr, 3, route_arr);
|
||||
set_val_arr (arr, 4, dns_arr);
|
||||
set_val_arr (arr, 5, domain_arr);
|
||||
set_val_arr (arr, 6, wins_arr);
|
||||
g_ptr_array_add (out.output_data, arr);
|
||||
|
||||
print_data_prepare_width (out.output_data);
|
||||
print_data (nmc_config, out_indices, NULL, 0, &out);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -840,7 +881,7 @@ nmc_secrets_requested (NMSecretAgentSimple *agent,
|
|||
}
|
||||
|
||||
success = get_secrets_from_user (request_id, title, msg, connection, nmc->nmc_config.in_editor || nmc->ask,
|
||||
nmc->show_secrets, nmc->pwds_hash, secrets);
|
||||
nmc->nmc_config.show_secrets, nmc->pwds_hash, secrets);
|
||||
if (success)
|
||||
nm_secret_agent_simple_response (agent, request_id, secrets);
|
||||
else {
|
||||
|
|
@ -1085,6 +1126,38 @@ nmc_rl_gen_func_basic (const char *text, int state, const char *const*words)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static struct {
|
||||
bool initialized;
|
||||
guint idx;
|
||||
char **values;
|
||||
} _rl_compentry_func_wrap = { 0 };
|
||||
|
||||
static char *
|
||||
_rl_compentry_func_wrap_fcn (const char *text, int state)
|
||||
{
|
||||
g_return_val_if_fail (_rl_compentry_func_wrap.initialized, NULL);
|
||||
|
||||
if ( !_rl_compentry_func_wrap.values
|
||||
|| !_rl_compentry_func_wrap.values[_rl_compentry_func_wrap.idx]) {
|
||||
g_strfreev (_rl_compentry_func_wrap.values);
|
||||
_rl_compentry_func_wrap.values = NULL;
|
||||
_rl_compentry_func_wrap.initialized = FALSE;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return g_strdup (_rl_compentry_func_wrap.values[_rl_compentry_func_wrap.idx++]);
|
||||
}
|
||||
|
||||
NmcCompEntryFunc
|
||||
nmc_rl_compentry_func_wrap (const char *const*values)
|
||||
{
|
||||
g_strfreev (_rl_compentry_func_wrap.values);
|
||||
_rl_compentry_func_wrap.values = g_strdupv ((char **) values);
|
||||
_rl_compentry_func_wrap.idx = 0;
|
||||
_rl_compentry_func_wrap.initialized = TRUE;
|
||||
return _rl_compentry_func_wrap_fcn;
|
||||
}
|
||||
|
||||
char *
|
||||
nmc_rl_gen_func_ifnames (const char *text, int state)
|
||||
{
|
||||
|
|
@ -1170,8 +1243,6 @@ nmc_parse_lldp_capabilities (guint value)
|
|||
return g_string_free (str, FALSE);
|
||||
}
|
||||
|
||||
extern GMainLoop *loop;
|
||||
|
||||
static void
|
||||
command_done (GObject *object, GAsyncResult *res, gpointer user_data)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
#include "nmcli.h"
|
||||
#include "nm-secret-agent-simple.h"
|
||||
|
||||
gboolean print_ip4_config (NMIPConfig *cfg4, const NmcConfig *nmc_config, const char *group_prefix, const char *one_field);
|
||||
gboolean print_ip4_config (NMIPConfig *cfg4, const NmcConfig *nmc_config, const char *one_field);
|
||||
gboolean print_ip6_config (NMIPConfig *cfg6, const NmcConfig *nmc_config, const char *group_prefix, const char *one_field);
|
||||
gboolean print_dhcp4_config (NMDhcpConfig *dhcp4, const NmcConfig *nmc_config, const char *group_prefix, const char *one_field);
|
||||
gboolean print_dhcp6_config (NMDhcpConfig *dhcp6, const NmcConfig *nmc_config, const char *group_prefix, const char *one_field);
|
||||
|
|
@ -53,6 +53,7 @@ char *nmc_unique_connection_name (const GPtrArray *connections,
|
|||
void nmc_cleanup_readline (void);
|
||||
char *nmc_readline (const char *prompt_fmt, ...) G_GNUC_PRINTF (1, 2);
|
||||
char *nmc_readline_echo (gboolean echo_on, const char *prompt_fmt, ...) G_GNUC_PRINTF (2, 3);
|
||||
NmcCompEntryFunc nmc_rl_compentry_func_wrap (const char *const*values);
|
||||
char *nmc_rl_gen_func_basic (const char *text, int state, const char *const*words);
|
||||
char *nmc_rl_gen_func_ifnames (const char *text, int state);
|
||||
gboolean nmc_get_in_readline (void);
|
||||
|
|
@ -80,7 +81,7 @@ void nmc_complete_bool (const char *prefix);
|
|||
|
||||
const char *nmc_error_get_simple_message (GError *error);
|
||||
|
||||
extern const NmcMetaGenericInfo *const nmc_fields_ip4_config[];
|
||||
extern const NmcMetaGenericInfo *const metagen_ip4_config[];
|
||||
extern const NmcMetaGenericInfo *const nmc_fields_dhcp4_config[];
|
||||
extern const NmcMetaGenericInfo *const nmc_fields_ip6_config[];
|
||||
extern const NmcMetaGenericInfo *const nmc_fields_dhcp6_config[];
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -208,7 +208,7 @@ const NmcMetaGenericInfo *const nmc_fields_dev_show_sections[] = {
|
|||
NMC_META_GENERIC_WITH_NESTED ("WIRED-PROPERTIES", nmc_fields_dev_show_wired_prop + 1), /* 4 */
|
||||
NMC_META_GENERIC_WITH_NESTED ("WIMAX-PROPERTIES", nmc_fields_dev_show_wimax_prop + 1), /* 5 */
|
||||
NMC_META_GENERIC_WITH_NESTED ("NSP", nmc_fields_dev_wimax_list + 1), /* 6 */
|
||||
NMC_META_GENERIC_WITH_NESTED ("IP4", nmc_fields_ip4_config + 1), /* 7 */
|
||||
NMC_META_GENERIC_WITH_NESTED ("IP4", metagen_ip4_config), /* 7 */
|
||||
NMC_META_GENERIC_WITH_NESTED ("DHCP4", nmc_fields_dhcp4_config + 1), /* 8 */
|
||||
NMC_META_GENERIC_WITH_NESTED ("IP6", nmc_fields_ip6_config + 1), /* 9 */
|
||||
NMC_META_GENERIC_WITH_NESTED ("DHCP6", nmc_fields_dhcp6_config + 1), /* 10 */
|
||||
|
|
@ -245,9 +245,6 @@ const NmcMetaGenericInfo *const nmc_fields_dev_lldp_list[] = {
|
|||
#define NMC_FIELDS_DEV_LLDP_LIST_COMMON "DEVICE,CHASSIS-ID,PORT-ID,PORT-DESCRIPTION,SYSTEM-NAME,SYSTEM-DESCRIPTION," \
|
||||
"SYSTEM-CAPABILITIES"
|
||||
|
||||
/* glib main loop variable - defined in nmcli.c */
|
||||
extern GMainLoop *loop;
|
||||
|
||||
static guint progress_id = 0; /* ID of event source for displaying progress */
|
||||
|
||||
static void
|
||||
|
|
@ -450,7 +447,6 @@ usage_device_lldp (void)
|
|||
"used to list neighbors for a particular interface.\n\n"));
|
||||
}
|
||||
|
||||
/* quit main loop */
|
||||
static void
|
||||
quit (void)
|
||||
{
|
||||
|
|
@ -459,7 +455,7 @@ quit (void)
|
|||
nmc_terminal_erase_line ();
|
||||
}
|
||||
|
||||
g_main_loop_quit (loop); /* quit main loop */
|
||||
g_main_loop_quit (loop);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -1273,7 +1269,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||
|
||||
/* IP4 */
|
||||
if (cfg4 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[7]->name))
|
||||
was_output = print_ip4_config (cfg4, &nmc->nmc_config, nmc_fields_dev_show_sections[7]->name, section_fld);
|
||||
was_output = print_ip4_config (cfg4, &nmc->nmc_config, section_fld);
|
||||
|
||||
/* DHCP4 */
|
||||
if (dhcp4 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[8]->name))
|
||||
|
|
@ -3110,7 +3106,7 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv)
|
|||
if (ap_flags & NM_802_11_AP_FLAGS_PRIVACY) {
|
||||
/* Ask for missing password when one is expected and '--ask' is used */
|
||||
if (!password && nmc->ask)
|
||||
password = passwd_ask = nmc_readline_echo (nmc->show_secrets, _("Password: "));
|
||||
password = passwd_ask = nmc_readline_echo (nmc->nmc_config.show_secrets, _("Password: "));
|
||||
|
||||
if (password) {
|
||||
if (!connection)
|
||||
|
|
@ -3408,7 +3404,7 @@ do_device_wifi_hotspot (NmCli *nmc, int argc, char **argv)
|
|||
|
||||
next_arg (nmc, &argc, &argv, NULL);
|
||||
}
|
||||
show_password = nmc->show_secrets || show_password;
|
||||
show_password = nmc->nmc_config.show_secrets || show_password;
|
||||
|
||||
if (nmc->complete)
|
||||
return nmc->return_value;
|
||||
|
|
|
|||
|
|
@ -35,20 +35,230 @@
|
|||
#include "devices.h"
|
||||
#include "connections.h"
|
||||
|
||||
static const NmcMetaGenericInfo *const nmc_fields_nm_status[] = {
|
||||
NMC_META_GENERIC ("RUNNING"), /* 0 */
|
||||
NMC_META_GENERIC ("VERSION"), /* 1 */
|
||||
NMC_META_GENERIC ("STATE"), /* 2 */
|
||||
NMC_META_GENERIC ("STARTUP"), /* 3 */
|
||||
NMC_META_GENERIC ("CONNECTIVITY"), /* 4 */
|
||||
NMC_META_GENERIC ("NETWORKING"), /* 5 */
|
||||
NMC_META_GENERIC ("WIFI-HW"), /* 6 */
|
||||
NMC_META_GENERIC ("WIFI"), /* 7 */
|
||||
NMC_META_GENERIC ("WWAN-HW"), /* 8 */
|
||||
NMC_META_GENERIC ("WWAN"), /* 9 */
|
||||
NMC_META_GENERIC ("WIMAX-HW"), /* 10 */
|
||||
NMC_META_GENERIC ("WIMAX"), /* 11 */
|
||||
NULL,
|
||||
/*****************************************************************************/
|
||||
|
||||
NM_UTILS_LOOKUP_STR_DEFINE_STATIC (nm_state_to_string_no_l10n, NMState,
|
||||
NM_UTILS_LOOKUP_DEFAULT (N_("unknown")),
|
||||
NM_UTILS_LOOKUP_ITEM (NM_STATE_ASLEEP, N_("asleep")),
|
||||
NM_UTILS_LOOKUP_ITEM (NM_STATE_CONNECTING, N_("connecting")),
|
||||
NM_UTILS_LOOKUP_ITEM (NM_STATE_CONNECTED_LOCAL, N_("connected (local only)")),
|
||||
NM_UTILS_LOOKUP_ITEM (NM_STATE_CONNECTED_SITE, N_("connected (site only)")),
|
||||
NM_UTILS_LOOKUP_ITEM (NM_STATE_CONNECTED_GLOBAL, N_("connected")),
|
||||
NM_UTILS_LOOKUP_ITEM (NM_STATE_DISCONNECTING, N_("disconnecting")),
|
||||
NM_UTILS_LOOKUP_ITEM (NM_STATE_DISCONNECTED, N_("disconnected")),
|
||||
NM_UTILS_LOOKUP_ITEM_IGNORE (NM_STATE_UNKNOWN),
|
||||
);
|
||||
|
||||
static const char *
|
||||
nm_state_to_string (NMState state)
|
||||
{
|
||||
return _(nm_state_to_string_no_l10n (state));
|
||||
}
|
||||
|
||||
static NMMetaTermColor
|
||||
state_to_color (NMState state)
|
||||
{
|
||||
switch (state) {
|
||||
case NM_STATE_CONNECTING:
|
||||
return NM_META_TERM_COLOR_YELLOW;
|
||||
case NM_STATE_CONNECTED_LOCAL:
|
||||
case NM_STATE_CONNECTED_SITE:
|
||||
case NM_STATE_CONNECTED_GLOBAL:
|
||||
return NM_META_TERM_COLOR_GREEN;
|
||||
case NM_STATE_DISCONNECTING:
|
||||
return NM_META_TERM_COLOR_YELLOW;
|
||||
case NM_STATE_ASLEEP:
|
||||
case NM_STATE_DISCONNECTED:
|
||||
return NM_META_TERM_COLOR_RED;
|
||||
default:
|
||||
return NM_META_TERM_COLOR_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
NM_UTILS_LOOKUP_STR_DEFINE_STATIC (nm_connectivity_to_string_no_l10n, NMConnectivityState,
|
||||
NM_UTILS_LOOKUP_DEFAULT (N_("unknown")),
|
||||
NM_UTILS_LOOKUP_ITEM (NM_CONNECTIVITY_NONE, N_("none")),
|
||||
NM_UTILS_LOOKUP_ITEM (NM_CONNECTIVITY_PORTAL, N_("portal")),
|
||||
NM_UTILS_LOOKUP_ITEM (NM_CONNECTIVITY_LIMITED, N_("limited")),
|
||||
NM_UTILS_LOOKUP_ITEM (NM_CONNECTIVITY_FULL, N_("full")),
|
||||
NM_UTILS_LOOKUP_ITEM_IGNORE (NM_CONNECTIVITY_UNKNOWN),
|
||||
);
|
||||
|
||||
static const char *
|
||||
nm_connectivity_to_string (NMConnectivityState connectivity)
|
||||
{
|
||||
return _(nm_connectivity_to_string_no_l10n (connectivity));
|
||||
}
|
||||
|
||||
static NMMetaTermColor
|
||||
connectivity_to_color (NMConnectivityState connectivity)
|
||||
{
|
||||
switch (connectivity) {
|
||||
case NM_CONNECTIVITY_NONE:
|
||||
return NM_META_TERM_COLOR_RED;
|
||||
case NM_CONNECTIVITY_PORTAL:
|
||||
case NM_CONNECTIVITY_LIMITED:
|
||||
return NM_META_TERM_COLOR_YELLOW;
|
||||
case NM_CONNECTIVITY_FULL:
|
||||
return NM_META_TERM_COLOR_GREEN;
|
||||
default:
|
||||
return NM_META_TERM_COLOR_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
static const char *
|
||||
permission_to_string (NMClientPermission perm)
|
||||
{
|
||||
switch (perm) {
|
||||
case NM_CLIENT_PERMISSION_ENABLE_DISABLE_NETWORK:
|
||||
return NM_AUTH_PERMISSION_ENABLE_DISABLE_NETWORK;
|
||||
case NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIFI:
|
||||
return NM_AUTH_PERMISSION_ENABLE_DISABLE_WIFI;
|
||||
case NM_CLIENT_PERMISSION_ENABLE_DISABLE_WWAN:
|
||||
return NM_AUTH_PERMISSION_ENABLE_DISABLE_WWAN;
|
||||
case NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIMAX:
|
||||
return NM_AUTH_PERMISSION_ENABLE_DISABLE_WIMAX;
|
||||
case NM_CLIENT_PERMISSION_SLEEP_WAKE:
|
||||
return NM_AUTH_PERMISSION_SLEEP_WAKE;
|
||||
case NM_CLIENT_PERMISSION_NETWORK_CONTROL:
|
||||
return NM_AUTH_PERMISSION_NETWORK_CONTROL;
|
||||
case NM_CLIENT_PERMISSION_WIFI_SHARE_PROTECTED:
|
||||
return NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED;
|
||||
case NM_CLIENT_PERMISSION_WIFI_SHARE_OPEN:
|
||||
return NM_AUTH_PERMISSION_WIFI_SHARE_OPEN;
|
||||
case NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM:
|
||||
return NM_AUTH_PERMISSION_SETTINGS_MODIFY_SYSTEM;
|
||||
case NM_CLIENT_PERMISSION_SETTINGS_MODIFY_OWN:
|
||||
return NM_AUTH_PERMISSION_SETTINGS_MODIFY_OWN;
|
||||
case NM_CLIENT_PERMISSION_SETTINGS_MODIFY_HOSTNAME:
|
||||
return NM_AUTH_PERMISSION_SETTINGS_MODIFY_HOSTNAME;
|
||||
case NM_CLIENT_PERMISSION_SETTINGS_MODIFY_GLOBAL_DNS:
|
||||
return NM_AUTH_PERMISSION_SETTINGS_MODIFY_GLOBAL_DNS;
|
||||
case NM_CLIENT_PERMISSION_RELOAD:
|
||||
return NM_AUTH_PERMISSION_RELOAD;
|
||||
case NM_CLIENT_PERMISSION_CHECKPOINT_ROLLBACK:
|
||||
return NM_AUTH_PERMISSION_CHECKPOINT_ROLLBACK;
|
||||
case NM_CLIENT_PERMISSION_ENABLE_DISABLE_STATISTICS:
|
||||
return NM_AUTH_PERMISSION_ENABLE_DISABLE_STATISTICS;
|
||||
default:
|
||||
return _("unknown");
|
||||
}
|
||||
}
|
||||
|
||||
NM_UTILS_LOOKUP_STR_DEFINE_STATIC (permission_result_to_string_no_l10n, NMClientPermissionResult,
|
||||
NM_UTILS_LOOKUP_DEFAULT (N_("unknown")),
|
||||
NM_UTILS_LOOKUP_ITEM (NM_CLIENT_PERMISSION_RESULT_YES, N_("yes")),
|
||||
NM_UTILS_LOOKUP_ITEM (NM_CLIENT_PERMISSION_RESULT_NO, N_("no")),
|
||||
NM_UTILS_LOOKUP_ITEM (NM_CLIENT_PERMISSION_RESULT_AUTH, N_("auth")),
|
||||
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_ITEM_IGNORE (NM_CLIENT_PERMISSION_RESULT_UNKNOWN),
|
||||
);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static const NmcMetaGenericInfo *const metagen_general_status[];
|
||||
|
||||
static gconstpointer
|
||||
_metagen_general_status_get_fcn (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NmcMetaGenericInfo *info,
|
||||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gpointer *out_to_free)
|
||||
{
|
||||
NmCli *nmc = target;
|
||||
const char *value;
|
||||
gboolean v_bool;
|
||||
NMState state;
|
||||
NMConnectivityState connectivity;
|
||||
|
||||
switch (info->info_type) {
|
||||
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_RUNNING:
|
||||
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
|
||||
value = N_("running");
|
||||
goto translate_and_out;
|
||||
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_VERSION:
|
||||
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
|
||||
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));
|
||||
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);
|
||||
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));
|
||||
value = nm_connectivity_to_string_no_l10n (connectivity);
|
||||
goto translate_and_out;
|
||||
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_NETWORKING:
|
||||
v_bool = nm_client_networking_get_enabled (nmc->client);
|
||||
goto enabled_out;
|
||||
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIFI_HW:
|
||||
v_bool = nm_client_wireless_hardware_get_enabled (nmc->client);
|
||||
goto enabled_out;
|
||||
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIFI:
|
||||
v_bool = nm_client_wireless_get_enabled (nmc->client);
|
||||
goto enabled_out;
|
||||
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WWAN_HW:
|
||||
v_bool = nm_client_wwan_hardware_get_enabled (nmc->client);
|
||||
goto enabled_out;
|
||||
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WWAN:
|
||||
v_bool = nm_client_wwan_get_enabled (nmc->client);
|
||||
goto enabled_out;
|
||||
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIMAX_HW:
|
||||
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIMAX:
|
||||
/* deprected fields. Don't return anything. */
|
||||
return NULL;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
g_return_val_if_reached (NULL);
|
||||
|
||||
enabled_out:
|
||||
NMC_HANDLE_TERMFORMAT (v_bool ? NM_META_TERM_COLOR_GREEN : NM_META_TERM_COLOR_RED);
|
||||
value = v_bool ? N_("enabled") : N_("disabled");
|
||||
goto translate_and_out;
|
||||
|
||||
clone_and_out:
|
||||
return (*out_to_free = g_strdup (value));
|
||||
|
||||
translate_and_out:
|
||||
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
|
||||
return _(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
static const NmcMetaGenericInfo *const metagen_general_status[_NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_NUM + 1] = {
|
||||
#define _METAGEN_GENERAL_STATUS(type, name) \
|
||||
[type] = NMC_META_GENERIC(name, .info_type = type, .get_fcn = _metagen_general_status_get_fcn)
|
||||
_METAGEN_GENERAL_STATUS (NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_RUNNING, "RUNNING"),
|
||||
_METAGEN_GENERAL_STATUS (NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_VERSION, "VERSION"),
|
||||
_METAGEN_GENERAL_STATUS (NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_STATE, "STATE"),
|
||||
_METAGEN_GENERAL_STATUS (NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_STARTUP, "STARTUP"),
|
||||
_METAGEN_GENERAL_STATUS (NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_CONNECTIVITY, "CONNECTIVITY"),
|
||||
_METAGEN_GENERAL_STATUS (NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_NETWORKING, "NETWORKING"),
|
||||
_METAGEN_GENERAL_STATUS (NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIFI_HW, "WIFI-HW"),
|
||||
_METAGEN_GENERAL_STATUS (NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIFI, "WIFI"),
|
||||
_METAGEN_GENERAL_STATUS (NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WWAN_HW, "WWAN-HW"),
|
||||
_METAGEN_GENERAL_STATUS (NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WWAN, "WWAN"),
|
||||
_METAGEN_GENERAL_STATUS (NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIMAX_HW, "WIMAX-HW"),
|
||||
_METAGEN_GENERAL_STATUS (NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIMAX, "WIMAX"),
|
||||
};
|
||||
#define NMC_FIELDS_NM_STATUS_ALL "RUNNING,VERSION,STATE,STARTUP,CONNECTIVITY,NETWORKING,WIFI-HW,WIFI,WWAN-HW,WWAN"
|
||||
#define NMC_FIELDS_NM_STATUS_SWITCH "NETWORKING,WIFI-HW,WIFI,WWAN-HW,WWAN"
|
||||
|
|
@ -60,29 +270,96 @@ static const NmcMetaGenericInfo *const nmc_fields_nm_status[] = {
|
|||
#define NMC_FIELDS_NM_WIMAX "WIMAX"
|
||||
#define NMC_FIELDS_NM_CONNECTIVITY "CONNECTIVITY"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/* Available fields for 'general permissions' */
|
||||
static const NmcMetaGenericInfo *const nmc_fields_nm_permissions[] = {
|
||||
NMC_META_GENERIC ("PERMISSION"), /* 0 */
|
||||
NMC_META_GENERIC ("VALUE"), /* 1 */
|
||||
NULL,
|
||||
static gconstpointer
|
||||
_metagen_general_permissions_get_fcn (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NmcMetaGenericInfo *info,
|
||||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gpointer *out_to_free)
|
||||
{
|
||||
NMClientPermission perm = GPOINTER_TO_UINT (target);
|
||||
NmCli *nmc = environment_user_data;
|
||||
NMClientPermissionResult perm_result;
|
||||
const char *s;
|
||||
|
||||
switch (info->info_type) {
|
||||
case NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_PERMISSION:
|
||||
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
|
||||
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));
|
||||
s = permission_result_to_string_no_l10n (perm_result);
|
||||
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
|
||||
return _(s);
|
||||
return s;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
g_return_val_if_reached (NULL);
|
||||
}
|
||||
|
||||
static const NmcMetaGenericInfo *const metagen_general_permissions[_NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_NUM + 1] = {
|
||||
#define _METAGEN_GENERAL_PERMISSIONS(type, name) \
|
||||
[type] = NMC_META_GENERIC(name, .info_type = type, .get_fcn = _metagen_general_permissions_get_fcn)
|
||||
_METAGEN_GENERAL_PERMISSIONS (NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_PERMISSION, "PERMISSION"),
|
||||
_METAGEN_GENERAL_PERMISSIONS (NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_VALUE, "VALUE"),
|
||||
};
|
||||
#define NMC_FIELDS_NM_PERMISSIONS_ALL "PERMISSION,VALUE"
|
||||
#define NMC_FIELDS_NM_PERMISSIONS_COMMON "PERMISSION,VALUE"
|
||||
|
||||
/* Available fields for 'general logging' */
|
||||
static const NmcMetaGenericInfo *const nmc_fields_nm_logging[] = {
|
||||
NMC_META_GENERIC ("LEVEL"), /* 0 */
|
||||
NMC_META_GENERIC ("DOMAINS"), /* 1 */
|
||||
NULL,
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
bool initialized;
|
||||
char **level;
|
||||
char **domains;
|
||||
} GetGeneralLoggingData;
|
||||
|
||||
static gconstpointer
|
||||
_metagen_general_logging_get_fcn (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NmcMetaGenericInfo *info,
|
||||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gpointer *out_to_free)
|
||||
{
|
||||
NmCli *nmc = environment_user_data;
|
||||
GetGeneralLoggingData *d = target;
|
||||
|
||||
nm_assert (info->info_type < _NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_NUM);
|
||||
|
||||
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
|
||||
|
||||
if (!d->initialized) {
|
||||
d->initialized = TRUE;
|
||||
if (!nm_client_get_logging (nmc->client,
|
||||
d->level,
|
||||
d->domains,
|
||||
NULL))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (info->info_type == NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_LEVEL)
|
||||
return *d->level;
|
||||
else
|
||||
return *d->domains;
|
||||
}
|
||||
|
||||
static const NmcMetaGenericInfo *const metagen_general_logging[_NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_NUM + 1] = {
|
||||
#define _METAGEN_GENERAL_LOGGING(type, name) \
|
||||
[type] = NMC_META_GENERIC(name, .info_type = type, .get_fcn = _metagen_general_logging_get_fcn)
|
||||
_METAGEN_GENERAL_LOGGING (NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_LEVEL, "LEVEL"),
|
||||
_METAGEN_GENERAL_LOGGING (NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_DOMAINS, "DOMAINS"),
|
||||
};
|
||||
#define NMC_FIELDS_NM_LOGGING_ALL "LEVEL,DOMAINS"
|
||||
#define NMC_FIELDS_NM_LOGGING_COMMON "LEVEL,DOMAINS"
|
||||
|
||||
|
||||
/* glib main loop variable - defined in nmcli.c */
|
||||
extern GMainLoop *loop;
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
usage_general (void)
|
||||
|
|
@ -223,107 +500,19 @@ usage_monitor (void)
|
|||
"Prints a line whenever a change occurs in NetworkManager\n\n"));
|
||||
}
|
||||
|
||||
/* quit main loop */
|
||||
static void
|
||||
quit (void)
|
||||
{
|
||||
g_main_loop_quit (loop); /* quit main loop */
|
||||
}
|
||||
|
||||
static const char *
|
||||
nm_state_to_string (NMState state)
|
||||
{
|
||||
switch (state) {
|
||||
case NM_STATE_ASLEEP:
|
||||
return _("asleep");
|
||||
case NM_STATE_CONNECTING:
|
||||
return _("connecting");
|
||||
case NM_STATE_CONNECTED_LOCAL:
|
||||
return _("connected (local only)");
|
||||
case NM_STATE_CONNECTED_SITE:
|
||||
return _("connected (site only)");
|
||||
case NM_STATE_CONNECTED_GLOBAL:
|
||||
return _("connected");
|
||||
case NM_STATE_DISCONNECTING:
|
||||
return _("disconnecting");
|
||||
case NM_STATE_DISCONNECTED:
|
||||
return _("disconnected");
|
||||
case NM_STATE_UNKNOWN:
|
||||
default:
|
||||
return _("unknown");
|
||||
}
|
||||
}
|
||||
|
||||
static NMMetaTermColor
|
||||
state_to_color (NMState state)
|
||||
{
|
||||
switch (state) {
|
||||
case NM_STATE_CONNECTING:
|
||||
return NM_META_TERM_COLOR_YELLOW;
|
||||
case NM_STATE_CONNECTED_LOCAL:
|
||||
case NM_STATE_CONNECTED_SITE:
|
||||
case NM_STATE_CONNECTED_GLOBAL:
|
||||
return NM_META_TERM_COLOR_GREEN;
|
||||
case NM_STATE_DISCONNECTING:
|
||||
return NM_META_TERM_COLOR_YELLOW;
|
||||
case NM_STATE_ASLEEP:
|
||||
case NM_STATE_DISCONNECTED:
|
||||
return NM_META_TERM_COLOR_RED;
|
||||
default:
|
||||
return NM_META_TERM_COLOR_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
static const char *
|
||||
nm_connectivity_to_string (NMConnectivityState connectivity)
|
||||
{
|
||||
switch (connectivity) {
|
||||
case NM_CONNECTIVITY_NONE:
|
||||
return _("none");
|
||||
case NM_CONNECTIVITY_PORTAL:
|
||||
return _("portal");
|
||||
case NM_CONNECTIVITY_LIMITED:
|
||||
return _("limited");
|
||||
case NM_CONNECTIVITY_FULL:
|
||||
return _("full");
|
||||
case NM_CONNECTIVITY_UNKNOWN:
|
||||
default:
|
||||
return _("unknown");
|
||||
}
|
||||
}
|
||||
|
||||
static NMMetaTermColor
|
||||
connectivity_to_color (NMConnectivityState connectivity)
|
||||
{
|
||||
switch (connectivity) {
|
||||
case NM_CONNECTIVITY_NONE:
|
||||
return NM_META_TERM_COLOR_RED;
|
||||
case NM_CONNECTIVITY_PORTAL:
|
||||
case NM_CONNECTIVITY_LIMITED:
|
||||
return NM_META_TERM_COLOR_YELLOW;
|
||||
case NM_CONNECTIVITY_FULL:
|
||||
return NM_META_TERM_COLOR_GREEN;
|
||||
default:
|
||||
return NM_META_TERM_COLOR_NORMAL;
|
||||
}
|
||||
g_main_loop_quit (loop);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_flds)
|
||||
{
|
||||
gboolean startup = FALSE;
|
||||
NMState state = NM_STATE_UNKNOWN;
|
||||
NMConnectivityState connectivity = NM_CONNECTIVITY_UNKNOWN;
|
||||
gboolean net_enabled;
|
||||
gboolean wireless_hw_enabled, wireless_enabled;
|
||||
gboolean wwan_hw_enabled, wwan_enabled;
|
||||
GError *error = NULL;
|
||||
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 NMMetaAbstractInfo *const*tmpl;
|
||||
NmcOutputField *arr;
|
||||
NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
|
||||
|
||||
if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0)
|
||||
fields_str = fields_common;
|
||||
|
|
@ -332,57 +521,16 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl
|
|||
else
|
||||
fields_str = nmc->required_fields;
|
||||
|
||||
tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_nm_status;
|
||||
out_indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
|
||||
|
||||
if (error) {
|
||||
if (!nmc_print (&nmc->nmc_config,
|
||||
(gpointer[]) { nmc, NULL },
|
||||
pretty_header_name ?: N_("NetworkManager status"),
|
||||
(const NMMetaAbstractInfo *const*) metagen_general_status,
|
||||
fields_str,
|
||||
&error)) {
|
||||
g_string_printf (nmc->return_text, _("Error: only these fields are allowed: %s"), fields_all);
|
||||
g_error_free (error);
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
state = nm_client_get_state (nmc->client);
|
||||
startup = nm_client_get_startup (nmc->client);
|
||||
connectivity = nm_client_get_connectivity (nmc->client);
|
||||
net_enabled = nm_client_networking_get_enabled (nmc->client);
|
||||
wireless_hw_enabled = nm_client_wireless_hardware_get_enabled (nmc->client);
|
||||
wireless_enabled = nm_client_wireless_get_enabled (nmc->client);
|
||||
wwan_hw_enabled = nm_client_wwan_hardware_get_enabled (nmc->client);
|
||||
wwan_enabled = nm_client_wwan_get_enabled (nmc->client);
|
||||
|
||||
arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES);
|
||||
g_ptr_array_add (out.output_data, arr);
|
||||
|
||||
arr = nmc_dup_fields_array (tmpl, 0);
|
||||
set_val_strc (arr, 0, _("running"));
|
||||
set_val_strc (arr, 1, nm_client_get_version (nmc->client));
|
||||
set_val_strc (arr, 2, nm_state_to_string (state));
|
||||
set_val_strc (arr, 3, startup ? _("starting") : _("started"));
|
||||
set_val_strc (arr, 4, nm_connectivity_to_string (connectivity));
|
||||
set_val_strc (arr, 5, net_enabled ? _("enabled") : _("disabled"));
|
||||
set_val_strc (arr, 6, wireless_hw_enabled ? _("enabled") : _("disabled"));
|
||||
set_val_strc (arr, 7, wireless_enabled ? _("enabled") : _("disabled"));
|
||||
set_val_strc (arr, 8, wwan_hw_enabled ? _("enabled") : _("disabled"));
|
||||
set_val_strc (arr, 9, wwan_enabled ? _("enabled") : _("disabled"));
|
||||
|
||||
/* Set colors */
|
||||
arr[2].color = state_to_color (state);
|
||||
arr[3].color = startup ? NM_META_TERM_COLOR_YELLOW : NM_META_TERM_COLOR_GREEN;
|
||||
arr[4].color = connectivity_to_color (connectivity);
|
||||
arr[5].color = net_enabled ? NM_META_TERM_COLOR_GREEN : NM_META_TERM_COLOR_RED;
|
||||
arr[6].color = wireless_hw_enabled ? NM_META_TERM_COLOR_GREEN : NM_META_TERM_COLOR_RED;
|
||||
arr[7].color = wireless_enabled ? NM_META_TERM_COLOR_GREEN : NM_META_TERM_COLOR_RED;
|
||||
arr[8].color = wwan_hw_enabled ? NM_META_TERM_COLOR_GREEN : NM_META_TERM_COLOR_RED;
|
||||
arr[9].color = wwan_enabled ? NM_META_TERM_COLOR_GREEN : NM_META_TERM_COLOR_RED;
|
||||
|
||||
g_ptr_array_add (out.output_data, arr);
|
||||
|
||||
print_data_prepare_width (out.output_data);
|
||||
print_data (&nmc->nmc_config, out_indices,
|
||||
pretty_header_name ?: _("NetworkManager status"),
|
||||
0, &out);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -397,60 +545,6 @@ do_general_status (NmCli *nmc, int argc, char **argv)
|
|||
return nmc->return_value;
|
||||
}
|
||||
|
||||
static const char *
|
||||
permission_to_string (NMClientPermission perm)
|
||||
{
|
||||
switch (perm) {
|
||||
case NM_CLIENT_PERMISSION_ENABLE_DISABLE_NETWORK:
|
||||
return NM_AUTH_PERMISSION_ENABLE_DISABLE_NETWORK;
|
||||
case NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIFI:
|
||||
return NM_AUTH_PERMISSION_ENABLE_DISABLE_WIFI;
|
||||
case NM_CLIENT_PERMISSION_ENABLE_DISABLE_WWAN:
|
||||
return NM_AUTH_PERMISSION_ENABLE_DISABLE_WWAN;
|
||||
case NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIMAX:
|
||||
return NM_AUTH_PERMISSION_ENABLE_DISABLE_WIMAX;
|
||||
case NM_CLIENT_PERMISSION_SLEEP_WAKE:
|
||||
return NM_AUTH_PERMISSION_SLEEP_WAKE;
|
||||
case NM_CLIENT_PERMISSION_NETWORK_CONTROL:
|
||||
return NM_AUTH_PERMISSION_NETWORK_CONTROL;
|
||||
case NM_CLIENT_PERMISSION_WIFI_SHARE_PROTECTED:
|
||||
return NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED;
|
||||
case NM_CLIENT_PERMISSION_WIFI_SHARE_OPEN:
|
||||
return NM_AUTH_PERMISSION_WIFI_SHARE_OPEN;
|
||||
case NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM:
|
||||
return NM_AUTH_PERMISSION_SETTINGS_MODIFY_SYSTEM;
|
||||
case NM_CLIENT_PERMISSION_SETTINGS_MODIFY_OWN:
|
||||
return NM_AUTH_PERMISSION_SETTINGS_MODIFY_OWN;
|
||||
case NM_CLIENT_PERMISSION_SETTINGS_MODIFY_HOSTNAME:
|
||||
return NM_AUTH_PERMISSION_SETTINGS_MODIFY_HOSTNAME;
|
||||
case NM_CLIENT_PERMISSION_SETTINGS_MODIFY_GLOBAL_DNS:
|
||||
return NM_AUTH_PERMISSION_SETTINGS_MODIFY_GLOBAL_DNS;
|
||||
case NM_CLIENT_PERMISSION_RELOAD:
|
||||
return NM_AUTH_PERMISSION_RELOAD;
|
||||
case NM_CLIENT_PERMISSION_CHECKPOINT_ROLLBACK:
|
||||
return NM_AUTH_PERMISSION_CHECKPOINT_ROLLBACK;
|
||||
case NM_CLIENT_PERMISSION_ENABLE_DISABLE_STATISTICS:
|
||||
return NM_AUTH_PERMISSION_ENABLE_DISABLE_STATISTICS;
|
||||
default:
|
||||
return _("unknown");
|
||||
}
|
||||
}
|
||||
|
||||
static const char *
|
||||
permission_result_to_string (NMClientPermissionResult perm_result)
|
||||
{
|
||||
switch (perm_result) {
|
||||
case NM_CLIENT_PERMISSION_RESULT_YES:
|
||||
return _("yes");
|
||||
case NM_CLIENT_PERMISSION_RESULT_NO:
|
||||
return _("no");
|
||||
case NM_CLIENT_PERMISSION_RESULT_AUTH:
|
||||
return _("auth");
|
||||
default:
|
||||
return _("unknown");
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
timeout_cb (gpointer user_data)
|
||||
{
|
||||
|
|
@ -466,50 +560,31 @@ static int
|
|||
print_permissions (void *user_data)
|
||||
{
|
||||
NmCli *nmc = user_data;
|
||||
gs_free_error GError *error = NULL;
|
||||
const char *fields_str = NULL;
|
||||
NMClientPermission perm;
|
||||
GError *error = NULL;
|
||||
const char *fields_str;
|
||||
const char *fields_all = NMC_FIELDS_NM_PERMISSIONS_ALL;
|
||||
const char *fields_common = NMC_FIELDS_NM_PERMISSIONS_COMMON;
|
||||
const NMMetaAbstractInfo *const*tmpl;
|
||||
NmcOutputField *arr;
|
||||
NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
|
||||
guint i;
|
||||
gpointer permissions[NM_CLIENT_PERMISSION_LAST + 1];
|
||||
|
||||
if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0)
|
||||
fields_str = fields_common;
|
||||
else if (!nmc->required_fields || strcasecmp (nmc->required_fields, "all") == 0)
|
||||
fields_str = fields_all;
|
||||
else
|
||||
if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0) {
|
||||
} else if (strcasecmp (nmc->required_fields, "all") == 0) {
|
||||
} else
|
||||
fields_str = nmc->required_fields;
|
||||
|
||||
tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_nm_permissions;
|
||||
out_indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
|
||||
for (i = 0, perm = NM_CLIENT_PERMISSION_NONE + 1; perm <= NM_CLIENT_PERMISSION_LAST; perm++)
|
||||
permissions[i++] = GINT_TO_POINTER (perm);
|
||||
permissions[i++] = NULL;
|
||||
|
||||
if (error) {
|
||||
if (!nmc_print (&nmc->nmc_config,
|
||||
permissions,
|
||||
_("NetworkManager permissions"),
|
||||
(const NMMetaAbstractInfo *const*) metagen_general_permissions,
|
||||
fields_str,
|
||||
&error)) {
|
||||
g_string_printf (nmc->return_text, _("Error: 'general permissions': %s"), error->message);
|
||||
g_error_free (error);
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES);
|
||||
g_ptr_array_add (out.output_data, arr);
|
||||
|
||||
|
||||
for (perm = NM_CLIENT_PERMISSION_NONE + 1; perm <= NM_CLIENT_PERMISSION_LAST; perm++) {
|
||||
NMClientPermissionResult perm_result = nm_client_get_permission_result (nmc->client, perm);
|
||||
|
||||
arr = nmc_dup_fields_array (tmpl, 0);
|
||||
set_val_strc (arr, 0, permission_to_string (perm));
|
||||
set_val_strc (arr, 1, permission_result_to_string (perm_result));
|
||||
g_ptr_array_add (out.output_data, arr);
|
||||
}
|
||||
print_data_prepare_width (out.output_data);
|
||||
print_data (&nmc->nmc_config,
|
||||
out_indices,
|
||||
_("NetworkManager permissions"),
|
||||
0, &out);
|
||||
|
||||
quit ();
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
|
@ -575,58 +650,32 @@ do_general_permissions (NmCli *nmc, int argc, char **argv)
|
|||
return nmc->return_value;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
static void
|
||||
show_general_logging (NmCli *nmc)
|
||||
{
|
||||
char *level = NULL;
|
||||
char *domains = NULL;
|
||||
GError *error = NULL;
|
||||
const char *fields_str;
|
||||
const char *fields_all = NMC_FIELDS_NM_LOGGING_ALL;
|
||||
const char *fields_common = NMC_FIELDS_NM_LOGGING_COMMON;
|
||||
const NMMetaAbstractInfo *const*tmpl;
|
||||
NmcOutputField *arr;
|
||||
NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
|
||||
gs_free char *level_cache = NULL;
|
||||
gs_free char *domains_cache = NULL;
|
||||
gs_free GError *error = NULL;
|
||||
const char *fields_str = NULL;
|
||||
GetGeneralLoggingData d = {
|
||||
.level = &level_cache,
|
||||
.domains = &domains_cache,
|
||||
};
|
||||
|
||||
if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0)
|
||||
fields_str = fields_common;
|
||||
else if (!nmc->required_fields || strcasecmp (nmc->required_fields, "all") == 0)
|
||||
fields_str = fields_all;
|
||||
else
|
||||
if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0) {
|
||||
} else if (strcasecmp (nmc->required_fields, "all") == 0) {
|
||||
} else
|
||||
fields_str = nmc->required_fields;
|
||||
|
||||
tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_nm_logging;
|
||||
out_indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
|
||||
|
||||
if (error) {
|
||||
if (!nmc_print (&nmc->nmc_config,
|
||||
(gpointer const []) { &d, NULL },
|
||||
_("NetworkManager logging"),
|
||||
(const NMMetaAbstractInfo *const*) metagen_general_logging,
|
||||
fields_str,
|
||||
&error)) {
|
||||
g_string_printf (nmc->return_text, _("Error: 'general logging': %s"), error->message);
|
||||
g_error_free (error);
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
nm_client_get_logging (nmc->client, &level, &domains, &error);
|
||||
if (error) {
|
||||
g_string_printf (nmc->return_text, _("Error: %s."), error->message);
|
||||
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
||||
g_error_free (error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES);
|
||||
g_ptr_array_add (out.output_data, arr);
|
||||
|
||||
arr = nmc_dup_fields_array (tmpl, 0);
|
||||
set_val_str (arr, 0, level);
|
||||
set_val_str (arr, 1, domains);
|
||||
g_ptr_array_add (out.output_data, arr);
|
||||
|
||||
print_data_prepare_width (out.output_data);
|
||||
print_data (&nmc->nmc_config, out_indices,
|
||||
_("NetworkManager logging"),
|
||||
0, &out);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -865,7 +914,7 @@ do_networking_connectivity (NmCli *nmc, int argc, char **argv)
|
|||
|
||||
if (!argc) {
|
||||
/* no arguments -> get current state */
|
||||
nmc_switch_show (nmc, NMC_FIELDS_NM_CONNECTIVITY, _("Connectivity"));
|
||||
nmc_switch_show (nmc, NMC_FIELDS_NM_CONNECTIVITY, N_("Connectivity"));
|
||||
} else if (matches (*argv, "check")) {
|
||||
gs_free_error GError *error = NULL;
|
||||
|
||||
|
|
@ -877,7 +926,7 @@ do_networking_connectivity (NmCli *nmc, int argc, char **argv)
|
|||
g_string_printf (nmc->return_text, _("Error: %s."), error->message);
|
||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
||||
} else
|
||||
nmc_switch_show (nmc, NMC_FIELDS_NM_CONNECTIVITY, _("Connectivity"));
|
||||
nmc_switch_show (nmc, NMC_FIELDS_NM_CONNECTIVITY, N_("Connectivity"));
|
||||
} else {
|
||||
usage_networking ();
|
||||
g_string_printf (nmc->return_text, _("Error: 'networking' command '%s' is not valid."), *argv);
|
||||
|
|
@ -894,7 +943,7 @@ do_networking_show (NmCli *nmc, int argc, char **argv)
|
|||
if (nmc->complete)
|
||||
return nmc->return_value;
|
||||
|
||||
nmc_switch_show (nmc, NMC_FIELDS_NM_NETWORKING, _("Networking"));
|
||||
nmc_switch_show (nmc, NMC_FIELDS_NM_NETWORKING, N_("Networking"));
|
||||
|
||||
return nmc->return_value;
|
||||
}
|
||||
|
|
@ -929,7 +978,7 @@ do_radio_all (NmCli *nmc, int argc, char **argv)
|
|||
return nmc->return_value;
|
||||
|
||||
/* no argument, show all radio switches */
|
||||
show_nm_status (nmc, _("Radio switches"), NMC_FIELDS_NM_STATUS_RADIO);
|
||||
show_nm_status (nmc, N_("Radio switches"), NMC_FIELDS_NM_STATUS_RADIO);
|
||||
} else {
|
||||
if (nmc->complete) {
|
||||
if (argc == 1)
|
||||
|
|
@ -959,7 +1008,7 @@ do_radio_wifi (NmCli *nmc, int argc, char **argv)
|
|||
return nmc->return_value;
|
||||
|
||||
/* no argument, show current WiFi state */
|
||||
nmc_switch_show (nmc, NMC_FIELDS_NM_WIFI, _("Wi-Fi radio switch"));
|
||||
nmc_switch_show (nmc, NMC_FIELDS_NM_WIFI, N_("Wi-Fi radio switch"));
|
||||
} else {
|
||||
if (nmc->complete) {
|
||||
if (argc == 1)
|
||||
|
|
@ -986,7 +1035,7 @@ do_radio_wwan (NmCli *nmc, int argc, char **argv)
|
|||
return nmc->return_value;
|
||||
|
||||
/* no argument, show current WWAN (mobile broadband) state */
|
||||
nmc_switch_show (nmc, NMC_FIELDS_NM_WWAN, _("WWAN radio switch"));
|
||||
nmc_switch_show (nmc, NMC_FIELDS_NM_WWAN, N_("WWAN radio switch"));
|
||||
} else {
|
||||
if (nmc->complete) {
|
||||
if (argc == 1)
|
||||
|
|
|
|||
|
|
@ -75,8 +75,6 @@ complete_field_setting (GHashTable *h, NMMetaSettingType setting_type)
|
|||
guint i;
|
||||
|
||||
for (i = 0; i < setting_info->properties_num; i++) {
|
||||
if (setting_info->properties[i].is_name)
|
||||
continue;
|
||||
g_hash_table_add (h, g_strdup_printf ("%s.%s",
|
||||
setting_info->general->setting_name,
|
||||
setting_info->properties[i].property_name));
|
||||
|
|
@ -119,7 +117,7 @@ complete_fields (const char *prefix)
|
|||
|
||||
h = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
||||
|
||||
complete_field (h, nmc_fields_ip4_config);
|
||||
complete_field (h, metagen_ip4_config);
|
||||
complete_field (h, nmc_fields_dhcp4_config);
|
||||
complete_field (h, nmc_fields_ip6_config);
|
||||
complete_field (h, nmc_fields_dhcp6_config);
|
||||
|
|
@ -538,12 +536,11 @@ nmc_init (NmCli *nmc)
|
|||
nmc->required_fields = NULL;
|
||||
nmc->ask = FALSE;
|
||||
nmc->complete = FALSE;
|
||||
nmc->show_secrets = 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_show_secrets = FALSE;
|
||||
nmc->editor_prompt_color = NM_META_TERM_COLOR_NORMAL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@
|
|||
typedef gpointer NMPolkitListener;
|
||||
#endif
|
||||
|
||||
typedef char *(*NmcCompEntryFunc) (const char *, int);
|
||||
|
||||
/* nmcli exit codes */
|
||||
typedef enum {
|
||||
/* Indicates successful execution */
|
||||
|
|
@ -111,9 +113,10 @@ typedef enum {
|
|||
typedef struct _NmcConfig {
|
||||
NMCPrintOutput print_output; /* Output mode */
|
||||
NmcColorOption use_colors; /* Whether to use colors for output: option '--color' */
|
||||
gboolean multiline_output; /* Multiline output instead of default tabular */
|
||||
gboolean escape_values; /* Whether to escape ':' and '\' in terse tabular mode */
|
||||
gboolean in_editor; /* Whether running the editor - nmcli con edit' */
|
||||
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' */
|
||||
} NmcConfig;
|
||||
|
||||
typedef struct _NmcOutputData {
|
||||
|
|
@ -143,11 +146,9 @@ typedef struct _NmCli {
|
|||
char *required_fields; /* Required fields in output: '--fields' option */
|
||||
gboolean ask; /* Ask for missing parameters: option '--ask' */
|
||||
gboolean complete; /* Autocomplete the command line */
|
||||
gboolean show_secrets; /* Whether to display secrets (both input and output): option '--show-secrets' */
|
||||
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' */
|
||||
gboolean editor_show_secrets; /* Whether to display secrets in the editor' */
|
||||
NMMetaTermColor editor_prompt_color; /* Color of prompt in connection editor */
|
||||
NMMetaTermColor editor_prompt_color; /* Color of prompt in connection editor */
|
||||
} NmCli;
|
||||
|
||||
extern NmCli nm_cli;
|
||||
|
|
@ -156,6 +157,8 @@ extern NmCli nm_cli;
|
|||
#define NMCLI_ERROR (nmcli_error_quark ())
|
||||
GQuark nmcli_error_quark (void);
|
||||
|
||||
extern GMainLoop *loop;
|
||||
|
||||
gboolean nmc_seen_sigint (void);
|
||||
void nmc_clear_sigint (void);
|
||||
void nmc_set_sigquit_internal (void);
|
||||
|
|
|
|||
|
|
@ -304,74 +304,6 @@ nmc_setting_connection_connect_handlers (NMSettingConnection *setting, NMConnect
|
|||
G_CALLBACK (connection_master_changed_cb), connection);
|
||||
}
|
||||
|
||||
/*
|
||||
* Customize some properties of the setting so that the setting has sensible
|
||||
* values.
|
||||
*/
|
||||
void
|
||||
nmc_setting_custom_init (NMSetting *setting)
|
||||
{
|
||||
g_return_if_fail (NM_IS_SETTING (setting));
|
||||
|
||||
if (NM_IS_SETTING_VLAN (setting)) {
|
||||
/* Set sensible initial VLAN values */
|
||||
g_object_set (NM_SETTING_VLAN (setting),
|
||||
NM_SETTING_VLAN_ID, 1,
|
||||
NULL);
|
||||
} else if (NM_IS_SETTING_INFINIBAND (setting)) {
|
||||
/* Initialize 'transport-mode' so that 'infiniband' is valid */
|
||||
g_object_set (NM_SETTING_INFINIBAND (setting),
|
||||
NM_SETTING_INFINIBAND_TRANSPORT_MODE, "datagram",
|
||||
NULL);
|
||||
} else if (NM_IS_SETTING_CDMA (setting)) {
|
||||
/* Initialize 'number' so that 'cdma' is valid */
|
||||
g_object_set (NM_SETTING_CDMA (setting),
|
||||
NM_SETTING_CDMA_NUMBER, "#777",
|
||||
NULL);
|
||||
} else if (NM_IS_SETTING_GSM (setting)) {
|
||||
/* Initialize 'number' so that 'gsm' is valid */
|
||||
g_object_set (NM_SETTING_GSM (setting),
|
||||
NM_SETTING_GSM_NUMBER, "*99#",
|
||||
NULL);
|
||||
} else if (NM_IS_SETTING_OLPC_MESH (setting)) {
|
||||
g_object_set (NM_SETTING_OLPC_MESH (setting),
|
||||
NM_SETTING_OLPC_MESH_CHANNEL, 1,
|
||||
NULL);
|
||||
} else if (NM_IS_SETTING_WIRELESS (setting)) {
|
||||
/* For Wi-Fi set mode to "infrastructure". Even though mode == NULL
|
||||
* is regarded as "infrastructure", explicit value makes no doubts.
|
||||
*/
|
||||
g_object_set (NM_SETTING_WIRELESS (setting),
|
||||
NM_SETTING_WIRELESS_MODE, NM_SETTING_WIRELESS_MODE_INFRA,
|
||||
NULL);
|
||||
} else if (NM_IS_SETTING_ADSL (setting)) {
|
||||
/* Initialize a protocol */
|
||||
g_object_set (NM_SETTING_ADSL (setting),
|
||||
NM_SETTING_ADSL_PROTOCOL, NM_SETTING_ADSL_PROTOCOL_PPPOE,
|
||||
NULL);
|
||||
} else if (NM_IS_SETTING_IP4_CONFIG (setting)) {
|
||||
g_object_set (NM_SETTING_IP_CONFIG (setting),
|
||||
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
|
||||
NULL);
|
||||
} else if (NM_IS_SETTING_IP6_CONFIG (setting)) {
|
||||
g_object_set (NM_SETTING_IP_CONFIG (setting),
|
||||
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
|
||||
NULL);
|
||||
} else if (NM_IS_SETTING_PROXY (setting)) {
|
||||
g_object_set (NM_SETTING_PROXY (setting),
|
||||
NM_SETTING_PROXY_METHOD, (int) NM_SETTING_PROXY_METHOD_NONE,
|
||||
NULL);
|
||||
} else if (NM_IS_SETTING_TUN (setting)) {
|
||||
g_object_set (NM_SETTING_TUN (setting),
|
||||
NM_SETTING_TUN_MODE, NM_SETTING_TUN_MODE_TUN,
|
||||
NULL);
|
||||
} else if (NM_IS_SETTING_BLUETOOTH (setting)) {
|
||||
g_object_set (NM_SETTING_BLUETOOTH (setting),
|
||||
NM_SETTING_BLUETOOTH_TYPE, NM_SETTING_BLUETOOTH_TYPE_PANU,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gboolean
|
||||
|
|
@ -456,31 +388,89 @@ _env_warn_fcn_handle (const NMMetaEnvironment *environment,
|
|||
g_print (_("Error: %s\n"), m);
|
||||
}
|
||||
|
||||
static NMDevice *const*
|
||||
_env_get_nm_devices (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
guint *out_len)
|
||||
{
|
||||
NmCli *nmc = environment_user_data;
|
||||
const GPtrArray *devices;
|
||||
|
||||
nm_assert (nmc);
|
||||
|
||||
/* the returned list is *not* NULL terminated. Need to
|
||||
* provide and honor the out_len argument. */
|
||||
nm_assert (out_len);
|
||||
|
||||
devices = nm_client_get_devices (nmc->client);
|
||||
if (!devices) {
|
||||
*out_len = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*out_len = devices->len;
|
||||
return (NMDevice *const*) devices->pdata;
|
||||
}
|
||||
|
||||
static NMRemoteConnection *const*
|
||||
_env_get_nm_connections (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
guint *out_len)
|
||||
{
|
||||
NmCli *nmc = environment_user_data;
|
||||
const GPtrArray *values;
|
||||
|
||||
nm_assert (nmc);
|
||||
|
||||
/* the returned list is *not* NULL terminated. Need to
|
||||
* provide and honor the out_len argument. */
|
||||
nm_assert (out_len);
|
||||
|
||||
values = nm_client_get_connections (nmc->client);
|
||||
if (!values) {
|
||||
*out_len = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*out_len = values->len;
|
||||
return (NMRemoteConnection *const*) values->pdata;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static const NMMetaEnvironment meta_environment = {
|
||||
const NMMetaEnvironment *const nmc_meta_environment = &((NMMetaEnvironment) {
|
||||
.warn_fcn = _env_warn_fcn_handle,
|
||||
};
|
||||
.get_nm_devices = _env_get_nm_devices,
|
||||
.get_nm_connections = _env_get_nm_connections,
|
||||
});
|
||||
|
||||
NmCli *const nmc_meta_environment_arg = &nm_cli;
|
||||
|
||||
static char *
|
||||
get_property_val (NMSetting *setting, const char *prop, NMMetaAccessorGetType get_type, gboolean show_secrets, GError **error)
|
||||
{
|
||||
const NMMetaPropertyInfo *property_info;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING (setting), FALSE);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
g_return_val_if_fail (NM_IS_SETTING (setting), NULL);
|
||||
g_return_val_if_fail (!error || !*error, NULL);
|
||||
g_return_val_if_fail (NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_PARSABLE, NM_META_ACCESSOR_GET_TYPE_PRETTY), NULL);
|
||||
|
||||
if ((property_info = nm_meta_property_info_find_by_setting (setting, prop))) {
|
||||
if (property_info->is_name) {
|
||||
/* Traditionally, the "name" property was not handled here.
|
||||
* For the moment, skip it from get_property_val(). */
|
||||
} else if (property_info->property_type->get_fcn) {
|
||||
return property_info->property_type->get_fcn (&meta_environment,
|
||||
NULL,
|
||||
property_info,
|
||||
setting,
|
||||
get_type,
|
||||
show_secrets ? NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS : 0);
|
||||
if (property_info->property_type->get_fcn) {
|
||||
NMMetaAccessorGetOutFlags out_flags = NM_META_ACCESSOR_GET_OUT_FLAGS_NONE;
|
||||
char *to_free = NULL;
|
||||
const char *value;
|
||||
|
||||
value = property_info->property_type->get_fcn (property_info,
|
||||
nmc_meta_environment,
|
||||
nmc_meta_environment_arg,
|
||||
setting,
|
||||
get_type,
|
||||
show_secrets ? NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS : 0,
|
||||
&out_flags,
|
||||
(gpointer *) &to_free);
|
||||
nm_assert (!out_flags);
|
||||
return to_free ?: g_strdup (value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -517,9 +507,9 @@ _set_fcn_call (const NMMetaPropertyInfo *property_info,
|
|||
const char *value,
|
||||
GError **error)
|
||||
{
|
||||
return property_info->property_type->set_fcn (&meta_environment,
|
||||
NULL,
|
||||
property_info,
|
||||
return property_info->property_type->set_fcn (property_info,
|
||||
nmc_meta_environment,
|
||||
nmc_meta_environment_arg,
|
||||
setting,
|
||||
value,
|
||||
error);
|
||||
|
|
@ -549,10 +539,7 @@ nmc_setting_set_property (NMSetting *setting, const char *prop, const char *valu
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
if (property_info->is_name) {
|
||||
/* Traditionally, the "name" property was not handled here.
|
||||
* For the moment, skip it from get_property_val(). */
|
||||
} else if (property_info->property_type->set_fcn) {
|
||||
if (property_info->property_type->set_fcn) {
|
||||
switch (property_info->setting_info->general->meta_type) {
|
||||
case NM_META_SETTING_TYPE_CONNECTION:
|
||||
if (nm_streq (property_info->property_name, NM_SETTING_CONNECTION_SECONDARIES)) {
|
||||
|
|
@ -613,10 +600,7 @@ nmc_setting_reset_property (NMSetting *setting, const char *prop, GError **error
|
|||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
if ((property_info = nm_meta_property_info_find_by_setting (setting, prop))) {
|
||||
if (property_info->is_name) {
|
||||
/* Traditionally, the "name" property was not handled here.
|
||||
* For the moment, skip it from get_property_val(). */
|
||||
} else if (property_info->property_type->set_fcn) {
|
||||
if (property_info->property_type->set_fcn) {
|
||||
nmc_property_set_default_value (setting, prop);
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -648,13 +632,10 @@ nmc_setting_remove_property_option (NMSetting *setting,
|
|||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
if ((property_info = nm_meta_property_info_find_by_setting (setting, prop))) {
|
||||
if (property_info->is_name) {
|
||||
/* Traditionally, the "name" property was not handled here.
|
||||
* For the moment, skip it from get_property_val(). */
|
||||
} else if (property_info->property_type->remove_fcn) {
|
||||
return property_info->property_type->remove_fcn (&meta_environment,
|
||||
NULL,
|
||||
property_info,
|
||||
if (property_info->property_type->remove_fcn) {
|
||||
return property_info->property_type->remove_fcn (property_info,
|
||||
nmc_meta_environment,
|
||||
nmc_meta_environment_arg,
|
||||
setting,
|
||||
option,
|
||||
idx,
|
||||
|
|
@ -707,10 +688,7 @@ nmc_setting_get_property_allowed_values (NMSetting *setting, const char *prop, c
|
|||
*out_to_free = NULL;
|
||||
|
||||
if ((property_info = nm_meta_property_info_find_by_setting (setting, prop))) {
|
||||
if (property_info->is_name) {
|
||||
/* Traditionally, the "name" property was not handled here.
|
||||
* For the moment, skip it from get_property_val(). */
|
||||
} else if (property_info->property_type->values_fcn) {
|
||||
if (property_info->property_type->values_fcn) {
|
||||
return property_info->property_type->values_fcn (property_info,
|
||||
out_to_free);
|
||||
} else if (property_info->property_typ_data && property_info->property_typ_data->values_static)
|
||||
|
|
@ -751,10 +729,7 @@ nmc_setting_get_property_desc (NMSetting *setting, const char *prop)
|
|||
setting_desc_title = _("[NM property description]");
|
||||
}
|
||||
|
||||
if (property_info->is_name) {
|
||||
/* Traditionally, the "name" property was not handled here.
|
||||
* For the moment, skip it from get_property_val(). */
|
||||
} else if (property_info->property_type->describe_fcn) {
|
||||
if (property_info->property_type->describe_fcn) {
|
||||
desc = property_info->property_type->describe_fcn (property_info, &desc_to_free);
|
||||
} else
|
||||
desc = property_info->describe_message;
|
||||
|
|
@ -809,29 +784,12 @@ nmc_property_set_gvalue (NMSetting *setting, const char *prop, GValue *value)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
static NmcOutputField *
|
||||
_dup_fields_array (const NMMetaSettingInfoEditor *setting_info, NmcOfFlags flags)
|
||||
{
|
||||
NmcOutputField *row;
|
||||
gsize l;
|
||||
|
||||
l = setting_info->properties_num;
|
||||
|
||||
row = g_malloc0 ((l + 1) * sizeof (NmcOutputField));
|
||||
for (l = 0; l < setting_info->properties_num; l++)
|
||||
row[l].info = (const NMMetaAbstractInfo *) &setting_info->properties[l];
|
||||
row[0].flags = flags;
|
||||
return row;
|
||||
}
|
||||
|
||||
gboolean
|
||||
setting_details (const NmcConfig *nmc_config, NMSetting *setting, const char *one_prop, gboolean show_secrets)
|
||||
setting_details (const NmcConfig *nmc_config, NMSetting *setting, const char *one_prop)
|
||||
{
|
||||
const NMMetaSettingInfoEditor *setting_info;
|
||||
NmcOutputField *arr;
|
||||
guint i;
|
||||
NMMetaAccessorGetType type = NM_META_ACCESSOR_GET_TYPE_PRETTY;
|
||||
NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
|
||||
gs_free_error GError *error = NULL;
|
||||
gs_free char *fields_str = NULL;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING (setting), FALSE);
|
||||
|
||||
|
|
@ -839,36 +797,20 @@ setting_details (const NmcConfig *nmc_config, NMSetting *setting, const char *on
|
|||
if (!setting_info)
|
||||
return FALSE;
|
||||
|
||||
if (nmc_config->print_output == NMC_PRINT_TERSE)
|
||||
type = NM_META_ACCESSOR_GET_TYPE_PARSABLE;
|
||||
|
||||
out_indices = parse_output_fields (one_prop,
|
||||
(const NMMetaAbstractInfo *const*) nm_property_infos_for_setting_type (setting_info->general->meta_type),
|
||||
FALSE, NULL, NULL);
|
||||
arr = _dup_fields_array (setting_info, NMC_OF_FLAG_FIELD_NAMES);
|
||||
g_ptr_array_add (out.output_data, arr);
|
||||
|
||||
arr = _dup_fields_array (setting_info, NMC_OF_FLAG_SECTION_PREFIX);
|
||||
for (i = 0; i < setting_info->properties_num; i++) {
|
||||
const NMMetaPropertyInfo *property_info = &setting_info->properties[i];
|
||||
|
||||
nm_assert (property_info->setting_info == setting_info);
|
||||
|
||||
if (!property_info->is_secret || show_secrets) {
|
||||
set_val_str (arr, i, property_info->property_type->get_fcn (&meta_environment,
|
||||
NULL,
|
||||
property_info,
|
||||
setting,
|
||||
type,
|
||||
show_secrets ? NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS : 0));
|
||||
} else
|
||||
set_val_str (arr, i, g_strdup (_(NM_META_TEXT_HIDDEN)));
|
||||
if (one_prop) {
|
||||
/* hack around setting-details being called for one setting. Must prefix the
|
||||
* property name with the setting name. Later we should remove setting_details()
|
||||
* and merge it into the caller. */
|
||||
fields_str = g_strdup_printf ("%s.%s", nm_setting_get_name (setting), one_prop);
|
||||
}
|
||||
|
||||
g_ptr_array_add (out.output_data, arr);
|
||||
|
||||
print_data_prepare_width (out.output_data);
|
||||
print_data (nmc_config, out_indices, NULL, 0, &out);
|
||||
if (!nmc_print (nmc_config,
|
||||
(gpointer[]) { setting, NULL },
|
||||
NULL,
|
||||
(const NMMetaAbstractInfo *const[]) { (const NMMetaAbstractInfo *) setting_info, NULL },
|
||||
fields_str,
|
||||
&error))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
void nmc_setting_custom_init (NMSetting *setting);
|
||||
void nmc_setting_ip4_connect_handlers (NMSettingIPConfig *setting);
|
||||
void nmc_setting_ip6_connect_handlers (NMSettingIPConfig *setting);
|
||||
void nmc_setting_proxy_connect_handlers (NMSettingProxy *setting);
|
||||
|
|
@ -60,6 +59,6 @@ void nmc_property_set_default_value (NMSetting *setting, const char *prop);
|
|||
gboolean nmc_property_get_gvalue (NMSetting *setting, const char *prop, GValue *value);
|
||||
gboolean nmc_property_set_gvalue (NMSetting *setting, const char *prop, GValue *value);
|
||||
|
||||
gboolean setting_details (const NmcConfig *nmc_config, NMSetting *setting, const char *one_prop, gboolean secrets);
|
||||
gboolean setting_details (const NmcConfig *nmc_config, NMSetting *setting, const char *one_prop);
|
||||
|
||||
#endif /* NMC_SETTINGS_H */
|
||||
|
|
|
|||
1251
clients/cli/utils.c
1251
clients/cli/utils.c
File diff suppressed because it is too large
Load diff
|
|
@ -63,6 +63,7 @@ void nmc_free_output_field_values (NmcOutputField fields_array[]);
|
|||
|
||||
typedef struct {
|
||||
const NMMetaAbstractInfo *info;
|
||||
const char *self_selection;
|
||||
const char *sub_selection;
|
||||
guint idx;
|
||||
} NmcOutputSelectionItem;
|
||||
|
|
@ -73,7 +74,9 @@ typedef struct {
|
|||
} NmcOutputSelection;
|
||||
|
||||
NmcOutputSelection *nmc_output_selection_create (const NMMetaAbstractInfo *const* fields_array,
|
||||
const char *fields_prefix,
|
||||
const char *fields_str,
|
||||
gboolean validate_nested,
|
||||
GError **error);
|
||||
|
||||
GArray *parse_output_fields (const char *fields_str,
|
||||
|
|
@ -81,8 +84,8 @@ GArray *parse_output_fields (const char *fields_str,
|
|||
gboolean parse_groups,
|
||||
GPtrArray **group_fields,
|
||||
GError **error);
|
||||
char *nmc_get_allowed_fields_nested (const NMMetaAbstractInfo *abstract_info);
|
||||
char *nmc_get_allowed_fields (const NMMetaAbstractInfo *const*fields_array);
|
||||
char *nmc_get_allowed_fields_nested (const NMMetaAbstractInfo *abstract_info, const char *name_prefix);
|
||||
char *nmc_get_allowed_fields (const NMMetaAbstractInfo *const*fields_array, const char *name_prefix);
|
||||
NmcOutputField *nmc_dup_fields_array (const NMMetaAbstractInfo *const*fields, NmcOfFlags flags);
|
||||
void nmc_empty_output_fields (NmcOutputData *output_data);
|
||||
void print_required_fields (const NmcConfig *nmc_config,
|
||||
|
|
@ -100,9 +103,54 @@ void print_data (const NmcConfig *nmc_config,
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
extern const NMMetaEnvironment *const nmc_meta_environment;
|
||||
extern NmCli *const nmc_meta_environment_arg;
|
||||
|
||||
typedef enum {
|
||||
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_RUNNING = 0,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_VERSION,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_STATE,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_STARTUP,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_CONNECTIVITY,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_NETWORKING,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIFI_HW,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIFI,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WWAN_HW,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WWAN,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIMAX_HW,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIMAX,
|
||||
_NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_NUM,
|
||||
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_PERMISSION = 0,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_VALUE,
|
||||
_NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_NUM,
|
||||
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_LEVEL = 0,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_DOMAINS,
|
||||
_NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_NUM,
|
||||
|
||||
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ADDRESS = 0,
|
||||
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_GATEWAY,
|
||||
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ROUTE,
|
||||
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DNS,
|
||||
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DOMAIN,
|
||||
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_WINS,
|
||||
_NMC_GENERIC_INFO_TYPE_IP4_CONFIG_NUM,
|
||||
|
||||
} NmcGenericInfoType;
|
||||
|
||||
#define NMC_HANDLE_TERMFORMAT(color) \
|
||||
G_STMT_START { \
|
||||
if (get_type == NM_META_ACCESSOR_GET_TYPE_TERMFORMAT) \
|
||||
return nm_meta_termformat_pack ((color), NM_META_TERM_FORMAT_NORMAL); \
|
||||
} G_STMT_END
|
||||
|
||||
struct _NmcMetaGenericInfo {
|
||||
const NMMetaType *meta_type;
|
||||
NmcGenericInfoType info_type;
|
||||
const char *name;
|
||||
const char *name_header;
|
||||
const NmcMetaGenericInfo *const*nested;
|
||||
gconstpointer (*get_fcn) (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
|
|
@ -110,6 +158,7 @@ struct _NmcMetaGenericInfo {
|
|||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gpointer *out_to_free);
|
||||
};
|
||||
|
||||
|
|
@ -120,8 +169,17 @@ struct _NmcMetaGenericInfo {
|
|||
__VA_ARGS__ \
|
||||
}))
|
||||
|
||||
#define NMC_META_GENERIC_WITH_NESTED(n, nest) \
|
||||
NMC_META_GENERIC (n, .nested = (nest))
|
||||
#define NMC_META_GENERIC_WITH_NESTED(n, nest, ...) \
|
||||
NMC_META_GENERIC (n, .nested = (nest), __VA_ARGS__)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
gboolean nmc_print (const NmcConfig *nmc_config,
|
||||
gpointer const *targets,
|
||||
const char *header_name_no_l10n,
|
||||
const NMMetaAbstractInfo *const*fields,
|
||||
const char *fields_str,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -92,8 +92,8 @@ nmc_string_to_uint (const char *str,
|
|||
gboolean
|
||||
nmc_string_to_bool (const char *str, gboolean *val_bool, GError **error)
|
||||
{
|
||||
const char *s_true[] = { "true", "yes", "on", NULL };
|
||||
const char *s_false[] = { "false", "no", "off", NULL };
|
||||
const char *s_true[] = { "true", "yes", "on", "1", NULL };
|
||||
const char *s_false[] = { "false", "no", "off", "0", NULL };
|
||||
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
|
|
|
|||
|
|
@ -24,26 +24,31 @@
|
|||
/*****************************************************************************/
|
||||
|
||||
const NMMetaSettingInfoEditor *
|
||||
nm_meta_setting_info_editor_find_by_name (const char *setting_name)
|
||||
nm_meta_setting_info_editor_find_by_name (const char *setting_name, gboolean use_alias)
|
||||
{
|
||||
const NMMetaSettingInfo *meta_setting_info;
|
||||
const NMMetaSettingInfoEditor *setting_info;
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (setting_name, NULL);
|
||||
|
||||
meta_setting_info = nm_meta_setting_infos_by_name (setting_name);
|
||||
|
||||
if (!meta_setting_info)
|
||||
return NULL;
|
||||
|
||||
g_return_val_if_fail (nm_streq0 (meta_setting_info->setting_name, setting_name), NULL);
|
||||
|
||||
if (meta_setting_info->meta_type >= G_N_ELEMENTS (nm_meta_setting_infos_editor))
|
||||
return NULL;
|
||||
|
||||
setting_info = &nm_meta_setting_infos_editor[meta_setting_info->meta_type];
|
||||
|
||||
g_return_val_if_fail (setting_info->general == meta_setting_info, NULL);
|
||||
setting_info = NULL;
|
||||
if (meta_setting_info) {
|
||||
nm_assert (nm_streq0 (meta_setting_info->setting_name, setting_name));
|
||||
if (meta_setting_info->meta_type < G_N_ELEMENTS (nm_meta_setting_infos_editor)) {
|
||||
setting_info = &nm_meta_setting_infos_editor[meta_setting_info->meta_type];
|
||||
nm_assert (setting_info->general == meta_setting_info);
|
||||
}
|
||||
}
|
||||
if (!setting_info && use_alias) {
|
||||
for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) {
|
||||
if (nm_streq0 (nm_meta_setting_infos_editor[i].alias, setting_name)) {
|
||||
setting_info = &nm_meta_setting_infos_editor[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return setting_info;
|
||||
}
|
||||
|
|
@ -81,7 +86,7 @@ nm_meta_setting_info_editor_find_by_setting (NMSetting *setting)
|
|||
|
||||
setting_info = nm_meta_setting_info_editor_find_by_gtype (G_OBJECT_TYPE (setting));
|
||||
|
||||
nm_assert (setting_info == nm_meta_setting_info_editor_find_by_name (nm_setting_get_name (setting)));
|
||||
nm_assert (setting_info == nm_meta_setting_info_editor_find_by_name (nm_setting_get_name (setting), FALSE));
|
||||
nm_assert (!setting_info || G_TYPE_CHECK_INSTANCE_TYPE (setting, setting_info->general->get_setting_gtype ()));
|
||||
|
||||
return setting_info;
|
||||
|
|
@ -111,7 +116,7 @@ nm_meta_property_info_find_by_name (const char *setting_name, const char *proper
|
|||
const NMMetaSettingInfoEditor *setting_info;
|
||||
const NMMetaPropertyInfo *property_info;
|
||||
|
||||
setting_info = nm_meta_setting_info_editor_find_by_name (setting_name);
|
||||
setting_info = nm_meta_setting_info_editor_find_by_name (setting_name, FALSE);
|
||||
if (!setting_info)
|
||||
return NULL;
|
||||
|
||||
|
|
@ -143,6 +148,26 @@ nm_meta_property_info_find_by_setting (NMSetting *setting, const char *property_
|
|||
return property_info;
|
||||
}
|
||||
|
||||
NMSetting *
|
||||
nm_meta_setting_info_editor_new_setting (const NMMetaSettingInfoEditor *setting_info,
|
||||
NMMetaAccessorSettingInitType init_type)
|
||||
{
|
||||
NMSetting *setting;
|
||||
|
||||
g_return_val_if_fail (setting_info, NULL);
|
||||
|
||||
setting = g_object_new (setting_info->general->get_setting_gtype (), NULL);
|
||||
|
||||
if ( setting_info->setting_init_fcn
|
||||
&& init_type != NM_META_ACCESSOR_SETTING_INIT_TYPE_DEFAULT) {
|
||||
setting_info->setting_init_fcn (setting_info,
|
||||
setting,
|
||||
init_type);
|
||||
}
|
||||
|
||||
return setting;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/* this basically returns NMMetaSettingType.properties, but with type
|
||||
|
|
@ -186,14 +211,14 @@ nm_meta_setting_infos_editor_p (void)
|
|||
/*****************************************************************************/
|
||||
|
||||
const char *
|
||||
nm_meta_abstract_info_get_name (const NMMetaAbstractInfo *abstract_info)
|
||||
nm_meta_abstract_info_get_name (const NMMetaAbstractInfo *abstract_info, gboolean for_header)
|
||||
{
|
||||
const char *n;
|
||||
|
||||
nm_assert (abstract_info);
|
||||
nm_assert (abstract_info->meta_type);
|
||||
nm_assert (abstract_info->meta_type->get_name);
|
||||
n = abstract_info->meta_type->get_name (abstract_info);
|
||||
n = abstract_info->meta_type->get_name (abstract_info, for_header);
|
||||
nm_assert (n && n[0]);
|
||||
return n;
|
||||
}
|
||||
|
|
@ -223,3 +248,104 @@ nm_meta_abstract_info_get_nested (const NMMetaAbstractInfo *abstract_info,
|
|||
NM_SET_OUT (out_len, 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gconstpointer
|
||||
nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info,
|
||||
const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gpointer *out_to_free)
|
||||
{
|
||||
nm_assert (abstract_info);
|
||||
nm_assert (abstract_info->meta_type);
|
||||
nm_assert (!out_to_free || !*out_to_free);
|
||||
nm_assert (out_flags);
|
||||
|
||||
*out_flags = NM_META_ACCESSOR_GET_OUT_FLAGS_NONE;
|
||||
|
||||
if (!abstract_info->meta_type->get_fcn)
|
||||
g_return_val_if_reached (NULL);
|
||||
|
||||
return abstract_info->meta_type->get_fcn (abstract_info,
|
||||
environment,
|
||||
environment_user_data,
|
||||
target,
|
||||
get_type,
|
||||
get_flags,
|
||||
out_flags,
|
||||
out_to_free);
|
||||
}
|
||||
|
||||
const char *const*
|
||||
nm_meta_abstract_info_complete (const NMMetaAbstractInfo *abstract_info,
|
||||
const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NMMetaOperationContext *operation_context,
|
||||
const char *text,
|
||||
char ***out_to_free)
|
||||
{
|
||||
const char *const*values;
|
||||
gsize i, j, text_len;
|
||||
|
||||
nm_assert (abstract_info);
|
||||
nm_assert (abstract_info->meta_type);
|
||||
nm_assert (out_to_free && !*out_to_free);
|
||||
|
||||
*out_to_free = NULL;
|
||||
|
||||
if (!abstract_info->meta_type->complete_fcn)
|
||||
return NULL;
|
||||
|
||||
values = abstract_info->meta_type->complete_fcn (abstract_info,
|
||||
environment,
|
||||
environment_user_data,
|
||||
operation_context,
|
||||
text,
|
||||
out_to_free);
|
||||
|
||||
nm_assert (!*out_to_free || values == (const char *const*) *out_to_free);
|
||||
|
||||
if (!text || !text[0] || !values || !values[0])
|
||||
return values;
|
||||
|
||||
/* for convenience, we all the complete_fcn() implementations to
|
||||
* ignore "text". We filter out invalid matches here. */
|
||||
|
||||
text_len = strlen (text);
|
||||
|
||||
if (*out_to_free) {
|
||||
char **v = *out_to_free;
|
||||
|
||||
for (i =0, j = 0; v[i]; i++) {
|
||||
if (strncmp (v[i], text, text_len) != 0)
|
||||
continue;
|
||||
v[j++] = v[i];
|
||||
}
|
||||
v[j++] = NULL;
|
||||
return (const char *const*) *out_to_free;
|
||||
} else {
|
||||
const char *const*v = values;
|
||||
char **r;
|
||||
|
||||
for (i = 0, j = 0; v[i]; i++) {
|
||||
if (strncmp (v[i], text, text_len) != 0)
|
||||
continue;
|
||||
j++;
|
||||
}
|
||||
if (j == i)
|
||||
return values;
|
||||
|
||||
r = g_new (char *, j + 1);
|
||||
v = values;
|
||||
for (i = 0, j = 0; v[i]; i++) {
|
||||
if (strncmp (v[i], text, text_len) != 0)
|
||||
continue;
|
||||
r[j++] = g_strdup (v[i]);
|
||||
}
|
||||
r[j++] = NULL;
|
||||
return (const char *const*) (*out_to_free = r);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,10 @@
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
const NMMetaSettingInfoEditor *nm_meta_setting_info_editor_find_by_name (const char *setting_name);
|
||||
NMSetting *nm_meta_setting_info_editor_new_setting (const NMMetaSettingInfoEditor *setting_info,
|
||||
NMMetaAccessorSettingInitType init_type);
|
||||
|
||||
const NMMetaSettingInfoEditor *nm_meta_setting_info_editor_find_by_name (const char *setting_name, gboolean use_alias);
|
||||
const NMMetaSettingInfoEditor *nm_meta_setting_info_editor_find_by_gtype (GType gtype);
|
||||
const NMMetaSettingInfoEditor *nm_meta_setting_info_editor_find_by_setting (NMSetting *setting);
|
||||
|
||||
|
|
@ -44,12 +47,28 @@ const NMMetaSettingInfoEditor *const*nm_meta_setting_infos_editor_p (void);
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
const char *nm_meta_abstract_info_get_name (const NMMetaAbstractInfo *abstract_info);
|
||||
const char *nm_meta_abstract_info_get_name (const NMMetaAbstractInfo *abstract_info, gboolean for_header);
|
||||
|
||||
const NMMetaAbstractInfo *const*nm_meta_abstract_info_get_nested (const NMMetaAbstractInfo *abstract_info,
|
||||
guint *out_len,
|
||||
gpointer *nested_to_free);
|
||||
|
||||
gconstpointer nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info,
|
||||
const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gpointer *out_to_free);
|
||||
|
||||
const char *const*nm_meta_abstract_info_complete (const NMMetaAbstractInfo *abstract_info,
|
||||
const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NMMetaOperationContext *operation_context,
|
||||
const char *text,
|
||||
char ***out_to_free);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#endif /* _NM_META_SETTING_ACCESS_H__ */
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -22,8 +22,64 @@
|
|||
|
||||
#include "nm-meta-setting.h"
|
||||
|
||||
struct _NMDevice;
|
||||
|
||||
#define NM_META_TEXT_HIDDEN "<hidden>"
|
||||
|
||||
#define NM_META_TEXT_PROMPT_ADSL_PROTO N_("Protocol")
|
||||
#define NM_META_TEXT_PROMPT_ADSL_PROTO_CHOICES "(" NM_SETTING_ADSL_PROTOCOL_PPPOA "/" NM_SETTING_ADSL_PROTOCOL_PPPOE "/" NM_SETTING_ADSL_PROTOCOL_IPOATM ")"
|
||||
|
||||
#define NM_META_TEXT_PROMPT_ADSL_ENCAP N_("ADSL encapsulation")
|
||||
#define NM_META_TEXT_PROMPT_ADSL_ENCAP_CHOICES "(" NM_SETTING_ADSL_ENCAPSULATION_VCMUX "/" NM_SETTING_ADSL_ENCAPSULATION_LLC ") [none]"
|
||||
|
||||
#define NM_META_TEXT_PROMPT_CON_TYPE N_("Connection type")
|
||||
#define NM_META_TEXT_PROMPT_IFNAME N_("Interface name [*]")
|
||||
#define NM_META_TEXT_PROMPT_VPN_TYPE N_("VPN type")
|
||||
#define NM_META_TEXT_PROMPT_MASTER N_("Master")
|
||||
|
||||
#define NM_META_TEXT_PROMPT_IB_MODE N_("Transport mode")
|
||||
#define NM_META_TEXT_WORD_DATAGRAM "datagram"
|
||||
#define NM_META_TEXT_WORD_CONNECTED "connected"
|
||||
#define NM_META_TEXT_PROMPT_IB_MODE_CHOICES "(" NM_META_TEXT_WORD_DATAGRAM "/" NM_META_TEXT_WORD_CONNECTED ") [" NM_META_TEXT_WORD_DATAGRAM "]"
|
||||
|
||||
#define NM_META_TEXT_PROMPT_BT_TYPE N_("Bluetooth type")
|
||||
#define NM_META_TEXT_WORD_PANU "panu"
|
||||
#define NM_META_TEXT_WORD_DUN_GSM "dun-gsm"
|
||||
#define NM_META_TEXT_WORD_DUN_CDMA "dun-cdma"
|
||||
#define NM_META_TEXT_PROMPT_BT_TYPE_CHOICES "(" NM_META_TEXT_WORD_PANU "/" NM_META_TEXT_WORD_DUN_GSM "/" NM_META_TEXT_WORD_DUN_CDMA ") [" NM_META_TEXT_WORD_PANU "]"
|
||||
|
||||
#define NM_META_TEXT_PROMPT_BOND_MODE N_("Bonding mode")
|
||||
|
||||
#define NM_META_TEXT_PROMPT_BOND_MON_MODE N_("Bonding monitoring mode")
|
||||
#define NM_META_TEXT_WORD_MIIMON "miimon"
|
||||
#define NM_META_TEXT_WORD_ARP "arp"
|
||||
#define NM_META_TEXT_PROMPT_BOND_MON_MODE_CHOICES "(" NM_META_TEXT_WORD_MIIMON "/" NM_META_TEXT_WORD_ARP ") [" NM_META_TEXT_WORD_MIIMON "]"
|
||||
|
||||
#define NM_META_TEXT_PROMPT_WIFI_MODE N_("Wi-Fi mode")
|
||||
#define NM_META_TEXT_WORD_INFRA "infrastructure"
|
||||
#define NM_META_TEXT_WORD_AP "ap"
|
||||
#define NM_META_TEXT_WORD_ADHOC "adhoc"
|
||||
#define NM_META_TEXT_PROMPT_WIFI_MODE_CHOICES "(" NM_META_TEXT_WORD_INFRA "/" NM_META_TEXT_WORD_AP "/" NM_META_TEXT_WORD_ADHOC ") [" NM_META_TEXT_WORD_INFRA "]"
|
||||
|
||||
#define NM_META_TEXT_PROMPT_TUN_MODE N_("Tun mode")
|
||||
#define NM_META_TEXT_WORD_TUN "tun"
|
||||
#define NM_META_TEXT_WORD_TAP "tap"
|
||||
#define NM_META_TEXT_PROMPT_TUN_MODE_CHOICES "(" NM_META_TEXT_WORD_TUN "/" NM_META_TEXT_WORD_TAP ") [" NM_META_TEXT_WORD_TUN "]"
|
||||
|
||||
#define NM_META_TEXT_PROMPT_IP_TUNNEL_MODE N_("IP Tunnel mode")
|
||||
|
||||
#define NM_META_TEXT_PROMPT_MACVLAN_MODE N_("MACVLAN mode")
|
||||
|
||||
#define NM_META_TEXT_PROMPT_MACSEC_MODE N_("MACsec mode")
|
||||
#define NM_META_TEXT_WORD_PSK "psk"
|
||||
#define NM_META_TEXT_WORD_EAP "eap"
|
||||
#define NM_META_TEXT_PROMPT_MACSEC_MODE_CHOICES "(" NM_META_TEXT_WORD_PSK "/" NM_META_TEXT_WORD_EAP ")"
|
||||
|
||||
#define NM_META_TEXT_PROMPT_PROXY_METHOD N_("Proxy method")
|
||||
#define NM_META_TEXT_WORD_NONE "none"
|
||||
#define NM_META_TEXT_WORD_AUTO "auto"
|
||||
#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,
|
||||
|
|
@ -49,13 +105,51 @@ typedef enum {
|
|||
typedef enum {
|
||||
NM_META_ACCESSOR_GET_TYPE_PRETTY,
|
||||
NM_META_ACCESSOR_GET_TYPE_PARSABLE,
|
||||
NM_META_ACCESSOR_GET_TYPE_TERMFORMAT,
|
||||
} NMMetaAccessorGetType;
|
||||
|
||||
typedef enum {
|
||||
NM_META_ACCESSOR_SETTING_INIT_TYPE_DEFAULT,
|
||||
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_SHOW_SECRETS = (1LL << 0),
|
||||
NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV = (1LL << 0),
|
||||
NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS = (1LL << 1),
|
||||
} NMMetaAccessorGetFlags;
|
||||
|
||||
typedef enum {
|
||||
NM_META_ACCESSOR_GET_OUT_FLAGS_NONE = 0,
|
||||
NM_META_ACCESSOR_GET_OUT_FLAGS_STRV = (1LL << 0),
|
||||
} NMMetaAccessorGetOutFlags;
|
||||
|
||||
typedef enum {
|
||||
NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC = (1LL << 0),
|
||||
NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC_HEX = (1LL << 1),
|
||||
|
|
@ -79,27 +173,36 @@ typedef struct _NMMetaSettingInfoEditor NMMetaSettingInfoEditor;
|
|||
typedef struct _NMMetaPropertyInfo NMMetaPropertyInfo;
|
||||
typedef struct _NMMetaPropertyType NMMetaPropertyType;
|
||||
typedef struct _NMMetaPropertyTypData NMMetaPropertyTypData;
|
||||
typedef struct _NMMetaOperationContext NMMetaOperationContext;
|
||||
|
||||
/* this gives some context information for virtual functions.
|
||||
* This command actually violates layering, and should be considered
|
||||
* a hack. In the future, try to replace it's use. */
|
||||
struct _NMMetaOperationContext {
|
||||
NMConnection *connection;
|
||||
};
|
||||
|
||||
struct _NMMetaPropertyType {
|
||||
|
||||
const char *(*describe_fcn) (const NMMetaPropertyInfo *property_info,
|
||||
char **out_to_free);
|
||||
|
||||
char *(*get_fcn) (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NMMetaPropertyInfo *property_info,
|
||||
NMSetting *setting,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags);
|
||||
gboolean (*set_fcn) (const NMMetaEnvironment *environment,
|
||||
gconstpointer (*get_fcn) (const NMMetaPropertyInfo *property_info,
|
||||
const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
NMSetting *setting,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gpointer *out_to_free);
|
||||
gboolean (*set_fcn) (const NMMetaPropertyInfo *property_info,
|
||||
const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NMMetaPropertyInfo *property_info,
|
||||
NMSetting *setting,
|
||||
const char *value,
|
||||
GError **error);
|
||||
gboolean (*remove_fcn) (const NMMetaEnvironment *environment,
|
||||
gboolean (*remove_fcn) (const NMMetaPropertyInfo *property_info,
|
||||
const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NMMetaPropertyInfo *property_info,
|
||||
NMSetting *setting,
|
||||
const char *option,
|
||||
guint32 idx,
|
||||
|
|
@ -107,10 +210,19 @@ struct _NMMetaPropertyType {
|
|||
|
||||
const char *const*(*values_fcn) (const NMMetaPropertyInfo *property_info,
|
||||
char ***out_to_free);
|
||||
|
||||
const char *const*(*complete_fcn) (const NMMetaPropertyInfo *property_info,
|
||||
const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NMMetaOperationContext *operation_context,
|
||||
const char *text,
|
||||
char ***out_to_free);
|
||||
};
|
||||
|
||||
struct _NMUtilsEnumValueInfo;
|
||||
|
||||
struct _NMMetaPropertyTypDataNested;
|
||||
|
||||
struct _NMMetaPropertyTypData {
|
||||
union {
|
||||
struct {
|
||||
|
|
@ -128,11 +240,29 @@ struct _NMMetaPropertyTypData {
|
|||
struct {
|
||||
NMMetaPropertyTypeMacMode mode;
|
||||
} mac;
|
||||
struct {
|
||||
const struct _NMMetaPropertyTypDataNested *data;
|
||||
} nested;
|
||||
} subtype;
|
||||
const char *const*values_static;
|
||||
NMMetaPropertyTypFlags typ_flags;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
NM_META_PROPERTY_INF_FLAG_NONE = 0x00,
|
||||
NM_META_PROPERTY_INF_FLAG_REQD = 0x01, /* Don't ask to ask. */
|
||||
NM_META_PROPERTY_INF_FLAG_DONT_ASK = 0x02, /* Don't ask interactively by default */
|
||||
NM_META_PROPERTY_INF_FLAG_MULTI = 0x04, /* Ask multiple times, do an append instead of set. */
|
||||
} NMMetaPropertyInfFlags;
|
||||
|
||||
enum {
|
||||
_NM_META_PROPERTY_TYPE_VPN_SERVICE_TYPE = 0,
|
||||
_NM_META_PROPERTY_TYPE_CONNECTION_TYPE = 4,
|
||||
};
|
||||
|
||||
#define nm_meta_property_info_connection_type (&nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_CONNECTION].properties[_NM_META_PROPERTY_TYPE_CONNECTION_TYPE])
|
||||
#define nm_meta_property_info_vpn_service_type (&nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_VPN].properties[_NM_META_PROPERTY_TYPE_VPN_SERVICE_TYPE])
|
||||
|
||||
struct _NMMetaPropertyInfo {
|
||||
const NMMetaType *meta_type;
|
||||
|
||||
|
|
@ -140,14 +270,17 @@ struct _NMMetaPropertyInfo {
|
|||
|
||||
const char *property_name;
|
||||
|
||||
/* the property list for now must contain as first field the
|
||||
* "name", which isn't a regular property. This is required by
|
||||
* NmcOutputField and this first field is ignored for the
|
||||
* group_list/setting_info. */
|
||||
bool is_name:1;
|
||||
const char *property_alias;
|
||||
|
||||
NMMetaPropertyInfFlags inf_flags;
|
||||
bool is_secret:1;
|
||||
|
||||
bool is_cli_option:1;
|
||||
|
||||
const char *prompt;
|
||||
|
||||
const char *def_hint;
|
||||
|
||||
const char *describe_doc;
|
||||
|
||||
const char *describe_message;
|
||||
|
|
@ -156,38 +289,63 @@ struct _NMMetaPropertyInfo {
|
|||
const NMMetaPropertyTypData *property_typ_data;
|
||||
};
|
||||
|
||||
typedef struct _NMMetaSettingValidPartItem {
|
||||
const NMMetaSettingInfoEditor *setting_info;
|
||||
bool mandatory;
|
||||
} NMMetaSettingValidPartItem;
|
||||
|
||||
struct _NMMetaSettingInfoEditor {
|
||||
const NMMetaType *meta_type;
|
||||
const NMMetaSettingInfo *general;
|
||||
const char *alias;
|
||||
const char *pretty_name;
|
||||
/* the order of the properties matter. The first *must* be the
|
||||
* "name", and then the order is as they are listed by default. */
|
||||
const NMMetaPropertyInfo *properties;
|
||||
guint properties_num;
|
||||
|
||||
/* a NMConnection has a main type (connection.type), which is a
|
||||
* main NMSetting instance. Depending on the type, a connection
|
||||
* may have a list of other allowed settings.
|
||||
*
|
||||
* For example, a connection of type "vlan" may have settings
|
||||
* of type "connection", "vlan", and "wired".
|
||||
*
|
||||
* Some setting types a not a main type (NMSettingProxy). They
|
||||
* don't have valid_settings but are usually referenced by other
|
||||
* settings to be valid for them. */
|
||||
const NMMetaSettingValidPartItem *const*valid_parts;
|
||||
|
||||
void (*setting_init_fcn) (const NMMetaSettingInfoEditor *setting_info,
|
||||
NMSetting *setting,
|
||||
NMMetaAccessorSettingInitType init_type);
|
||||
};
|
||||
|
||||
struct _NMMetaType {
|
||||
const char *type_name;
|
||||
const char *(*get_name) (const NMMetaAbstractInfo *abstract_info);
|
||||
const char *(*get_name) (const NMMetaAbstractInfo *abstract_info,
|
||||
gboolean for_header);
|
||||
const NMMetaAbstractInfo *const*(*get_nested) (const NMMetaAbstractInfo *abstract_info,
|
||||
guint *out_len,
|
||||
gpointer *out_to_free);
|
||||
gconstpointer (*get_fcn) (const NMMetaEnvironment *environment,
|
||||
gconstpointer (*get_fcn) (const NMMetaAbstractInfo *info,
|
||||
const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NMMetaAbstractInfo *info,
|
||||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gpointer *out_to_free);
|
||||
const char *const*(*complete_fcn) (const NMMetaAbstractInfo *info,
|
||||
const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NMMetaOperationContext *operation_context,
|
||||
const char *text,
|
||||
char ***out_to_free);
|
||||
};
|
||||
|
||||
struct _NMMetaAbstractInfo {
|
||||
union {
|
||||
const NMMetaType *meta_type;
|
||||
union {
|
||||
NMMetaSettingInfoEditor setting_info;
|
||||
NMMetaPropertyInfo property_info;
|
||||
} as;
|
||||
};
|
||||
const NMMetaType *meta_type;
|
||||
};
|
||||
|
||||
extern const NMMetaType nm_meta_type_setting_info_editor;
|
||||
|
|
@ -195,6 +353,10 @@ extern const NMMetaType nm_meta_type_property_info;
|
|||
|
||||
extern const NMMetaSettingInfoEditor nm_meta_setting_infos_editor[_NM_META_SETTING_TYPE_NUM];
|
||||
|
||||
extern const NMMetaSettingValidPartItem *const nm_meta_setting_info_valid_parts_default[];
|
||||
|
||||
const NMMetaSettingValidPartItem *const*nm_meta_setting_info_valid_parts_for_slave_type (const char *slave_type, const char **out_slave_name);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef enum {
|
||||
|
|
@ -214,8 +376,40 @@ struct _NMMetaEnvironment {
|
|||
const char *fmt_l10n, /* the untranslated format string, but it is marked for translation using N_(). */
|
||||
va_list ap);
|
||||
|
||||
struct _NMDevice *const*(*get_nm_devices) (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
guint *out_len);
|
||||
|
||||
struct _NMRemoteConnection *const*(*get_nm_connections) (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
guint *out_len);
|
||||
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/* NMSettingBond is special in that it has nested properties.
|
||||
* We will add API to proper handle such types (Bond, VPN, User),
|
||||
* but for now just expose the type info directly. */
|
||||
|
||||
extern const NMMetaType nm_meta_type_nested_property_info;
|
||||
|
||||
typedef struct _NMMetaNestedPropertyTypeInfo {
|
||||
const NMMetaType *meta_type;
|
||||
const NMMetaPropertyInfo *parent_info;
|
||||
const char *field_name;
|
||||
NMMetaPropertyInfFlags inf_flags;
|
||||
const char *prompt;
|
||||
const char *def_hint;
|
||||
} NMMetaNestedPropertyTypeInfo;
|
||||
|
||||
typedef struct _NMMetaPropertyTypDataNested {
|
||||
const NMMetaNestedPropertyTypeInfo *nested;
|
||||
guint nested_len;
|
||||
} NMMetaPropertyTypDataNested;
|
||||
|
||||
const NMMetaPropertyTypDataNested nm_meta_property_typ_data_bond;
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#endif /* __NM_META_SETTING_DESC_H__ */
|
||||
|
|
|
|||
|
|
@ -34,6 +34,9 @@ test_client_meta_check (void)
|
|||
NMMetaSettingType m;
|
||||
guint p;
|
||||
|
||||
G_STATIC_ASSERT (G_STRUCT_OFFSET (NMMetaAbstractInfo, meta_type) == G_STRUCT_OFFSET (NMMetaSettingInfoEditor, meta_type));
|
||||
G_STATIC_ASSERT (G_STRUCT_OFFSET (NMMetaAbstractInfo, meta_type) == G_STRUCT_OFFSET (NMMetaPropertyInfo, meta_type));
|
||||
|
||||
for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) {
|
||||
const NMMetaSettingInfo *info = &nm_meta_setting_infos[m];
|
||||
GType gtype;
|
||||
|
|
@ -68,7 +71,8 @@ test_client_meta_check (void)
|
|||
g_assert (info->general);
|
||||
g_assert (info->general == &nm_meta_setting_infos[m]);
|
||||
|
||||
g_assert (info->general->setting_name == info->meta_type->get_name ((const NMMetaAbstractInfo *) info));
|
||||
g_assert_cmpstr (info->general->setting_name, ==, info->meta_type->get_name ((const NMMetaAbstractInfo *) info, FALSE));
|
||||
g_assert_cmpstr ("name", ==, info->meta_type->get_name ((const NMMetaAbstractInfo *) info, TRUE));
|
||||
|
||||
if (info->properties_num) {
|
||||
gs_unref_hashtable GHashTable *property_names = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
|
|
@ -83,18 +87,37 @@ test_client_meta_check (void)
|
|||
|
||||
g_assert (nm_g_hash_table_add (property_names, (gpointer) pi->property_name));
|
||||
|
||||
g_assert (pi->property_name == pi->meta_type->get_name ((const NMMetaAbstractInfo *) pi));
|
||||
|
||||
if (pi->is_name)
|
||||
g_assert (p == 0);
|
||||
else
|
||||
g_assert (p != 0);
|
||||
g_assert_cmpstr (pi->property_name, ==, pi->meta_type->get_name ((const NMMetaAbstractInfo *) pi, FALSE));
|
||||
g_assert_cmpstr (pi->property_name, ==, pi->meta_type->get_name ((const NMMetaAbstractInfo *) pi, TRUE));
|
||||
|
||||
g_assert (pi->property_type);
|
||||
g_assert (pi->property_type->get_fcn);
|
||||
}
|
||||
} else
|
||||
g_assert (!info->properties);
|
||||
|
||||
if (info->valid_parts) {
|
||||
gsize i, l;
|
||||
gs_unref_hashtable GHashTable *dup = g_hash_table_new (NULL, NULL);
|
||||
|
||||
l = NM_PTRARRAY_LEN (info->valid_parts);
|
||||
g_assert (l >= 2);
|
||||
|
||||
for (i = 0; info->valid_parts[i]; i++) {
|
||||
g_assert (info->valid_parts[i]->setting_info);
|
||||
g_assert (nm_g_hash_table_add (dup, (gpointer) info->valid_parts[i]->setting_info));
|
||||
|
||||
if (i == 0) {
|
||||
g_assert (info->valid_parts[i]->setting_info == &nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_CONNECTION]);
|
||||
g_assert (info->valid_parts[i]->mandatory);
|
||||
}
|
||||
if (i == 1) {
|
||||
g_assert (info->valid_parts[i]->setting_info == &nm_meta_setting_infos_editor[m]);
|
||||
g_assert (info->valid_parts[i]->mandatory);
|
||||
}
|
||||
}
|
||||
g_assert (i == l);
|
||||
}
|
||||
}
|
||||
|
||||
for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) {
|
||||
|
|
@ -112,7 +135,7 @@ test_client_meta_check (void)
|
|||
for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) {
|
||||
const NMMetaSettingInfoEditor *info = &nm_meta_setting_infos_editor[m];
|
||||
|
||||
g_assert (nm_meta_setting_info_editor_find_by_name (info->general->setting_name) == info);
|
||||
g_assert (nm_meta_setting_info_editor_find_by_name (info->general->setting_name, FALSE) == info);
|
||||
g_assert (nm_meta_setting_info_editor_find_by_gtype (info->general->get_setting_gtype ()) == info);
|
||||
|
||||
for (p = 0; p < info->properties_num; p++) {
|
||||
|
|
|
|||
|
|
@ -4655,6 +4655,81 @@ test_nm_utils_strstrdictkey (void)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
static guint
|
||||
_g_strv_length (gconstpointer arr)
|
||||
{
|
||||
return arr ? g_strv_length ((char **) arr) : 0;
|
||||
}
|
||||
|
||||
static void
|
||||
test_nm_ptrarray_len (void)
|
||||
{
|
||||
#define _PTRARRAY_cmp(len, arr) \
|
||||
G_STMT_START { \
|
||||
g_assert_cmpint (len, ==, NM_PTRARRAY_LEN (arr)); \
|
||||
g_assert_cmpint (len, ==, _g_strv_length (arr)); \
|
||||
} G_STMT_END
|
||||
#define _PTRARRAY_LEN0(T) \
|
||||
G_STMT_START { \
|
||||
T **vnull = NULL; \
|
||||
T *const*vnull1 = NULL; \
|
||||
T *const*const vnull2 = NULL; \
|
||||
T *v0[] = { NULL }; \
|
||||
T *const*v01 = v0; \
|
||||
T *const*const v02 = v0; \
|
||||
T **const v03 = v0; \
|
||||
\
|
||||
_PTRARRAY_cmp (0, vnull); \
|
||||
_PTRARRAY_cmp (0, vnull1); \
|
||||
_PTRARRAY_cmp (0, vnull2); \
|
||||
_PTRARRAY_cmp (0, v0); \
|
||||
_PTRARRAY_cmp (0, v01); \
|
||||
_PTRARRAY_cmp (0, v02); \
|
||||
_PTRARRAY_cmp (0, v03); \
|
||||
} G_STMT_END
|
||||
|
||||
_PTRARRAY_LEN0 (char);
|
||||
_PTRARRAY_LEN0 (const char);
|
||||
_PTRARRAY_LEN0 (int);
|
||||
_PTRARRAY_LEN0 (const int);
|
||||
_PTRARRAY_LEN0 (void *);
|
||||
_PTRARRAY_LEN0 (void);
|
||||
_PTRARRAY_LEN0 (const void);
|
||||
|
||||
#define _PTRARRAY_LENn(T) \
|
||||
G_STMT_START { \
|
||||
T x[5] = { 0 }; \
|
||||
\
|
||||
T *v1[] = { &x[0], NULL }; \
|
||||
T *const*v11 = v1; \
|
||||
T *const*const v12 = v1; \
|
||||
T **const v13 = v1; \
|
||||
\
|
||||
T *v2[] = { &x[0], &x[1], NULL }; \
|
||||
T *const*v21 = v2; \
|
||||
T *const*const v22 = v2; \
|
||||
T **const v23 = v2; \
|
||||
\
|
||||
_PTRARRAY_cmp (1, v1); \
|
||||
_PTRARRAY_cmp (1, v11); \
|
||||
_PTRARRAY_cmp (1, v12); \
|
||||
_PTRARRAY_cmp (1, v13); \
|
||||
\
|
||||
_PTRARRAY_cmp (2, v2); \
|
||||
_PTRARRAY_cmp (2, v21); \
|
||||
_PTRARRAY_cmp (2, v22); \
|
||||
_PTRARRAY_cmp (2, v23); \
|
||||
} G_STMT_END
|
||||
|
||||
_PTRARRAY_LENn (char);
|
||||
_PTRARRAY_LENn (const char);
|
||||
_PTRARRAY_LENn (int);
|
||||
_PTRARRAY_LENn (const int);
|
||||
_PTRARRAY_LENn (void *);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
test_nm_utils_dns_option_validate_do (char *option, gboolean ipv6, const NMUtilsDNSOptionDesc *descs,
|
||||
gboolean exp_result, char *exp_name, gboolean exp_value)
|
||||
|
|
@ -5716,6 +5791,7 @@ int main (int argc, char **argv)
|
|||
g_test_add_func ("/core/general/_glib_compat_g_hash_table_get_keys_as_array", test_g_hash_table_get_keys_as_array);
|
||||
g_test_add_func ("/core/general/_nm_utils_ptrarray_find_binary_search", test_nm_utils_ptrarray_find_binary_search);
|
||||
g_test_add_func ("/core/general/_nm_utils_strstrdictkey", test_nm_utils_strstrdictkey);
|
||||
g_test_add_func ("/core/general/nm_ptrarray_len", test_nm_ptrarray_len);
|
||||
|
||||
g_test_add_func ("/core/general/_nm_utils_dns_option_validate", test_nm_utils_dns_option_validate);
|
||||
g_test_add_func ("/core/general/_nm_utils_dns_option_find_idx", test_nm_utils_dns_option_find_idx);
|
||||
|
|
|
|||
|
|
@ -190,6 +190,11 @@ const NMMetaSettingInfo nm_meta_setting_infos[] = {
|
|||
.setting_name = N_ (NM_SETTING_DUMMY_SETTING_NAME),
|
||||
.get_setting_gtype = nm_setting_dummy_get_type,
|
||||
},
|
||||
[NM_META_SETTING_TYPE_GENERIC] = {
|
||||
.meta_type = NM_META_SETTING_TYPE_GENERIC,
|
||||
.setting_name = N_ (NM_SETTING_GENERIC_SETTING_NAME),
|
||||
.get_setting_gtype = nm_setting_generic_get_type,
|
||||
},
|
||||
[NM_META_SETTING_TYPE_GSM] = {
|
||||
.meta_type = NM_META_SETTING_TYPE_GSM,
|
||||
.setting_name = N_ (NM_SETTING_GSM_SETTING_NAME),
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ typedef enum {
|
|||
NM_META_SETTING_TYPE_CONNECTION,
|
||||
NM_META_SETTING_TYPE_DCB,
|
||||
NM_META_SETTING_TYPE_DUMMY,
|
||||
NM_META_SETTING_TYPE_GENERIC,
|
||||
NM_META_SETTING_TYPE_GSM,
|
||||
NM_META_SETTING_TYPE_INFINIBAND,
|
||||
NM_META_SETTING_TYPE_IP4_CONFIG,
|
||||
|
|
|
|||
|
|
@ -209,6 +209,23 @@ NM_G_ERROR_MSG (GError *error)
|
|||
/* macro to return strlen() of a compile time string. */
|
||||
#define NM_STRLEN(str) ( sizeof ("" str) - 1 )
|
||||
|
||||
/* returns the length of a NULL terminated array of pointers,
|
||||
* like g_strv_length() does. The difference is:
|
||||
* - it operats on arrays of pointers (of any kind, requiring no cast).
|
||||
* - it accepts NULL to return zero. */
|
||||
#define NM_PTRARRAY_LEN(array) \
|
||||
({ \
|
||||
typeof (*(array)) *const _array = (array); \
|
||||
gsize _n = 0; \
|
||||
\
|
||||
if (_array) { \
|
||||
_nm_unused typeof (*(_array[0])) *_array_check = _array[0]; \
|
||||
while (_array[_n]) \
|
||||
_n++; \
|
||||
} \
|
||||
_n; \
|
||||
})
|
||||
|
||||
/* Note: @value is only evaluated when *out_val is present.
|
||||
* Thus,
|
||||
* NM_SET_OUT (out_str, g_strdup ("hallo"));
|
||||
|
|
|
|||
|
|
@ -27,6 +27,10 @@
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
const void *const _NM_PTRARRAY_EMPTY[1] = { NULL };
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void
|
||||
nm_utils_strbuf_append_c (char **buf, gsize *len, char c)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -24,6 +24,10 @@
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
extern const void *const _NM_PTRARRAY_EMPTY[1];
|
||||
|
||||
#define NM_PTRARRAY_EMPTY(type) ((type const*) _NM_PTRARRAY_EMPTY)
|
||||
|
||||
static inline void
|
||||
_nm_utils_strbuf_init (char *buf, gsize len, char **p_buf_ptr, gsize *p_buf_len)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue