mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-09 14:40:21 +01:00
cli: use nmc_print() to output device's IP4 info
The IP4 info adds a new type: to expose strv arguments for addresses, etc.
This commit is contained in:
parent
c5c48d4f5f
commit
41b31051f2
13 changed files with 384 additions and 206 deletions
|
|
@ -36,17 +36,122 @@
|
|||
|
||||
#include "utils.h"
|
||||
|
||||
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 */
|
||||
|
|
@ -72,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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
@ -80,7 +80,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[];
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ const NmcMetaGenericInfo *const nmc_fields_con_active_details_vpn[] = {
|
|||
|
||||
const NmcMetaGenericInfo *const nmc_fields_con_active_details_groups[] = {
|
||||
NMC_META_GENERIC_WITH_NESTED ("GENERAL", nmc_fields_con_active_details_general + 1), /* 0 */
|
||||
NMC_META_GENERIC_WITH_NESTED ("IP4", nmc_fields_ip4_config + 1), /* 1 */
|
||||
NMC_META_GENERIC_WITH_NESTED ("IP4", metagen_ip4_config), /* 1 */
|
||||
NMC_META_GENERIC_WITH_NESTED ("DHCP4", nmc_fields_dhcp4_config + 1), /* 2 */
|
||||
NMC_META_GENERIC_WITH_NESTED ("IP6", nmc_fields_ip6_config + 1), /* 3 */
|
||||
NMC_META_GENERIC_WITH_NESTED ("DHCP6", nmc_fields_dhcp6_config + 1), /* 4 */
|
||||
|
|
@ -1215,7 +1215,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc)
|
|||
gboolean b1 = FALSE;
|
||||
NMIPConfig *cfg4 = nm_active_connection_get_ip4_config (acon);
|
||||
|
||||
b1 = print_ip4_config (cfg4, &nmc->nmc_config, "IP4", group_fld);
|
||||
b1 = print_ip4_config (cfg4, &nmc->nmc_config, group_fld);
|
||||
was_output = was_output || b1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
@ -1269,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))
|
||||
|
|
|
|||
|
|
@ -161,12 +161,6 @@ _NM_UTILS_LOOKUP_DEFINE (static, permission_result_to_color, NMClientPermissionR
|
|||
NM_UTILS_LOOKUP_ITEM_IGNORE (NM_CLIENT_PERMISSION_RESULT_UNKNOWN),
|
||||
);
|
||||
|
||||
#define 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
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static const NmcMetaGenericInfo *const metagen_general_status[];
|
||||
|
|
@ -178,6 +172,7 @@ _metagen_general_status_get_fcn (const NMMetaEnvironment *environment,
|
|||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gpointer *out_to_free)
|
||||
{
|
||||
NmCli *nmc = target;
|
||||
|
|
@ -188,26 +183,26 @@ _metagen_general_status_get_fcn (const NMMetaEnvironment *environment,
|
|||
|
||||
switch (info->info_type) {
|
||||
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_RUNNING:
|
||||
HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
|
||||
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
|
||||
value = N_("running");
|
||||
goto translate_and_out;
|
||||
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_VERSION:
|
||||
HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
|
||||
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);
|
||||
HANDLE_TERMFORMAT (state_to_color (state));
|
||||
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);
|
||||
HANDLE_TERMFORMAT (v_bool ? NM_META_TERM_COLOR_YELLOW : NM_META_TERM_COLOR_GREEN);
|
||||
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);
|
||||
HANDLE_TERMFORMAT (connectivity_to_color (connectivity));
|
||||
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:
|
||||
|
|
@ -236,7 +231,7 @@ _metagen_general_status_get_fcn (const NMMetaEnvironment *environment,
|
|||
g_return_val_if_reached (NULL);
|
||||
|
||||
enabled_out:
|
||||
HANDLE_TERMFORMAT (v_bool ? NM_META_TERM_COLOR_GREEN : NM_META_TERM_COLOR_RED);
|
||||
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;
|
||||
|
||||
|
|
@ -284,6 +279,7 @@ _metagen_general_permissions_get_fcn (const NMMetaEnvironment *environment,
|
|||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gpointer *out_to_free)
|
||||
{
|
||||
NMClientPermission perm = GPOINTER_TO_UINT (target);
|
||||
|
|
@ -293,11 +289,11 @@ _metagen_general_permissions_get_fcn (const NMMetaEnvironment *environment,
|
|||
|
||||
switch (info->info_type) {
|
||||
case NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_PERMISSION:
|
||||
HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
|
||||
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);
|
||||
HANDLE_TERMFORMAT (permission_result_to_color (perm_result));
|
||||
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);
|
||||
|
|
@ -331,6 +327,7 @@ _metagen_general_logging_get_fcn (const NMMetaEnvironment *environment,
|
|||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gpointer *out_to_free)
|
||||
{
|
||||
NmCli *nmc = environment_user_data;
|
||||
|
|
@ -338,7 +335,7 @@ _metagen_general_logging_get_fcn (const NMMetaEnvironment *environment,
|
|||
|
||||
nm_assert (info->info_type < _NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_NUM);
|
||||
|
||||
HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
|
||||
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
|
||||
|
||||
if (!d->initialized) {
|
||||
d->initialized = TRUE;
|
||||
|
|
|
|||
|
|
@ -117,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);
|
||||
|
|
|
|||
|
|
@ -41,9 +41,13 @@
|
|||
/*****************************************************************************/
|
||||
|
||||
static const char *
|
||||
_meta_type_nmc_generic_info_get_name (const NMMetaAbstractInfo *abstract_info)
|
||||
_meta_type_nmc_generic_info_get_name (const NMMetaAbstractInfo *abstract_info, gboolean for_header)
|
||||
{
|
||||
return ((const NmcMetaGenericInfo *) abstract_info)->name;
|
||||
const NmcMetaGenericInfo *info = (const NmcMetaGenericInfo *) abstract_info;
|
||||
|
||||
if (for_header)
|
||||
return info->name_header ?: info->name;
|
||||
return info->name;
|
||||
}
|
||||
|
||||
static const NMMetaAbstractInfo *const*
|
||||
|
|
@ -75,14 +79,14 @@ _meta_type_nmc_generic_info_get_fcn (const NMMetaEnvironment *environment,
|
|||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gpointer *out_to_free)
|
||||
{
|
||||
const NmcMetaGenericInfo *info = (const NmcMetaGenericInfo *) abstract_info;
|
||||
|
||||
nm_assert (!out_to_free || !*out_to_free);
|
||||
nm_assert (out_flags && !*out_flags);
|
||||
|
||||
if (!info->get_fcn)
|
||||
g_return_val_if_reached (NULL);
|
||||
if (!NM_IN_SET (get_type,
|
||||
NM_META_ACCESSOR_GET_TYPE_PARSABLE,
|
||||
NM_META_ACCESSOR_GET_TYPE_PRETTY,
|
||||
|
|
@ -92,10 +96,26 @@ _meta_type_nmc_generic_info_get_fcn (const NMMetaEnvironment *environment,
|
|||
/* omitting the out_to_free value is only allowed for TERMFORMAT. */
|
||||
nm_assert (out_to_free || NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_TERMFORMAT));
|
||||
|
||||
return info->get_fcn (environment, environment_user_data,
|
||||
info, target,
|
||||
get_type, get_flags,
|
||||
out_to_free);
|
||||
if (info->get_fcn) {
|
||||
return info->get_fcn (environment, environment_user_data,
|
||||
info, target,
|
||||
get_type,
|
||||
get_flags,
|
||||
out_flags,
|
||||
out_to_free);
|
||||
}
|
||||
|
||||
if (info->nested) {
|
||||
const char *s;
|
||||
|
||||
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
|
||||
s = info->name;
|
||||
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
|
||||
return _(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
g_return_val_if_reached (NULL);
|
||||
}
|
||||
|
||||
const NMMetaType nmc_meta_type_generic_info = {
|
||||
|
|
@ -823,7 +843,7 @@ _output_selection_select_one (const NMMetaAbstractInfo *const* fields_array,
|
|||
for (i = 0; fields_array[i]; i++) {
|
||||
const NMMetaAbstractInfo *fi = fields_array[i];
|
||||
|
||||
if (g_ascii_strcasecmp (i_name, nm_meta_abstract_info_get_name (fi)) != 0)
|
||||
if (g_ascii_strcasecmp (i_name, nm_meta_abstract_info_get_name (fi, FALSE)) != 0)
|
||||
continue;
|
||||
|
||||
if (!right || !validate_nested) {
|
||||
|
|
@ -844,7 +864,7 @@ _output_selection_select_one (const NMMetaAbstractInfo *const* fields_array,
|
|||
const NmcMetaGenericInfo *fi_g = (const NmcMetaGenericInfo *) fi;
|
||||
|
||||
for (j = 0; fi_g->nested && fi_g->nested[j]; j++) {
|
||||
if (g_ascii_strcasecmp (right, nm_meta_abstract_info_get_name ((const NMMetaAbstractInfo *) fi_g->nested[j])) == 0) {
|
||||
if (g_ascii_strcasecmp (right, nm_meta_abstract_info_get_name ((const NMMetaAbstractInfo *) fi_g->nested[j], FALSE)) == 0) {
|
||||
found = TRUE;
|
||||
break;
|
||||
}
|
||||
|
|
@ -869,7 +889,7 @@ not_found:
|
|||
|
||||
if (fields_prefix) {
|
||||
p = g_strdup_printf ("%s.%s", fields_prefix,
|
||||
nm_meta_abstract_info_get_name (fields_array_failure));
|
||||
nm_meta_abstract_info_get_name (fields_array_failure, FALSE));
|
||||
}
|
||||
allowed_fields = nmc_get_allowed_fields_nested (fields_array_failure, p);
|
||||
} else
|
||||
|
|
@ -1038,7 +1058,9 @@ _output_selection_append (GArray *cols,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (selection_item->info->meta_type != &nm_meta_type_setting_info_editor)
|
||||
if (!NM_IN_SET(selection_item->info->meta_type,
|
||||
&nm_meta_type_setting_info_editor,
|
||||
&nmc_meta_type_generic_info))
|
||||
g_array_index (cols, PrintDataCol, col_idx).is_leaf = FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -1216,11 +1238,11 @@ nmc_get_allowed_fields_nested (const NMMetaAbstractInfo *abstract_info, const ch
|
|||
allowed_fields = g_string_sized_new (256);
|
||||
|
||||
if (!name_prefix)
|
||||
name_prefix = nm_meta_abstract_info_get_name (abstract_info);
|
||||
name_prefix = nm_meta_abstract_info_get_name (abstract_info, FALSE);
|
||||
|
||||
for (i = 0; nested[i]; i++) {
|
||||
g_string_append_printf (allowed_fields, "%s.%s,",
|
||||
name_prefix, nm_meta_abstract_info_get_name (nested[i]));
|
||||
name_prefix, nm_meta_abstract_info_get_name (nested[i], FALSE));
|
||||
}
|
||||
g_string_truncate (allowed_fields, allowed_fields->len - 1);
|
||||
return g_string_free (allowed_fields, FALSE);
|
||||
|
|
@ -1239,7 +1261,7 @@ nmc_get_allowed_fields (const NMMetaAbstractInfo *const*fields_array, const char
|
|||
for (i = 0; fields_array[i]; i++) {
|
||||
if (name_prefix)
|
||||
g_string_append_printf (allowed_fields, "%s.", name_prefix);
|
||||
g_string_append_printf (allowed_fields, "%s,", nm_meta_abstract_info_get_name (fields_array[i]));
|
||||
g_string_append_printf (allowed_fields, "%s,", nm_meta_abstract_info_get_name (fields_array[i], FALSE));
|
||||
}
|
||||
g_string_truncate (allowed_fields, allowed_fields->len - 1);
|
||||
return g_string_free (allowed_fields, FALSE);
|
||||
|
|
@ -1282,18 +1304,26 @@ nmc_empty_output_fields (NmcOutputData *output_data)
|
|||
typedef struct {
|
||||
guint col_idx;
|
||||
const PrintDataCol *col;
|
||||
bool is_nested;
|
||||
const char *title;
|
||||
bool title_to_free:1;
|
||||
int width;
|
||||
} PrintDataHeaderCell;
|
||||
|
||||
typedef enum {
|
||||
PRINT_DATA_CELL_FORMAT_TYPE_PLAIN = 0,
|
||||
PRINT_DATA_CELL_FORMAT_TYPE_STRV,
|
||||
} PrintDataCellFormatType;
|
||||
|
||||
typedef struct {
|
||||
guint row_idx;
|
||||
const PrintDataHeaderCell *header_cell;
|
||||
NMMetaTermColor term_color;
|
||||
NMMetaTermFormat term_format;
|
||||
const char *text;
|
||||
union {
|
||||
const char *plain;
|
||||
const char *const*strv;
|
||||
} text;
|
||||
PrintDataCellFormatType text_format:3;
|
||||
bool text_to_free:1;
|
||||
} PrintDataCell;
|
||||
|
||||
|
|
@ -1313,10 +1343,17 @@ static void
|
|||
_print_data_cell_clear_text (PrintDataCell *cell)
|
||||
{
|
||||
if (cell->text_to_free) {
|
||||
g_free ((char *) cell->text);
|
||||
switch (cell->text_format) {
|
||||
case PRINT_DATA_CELL_FORMAT_TYPE_PLAIN:
|
||||
g_free ((char *) cell->text.plain);
|
||||
break;
|
||||
case PRINT_DATA_CELL_FORMAT_TYPE_STRV:
|
||||
g_strfreev ((char **) cell->text.strv);
|
||||
break;
|
||||
};
|
||||
cell->text_to_free = FALSE;
|
||||
}
|
||||
cell->text = NULL;
|
||||
memset (&cell->text, 0, sizeof (cell->text));
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -1368,25 +1405,23 @@ _print_fill (const NmcConfig *nmc_config,
|
|||
|
||||
header_cell->col_idx = col_idx;
|
||||
header_cell->col = col;
|
||||
header_cell->is_nested = FALSE;
|
||||
|
||||
translate_title = pretty;
|
||||
|
||||
if (info->meta_type == &nm_meta_type_property_info) {
|
||||
header_cell->title = nm_meta_abstract_info_get_name (info);
|
||||
if (nmc_config->multiline_output) {
|
||||
header_cell->title = g_strdup_printf ("%s.%s",
|
||||
((const NMMetaPropertyInfo *) info)->setting_info->general->setting_name,
|
||||
header_cell->title);
|
||||
header_cell->title_to_free = TRUE;
|
||||
}
|
||||
} else if (info->meta_type == &nm_meta_type_setting_info_editor)
|
||||
header_cell->title = N_("name");
|
||||
else
|
||||
header_cell->title = nm_meta_abstract_info_get_name (info);
|
||||
|
||||
if (translate_title)
|
||||
header_cell->title = _(header_cell->title);
|
||||
header_cell->title = nm_meta_abstract_info_get_name (info, TRUE);
|
||||
if ( nmc_config->multiline_output
|
||||
&& col->parent_idx != PRINT_DATA_COL_PARENT_NIL
|
||||
&& NM_IN_SET (info->meta_type,
|
||||
&nm_meta_type_property_info,
|
||||
&nmc_meta_type_generic_info)) {
|
||||
header_cell->title = g_strdup_printf ("%s.%s",
|
||||
nm_meta_abstract_info_get_name (cols[col->parent_idx].selection_item->info, FALSE),
|
||||
header_cell->title);
|
||||
header_cell->title_to_free = TRUE;
|
||||
} else {
|
||||
if (translate_title)
|
||||
header_cell->title = _(header_cell->title);
|
||||
}
|
||||
}
|
||||
|
||||
targets_len = NM_PTRARRAY_LEN (targets);
|
||||
|
|
@ -1398,7 +1433,7 @@ _print_fill (const NmcConfig *nmc_config,
|
|||
text_get_type = pretty
|
||||
? NM_META_ACCESSOR_GET_TYPE_PRETTY
|
||||
: NM_META_ACCESSOR_GET_TYPE_PARSABLE;
|
||||
text_get_flags = NM_META_ACCESSOR_GET_FLAGS_NONE;
|
||||
text_get_flags = NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV;
|
||||
if (nmc_config->show_secrets)
|
||||
text_get_flags |= NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS;
|
||||
|
||||
|
|
@ -1411,20 +1446,40 @@ _print_fill (const NmcConfig *nmc_config,
|
|||
PrintDataCell *cell = &cells_line[i_col];
|
||||
const PrintDataHeaderCell *header_cell;
|
||||
const NMMetaAbstractInfo *info;
|
||||
NMMetaAccessorGetOutFlags text_out_flags, color_out_flags;
|
||||
gconstpointer value;
|
||||
|
||||
header_cell = &g_array_index (header_row, PrintDataHeaderCell, i_col);
|
||||
info = header_cell->col->selection_item->info;
|
||||
|
||||
cell->row_idx = i_row;
|
||||
cell->header_cell = header_cell;
|
||||
cell->text = nm_meta_abstract_info_get (info,
|
||||
NULL,
|
||||
&nm_cli,
|
||||
target,
|
||||
text_get_type,
|
||||
text_get_flags,
|
||||
(gpointer *) &to_free);
|
||||
cell->text_to_free = !!to_free;
|
||||
|
||||
value = nm_meta_abstract_info_get (info,
|
||||
NULL,
|
||||
&nm_cli,
|
||||
target,
|
||||
text_get_type,
|
||||
text_get_flags,
|
||||
&text_out_flags,
|
||||
(gpointer *) &to_free);
|
||||
if (NM_FLAGS_HAS (text_out_flags, NM_META_ACCESSOR_GET_OUT_FLAGS_STRV)) {
|
||||
if (value) {
|
||||
if (nmc_config->multiline_output) {
|
||||
cell->text_format = PRINT_DATA_CELL_FORMAT_TYPE_STRV;
|
||||
cell->text.strv = value;
|
||||
cell->text_to_free = !!to_free;
|
||||
} else {
|
||||
cell->text.plain = g_strjoinv (" | ", (char **) value);
|
||||
cell->text_to_free = TRUE;
|
||||
if (to_free)
|
||||
g_strfreev ((char **) to_free);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cell->text.plain = value;
|
||||
cell->text_to_free = !!to_free;
|
||||
}
|
||||
|
||||
nm_meta_termformat_unpack (nm_meta_abstract_info_get (info,
|
||||
NULL,
|
||||
|
|
@ -1432,15 +1487,18 @@ _print_fill (const NmcConfig *nmc_config,
|
|||
target,
|
||||
NM_META_ACCESSOR_GET_TYPE_TERMFORMAT,
|
||||
NM_META_ACCESSOR_GET_FLAGS_NONE,
|
||||
&color_out_flags,
|
||||
NULL),
|
||||
&cell->term_color,
|
||||
&cell->term_format);
|
||||
|
||||
if (pretty && (!cell->text || !cell->text[0])) {
|
||||
_print_data_cell_clear_text (cell);
|
||||
cell->text = "--";
|
||||
} else if (!cell->text)
|
||||
cell->text = "";
|
||||
if (cell->text_format == PRINT_DATA_CELL_FORMAT_TYPE_PLAIN) {
|
||||
if (pretty && (!cell->text.plain|| !cell->text.plain[0])) {
|
||||
_print_data_cell_clear_text (cell);
|
||||
cell->text.plain = "--";
|
||||
} else if (!cell->text.plain)
|
||||
cell->text.plain = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1451,12 +1509,22 @@ _print_fill (const NmcConfig *nmc_config,
|
|||
|
||||
for (i_row = 0; i_row < targets_len; i_row++) {
|
||||
const PrintDataCell *cell = &g_array_index (cells, PrintDataCell, i_row * cols_len + i_col);
|
||||
const char *const*i_strv;
|
||||
|
||||
if (header_cell->is_nested) {
|
||||
g_assert_not_reached (/*TODO*/);
|
||||
} else {
|
||||
switch (cell->text_format) {
|
||||
case PRINT_DATA_CELL_FORMAT_TYPE_PLAIN:
|
||||
header_cell->width = NM_MAX (header_cell->width,
|
||||
nmc_string_screen_width (cell->text, NULL));
|
||||
nmc_string_screen_width (cell->text.plain, NULL));
|
||||
break;
|
||||
case PRINT_DATA_CELL_FORMAT_TYPE_STRV:
|
||||
i_strv = cell->text.strv;
|
||||
if (i_strv) {
|
||||
for (; *i_strv; i_strv++) {
|
||||
header_cell->width = NM_MAX (header_cell->width,
|
||||
nmc_string_screen_width (*i_strv, NULL));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1471,14 +1539,27 @@ static gboolean
|
|||
_print_skip_column (const NmcConfig *nmc_config,
|
||||
const PrintDataHeaderCell *header_cell)
|
||||
{
|
||||
const NmcOutputSelectionItem *selection_item;
|
||||
const NMMetaAbstractInfo *info;
|
||||
|
||||
selection_item = header_cell->col->selection_item;
|
||||
info = selection_item->info;
|
||||
|
||||
if (nmc_config->multiline_output) {
|
||||
if (header_cell->col->selection_item->info->meta_type == &nm_meta_type_setting_info_editor) {
|
||||
if (info->meta_type == &nm_meta_type_setting_info_editor) {
|
||||
/* we skip the "name" entry for the setting in multiline output. */
|
||||
return TRUE;
|
||||
}
|
||||
if ( info->meta_type == &nmc_meta_type_generic_info
|
||||
&& ((const NmcMetaGenericInfo *) info)->nested) {
|
||||
/* skip the "name" entry for parent generic-infos */
|
||||
return TRUE;
|
||||
}
|
||||
} else {
|
||||
if ( header_cell->col->selection_item->info->meta_type == &nm_meta_type_setting_info_editor
|
||||
&& header_cell->col->selection_item->sub_selection) {
|
||||
if ( NM_IN_SET (info->meta_type,
|
||||
&nm_meta_type_setting_info_editor,
|
||||
&nmc_meta_type_generic_info)
|
||||
&& selection_item->sub_selection) {
|
||||
/* in tabular form, we skip the "name" entry for sections that have sub-selections.
|
||||
* That is, for "ipv4.may-fail", but not for "ipv4". */
|
||||
return TRUE;
|
||||
|
|
@ -1568,49 +1649,66 @@ _print_do (const NmcConfig *nmc_config,
|
|||
|
||||
for (i_col = 0; i_col < col_len; i_col++) {
|
||||
const PrintDataCell *cell = ¤t_line[i_col];
|
||||
gs_free char *text_to_free = NULL;
|
||||
const char *text;
|
||||
const char *const*lines = NULL;
|
||||
guint i_lines, lines_len;
|
||||
|
||||
if (_print_skip_column (nmc_config, cell->header_cell))
|
||||
continue;
|
||||
|
||||
if (cell->header_cell->is_nested) {
|
||||
g_assert_not_reached (/*TODO*/);
|
||||
} else {
|
||||
lines_len = 0;
|
||||
switch (cell->text_format) {
|
||||
case PRINT_DATA_CELL_FORMAT_TYPE_PLAIN:
|
||||
lines = &cell->text.plain;
|
||||
lines_len = 1;
|
||||
break;
|
||||
case PRINT_DATA_CELL_FORMAT_TYPE_STRV:
|
||||
nm_assert (multiline);
|
||||
lines = cell->text.strv;
|
||||
lines_len = NM_PTRARRAY_LEN (lines);
|
||||
break;
|
||||
}
|
||||
|
||||
for (i_lines = 0; i_lines < lines_len; i_lines++) {
|
||||
gs_free char *text_to_free = NULL;
|
||||
const char *text;
|
||||
|
||||
text = colorize_string (nmc_config->use_colors,
|
||||
cell->term_color, cell->term_format,
|
||||
cell->text, &text_to_free);
|
||||
}
|
||||
if (multiline) {
|
||||
gs_free char *prefix = NULL;
|
||||
lines[i_lines], &text_to_free);
|
||||
if (multiline) {
|
||||
gs_free char *prefix = NULL;
|
||||
|
||||
prefix = g_strdup_printf ("%s:", cell->header_cell->title);
|
||||
width1 = strlen (prefix);
|
||||
width2 = nmc_string_screen_width (prefix, NULL);
|
||||
g_print ("%-*s%s\n", (int) (terse ? 0 : ML_VALUE_INDENT+width1-width2), prefix, text);
|
||||
} else {
|
||||
nm_assert (str);
|
||||
if (terse) {
|
||||
if (nmc_config->escape_values) {
|
||||
const char *p = text;
|
||||
while (*p) {
|
||||
if (*p == ':' || *p == '\\')
|
||||
g_string_append_c (str, '\\'); /* Escaping by '\' */
|
||||
g_string_append_c (str, *p);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
if (cell->text_format == PRINT_DATA_CELL_FORMAT_TYPE_STRV)
|
||||
prefix = g_strdup_printf ("%s[%u]:", cell->header_cell->title, i_lines + 1);
|
||||
else
|
||||
g_string_append_printf (str, "%s", text);
|
||||
g_string_append_c (str, ':'); /* Column separator */
|
||||
prefix = g_strdup_printf ("%s:", cell->header_cell->title);
|
||||
width1 = strlen (prefix);
|
||||
width2 = nmc_string_screen_width (prefix, NULL);
|
||||
g_print ("%-*s%s\n", (int) (terse ? 0 : ML_VALUE_INDENT+width1-width2), prefix, text);
|
||||
} else {
|
||||
const PrintDataHeaderCell *header_cell = &header_row[i_col];
|
||||
nm_assert (str);
|
||||
if (terse) {
|
||||
if (nmc_config->escape_values) {
|
||||
const char *p = text;
|
||||
while (*p) {
|
||||
if (*p == ':' || *p == '\\')
|
||||
g_string_append_c (str, '\\'); /* Escaping by '\' */
|
||||
g_string_append_c (str, *p);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
else
|
||||
g_string_append_printf (str, "%s", text);
|
||||
g_string_append_c (str, ':'); /* Column separator */
|
||||
} else {
|
||||
const PrintDataHeaderCell *header_cell = &header_row[i_col];
|
||||
|
||||
width1 = strlen (text);
|
||||
width2 = nmc_string_screen_width (text, NULL); /* Width of the string (in screen colums) */
|
||||
g_string_append_printf (str, "%-*s", (int) (header_cell->width + width1 - width2), text);
|
||||
g_string_append_c (str, ' '); /* Column separator */
|
||||
table_width += header_cell->width + width1 - width2 + 1;
|
||||
width1 = strlen (text);
|
||||
width2 = nmc_string_screen_width (text, NULL); /* Width of the string (in screen colums) */
|
||||
g_string_append_printf (str, "%-*s", (int) (header_cell->width + width1 - width2), text);
|
||||
g_string_append_c (str, ' '); /* Column separator */
|
||||
table_width += header_cell->width + width1 - width2 + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1685,7 +1783,7 @@ get_value_to_print (NmcColorOption color_option,
|
|||
nm_assert (out_to_free && !*out_to_free);
|
||||
|
||||
if (field_name)
|
||||
value = _(nm_meta_abstract_info_get_name (field->info));
|
||||
value = _(nm_meta_abstract_info_get_name (field->info, FALSE));
|
||||
else {
|
||||
value = field->value
|
||||
? (is_array
|
||||
|
|
@ -1793,7 +1891,7 @@ print_required_fields (const NmcConfig *nmc_config,
|
|||
tmp = g_strdup_printf ("%s%s%s[%d]:",
|
||||
section_prefix ? (const char*) field_values[0].value : "",
|
||||
section_prefix ? "." : "",
|
||||
_(nm_meta_abstract_info_get_name (field_values[idx].info)),
|
||||
_(nm_meta_abstract_info_get_name (field_values[idx].info, FALSE)),
|
||||
j);
|
||||
width1 = strlen (tmp);
|
||||
width2 = nmc_string_screen_width (tmp, NULL);
|
||||
|
|
@ -1814,7 +1912,7 @@ print_required_fields (const NmcConfig *nmc_config,
|
|||
tmp = g_strdup_printf ("%s%s%s:",
|
||||
section_prefix ? hdr_name : "",
|
||||
section_prefix ? "." : "",
|
||||
_(nm_meta_abstract_info_get_name (field_values[idx].info)));
|
||||
_(nm_meta_abstract_info_get_name (field_values[idx].info, FALSE)));
|
||||
width1 = strlen (tmp);
|
||||
width2 = nmc_string_screen_width (tmp, NULL);
|
||||
g_print ("%-*s%s\n", (int) (terse ? 0 : ML_VALUE_INDENT+width1-width2), tmp, print_val);
|
||||
|
|
|
|||
|
|
@ -127,12 +127,27 @@ typedef enum {
|
|||
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,
|
||||
|
|
@ -140,6 +155,7 @@ struct _NmcMetaGenericInfo {
|
|||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gpointer *out_to_free);
|
||||
};
|
||||
|
||||
|
|
@ -150,8 +166,8 @@ 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__)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -186,14 +186,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;
|
||||
}
|
||||
|
|
@ -231,11 +231,15 @@ nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info,
|
|||
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);
|
||||
|
|
@ -245,5 +249,6 @@ nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info,
|
|||
target,
|
||||
get_type,
|
||||
get_flags,
|
||||
out_flags,
|
||||
out_to_free);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ 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,
|
||||
|
|
@ -56,6 +56,7 @@ gconstpointer nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info
|
|||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gpointer *out_to_free);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
|
|
@ -6560,13 +6560,15 @@ const NMMetaSettingInfoEditor nm_meta_setting_infos_editor[] = {
|
|||
/*****************************************************************************/
|
||||
|
||||
static const char *
|
||||
_meta_type_setting_info_editor_get_name (const NMMetaAbstractInfo *abstract_info)
|
||||
_meta_type_setting_info_editor_get_name (const NMMetaAbstractInfo *abstract_info, gboolean for_header)
|
||||
{
|
||||
if (for_header)
|
||||
return N_("name");
|
||||
return ((const NMMetaSettingInfoEditor *) abstract_info)->general->setting_name;
|
||||
}
|
||||
|
||||
static const char *
|
||||
_meta_type_property_info_get_name (const NMMetaAbstractInfo *abstract_info)
|
||||
_meta_type_property_info_get_name (const NMMetaAbstractInfo *abstract_info, gboolean for_header)
|
||||
{
|
||||
return ((const NMMetaPropertyInfo *) abstract_info)->property_name;
|
||||
}
|
||||
|
|
@ -6578,11 +6580,13 @@ _meta_type_setting_info_editor_get_fcn (const NMMetaEnvironment *environment,
|
|||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gpointer *out_to_free)
|
||||
{
|
||||
const NMMetaSettingInfoEditor *info = (const NMMetaSettingInfoEditor *) abstract_info;
|
||||
|
||||
nm_assert (!out_to_free || !*out_to_free);
|
||||
nm_assert (out_flags && !*out_flags);
|
||||
|
||||
if (!NM_IN_SET (get_type,
|
||||
NM_META_ACCESSOR_GET_TYPE_PARSABLE,
|
||||
|
|
@ -6603,11 +6607,13 @@ _meta_type_property_info_get_fcn (const NMMetaEnvironment *environment,
|
|||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gpointer *out_to_free)
|
||||
{
|
||||
const NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info;
|
||||
|
||||
nm_assert (!out_to_free || !*out_to_free);
|
||||
nm_assert (out_flags && !*out_flags);
|
||||
|
||||
if (!NM_IN_SET (get_type,
|
||||
NM_META_ACCESSOR_GET_TYPE_PARSABLE,
|
||||
|
|
|
|||
|
|
@ -80,9 +80,15 @@ nm_meta_termformat_pack (NMMetaTermColor color, NMMetaTermFormat format)
|
|||
|
||||
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),
|
||||
|
|
@ -188,7 +194,7 @@ struct _NMMetaSettingInfoEditor {
|
|||
|
||||
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);
|
||||
|
|
@ -198,6 +204,7 @@ struct _NMMetaType {
|
|||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gpointer *out_to_free);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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,7 +87,8 @@ 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));
|
||||
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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue