cli: rework printing of dhcp options
This commit is contained in:
@@ -270,12 +270,67 @@ const NmcMetaGenericInfo *const metagen_ip6_config[_NMC_GENERIC_INFO_TYPE_IP6_CO
|
|||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
const NmcMetaGenericInfo *const nmc_fields_dhcp_config[] = {
|
static gconstpointer
|
||||||
NMC_META_GENERIC ("GROUP"), /* 0 */
|
_metagen_dhcp_config_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS)
|
||||||
NMC_META_GENERIC ("OPTION"), /* 1 */
|
{
|
||||||
NULL,
|
NMDhcpConfig *dhcp = target;
|
||||||
|
guint i;
|
||||||
|
char **arr = NULL;
|
||||||
|
|
||||||
|
NMC_HANDLE_COLOR (NM_META_COLOR_NONE);
|
||||||
|
|
||||||
|
switch (info->info_type) {
|
||||||
|
case NMC_GENERIC_INFO_TYPE_DHCP_CONFIG_OPTION:
|
||||||
|
{
|
||||||
|
GHashTable *table;
|
||||||
|
gs_free char **arr2 = NULL;
|
||||||
|
guint n;
|
||||||
|
|
||||||
|
if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
table = nm_dhcp_config_get_options (dhcp);
|
||||||
|
if (!table)
|
||||||
|
goto arr_out;
|
||||||
|
|
||||||
|
arr2 = (char **) nm_utils_strdict_get_keys (table, TRUE, &n);
|
||||||
|
if (!n)
|
||||||
|
goto arr_out;
|
||||||
|
|
||||||
|
nm_assert (arr2 && !arr2[n] && n == NM_PTRARRAY_LEN (arr2));
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
const char *k = arr2[i];
|
||||||
|
const char *v;
|
||||||
|
|
||||||
|
nm_assert (k);
|
||||||
|
v = g_hash_table_lookup (table, k);
|
||||||
|
arr2[i] = g_strdup_printf ("%s = %s", k, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
arr = g_steal_pointer (&arr2);
|
||||||
|
goto arr_out;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_return_val_if_reached (NULL);
|
||||||
|
|
||||||
|
arr_out:
|
||||||
|
NM_SET_OUT (out_is_default, !arr || !arr[0]);
|
||||||
|
*out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV;
|
||||||
|
*out_to_free = arr;
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const NmcMetaGenericInfo *const metagen_dhcp_config[_NMC_GENERIC_INFO_TYPE_DHCP_CONFIG_NUM + 1] = {
|
||||||
|
#define _METAGEN_DHCP_CONFIG(type, name) \
|
||||||
|
[type] = NMC_META_GENERIC(name, .info_type = type, .get_fcn = _metagen_dhcp_config_get_fcn)
|
||||||
|
_METAGEN_DHCP_CONFIG (NMC_GENERIC_INFO_TYPE_DHCP_CONFIG_OPTION, "OPTION"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
const NmcMetaGenericInfo *const nmc_fields_ip6_config[] = {
|
const NmcMetaGenericInfo *const nmc_fields_ip6_config[] = {
|
||||||
NMC_META_GENERIC ("GROUP"), /* 0 */
|
NMC_META_GENERIC ("GROUP"), /* 0 */
|
||||||
NMC_META_GENERIC ("ADDRESS"), /* 1 */
|
NMC_META_GENERIC ("ADDRESS"), /* 1 */
|
||||||
@@ -343,45 +398,24 @@ print_dhcp_config (NMDhcpConfig *dhcp,
|
|||||||
const char *group_prefix,
|
const char *group_prefix,
|
||||||
const char *one_field)
|
const char *one_field)
|
||||||
{
|
{
|
||||||
GHashTable *table;
|
gs_free_error GError *error = NULL;
|
||||||
const NMMetaAbstractInfo *const*tmpl;
|
gs_free char *field_str = NULL;
|
||||||
NmcOutputField *arr;
|
|
||||||
|
|
||||||
if (dhcp == NULL)
|
if (!dhcp)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
table = nm_dhcp_config_get_options (dhcp);
|
if (one_field)
|
||||||
if (table) {
|
field_str = g_strdup_printf ("%s.%s", group_prefix, one_field);
|
||||||
char **options_arr = NULL;
|
|
||||||
NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
|
|
||||||
gs_free const char **keys = NULL;
|
|
||||||
guint i, nkeys;
|
|
||||||
|
|
||||||
tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dhcp_config;
|
if (!nmc_print (nmc_config,
|
||||||
out_indices = parse_output_fields (one_field,
|
(gpointer[]) { dhcp, NULL },
|
||||||
tmpl, FALSE, NULL, NULL);
|
NULL,
|
||||||
arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_FIELD_NAMES);
|
NMC_META_GENERIC_GROUP (group_prefix, metagen_dhcp_config, N_("GROUP")),
|
||||||
g_ptr_array_add (out.output_data, arr);
|
field_str,
|
||||||
|
&error)) {
|
||||||
keys = (const char **) g_hash_table_get_keys_as_array (table, &nkeys);
|
return FALSE;
|
||||||
nm_utils_strv_sort (keys, nkeys);
|
|
||||||
|
|
||||||
options_arr = g_new (char *, nkeys + 1);
|
|
||||||
for (i = 0; i < nkeys; i++)
|
|
||||||
options_arr[i] = g_strdup_printf ("%s = %s", keys[i], (const char *) g_hash_table_lookup (table, keys[i]));
|
|
||||||
options_arr[i] = NULL;
|
|
||||||
|
|
||||||
arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_SECTION_PREFIX);
|
|
||||||
set_val_strc (arr, 0, group_prefix);
|
|
||||||
set_val_arr (arr, 1, options_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;
|
|
||||||
}
|
}
|
||||||
return FALSE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -84,6 +84,6 @@ const char *nmc_error_get_simple_message (GError *error);
|
|||||||
|
|
||||||
extern const NmcMetaGenericInfo *const metagen_ip4_config[];
|
extern const NmcMetaGenericInfo *const metagen_ip4_config[];
|
||||||
extern const NmcMetaGenericInfo *const nmc_fields_ip6_config[];
|
extern const NmcMetaGenericInfo *const nmc_fields_ip6_config[];
|
||||||
extern const NmcMetaGenericInfo *const nmc_fields_dhcp_config[];
|
extern const NmcMetaGenericInfo *const metagen_dhcp_config[];
|
||||||
|
|
||||||
#endif /* NMC_COMMON_H */
|
#endif /* NMC_COMMON_H */
|
||||||
|
@@ -776,9 +776,9 @@ const NmcMetaGenericInfo *const metagen_con_active_vpn[_NMC_GENERIC_INFO_TYPE_CO
|
|||||||
const NmcMetaGenericInfo *const nmc_fields_con_active_details_groups[] = {
|
const NmcMetaGenericInfo *const nmc_fields_con_active_details_groups[] = {
|
||||||
NMC_META_GENERIC_WITH_NESTED ("GENERAL", metagen_con_active_general), /* 0 */
|
NMC_META_GENERIC_WITH_NESTED ("GENERAL", metagen_con_active_general), /* 0 */
|
||||||
NMC_META_GENERIC_WITH_NESTED ("IP4", metagen_ip4_config), /* 1 */
|
NMC_META_GENERIC_WITH_NESTED ("IP4", metagen_ip4_config), /* 1 */
|
||||||
NMC_META_GENERIC_WITH_NESTED ("DHCP4", nmc_fields_dhcp_config + 1), /* 2 */
|
NMC_META_GENERIC_WITH_NESTED ("DHCP4", metagen_dhcp_config), /* 2 */
|
||||||
NMC_META_GENERIC_WITH_NESTED ("IP6", nmc_fields_ip6_config + 1), /* 3 */
|
NMC_META_GENERIC_WITH_NESTED ("IP6", nmc_fields_ip6_config + 1), /* 3 */
|
||||||
NMC_META_GENERIC_WITH_NESTED ("DHCP6", nmc_fields_dhcp_config + 1), /* 4 */
|
NMC_META_GENERIC_WITH_NESTED ("DHCP6", metagen_dhcp_config), /* 4 */
|
||||||
NMC_META_GENERIC_WITH_NESTED ("VPN", metagen_con_active_vpn), /* 5 */
|
NMC_META_GENERIC_WITH_NESTED ("VPN", metagen_con_active_vpn), /* 5 */
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
@@ -209,9 +209,9 @@ const NmcMetaGenericInfo *const nmc_fields_dev_show_sections[] = {
|
|||||||
NMC_META_GENERIC_WITH_NESTED ("WIMAX-PROPERTIES", nmc_fields_dev_show_wimax_prop + 1), /* 5 */
|
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 ("NSP", nmc_fields_dev_wimax_list + 1), /* 6 */
|
||||||
NMC_META_GENERIC_WITH_NESTED ("IP4", metagen_ip4_config), /* 7 */
|
NMC_META_GENERIC_WITH_NESTED ("IP4", metagen_ip4_config), /* 7 */
|
||||||
NMC_META_GENERIC_WITH_NESTED ("DHCP4", nmc_fields_dhcp_config + 1), /* 8 */
|
NMC_META_GENERIC_WITH_NESTED ("DHCP4", metagen_dhcp_config), /* 8 */
|
||||||
NMC_META_GENERIC_WITH_NESTED ("IP6", nmc_fields_ip6_config + 1), /* 9 */
|
NMC_META_GENERIC_WITH_NESTED ("IP6", nmc_fields_ip6_config + 1), /* 9 */
|
||||||
NMC_META_GENERIC_WITH_NESTED ("DHCP6", nmc_fields_dhcp_config + 1), /* 10 */
|
NMC_META_GENERIC_WITH_NESTED ("DHCP6", metagen_dhcp_config), /* 10 */
|
||||||
NMC_META_GENERIC_WITH_NESTED ("BOND", nmc_fields_dev_show_master_prop + 1), /* 11 */
|
NMC_META_GENERIC_WITH_NESTED ("BOND", nmc_fields_dev_show_master_prop + 1), /* 11 */
|
||||||
NMC_META_GENERIC_WITH_NESTED ("TEAM", nmc_fields_dev_show_team_prop + 1), /* 12 */
|
NMC_META_GENERIC_WITH_NESTED ("TEAM", nmc_fields_dev_show_team_prop + 1), /* 12 */
|
||||||
NMC_META_GENERIC_WITH_NESTED ("BRIDGE", nmc_fields_dev_show_master_prop + 1), /* 13 */
|
NMC_META_GENERIC_WITH_NESTED ("BRIDGE", nmc_fields_dev_show_master_prop + 1), /* 13 */
|
||||||
|
@@ -189,7 +189,7 @@ complete_fields (const char *option, const char *prefix)
|
|||||||
h = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, NULL);
|
h = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, NULL);
|
||||||
|
|
||||||
complete_field (h, metagen_ip4_config);
|
complete_field (h, metagen_ip4_config);
|
||||||
complete_field (h, nmc_fields_dhcp_config);
|
complete_field (h, metagen_dhcp_config);
|
||||||
complete_field (h, nmc_fields_ip6_config);
|
complete_field (h, nmc_fields_ip6_config);
|
||||||
complete_field (h, metagen_con_show);
|
complete_field (h, metagen_con_show);
|
||||||
complete_field (h, metagen_con_active_general);
|
complete_field (h, metagen_con_active_general);
|
||||||
|
@@ -121,6 +121,9 @@ typedef enum {
|
|||||||
NMC_GENERIC_INFO_TYPE_IP6_CONFIG_DOMAIN,
|
NMC_GENERIC_INFO_TYPE_IP6_CONFIG_DOMAIN,
|
||||||
_NMC_GENERIC_INFO_TYPE_IP6_CONFIG_NUM,
|
_NMC_GENERIC_INFO_TYPE_IP6_CONFIG_NUM,
|
||||||
|
|
||||||
|
NMC_GENERIC_INFO_TYPE_DHCP_CONFIG_OPTION = 0,
|
||||||
|
_NMC_GENERIC_INFO_TYPE_DHCP_CONFIG_NUM,
|
||||||
|
|
||||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_NAME = 0,
|
NMC_GENERIC_INFO_TYPE_CON_SHOW_NAME = 0,
|
||||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_UUID,
|
NMC_GENERIC_INFO_TYPE_CON_SHOW_UUID,
|
||||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_TYPE,
|
NMC_GENERIC_INFO_TYPE_CON_SHOW_TYPE,
|
||||||
|
Reference in New Issue
Block a user