diff --git a/.gitignore b/.gitignore index 1463e087bd..42e68e201b 100644 --- a/.gitignore +++ b/.gitignore @@ -270,6 +270,8 @@ test-*.trs /src/tests/test-utils /src/tests/test-wired-defname +/clients/common/tests/test-general + /vapi/*.vapi # The following names are no longer present on this branch, diff --git a/Makefile.am b/Makefile.am index 598dfdfdde..975171c07e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -28,6 +28,7 @@ examples_DATA = CLEANFILES = DISTCLEANFILES = EXTRA_DIST = +EXTRA_LTLIBRARIES = dist_hook = dist_dependencies = dist_configure_check = @@ -3111,15 +3112,70 @@ clients_nm_online_LDADD = \ $(clients_nm_online_OBJECTS): $(libnm_core_lib_h_pub_mkenums) ############################################################################### -# clients/cli +# clients/common ############################################################################### -if BUILD_NMCLI +clients_cppflags = \ + -I$(srcdir)/shared \ + -I$(builddir)/shared \ + -I$(srcdir)/libnm-core \ + -I$(builddir)/libnm-core \ + -I$(srcdir)/libnm \ + -I$(builddir)/libnm \ + -I$(srcdir)/clients/common \ + -I$(builddir)/clients/common \ + $(GLIB_CFLAGS) \ + -DNMLOCALEDIR=\"$(datadir)/locale\" -bin_PROGRAMS += clients/cli/nmcli +check_ltlibraries += clients/common/libnmc-base.la -clients_cli_nmcli_SOURCES = \ - \ +clients_common_libnmc_base_la_SOURCES = \ + clients/common/nm-secret-agent-simple.c \ + clients/common/nm-secret-agent-simple.h \ + clients/common/nm-vpn-helpers.c \ + clients/common/nm-vpn-helpers.h + +clients_common_libnmc_base_la_CPPFLAGS = \ + $(clients_cppflags) \ + -DG_LOG_DOMAIN=\""libnmc"\" + +clients_common_libnmc_base_la_LIBADD = \ + libnm/libnm.la \ + $(GLIB_LIBS) + +$(clients_common_libnmc_base_la_OBJECTS): $(libnm_core_lib_h_pub_mkenums) + + +clients_common_settings_doc_c = clients/common/settings-docs.c +if HAVE_INTROSPECTION +$(clients_common_settings_doc_c): clients/common/settings-docs.xsl libnm/nm-property-docs.xml clients/common/.dirstamp + $(AM_V_GEN) $(XSLTPROC) --output $@ $< $(word 2,$^) +DISTCLEANFILES += $(clients_common_settings_doc_c) +check-local-settings-docs: $(clients_common_settings_doc_c) + @if test -z "$$NMTST_NO_CHECK_SETTINGS_DOCS" ; then \ + if ! cmp -s "$(srcdir)/$(clients_common_settings_doc_c).in" "$(builddir)/$(clients_common_settings_doc_c)" ; then \ + echo "The generated file \"$(builddir)/$(clients_common_settings_doc_c)\" differs from the source file \"$(srcdir)/$(clients_common_settings_doc_c).in\". You probably should copy the generated file over to the source file. You can skip this test by setting \$$NMTST_NO_CHECK_SETTINGS_DOCS=yes"; \ + false; \ + fi;\ + fi +check_local += check-local-settings-docs +else +$(clients_common_settings_doc_c): $(clients_common_settings_doc_c).in clients/common/.dirstamp + $(AM_V_GEN) cp "$(srcdir)/$(clients_common_settings_doc_c).in" "$(builddir)/$(clients_common_settings_doc_c)" +check-local-settings-docs: +endif +EXTRA_DIST += \ + $(clients_common_settings_doc_c) \ + $(clients_common_settings_doc_c).in + + +if HAVE_INTROSPECTION +check_ltlibraries += clients/common/libnmc.la +else +EXTRA_LTLIBRARIES += clients/common/libnmc.la +endif + +clients_common_libnmc_la_SOURCES = \ shared/nm-utils/nm-enum-utils.c \ shared/nm-utils/nm-enum-utils.h \ shared/nm-utils/nm-shared-utils.c \ @@ -3132,50 +3188,85 @@ clients_cli_nmcli_SOURCES = \ clients/common/nm-client-utils.h \ clients/common/nm-meta-setting-desc.c \ clients/common/nm-meta-setting-desc.h \ - \ - clients/cli/agent.c \ - clients/cli/agent.h \ + clients/common/nm-meta-setting-access.c \ + clients/common/nm-meta-setting-access.h \ + $(NULL) + +clients_common_libnmc_la_CPPFLAGS = \ + $(clients_cppflags) \ + -DG_LOG_DOMAIN=\""libnmc"\" + +clients_common_libnmc_la_LIBADD = \ + libnm/libnm.la \ + clients/common/libnmc-base.la \ + $(GLIB_LIBS) + +$(clients_common_libnmc_la_OBJECTS): $(libnm_core_lib_h_pub_mkenums) +$(clients_common_libnmc_la_OBJECTS): $(clients_common_settings_doc_c) +$(clients_common_libnmc_la_OBJECTS): clients/common/.dirstamp + +if HAVE_INTROSPECTION +check_programs += clients/common/tests/test-general +else +if BUILD_NMCLI +check_programs += clients/common/tests/test-general +endif +endif + +clients_common_tests_test_general_CPPFLAGS = \ + -I$(srcdir)/clients/common/tests \ + $(clients_cppflags) \ + -DG_LOG_DOMAIN=\""libnmc"\" + +clients_common_tests_test_general_LDADD = \ + libnm/libnm.la \ + clients/common/libnmc-base.la \ + clients/common/libnmc.la \ + $(GLIB_LIBS) + +$(clients_common_tests_test_general_OBJECTS): $(libnm_core_lib_h_pub_mkenums) + +############################################################################### +# clients/cli +############################################################################### + +if BUILD_NMCLI + +bin_PROGRAMS += clients/cli/nmcli + +clients_cli_nmcli_SOURCES = \ clients/cli/common.c \ clients/cli/common.h \ + clients/cli/utils.c \ + clients/cli/utils.h \ + clients/cli/agent.c \ + clients/cli/agent.h \ + clients/cli/general.c \ + clients/cli/general.h \ clients/cli/connections.c \ clients/cli/connections.h \ clients/cli/devices.c \ clients/cli/devices.h \ - clients/cli/general.c \ - clients/cli/general.h \ clients/cli/settings.c \ clients/cli/settings.h \ clients/cli/nmcli.c \ clients/cli/nmcli.h \ - clients/cli/utils.c \ - clients/cli/utils.h \ clients/cli/polkit-agent.c \ clients/cli/polkit-agent.h \ - \ - clients/common/nm-secret-agent-simple.c \ - clients/common/nm-secret-agent-simple.h \ - clients/common/nm-vpn-helpers.c \ - clients/common/nm-vpn-helpers.h \ $(NULL) clients_cli_nmcli_CPPFLAGS = \ - -I$(srcdir)/shared \ - -I$(builddir)/shared \ - -I$(srcdir)/libnm-core \ - -I$(builddir)/libnm-core \ - -I$(srcdir)/libnm \ - -I$(builddir)/libnm \ -I$(srcdir)/clients/cli \ - -I$(srcdir)/clients/common \ - -I$(builddir)/clients/common \ - $(GLIB_CFLAGS) \ + $(clients_cppflags) \ -DG_LOG_DOMAIN=\""nmcli"\" \ -DNMCLI_LOCALEDIR=\"$(datadir)/locale\" clients_cli_nmcli_LDADD = \ + libnm/libnm.la \ + clients/common/libnmc-base.la \ + clients/common/libnmc.la \ $(GLIB_LIBS) \ - $(READLINE_LIBS) \ - libnm/libnm.la + $(READLINE_LIBS) if WITH_POLKIT_AGENT clients_cli_nmcli_CPPFLAGS += $(POLKIT_CFLAGS) @@ -3188,8 +3279,7 @@ endif clients_cli_nmcli_LDFLAGS = \ -Wl,--version-script="$(srcdir)/linker-script-binary.ver" -$(clients_cli_nmcli_OBJECTS): $(clients_common_settings_doc_c) -$(clients_cli_nmcli_OBJECTS): clients/cli/.dirstamp +$(clients_cli_nmcli_OBJECTS): $(libnm_core_lib_h_pub_mkenums) install-data-hook-nmcli: $(mkinstalldirs) $(DESTDIR)$(completiondir) @@ -3204,22 +3294,6 @@ uninstall_hook += uninstall-hook-nmcli endif - -clients_common_settings_doc_c = clients/common/settings-docs.c -if HAVE_INTROSPECTION -$(clients_common_settings_doc_c): clients/common/settings-docs.xsl libnm/nm-property-docs.xml - $(AM_V_GEN) $(XSLTPROC) --output $@ $< $(word 2,$^) -$(clients_common_settings_doc_c): clients/common/.dirstamp -DISTCLEANFILES += $(clients_common_settings_doc_c) -else -$(clients_common_settings_doc_c): - @echo "to generate $(clients_common_settings_doc_c), configure with --enable-introspection" - @echo "alternatively, build --without-nmcli" - @false -endif -EXTRA_DIST += $(clients_common_settings_doc_c) - - EXTRA_DIST += \ clients/cli/nmcli-completion \ clients/common/settings-docs.xsl @@ -3372,26 +3446,14 @@ clients_tui_nmtui_SOURCES = \ clients/tui/nmt-utils.h \ clients/tui/nmt-widget-list.c \ clients/tui/nmt-widget-list.h \ - clients/common/nm-secret-agent-simple.c \ - clients/common/nm-secret-agent-simple.h \ - clients/common/nm-vpn-helpers.c \ - clients/common/nm-vpn-helpers.h \ $(NULL) clients_tui_nmtui_CPPFLAGS = \ - -I$(srcdir)/shared \ - -I$(builddir)/shared \ - -I$(srcdir)/libnm-core \ - -I$(builddir)/libnm-core \ - -I$(srcdir)/libnm \ - -I$(builddir)/libnm \ -I$(srcdir)/clients/tui/newt \ - -I$(srcdir)/clients/common \ - $(GLIB_CFLAGS) \ + $(clients_cppflags) \ $(NEWT_CFLAGS) \ -DG_LOG_DOMAIN=\""nmtui"\" \ - -DLOCALEDIR=\""$(localedir)"\" \ - $(NULL) + -DLOCALEDIR=\""$(localedir)"\" clients_tui_nmtui_LDFLAGS = \ -Wl,--version-script="$(srcdir)/linker-script-binary.ver" @@ -3399,6 +3461,7 @@ clients_tui_nmtui_LDFLAGS = \ clients_tui_nmtui_LDADD = \ libnm/libnm.la \ clients/tui/newt/libnmt-newt.a \ + clients/common/libnmc-base.la \ $(GLIB_LIBS) \ $(NEWT_LIBS) \ $(NULL) diff --git a/clients/cli/agent.c b/clients/cli/agent.c index 601e0ca44d..656a58511d 100644 --- a/clients/cli/agent.c +++ b/clients/cli/agent.c @@ -21,6 +21,8 @@ #include "nm-default.h" +#include "agent.h" + #include #include #include @@ -31,7 +33,6 @@ #include "utils.h" #include "nm-secret-agent-simple.h" #include "polkit-agent.h" -#include "agent.h" static void usage (void) diff --git a/clients/cli/common.c b/clients/cli/common.c index 39b314f0a0..3656cdbf82 100644 --- a/clients/cli/common.c +++ b/clients/cli/common.c @@ -21,6 +21,8 @@ #include "nm-default.h" +#include "common.h" + #include #include #include @@ -32,54 +34,42 @@ #include "nm-vpn-helpers.h" #include "nm-client-utils.h" -#include "common.h" #include "utils.h" extern GMainLoop *loop; -#define OUTPUT_FIELD_WITH_NAME(n) { .name = N_ (n), } - -/* Available fields for IPv4 group */ -NmcOutputField nmc_fields_ip4_config[] = { - OUTPUT_FIELD_WITH_NAME ("GROUP"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("ADDRESS"), /* 1 */ - OUTPUT_FIELD_WITH_NAME ("GATEWAY"), /* 2 */ - OUTPUT_FIELD_WITH_NAME ("ROUTE"), /* 3 */ - OUTPUT_FIELD_WITH_NAME ("DNS"), /* 4 */ - OUTPUT_FIELD_WITH_NAME ("DOMAIN"), /* 5 */ - OUTPUT_FIELD_WITH_NAME ("WINS"), /* 6 */ - { 0 } +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 */ + NULL, }; -#define NMC_FIELDS_IP4_CONFIG_ALL "GROUP,ADDRESS,GATEWAY,ROUTE,DNS,DOMAIN,WINS" -/* Available fields for DHCPv4 group */ -NmcOutputField nmc_fields_dhcp4_config[] = { - OUTPUT_FIELD_WITH_NAME ("GROUP"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("OPTION"), /* 1 */ - { 0 } +const NmcMetaGenericInfo *const nmc_fields_dhcp4_config[] = { + NMC_META_GENERIC ("GROUP"), /* 0 */ + NMC_META_GENERIC ("OPTION"), /* 1 */ + NULL, }; -#define NMC_FIELDS_DHCP4_CONFIG_ALL "GROUP,OPTION" -/* Available fields for IPv6 group */ -NmcOutputField nmc_fields_ip6_config[] = { - OUTPUT_FIELD_WITH_NAME ("GROUP"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("ADDRESS"), /* 1 */ - OUTPUT_FIELD_WITH_NAME ("GATEWAY"), /* 2 */ - OUTPUT_FIELD_WITH_NAME ("ROUTE"), /* 3 */ - OUTPUT_FIELD_WITH_NAME ("DNS"), /* 4 */ - OUTPUT_FIELD_WITH_NAME ("DOMAIN"), /* 5 */ - { 0 } +const NmcMetaGenericInfo *const nmc_fields_ip6_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 */ + NULL, }; -#define NMC_FIELDS_IP6_CONFIG_ALL "GROUP,ADDRESS,GATEWAY,ROUTE,DNS,DOMAIN" -/* Available fields for DHCPv6 group */ -NmcOutputField nmc_fields_dhcp6_config[] = { - OUTPUT_FIELD_WITH_NAME ("GROUP"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("OPTION"), /* 1 */ - { 0 } +const NmcMetaGenericInfo *const nmc_fields_dhcp6_config[] = { + NMC_META_GENERIC ("GROUP"), /* 0 */ + NMC_META_GENERIC ("OPTION"), /* 1 */ + NULL, }; -#define NMC_FIELDS_DHCP6_CONFIG_ALL "GROUP,OPTION" - gboolean print_ip4_config (NMIPConfig *cfg4, @@ -94,18 +84,17 @@ print_ip4_config (NMIPConfig *cfg4, char **domain_arr = NULL; char **wins_arr = NULL; int i = 0; - NmcOutputField *tmpl, *arr; - size_t tmpl_len; + const NMMetaAbstractInfo *const*tmpl; + NmcOutputField *arr; NMC_OUTPUT_DATA_DEFINE_SCOPED (out); if (cfg4 == NULL) return FALSE; - tmpl = nmc_fields_ip4_config; - tmpl_len = sizeof (nmc_fields_ip4_config); - out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_IP4_CONFIG_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); + 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); /* addresses */ @@ -153,7 +142,7 @@ print_ip4_config (NMIPConfig *cfg4, /* WINS */ wins_arr = g_strdupv ((char **) nm_ip_config_get_wins_servers (cfg4)); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); + 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)); @@ -164,7 +153,7 @@ print_ip4_config (NMIPConfig *cfg4, g_ptr_array_add (out.output_data, arr); print_data_prepare_width (out.output_data); - print_data (nmc_config, &out); + print_data (nmc_config, out_indices, NULL, 0, &out); return TRUE; } @@ -181,18 +170,17 @@ print_ip6_config (NMIPConfig *cfg6, char **dns_arr = NULL; char **domain_arr = NULL; int i = 0; - NmcOutputField *tmpl, *arr; - size_t tmpl_len; + const NMMetaAbstractInfo *const*tmpl; + NmcOutputField *arr; NMC_OUTPUT_DATA_DEFINE_SCOPED (out); if (cfg6 == NULL) return FALSE; - tmpl = nmc_fields_ip6_config; - tmpl_len = sizeof (nmc_fields_ip6_config); - out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_IP6_CONFIG_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_ip6_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); /* addresses */ @@ -237,7 +225,7 @@ print_ip6_config (NMIPConfig *cfg6, /* domains */ domain_arr = g_strdupv ((char **) nm_ip_config_get_domains (cfg6)); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); + 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 (cfg6)); @@ -247,7 +235,7 @@ print_ip6_config (NMIPConfig *cfg6, g_ptr_array_add (out.output_data, arr); print_data_prepare_width (out.output_data); - print_data (nmc_config, &out); + print_data (nmc_config, out_indices, NULL, 0, &out); return TRUE; } @@ -259,8 +247,8 @@ print_dhcp4_config (NMDhcpConfig *dhcp4, const char *one_field) { GHashTable *table; - NmcOutputField *tmpl, *arr; - size_t tmpl_len; + const NMMetaAbstractInfo *const*tmpl; + NmcOutputField *arr; if (dhcp4 == NULL) return FALSE; @@ -273,11 +261,10 @@ print_dhcp4_config (NMDhcpConfig *dhcp4, int i = 0; NMC_OUTPUT_DATA_DEFINE_SCOPED (out); - tmpl = nmc_fields_dhcp4_config; - tmpl_len = sizeof (nmc_fields_dhcp4_config); - out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DHCP4_CONFIG_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dhcp4_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); options_arr = g_new (char *, g_hash_table_size (table) + 1); @@ -286,13 +273,13 @@ print_dhcp4_config (NMDhcpConfig *dhcp4, options_arr[i++] = g_strdup_printf ("%s = %s", (char *) key, (char *) value); options_arr[i] = NULL; - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); + 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); + print_data (nmc_config, out_indices, NULL, 0, &out); return TRUE; } @@ -306,8 +293,8 @@ print_dhcp6_config (NMDhcpConfig *dhcp6, const char *one_field) { GHashTable *table; - NmcOutputField *tmpl, *arr; - size_t tmpl_len; + const NMMetaAbstractInfo *const*tmpl; + NmcOutputField *arr; if (dhcp6 == NULL) return FALSE; @@ -320,11 +307,10 @@ print_dhcp6_config (NMDhcpConfig *dhcp6, int i = 0; NMC_OUTPUT_DATA_DEFINE_SCOPED (out); - tmpl = nmc_fields_dhcp6_config; - tmpl_len = sizeof (nmc_fields_dhcp6_config); - out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DHCP6_CONFIG_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dhcp6_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); options_arr = g_new (char *, g_hash_table_size (table) + 1); @@ -333,13 +319,13 @@ print_dhcp6_config (NMDhcpConfig *dhcp6, options_arr[i++] = g_strdup_printf ("%s = %s", (char *) key, (char *) value); options_arr[i] = NULL; - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); + 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); + print_data (nmc_config, out_indices, NULL, 0, &out); return TRUE; } diff --git a/clients/cli/common.h b/clients/cli/common.h index ca4b030820..2534c4f73f 100644 --- a/clients/cli/common.h +++ b/clients/cli/common.h @@ -80,9 +80,9 @@ void nmc_complete_bool (const char *prefix); const char *nmc_error_get_simple_message (GError *error); -extern NmcOutputField nmc_fields_ip4_config[]; -extern NmcOutputField nmc_fields_dhcp4_config[]; -extern NmcOutputField nmc_fields_ip6_config[]; -extern NmcOutputField nmc_fields_dhcp6_config[]; +extern const NmcMetaGenericInfo *const nmc_fields_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[]; #endif /* NMC_COMMON_H */ diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 630cefb303..a394084be6 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -19,6 +19,8 @@ #include "nm-default.h" +#include "connections.h" + #include #include #include @@ -30,18 +32,15 @@ #include #include "nm-client-utils.h" +#include "nm-vpn-helpers.h" +#include "nm-meta-setting-access.h" +#include "nm-secret-agent-simple.h" #include "utils.h" #include "common.h" #include "settings.h" -#include "connections.h" #include "devices.h" -#include "nm-secret-agent-simple.h" #include "polkit-agent.h" -#include "nm-vpn-helpers.h" - -#define OUTPUT_FIELD_WITH_NAME(n) { .name = N_ (n), } -#define OUTPUT_FIELD_WITH_FIELDS(n, fields) { .name = N_ (n), .group_list = fields + 1, } typedef struct _OptionInfo OptionInfo; struct _OptionInfo { @@ -130,70 +129,42 @@ struct _OptionInfo { #define BASE_PROMPT "nmcli> " -/* Available fields for 'connection show' */ -NmcOutputField nmc_fields_con_show[] = { - OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("UUID"), /* 1 */ - OUTPUT_FIELD_WITH_NAME ("TYPE"), /* 2 */ - OUTPUT_FIELD_WITH_NAME ("TIMESTAMP"), /* 3 */ - OUTPUT_FIELD_WITH_NAME ("TIMESTAMP-REAL"), /* 4 */ - OUTPUT_FIELD_WITH_NAME ("AUTOCONNECT"), /* 5 */ - OUTPUT_FIELD_WITH_NAME ("AUTOCONNECT-PRIORITY"), /* 6 */ - OUTPUT_FIELD_WITH_NAME ("READONLY"), /* 7 */ - OUTPUT_FIELD_WITH_NAME ("DBUS-PATH"), /* 8 */ - OUTPUT_FIELD_WITH_NAME ("ACTIVE"), /* 9 */ - OUTPUT_FIELD_WITH_NAME ("DEVICE"), /* 10 */ - OUTPUT_FIELD_WITH_NAME ("STATE"), /* 11 */ - OUTPUT_FIELD_WITH_NAME ("ACTIVE-PATH"), /* 12 */ - OUTPUT_FIELD_WITH_NAME ("SLAVE"), /* 13 */ - { 0 } +/*****************************************************************************/ + +const NmcMetaGenericInfo *const nmc_fields_con_show[] = { + NMC_META_GENERIC ("NAME"), /* 0 */ + NMC_META_GENERIC ("UUID"), /* 1 */ + NMC_META_GENERIC ("TYPE"), /* 2 */ + NMC_META_GENERIC ("TIMESTAMP"), /* 3 */ + NMC_META_GENERIC ("TIMESTAMP-REAL"), /* 4 */ + NMC_META_GENERIC ("AUTOCONNECT"), /* 5 */ + NMC_META_GENERIC ("AUTOCONNECT-PRIORITY"), /* 6 */ + NMC_META_GENERIC ("READONLY"), /* 7 */ + NMC_META_GENERIC ("DBUS-PATH"), /* 8 */ + NMC_META_GENERIC ("ACTIVE"), /* 9 */ + NMC_META_GENERIC ("DEVICE"), /* 10 */ + NMC_META_GENERIC ("STATE"), /* 11 */ + NMC_META_GENERIC ("ACTIVE-PATH"), /* 12 */ + NMC_META_GENERIC ("SLAVE"), /* 13 */ + NULL, }; -#define NMC_FIELDS_CON_SHOW_ALL "NAME,UUID,TYPE,TIMESTAMP,TIMESTAMP-REAL,AUTOCONNECT,AUTOCONNECT-PRIORITY,READONLY,DBUS-PATH,"\ - "ACTIVE,DEVICE,STATE,ACTIVE-PATH,SLAVE" #define NMC_FIELDS_CON_SHOW_COMMON "NAME,UUID,TYPE,DEVICE" -/* Helper macro to define fields */ -#define OUTPUT_FIELD_WITH_SETTING(setting, setting_type) \ - { \ - .name = setting, \ - .setting_info = &nm_meta_setting_infos_editor[setting_type], \ - } - -/* Available settings for 'connection show ' - profile part */ -NmcOutputField nmc_fields_settings_names[] = { - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_CONNECTION_SETTING_NAME, NM_META_SETTING_TYPE_CONNECTION), /* 0 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_WIRED_SETTING_NAME, NM_META_SETTING_TYPE_WIRED), /* 1 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_802_1X_SETTING_NAME, NM_META_SETTING_TYPE_802_1X), /* 2 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_WIRELESS_SETTING_NAME, NM_META_SETTING_TYPE_WIRELESS), /* 3 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_META_SETTING_TYPE_WIRELESS_SECURITY), /* 4 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_META_SETTING_TYPE_IP4_CONFIG), /* 5 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_META_SETTING_TYPE_IP6_CONFIG), /* 6 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_SERIAL_SETTING_NAME, NM_META_SETTING_TYPE_SERIAL), /* 7 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_PPP_SETTING_NAME, NM_META_SETTING_TYPE_PPP), /* 8 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_PPPOE_SETTING_NAME, NM_META_SETTING_TYPE_PPPOE), /* 9 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_GSM_SETTING_NAME, NM_META_SETTING_TYPE_GSM), /* 10 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_CDMA_SETTING_NAME, NM_META_SETTING_TYPE_CDMA), /* 11 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_BLUETOOTH_SETTING_NAME, NM_META_SETTING_TYPE_BLUETOOTH), /* 12 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_OLPC_MESH_SETTING_NAME, NM_META_SETTING_TYPE_OLPC_MESH), /* 13 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_VPN_SETTING_NAME, NM_META_SETTING_TYPE_VPN), /* 14 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_WIMAX_SETTING_NAME, NM_META_SETTING_TYPE_WIMAX), /* 15 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_INFINIBAND_SETTING_NAME, NM_META_SETTING_TYPE_INFINIBAND), /* 16 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_BOND_SETTING_NAME, NM_META_SETTING_TYPE_BOND), /* 17 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_VLAN_SETTING_NAME, NM_META_SETTING_TYPE_VLAN), /* 18 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_ADSL_SETTING_NAME, NM_META_SETTING_TYPE_ADSL), /* 19 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_BRIDGE_SETTING_NAME, NM_META_SETTING_TYPE_BRIDGE), /* 20 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_BRIDGE_PORT_SETTING_NAME, NM_META_SETTING_TYPE_BRIDGE_PORT), /* 21 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_TEAM_SETTING_NAME, NM_META_SETTING_TYPE_TEAM), /* 22 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_TEAM_PORT_SETTING_NAME, NM_META_SETTING_TYPE_TEAM_PORT), /* 23 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_DCB_SETTING_NAME, NM_META_SETTING_TYPE_DCB), /* 24 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_TUN_SETTING_NAME, NM_META_SETTING_TYPE_TUN), /* 25 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_IP_TUNNEL_SETTING_NAME, NM_META_SETTING_TYPE_IP_TUNNEL), /* 26 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_MACSEC_SETTING_NAME, NM_META_SETTING_TYPE_MACSEC), /* 27 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_MACVLAN_SETTING_NAME, NM_META_SETTING_TYPE_MACVLAN), /* 28 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_VXLAN_SETTING_NAME, NM_META_SETTING_TYPE_VXLAN), /* 29 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_PROXY_SETTING_NAME, NM_META_SETTING_TYPE_PROXY), /* 30 */ - OUTPUT_FIELD_WITH_SETTING (NM_SETTING_DUMMY_SETTING_NAME, NM_META_SETTING_TYPE_DUMMY), /* 31 */ - { 0 } +const NmcMetaGenericInfo *const nmc_fields_con_active_details_general[] = { + NMC_META_GENERIC ("GROUP"), /* 0 */ + NMC_META_GENERIC ("NAME"), /* 1 */ + NMC_META_GENERIC ("UUID"), /* 2 */ + NMC_META_GENERIC ("DEVICES"), /* 3 */ + NMC_META_GENERIC ("STATE"), /* 4 */ + NMC_META_GENERIC ("DEFAULT"), /* 5 */ + NMC_META_GENERIC ("DEFAULT6"), /* 6 */ + NMC_META_GENERIC ("SPEC-OBJECT"), /* 7 */ + NMC_META_GENERIC ("VPN"), /* 8 */ + NMC_META_GENERIC ("DBUS-PATH"), /* 9 */ + NMC_META_GENERIC ("CON-PATH"), /* 10 */ + NMC_META_GENERIC ("ZONE"), /* 11 */ + NMC_META_GENERIC ("MASTER-PATH"), /* 12 */ + NULL, }; #define NMC_FIELDS_SETTINGS_NAMES_ALL NM_SETTING_CONNECTION_SETTING_NAME","\ NM_SETTING_WIRED_SETTING_NAME","\ @@ -228,59 +199,27 @@ NmcOutputField nmc_fields_settings_names[] = { // NM_SETTING_DUMMY_SETTING_NAME // NM_SETTING_WIMAX_SETTING_NAME -/* Active connection data */ -/* Available fields for GENERAL group */ -NmcOutputField nmc_fields_con_active_details_general[] = { - OUTPUT_FIELD_WITH_NAME ("GROUP"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("NAME"), /* 1 */ - OUTPUT_FIELD_WITH_NAME ("UUID"), /* 2 */ - OUTPUT_FIELD_WITH_NAME ("DEVICES"), /* 3 */ - OUTPUT_FIELD_WITH_NAME ("STATE"), /* 4 */ - OUTPUT_FIELD_WITH_NAME ("DEFAULT"), /* 5 */ - OUTPUT_FIELD_WITH_NAME ("DEFAULT6"), /* 6 */ - OUTPUT_FIELD_WITH_NAME ("SPEC-OBJECT"), /* 7 */ - OUTPUT_FIELD_WITH_NAME ("VPN"), /* 8 */ - OUTPUT_FIELD_WITH_NAME ("DBUS-PATH"), /* 9 */ - OUTPUT_FIELD_WITH_NAME ("CON-PATH"), /* 10 */ - OUTPUT_FIELD_WITH_NAME ("ZONE"), /* 11 */ - OUTPUT_FIELD_WITH_NAME ("MASTER-PATH"), /* 12 */ - { 0 } + +const NmcMetaGenericInfo *const nmc_fields_con_active_details_vpn[] = { + NMC_META_GENERIC ("GROUP"), /* 0 */ + NMC_META_GENERIC ("TYPE"), /* 1 */ + NMC_META_GENERIC ("USERNAME"), /* 2 */ + NMC_META_GENERIC ("GATEWAY"), /* 3 */ + NMC_META_GENERIC ("BANNER"), /* 4 */ + NMC_META_GENERIC ("VPN-STATE"), /* 5 */ + NMC_META_GENERIC ("CFG"), /* 6 */ + NULL, }; -#define NMC_FIELDS_CON_ACTIVE_DETAILS_GENERAL_ALL "GROUP,NAME,UUID,DEVICES,STATE,DEFAULT,DEFAULT6,"\ - "VPN,ZONE,DBUS-PATH,CON-PATH,SPEC-OBJECT,MASTER-PATH" -/* IP group is handled by common.c */ - -/* Available fields for VPN group */ -NmcOutputField nmc_fields_con_active_details_vpn[] = { - OUTPUT_FIELD_WITH_NAME ("GROUP"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("TYPE"), /* 1 */ - OUTPUT_FIELD_WITH_NAME ("USERNAME"), /* 2 */ - OUTPUT_FIELD_WITH_NAME ("GATEWAY"), /* 3 */ - OUTPUT_FIELD_WITH_NAME ("BANNER"), /* 4 */ - OUTPUT_FIELD_WITH_NAME ("VPN-STATE"), /* 5 */ - OUTPUT_FIELD_WITH_NAME ("CFG"), /* 6 */ - { 0 } +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 ("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 */ + NMC_META_GENERIC_WITH_NESTED ("VPN", nmc_fields_con_active_details_vpn + 1), /* 5 */ + NULL, }; -#define NMC_FIELDS_CON_ACTIVE_DETAILS_VPN_ALL "GROUP,TYPE,USERNAME,GATEWAY,BANNER,VPN-STATE,CFG" - -/* defined in common.c */ -extern NmcOutputField nmc_fields_ip4_config[]; -extern NmcOutputField nmc_fields_ip6_config[]; -extern NmcOutputField nmc_fields_dhcp4_config[]; -extern NmcOutputField nmc_fields_dhcp6_config[]; - -/* Available fields for 'connection show ' - active part */ -NmcOutputField nmc_fields_con_active_details_groups[] = { - OUTPUT_FIELD_WITH_FIELDS ("GENERAL", nmc_fields_con_active_details_general), /* 0 */ - OUTPUT_FIELD_WITH_FIELDS ("IP4", nmc_fields_ip4_config), /* 1 */ - OUTPUT_FIELD_WITH_FIELDS ("DHCP4", nmc_fields_dhcp4_config), /* 2 */ - OUTPUT_FIELD_WITH_FIELDS ("IP6", nmc_fields_ip6_config), /* 3 */ - OUTPUT_FIELD_WITH_FIELDS ("DHCP6", nmc_fields_dhcp6_config), /* 4 */ - OUTPUT_FIELD_WITH_FIELDS ("VPN", nmc_fields_con_active_details_vpn), /* 5 */ - { 0 } -}; -#define NMC_FIELDS_CON_ACTIVE_DETAILS_ALL "GENERAL,IP4,DHCP4,IP6,DHCP6,VPN" /* Pseudo group names for 'connection show ' */ /* e.g.: nmcli -f profile con show my-eth0 */ @@ -616,6 +555,22 @@ usage_connection_export (void) "The data are directed to standard output or to a file if a name is given.\n\n")); } +static NMSetting * +nmc_setting_new_for_name (const char *name) +{ + GType stype; + NMSetting *setting = NULL; + + if (name) { + stype = nm_setting_lookup_type (name); + if (stype != G_TYPE_INVALID) { + setting = g_object_new (stype, NULL); + g_warn_if_fail (NM_IS_SETTING (setting)); + } + } + return setting; +} + /* quit main loop */ static void quit (void) @@ -629,20 +584,13 @@ quit (void) g_main_loop_quit (loop); /* quit main loop */ } -static const char * +static char * construct_header_name (const char *base, const char *spec) { - static char header_name[128]; - if (spec == NULL) - return base; + return g_strdup (base); - g_strlcpy (header_name, base, sizeof (header_name)); - g_strlcat (header_name, " (", sizeof (header_name)); - g_strlcat (header_name, spec, sizeof (header_name)); - g_strlcat (header_name, ")", sizeof (header_name)); - - return header_name; + return g_strdup_printf ("%s (%s)", base, spec); } static const char * @@ -746,12 +694,12 @@ update_secrets_in_connection (NMRemoteConnection *remote, NMConnection *local) int i; GError *error = NULL; - for (i = 0; nmc_fields_settings_names[i].name; i++) { - secrets = nm_remote_connection_get_secrets (remote, nmc_fields_settings_names[i].name, NULL, NULL); + for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { + secrets = nm_remote_connection_get_secrets (remote, nm_meta_setting_infos[i].setting_name, NULL, NULL); if (secrets) { if (!nm_connection_update_secrets (local, NULL, secrets, &error) && error) { g_printerr (_("Error updating secrets for %s: %s\n"), - nmc_fields_settings_names[i].name, + nm_meta_setting_infos[i].setting_name, error->message); g_clear_error (&error); } @@ -780,7 +728,8 @@ nmc_connection_profile_details (NMConnection *connection, NmCli *nmc, gboolean s else fields_str = nmc->required_fields; - print_settings_array = parse_output_fields (fields_str, nmc_fields_settings_names, TRUE, &prop_array, &error); + print_settings_array = parse_output_fields (fields_str, (const NMMetaAbstractInfo *const*) nm_meta_setting_infos_editor_p (), + TRUE, &prop_array, &error); if (error) { g_string_printf (nmc->return_text, _("Error: 'connection show': %s"), error->message); g_error_free (error); @@ -791,14 +740,22 @@ nmc_connection_profile_details (NMConnection *connection, NmCli *nmc, gboolean s /* Main header */ { - NMC_OUTPUT_DATA_DEFINE_SCOPED (out); + gs_free char *header_name = NULL; + gs_free NmcOutputField *row = NULL; + gs_unref_array GArray *out_indices = NULL; - out.print_fields.header_name = (char *) construct_header_name (base_hdr, nm_connection_get_id (connection)); - out.print_fields.indices = parse_output_fields (NMC_FIELDS_SETTINGS_NAMES_ALL, - nmc_fields_settings_names, FALSE, NULL, NULL); + header_name = construct_header_name (base_hdr, nm_connection_get_id (connection)); + out_indices = parse_output_fields (NMC_FIELDS_SETTINGS_NAMES_ALL, + (const NMMetaAbstractInfo *const*) nm_meta_setting_infos_editor_p (), + FALSE, NULL, NULL); - nmc_fields_settings_names[0].flags = NMC_OF_FLAG_MAIN_HEADER_ONLY; - print_required_fields (&nmc->nmc_config, &out.print_fields, nmc_fields_settings_names); + row = g_new0 (NmcOutputField, _NM_META_SETTING_TYPE_NUM + 1); + for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) + row[i].info = (const NMMetaAbstractInfo *) &nm_meta_setting_infos_editor[i]; + + print_required_fields (&nmc->nmc_config, NMC_OF_FLAG_MAIN_HEADER_ONLY, + out_indices, header_name, + 0, row); } /* Loop through the required settings and print them. */ @@ -812,9 +769,9 @@ nmc_connection_profile_details (NMConnection *connection, NmCli *nmc, gboolean s was_output = FALSE; - setting = nm_connection_get_setting_by_name (connection, nmc_fields_settings_names[section_idx].name); + setting = nm_connection_get_setting_by_name (connection, nm_meta_setting_infos_editor[section_idx].general->setting_name); if (setting) { - setting_details (setting, nmc, prop_name, secrets); + setting_details (&nmc->nmc_config, setting, prop_name, secrets); was_output = TRUE; } } @@ -904,16 +861,16 @@ found: } void -nmc_active_connection_state_to_color (NMActiveConnectionState state, NmcTermColor *color) +nmc_active_connection_state_to_color (NMActiveConnectionState state, NMMetaTermColor *color) { - *color = NMC_TERM_COLOR_NORMAL; + *color = NM_META_TERM_COLOR_NORMAL; if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATING) - *color = NMC_TERM_COLOR_YELLOW; + *color = NM_META_TERM_COLOR_YELLOW; else if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) - *color = NMC_TERM_COLOR_GREEN; + *color = NM_META_TERM_COLOR_GREEN; else if (state > NM_ACTIVE_CONNECTION_STATE_ACTIVATED) - *color = NMC_TERM_COLOR_RED; + *color = NM_META_TERM_COLOR_RED; } static void @@ -931,7 +888,7 @@ fill_output_connection (NMConnection *connection, NMClient *client, GPtrArray *o const char *ac_state = NULL; NMActiveConnectionState ac_state_int = NM_ACTIVE_CONNECTION_STATE_UNKNOWN; char *ac_dev = NULL; - NmcTermColor color; + NMMetaTermColor color; s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); @@ -957,9 +914,7 @@ fill_output_connection (NMConnection *connection, NMClient *client, GPtrArray *o } prio_str = g_strdup_printf ("%u", nm_setting_connection_get_autoconnect_priority (s_con)); - arr = nmc_dup_fields_array (nmc_fields_con_show, - sizeof (nmc_fields_con_show), - 0); + arr = nmc_dup_fields_array ((const NMMetaAbstractInfo *const*) nmc_fields_con_show, 0); /* Show active connections in color */ nmc_active_connection_state_to_color (ac_state_int, &color); @@ -996,9 +951,7 @@ fill_output_connection_for_invisible (NMActiveConnection *ac, GPtrArray *output_ ac_state = active_connection_state_to_string (nm_active_connection_get_state (ac)); ac_dev = get_ac_device_string (ac); - arr = nmc_dup_fields_array (nmc_fields_con_show, - sizeof (nmc_fields_con_show), - 0); + arr = nmc_dup_fields_array ((const NMMetaAbstractInfo *const*) nmc_fields_con_show, 0); set_val_str (arr, 0, name); set_val_strc (arr, 1, nm_active_connection_get_uuid (ac)); @@ -1015,7 +968,7 @@ fill_output_connection_for_invisible (NMActiveConnection *ac, GPtrArray *output_ set_val_strc (arr, 12, ac_path); set_val_strc (arr, 13, NULL); - set_val_color_fmt_all (arr, NMC_TERM_FORMAT_DIM); + set_val_color_fmt_all (arr, NM_META_TERM_FORMAT_DIM); g_ptr_array_add (output_data, arr); } @@ -1034,8 +987,8 @@ fill_output_active_connection (NMActiveConnection *active, NMDevice *master; const char *con_path = NULL, *con_zone = NULL; int i; - NmcOutputField *tmpl, *arr; - size_t tmpl_len; + const NMMetaAbstractInfo *const*tmpl; + NmcOutputField *arr; int idx_start = with_group ? 0 : 1; con = nm_active_connection_get_connection (active); @@ -1064,17 +1017,14 @@ fill_output_active_connection (NMActiveConnection *active, if (dev_str->len > 0) g_string_truncate (dev_str, dev_str->len - 1); /* Cut off last ',' */ - tmpl = nmc_fields_con_active_details_general; - tmpl_len = sizeof (nmc_fields_con_active_details_general); - if (!with_group) { + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_con_active_details_general; + if (!with_group) tmpl++; - tmpl_len -= sizeof (NmcOutputField); - } /* Fill field values */ - arr = nmc_dup_fields_array (tmpl, tmpl_len, o_flags); + arr = nmc_dup_fields_array (tmpl, o_flags); if (with_group) - set_val_strc (arr, 0, nmc_fields_con_active_details_groups[0].name); + set_val_strc (arr, 0, nmc_fields_con_active_details_groups[0]->name); set_val_strc (arr, 1-idx_start, nm_active_connection_get_id (active)); set_val_strc (arr, 2-idx_start, nm_active_connection_get_uuid (active)); set_val_str (arr, 3-idx_start, dev_str->str); @@ -1192,22 +1142,19 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) GArray *print_groups; GPtrArray *group_fields = NULL; int i; - char *fields_str; - char *fields_all = NMC_FIELDS_CON_ACTIVE_DETAILS_ALL; - char *fields_common = NMC_FIELDS_CON_ACTIVE_DETAILS_ALL; - NmcOutputField *tmpl, *arr; + const char *fields_str = NULL; + const NMMetaAbstractInfo *const*tmpl; + NmcOutputField *arr; size_t tmpl_len; const char *base_hdr = _("Activate connection details"); gboolean was_output = FALSE; - 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 (!nmc->required_fields || strcasecmp (nmc->required_fields, "all") == 0) { + } else fields_str = nmc->required_fields; - print_groups = parse_output_fields (fields_str, nmc_fields_con_active_details_groups, TRUE, &group_fields, &error); + print_groups = parse_output_fields (fields_str, (const NMMetaAbstractInfo *const*) nmc_fields_con_active_details_groups, TRUE, &group_fields, &error); if (error) { g_string_printf (nmc->return_text, _("Error: 'connection show': %s"), error->message); g_error_free (error); @@ -1218,14 +1165,22 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) /* Main header */ { - NMC_OUTPUT_DATA_DEFINE_SCOPED (out); + gs_free char *header_name = NULL; + gs_free NmcOutputField *row = NULL; + gs_unref_array GArray *out_indices = NULL; - out.print_fields.header_name = (char *) construct_header_name (base_hdr, nm_active_connection_get_uuid (acon)); - out.print_fields.indices = parse_output_fields (NMC_FIELDS_CON_ACTIVE_DETAILS_ALL, - nmc_fields_con_active_details_groups, FALSE, NULL, NULL); + header_name = construct_header_name (base_hdr, nm_active_connection_get_uuid (acon)); + out_indices = parse_output_fields (NULL, + (const NMMetaAbstractInfo *const*) nmc_fields_con_active_details_groups, + FALSE, NULL, NULL); - nmc_fields_con_active_details_groups[0].flags = NMC_OF_FLAG_MAIN_HEADER_ONLY; - print_required_fields (&nmc->nmc_config, &out.print_fields, nmc_fields_con_active_details_groups); + row = g_new0 (NmcOutputField, G_N_ELEMENTS (nmc_fields_con_active_details_groups) + 1); + for (i = 0; nmc_fields_con_active_details_groups[i]; i++) + row[i].info = (const NMMetaAbstractInfo *) nmc_fields_con_active_details_groups[i]; + + print_required_fields (&nmc->nmc_config, NMC_OF_FLAG_MAIN_HEADER_ONLY, + out_indices, header_name, + 0, row); } /* Loop through the groups and print them. */ @@ -1239,28 +1194,28 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) was_output = FALSE; /* GENERAL */ - if (strcasecmp (nmc_fields_con_active_details_groups[group_idx].name, nmc_fields_con_active_details_groups[0].name) == 0) { + if (strcasecmp (nmc_fields_con_active_details_groups[group_idx]->name, nmc_fields_con_active_details_groups[0]->name) == 0) { NMC_OUTPUT_DATA_DEFINE_SCOPED (out); /* Add field names */ - tmpl = nmc_fields_con_active_details_general; + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_con_active_details_general; tmpl_len = sizeof (nmc_fields_con_active_details_general); - out.print_fields.indices = parse_output_fields (group_fld ? group_fld : NMC_FIELDS_CON_ACTIVE_DETAILS_GENERAL_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); + out_indices = parse_output_fields (group_fld, + tmpl, FALSE, NULL, NULL); + arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); /* Fill in values */ fill_output_active_connection (acon, out.output_data, TRUE, NMC_OF_FLAG_SECTION_PREFIX); print_data_prepare_width (out.output_data); - print_data (&nmc->nmc_config, &out); + print_data (&nmc->nmc_config, out_indices, NULL, 0, &out); was_output = TRUE; } /* IP4 */ - if (strcasecmp (nmc_fields_con_active_details_groups[group_idx].name, nmc_fields_con_active_details_groups[1].name) == 0) { + if (strcasecmp (nmc_fields_con_active_details_groups[group_idx]->name, nmc_fields_con_active_details_groups[1]->name) == 0) { gboolean b1 = FALSE; NMIPConfig *cfg4 = nm_active_connection_get_ip4_config (acon); @@ -1269,7 +1224,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) } /* DHCP4 */ - if (strcasecmp (nmc_fields_con_active_details_groups[group_idx].name, nmc_fields_con_active_details_groups[2].name) == 0) { + if (strcasecmp (nmc_fields_con_active_details_groups[group_idx]->name, nmc_fields_con_active_details_groups[2]->name) == 0) { gboolean b1 = FALSE; NMDhcpConfig *dhcp4 = nm_active_connection_get_dhcp4_config (acon); @@ -1278,7 +1233,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) } /* IP6 */ - if (strcasecmp (nmc_fields_con_active_details_groups[group_idx].name, nmc_fields_con_active_details_groups[3].name) == 0) { + if (strcasecmp (nmc_fields_con_active_details_groups[group_idx]->name, nmc_fields_con_active_details_groups[3]->name) == 0) { gboolean b1 = FALSE; NMIPConfig *cfg6 = nm_active_connection_get_ip6_config (acon); @@ -1287,7 +1242,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) } /* DHCP6 */ - if (strcasecmp (nmc_fields_con_active_details_groups[group_idx].name, nmc_fields_con_active_details_groups[4].name) == 0) { + if (strcasecmp (nmc_fields_con_active_details_groups[group_idx]->name, nmc_fields_con_active_details_groups[4]->name) == 0) { gboolean b1 = FALSE; NMDhcpConfig *dhcp6 = nm_active_connection_get_dhcp6_config (acon); @@ -1297,7 +1252,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) /* VPN */ if (NM_IS_VPN_CONNECTION (acon) && - strcasecmp (nmc_fields_con_active_details_groups[group_idx].name, nmc_fields_con_active_details_groups[5].name) == 0) { + strcasecmp (nmc_fields_con_active_details_groups[group_idx]->name, nmc_fields_con_active_details_groups[5]->name) == 0) { NMConnection *con; NMSettingConnection *s_con; NMSettingVpn *s_vpn; @@ -1314,11 +1269,10 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) s_con = nm_connection_get_setting_connection (con); g_assert (s_con != NULL); - tmpl = nmc_fields_con_active_details_vpn; - tmpl_len = sizeof (nmc_fields_con_active_details_vpn); - out.print_fields.indices = parse_output_fields (group_fld ? group_fld : NMC_FIELDS_CON_ACTIVE_DETAILS_VPN_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_con_active_details_vpn; + out_indices = parse_output_fields (group_fld, + tmpl, FALSE, NULL, NULL); + arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); s_vpn = nm_connection_get_setting_vpn (con); @@ -1344,8 +1298,8 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) vpn_state_str = g_strdup_printf ("%d - %s", vpn_state, vpn_connection_state_to_string (vpn_state)); /* Add values */ - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_strc (arr, 0, nmc_fields_con_active_details_groups[5].name); + arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_SECTION_PREFIX); + set_val_strc (arr, 0, nmc_fields_con_active_details_groups[5]->name); set_val_str (arr, 1, type_str); set_val_strc (arr, 2, username ? username : get_vpn_data_item (con, VPN_DATA_ITEM_USERNAME)); set_val_strc (arr, 3, get_vpn_data_item (con, VPN_DATA_ITEM_GATEWAY)); @@ -1355,7 +1309,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) g_ptr_array_add (out.output_data, arr); print_data_prepare_width (out.output_data); - print_data (&nmc->nmc_config, &out); + print_data (&nmc->nmc_config, out_indices, NULL, 0, &out); was_output = TRUE; } } @@ -1405,9 +1359,9 @@ split_required_fields_for_con_show (const char *input, found = FALSE; - for (i = 0; nmc_fields_settings_names[i].name; i++) { + for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { if ( is_all || is_common - || !strcasecmp (*iter, nmc_fields_settings_names[i].name)) { + || !strcasecmp (*iter, nm_meta_setting_infos[i].setting_name)) { if (dot) *dot = '.'; g_string_append (str1, *iter); @@ -1418,9 +1372,9 @@ split_required_fields_for_con_show (const char *input, } if (found) continue; - for (i = 0; nmc_fields_con_active_details_groups[i].name; i++) { + for (i = 0; nmc_fields_con_active_details_groups[i]; i++) { if ( is_all || is_common - || !strcasecmp (*iter, nmc_fields_con_active_details_groups[i].name)) { + || !strcasecmp (*iter, nmc_fields_con_active_details_groups[i]->name)) { if (dot) *dot = '.'; g_string_append (str2, *iter); @@ -1437,8 +1391,8 @@ split_required_fields_for_con_show (const char *input, else if (!strcasecmp (*iter, CON_SHOW_DETAIL_GROUP_ACTIVE)) group_active = TRUE; else { - char *allowed1 = nmc_get_allowed_fields (nmc_fields_settings_names, -1); - char *allowed2 = nmc_get_allowed_fields (nmc_fields_con_active_details_groups, -1); + char *allowed1 = nmc_get_allowed_fields ((const NMMetaAbstractInfo *const*) nm_meta_setting_infos_editor_p ()); + char *allowed2 = nmc_get_allowed_fields ((const NMMetaAbstractInfo *const*) nmc_fields_con_active_details_groups); g_set_error (error, NMCLI_ERROR, 0, _("invalid field '%s'; allowed fields: %s and %s, or %s,%s"), *iter, allowed1, allowed2, CON_SHOW_DETAIL_GROUP_PROFILE, CON_SHOW_DETAIL_GROUP_ACTIVE); g_free (allowed1); @@ -1791,11 +1745,10 @@ do_connections_show (NmCli *nmc, int argc, char **argv) if (argc == 0) { const GPtrArray *connections; - char *fields_str; - char *fields_all = NMC_FIELDS_CON_SHOW_ALL; + const char *fields_str = NULL; char *fields_common = NMC_FIELDS_CON_SHOW_COMMON; - NmcOutputField *tmpl, *arr; - size_t tmpl_len; + const NMMetaAbstractInfo *const*tmpl; + NmcOutputField *arr; NMC_OUTPUT_DATA_DEFINE_SCOPED (out); if (nmc->complete) @@ -1803,21 +1756,17 @@ do_connections_show (NmCli *nmc, int argc, char **argv) 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 + else if (!nmc->required_fields || strcasecmp (nmc->required_fields, "all") == 0) { + } else fields_str = nmc->required_fields; - tmpl = nmc_fields_con_show; - tmpl_len = sizeof (nmc_fields_con_show); - out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &err); + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_con_show; + out_indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &err); if (err) goto finish; /* Add headers */ - out.print_fields.header_name = active_only ? _("NetworkManager active profiles") : - _("NetworkManager connection profiles"); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); + 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); /* There might be active connections not present in connection list @@ -1835,7 +1784,10 @@ do_connections_show (NmCli *nmc, int argc, char **argv) g_ptr_array_free (sorted_cons, TRUE); print_data_prepare_width (out.output_data); - print_data (&nmc->nmc_config, &out); + print_data (&nmc->nmc_config, out_indices, + active_only ? _("NetworkManager active profiles") + : _("NetworkManager connection profiles"), + 0, &out); } else { gboolean new_line = FALSE; gboolean without_fields = (nmc->required_fields == NULL); @@ -3063,7 +3015,6 @@ static const NameItem nmc_dummy_settings [] = { { NULL, NULL, NULL, FALSE } }; -/* Available connection types */ static const NameItem nmc_valid_connection_types[] = { { NM_SETTING_GENERIC_SETTING_NAME, NULL, nmc_generic_settings }, /* Needs to be first. */ { NM_SETTING_WIRED_SETTING_NAME, "ethernet", nmc_ethernet_settings }, @@ -3199,7 +3150,6 @@ get_valid_properties_string (const NameItem *array, const char *postfix) { const NameItem *iter = array; - const NmcOutputField *field_iter; const NMMetaSettingInfoEditor *setting_info; const char *prop_name = NULL; GString *str; @@ -3236,28 +3186,15 @@ get_valid_properties_string (const NameItem *array, } /* Search the array with the arguments of the current property */ - j = 0; - while (!nm_streq0 (iter->name, nmc_fields_settings_names[j].name)) { - g_assert (nmc_fields_settings_names[j].name); - j++; - } - field_iter = nmc_fields_settings_names[j].group_list; - setting_info = nmc_fields_settings_names[j].setting_info; - + setting_info = nm_meta_setting_info_editor_find_by_name (iter->name); j = 0; while (TRUE) { gchar *new; const char *arg_name; - if (field_iter) { - arg_name = field_iter[j].name; - if (!arg_name) - break; - } else { - if (j + 1 >= setting_info->properties_num) - break; - arg_name = setting_info->properties[j + 1].property_name; - } + if (j + 1 >= setting_info->properties_num) + break; + arg_name = setting_info->properties[j + 1].property_name; /* If required, expand the alias too */ if (!postfix && iter->alias) { @@ -6045,7 +5982,7 @@ editor_show_setting (NMSetting *setting, NmCli *nmc) nmc->nmc_config_mutable.multiline_output = TRUE; nmc->nmc_config_mutable.escape_values = 0; - setting_details (setting, nmc, NULL, nmc->editor_show_secrets); + setting_details (&nmc->nmc_config, setting, NULL, nmc->editor_show_secrets); } typedef enum { @@ -6631,7 +6568,7 @@ property_edit_submenu (NmCli *nmc, /* Set global variable for use in TAB completion */ nmc_tab_completion.property = prop_name; - prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NMC_TERM_FORMAT_NORMAL, + prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NM_META_TERM_FORMAT_NORMAL, "nmcli %s.%s> ", nm_setting_get_name (curr_setting), prop_name); @@ -6970,11 +6907,11 @@ static void menu_switch_to_level0 (NmcColorOption color_option, NmcEditorMenuContext *menu_ctx, const char *prompt, - NmcTermColor prompt_color) + NMMetaTermColor prompt_color) { menu_ctx->level = 0; g_free (menu_ctx->main_prompt); - menu_ctx->main_prompt = nmc_colorize (color_option, prompt_color, NMC_TERM_FORMAT_NORMAL, "%s", prompt); + menu_ctx->main_prompt = nmc_colorize (color_option, prompt_color, NM_META_TERM_FORMAT_NORMAL, "%s", prompt); menu_ctx->curr_setting = NULL; g_strfreev (menu_ctx->valid_props); menu_ctx->valid_props = NULL; @@ -6987,11 +6924,11 @@ menu_switch_to_level1 (NmcColorOption color_option, NmcEditorMenuContext *menu_ctx, NMSetting *setting, const char *setting_name, - NmcTermColor prompt_color) + NMMetaTermColor prompt_color) { menu_ctx->level = 1; g_free (menu_ctx->main_prompt); - menu_ctx->main_prompt = nmc_colorize (color_option, prompt_color, NMC_TERM_FORMAT_NORMAL, + menu_ctx->main_prompt = nmc_colorize (color_option, prompt_color, NM_META_TERM_FORMAT_NORMAL, "nmcli %s> ", setting_name); menu_ctx->curr_setting = setting; g_strfreev (menu_ctx->valid_props); @@ -7037,7 +6974,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t g_print (_("You may edit the following settings: %s\n"), valid_settings_str); menu_ctx.level = 0; - menu_ctx.main_prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NMC_TERM_FORMAT_NORMAL, + menu_ctx.main_prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NM_META_TERM_FORMAT_NORMAL, BASE_PROMPT); menu_ctx.curr_setting = NULL; menu_ctx.valid_props = NULL; @@ -7710,7 +7647,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t nmc->editor_show_secrets = bb; } else if (cmd_arg_p && matches (cmd_arg_p, "prompt-color")) { GError *tmp_err = NULL; - NmcTermColor color; + NMMetaTermColor color; color = nmc_term_color_parse_string (cmd_arg_v ? g_strstrip (cmd_arg_v) : " ", &tmp_err); if (tmp_err) { g_print (_("Error: bad color: %s\n"), tmp_err->message); @@ -7719,10 +7656,10 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t nmc->editor_prompt_color = color; g_free (menu_ctx.main_prompt); if (menu_ctx.level == 0) - menu_ctx.main_prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NMC_TERM_FORMAT_NORMAL, + menu_ctx.main_prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NM_META_TERM_FORMAT_NORMAL, BASE_PROMPT); else - menu_ctx.main_prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NMC_TERM_FORMAT_NORMAL, + menu_ctx.main_prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NM_META_TERM_FORMAT_NORMAL, "nmcli %s> ", nm_setting_get_name (menu_ctx.curr_setting)); } diff --git a/clients/cli/connections.h b/clients/cli/connections.h index c73178e24e..01e78b02ca 100644 --- a/clients/cli/connections.h +++ b/clients/cli/connections.h @@ -33,12 +33,11 @@ nmc_read_connection_properties (NmCli *nmc, char ***argv, GError **error); -void nmc_active_connection_state_to_color (NMActiveConnectionState state, NmcTermColor *color); +void nmc_active_connection_state_to_color (NMActiveConnectionState state, NMMetaTermColor *color); -extern NmcOutputField nmc_fields_con_show[]; -extern NmcOutputField nmc_fields_settings_names[]; -extern NmcOutputField nmc_fields_con_active_details_general[]; -extern NmcOutputField nmc_fields_con_active_details_vpn[]; -extern NmcOutputField nmc_fields_con_active_details_groups[]; +extern const NmcMetaGenericInfo *const nmc_fields_con_show[]; +extern const NmcMetaGenericInfo *const nmc_fields_con_active_details_general[]; +extern const NmcMetaGenericInfo *const nmc_fields_con_active_details_vpn[]; +extern const NmcMetaGenericInfo *const nmc_fields_con_active_details_groups[]; #endif /* NMC_CONNECTIONS_H */ diff --git a/clients/cli/devices.c b/clients/cli/devices.c index f05f2ca996..750b4b022d 100644 --- a/clients/cli/devices.c +++ b/clients/cli/devices.c @@ -19,6 +19,8 @@ #include "nm-default.h" +#include "devices.h" + #include #include #include @@ -31,260 +33,215 @@ #include "polkit-agent.h" #include "utils.h" #include "common.h" -#include "devices.h" #include "connections.h" /* define some prompts */ #define PROMPT_INTERFACE _("Interface: ") #define PROMPT_INTERFACES _("Interface(s): ") -#define OUTPUT_FIELD_WITH_NAME(n) { .name = N_ (n), } -#define OUTPUT_FIELD_WITH_FIELDS(n, fields) { .name = N_ (n), .group_list = fields + 1, } - -/* Available fields for 'device status' */ -NmcOutputField nmc_fields_dev_status[] = { - OUTPUT_FIELD_WITH_NAME ("DEVICE"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("TYPE"), /* 1 */ - OUTPUT_FIELD_WITH_NAME ("STATE"), /* 2 */ - OUTPUT_FIELD_WITH_NAME ("DBUS-PATH"), /* 3 */ - OUTPUT_FIELD_WITH_NAME ("CONNECTION"), /* 4 */ - OUTPUT_FIELD_WITH_NAME ("CON-UUID"), /* 5 */ - OUTPUT_FIELD_WITH_NAME ("CON-PATH"), /* 6 */ - { 0 } +const NmcMetaGenericInfo *const nmc_fields_dev_status[] = { + NMC_META_GENERIC ("DEVICE"), /* 0 */ + NMC_META_GENERIC ("TYPE"), /* 1 */ + NMC_META_GENERIC ("STATE"), /* 2 */ + NMC_META_GENERIC ("DBUS-PATH"), /* 3 */ + NMC_META_GENERIC ("CONNECTION"), /* 4 */ + NMC_META_GENERIC ("CON-UUID"), /* 5 */ + NMC_META_GENERIC ("CON-PATH"), /* 6 */ + NULL, }; -#define NMC_FIELDS_DEV_STATUS_ALL "DEVICE,TYPE,STATE,DBUS-PATH,CONNECTION,CON-UUID,CON-PATH" #define NMC_FIELDS_DEV_STATUS_COMMON "DEVICE,TYPE,STATE,CONNECTION" -/* Available fields for 'device show' - GENERAL part */ -NmcOutputField nmc_fields_dev_show_general[] = { - OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("DEVICE"), /* 1 */ - OUTPUT_FIELD_WITH_NAME ("TYPE"), /* 2 */ - OUTPUT_FIELD_WITH_NAME ("NM-TYPE"), /* 3 */ - OUTPUT_FIELD_WITH_NAME ("VENDOR"), /* 4 */ - OUTPUT_FIELD_WITH_NAME ("PRODUCT"), /* 5 */ - OUTPUT_FIELD_WITH_NAME ("DRIVER"), /* 6 */ - OUTPUT_FIELD_WITH_NAME ("DRIVER-VERSION"), /* 7 */ - OUTPUT_FIELD_WITH_NAME ("FIRMWARE-VERSION"), /* 8 */ - OUTPUT_FIELD_WITH_NAME ("HWADDR"), /* 9 */ - OUTPUT_FIELD_WITH_NAME ("MTU"), /* 10 */ - OUTPUT_FIELD_WITH_NAME ("STATE"), /* 11 */ - OUTPUT_FIELD_WITH_NAME ("REASON"), /* 12 */ - OUTPUT_FIELD_WITH_NAME ("UDI"), /* 13 */ - OUTPUT_FIELD_WITH_NAME ("IP-IFACE"), /* 14 */ - OUTPUT_FIELD_WITH_NAME ("IS-SOFTWARE"), /* 15 */ - OUTPUT_FIELD_WITH_NAME ("NM-MANAGED"), /* 16 */ - OUTPUT_FIELD_WITH_NAME ("AUTOCONNECT"), /* 17 */ - OUTPUT_FIELD_WITH_NAME ("FIRMWARE-MISSING"), /* 18 */ - OUTPUT_FIELD_WITH_NAME ("NM-PLUGIN-MISSING"), /* 19 */ - OUTPUT_FIELD_WITH_NAME ("PHYS-PORT-ID"), /* 20 */ - OUTPUT_FIELD_WITH_NAME ("CONNECTION"), /* 21 */ - OUTPUT_FIELD_WITH_NAME ("CON-UUID"), /* 22 */ - OUTPUT_FIELD_WITH_NAME ("CON-PATH"), /* 23 */ - OUTPUT_FIELD_WITH_NAME ("METERED"), /* 24 */ - { 0 } +const NmcMetaGenericInfo *const nmc_fields_dev_show_general[] = { + NMC_META_GENERIC ("NAME"), /* 0 */ + NMC_META_GENERIC ("DEVICE"), /* 1 */ + NMC_META_GENERIC ("TYPE"), /* 2 */ + NMC_META_GENERIC ("NM-TYPE"), /* 3 */ + NMC_META_GENERIC ("VENDOR"), /* 4 */ + NMC_META_GENERIC ("PRODUCT"), /* 5 */ + NMC_META_GENERIC ("DRIVER"), /* 6 */ + NMC_META_GENERIC ("DRIVER-VERSION"), /* 7 */ + NMC_META_GENERIC ("FIRMWARE-VERSION"), /* 8 */ + NMC_META_GENERIC ("HWADDR"), /* 9 */ + NMC_META_GENERIC ("MTU"), /* 10 */ + NMC_META_GENERIC ("STATE"), /* 11 */ + NMC_META_GENERIC ("REASON"), /* 12 */ + NMC_META_GENERIC ("UDI"), /* 13 */ + NMC_META_GENERIC ("IP-IFACE"), /* 14 */ + NMC_META_GENERIC ("IS-SOFTWARE"), /* 15 */ + NMC_META_GENERIC ("NM-MANAGED"), /* 16 */ + NMC_META_GENERIC ("AUTOCONNECT"), /* 17 */ + NMC_META_GENERIC ("FIRMWARE-MISSING"), /* 18 */ + NMC_META_GENERIC ("NM-PLUGIN-MISSING"), /* 19 */ + NMC_META_GENERIC ("PHYS-PORT-ID"), /* 20 */ + NMC_META_GENERIC ("CONNECTION"), /* 21 */ + NMC_META_GENERIC ("CON-UUID"), /* 22 */ + NMC_META_GENERIC ("CON-PATH"), /* 23 */ + NMC_META_GENERIC ("METERED"), /* 24 */ + NULL, }; -#define NMC_FIELDS_DEV_SHOW_GENERAL_ALL "NAME,DEVICE,TYPE,NM-TYPE,VENDOR,PRODUCT,DRIVER,DRIVER-VERSION,FIRMWARE-VERSION,HWADDR,MTU,"\ - "STATE,REASON,UDI,IP-IFACE,IS-SOFTWARE,NM-MANAGED,AUTOCONNECT,FIRMWARE-MISSING,NM-PLUGIN-MISSING,"\ - "PHYS-PORT-ID,CONNECTION,CON-UUID,CON-PATH,METERED" #define NMC_FIELDS_DEV_SHOW_GENERAL_COMMON "NAME,DEVICE,TYPE,VENDOR,PRODUCT,DRIVER,HWADDR,STATE" -/* Available fields for 'device show' - CONNECTIONS part */ -NmcOutputField nmc_fields_dev_show_connections[] = { - OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("AVAILABLE-CONNECTION-PATHS"), /* 1 */ - OUTPUT_FIELD_WITH_NAME ("AVAILABLE-CONNECTIONS"), /* 2 */ - { 0 } +const NmcMetaGenericInfo *const nmc_fields_dev_show_connections[] = { + NMC_META_GENERIC ("NAME"), /* 0 */ + NMC_META_GENERIC ("AVAILABLE-CONNECTION-PATHS"), /* 1 */ + NMC_META_GENERIC ("AVAILABLE-CONNECTIONS"), /* 2 */ + NULL, }; -#define NMC_FIELDS_DEV_SHOW_CONNECTIONS_ALL "NAME,AVAILABLE-CONNECTION-PATHS,AVAILABLE-CONNECTIONS" #define NMC_FIELDS_DEV_SHOW_CONNECTIONS_COMMON "NAME,AVAILABLE-CONNECTION-PATHS,AVAILABLE-CONNECTIONS" -/* Available fields for 'device show' - CAPABILITIES part */ -NmcOutputField nmc_fields_dev_show_cap[] = { - OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("CARRIER-DETECT"), /* 1 */ - OUTPUT_FIELD_WITH_NAME ("SPEED"), /* 2 */ - OUTPUT_FIELD_WITH_NAME ("IS-SOFTWARE"), /* 3 */ - { 0 } +const NmcMetaGenericInfo *const nmc_fields_dev_show_cap[] = { + NMC_META_GENERIC ("NAME"), /* 0 */ + NMC_META_GENERIC ("CARRIER-DETECT"), /* 1 */ + NMC_META_GENERIC ("SPEED"), /* 2 */ + NMC_META_GENERIC ("IS-SOFTWARE"), /* 3 */ + NULL, }; -#define NMC_FIELDS_DEV_SHOW_CAP_ALL "NAME,CARRIER-DETECT,SPEED,IS-SOFTWARE" #define NMC_FIELDS_DEV_SHOW_CAP_COMMON "NAME,CARRIER-DETECT,SPEED,IS-SOFTWARE" -/* Available fields for 'device show' - wired properties part */ -NmcOutputField nmc_fields_dev_show_wired_prop[] = { - OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("CARRIER"), /* 1 */ - OUTPUT_FIELD_WITH_NAME ("S390-SUBCHANNELS"), /* 2 */ - { 0 } +const NmcMetaGenericInfo *const nmc_fields_dev_show_wired_prop[] = { + NMC_META_GENERIC ("NAME"), /* 0 */ + NMC_META_GENERIC ("CARRIER"), /* 1 */ + NMC_META_GENERIC ("S390-SUBCHANNELS"), /* 2 */ + NULL, }; -#define NMC_FIELDS_DEV_SHOW_WIRED_PROP_ALL "NAME,CARRIER,S390-SUBCHANNELS" #define NMC_FIELDS_DEV_SHOW_WIRED_PROP_COMMON "NAME,CARRIER,S390-SUBCHANNELS" -/* Available fields for 'device show' - wireless properties part */ -NmcOutputField nmc_fields_dev_show_wifi_prop[] = { - OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("WEP"), /* 1 */ - OUTPUT_FIELD_WITH_NAME ("WPA"), /* 2 */ - OUTPUT_FIELD_WITH_NAME ("WPA2"), /* 3 */ - OUTPUT_FIELD_WITH_NAME ("TKIP"), /* 4 */ - OUTPUT_FIELD_WITH_NAME ("CCMP"), /* 5 */ - OUTPUT_FIELD_WITH_NAME ("AP"), /* 6 */ - OUTPUT_FIELD_WITH_NAME ("ADHOC"), /* 7 */ - OUTPUT_FIELD_WITH_NAME ("2GHZ"), /* 8 */ - OUTPUT_FIELD_WITH_NAME ("5GHZ"), /* 9 */ - { 0 } +const NmcMetaGenericInfo *const nmc_fields_dev_show_wifi_prop[] = { + NMC_META_GENERIC ("NAME"), /* 0 */ + NMC_META_GENERIC ("WEP"), /* 1 */ + NMC_META_GENERIC ("WPA"), /* 2 */ + NMC_META_GENERIC ("WPA2"), /* 3 */ + NMC_META_GENERIC ("TKIP"), /* 4 */ + NMC_META_GENERIC ("CCMP"), /* 5 */ + NMC_META_GENERIC ("AP"), /* 6 */ + NMC_META_GENERIC ("ADHOC"), /* 7 */ + NMC_META_GENERIC ("2GHZ"), /* 8 */ + NMC_META_GENERIC ("5GHZ"), /* 9 */ + NULL, }; -#define NMC_FIELDS_DEV_SHOW_WIFI_PROP_ALL "NAME,WEP,WPA,WPA2,TKIP,CCMP,AP,ADHOC,2GHZ,5GHZ" #define NMC_FIELDS_DEV_SHOW_WIFI_PROP_COMMON "NAME,WEP,WPA,WPA2,TKIP,CCMP,AP,ADHOC" -/* Available fields for 'device show' - wimax properties part */ -NmcOutputField nmc_fields_dev_show_wimax_prop[] = { - OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("CTR-FREQ"), /* 1 */ - OUTPUT_FIELD_WITH_NAME ("RSSI"), /* 2 */ - OUTPUT_FIELD_WITH_NAME ("CINR"), /* 3 */ - OUTPUT_FIELD_WITH_NAME ("TX-POW"), /* 4 */ - OUTPUT_FIELD_WITH_NAME ("BSID"), /* 5 */ - { 0 } +const NmcMetaGenericInfo *const nmc_fields_dev_show_wimax_prop[] = { + NMC_META_GENERIC ("NAME"), /* 0 */ + NMC_META_GENERIC ("CTR-FREQ"), /* 1 */ + NMC_META_GENERIC ("RSSI"), /* 2 */ + NMC_META_GENERIC ("CINR"), /* 3 */ + NMC_META_GENERIC ("TX-POW"), /* 4 */ + NMC_META_GENERIC ("BSID"), /* 5 */ + NULL, }; -#define NMC_FIELDS_DEV_SHOW_WIMAX_PROP_ALL "NAME,CTR-FREQ,RSSI,CINR,TX-POW,BSID" #define NMC_FIELDS_DEV_SHOW_WIMAX_PROP_COMMON "NAME,CTR-FREQ,RSSI,CINR,TX-POW,BSID" -/* Available fields for 'device wifi list' */ -NmcOutputField nmc_fields_dev_wifi_list[] = { - OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("SSID"), /* 1 */ - OUTPUT_FIELD_WITH_NAME ("SSID-HEX"), /* 2 */ - OUTPUT_FIELD_WITH_NAME ("BSSID"), /* 3 */ - OUTPUT_FIELD_WITH_NAME ("MODE"), /* 4 */ - OUTPUT_FIELD_WITH_NAME ("CHAN"), /* 5 */ - OUTPUT_FIELD_WITH_NAME ("FREQ"), /* 6 */ - OUTPUT_FIELD_WITH_NAME ("RATE"), /* 7 */ - OUTPUT_FIELD_WITH_NAME ("SIGNAL"), /* 8 */ - OUTPUT_FIELD_WITH_NAME ("BARS"), /* 9 */ - OUTPUT_FIELD_WITH_NAME ("SECURITY"), /* 10 */ - OUTPUT_FIELD_WITH_NAME ("WPA-FLAGS"), /* 11 */ - OUTPUT_FIELD_WITH_NAME ("RSN-FLAGS"), /* 12 */ - OUTPUT_FIELD_WITH_NAME ("DEVICE"), /* 13 */ - OUTPUT_FIELD_WITH_NAME ("ACTIVE"), /* 14 */ - OUTPUT_FIELD_WITH_NAME ("IN-USE"), /* 15 */ - OUTPUT_FIELD_WITH_NAME ("DBUS-PATH"), /* 16 */ - { 0 } +const NmcMetaGenericInfo *const nmc_fields_dev_wifi_list[] = { + NMC_META_GENERIC ("NAME"), /* 0 */ + NMC_META_GENERIC ("SSID"), /* 1 */ + NMC_META_GENERIC ("SSID-HEX"), /* 2 */ + NMC_META_GENERIC ("BSSID"), /* 3 */ + NMC_META_GENERIC ("MODE"), /* 4 */ + NMC_META_GENERIC ("CHAN"), /* 5 */ + NMC_META_GENERIC ("FREQ"), /* 6 */ + NMC_META_GENERIC ("RATE"), /* 7 */ + NMC_META_GENERIC ("SIGNAL"), /* 8 */ + NMC_META_GENERIC ("BARS"), /* 9 */ + NMC_META_GENERIC ("SECURITY"), /* 10 */ + NMC_META_GENERIC ("WPA-FLAGS"), /* 11 */ + NMC_META_GENERIC ("RSN-FLAGS"), /* 12 */ + NMC_META_GENERIC ("DEVICE"), /* 13 */ + NMC_META_GENERIC ("ACTIVE"), /* 14 */ + NMC_META_GENERIC ("IN-USE"), /* 15 */ + NMC_META_GENERIC ("DBUS-PATH"), /* 16 */ + NULL, }; -#define NMC_FIELDS_DEV_WIFI_LIST_ALL "SSID,SSID-HEX,BSSID,MODE,CHAN,FREQ,RATE,SIGNAL,BARS,SECURITY,"\ - "WPA-FLAGS,RSN-FLAGS,DEVICE,ACTIVE,IN-USE,DBUS-PATH" #define NMC_FIELDS_DEV_WIFI_LIST_COMMON "IN-USE,SSID,MODE,CHAN,RATE,SIGNAL,BARS,SECURITY" #define NMC_FIELDS_DEV_WIFI_LIST_FOR_DEV_LIST "NAME,"NMC_FIELDS_DEV_WIFI_LIST_COMMON -/* Available fields for 'device wimax list' */ -NmcOutputField nmc_fields_dev_wimax_list[] = { - OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("NSP"), /* 1 */ - OUTPUT_FIELD_WITH_NAME ("SIGNAL"), /* 2 */ - OUTPUT_FIELD_WITH_NAME ("TYPE"), /* 3 */ - OUTPUT_FIELD_WITH_NAME ("DEVICE"), /* 4 */ - OUTPUT_FIELD_WITH_NAME ("ACTIVE"), /* 5 */ - OUTPUT_FIELD_WITH_NAME ("DBUS-PATH"), /* 6 */ - { 0 } +const NmcMetaGenericInfo *const nmc_fields_dev_wimax_list[] = { + NMC_META_GENERIC ("NAME"), /* 0 */ + NMC_META_GENERIC ("NSP"), /* 1 */ + NMC_META_GENERIC ("SIGNAL"), /* 2 */ + NMC_META_GENERIC ("TYPE"), /* 3 */ + NMC_META_GENERIC ("DEVICE"), /* 4 */ + NMC_META_GENERIC ("ACTIVE"), /* 5 */ + NMC_META_GENERIC ("DBUS-PATH"), /* 6 */ + NULL, }; -#define NMC_FIELDS_DEV_WIMAX_LIST_ALL "NSP,SIGNAL,TYPE,DEVICE,ACTIVE,DBUS-PATH" #define NMC_FIELDS_DEV_WIMAX_LIST_COMMON "NSP,SIGNAL,TYPE,DEVICE,ACTIVE" #define NMC_FIELDS_DEV_WIMAX_LIST_FOR_DEV_LIST "NAME,"NMC_FIELDS_DEV_WIMAX_LIST_COMMON -/* Available fields for 'device show' - BOND, BRIDGE part */ -NmcOutputField nmc_fields_dev_show_master_prop[] = { - OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("SLAVES"), /* 1 */ - { 0 } +const NmcMetaGenericInfo *const nmc_fields_dev_show_master_prop[] = { + NMC_META_GENERIC ("NAME"), /* 0 */ + NMC_META_GENERIC ("SLAVES"), /* 1 */ + NULL, }; -#define NMC_FIELDS_DEV_SHOW_MASTER_PROP_ALL "NAME,SLAVES" #define NMC_FIELDS_DEV_SHOW_MASTER_PROP_COMMON "NAME,SLAVES" -/* Available fields for 'device show' - TEAM part */ -NmcOutputField nmc_fields_dev_show_team_prop[] = { - OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("SLAVES"), /* 1 */ - OUTPUT_FIELD_WITH_NAME ("CONFIG"), /* 2 */ - { 0 } +const NmcMetaGenericInfo *const nmc_fields_dev_show_team_prop[] = { + NMC_META_GENERIC ("NAME"), /* 0 */ + NMC_META_GENERIC ("SLAVES"), /* 1 */ + NMC_META_GENERIC ("CONFIG"), /* 2 */ + NULL, }; -#define NMC_FIELDS_DEV_SHOW_TEAM_PROP_ALL "NAME,SLAVES,CONFIG" #define NMC_FIELDS_DEV_SHOW_TEAM_PROP_COMMON "NAME,SLAVES,CONFIG" -/* Available fields for 'device show' - VLAN part */ -NmcOutputField nmc_fields_dev_show_vlan_prop[] = { - OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("PARENT"), /* 1 */ - OUTPUT_FIELD_WITH_NAME ("ID"), /* 2 */ - { 0 } +const NmcMetaGenericInfo *const nmc_fields_dev_show_vlan_prop[] = { + NMC_META_GENERIC ("NAME"), /* 0 */ + NMC_META_GENERIC ("PARENT"), /* 1 */ + NMC_META_GENERIC ("ID"), /* 2 */ + NULL, }; -#define NMC_FIELDS_DEV_SHOW_VLAN_PROP_ALL "NAME,PARENT,ID" #define NMC_FIELDS_DEV_SHOW_VLAN_PROP_COMMON "NAME,PARENT,ID" -/* Available fields for 'device show' - BLUETOOTH part */ -NmcOutputField nmc_fields_dev_show_bluetooth[] = { - OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("CAPABILITIES"), /* 1 */ - { 0 } +const NmcMetaGenericInfo *const nmc_fields_dev_show_bluetooth[] = { + NMC_META_GENERIC ("NAME"), /* 0 */ + NMC_META_GENERIC ("CAPABILITIES"), /* 1 */ + NULL, }; -#define NMC_FIELDS_DEV_SHOW_BLUETOOTH_ALL "NAME,CAPABILITIES" #define NMC_FIELDS_DEV_SHOW_BLUETOOTH_COMMON "NAME,CAPABILITIES" -/* defined in common.c */ -extern NmcOutputField nmc_fields_ip4_config[]; -extern NmcOutputField nmc_fields_ip6_config[]; -extern NmcOutputField nmc_fields_dhcp4_config[]; -extern NmcOutputField nmc_fields_dhcp6_config[]; - /* Available sections for 'device show' */ -NmcOutputField nmc_fields_dev_show_sections[] = { - OUTPUT_FIELD_WITH_FIELDS ("GENERAL", nmc_fields_dev_show_general), /* 0 */ - OUTPUT_FIELD_WITH_FIELDS ("CAPABILITIES", nmc_fields_dev_show_cap), /* 1 */ - OUTPUT_FIELD_WITH_FIELDS ("WIFI-PROPERTIES", nmc_fields_dev_show_wifi_prop), /* 2 */ - OUTPUT_FIELD_WITH_FIELDS ("AP", nmc_fields_dev_wifi_list), /* 3 */ - OUTPUT_FIELD_WITH_FIELDS ("WIRED-PROPERTIES", nmc_fields_dev_show_wired_prop), /* 4 */ - OUTPUT_FIELD_WITH_FIELDS ("WIMAX-PROPERTIES", nmc_fields_dev_show_wimax_prop), /* 5 */ - OUTPUT_FIELD_WITH_FIELDS ("NSP", nmc_fields_dev_wimax_list), /* 6 */ - OUTPUT_FIELD_WITH_FIELDS ("IP4", nmc_fields_ip4_config), /* 7 */ - OUTPUT_FIELD_WITH_FIELDS ("DHCP4", nmc_fields_dhcp4_config), /* 8 */ - OUTPUT_FIELD_WITH_FIELDS ("IP6", nmc_fields_ip6_config), /* 9 */ - OUTPUT_FIELD_WITH_FIELDS ("DHCP6", nmc_fields_dhcp6_config), /* 10 */ - OUTPUT_FIELD_WITH_FIELDS ("BOND", nmc_fields_dev_show_master_prop), /* 11 */ - OUTPUT_FIELD_WITH_FIELDS ("TEAM", nmc_fields_dev_show_team_prop), /* 12 */ - OUTPUT_FIELD_WITH_FIELDS ("BRIDGE", nmc_fields_dev_show_master_prop), /* 13 */ - OUTPUT_FIELD_WITH_FIELDS ("VLAN", nmc_fields_dev_show_vlan_prop), /* 14 */ - OUTPUT_FIELD_WITH_FIELDS ("BLUETOOTH", nmc_fields_dev_show_bluetooth), /* 15 */ - OUTPUT_FIELD_WITH_FIELDS ("CONNECTIONS", nmc_fields_dev_show_connections), /* 16 */ - { 0 } +const NmcMetaGenericInfo *const nmc_fields_dev_show_sections[] = { + NMC_META_GENERIC_WITH_NESTED ("GENERAL", nmc_fields_dev_show_general + 1), /* 0 */ + NMC_META_GENERIC_WITH_NESTED ("CAPABILITIES", nmc_fields_dev_show_cap + 1), /* 1 */ + NMC_META_GENERIC_WITH_NESTED ("WIFI-PROPERTIES", nmc_fields_dev_show_wifi_prop + 1), /* 2 */ + NMC_META_GENERIC_WITH_NESTED ("AP", nmc_fields_dev_wifi_list + 1), /* 3 */ + 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 ("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 */ + 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 ("BRIDGE", nmc_fields_dev_show_master_prop + 1), /* 13 */ + NMC_META_GENERIC_WITH_NESTED ("VLAN", nmc_fields_dev_show_vlan_prop + 1), /* 14 */ + NMC_META_GENERIC_WITH_NESTED ("BLUETOOTH", nmc_fields_dev_show_bluetooth + 1), /* 15 */ + NMC_META_GENERIC_WITH_NESTED ("CONNECTIONS", nmc_fields_dev_show_connections + 1), /* 16 */ + NULL, }; -#define NMC_FIELDS_DEV_SHOW_SECTIONS_ALL "GENERAL,CAPABILITIES,BOND,TEAM,BRIDGE,VLAN,WIFI-PROPERTIES,AP,WIRED-PROPERTIES,"\ - "BLUETOOTH,CONNECTIONS,IP4,DHCP4,IP6,DHCP6" #define NMC_FIELDS_DEV_SHOW_SECTIONS_COMMON "GENERAL.DEVICE,GENERAL.TYPE,GENERAL.HWADDR,GENERAL.MTU,GENERAL.STATE,"\ "GENERAL.CONNECTION,GENERAL.CON-PATH,WIRED-PROPERTIES,IP4,IP6" -/* Available fields for 'device lldp' */ -NmcOutputField nmc_fields_dev_lldp_list[] = { - OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("DEVICE"), /* 1 */ - OUTPUT_FIELD_WITH_NAME ("CHASSIS-ID"), /* 2 */ - OUTPUT_FIELD_WITH_NAME ("PORT-ID"), /* 3 */ - OUTPUT_FIELD_WITH_NAME ("PORT-DESCRIPTION"), /* 4 */ - OUTPUT_FIELD_WITH_NAME ("SYSTEM-NAME"), /* 5 */ - OUTPUT_FIELD_WITH_NAME ("SYSTEM-DESCRIPTION"), /* 6 */ - OUTPUT_FIELD_WITH_NAME ("SYSTEM-CAPABILITIES"), /* 7 */ - OUTPUT_FIELD_WITH_NAME ("IEEE-802-1-PVID"), /* 8 */ - OUTPUT_FIELD_WITH_NAME ("IEEE-802-1-PPVID"), /* 9 */ - OUTPUT_FIELD_WITH_NAME ("IEEE-802-1-PPVID-FLAGS"), /* 10 */ - OUTPUT_FIELD_WITH_NAME ("IEEE-802-1-VID"), /* 11 */ - OUTPUT_FIELD_WITH_NAME ("IEEE-802-1-VLAN-NAME"), /* 12 */ - OUTPUT_FIELD_WITH_NAME ("DESTINATION"), /* 13 */ - OUTPUT_FIELD_WITH_NAME ("CHASSIS-ID-TYPE"), /* 14 */ - OUTPUT_FIELD_WITH_NAME ("PORT-ID-TYPE"), /* 15 */ - { 0 } +const NmcMetaGenericInfo *const nmc_fields_dev_lldp_list[] = { + NMC_META_GENERIC ("NAME"), /* 0 */ + NMC_META_GENERIC ("DEVICE"), /* 1 */ + NMC_META_GENERIC ("CHASSIS-ID"), /* 2 */ + NMC_META_GENERIC ("PORT-ID"), /* 3 */ + NMC_META_GENERIC ("PORT-DESCRIPTION"), /* 4 */ + NMC_META_GENERIC ("SYSTEM-NAME"), /* 5 */ + NMC_META_GENERIC ("SYSTEM-DESCRIPTION"), /* 6 */ + NMC_META_GENERIC ("SYSTEM-CAPABILITIES"), /* 7 */ + NMC_META_GENERIC ("IEEE-802-1-PVID"), /* 8 */ + NMC_META_GENERIC ("IEEE-802-1-PPVID"), /* 9 */ + NMC_META_GENERIC ("IEEE-802-1-PPVID-FLAGS"), /* 10 */ + NMC_META_GENERIC ("IEEE-802-1-VID"), /* 11 */ + NMC_META_GENERIC ("IEEE-802-1-VLAN-NAME"), /* 12 */ + NMC_META_GENERIC ("DESTINATION"), /* 13 */ + NMC_META_GENERIC ("CHASSIS-ID-TYPE"), /* 14 */ + NMC_META_GENERIC ("PORT-ID-TYPE"), /* 15 */ + NULL, }; -#define NMC_FIELDS_DEV_LLDP_LIST_ALL "DEVICE,CHASSIS-ID,PORT-ID,PORT-DESCRIPTION,SYSTEM-NAME,SYSTEM-DESCRIPTION," \ - "SYSTEM-CAPABILITIES,IEEE-802-1-PVID,IEEE-802-1-PPVID,IEEE-802-1-PPVID-FLAGS," \ - "IEEE-802-1-VID,IEEE-802-1-VLAN-NAME,DESTINATION,CHASSIS-ID-TYPE,PORT-ID-TYPE" #define NMC_FIELDS_DEV_LLDP_LIST_COMMON "DEVICE,CHASSIS-ID,PORT-ID,PORT-DESCRIPTION,SYSTEM-NAME,SYSTEM-DESCRIPTION," \ "SYSTEM-CAPABILITIES" @@ -701,21 +658,21 @@ sort_access_points (const GPtrArray *aps) } static void -wifi_signal_to_color (guint8 strength, NmcTermColor *color, NmcTermFormat *color_fmt) +wifi_signal_to_color (guint8 strength, NMMetaTermColor *color, NMMetaTermFormat *color_fmt) { - *color = NMC_TERM_COLOR_NORMAL; - *color_fmt = NMC_TERM_FORMAT_NORMAL; + *color = NM_META_TERM_COLOR_NORMAL; + *color_fmt = NM_META_TERM_FORMAT_NORMAL; if (strength > 80) - *color = NMC_TERM_COLOR_GREEN; + *color = NM_META_TERM_COLOR_GREEN; else if (strength > 55) - *color = NMC_TERM_COLOR_YELLOW; + *color = NM_META_TERM_COLOR_YELLOW; else if (strength > 30) - *color = NMC_TERM_COLOR_MAGENTA; + *color = NM_META_TERM_COLOR_MAGENTA; else if (strength > 5) - *color = NMC_TERM_COLOR_CYAN; + *color = NM_META_TERM_COLOR_CYAN; else - *color_fmt = NMC_TERM_FORMAT_DIM; + *color_fmt = NM_META_TERM_FORMAT_DIM; } static char * @@ -788,8 +745,8 @@ fill_output_access_point (gpointer data, gpointer user_data) GString *security_str; char *ap_name; const char *sig_bars; - NmcTermColor color; - NmcTermFormat color_fmt; + NMMetaTermColor color; + NMMetaTermFormat color_fmt; if (info->active_bssid) { const char *current_bssid = nm_access_point_get_bssid (ap); @@ -850,8 +807,7 @@ fill_output_access_point (gpointer data, gpointer user_data) if (security_str->len > 0) g_string_truncate (security_str, security_str->len-1); /* Chop off last space */ - arr = nmc_dup_fields_array (nmc_fields_dev_wifi_list, - sizeof (nmc_fields_dev_wifi_list), + arr = nmc_dup_fields_array ((const NMMetaAbstractInfo *const*) nmc_fields_dev_wifi_list, info->output_flags); ap_name = g_strdup_printf ("AP[%d]", info->index++); /* AP */ @@ -880,7 +836,7 @@ fill_output_access_point (gpointer data, gpointer user_data) set_val_color_all (arr, color); set_val_color_fmt_all (arr, color_fmt); if (active) - arr[15].color = NMC_TERM_COLOR_GREEN; + arr[15].color = NM_META_TERM_COLOR_GREEN; g_ptr_array_add (info->output_data, arr); @@ -913,20 +869,13 @@ bluetooth_caps_to_string (NMBluetoothCapabilities caps) return ret_str; } -static const char * +static char * construct_header_name (const char *base, const char *spec) { - static char header_name[128]; - if (spec == NULL) - return base; + return g_strdup (base); - g_strlcpy (header_name, base, sizeof (header_name)); - g_strlcat (header_name, " (", sizeof (header_name)); - g_strlcat (header_name, spec, sizeof (header_name)); - g_strlcat (header_name, ")", sizeof (header_name)); - - return header_name; + return g_strdup_printf ("%s (%s)", base, spec); } static const char * @@ -950,8 +899,8 @@ print_bond_bridge_info (NMDevice *device, const GPtrArray *slaves = NULL; GString *slaves_str; int idx; - NmcOutputField *tmpl, *arr; - size_t tmpl_len; + const NMMetaAbstractInfo *const*tmpl; + NmcOutputField *arr; NMC_OUTPUT_DATA_DEFINE_SCOPED (out); if (NM_IS_DEVICE_BOND (device)) @@ -974,20 +923,19 @@ print_bond_bridge_info (NMDevice *device, if (slaves_str->len > 0) g_string_truncate (slaves_str, slaves_str->len-1); /* Chop off last space */ - tmpl = nmc_fields_dev_show_master_prop; - tmpl_len = sizeof (nmc_fields_dev_show_master_prop); - out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DEV_SHOW_MASTER_PROP_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dev_show_master_prop; + 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); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); + arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_SECTION_PREFIX); set_val_strc (arr, 0, group_prefix); /* i.e. BOND, TEAM, BRIDGE */ set_val_str (arr, 1, slaves_str->str); g_ptr_array_add (out.output_data, arr); print_data_prepare_width (out.output_data); - print_data (&nmc->nmc_config, &out); + print_data (&nmc->nmc_config, out_indices, NULL, 0, &out); g_string_free (slaves_str, FALSE); @@ -1022,8 +970,8 @@ print_team_info (NMDevice *device, const GPtrArray *slaves = NULL; GString *slaves_str; int idx; - NmcOutputField *tmpl, *arr; - size_t tmpl_len; + const NMMetaAbstractInfo *const* tmpl; + NmcOutputField *arr; NMC_OUTPUT_DATA_DEFINE_SCOPED (out); if (NM_IS_DEVICE_TEAM (device)) @@ -1044,24 +992,22 @@ print_team_info (NMDevice *device, if (slaves_str->len > 0) g_string_truncate (slaves_str, slaves_str->len-1); /* Chop off last space */ - tmpl = nmc_fields_dev_show_team_prop; - tmpl_len = sizeof (nmc_fields_dev_show_team_prop); - out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DEV_SHOW_TEAM_PROP_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dev_show_team_prop; + 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); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); + arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_SECTION_PREFIX); set_val_strc (arr, 0, group_prefix); /* TEAM */ set_val_str (arr, 1, slaves_str->str); set_val_str (arr, 2, sanitize_team_config (nm_device_team_get_config (NM_DEVICE_TEAM (device)))); g_ptr_array_add (out.output_data, arr); print_data_prepare_width (out.output_data); - print_data (&nmc->nmc_config, &out); + print_data (&nmc->nmc_config, out_indices, NULL, 0, &out); g_string_free (slaves_str, FALSE); - nmc_empty_output_fields (&out); return TRUE; } @@ -1079,11 +1025,9 @@ show_device_info (NMDevice *device, NmCli *nmc) char *speed_str, *state_str, *reason_str, *mtu_str; GArray *sections_array; int k; - char *fields_str; - char *fields_all = NMC_FIELDS_DEV_SHOW_SECTIONS_ALL; - char *fields_common = NMC_FIELDS_DEV_SHOW_SECTIONS_COMMON; - NmcOutputField *tmpl, *arr; - size_t tmpl_len; + const char *fields_str = NULL; + const NMMetaAbstractInfo *const*tmpl; + NmcOutputField *arr; gboolean was_output = FALSE; NMIPConfig *cfg4, *cfg6; NMDhcpConfig *dhcp4, *dhcp6; @@ -1091,13 +1035,12 @@ show_device_info (NMDevice *device, NmCli *nmc) GPtrArray *fields_in_section = NULL; if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0) - fields_str = fields_common; - else if (strcasecmp (nmc->required_fields, "all") == 0) - fields_str = fields_all; - else + fields_str = NMC_FIELDS_DEV_SHOW_SECTIONS_COMMON; + else if (strcasecmp (nmc->required_fields, "all") == 0) { + } else fields_str = nmc->required_fields; - sections_array = parse_output_fields (fields_str, nmc_fields_dev_show_sections, TRUE, &fields_in_section, &error); + sections_array = parse_output_fields (fields_str, (const NMMetaAbstractInfo *const*) nmc_fields_dev_show_sections, TRUE, &fields_in_section, &error); if (error) { g_string_printf (nmc->return_text, _("Error: 'device show': %s"), error->message); g_error_free (error); @@ -1106,17 +1049,26 @@ show_device_info (NMDevice *device, NmCli *nmc) } { - NMC_OUTPUT_DATA_DEFINE_SCOPED (out); + gs_unref_array GArray *out_indices = NULL; + gs_free char *header_name = NULL; + gs_free NmcOutputField *row = NULL; + int i; /* Main header (pretty only) */ - out.print_fields.header_name = (char *) construct_header_name (base_hdr, nm_device_get_iface (device)); + header_name = construct_header_name (base_hdr, nm_device_get_iface (device)); /* Lazy way to retrieve sorted array from 0 to the number of dev fields */ - out.print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_GENERAL_ALL, - nmc_fields_dev_show_general, FALSE, NULL, NULL); + out_indices = parse_output_fields (NULL, + (const NMMetaAbstractInfo *const*) nmc_fields_dev_show_general, + FALSE, NULL, NULL); - nmc_fields_dev_show_general[0].flags = NMC_OF_FLAG_MAIN_HEADER_ONLY; - print_required_fields (&nmc->nmc_config, &out.print_fields, nmc_fields_dev_show_general); + row = g_new0 (NmcOutputField, _NM_META_SETTING_TYPE_NUM + 1); + for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) + row[i].info = (const NMMetaAbstractInfo *) &nmc_fields_dev_show_general[i]; + + print_required_fields (&nmc->nmc_config, NMC_OF_FLAG_MAIN_HEADER_ONLY, + out_indices, header_name, + 0, row); } /* Loop through the required sections and print them. */ @@ -1133,14 +1085,13 @@ show_device_info (NMDevice *device, NmCli *nmc) reason = nm_device_get_state_reason (device); /* section GENERAL */ - if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[0].name)) { + if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[0]->name)) { NMC_OUTPUT_DATA_DEFINE_SCOPED (out); - tmpl = nmc_fields_dev_show_general; - tmpl_len = sizeof (nmc_fields_dev_show_general); - out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_GENERAL_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dev_show_general; + out_indices = parse_output_fields (section_fld, + tmpl, FALSE, NULL, NULL); + arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); state_str = g_strdup_printf ("%d (%s)", state, nmc_device_state_to_string (state)); @@ -1149,8 +1100,8 @@ show_device_info (NMDevice *device, NmCli *nmc) mtu_str = g_strdup_printf ("%u", nm_device_get_mtu (device)); acon = nm_device_get_active_connection (device); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_strc (arr, 0, nmc_fields_dev_show_sections[0].name); /* "GENERAL"*/ + arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_SECTION_PREFIX); + set_val_strc (arr, 0, nmc_fields_dev_show_sections[0]->name); /* "GENERAL"*/ set_val_strc (arr, 1, nm_device_get_iface (device)); set_val_strc (arr, 2, nm_device_get_type_description (device)); set_val_strc (arr, 3, G_OBJECT_TYPE_NAME (device)); @@ -1178,19 +1129,18 @@ show_device_info (NMDevice *device, NmCli *nmc) g_ptr_array_add (out.output_data, arr); print_data_prepare_width (out.output_data); - print_data (&nmc->nmc_config, &out); + print_data (&nmc->nmc_config, out_indices, NULL, 0, &out); was_output = TRUE; } /* section CAPABILITIES */ - if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[1].name)) { + if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[1]->name)) { NMC_OUTPUT_DATA_DEFINE_SCOPED (out); - tmpl = nmc_fields_dev_show_cap; - tmpl_len = sizeof (nmc_fields_dev_show_cap); - out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_CAP_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dev_show_cap; + out_indices = parse_output_fields (section_fld, + tmpl, FALSE, NULL, NULL); + arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); caps = nm_device_get_capabilities (device); @@ -1205,15 +1155,15 @@ show_device_info (NMDevice *device, NmCli *nmc) } speed_str = speed ? g_strdup_printf (_("%u Mb/s"), speed) : g_strdup (_("unknown")); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_strc (arr, 0, nmc_fields_dev_show_sections[1].name); /* "CAPABILITIES" */ + arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_SECTION_PREFIX); + set_val_strc (arr, 0, nmc_fields_dev_show_sections[1]->name); /* "CAPABILITIES" */ set_val_strc (arr, 1, (caps & NM_DEVICE_CAP_CARRIER_DETECT) ? _("yes") : _("no")); set_val_str (arr, 2, speed_str); set_val_strc (arr, 3, (caps & NM_DEVICE_CAP_IS_SOFTWARE) ? _("yes") : _("no")); g_ptr_array_add (out.output_data, arr); print_data_prepare_width (out.output_data); - print_data (&nmc->nmc_config, &out); + print_data (&nmc->nmc_config, out_indices, NULL, 0, &out); was_output = TRUE; } @@ -1225,20 +1175,19 @@ show_device_info (NMDevice *device, NmCli *nmc) GPtrArray *aps; /* section WIFI-PROPERTIES */ - if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[2].name)) { + if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[2]->name)) { NMC_OUTPUT_DATA_DEFINE_SCOPED (out); wcaps = nm_device_wifi_get_capabilities (NM_DEVICE_WIFI (device)); - tmpl = nmc_fields_dev_show_wifi_prop; - tmpl_len = sizeof (nmc_fields_dev_show_wifi_prop); - out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_WIFI_PROP_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dev_show_wifi_prop; + out_indices = parse_output_fields (section_fld, + tmpl, FALSE, NULL, NULL); + arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_strc (arr, 0, nmc_fields_dev_show_sections[2].name); /* "WIFI-PROPERTIES" */ + arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_SECTION_PREFIX); + set_val_strc (arr, 0, nmc_fields_dev_show_sections[2]->name); /* "WIFI-PROPERTIES" */ set_val_strc (arr, 1, (wcaps & (NM_WIFI_DEVICE_CAP_CIPHER_WEP40 | NM_WIFI_DEVICE_CAP_CIPHER_WEP104)) ? _("yes") : _("no")); set_val_strc (arr, 2, (wcaps & NM_WIFI_DEVICE_CAP_WPA) ? _("yes") : _("no")); @@ -1254,12 +1203,12 @@ show_device_info (NMDevice *device, NmCli *nmc) g_ptr_array_add (out.output_data, arr); print_data_prepare_width (out.output_data); - print_data (&nmc->nmc_config, &out); + print_data (&nmc->nmc_config, out_indices, NULL, 0, &out); was_output = TRUE; } /* section AP */ - if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[3].name)) { + if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[3]->name)) { NMC_OUTPUT_DATA_DEFINE_SCOPED (out); if (state == NM_DEVICE_STATE_ACTIVATED) { @@ -1267,11 +1216,10 @@ show_device_info (NMDevice *device, NmCli *nmc) active_bssid = active_ap ? nm_access_point_get_bssid (active_ap) : NULL; } - tmpl = nmc_fields_dev_wifi_list; - tmpl_len = sizeof (nmc_fields_dev_wifi_list); - out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_WIFI_LIST_FOR_DEV_LIST, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dev_wifi_list; + out_indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_WIFI_LIST_FOR_DEV_LIST, + tmpl, FALSE, NULL, NULL); + arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); { @@ -1290,30 +1238,29 @@ show_device_info (NMDevice *device, NmCli *nmc) } print_data_prepare_width (out.output_data); - print_data (&nmc->nmc_config, &out); + print_data (&nmc->nmc_config, out_indices, NULL, 0, &out); was_output = TRUE; } } else if (NM_IS_DEVICE_ETHERNET (device)) { /* WIRED-PROPERTIES */ - if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[4].name)) { + if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[4]->name)) { NMC_OUTPUT_DATA_DEFINE_SCOPED (out); - tmpl = nmc_fields_dev_show_wired_prop; - tmpl_len = sizeof (nmc_fields_dev_show_wired_prop); - out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_WIRED_PROP_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dev_show_wired_prop; + out_indices = parse_output_fields (section_fld, + tmpl, FALSE, NULL, NULL); + arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_strc (arr, 0, nmc_fields_dev_show_sections[4].name); /* "WIRED-PROPERTIES" */ + arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_SECTION_PREFIX); + set_val_strc (arr, 0, nmc_fields_dev_show_sections[4]->name); /* "WIRED-PROPERTIES" */ set_val_strc (arr, 1, (nm_device_ethernet_get_carrier (NM_DEVICE_ETHERNET (device))) ? _("on") : _("off")); set_val_arrc (arr, 2, ((const char **) nm_device_ethernet_get_s390_subchannels (NM_DEVICE_ETHERNET (device)))); g_ptr_array_add (out.output_data, arr); print_data_prepare_width (out.output_data); - print_data (&nmc->nmc_config, &out); + print_data (&nmc->nmc_config, out_indices, NULL, 0, &out); was_output = TRUE; } } @@ -1325,101 +1272,98 @@ show_device_info (NMDevice *device, NmCli *nmc) dhcp6 = nm_device_get_dhcp6_config (device); /* 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); + 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); /* DHCP4 */ - if (dhcp4 && !strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[8].name)) - was_output = print_dhcp4_config (dhcp4, &nmc->nmc_config, nmc_fields_dev_show_sections[8].name, section_fld); + if (dhcp4 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[8]->name)) + was_output = print_dhcp4_config (dhcp4, &nmc->nmc_config, nmc_fields_dev_show_sections[8]->name, section_fld); /* IP6 */ - if (cfg6 && !strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[9].name)) - was_output = print_ip6_config (cfg6, &nmc->nmc_config, nmc_fields_dev_show_sections[9].name, section_fld); + if (cfg6 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[9]->name)) + was_output = print_ip6_config (cfg6, &nmc->nmc_config, nmc_fields_dev_show_sections[9]->name, section_fld); /* DHCP6 */ - if (dhcp6 && !strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[10].name)) - was_output = print_dhcp6_config (dhcp6, &nmc->nmc_config, nmc_fields_dev_show_sections[10].name, section_fld); + if (dhcp6 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[10]->name)) + was_output = print_dhcp6_config (dhcp6, &nmc->nmc_config, nmc_fields_dev_show_sections[10]->name, section_fld); /* Bond specific information */ if (NM_IS_DEVICE_BOND (device)) { - if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[11].name)) - was_output = print_bond_bridge_info (device, nmc, nmc_fields_dev_show_sections[11].name, section_fld); + if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[11]->name)) + was_output = print_bond_bridge_info (device, nmc, nmc_fields_dev_show_sections[11]->name, section_fld); } /* Team specific information */ if (NM_IS_DEVICE_TEAM (device)) { - if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[12].name)) - was_output = print_team_info (device, nmc, nmc_fields_dev_show_sections[12].name, section_fld); + if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[12]->name)) + was_output = print_team_info (device, nmc, nmc_fields_dev_show_sections[12]->name, section_fld); } /* Bridge specific information */ if (NM_IS_DEVICE_BRIDGE (device)) { - if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[13].name)) - was_output = print_bond_bridge_info (device, nmc, nmc_fields_dev_show_sections[13].name, section_fld); + if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[13]->name)) + was_output = print_bond_bridge_info (device, nmc, nmc_fields_dev_show_sections[13]->name, section_fld); } /* VLAN-specific information */ if ((NM_IS_DEVICE_VLAN (device))) { - if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[14].name)) { + if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[14]->name)) { char * vlan_id_str = g_strdup_printf ("%u", nm_device_vlan_get_vlan_id (NM_DEVICE_VLAN (device))); NMDevice *parent = nm_device_vlan_get_parent (NM_DEVICE_VLAN (device)); NMC_OUTPUT_DATA_DEFINE_SCOPED (out); - tmpl = nmc_fields_dev_show_vlan_prop; - tmpl_len = sizeof (nmc_fields_dev_show_vlan_prop); - out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_VLAN_PROP_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dev_show_vlan_prop; + out_indices = parse_output_fields (section_fld, + tmpl, FALSE, NULL, NULL); + arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_strc (arr, 0, nmc_fields_dev_show_sections[14].name); /* "VLAN" */ + arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_SECTION_PREFIX); + set_val_strc (arr, 0, nmc_fields_dev_show_sections[14]->name); /* "VLAN" */ set_val_strc (arr, 1, parent ? nm_device_get_iface (parent) : NULL); set_val_str (arr, 2, vlan_id_str); g_ptr_array_add (out.output_data, arr); print_data_prepare_width (out.output_data); - print_data (&nmc->nmc_config, &out); + print_data (&nmc->nmc_config, out_indices, NULL, 0, &out); was_output = TRUE; } } if (NM_IS_DEVICE_BT (device)) { - if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[15].name)) { + if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[15]->name)) { NMC_OUTPUT_DATA_DEFINE_SCOPED (out); - tmpl = nmc_fields_dev_show_bluetooth; - tmpl_len = sizeof (nmc_fields_dev_show_bluetooth); - out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_BLUETOOTH_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dev_show_bluetooth; + out_indices = parse_output_fields (section_fld, + tmpl, FALSE, NULL, NULL); + arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_strc (arr, 0, nmc_fields_dev_show_sections[15].name); /* "BLUETOOTH" */ + arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_SECTION_PREFIX); + set_val_strc (arr, 0, nmc_fields_dev_show_sections[15]->name); /* "BLUETOOTH" */ set_val_str (arr, 1, bluetooth_caps_to_string (nm_device_bt_get_capabilities (NM_DEVICE_BT (device)))); g_ptr_array_add (out.output_data, arr); print_data_prepare_width (out.output_data); - print_data (&nmc->nmc_config, &out); + print_data (&nmc->nmc_config, out_indices, NULL, 0, &out); was_output = TRUE; } } /* section CONNECTIONS */ - if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[16].name)) { + if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[16]->name)) { const GPtrArray *avail_cons; GString *ac_paths_str; char **ac_arr = NULL; int i; NMC_OUTPUT_DATA_DEFINE_SCOPED (out); - tmpl = nmc_fields_dev_show_connections; - tmpl_len = sizeof (nmc_fields_dev_show_connections); - out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_CONNECTIONS_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dev_show_connections; + out_indices = parse_output_fields (section_fld, + tmpl, FALSE, NULL, NULL); + arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); /* available-connections */ @@ -1446,14 +1390,14 @@ show_device_info (NMDevice *device, NmCli *nmc) if (ac_paths_str->len > 0) g_string_append_c (ac_paths_str, '}'); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_strc (arr, 0, nmc_fields_dev_show_sections[16].name); /* "CONNECTIONS" */ + arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_SECTION_PREFIX); + set_val_strc (arr, 0, nmc_fields_dev_show_sections[16]->name); /* "CONNECTIONS" */ set_val_str (arr, 1, ac_paths_str->str); set_val_arr (arr, 2, (ac_arr)); g_ptr_array_add (out.output_data, arr); print_data_prepare_width (out.output_data); - print_data (&nmc->nmc_config, &out); + print_data (&nmc->nmc_config, out_indices, NULL, 0, &out); g_string_free (ac_paths_str, FALSE); was_output = TRUE; @@ -1469,19 +1413,19 @@ show_device_info (NMDevice *device, NmCli *nmc) } void -nmc_device_state_to_color (NMDeviceState state, NmcTermColor *color, NmcTermFormat *color_fmt) +nmc_device_state_to_color (NMDeviceState state, NMMetaTermColor *color, NMMetaTermFormat *color_fmt) { - *color = NMC_TERM_COLOR_NORMAL; - *color_fmt = NMC_TERM_FORMAT_NORMAL; + *color = NM_META_TERM_COLOR_NORMAL; + *color_fmt = NM_META_TERM_FORMAT_NORMAL; if (state <= NM_DEVICE_STATE_UNAVAILABLE) - *color_fmt= NMC_TERM_FORMAT_DIM; + *color_fmt= NM_META_TERM_FORMAT_DIM; else if (state == NM_DEVICE_STATE_DISCONNECTED) - *color = NMC_TERM_COLOR_RED; + *color = NM_META_TERM_COLOR_RED; else if (state >= NM_DEVICE_STATE_PREPARE && state <= NM_DEVICE_STATE_SECONDARIES) - *color = NMC_TERM_COLOR_YELLOW; + *color = NM_META_TERM_COLOR_YELLOW; else if (state == NM_DEVICE_STATE_ACTIVATED) - *color = NMC_TERM_COLOR_GREEN; + *color = NM_META_TERM_COLOR_GREEN; } static void @@ -1489,10 +1433,9 @@ fill_output_device_status (NMDevice *device, GPtrArray *output_data) { NMActiveConnection *ac; NMDeviceState state; - NmcTermColor color; - NmcTermFormat color_fmt; - NmcOutputField *arr = nmc_dup_fields_array (nmc_fields_dev_status, - sizeof (nmc_fields_dev_status), + NMMetaTermColor color; + NMMetaTermFormat color_fmt; + NmcOutputField *arr = nmc_dup_fields_array ((const NMMetaAbstractInfo *const*) nmc_fields_dev_status, 0); state = nm_device_get_state (device); @@ -1520,11 +1463,9 @@ do_devices_status (NmCli *nmc, int argc, char **argv) GError *error = NULL; NMDevice **devices; int i; - char *fields_str; - char *fields_all = NMC_FIELDS_DEV_STATUS_ALL; - char *fields_common = NMC_FIELDS_DEV_STATUS_COMMON; - NmcOutputField *tmpl, *arr; - size_t tmpl_len; + const char *fields_str = NULL; + const NMMetaAbstractInfo *const*tmpl; + NmcOutputField *arr; NMC_OUTPUT_DATA_DEFINE_SCOPED (out); next_arg (nmc, &argc, &argv, NULL); @@ -1539,15 +1480,13 @@ do_devices_status (NmCli *nmc, int argc, char **argv) } 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 + fields_str = NMC_FIELDS_DEV_STATUS_COMMON; + else if (!nmc->required_fields || strcasecmp (nmc->required_fields, "all") == 0) { + } else fields_str = nmc->required_fields; - tmpl = nmc_fields_dev_status; - tmpl_len = sizeof (nmc_fields_dev_status); - out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dev_status; + out_indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); if (error) { g_string_printf (nmc->return_text, _("Error: 'device status': %s"), error->message); @@ -1556,8 +1495,7 @@ do_devices_status (NmCli *nmc, int argc, char **argv) } /* Add headers */ - out.print_fields.header_name = _("Status of devices"); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); + 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); devices = nmc_get_devices_sorted (nmc->client); @@ -1565,7 +1503,7 @@ do_devices_status (NmCli *nmc, int argc, char **argv) fill_output_device_status (devices[i], out.output_data); print_data_prepare_width (out.output_data); - print_data (&nmc->nmc_config, &out); + print_data (&nmc->nmc_config, out_indices, _("Status of devices"), 0, &out); g_free (devices); @@ -2417,8 +2355,8 @@ static void device_state (NMDevice *device, GParamSpec *pspec, NmCli *nmc) { NMDeviceState state = nm_device_get_state (device); - NmcTermColor color; - NmcTermFormat color_fmt; + NMMetaTermColor color; + NMMetaTermFormat color_fmt; char *str; nmc_device_state_to_color (state, &color, &color_fmt); @@ -2521,7 +2459,7 @@ show_access_point_info (NMDevice *device, NmCli *nmc, NmcOutputData *out) active_bssid = active_ap ? nm_access_point_get_bssid (active_ap) : NULL; } - arr = nmc_dup_fields_array (nmc_fields_dev_wifi_list, sizeof (nmc_fields_dev_wifi_list), + arr = nmc_dup_fields_array ((const NMMetaAbstractInfo *const*) nmc_fields_dev_wifi_list, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out->output_data, arr); @@ -2541,7 +2479,6 @@ show_access_point_info (NMDevice *device, NmCli *nmc, NmcOutputData *out) } print_data_prepare_width (out->output_data); - print_data (&nmc->nmc_config, out); } /* @@ -2668,13 +2605,12 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) const GPtrArray *aps; APInfo *info; int i, j; - char *fields_str; - char *fields_all = NMC_FIELDS_DEV_WIFI_LIST_ALL; - char *fields_common = NMC_FIELDS_DEV_WIFI_LIST_COMMON; - NmcOutputField *tmpl, *arr; - size_t tmpl_len; + const char *fields_str = NULL; + const NMMetaAbstractInfo *const*tmpl; + NmcOutputField *arr; const char *base_hdr = _("Wi-Fi scan list"); NMC_OUTPUT_DATA_DEFINE_SCOPED (out); + gs_free char *header_name = NULL; devices = nmc_get_devices_sorted (nmc->client); @@ -2711,15 +2647,13 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) } 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 + fields_str = NMC_FIELDS_DEV_WIFI_LIST_COMMON; + else if (!nmc->required_fields || strcasecmp (nmc->required_fields, "all") == 0) { + } else fields_str = nmc->required_fields; - tmpl = nmc_fields_dev_wifi_list; - tmpl_len = sizeof (nmc_fields_dev_wifi_list); - out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dev_wifi_list; + out_indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); if (error) { g_string_printf (nmc->return_text, _("Error: 'device wifi': %s"), error->message); @@ -2731,13 +2665,14 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) return nmc->return_value; if (ifname) { + device = find_wifi_device_by_iface (devices, ifname, NULL); if (!device) { g_string_printf (nmc->return_text, _("Error: Device '%s' not found."), ifname); return NMC_RESULT_ERROR_NOT_FOUND; } /* Main header name */ - out.print_fields.header_name = (char *) construct_header_name (base_hdr, ifname); + header_name = construct_header_name (base_hdr, ifname); if (NM_IS_DEVICE_WIFI (device)) { if (bssid_user) { @@ -2759,7 +2694,7 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) return NMC_RESULT_ERROR_NOT_FOUND; } /* Add headers (field names) */ - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); + 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); info = g_malloc0 (sizeof (APInfo)); @@ -2772,10 +2707,11 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) fill_output_access_point (ap, info); print_data_prepare_width (out.output_data); - print_data (&nmc->nmc_config, &out); + print_data (&nmc->nmc_config, out_indices, header_name, 0, &out); g_free (info); } else { show_access_point_info (device, nmc, &out); + print_data (&nmc->nmc_config, out_indices, NULL, 0, &out); } } else { if ( nm_device_get_device_type (device) == NM_DEVICE_TYPE_GENERIC @@ -2798,16 +2734,18 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) /* Specific AP requested - list only that */ for (i = 0; devices[i]; i++) { NMDevice *dev = devices[i]; + NMC_OUTPUT_DATA_DEFINE_SCOPED (out2); + gs_free char *header_name2 = NULL; if (!NM_IS_DEVICE_WIFI (dev)) continue; /* Main header name */ - out.print_fields.header_name = (char *) construct_header_name (base_hdr, nm_device_get_iface (dev)); - out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, NULL); + header_name2 = construct_header_name (base_hdr, nm_device_get_iface (dev)); + out2_indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, 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, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); + g_ptr_array_add (out2.output_data, arr); aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (dev)); for (j = 0; j < aps->len; j++) { @@ -2832,9 +2770,8 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) } if (empty_line) g_print ("\n"); /* Empty line between devices' APs */ - print_data_prepare_width (out.output_data); - print_data (&nmc->nmc_config, &out); - nmc_empty_output_fields (&out); + print_data_prepare_width (out2.output_data); + print_data (&nmc->nmc_config, out2_indices, header_name2, 0, &out2); empty_line = TRUE; } if (!ap) { @@ -2846,16 +2783,18 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) for (i = 0; devices[i]; i++) { NMDevice *dev = devices[i]; NMC_OUTPUT_DATA_DEFINE_SCOPED (out2); + gs_free char *header_name2 = NULL; /* Main header name */ - out2.print_fields.header_name = (char *) construct_header_name (base_hdr, - nm_device_get_iface (dev)); - out2.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, NULL); + header_name2 = construct_header_name (base_hdr, + nm_device_get_iface (dev)); + out2_indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, NULL); if (NM_IS_DEVICE_WIFI (dev)) { if (empty_line) g_print ("\n"); /* Empty line between devices' APs */ show_access_point_info (dev, nmc, &out2); + print_data (&nmc->nmc_config, out2_indices, header_name2, 0, &out2); empty_line = TRUE; } } @@ -3709,35 +3648,35 @@ do_device_wifi (NmCli *nmc, int argc, char **argv) } static int -show_device_lldp_list (NMDevice *device, NmCli *nmc, char *fields_str, int *counter) +show_device_lldp_list (NMDevice *device, NmCli *nmc, const char *fields_str, int *counter) { - NmcOutputField *tmpl, *arr; + const NMMetaAbstractInfo *const*tmpl; + NmcOutputField *arr; GPtrArray *neighbors; - size_t tmpl_len; const char *str; int i; NMC_OUTPUT_DATA_DEFINE_SCOPED (out); + gs_free char *header_name = NULL; neighbors = nm_device_get_lldp_neighbors (device); if (!neighbors || !neighbors->len) return 0; - tmpl = nmc_fields_dev_lldp_list; - tmpl_len = sizeof (nmc_fields_dev_lldp_list); + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dev_lldp_list; /* Main header name */ - out.print_fields.header_name = (char *) construct_header_name (_("Device LLDP neighbors"), - nm_device_get_iface (device)); - out.print_fields.indices = parse_output_fields (fields_str, nmc_fields_dev_lldp_list, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); + header_name = construct_header_name (_("Device LLDP neighbors"), + nm_device_get_iface (device)); + out_indices = parse_output_fields (fields_str, (const NMMetaAbstractInfo *const*) nmc_fields_dev_lldp_list, FALSE, NULL, NULL); + 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 (i = 0; i < neighbors->len; i++) { NMLldpNeighbor *neighbor = neighbors->pdata[i]; guint value; - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); + arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_SECTION_PREFIX); set_val_str (arr, 0, g_strdup_printf ("NEIGHBOR[%d]", (*counter)++)); set_val_strc (arr, 1, nm_device_get_iface (device)); @@ -3788,7 +3727,7 @@ show_device_lldp_list (NMDevice *device, NmCli *nmc, char *fields_str, int *coun } print_data_prepare_width (out.output_data); - print_data (&nmc->nmc_config, &out); + print_data (&nmc->nmc_config, out_indices, header_name, 0, &out); return neighbors->len; } @@ -3798,9 +3737,9 @@ do_device_lldp_list (NmCli *nmc, int argc, char **argv) { NMDevice *device = NULL; gs_free_error GError *error = NULL; - char *fields_str; + const char *fields_str = NULL; int counter = 0; - NMC_OUTPUT_DATA_DEFINE_SCOPED (out); + gs_unref_array GArray *out_indices = NULL; next_arg (nmc, &argc, &argv, NULL); while (argc > 0) { @@ -3830,12 +3769,11 @@ do_device_lldp_list (NmCli *nmc, int argc, char **argv) if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0) fields_str = NMC_FIELDS_DEV_LLDP_LIST_COMMON; - else if (!nmc->required_fields || strcasecmp (nmc->required_fields, "all") == 0) - fields_str = NMC_FIELDS_DEV_LLDP_LIST_ALL; - else + else if (!nmc->required_fields || strcasecmp (nmc->required_fields, "all") == 0) { + } else fields_str = nmc->required_fields; - out.print_fields.indices = parse_output_fields (fields_str, nmc_fields_dev_lldp_list, FALSE, NULL, &error); + out_indices = parse_output_fields (fields_str, (const NMMetaAbstractInfo *const*) nmc_fields_dev_lldp_list, FALSE, NULL, &error); if (error) { g_string_printf (nmc->return_text, _("Error: 'device lldp list': %s"), error->message); diff --git a/clients/cli/devices.h b/clients/cli/devices.h index 672944beda..2c261bc7ab 100644 --- a/clients/cli/devices.h +++ b/clients/cli/devices.h @@ -32,22 +32,22 @@ void monitor_devices (NmCli *nmc); NMDevice ** nmc_get_devices_sorted (NMClient *client); -void nmc_device_state_to_color (NMDeviceState state, NmcTermColor *color, NmcTermFormat *color_fmt); +void nmc_device_state_to_color (NMDeviceState state, NMMetaTermColor *color, NMMetaTermFormat *color_fmt); -extern NmcOutputField nmc_fields_dev_status[]; -extern NmcOutputField nmc_fields_dev_show_general[]; -extern NmcOutputField nmc_fields_dev_show_connections[]; -extern NmcOutputField nmc_fields_dev_show_cap[]; -extern NmcOutputField nmc_fields_dev_show_wired_prop[]; -extern NmcOutputField nmc_fields_dev_show_wifi_prop[]; -extern NmcOutputField nmc_fields_dev_show_wimax_prop[]; -extern NmcOutputField nmc_fields_dev_wifi_list[]; -extern NmcOutputField nmc_fields_dev_wimax_list[]; -extern NmcOutputField nmc_fields_dev_show_master_prop[]; -extern NmcOutputField nmc_fields_dev_show_team_prop[]; -extern NmcOutputField nmc_fields_dev_show_vlan_prop[]; -extern NmcOutputField nmc_fields_dev_show_bluetooth[]; -extern NmcOutputField nmc_fields_dev_show_sections[]; -extern NmcOutputField nmc_fields_dev_lldp_list[]; +extern const NmcMetaGenericInfo *const nmc_fields_dev_status[]; +extern const NmcMetaGenericInfo *const nmc_fields_dev_show_general[]; +extern const NmcMetaGenericInfo *const nmc_fields_dev_show_connections[]; +extern const NmcMetaGenericInfo *const nmc_fields_dev_show_cap[]; +extern const NmcMetaGenericInfo *const nmc_fields_dev_show_wired_prop[]; +extern const NmcMetaGenericInfo *const nmc_fields_dev_show_wifi_prop[]; +extern const NmcMetaGenericInfo *const nmc_fields_dev_show_wimax_prop[]; +extern const NmcMetaGenericInfo *const nmc_fields_dev_wifi_list[]; +extern const NmcMetaGenericInfo *const nmc_fields_dev_wimax_list[]; +extern const NmcMetaGenericInfo *const nmc_fields_dev_show_master_prop[]; +extern const NmcMetaGenericInfo *const nmc_fields_dev_show_team_prop[]; +extern const NmcMetaGenericInfo *const nmc_fields_dev_show_vlan_prop[]; +extern const NmcMetaGenericInfo *const nmc_fields_dev_show_bluetooth[]; +extern const NmcMetaGenericInfo *const nmc_fields_dev_show_sections[]; +extern const NmcMetaGenericInfo *const nmc_fields_dev_lldp_list[]; #endif /* NMC_DEVICES_H */ diff --git a/clients/cli/general.c b/clients/cli/general.c index 71f3a626a3..fe29e9947e 100644 --- a/clients/cli/general.c +++ b/clients/cli/general.c @@ -19,6 +19,8 @@ #include "nm-default.h" +#include "general.h" + #include #include @@ -29,28 +31,24 @@ #include "polkit-agent.h" #include "utils.h" #include "common.h" -#include "general.h" #include "common.h" #include "devices.h" #include "connections.h" -#define OUTPUT_FIELD_WITH_NAME(n) { .name = N_ (n), } - -/* Available fields for 'general status' */ -static NmcOutputField nmc_fields_nm_status[] = { - OUTPUT_FIELD_WITH_NAME ("RUNNING"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("VERSION"), /* 1 */ - OUTPUT_FIELD_WITH_NAME ("STATE"), /* 2 */ - OUTPUT_FIELD_WITH_NAME ("STARTUP"), /* 3 */ - OUTPUT_FIELD_WITH_NAME ("CONNECTIVITY"), /* 4 */ - OUTPUT_FIELD_WITH_NAME ("NETWORKING"), /* 5 */ - OUTPUT_FIELD_WITH_NAME ("WIFI-HW"), /* 6 */ - OUTPUT_FIELD_WITH_NAME ("WIFI"), /* 7 */ - OUTPUT_FIELD_WITH_NAME ("WWAN-HW"), /* 8 */ - OUTPUT_FIELD_WITH_NAME ("WWAN"), /* 9 */ - OUTPUT_FIELD_WITH_NAME ("WIMAX-HW"), /* 10 */ - OUTPUT_FIELD_WITH_NAME ("WIMAX"), /* 11 */ - { 0 } +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, }; #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" @@ -64,19 +62,19 @@ static NmcOutputField nmc_fields_nm_status[] = { /* Available fields for 'general permissions' */ -static NmcOutputField nmc_fields_nm_permissions[] = { - OUTPUT_FIELD_WITH_NAME ("PERMISSION"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("VALUE"), /* 1 */ - { 0 } +static const NmcMetaGenericInfo *const nmc_fields_nm_permissions[] = { + NMC_META_GENERIC ("PERMISSION"), /* 0 */ + NMC_META_GENERIC ("VALUE"), /* 1 */ + NULL, }; #define NMC_FIELDS_NM_PERMISSIONS_ALL "PERMISSION,VALUE" #define NMC_FIELDS_NM_PERMISSIONS_COMMON "PERMISSION,VALUE" /* Available fields for 'general logging' */ -static NmcOutputField nmc_fields_nm_logging[] = { - OUTPUT_FIELD_WITH_NAME ("LEVEL"), /* 0 */ - OUTPUT_FIELD_WITH_NAME ("DOMAINS"), /* 1 */ - { 0 } +static const NmcMetaGenericInfo *const nmc_fields_nm_logging[] = { + NMC_META_GENERIC ("LEVEL"), /* 0 */ + NMC_META_GENERIC ("DOMAINS"), /* 1 */ + NULL, }; #define NMC_FIELDS_NM_LOGGING_ALL "LEVEL,DOMAINS" #define NMC_FIELDS_NM_LOGGING_COMMON "LEVEL,DOMAINS" @@ -256,23 +254,23 @@ nm_state_to_string (NMState state) } } -static NmcTermColor +static NMMetaTermColor state_to_color (NMState state) { switch (state) { case NM_STATE_CONNECTING: - return NMC_TERM_COLOR_YELLOW; + return NM_META_TERM_COLOR_YELLOW; case NM_STATE_CONNECTED_LOCAL: case NM_STATE_CONNECTED_SITE: case NM_STATE_CONNECTED_GLOBAL: - return NMC_TERM_COLOR_GREEN; + return NM_META_TERM_COLOR_GREEN; case NM_STATE_DISCONNECTING: - return NMC_TERM_COLOR_YELLOW; + return NM_META_TERM_COLOR_YELLOW; case NM_STATE_ASLEEP: case NM_STATE_DISCONNECTED: - return NMC_TERM_COLOR_RED; + return NM_META_TERM_COLOR_RED; default: - return NMC_TERM_COLOR_NORMAL; + return NM_META_TERM_COLOR_NORMAL; } } @@ -294,19 +292,19 @@ nm_connectivity_to_string (NMConnectivityState connectivity) } } -static NmcTermColor +static NMMetaTermColor connectivity_to_color (NMConnectivityState connectivity) { switch (connectivity) { case NM_CONNECTIVITY_NONE: - return NMC_TERM_COLOR_RED; + return NM_META_TERM_COLOR_RED; case NM_CONNECTIVITY_PORTAL: case NM_CONNECTIVITY_LIMITED: - return NMC_TERM_COLOR_YELLOW; + return NM_META_TERM_COLOR_YELLOW; case NM_CONNECTIVITY_FULL: - return NMC_TERM_COLOR_GREEN; + return NM_META_TERM_COLOR_GREEN; default: - return NMC_TERM_COLOR_NORMAL; + return NM_META_TERM_COLOR_NORMAL; } } @@ -323,8 +321,8 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl 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; - NmcOutputField *tmpl, *arr; - size_t tmpl_len; + const NMMetaAbstractInfo *const*tmpl; + NmcOutputField *arr; NMC_OUTPUT_DATA_DEFINE_SCOPED (out); if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0) @@ -334,9 +332,8 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl else fields_str = nmc->required_fields; - tmpl = nmc_fields_nm_status; - tmpl_len = sizeof (nmc_fields_nm_status); - out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_nm_status; + out_indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); if (error) { g_string_printf (nmc->return_text, _("Error: only these fields are allowed: %s"), fields_all); @@ -354,11 +351,10 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl wwan_hw_enabled = nm_client_wwan_hardware_get_enabled (nmc->client); wwan_enabled = nm_client_wwan_get_enabled (nmc->client); - out.print_fields.header_name = pretty_header_name ? (char *) pretty_header_name : _("NetworkManager status"); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); + 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, tmpl_len, 0); + 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)); @@ -372,18 +368,20 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl /* Set colors */ arr[2].color = state_to_color (state); - arr[3].color = startup ? NMC_TERM_COLOR_YELLOW : NMC_TERM_COLOR_GREEN; + 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 ? NMC_TERM_COLOR_GREEN : NMC_TERM_COLOR_RED; - arr[6].color = wireless_hw_enabled ? NMC_TERM_COLOR_GREEN : NMC_TERM_COLOR_RED; - arr[7].color = wireless_enabled ? NMC_TERM_COLOR_GREEN : NMC_TERM_COLOR_RED; - arr[8].color = wwan_hw_enabled ? NMC_TERM_COLOR_GREEN : NMC_TERM_COLOR_RED; - arr[9].color = wwan_enabled ? NMC_TERM_COLOR_GREEN : NMC_TERM_COLOR_RED; + 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); + print_data (&nmc->nmc_config, out_indices, + pretty_header_name ?: _("NetworkManager status"), + 0, &out); return TRUE; } @@ -473,8 +471,8 @@ print_permissions (void *user_data) const char *fields_str; const char *fields_all = NMC_FIELDS_NM_PERMISSIONS_ALL; const char *fields_common = NMC_FIELDS_NM_PERMISSIONS_COMMON; - NmcOutputField *tmpl, *arr; - size_t tmpl_len; + const NMMetaAbstractInfo *const*tmpl; + NmcOutputField *arr; NMC_OUTPUT_DATA_DEFINE_SCOPED (out); if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0) @@ -484,9 +482,8 @@ print_permissions (void *user_data) else fields_str = nmc->required_fields; - tmpl = nmc_fields_nm_permissions; - tmpl_len = sizeof (nmc_fields_nm_permissions); - out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_nm_permissions; + out_indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); if (error) { g_string_printf (nmc->return_text, _("Error: 'general permissions': %s"), error->message); @@ -495,21 +492,23 @@ print_permissions (void *user_data) return FALSE; } - out.print_fields.header_name = _("NetworkManager permissions"); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); + 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, tmpl_len, 0); + 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); + print_data (&nmc->nmc_config, + out_indices, + _("NetworkManager permissions"), + 0, &out); quit (); return G_SOURCE_REMOVE; @@ -585,8 +584,8 @@ show_general_logging (NmCli *nmc) const char *fields_str; const char *fields_all = NMC_FIELDS_NM_LOGGING_ALL; const char *fields_common = NMC_FIELDS_NM_LOGGING_COMMON; - NmcOutputField *tmpl, *arr; - size_t tmpl_len; + const NMMetaAbstractInfo *const*tmpl; + NmcOutputField *arr; NMC_OUTPUT_DATA_DEFINE_SCOPED (out); if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0) @@ -596,9 +595,8 @@ show_general_logging (NmCli *nmc) else fields_str = nmc->required_fields; - tmpl = nmc_fields_nm_logging; - tmpl_len = sizeof (nmc_fields_nm_logging); - out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_nm_logging; + out_indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); if (error) { g_string_printf (nmc->return_text, _("Error: 'general logging': %s"), error->message); @@ -615,17 +613,18 @@ show_general_logging (NmCli *nmc) return FALSE; } - out.print_fields.header_name = _("NetworkManager logging"); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); + 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, tmpl_len, 0); + 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); + print_data (&nmc->nmc_config, out_indices, + _("NetworkManager logging"), + 0, &out); return TRUE; } @@ -1034,8 +1033,8 @@ networkmanager_running (NMClient *client, GParamSpec *param, NmCli *nmc) running = nm_client_get_nm_running (client); str = nmc_colorize (nmc->nmc_config.use_colors, - running ? NMC_TERM_COLOR_GREEN : NMC_TERM_COLOR_RED, - NMC_TERM_FORMAT_NORMAL, + running ? NM_META_TERM_COLOR_GREEN : NM_META_TERM_COLOR_RED, + NM_META_TERM_FORMAT_NORMAL, running ? _("NetworkManager has started") : _("NetworkManager has stopped")); g_print ("%s\n", str); g_free (str); @@ -1075,7 +1074,7 @@ client_connectivity (NMClient *client, GParamSpec *param, NmCli *nmc) char *str; g_object_get (client, NM_CLIENT_CONNECTIVITY, &connectivity, NULL); - str = nmc_colorize (nmc->nmc_config.use_colors, connectivity_to_color (connectivity), NMC_TERM_FORMAT_NORMAL, + str = nmc_colorize (nmc->nmc_config.use_colors, connectivity_to_color (connectivity), NM_META_TERM_FORMAT_NORMAL, _("Connectivity is now '%s'\n"), nm_connectivity_to_string (connectivity)); g_print ("%s", str); g_free (str); @@ -1088,7 +1087,7 @@ client_state (NMClient *client, GParamSpec *param, NmCli *nmc) char *str; g_object_get (client, NM_CLIENT_STATE, &state, NULL); - str = nmc_colorize (nmc->nmc_config.use_colors, state_to_color (state), NMC_TERM_FORMAT_NORMAL, + str = nmc_colorize (nmc->nmc_config.use_colors, state_to_color (state), NM_META_TERM_FORMAT_NORMAL, _("Networkmanager is now in the '%s' state\n"), nm_state_to_string (state)); g_print ("%s", str); @@ -1132,12 +1131,12 @@ device_overview (NmCli *nmc, NMDevice *device) if (!nm_device_get_autoconnect (device)) g_string_append_printf (outbuf, "%s, ", _("autoconnect")); if (nm_device_get_firmware_missing (device)) { - tmp = nmc_colorize (nmc->nmc_config.use_colors, NMC_TERM_COLOR_RED, NMC_TERM_FORMAT_NORMAL, _("fw missing")); + tmp = nmc_colorize (nmc->nmc_config.use_colors, NM_META_TERM_COLOR_RED, NM_META_TERM_FORMAT_NORMAL, _("fw missing")); g_string_append_printf (outbuf, "%s, ", tmp); g_free (tmp); } if (nm_device_get_nm_plugin_missing (device)) { - tmp = nmc_colorize (nmc->nmc_config.use_colors, NMC_TERM_COLOR_RED, NMC_TERM_FORMAT_NORMAL, _("plugin missing")); + tmp = nmc_colorize (nmc->nmc_config.use_colors, NM_META_TERM_COLOR_RED, NM_META_TERM_FORMAT_NORMAL, _("plugin missing")); g_string_append_printf (outbuf, "%s, ", tmp); g_free (tmp); } @@ -1238,7 +1237,7 @@ do_overview (NmCli *nmc, int argc, char **argv) NMDevice **devices; const GPtrArray *p; NMActiveConnection *ac; - NmcTermColor color; + NMMetaTermColor color; NMDnsEntry *dns; char *tmp; int i; @@ -1260,7 +1259,7 @@ do_overview (NmCli *nmc, int argc, char **argv) state = nm_active_connection_get_state (ac); nmc_active_connection_state_to_color (state, &color); - tmp = nmc_colorize (nmc->nmc_config.use_colors, color, NMC_TERM_FORMAT_NORMAL, _("%s VPN connection"), + tmp = nmc_colorize (nmc->nmc_config.use_colors, color, NM_META_TERM_FORMAT_NORMAL, _("%s VPN connection"), nm_active_connection_get_id (ac)); g_print ("%s\n", tmp); g_free (tmp); @@ -1271,7 +1270,7 @@ do_overview (NmCli *nmc, int argc, char **argv) devices = nmc_get_devices_sorted (nmc->client); for (i = 0; devices[i]; i++) { - NmcTermFormat color_fmt; + NMMetaTermFormat color_fmt; NMDeviceState state; ac = nm_device_get_active_connection (devices[i]); @@ -1362,7 +1361,7 @@ do_monitor (NmCli *nmc, int argc, char **argv) if (!nm_client_get_nm_running (nmc->client)) { char *str; - str = nmc_colorize (nmc->nmc_config.use_colors, NMC_TERM_COLOR_RED, NMC_TERM_FORMAT_NORMAL, + str = nmc_colorize (nmc->nmc_config.use_colors, NM_META_TERM_COLOR_RED, NM_META_TERM_FORMAT_NORMAL, _("Networkmanager is not running (waiting for it)\n")); g_print ("%s", str); g_free (str); diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c index 3c01828a71..dcb86fe1dc 100644 --- a/clients/cli/nmcli.c +++ b/clients/cli/nmcli.c @@ -21,6 +21,8 @@ #include "nm-default.h" +#include "nmcli.h" + #include #include #include @@ -35,7 +37,6 @@ #include "nm-client-utils.h" #include "polkit-agent.h" -#include "nmcli.h" #include "utils.h" #include "common.h" #include "connections.h" @@ -51,10 +52,10 @@ #endif /* Global NmCli object */ -// FIXME: Currently, we pass NmCli over in most APIs, but we might refactor -// that and use the global variable directly instead. NmCli nm_cli; +/*****************************************************************************/ + typedef struct { NmCli *nmc; int argc; @@ -83,16 +84,12 @@ complete_field_setting (GHashTable *h, NMMetaSettingType setting_type) } static void -complete_field (GHashTable *h, const char *setting, const NmcOutputField *field) +complete_field (GHashTable *h, const NmcMetaGenericInfo *const*field) { int i; - for (i = 0; field[i].name; i++) { - if (setting) - g_hash_table_add (h, g_strdup_printf ("%s.%s", setting, field[i].name)); - else - g_hash_table_add (h, g_strdup (field[i].name)); - } + for (i = 0; field[i]; i++) + g_hash_table_add (h, g_strdup (field[i]->name)); } static void @@ -122,30 +119,29 @@ complete_fields (const char *prefix) h = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - complete_field (h, NULL, nmc_fields_ip4_config); - complete_field (h, NULL, nmc_fields_dhcp4_config); - complete_field (h, NULL, nmc_fields_ip6_config); - complete_field (h, NULL, nmc_fields_dhcp6_config); - complete_field (h, NULL, nmc_fields_con_show); - complete_field (h, NULL, nmc_fields_settings_names); - complete_field (h, NULL, nmc_fields_con_active_details_general); - complete_field (h, NULL, nmc_fields_con_active_details_vpn); - complete_field (h, NULL, nmc_fields_con_active_details_groups); - complete_field (h, NULL, nmc_fields_dev_status); - complete_field (h, NULL, nmc_fields_dev_show_general); - complete_field (h, NULL, nmc_fields_dev_show_connections); - complete_field (h, NULL, nmc_fields_dev_show_cap); - complete_field (h, NULL, nmc_fields_dev_show_wired_prop); - complete_field (h, NULL, nmc_fields_dev_show_wifi_prop); - complete_field (h, NULL, nmc_fields_dev_show_wimax_prop); - complete_field (h, NULL, nmc_fields_dev_wifi_list); - complete_field (h, NULL, nmc_fields_dev_wimax_list); - complete_field (h, NULL, nmc_fields_dev_show_master_prop); - complete_field (h, NULL, nmc_fields_dev_show_team_prop); - complete_field (h, NULL, nmc_fields_dev_show_vlan_prop); - complete_field (h, NULL, nmc_fields_dev_show_bluetooth); - complete_field (h, NULL, nmc_fields_dev_show_sections); - complete_field (h, NULL, nmc_fields_dev_lldp_list); + complete_field (h, nmc_fields_ip4_config); + complete_field (h, nmc_fields_dhcp4_config); + complete_field (h, nmc_fields_ip6_config); + complete_field (h, nmc_fields_dhcp6_config); + complete_field (h, nmc_fields_con_show); + complete_field (h, nmc_fields_con_active_details_general); + complete_field (h, nmc_fields_con_active_details_vpn); + complete_field (h, nmc_fields_con_active_details_groups); + complete_field (h, nmc_fields_dev_status); + complete_field (h, nmc_fields_dev_show_general); + complete_field (h, nmc_fields_dev_show_connections); + complete_field (h, nmc_fields_dev_show_cap); + complete_field (h, nmc_fields_dev_show_wired_prop); + complete_field (h, nmc_fields_dev_show_wifi_prop); + complete_field (h, nmc_fields_dev_show_wimax_prop); + complete_field (h, nmc_fields_dev_wifi_list); + complete_field (h, nmc_fields_dev_wimax_list); + complete_field (h, nmc_fields_dev_show_master_prop); + complete_field (h, nmc_fields_dev_show_team_prop); + complete_field (h, nmc_fields_dev_show_vlan_prop); + complete_field (h, nmc_fields_dev_show_bluetooth); + complete_field (h, nmc_fields_dev_show_sections); + complete_field (h, nmc_fields_dev_lldp_list); for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) complete_field_setting (h, i); @@ -548,7 +544,7 @@ nmc_init (NmCli *nmc) nmc->editor_status_line = FALSE; nmc->editor_save_confirmation = TRUE; nmc->editor_show_secrets = FALSE; - nmc->editor_prompt_color = NMC_TERM_COLOR_NORMAL; + nmc->editor_prompt_color = NM_META_TERM_COLOR_NORMAL; } static void diff --git a/clients/cli/nmcli.h b/clients/cli/nmcli.h index 1b9c3e72e1..c3949b5f68 100644 --- a/clients/cli/nmcli.h +++ b/clients/cli/nmcli.h @@ -23,6 +23,8 @@ #include "NetworkManager.h" #include "nm-secret-agent-old.h" +#include "nm-meta-setting-desc.h" + #if WITH_POLKIT_AGENT #include "nm-polkit-listener.h" #else @@ -69,28 +71,6 @@ typedef enum { NMC_RESULT_COMPLETE_FILE = 65, } NMCResultCode; -typedef enum { - NMC_TERM_COLOR_NORMAL = 0, - NMC_TERM_COLOR_BLACK = 1, - NMC_TERM_COLOR_RED = 2, - NMC_TERM_COLOR_GREEN = 3, - NMC_TERM_COLOR_YELLOW = 4, - NMC_TERM_COLOR_BLUE = 5, - NMC_TERM_COLOR_MAGENTA = 6, - NMC_TERM_COLOR_CYAN = 7, - NMC_TERM_COLOR_WHITE = 8 -} NmcTermColor; - -typedef enum { - NMC_TERM_FORMAT_NORMAL, - NMC_TERM_FORMAT_BOLD, - NMC_TERM_FORMAT_DIM, - NMC_TERM_FORMAT_UNDERLINE, - NMC_TERM_FORMAT_BLINK, - NMC_TERM_FORMAT_REVERSE, - NMC_TERM_FORMAT_HIDDEN, -} NmcTermFormat; - typedef enum { NMC_PRINT_TERSE = 0, NMC_PRINT_NORMAL = 1, @@ -98,39 +78,29 @@ typedef enum { } NMCPrintOutput; /* === Output fields === */ -/* Flags for NmcOutputField */ -#define NMC_OF_FLAG_FIELD_NAMES 0x00000001 /* Print field names instead of values */ -#define NMC_OF_FLAG_SECTION_PREFIX 0x00000002 /* Use the first value as section prefix for the other field names - just in multiline */ -#define NMC_OF_FLAG_MAIN_HEADER_ADD 0x00000004 /* Print main header in addition to values/field names */ -#define NMC_OF_FLAG_MAIN_HEADER_ONLY 0x00000008 /* Print main header only */ -struct _NMMetaSettingInfoEditor; +typedef enum { + NMC_OF_FLAG_FIELD_NAMES = 0x00000001, /* Print field names instead of values */ + NMC_OF_FLAG_SECTION_PREFIX = 0x00000002, /* Use the first value as section prefix for the other field names - just in multiline */ + NMC_OF_FLAG_MAIN_HEADER_ADD = 0x00000004, /* Print main header in addition to values/field names */ + NMC_OF_FLAG_MAIN_HEADER_ONLY = 0x00000008, /* Print main header only */ +} NmcOfFlags; -typedef struct _NmcOutputField { - const char *name; /* Field's name */ +extern const const NMMetaType nmc_meta_type_generic_info; + +typedef struct _NmcOutputField NmcOutputField; +typedef struct _NmcMetaGenericInfo NmcMetaGenericInfo; + +struct _NmcOutputField { + const NMMetaAbstractInfo *info; int width; /* Width in screen columns */ - const struct _NmcOutputField *group_list; /* Points to an array with available section field names if this is a section (group) field */ void *value; /* Value of current field - char* or char** (NULL-terminated array) */ gboolean value_is_array; /* Whether value is char** instead of char* */ gboolean free_value; /* Whether to free the value */ - guint32 flags; /* Flags - whether and how to print values/field names/headers */ - NmcTermColor color; /* Use this color to print value */ - NmcTermFormat color_fmt; /* Use this terminal format to print value */ - - /* in a very particular case NmcOutputField is used in combination with - * the @group_list above. That list will go away (and the entire NmcOutputField - * should separate formatting-options, setting-metadata and output. - * - * For now, hack around that by alternatively providing a @setting_info instead - * of @group_list. */ - const struct _NMMetaSettingInfoEditor *setting_info; -} NmcOutputField; - -typedef struct { - GArray *indices; /* Array of field indices to the array of allowed fields */ - char *header_name; /* Name of the output */ - int indent; /* Indent by this number of spaces */ -} NmcPrintFields; + NmcOfFlags flags; /* Flags - whether and how to print values/field names/headers */ + NMMetaTermColor color; /* Use this color to print value */ + NMMetaTermFormat color_fmt; /* Use this terminal format to print value */ +}; typedef enum { NMC_USE_COLOR_AUTO, @@ -148,7 +118,6 @@ typedef struct _NmcConfig { typedef struct _NmcOutputData { GPtrArray *output_data; /* GPtrArray of arrays of NmcOutputField structs - accumulates data for output */ - NmcPrintFields print_fields; /* Structure with field indices to print */ } NmcOutputData; /* NmCli - main structure */ @@ -178,7 +147,7 @@ typedef struct _NmCli { 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' */ - NmcTermColor editor_prompt_color; /* Color of prompt in connection editor */ + NMMetaTermColor editor_prompt_color; /* Color of prompt in connection editor */ } NmCli; extern NmCli nm_cli; @@ -195,6 +164,7 @@ void nmc_exit (void); void nmc_empty_output_fields (NmcOutputData *output_data); #define NMC_OUTPUT_DATA_DEFINE_SCOPED(out) \ + gs_unref_array GArray *out##_indices = NULL; \ nm_auto (nmc_empty_output_fields) NmcOutputData out = { \ .output_data = g_ptr_array_new_full (20, g_free), \ } diff --git a/clients/cli/polkit-agent.c b/clients/cli/polkit-agent.c index 086851de9b..10a84f9cdb 100644 --- a/clients/cli/polkit-agent.c +++ b/clients/cli/polkit-agent.c @@ -21,13 +21,15 @@ #if WITH_POLKIT_AGENT +#include "polkit-agent.h" + #include #include #include #include -#include "polkit-agent.h" #include "nm-polkit-listener.h" + #include "common.h" static char * diff --git a/clients/cli/settings.c b/clients/cli/settings.c index c6d68aefc3..429d93035c 100644 --- a/clients/cli/settings.c +++ b/clients/cli/settings.c @@ -28,169 +28,13 @@ #include "nm-client-utils.h" #include "nm-vpn-helpers.h" +#include "nm-meta-setting-access.h" #include "utils.h" #include "common.h" /*****************************************************************************/ -static const NMMetaSettingInfoEditor * -_meta_find_setting_info_by_name (const char *setting_name) -{ - const NMMetaSettingInfo *meta_setting_info; - const NMMetaSettingInfoEditor *setting_info; - - 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); - - return setting_info; -} - -static const NMMetaSettingInfoEditor * -_meta_find_setting_info_by_gtype (GType gtype) -{ - const NMMetaSettingInfo *meta_setting_info; - const NMMetaSettingInfoEditor *setting_info; - - meta_setting_info = nm_meta_setting_infos_by_gtype (gtype); - - if (!meta_setting_info) - return NULL; - - g_return_val_if_fail (meta_setting_info->get_setting_gtype, NULL); - g_return_val_if_fail (meta_setting_info->get_setting_gtype () == gtype, 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); - - return setting_info; -} - -static const NMMetaSettingInfoEditor * -_meta_find_setting_info_by_setting (NMSetting *setting) -{ - const NMMetaSettingInfoEditor *setting_info; - - g_return_val_if_fail (NM_IS_SETTING (setting), NULL); - - setting_info = _meta_find_setting_info_by_gtype (G_OBJECT_TYPE (setting)); - - if (!setting_info) - return NULL; - - g_return_val_if_fail (setting_info == _meta_find_setting_info_by_name (nm_setting_get_name (setting)), NULL); - - return setting_info; -} - -static const NMMetaPropertyInfo * -_meta_setting_info_find_property_info (const NMMetaSettingInfoEditor *setting_info, const char *property_name) -{ - guint i; - - g_return_val_if_fail (setting_info, NULL); - g_return_val_if_fail (property_name, NULL); - - for (i = 0; i < setting_info->properties_num; i++) { - if (nm_streq (setting_info->properties[i].property_name, property_name)) - return &setting_info->properties[i]; - } - - return NULL; -} - -static const NMMetaPropertyInfo * -_meta_find_property_info_by_name (const char *setting_name, const char *property_name, const NMMetaSettingInfoEditor **out_setting_info) -{ - const NMMetaSettingInfoEditor *setting_info; - - setting_info = _meta_find_setting_info_by_name (setting_name); - - NM_SET_OUT (out_setting_info, setting_info); - if (!setting_info) - return NULL; - return _meta_setting_info_find_property_info (setting_info, property_name); -} - -static const NMMetaPropertyInfo * -_meta_find_property_info_by_setting (NMSetting *setting, const char *property_name, const NMMetaSettingInfoEditor **out_setting_info) -{ - const NMMetaSettingInfoEditor *setting_info; - const NMMetaPropertyInfo *property_info; - - setting_info = _meta_find_setting_info_by_setting (setting); - - NM_SET_OUT (out_setting_info, setting_info); - if (!setting_info) - return NULL; - property_info = _meta_setting_info_find_property_info (setting_info, property_name); - - nm_assert (property_info == _meta_find_property_info_by_name (nm_setting_get_name (setting), property_name, NULL)); - - return property_info; -} - -/*****************************************************************************/ - -static const NmcOutputField * -_get_nmc_output_fields (const NMMetaSettingInfoEditor *setting_info) -{ - static NmcOutputField *fields[_NM_META_SETTING_TYPE_NUM + 1] = { }; - NmcOutputField **field; - guint i; - - g_return_val_if_fail (setting_info, NULL); - g_return_val_if_fail (setting_info->general->meta_type < _NM_META_SETTING_TYPE_NUM, NULL); - - field = &fields[setting_info->general->meta_type]; - - if (G_UNLIKELY (!*field)) { - *field = g_new0 (NmcOutputField, setting_info->properties_num + 1); - for (i = 0; i < setting_info->properties_num; i++) { - NmcOutputField *f = &(*field)[i]; - - f->name = setting_info->properties[i].property_name; - } - } - - return *field; -} - -/*****************************************************************************/ - -NMSetting * -nmc_setting_new_for_name (const char *name) -{ - GType stype; - NMSetting *setting = NULL; - - if (name) { - stype = nm_setting_lookup_type (name); - if (stype != G_TYPE_INVALID) { - setting = g_object_new (stype, NULL); - g_warn_if_fail (NM_IS_SETTING (setting)); - } - } - return setting; -} - static gboolean get_answer (const char *prop, const char *value) { @@ -530,25 +374,113 @@ nmc_setting_custom_init (NMSetting *setting) /*****************************************************************************/ +static gboolean +_set_fcn_precheck_connection_secondaries (const char *value, + char **value_coerced, + GError **error) +{ + const GPtrArray *connections; + NMConnection *con; + gs_strfreev char **strv = NULL; + char **iter; + gboolean modified; + + strv = nmc_strsplit_set (value, " \t,", 0); + if (!strv) + return TRUE; + + connections = nm_client_get_connections (nm_cli.client); + + for (iter = strv; *iter; iter++) { + if (nm_utils_is_uuid (*iter)) { + con = nmc_find_connection (connections, "uuid", *iter, NULL, FALSE); + if (!con){ + g_print (_("Warning: %s is not an UUID of any existing connection profile\n"), + *iter); + } else { + /* Currenly NM only supports VPN connections as secondaries */ + if (!nm_connection_is_type (con, NM_SETTING_VPN_SETTING_NAME)) { + g_set_error (error, 1, 0, _("'%s' is not a VPN connection profile"), *iter); + return FALSE; + } + } + } else { + con = nmc_find_connection (connections, "id", *iter, NULL, FALSE); + if (!con) { + g_set_error (error, 1, 0, _("'%s' is not a name of any exiting profile"), *iter); + return FALSE; + } + + /* Currenly NM only supports VPN connections as secondaries */ + if (!nm_connection_is_type (con, NM_SETTING_VPN_SETTING_NAME)) { + g_set_error (error, 1, 0, _("'%s' is not a VPN connection profile"), *iter); + return FALSE; + } + + /* translate id to uuid */ + g_free (*iter); + *iter = g_strdup (nm_connection_get_uuid (con)); + modified = TRUE; + } + } + + if (modified) + *value_coerced = g_strjoinv (" ", strv); + + return TRUE; +} + +/*****************************************************************************/ + +static void +_env_warn_fcn_handle (const NMMetaEnvironment *environment, + gpointer environment_user_data, + NMMetaEnvWarnLevel warn_level, + const char *fmt_l10n, /* the untranslated format string, but it is marked for translation using N_(). */ + va_list ap) +{ + gs_free char *m = NULL; + + NM_PRAGMA_WARNING_DISABLE("-Wformat-nonliteral") + m = g_strdup_vprintf (_(fmt_l10n), ap); + NM_PRAGMA_WARNING_REENABLE + + switch (warn_level) { + case NM_META_ENV_WARN_LEVEL_WARN: + g_print (_("Warning: %s\n"), m); + return; + case NM_META_ENV_WARN_LEVEL_INFO: + g_print (_("Info: %s\n"), m); + return; + } + g_print (_("Error: %s\n"), m); +} + +/*****************************************************************************/ + +static const NMMetaEnvironment meta_environment = { + .warn_fcn = _env_warn_fcn_handle, +}; + static char * get_property_val (NMSetting *setting, const char *prop, NMMetaAccessorGetType get_type, gboolean show_secrets, GError **error) { - const NMMetaSettingInfoEditor *setting_info; const NMMetaPropertyInfo *property_info; g_return_val_if_fail (NM_IS_SETTING (setting), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - if ((property_info = _meta_find_property_info_by_setting (setting, prop, &setting_info))) { + 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 (setting_info, + return property_info->property_type->get_fcn (&meta_environment, + NULL, property_info, setting, get_type, - show_secrets); + show_secrets ? NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS : 0); } } @@ -579,6 +511,20 @@ nmc_setting_get_property_parsable (NMSetting *setting, const char *prop, GError return get_property_val (setting, prop, NM_META_ACCESSOR_GET_TYPE_PARSABLE, TRUE, error); } +static gboolean +_set_fcn_call (const NMMetaPropertyInfo *property_info, + NMSetting *setting, + const char *value, + GError **error) +{ + return property_info->property_type->set_fcn (&meta_environment, + NULL, + property_info, + setting, + value, + error); +} + /* * Generic function for setting property value. * @@ -590,13 +536,12 @@ nmc_setting_get_property_parsable (NMSetting *setting, const char *prop, GError gboolean nmc_setting_set_property (NMSetting *setting, const char *prop, const char *value, GError **error) { - const NMMetaSettingInfoEditor *setting_info; const NMMetaPropertyInfo *property_info; g_return_val_if_fail (NM_IS_SETTING (setting), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - if ((property_info = _meta_find_property_info_by_setting (setting, prop, &setting_info))) { + if ((property_info = nm_meta_property_info_find_by_setting (setting, prop))) { if (!value) { /* No value argument sets default value */ @@ -608,11 +553,27 @@ nmc_setting_set_property (NMSetting *setting, const char *prop, const char *valu /* 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) { - return property_info->property_type->set_fcn (setting_info, - property_info, - setting, - value, - error); + 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)) { + gs_free char *value_coerced = NULL; + + if (!_set_fcn_precheck_connection_secondaries (value, &value_coerced, error)) + return FALSE; + + return _set_fcn_call (property_info, + setting, + value_coerced ?: value, + error); + } + break; + default: + break; + } + return _set_fcn_call (property_info, + setting, + value, + error); } } @@ -646,13 +607,12 @@ nmc_property_set_default_value (NMSetting *setting, const char *prop) gboolean nmc_setting_reset_property (NMSetting *setting, const char *prop, GError **error) { - const NMMetaSettingInfoEditor *setting_info; const NMMetaPropertyInfo *property_info; g_return_val_if_fail (NM_IS_SETTING (setting), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - if ((property_info = _meta_find_property_info_by_setting (setting, prop, &setting_info))) { + 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(). */ @@ -682,18 +642,18 @@ nmc_setting_remove_property_option (NMSetting *setting, guint32 idx, GError **error) { - const NMMetaSettingInfoEditor *setting_info; const NMMetaPropertyInfo *property_info; g_return_val_if_fail (NM_IS_SETTING (setting), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - if ((property_info = _meta_find_property_info_by_setting (setting, prop, &setting_info))) { + 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 (setting_info, + return property_info->property_type->remove_fcn (&meta_environment, + NULL, property_info, setting, option, @@ -739,8 +699,6 @@ nmc_setting_get_valid_properties (NMSetting *setting) const char *const* nmc_setting_get_property_allowed_values (NMSetting *setting, const char *prop, char ***out_to_free) { - - const NMMetaSettingInfoEditor *setting_info; const NMMetaPropertyInfo *property_info; g_return_val_if_fail (NM_IS_SETTING (setting), FALSE); @@ -748,13 +706,12 @@ nmc_setting_get_property_allowed_values (NMSetting *setting, const char *prop, c *out_to_free = NULL; - if ((property_info = _meta_find_property_info_by_setting (setting, prop, &setting_info))) { + 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) { - return property_info->property_type->values_fcn (setting_info, - property_info, + 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) return property_info->property_typ_data->values_static; @@ -780,12 +737,11 @@ nmc_setting_get_property_desc (NMSetting *setting, const char *prop) const char *nmcli_desc = NULL; const char *nmcli_desc_title = ""; const char *nmcli_nl = ""; - const NMMetaSettingInfoEditor *setting_info; const NMMetaPropertyInfo *property_info; g_return_val_if_fail (NM_IS_SETTING (setting), FALSE); - if ((property_info = _meta_find_property_info_by_setting (setting, prop, &setting_info))) { + if ((property_info = nm_meta_property_info_find_by_setting (setting, prop))) { const char *desc = NULL; if (property_info->describe_doc) { @@ -797,7 +753,7 @@ nmc_setting_get_property_desc (NMSetting *setting, const char *prop) /* 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) { - desc = property_info->property_type->describe_fcn (setting_info, property_info, &desc_to_free); + desc = property_info->property_type->describe_fcn (property_info, &desc_to_free); } else desc = property_info->describe_message; @@ -853,65 +809,58 @@ nmc_property_set_gvalue (NMSetting *setting, const char *prop, GValue *value) /*****************************************************************************/ -static char * -_all_properties (const NMMetaSettingInfoEditor *setting_info) +static NmcOutputField * +_dup_fields_array (const NMMetaSettingInfoEditor *setting_info, NmcOfFlags flags) { - GString *str; - guint i; + NmcOutputField *row; + gsize l; - str = g_string_sized_new (250); - for (i = 0; i < setting_info->properties_num; i++) { - if (str->len) - g_string_append_c (str, ','); - g_string_append (str, setting_info->properties[i].property_name); - } - return g_string_free (str, FALSE); + 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 (NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean show_secrets) +setting_details (const NmcConfig *nmc_config, NMSetting *setting, const char *one_prop, gboolean show_secrets) { - const NMMetaSettingInfo *meta_setting_info; const NMMetaSettingInfoEditor *setting_info; - gs_free NmcOutputField *tmpl = NULL; NmcOutputField *arr; guint i; - size_t tmpl_len; - gs_free char *s_all = NULL; NMMetaAccessorGetType type = NM_META_ACCESSOR_GET_TYPE_PRETTY; NMC_OUTPUT_DATA_DEFINE_SCOPED (out); g_return_val_if_fail (NM_IS_SETTING (setting), FALSE); - meta_setting_info = nm_meta_setting_infos_by_gtype (G_OBJECT_TYPE (setting)); - g_return_val_if_fail (meta_setting_info, FALSE); + setting_info = nm_meta_setting_info_editor_find_by_setting (setting); + if (!setting_info) + return FALSE; - setting_info = &nm_meta_setting_infos_editor[meta_setting_info->meta_type]; - g_return_val_if_fail (setting_info, FALSE); - - g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (setting, setting_info->general->get_setting_gtype ()), FALSE); - - if (nmc->nmc_config.print_output == NMC_PRINT_TERSE) + if (nmc_config->print_output == NMC_PRINT_TERSE) type = NM_META_ACCESSOR_GET_TYPE_PARSABLE; - tmpl_len = sizeof (NmcOutputField) * (setting_info->properties_num + 1); - tmpl = g_memdup (_get_nmc_output_fields (setting_info), tmpl_len); - - out.print_fields.indices = parse_output_fields (one_prop ?: (s_all = _all_properties (setting_info)), - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); + 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 = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); + 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 (setting_info, + set_val_str (arr, i, property_info->property_type->get_fcn (&meta_environment, + NULL, property_info, setting, type, - show_secrets)); + show_secrets ? NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS : 0)); } else set_val_str (arr, i, g_strdup (_(NM_META_TEXT_HIDDEN))); } @@ -919,7 +868,7 @@ setting_details (NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean g_ptr_array_add (out.output_data, arr); print_data_prepare_width (out.output_data); - print_data (&nmc->nmc_config, &out); + print_data (nmc_config, out_indices, NULL, 0, &out); return TRUE; } diff --git a/clients/cli/settings.h b/clients/cli/settings.h index 7b99f8598d..2a90753057 100644 --- a/clients/cli/settings.h +++ b/clients/cli/settings.h @@ -24,11 +24,9 @@ #include "nm-meta-setting-desc.h" #include "nmcli.h" -#include "utils.h" /*****************************************************************************/ -NMSetting *nmc_setting_new_for_name (const char *name); void nmc_setting_custom_init (NMSetting *setting); void nmc_setting_ip4_connect_handlers (NMSettingIPConfig *setting); void nmc_setting_ip6_connect_handlers (NMSettingIPConfig *setting); @@ -62,6 +60,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 (NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean secrets); +gboolean setting_details (const NmcConfig *nmc_config, NMSetting *setting, const char *one_prop, gboolean secrets); #endif /* NMC_SETTINGS_H */ diff --git a/clients/cli/utils.c b/clients/cli/utils.c index e197e9a66d..f67df6a3fd 100644 --- a/clients/cli/utils.c +++ b/clients/cli/utils.c @@ -19,6 +19,8 @@ #include "nm-default.h" +#include "utils.h" + #include #include #include @@ -28,11 +30,71 @@ #include #include "nm-client-utils.h" +#include "nm-meta-setting-access.h" -#include "utils.h" #include "common.h" #include "settings.h" +/*****************************************************************************/ + +static const char * +_meta_type_nmc_generic_info_get_name (const NMMetaAbstractInfo *abstract_info) +{ + return ((const NmcMetaGenericInfo *) abstract_info)->name; +} + +static const NMMetaAbstractInfo *const* +_meta_type_nmc_generic_info_get_nested (const NMMetaAbstractInfo *abstract_info, + guint *out_len, + gpointer *out_to_free) +{ + const NmcMetaGenericInfo *info; + guint n; + + info = (const NmcMetaGenericInfo *) abstract_info; + + if (out_len) { + n = 0; + if (info->nested) { + for (; info->nested[n]; n++) { + } + } + *out_len = n; + } + *out_to_free = NULL; + return (const NMMetaAbstractInfo *const*) info->nested; +} + +static gconstpointer +_meta_type_nmc_generic_info_get_fcn (const NMMetaEnvironment *environment, + gpointer environment_user_data, + const NMMetaAbstractInfo *abstract_info, + gpointer target, + NMMetaAccessorGetType get_type, + NMMetaAccessorGetFlags get_flags, + gpointer *out_to_free) +{ + const NmcMetaGenericInfo *info = (const NmcMetaGenericInfo *) abstract_info; + + nm_assert (out_to_free && !*out_to_free); + + if (!info->get_fcn) + g_return_val_if_reached (NULL); + return info->get_fcn (environment, environment_user_data, + info, target, + get_type, get_flags, + out_to_free); +} + +const NMMetaType nmc_meta_type_generic_info = { + .type_name = "nmc-generic-info", + .get_name = _meta_type_nmc_generic_info_get_name, + .get_nested = _meta_type_nmc_generic_info_get_nested, + .get_fcn = _meta_type_nmc_generic_info_get_fcn, +}; + +/*****************************************************************************/ + static gboolean parse_global_arg (NmCli *nmc, const char *arg) { @@ -273,31 +335,31 @@ nmc_terminal_show_progress (const char *str) } const char * -nmc_term_color_sequence (NmcTermColor color) +nmc_term_color_sequence (NMMetaTermColor color) { switch (color) { - case NMC_TERM_COLOR_BLACK: + case NM_META_TERM_COLOR_BLACK: return "\33[30m"; break; - case NMC_TERM_COLOR_RED: + case NM_META_TERM_COLOR_RED: return "\33[31m"; break; - case NMC_TERM_COLOR_GREEN: + case NM_META_TERM_COLOR_GREEN: return "\33[32m"; break; - case NMC_TERM_COLOR_YELLOW: + case NM_META_TERM_COLOR_YELLOW: return "\33[33m"; break; - case NMC_TERM_COLOR_BLUE: + case NM_META_TERM_COLOR_BLUE: return "\33[34m"; break; - case NMC_TERM_COLOR_MAGENTA: + case NM_META_TERM_COLOR_MAGENTA: return "\33[35m"; break; - case NMC_TERM_COLOR_CYAN: + case NM_META_TERM_COLOR_CYAN: return "\33[36m"; break; - case NMC_TERM_COLOR_WHITE: + case NM_META_TERM_COLOR_WHITE: return "\33[37m"; break; default: @@ -307,7 +369,7 @@ nmc_term_color_sequence (NmcTermColor color) } /* Parses @str for color as string or number */ -NmcTermColor +NMMetaTermColor nmc_term_color_parse_string (const char *str, GError **error) { unsigned long color_int; @@ -315,7 +377,7 @@ nmc_term_color_parse_string (const char *str, GError **error) "blue", "magenta", "cyan", "white", NULL }; if (nmc_string_to_uint (str, TRUE, 0, 8, &color_int)) { - return (NmcTermColor) color_int; + return (NMMetaTermColor) color_int; } else { const char *color, **p; int i; @@ -323,32 +385,32 @@ nmc_term_color_parse_string (const char *str, GError **error) color = nmc_string_is_valid (str, colors, error); for (p = colors, i = 0; *p != NULL; p++, i++) { if (*p == color) - return (NmcTermColor) i; + return (NMMetaTermColor) i; } return -1; } } const char * -nmc_term_format_sequence (NmcTermFormat format) +nmc_term_format_sequence (NMMetaTermFormat format) { switch (format) { - case NMC_TERM_FORMAT_BOLD: + case NM_META_TERM_FORMAT_BOLD: return "\33[1m"; break; - case NMC_TERM_FORMAT_DIM: + case NM_META_TERM_FORMAT_DIM: return "\33[2m"; break; - case NMC_TERM_FORMAT_UNDERLINE: + case NM_META_TERM_FORMAT_UNDERLINE: return "\33[4m"; break; - case NMC_TERM_FORMAT_BLINK: + case NM_META_TERM_FORMAT_BLINK: return "\33[5m"; break; - case NMC_TERM_FORMAT_REVERSE: + case NM_META_TERM_FORMAT_REVERSE: return "\33[7m"; break; - case NMC_TERM_FORMAT_HIDDEN: + case NM_META_TERM_FORMAT_HIDDEN: return "\33[8m"; break; default: @@ -377,7 +439,7 @@ use_colors (NmcColorOption color_option) } char * -nmc_colorize (NmcColorOption color_option, NmcTermColor color, NmcTermFormat format, const char *fmt, ...) +nmc_colorize (NmcColorOption color_option, NMMetaTermColor color, NMMetaTermFormat format, const char *fmt, ...) { va_list args; char *str, *colored; @@ -609,21 +671,21 @@ set_val_arrc (NmcOutputField fields_array[], guint32 idx, const char **value) } void -set_val_color_all (NmcOutputField fields_array[], NmcTermColor color) +set_val_color_all (NmcOutputField fields_array[], NMMetaTermColor color) { int i; - for (i = 0; fields_array[i].name; i++) { + for (i = 0; fields_array[i].info; i++) { fields_array[i].color = color; } } void -set_val_color_fmt_all (NmcOutputField fields_array[], NmcTermFormat format) +set_val_color_fmt_all (NmcOutputField fields_array[], NMMetaTermFormat format) { int i; - for (i = 0; fields_array[i].name; i++) { + for (i = 0; fields_array[i].info; i++) { fields_array[i].color_fmt = format; } } @@ -636,7 +698,7 @@ nmc_free_output_field_values (NmcOutputField fields_array[]) { NmcOutputField *iter = fields_array; - while (iter && iter->name) { + while (iter && iter->info) { if (iter->free_value) { if (iter->value_is_array) g_strfreev ((char **) iter->value); @@ -648,6 +710,159 @@ nmc_free_output_field_values (NmcOutputField fields_array[]) } } +typedef struct { + guint idx; + gsize offset_plus_1; +} OutputSelectionItem; + +NmcOutputSelection * +nmc_output_selection_create (const NMMetaAbstractInfo *const* fields_array, + const char *fields_str, + GError **error) +{ + gs_unref_array GArray *array = NULL; + nm_auto_free_gstring GString *str = NULL; + guint i, j; + NmcOutputSelection *result; + + g_return_val_if_fail (!error || !*error, NULL); + + array = g_array_new (FALSE, FALSE, sizeof (OutputSelectionItem)); + + if (!fields_str) { + for (i = 0; fields_array[i]; i++) { + OutputSelectionItem s = { + .idx = i, + }; + + g_array_append_val (array, s); + } + } else { + gs_free char *fields_str_clone = NULL; + char *fields_str_cur; + char *fields_str_next; + + fields_str_clone = g_strdup (fields_str); + for (fields_str_cur = fields_str_clone; fields_str_cur; fields_str_cur = fields_str_next) { + const char *i_name; + const char *right = NULL; + gboolean found = FALSE; + const NMMetaAbstractInfo *fields_array_failure = NULL; + + fields_str_cur = nm_str_skip_leading_spaces (fields_str_cur); + fields_str_next = strchr (fields_str_cur, ','); + if (fields_str_next) + *fields_str_next++ = '\0'; + + g_strchomp (fields_str_cur); + if (!fields_str_cur[0]) + continue; + + i_name = fields_str_cur; + fields_str_cur = strchr (fields_str_cur, '.'); + if (fields_str_cur) { + right = fields_str_cur + 1; + *fields_str_cur = '\0'; + } + + 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) + continue; + + if (!right) + found = TRUE; + else { + found = FALSE; + if (fi->meta_type == &nm_meta_type_setting_info_editor) { + const NMMetaSettingInfoEditor *fi_s = &fi->as.setting_info; + + for (j = 1; j < fi_s->properties_num; j++) { + if (g_ascii_strcasecmp (right, fi_s->properties[j].property_name) == 0) { + found = TRUE; + break; + } + } + } else if (fi->meta_type == &nmc_meta_type_generic_info) { + 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) { + found = TRUE; + break; + } + } + } + } + + if (found) { + OutputSelectionItem s = { + .idx = i, + }; + + if (right) { + if (!str) + str = g_string_sized_new (32); + + s.offset_plus_1 = str->len + 1; + g_string_append_len (str, right, strlen (right) + 1); + } + + g_array_append_val (array, s); + } + + fields_array_failure = fields_array[i]; + break; + } + + if (!found) { + if ( !right + && ( !g_ascii_strcasecmp (i_name, "all") + || !g_ascii_strcasecmp (i_name, "common"))) + g_set_error (error, NMCLI_ERROR, 0, _("field '%s' has to be alone"), i_name); + else { + gs_free char *allowed_fields = NULL; + + if (fields_array_failure) + allowed_fields = nmc_get_allowed_fields_nested (fields_array_failure); + else + allowed_fields = nmc_get_allowed_fields (fields_array); + + g_set_error (error, NMCLI_ERROR, 1, _("invalid field '%s%s%s'; allowed fields: %s"), + i_name, right ? "." : "", right ?: "", allowed_fields); + } + + return NULL; + } + } + } + + /* re-organize the collected output data in one buffer that can be freed using + * g_free(). This makes allocation more complicated, but saves us from special + * handling for free. */ + result = g_malloc0 (sizeof (NmcOutputSelection) + (array->len * sizeof (NmcOutputSelectionItem)) + (str ? str->len : 0)); + *((guint *) &result->num) = array->len; + if (array->len > 0) { + char *pdata = &((char *) result)[sizeof (NmcOutputSelection) + (array->len * sizeof (NmcOutputSelectionItem))]; + + if (str) + memcpy (pdata, str->str, str->len); + for (i = 0; i < array->len; i++) { + const OutputSelectionItem *a = &g_array_index (array, OutputSelectionItem, i); + NmcOutputSelectionItem *p = (NmcOutputSelectionItem *) &result->items[i]; + + p->info = fields_array[a->idx]; + p->idx = a->idx; + if (a->offset_plus_1 > 0) + p->sub_selection = &pdata[a->offset_plus_1 - 1]; + } + } + + return result; +} + + /** * parse_output_fields: * @field_str: comma-separated field names to parse @@ -670,159 +885,91 @@ nmc_free_output_field_values (NmcOutputField fields_array[]) */ GArray * parse_output_fields (const char *fields_str, - const NmcOutputField fields_array[], + const NMMetaAbstractInfo *const*fields_array, gboolean parse_groups, - GPtrArray **group_fields, + GPtrArray **out_group_fields, GError **error) { - char **fields, **iter; + gs_free NmcOutputSelection *selection = NULL; GArray *array; - int i, j; + GPtrArray *group_fields = NULL; + guint i; - g_return_val_if_fail (error == NULL || *error == NULL, NULL); - g_return_val_if_fail (group_fields == NULL || *group_fields == NULL, NULL); + g_return_val_if_fail (!error || !*error, NULL); + g_return_val_if_fail (!out_group_fields || !*out_group_fields, NULL); - array = g_array_new (FALSE, FALSE, sizeof (int)); - if (parse_groups && group_fields) - *group_fields = g_ptr_array_new_full (20, (GDestroyNotify) g_free); + selection = nmc_output_selection_create (fields_array, fields_str, error); + if (!selection) + return NULL; - /* Split supplied fields string */ - fields = g_strsplit_set (fields_str, ",", -1); - for (iter = fields; iter && *iter; iter++) { - int idx = -1; + array = g_array_sized_new (FALSE, FALSE, sizeof (int), selection->num); + if (parse_groups && out_group_fields) + group_fields = g_ptr_array_new_full (selection->num, g_free); - g_strstrip (*iter); - if (parse_groups) { - /* e.g. "general.device,general.driver,ip4,ip6" */ - gboolean found = FALSE; - char *left = *iter; - char *right = strchr (*iter, '.'); + for (i = 0; i < selection->num; i++) { + int idx = selection->items[i].idx; - if (right) - *right++ = '\0'; - - for (i = 0; fields_array[i].name; i++) { - if (strcasecmp (left, fields_array[i].name) == 0) { - const NmcOutputField *valid_names = fields_array[i].group_list; - const NMMetaSettingInfoEditor *setting_info = fields_array[i].setting_info; - - idx = i; - if (!right && !valid_names && !setting_info) { - found = TRUE; - break; - } - if (valid_names) { - for (j = 0; valid_names[j].name; j++) { - if (!right || strcasecmp (right, valid_names[j].name) == 0) { - found = TRUE; - break; - } - } - } else if (setting_info) { - for (j = 1; j < setting_info->properties_num; j++) { - if (!right || strcasecmp (right, setting_info->properties[j].property_name) == 0) { - found = TRUE; - break; - } - } - } - if (found) - break; - } - } - if (found) { - /* Add index to array, and field name (or NULL) to group_fields array */ - g_array_append_val (array, idx); - if (group_fields && *group_fields) - g_ptr_array_add (*group_fields, g_strdup (right)); - } - if (right) - *(right-1) = '.'; /* Restore the original string */ - } else { - /* e.g. "general,ip4,ip6" */ - for (i = 0; fields_array[i].name; i++) { - if (strcasecmp (*iter, fields_array[i].name) == 0) { - g_array_append_val (array, i); - break; - } - } - } - - /* Field was not found - error case */ - if (fields_array[i].name == NULL) { - /* Set GError */ - if (!strcasecmp (*iter, "all") || !strcasecmp (*iter, "common")) - g_set_error (error, NMCLI_ERROR, 0, _("field '%s' has to be alone"), *iter); - else { - char *allowed_fields = nmc_get_allowed_fields (fields_array, idx); - g_set_error (error, NMCLI_ERROR, 1, _("invalid field '%s'; allowed fields: %s"), - *iter, allowed_fields); - g_free (allowed_fields); - } - - /* Free arrays on error */ - g_array_free (array, TRUE); - array = NULL; - if (group_fields && *group_fields) { - g_ptr_array_free (*group_fields, TRUE); - *group_fields = NULL; - } - goto done; - } + g_array_append_val (array, idx); + if (group_fields) + g_ptr_array_add (group_fields, g_strdup (selection->items[i].sub_selection)); } -done: - if (fields) - g_strfreev (fields); + + if (group_fields) + *out_group_fields = group_fields; return array; } -/** -* nmc_get_allowed_fields: -* @fields_array: array of fields -* @group_idx: index to the array (for second-level array in 'group' member), -* or -1 -* -* Returns: string of allowed fields names. -* Caller is responsible for freeing the array. -*/ char * -nmc_get_allowed_fields (const NmcOutputField fields_array[], int group_idx) +nmc_get_allowed_fields_nested (const NMMetaAbstractInfo *abstract_info) { GString *allowed_fields = g_string_sized_new (256); int i; + const char *name = nm_meta_abstract_info_get_name (abstract_info); + gs_free gpointer nested_to_free = NULL; + const NMMetaAbstractInfo *const*nested = NULL; - if (group_idx != -1 && fields_array[group_idx].group_list) { - const NmcOutputField *second_level = fields_array[group_idx].group_list; - - for (i = 0; second_level[i].name; i++) { + nested = nm_meta_abstract_info_get_nested (abstract_info, NULL, &nested_to_free); + if (nested) { + for (i = 0; nested && nested[i]; i++) { g_string_append_printf (allowed_fields, "%s.%s,", - fields_array[group_idx].name, second_level[i].name); + name, nm_meta_abstract_info_get_name (nested[i])); } - } else if (group_idx != -1 && fields_array[group_idx].setting_info) { - const NMMetaSettingInfoEditor *second_level = fields_array[group_idx].setting_info; + } else + g_string_append_printf (allowed_fields, "%s,", name); - for (i = 1; i < second_level->properties_num; i++) { - g_string_append_printf (allowed_fields, "%s.%s,", - fields_array[group_idx].name, second_level->properties[i].property_name); - } - } else { - for (i = 0; fields_array[i].name; i++) - g_string_append_printf (allowed_fields, "%s,", fields_array[i].name); - } g_string_truncate (allowed_fields, allowed_fields->len - 1); return g_string_free (allowed_fields, FALSE); } +char * +nmc_get_allowed_fields (const NMMetaAbstractInfo *const*fields_array) +{ + GString *allowed_fields = g_string_sized_new (256); + guint i; + + for (i = 0; fields_array[i]; i++) + g_string_append_printf (allowed_fields, "%s,", nm_meta_abstract_info_get_name (fields_array[i])); + + if (allowed_fields->len) + g_string_truncate (allowed_fields, allowed_fields->len - 1); + + return g_string_free (allowed_fields, FALSE); +} + NmcOutputField * -nmc_dup_fields_array (NmcOutputField fields[], size_t size, guint32 flags) +nmc_dup_fields_array (const NMMetaAbstractInfo *const*fields, NmcOfFlags flags) { NmcOutputField *row; + gsize l; - row = g_malloc0 (size); - memcpy (row, fields, size); + for (l = 0; fields[l]; l++) { + } + + row = g_new0 (NmcOutputField, l + 1); + for (l = 0; fields[l]; l++) + row[l].info = fields[l]; row[0].flags = flags; - return row; } @@ -840,24 +987,19 @@ nmc_empty_output_fields (NmcOutputData *output_data) /* Empty output_data array */ if (output_data->output_data->len > 0) g_ptr_array_remove_range (output_data->output_data, 0, output_data->output_data->len); - - if (output_data->print_fields.indices) { - g_array_free (output_data->print_fields.indices, TRUE); - output_data->print_fields.indices = NULL; - } } static const char * colorize_string (NmcColorOption color_option, - NmcTermColor color, - NmcTermFormat color_fmt, + NMMetaTermColor color, + NMMetaTermFormat color_fmt, const char *str, char **out_to_free) { const char *out = str; if ( use_colors (color_option) - && (color != NMC_TERM_COLOR_NORMAL || color_fmt != NMC_TERM_FORMAT_NORMAL)) { + && (color != NM_META_TERM_COLOR_NORMAL || color_fmt != NM_META_TERM_FORMAT_NORMAL)) { *out_to_free = nmc_colorize (color_option, color, color_fmt, "%s", str); out = *out_to_free; } @@ -880,7 +1022,7 @@ get_value_to_print (NmcColorOption color_option, nm_assert (out_to_free && !*out_to_free); if (field_name) - value = _(field->name); + value = _(nm_meta_abstract_info_get_name (field->info)); else { value = field->value ? (is_array @@ -905,12 +1047,17 @@ get_value_to_print (NmcColorOption color_option, /* * Print both headers or values of 'field_values' array. * Entries to print and their order are specified via indices in - * 'nmc->print_fields.indices' array. + * 'nmc->indices' array. * Various flags influencing the output of fields are set up in the first item * of 'field_values' array. */ void -print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_fields, const NmcOutputField *field_values) +print_required_fields (const NmcConfig *nmc_config, + NmcOfFlags of_flags, + const GArray *indices, + const char *header_name, + int indent, + const NmcOutputField *field_values) { GString *str; int width1, width2; @@ -923,19 +1070,18 @@ print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_ gboolean terse = (nmc_config->print_output == NMC_PRINT_TERSE); gboolean pretty = (nmc_config->print_output == NMC_PRINT_PRETTY); gboolean escape = nmc_config->escape_values; - gboolean main_header_add = field_values[0].flags & NMC_OF_FLAG_MAIN_HEADER_ADD; - gboolean main_header_only = field_values[0].flags & NMC_OF_FLAG_MAIN_HEADER_ONLY; - gboolean field_names = field_values[0].flags & NMC_OF_FLAG_FIELD_NAMES; - gboolean section_prefix = field_values[0].flags & NMC_OF_FLAG_SECTION_PREFIX; - gboolean main_header = main_header_add || main_header_only; + gboolean main_header_add = of_flags & NMC_OF_FLAG_MAIN_HEADER_ADD; + gboolean main_header_only = of_flags & NMC_OF_FLAG_MAIN_HEADER_ONLY; + gboolean field_names = of_flags & NMC_OF_FLAG_FIELD_NAMES; + gboolean section_prefix = of_flags & NMC_OF_FLAG_SECTION_PREFIX; enum { ML_HEADER_WIDTH = 79 }; enum { ML_VALUE_INDENT = 40 }; /* --- Main header --- */ - if (main_header && pretty) { - int header_width = nmc_string_screen_width (print_fields->header_name, NULL) + 4; + if ((main_header_add || main_header_only) && pretty) { + int header_width = nmc_string_screen_width (header_name, NULL) + 4; if (multiline) { table_width = header_width < ML_HEADER_WIDTH ? ML_HEADER_WIDTH : header_width; @@ -945,10 +1091,10 @@ print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_ line = g_strnfill (table_width, '='); } - width1 = strlen (print_fields->header_name); - width2 = nmc_string_screen_width (print_fields->header_name, NULL); + width1 = strlen (header_name); + width2 = nmc_string_screen_width (header_name, NULL); g_print ("%s\n", line); - g_print ("%*s\n", (table_width + width2)/2 + width1 - width2, print_fields->header_name); + g_print ("%*s\n", (table_width + width2)/2 + width1 - width2, header_name); g_print ("%s\n", line); g_free (line); } @@ -965,9 +1111,9 @@ print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_ if (multiline) { - for (i = 0; i < print_fields->indices->len; i++) { + for (i = 0; i < indices->len; i++) { char *tmp; - int idx = g_array_index (print_fields->indices, int, i); + int idx = g_array_index (indices, int, i); gboolean is_array = field_values[idx].value_is_array; /* section prefix can't be an array */ @@ -989,7 +1135,7 @@ print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_ tmp = g_strdup_printf ("%s%s%s[%d]:", section_prefix ? (const char*) field_values[0].value : "", section_prefix ? "." : "", - _(field_values[idx].name), + _(nm_meta_abstract_info_get_name (field_values[idx].info)), j); width1 = strlen (tmp); width2 = nmc_string_screen_width (tmp, NULL); @@ -1009,7 +1155,7 @@ print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_ tmp = g_strdup_printf ("%s%s%s:", section_prefix ? hdr_name : "", section_prefix ? "." : "", - _(field_values[idx].name)); + _(nm_meta_abstract_info_get_name (field_values[idx].info))); width1 = strlen (tmp); width2 = nmc_string_screen_width (tmp, NULL); g_print ("%-*s%s\n", terse ? 0 : ML_VALUE_INDENT+width1-width2, tmp, print_val); @@ -1029,8 +1175,8 @@ print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_ str = g_string_new (NULL); - for (i = 0; i < print_fields->indices->len; i++) { - int idx = g_array_index (print_fields->indices, int, i); + for (i = 0; i < indices->len; i++) { + int idx = g_array_index (indices, int, i); gs_free char *val_to_free = NULL; const char *value = get_value_to_print (nmc_config->use_colors, (NmcOutputField *) field_values+idx, field_names, not_set_str, &val_to_free); @@ -1060,8 +1206,8 @@ print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_ /* Print actual values */ if (str->len > 0) { g_string_truncate (str, str->len-1); /* Chop off last column separator */ - if (print_fields->indent > 0) { - indent_str = g_strnfill (print_fields->indent, ' '); + if (indent > 0) { + indent_str = g_strnfill (indent, ' '); g_string_prepend (str, indent_str); g_free (indent_str); } @@ -1091,7 +1237,7 @@ print_data_prepare_width (GPtrArray *output_data) /* How many fields? */ row = g_ptr_array_index (output_data, 0); - while (row->name) { + while (row->info) { num_fields++; row++; } @@ -1118,13 +1264,20 @@ print_data_prepare_width (GPtrArray *output_data) } void -print_data (const NmcConfig *nmc_config, const NmcOutputData *out) +print_data (const NmcConfig *nmc_config, + const GArray *indices, + const char *header_name, + int indent, + const NmcOutputData *out) { guint i; for (i = 0; i < out->output_data->len; i++) { - print_required_fields (nmc_config, &out->print_fields, - g_ptr_array_index (out->output_data, i)); + const NmcOutputField *field_values = g_ptr_array_index (out->output_data, i); + + print_required_fields (nmc_config, field_values[0].flags, + indices, header_name, + indent, field_values); } } diff --git a/clients/cli/utils.h b/clients/cli/utils.h index 0f8c2949a5..d212ecb31a 100644 --- a/clients/cli/utils.h +++ b/clients/cli/utils.h @@ -40,10 +40,10 @@ gboolean nmc_parse_args (nmc_arg_t *arg_arr, gboolean last, int *argc, char ***a char *ssid_to_hex (const char *str, gsize len); void nmc_terminal_erase_line (void); void nmc_terminal_show_progress (const char *str); -const char *nmc_term_color_sequence (NmcTermColor color); -const char *nmc_term_format_sequence (NmcTermFormat format); -NmcTermColor nmc_term_color_parse_string (const char *str, GError **error); -char *nmc_colorize (NmcColorOption color_option, NmcTermColor color, NmcTermFormat format, const char * fmt, ...) _nm_printf (4, 5); +const char *nmc_term_color_sequence (NMMetaTermColor color); +const char *nmc_term_format_sequence (NMMetaTermFormat format); +NMMetaTermColor nmc_term_color_parse_string (const char *str, GError **error); +char *nmc_colorize (NmcColorOption color_option, NMMetaTermColor color, NMMetaTermFormat format, const char * fmt, ...) _nm_printf (4, 5); void nmc_filter_out_colors_inplace (char *str); char *nmc_filter_out_colors (const char *str); char *nmc_get_user_input (const char *ask_str); @@ -57,19 +57,72 @@ void set_val_str (NmcOutputField fields_array[], guint32 index, char *value); void set_val_strc (NmcOutputField fields_array[], guint32 index, const char *value); void set_val_arr (NmcOutputField fields_array[], guint32 index, char **value); void set_val_arrc (NmcOutputField fields_array[], guint32 index, const char **value); -void set_val_color_all (NmcOutputField fields_array[], NmcTermColor color); -void set_val_color_fmt_all (NmcOutputField fields_array[], NmcTermFormat format); +void set_val_color_all (NmcOutputField fields_array[], NMMetaTermColor color); +void set_val_color_fmt_all (NmcOutputField fields_array[], NMMetaTermFormat format); void nmc_free_output_field_values (NmcOutputField fields_array[]); + +typedef struct { + const NMMetaAbstractInfo *info; + const char *sub_selection; + guint idx; +} NmcOutputSelectionItem; + +typedef struct { + const guint num; + const NmcOutputSelectionItem items[]; +} NmcOutputSelection; + +NmcOutputSelection *nmc_output_selection_create (const NMMetaAbstractInfo *const* fields_array, + const char *fields_str, + GError **error); + GArray *parse_output_fields (const char *fields_str, - const NmcOutputField fields_array[], + const NMMetaAbstractInfo *const* fields_array, gboolean parse_groups, GPtrArray **group_fields, GError **error); -char *nmc_get_allowed_fields (const NmcOutputField fields_array[], int group_idx); -NmcOutputField *nmc_dup_fields_array (NmcOutputField fields[], size_t size, guint32 flags); +char *nmc_get_allowed_fields_nested (const NMMetaAbstractInfo *abstract_info); +char *nmc_get_allowed_fields (const NMMetaAbstractInfo *const*fields_array); +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, const NmcPrintFields *print_fields, const NmcOutputField field_values[]); +void print_required_fields (const NmcConfig *nmc_config, + NmcOfFlags of_flags, + const GArray *indices, + const char *header_name, + int indent, + const NmcOutputField *field_values); void print_data_prepare_width (GPtrArray *output_data); -void print_data (const NmcConfig *nmc_config, const NmcOutputData *out); +void print_data (const NmcConfig *nmc_config, + const GArray *indices, + const char *header_name, + int indent, + const NmcOutputData *out); + +/*****************************************************************************/ + +struct _NmcMetaGenericInfo { + const NMMetaType *meta_type; + const char *name; + const NmcMetaGenericInfo *const*nested; + gconstpointer (*get_fcn) (const NMMetaEnvironment *environment, + gpointer environment_user_data, + const NmcMetaGenericInfo *info, + gpointer target, + NMMetaAccessorGetType get_type, + NMMetaAccessorGetFlags get_flags, + gpointer *out_to_free); +}; + +#define NMC_META_GENERIC(n, ...) \ + (&((NmcMetaGenericInfo) { \ + .meta_type = &nmc_meta_type_generic_info, \ + .name = N_ (n), \ + __VA_ARGS__ \ + })) + +#define NMC_META_GENERIC_WITH_NESTED(n, nest) \ + NMC_META_GENERIC (n, .nested = (nest)) + +/*****************************************************************************/ #endif /* NMC_UTILS_H */ diff --git a/clients/common/nm-client-utils.c b/clients/common/nm-client-utils.c index 6df143861a..8f8b51606b 100644 --- a/clients/common/nm-client-utils.c +++ b/clients/common/nm-client-utils.c @@ -210,22 +210,9 @@ finish: char ** nmc_strsplit_set (const char *str, const char *delimiter, int max_tokens) { - char **result; - uint i; - uint j; - - result = g_strsplit_set (str, delimiter, max_tokens); - /* remove empty strings */ - for (i = 0; result && result[i]; i++) { - if (*(result[i]) == '\0') { - g_free (result[i]); - for (j = i; result[j]; j++) - result[j] = result[j + 1]; - i--; - } - } - return result; + return _nm_utils_strv_cleanup (g_strsplit_set (str, delimiter, max_tokens), + FALSE, TRUE, FALSE); } gboolean @@ -237,3 +224,24 @@ matches (const char *cmd, const char *pattern) return memcmp (pattern, cmd, len) == 0; } +const char * +nmc_bond_validate_mode (const char *mode, GError **error) +{ + unsigned long mode_int; + static const char *valid_modes[] = { "balance-rr", + "active-backup", + "balance-xor", + "broadcast", + "802.3ad", + "balance-tlb", + "balance-alb", + NULL }; + if (nmc_string_to_uint (mode, TRUE, 0, 6, &mode_int)) { + /* Translate bonding mode numbers to mode names: + * https://www.kernel.org/doc/Documentation/networking/bonding.txt + */ + return valid_modes[mode_int]; + } else + return nmc_string_is_valid (mode, valid_modes, error); +} + diff --git a/clients/common/nm-client-utils.h b/clients/common/nm-client-utils.h index 7f700f930f..9ef568991c 100644 --- a/clients/common/nm-client-utils.h +++ b/clients/common/nm-client-utils.h @@ -60,4 +60,7 @@ gboolean nmc_string_to_tristate (const char *str, NMCTriStateValue *val, GError gboolean matches (const char *cmd, const char *pattern); +/* FIXME: don't expose this function on it's own, at least not from this file. */ +const char *nmc_bond_validate_mode (const char *mode, GError **error); + #endif /* __NM_CLIENT_UTILS_H__ */ diff --git a/clients/common/nm-meta-setting-access.c b/clients/common/nm-meta-setting-access.c new file mode 100644 index 0000000000..5f538bf87a --- /dev/null +++ b/clients/common/nm-meta-setting-access.c @@ -0,0 +1,221 @@ +/* NetworkManager + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2010 - 2017 Red Hat, Inc. + */ + +#include "nm-default.h" + +#include "nm-meta-setting-access.h" + +/*****************************************************************************/ + +const NMMetaSettingInfoEditor * +nm_meta_setting_info_editor_find_by_name (const char *setting_name) +{ + const NMMetaSettingInfo *meta_setting_info; + const NMMetaSettingInfoEditor *setting_info; + + 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); + + return setting_info; +} + +const NMMetaSettingInfoEditor * +nm_meta_setting_info_editor_find_by_gtype (GType gtype) +{ + const NMMetaSettingInfo *meta_setting_info; + const NMMetaSettingInfoEditor *setting_info; + + meta_setting_info = nm_meta_setting_infos_by_gtype (gtype); + + if (!meta_setting_info) + return NULL; + + g_return_val_if_fail (meta_setting_info->get_setting_gtype, NULL); + g_return_val_if_fail (meta_setting_info->get_setting_gtype () == gtype, 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); + + return setting_info; +} + +const NMMetaSettingInfoEditor * +nm_meta_setting_info_editor_find_by_setting (NMSetting *setting) +{ + const NMMetaSettingInfoEditor *setting_info; + + g_return_val_if_fail (NM_IS_SETTING (setting), NULL); + + 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 || G_TYPE_CHECK_INSTANCE_TYPE (setting, setting_info->general->get_setting_gtype ())); + + return setting_info; +} + +const NMMetaPropertyInfo * +nm_meta_setting_info_editor_get_property_info (const NMMetaSettingInfoEditor *setting_info, const char *property_name) +{ + guint i; + + g_return_val_if_fail (setting_info, NULL); + g_return_val_if_fail (property_name, NULL); + + for (i = 0; i < setting_info->properties_num; i++) { + nm_assert (setting_info->properties[i].property_name); + nm_assert (setting_info->properties[i].setting_info == setting_info); + if (nm_streq (setting_info->properties[i].property_name, property_name)) + return &setting_info->properties[i]; + } + + return NULL; +} + +const NMMetaPropertyInfo * +nm_meta_property_info_find_by_name (const char *setting_name, const char *property_name) +{ + const NMMetaSettingInfoEditor *setting_info; + const NMMetaPropertyInfo *property_info; + + setting_info = nm_meta_setting_info_editor_find_by_name (setting_name); + if (!setting_info) + return NULL; + + property_info = nm_meta_setting_info_editor_get_property_info (setting_info, property_name); + + nm_assert (property_info->setting_info == setting_info); + + return property_info; +} + +const NMMetaPropertyInfo * +nm_meta_property_info_find_by_setting (NMSetting *setting, const char *property_name) +{ + const NMMetaSettingInfoEditor *setting_info; + const NMMetaPropertyInfo *property_info; + + setting_info = nm_meta_setting_info_editor_find_by_setting (setting); + if (!setting_info) + return NULL; + property_info = nm_meta_setting_info_editor_get_property_info (setting_info, property_name); + + nm_assert (property_info->setting_info == setting_info); + nm_assert (property_info == nm_meta_property_info_find_by_name (nm_setting_get_name (setting), property_name)); + + return property_info; +} + +/*****************************************************************************/ + +/* this basically returns NMMetaSettingType.properties, but with type + * (NMMetaPropertyInfo **) instead of (NMMetaPropertyInfo *), which is + * required by some APIs. */ +const NMMetaPropertyInfo *const* +nm_property_infos_for_setting_type (NMMetaSettingType setting_type) +{ + static const NMMetaPropertyInfo **cache[_NM_META_SETTING_TYPE_NUM] = { NULL }; + const NMMetaPropertyInfo **p; + guint i; + + nm_assert (setting_type < _NM_META_SETTING_TYPE_NUM); + nm_assert (setting_type == 0 || setting_type > 0); + + if (G_UNLIKELY (!(p = cache[setting_type]))) { + const NMMetaSettingInfoEditor *setting_info = &nm_meta_setting_infos_editor[setting_type]; + + p = g_new (const NMMetaPropertyInfo *, setting_info->properties_num + 1); + for (i = 0; i < setting_info->properties_num; i++) + p[i] = &setting_info->properties[i]; + p[i] = NULL; + cache[setting_type] = p; + } + return (const NMMetaPropertyInfo *const*) p; +} + +const NMMetaSettingInfoEditor *const* +nm_meta_setting_infos_editor_p (void) +{ + static const NMMetaSettingInfoEditor *cache[_NM_META_SETTING_TYPE_NUM + 1] = { NULL }; + guint i; + + if (G_UNLIKELY (!cache[0])) { + for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) + cache[i] = &nm_meta_setting_infos_editor[i]; + } + return cache; +} + +/*****************************************************************************/ + +const char * +nm_meta_abstract_info_get_name (const NMMetaAbstractInfo *abstract_info) +{ + 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); + nm_assert (n && n[0]); + return n; +} + +const NMMetaAbstractInfo *const* +nm_meta_abstract_info_get_nested (const NMMetaAbstractInfo *abstract_info, + guint *out_len, + gpointer *nested_to_free) +{ + const NMMetaAbstractInfo *const*nested; + guint l = 0; + gs_free gpointer f = NULL; + + nm_assert (abstract_info); + nm_assert (abstract_info->meta_type); + nm_assert (nested_to_free && !*nested_to_free); + + if (abstract_info->meta_type->get_nested) { + nested = abstract_info->meta_type->get_nested (abstract_info, &l, &f); + nm_assert ((nested ? g_strv_length ((char **) nested) : 0) == l); + if (nested && nested[0]) { + NM_SET_OUT (out_len, l); + *nested_to_free = g_steal_pointer (&f); + return nested; + } + } + NM_SET_OUT (out_len, 0); + return NULL; +} diff --git a/clients/common/nm-meta-setting-access.h b/clients/common/nm-meta-setting-access.h new file mode 100644 index 0000000000..553f41136f --- /dev/null +++ b/clients/common/nm-meta-setting-access.h @@ -0,0 +1,55 @@ +/* NetworkManager + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2010 - 2017 Red Hat, Inc. + */ + +#ifndef _NM_META_SETTING_ACCESS_H__ +#define _NM_META_SETTING_ACCESS_H__ + +#include "nm-meta-setting.h" +#include "nm-meta-setting-desc.h" + +/*****************************************************************************/ + +const NMMetaSettingInfoEditor *nm_meta_setting_info_editor_find_by_name (const char *setting_name); +const NMMetaSettingInfoEditor *nm_meta_setting_info_editor_find_by_gtype (GType gtype); +const NMMetaSettingInfoEditor *nm_meta_setting_info_editor_find_by_setting (NMSetting *setting); + +const NMMetaPropertyInfo *nm_meta_setting_info_editor_get_property_info (const NMMetaSettingInfoEditor *setting_info, + const char *property_name); +const NMMetaPropertyInfo *nm_meta_property_info_find_by_name (const char *setting_name, + const char *property_name); +const NMMetaPropertyInfo *nm_meta_property_info_find_by_setting (NMSetting *setting, + const char *property_name); + +/*****************************************************************************/ + +const NMMetaPropertyInfo *const*nm_property_infos_for_setting_type (NMMetaSettingType setting_type); + +const NMMetaSettingInfoEditor *const*nm_meta_setting_infos_editor_p (void); + +/*****************************************************************************/ + +const char *nm_meta_abstract_info_get_name (const NMMetaAbstractInfo *abstract_info); + +const NMMetaAbstractInfo *const*nm_meta_abstract_info_get_nested (const NMMetaAbstractInfo *abstract_info, + guint *out_len, + gpointer *nested_to_free); + +/*****************************************************************************/ + +#endif /* _NM_META_SETTING_ACCESS_H__ */ diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index dab414a900..a41e19e4e5 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -27,26 +27,10 @@ #include "nm-common-macros.h" #include "nm-utils/nm-enum-utils.h" +#include "NetworkManager.h" #include "nm-vpn-helpers.h" #include "nm-client-utils.h" - -/*****************************************************************************/ - -/* FIXME: don't include headers from nmcli. And move all uses of NMClient out - * of there. */ - -/* FIXME: don't directly print any warnings. Instead, add a hook mechanism to notify - * the caller about warnings, error or whatever. - */ - -#include "nmcli.h" - -NMConnection * -nmc_find_connection (const GPtrArray *connections, - const char *filter_type, - const char *filter_val, - int *start, - gboolean complete); +#include "nm-meta-setting-access.h" /*****************************************************************************/ @@ -417,27 +401,6 @@ nmc_proxy_check_script (const char *script, char **out_script, GError **error) return TRUE; } -const char * -nmc_bond_validate_mode (const char *mode, GError **error) -{ - unsigned long mode_int; - static const char *valid_modes[] = { "balance-rr", - "active-backup", - "balance-xor", - "broadcast", - "802.3ad", - "balance-tlb", - "balance-alb", - NULL }; - if (nmc_string_to_uint (mode, TRUE, 0, 6, &mode_int)) { - /* Translate bonding mode numbers to mode names: - * https://www.kernel.org/doc/Documentation/networking/bonding.txt - */ - return valid_modes[mode_int]; - } else - return nmc_string_is_valid (mode, valid_modes, error); -} - /* * nmc_team_check_config: * @config: file name with team config, or raw team JSON config data @@ -516,26 +479,50 @@ nmc_team_check_config (const char *config, char **out_config, GError **error) /*****************************************************************************/ +G_GNUC_PRINTF (4, 5) +static void +_env_warn_fcn (const NMMetaEnvironment *environment, + gpointer environment_user_data, + NMMetaEnvWarnLevel warn_level, + const char *fmt_l10n, + ...) +{ + va_list ap; + + if (!environment || !environment->warn_fcn) + return; + + va_start (ap, fmt_l10n); + environment->warn_fcn (environment, + environment_user_data, + warn_level, + fmt_l10n, + ap); + va_end (ap); +} + +/*****************************************************************************/ + #define ARGS_DESCRIBE_FCN \ - const NMMetaSettingInfoEditor *setting_info, const NMMetaPropertyInfo *property_info, char **out_to_free + const NMMetaPropertyInfo *property_info, char **out_to_free #define ARGS_GET_FCN \ - const NMMetaSettingInfoEditor *setting_info, const NMMetaPropertyInfo *property_info, NMSetting *setting, NMMetaAccessorGetType get_type, gboolean show_secrets + const NMMetaEnvironment *environment, gpointer environment_user_data, const NMMetaPropertyInfo *property_info, NMSetting *setting, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags #define ARGS_SET_FCN \ - const NMMetaSettingInfoEditor *setting_info, const NMMetaPropertyInfo *property_info, NMSetting *setting, const char *value, GError **error + const NMMetaEnvironment *environment, gpointer environment_user_data, const NMMetaPropertyInfo *property_info, NMSetting *setting, const char *value, GError **error #define ARGS_REMOVE_FCN \ - const NMMetaSettingInfoEditor *setting_info, const NMMetaPropertyInfo *property_info, NMSetting *setting, const char *value, guint32 idx, GError **error + const NMMetaEnvironment *environment, gpointer environment_user_data, const NMMetaPropertyInfo *property_info, NMSetting *setting, const char *value, guint32 idx, GError **error #define ARGS_VALUES_FCN \ - const NMMetaSettingInfoEditor *setting_info, const NMMetaPropertyInfo *property_info, char ***out_to_free + const NMMetaPropertyInfo *property_info, char ***out_to_free static char * _get_fcn_name (ARGS_GET_FCN) { - nm_assert (nm_streq0 (nm_setting_get_name (setting), setting_info->general->setting_name)); - return g_strdup (setting_info->general->setting_name); + nm_assert (nm_streq0 (nm_setting_get_name (setting), property_info->setting_info->general->setting_name)); + return g_strdup (property_info->setting_info->general->setting_name); } static char * @@ -546,35 +533,59 @@ _get_fcn_nmc_with_default (ARGS_GET_FCN) GValue val = G_VALUE_INIT; if (property_info->property_typ_data->subtype.get_with_default.fcn (setting)) { - if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) - return g_strdup (""); - return g_strdup (_("(default)")); + if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) + return g_strdup (_("(default)")); + return g_strdup (""); } g_value_init (&val, G_TYPE_STRING); g_object_get_property (G_OBJECT (setting), property_info->property_name, &val); s = g_value_get_string (&val); - if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) - s_full = g_strdup (s && *s ? s : " "); - else + if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) s_full = s ? g_strdup_printf ("\"%s\"", s) : g_strdup (""); + else + s_full = g_strdup (s && *s ? s : " "); g_value_unset (&val); return s_full; } static char * -_get_fcn_gobject (ARGS_GET_FCN) +_get_fcn_gobject_impl (const NMMetaPropertyInfo *property_info, + NMSetting *setting, + NMMetaAccessorGetType get_type) { char *s; - GValue val = G_VALUE_INIT; + const char *s_c; + GType gtype_prop; + nm_auto_unset_gvalue GValue val = G_VALUE_INIT; - g_value_init (&val, G_TYPE_STRING); - g_object_get_property (G_OBJECT (setting), property_info->property_name, &val); - s = g_value_dup_string (&val); - g_value_unset (&val); + gtype_prop = _gobject_property_get_gtype (G_OBJECT (setting), property_info->property_name); + + if (gtype_prop == G_TYPE_BOOLEAN) { + gboolean b; + + g_value_init (&val, gtype_prop); + g_object_get_property (G_OBJECT (setting), property_info->property_name, &val); + b = g_value_get_boolean (&val); + if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) + s_c = b ? _("yes") : _("no"); + else + s_c = b ? "yes" : "no"; + s = g_strdup (s_c); + } else { + g_value_init (&val, G_TYPE_STRING); + g_object_get_property (G_OBJECT (setting), property_info->property_name, &val); + s = g_value_dup_string (&val); + } return s; } +static char * +_get_fcn_gobject (ARGS_GET_FCN) +{ + return _get_fcn_gobject_impl (property_info, setting, get_type); +} + static char * _get_fcn_gobject_mtu (ARGS_GET_FCN) { @@ -582,14 +593,13 @@ _get_fcn_gobject_mtu (ARGS_GET_FCN) if ( !property_info->property_typ_data || !property_info->property_typ_data->subtype.mtu.get_fcn) - return _get_fcn_gobject (setting_info, property_info, setting, get_type, show_secrets); + return _get_fcn_gobject_impl (property_info, setting, get_type); mtu = property_info->property_typ_data->subtype.mtu.get_fcn (setting); if (mtu == 0) { - if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) - return g_strdup ("auto"); - else + if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) return g_strdup (_("auto")); + return g_strdup ("auto"); } return g_strdup_printf ("%u", (unsigned) mtu); } @@ -643,7 +653,7 @@ _get_fcn_gobject_enum (ARGS_GET_FCN) format_text_l10n = NM_FLAGS_HAS (property_info->property_typ_data->typ_flags, NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT_L10N); format_text = format_text_l10n || NM_FLAGS_HAS (property_info->property_typ_data->typ_flags, NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT); } else if ( property_info->property_typ_data - && get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE + && get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY && NM_FLAGS_ANY (property_info->property_typ_data->typ_flags, NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC_HEX | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT)) { @@ -844,7 +854,7 @@ _set_fcn_gobject_mtu (ARGS_SET_FCN) { if (nm_streq0 (value, "auto")) value = "0"; - return _set_fcn_gobject_uint (setting_info, property_info, setting, value, error); + return _set_fcn_gobject_uint (environment, environment_user_data, property_info, setting, value, error); } static gboolean @@ -899,7 +909,10 @@ _set_fcn_gobject_secret_flags (ARGS_SET_FCN) /* Validate the flags number */ if (flags > ALL_SECRET_FLAGS) { flags = ALL_SECRET_FLAGS; - g_print (_("Warning: '%s' sum is higher than all flags => all flags set\n"), value); + _env_warn_fcn (environment, environment_user_data, + NM_META_ENV_WARN_LEVEL_WARN, + N_ ("'%s' sum is higher than all flags => all flags set"), + value); } g_object_set (setting, property_info->property_name, (guint) flags, NULL); @@ -1016,7 +1029,7 @@ _values_fcn_gobject_enum (ARGS_VALUES_FCN) } if (!has_gtype) { - gtype = _gtype_property_get_gtype (setting_info->general->get_setting_gtype (), + gtype = _gtype_property_get_gtype (property_info->setting_info->general->get_setting_gtype (), property_info->property_name); } @@ -1071,7 +1084,7 @@ vlan_flags_to_string (guint32 flags, NMMetaAccessorGetType get_type) { GString *flag_str; - if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) return g_strdup_printf ("%u", flags); if (flags == 0) @@ -1121,7 +1134,7 @@ vlan_priorities_to_string (NMSettingVlan *s_vlan, NMVlanPriorityMap map) static char * ip6_privacy_to_string (NMSettingIP6ConfigPrivacy ip6_privacy, NMMetaAccessorGetType get_type) { - if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) return g_strdup_printf ("%d", ip6_privacy); switch (ip6_privacy) { @@ -1140,7 +1153,7 @@ static char * autoconnect_slaves_to_string (NMSettingConnectionAutoconnectSlaves autoconnect_slaves, NMMetaAccessorGetType get_type) { - if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) return g_strdup_printf ("%d", autoconnect_slaves); switch (autoconnect_slaves) { @@ -1159,7 +1172,7 @@ secret_flags_to_string (guint32 flags, NMMetaAccessorGetType get_type) { GString *flag_str; - if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) return g_strdup_printf ("%u", flags); if (flags == 0) @@ -1627,7 +1640,7 @@ _get_fcn_802_1x_client_cert (ARGS_GET_FCN) switch (nm_setting_802_1x_get_client_cert_scheme (s_8021X)) { case NM_SETTING_802_1X_CK_SCHEME_BLOB: - if (show_secrets) + if (NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS)) cert_str = bytes_to_string (nm_setting_802_1x_get_client_cert_blob (s_8021X)); else cert_str = g_strdup (_(NM_META_TEXT_HIDDEN)); @@ -1676,7 +1689,7 @@ _get_fcn_802_1x_phase2_client_cert (ARGS_GET_FCN) switch (nm_setting_802_1x_get_phase2_client_cert_scheme (s_8021X)) { case NM_SETTING_802_1X_CK_SCHEME_BLOB: - if (show_secrets) + if (NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS)) cert_str = bytes_to_string (nm_setting_802_1x_get_phase2_client_cert_blob (s_8021X)); else cert_str = g_strdup (_(NM_META_TEXT_HIDDEN)); @@ -1709,7 +1722,7 @@ _get_fcn_802_1x_private_key (ARGS_GET_FCN) switch (nm_setting_802_1x_get_private_key_scheme (s_8021X)) { case NM_SETTING_802_1X_CK_SCHEME_BLOB: - if (show_secrets) + if (NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS)) key_str = bytes_to_string (nm_setting_802_1x_get_private_key_blob (s_8021X)); else key_str = g_strdup (_(NM_META_TEXT_HIDDEN)); @@ -1735,7 +1748,7 @@ _get_fcn_802_1x_phase2_private_key (ARGS_GET_FCN) switch (nm_setting_802_1x_get_phase2_private_key_scheme (s_8021X)) { case NM_SETTING_802_1X_CK_SCHEME_BLOB: - if (show_secrets) + if (NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS)) key_str = bytes_to_string (nm_setting_802_1x_get_phase2_private_key_blob (s_8021X)); else key_str = g_strdup (_(NM_META_TEXT_HIDDEN)); @@ -2036,7 +2049,7 @@ _get_fcn_connection_autoconnect_retires (ARGS_GET_FCN) gint retries; retries = nm_setting_connection_get_autoconnect_retries (s_con); - if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) return g_strdup_printf ("%d", retries); switch (retries) { @@ -2195,54 +2208,16 @@ _set_fcn_connection_master (ARGS_SET_FCN) static gboolean _set_fcn_connection_secondaries (ARGS_SET_FCN) { - const GPtrArray *connections; - NMConnection *con; - char **strv = NULL, **iter; - guint i = 0; + gs_strfreev char **strv = NULL; + char **iter; - connections = nm_client_get_connections (nm_cli.client); strv = nmc_strsplit_set (value, " \t,", 0); - for (iter = strv; iter && *iter; iter++) { - if (**iter == '\0') - continue; - - if (nm_utils_is_uuid (*iter)) { - con = nmc_find_connection (connections, "uuid", *iter, NULL, FALSE); - if (!con) - g_print (_("Warning: %s is not an UUID of any existing connection profile\n"), *iter); - else { - /* Currenly NM only supports VPN connections as secondaries */ - if (!nm_connection_is_type (con, NM_SETTING_VPN_SETTING_NAME)) { - g_set_error (error, 1, 0, _("'%s' is not a VPN connection profile"), *iter); - g_strfreev (strv); - return FALSE; - } - } - } else { - con = nmc_find_connection (connections, "id", *iter, NULL, FALSE); - if (!con) { - g_set_error (error, 1, 0, _("'%s' is not a name of any exiting profile"), *iter); - g_strfreev (strv); - return FALSE; - } - - /* Currenly NM only supports VPN connections as secondaries */ - if (!nm_connection_is_type (con, NM_SETTING_VPN_SETTING_NAME)) { - g_set_error (error, 1, 0, _("'%s' is not a VPN connection profile"), *iter); - g_strfreev (strv); - return FALSE; - } - - /* translate id to uuid */ - g_free (*iter); - *iter = g_strdup (nm_connection_get_uuid (con)); + if (strv) { + for (iter = strv; *iter; iter++) { + if (**iter) + nm_setting_connection_add_secondary (NM_SETTING_CONNECTION (setting), *iter); } } - - while (strv && strv[i]) - nm_setting_connection_add_secondary (NM_SETTING_CONNECTION (setting), strv[i++]); - g_strfreev (strv); - return TRUE; } @@ -2276,7 +2251,7 @@ _get_fcn_connection_metered (ARGS_GET_FCN) { NMSettingConnection *s_conn = NM_SETTING_CONNECTION (setting); - if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) { + if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) { switch (nm_setting_connection_get_metered (s_conn)) { case NM_METERED_YES: return g_strdup ("yes"); @@ -2563,13 +2538,17 @@ error: } static void -dcb_check_feature_enabled (NMSettingDcb *s_dcb, const char *flags_prop) +dcb_check_feature_enabled (const NMMetaEnvironment *environment, gpointer *environment_user_data, NMSettingDcb *s_dcb, const char *flags_prop) { NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; g_object_get (s_dcb, flags_prop, &flags, NULL); - if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) - g_print (_("Warning: changes will have no effect until '%s' includes 1 (enabled)\n\n"), flags_prop); + if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) { + _env_warn_fcn (environment, environment_user_data, + NM_META_ENV_WARN_LEVEL_WARN, + N_ ("changes will have no effect until '%s' includes 1 (enabled)"), + flags_prop); + } } static gboolean @@ -2586,7 +2565,7 @@ _set_fcn_dcb_priority_flow_control (ARGS_SET_FCN) for (i = 0; i < 8; i++) nm_setting_dcb_set_priority_flow_control (NM_SETTING_DCB (setting), i, !!nums[i]); - dcb_check_feature_enabled (NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS); + dcb_check_feature_enabled (environment, environment_user_data, NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS); return TRUE; } @@ -2604,7 +2583,7 @@ _set_fcn_dcb_priority_group_id (ARGS_SET_FCN) for (i = 0; i < 8; i++) nm_setting_dcb_set_priority_group_id (NM_SETTING_DCB (setting), i, nums[i]); - dcb_check_feature_enabled (NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); + dcb_check_feature_enabled (environment, environment_user_data, NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); return TRUE; } @@ -2629,7 +2608,7 @@ _set_fcn_dcb_priority_group_bandwidth (ARGS_SET_FCN) for (i = 0; i < 8; i++) nm_setting_dcb_set_priority_group_bandwidth (NM_SETTING_DCB (setting), i, nums[i]); - dcb_check_feature_enabled (NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); + dcb_check_feature_enabled (environment, environment_user_data, NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); return TRUE; } @@ -2647,7 +2626,7 @@ _set_fcn_dcb_priority_bandwidth (ARGS_SET_FCN) for (i = 0; i < 8; i++) nm_setting_dcb_set_priority_bandwidth (NM_SETTING_DCB (setting), i, nums[i]); - dcb_check_feature_enabled (NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); + dcb_check_feature_enabled (environment, environment_user_data, NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); return TRUE; } @@ -2665,7 +2644,7 @@ _set_fcn_dcb_priority_strict (ARGS_SET_FCN) for (i = 0; i < 8; i++) nm_setting_dcb_set_priority_strict_bandwidth (NM_SETTING_DCB (setting), i, !!nums[i]); - dcb_check_feature_enabled (NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); + dcb_check_feature_enabled (environment, environment_user_data, NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); return TRUE; } @@ -2683,7 +2662,7 @@ _set_fcn_dcb_priority_traffic_class (ARGS_SET_FCN) for (i = 0; i < 8; i++) nm_setting_dcb_set_priority_traffic_class (NM_SETTING_DCB (setting), i, nums[i]); - dcb_check_feature_enabled (NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); + dcb_check_feature_enabled (environment, environment_user_data, NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); return TRUE; } @@ -2746,7 +2725,7 @@ _get_fcn_infiniband_p_key (ARGS_GET_FCN) p_key = nm_setting_infiniband_get_p_key (s_infiniband); if (p_key == -1) { - if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) return g_strdup ("default"); else return g_strdup (_("default")); @@ -2854,7 +2833,7 @@ _get_fcn_ip_config_routes (ARGS_GET_FCN) attr_str = nm_utils_format_variant_attributes (hash, ' ', '='); - if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) { + if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) { if (printable->len > 0) g_string_append (printable, ", "); @@ -2903,7 +2882,7 @@ _get_fcn_ip4_config_dad_timeout (ARGS_GET_FCN) gint dad_timeout; dad_timeout = nm_setting_ip_config_get_dad_timeout (s_ip); - if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) return g_strdup_printf ("%d", dad_timeout); switch (dad_timeout) { @@ -3556,7 +3535,7 @@ _get_fcn_macvlan_mode (ARGS_GET_FCN) mode = nm_setting_macvlan_get_mode (s_macvlan); tmp = nm_utils_enum_to_str (nm_setting_macvlan_mode_get_type (), mode); - if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) str = g_strdup (tmp ? tmp : ""); else str = g_strdup_printf ("%d (%s)", mode, tmp ? tmp : ""); @@ -3738,7 +3717,7 @@ _get_fcn_tun_mode (ARGS_GET_FCN) mode = nm_setting_tun_get_mode (s_tun); tmp = nm_utils_enum_to_str (nm_setting_tun_mode_get_type (), mode); - if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) str = g_strdup_printf ("%s", tmp ? tmp : ""); else str = g_strdup_printf ("%d (%s)", mode, tmp ? tmp : ""); @@ -3823,7 +3802,9 @@ _set_fcn_vlan_egress_priority_map (ARGS_SET_FCN) } static gboolean -_remove_vlan_xgress_priority_map (NMSetting *setting, +_remove_vlan_xgress_priority_map (const NMMetaEnvironment *environment, + gpointer environment_user_data, + NMSetting *setting, const NMMetaPropertyInfo *property_info, const char *value, guint32 idx, @@ -3841,9 +3822,12 @@ _remove_vlan_xgress_priority_map (NMSetting *setting, prio_map = nmc_vlan_parse_priority_maps (v, map_type, error); if (!prio_map) return FALSE; - if (prio_map[1]) - g_print (_("Warning: only one mapping at a time is supported; taking the first one (%s)\n"), - prio_map[0]); + if (prio_map[1]) { + _env_warn_fcn (environment, environment_user_data, + NM_META_ENV_WARN_LEVEL_WARN, + N_ ("only one mapping at a time is supported; taking the first one (%s)"), + prio_map[0]); + } ret = nm_setting_vlan_remove_priority_str_by_value (NM_SETTING_VLAN (setting), map_type, prio_map[0]); @@ -3873,7 +3857,9 @@ _remove_vlan_xgress_priority_map (NMSetting *setting, static gboolean _remove_fcn_vlan_ingress_priority_map (ARGS_REMOVE_FCN) { - return _remove_vlan_xgress_priority_map (setting, + return _remove_vlan_xgress_priority_map (environment, + environment_user_data, + setting, property_info, value, idx, @@ -3884,7 +3870,9 @@ _remove_fcn_vlan_ingress_priority_map (ARGS_REMOVE_FCN) static gboolean _remove_fcn_vlan_egress_priority_map (ARGS_REMOVE_FCN) { - return _remove_vlan_xgress_priority_map (setting, + return _remove_vlan_xgress_priority_map (environment, + environment_user_data, + setting, property_info, value, idx, @@ -3957,7 +3945,7 @@ _get_fcn_wired_wake_on_lan (ARGS_GET_FCN) wol = nm_setting_wired_get_wake_on_lan (s_wired); tmp = nm_utils_enum_to_str (nm_setting_wired_wake_on_lan_get_type (), wol); - if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) str = g_strdup_printf ("%s", tmp && *tmp ? tmp : "none"); else str = g_strdup_printf ("%d (%s)", wol, tmp && *tmp ? tmp : "none"); @@ -4390,9 +4378,16 @@ _set_fcn_wireless_wep_key (ARGS_SET_FCN) } prev_idx = nm_setting_wireless_security_get_wep_tx_keyidx (NM_SETTING_WIRELESS_SECURITY (setting)); idx = property_info->property_name[strlen (property_info->property_name) - 1] - '0'; - g_print (_("WEP key is guessed to be of '%s'\n"), wep_key_type_to_string (guessed_type)); - if (idx != prev_idx) - g_print (_("WEP key index set to '%d'\n"), idx); + _env_warn_fcn (environment, environment_user_data, + NM_META_ENV_WARN_LEVEL_INFO, + N_ ("WEP key is guessed to be of '%s'"), + wep_key_type_to_string (guessed_type)); + if (idx != prev_idx) { + _env_warn_fcn (environment, environment_user_data, + NM_META_ENV_WARN_LEVEL_INFO, + N_ ("WEP key index set to '%d'"), + idx); + } g_object_set (setting, property_info->property_name, value, NULL); g_object_set (setting, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, guessed_type, NULL); @@ -4407,7 +4402,6 @@ _set_fcn_wireless_security_wep_key_type (ARGS_SET_FCN) unsigned long type_int; const char *valid_wep_types[] = { "unknown", "key", "passphrase", NULL }; const char *type_str = NULL; - const char *key0, *key1,* key2, *key3; NMWepKeyType type = NM_WEP_KEY_TYPE_UNKNOWN; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); @@ -4425,22 +4419,26 @@ _set_fcn_wireless_security_wep_key_type (ARGS_SET_FCN) type = (NMWepKeyType) type_int; /* Check type compatibility with set keys */ - key0 = nm_setting_wireless_security_get_wep_key (NM_SETTING_WIRELESS_SECURITY (setting), 0); - key1 = nm_setting_wireless_security_get_wep_key (NM_SETTING_WIRELESS_SECURITY (setting), 1); - key2 = nm_setting_wireless_security_get_wep_key (NM_SETTING_WIRELESS_SECURITY (setting), 2); - key3 = nm_setting_wireless_security_get_wep_key (NM_SETTING_WIRELESS_SECURITY (setting), 3); - if (key0 && !nm_utils_wep_key_valid (key0, type)) - g_print (_("Warning: '%s' is not compatible with '%s' type, please change or delete the key.\n"), - NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, wep_key_type_to_string (type)); - if (key1 && !nm_utils_wep_key_valid (key1, type)) - g_print (_("Warning: '%s' is not compatible with '%s' type, please change or delete the key.\n"), - NM_SETTING_WIRELESS_SECURITY_WEP_KEY1, wep_key_type_to_string (type)); - if (key2 && !nm_utils_wep_key_valid (key2, type)) - g_print (_("Warning: '%s' is not compatible with '%s' type, please change or delete the key.\n"), - NM_SETTING_WIRELESS_SECURITY_WEP_KEY2, wep_key_type_to_string (type)); - if (key3 && !nm_utils_wep_key_valid (key3, type)) - g_print (_("Warning: '%s' is not compatible with '%s' type, please change or delete the key.\n"), - NM_SETTING_WIRELESS_SECURITY_WEP_KEY3, wep_key_type_to_string (type)); + { + guint i; + const char *key; + const char *keynames[] = { + NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, + NM_SETTING_WIRELESS_SECURITY_WEP_KEY1, + NM_SETTING_WIRELESS_SECURITY_WEP_KEY2, + NM_SETTING_WIRELESS_SECURITY_WEP_KEY3, + }; + + for (i = 0; i < 4; i++) { + key = nm_setting_wireless_security_get_wep_key (NM_SETTING_WIRELESS_SECURITY (setting), i); + if (key && !nm_utils_wep_key_valid (key, type)) { + _env_warn_fcn (environment, environment_user_data, + NM_META_ENV_WARN_LEVEL_WARN, + N_ ("'%s' is not compatible with '%s' type, please change or delete the key."), + keynames[i], wep_key_type_to_string (type)); + } + } + } g_object_set (setting, property_info->property_name, type, NULL); return TRUE; @@ -4459,34 +4457,6 @@ _set_fcn_wireless_security_psk (ARGS_SET_FCN) /*****************************************************************************/ -static void -nmc_value_transform_bool_string (const GValue *src_value, - GValue *dest_value) -{ - dest_value->data[0].v_pointer = g_strdup (src_value->data[0].v_int ? "yes" : "no"); -} - -static void -nmc_value_transform_char_string (const GValue *src_value, - GValue *dest_value) -{ - dest_value->data[0].v_pointer = g_strdup_printf ("%c", src_value->data[0].v_uint); -} - -static void __attribute__((constructor)) -register_nmcli_value_transforms (void) -{ - /* FIXME: we should not register a g-value transform function. Instead, our meta data - * should be able to access the values according to their type. - * - * Also, running code as a ((constructor)) is hightly unexpected and affects the - * entire binary. */ - g_value_register_transform_func (G_TYPE_BOOLEAN, G_TYPE_STRING, nmc_value_transform_bool_string); - g_value_register_transform_func (G_TYPE_CHAR, G_TYPE_STRING, nmc_value_transform_char_string); -} - -/*****************************************************************************/ - #define DEFINE_PROPERTY_TYPE(...) \ (&((NMMetaPropertyType) { __VA_ARGS__ } )) @@ -4568,12 +4538,16 @@ static const NMMetaPropertyType _pt_gobject_enum = { * in NMMetaSettingInfo. */ #define PROPERTY_INFO_NAME() \ { \ + .meta_type = &nm_meta_type_property_info, \ + .setting_info = &nm_meta_setting_infos_editor[_CURRENT_NM_META_SETTING_TYPE], \ .property_name = N_ ("name"), \ .is_name = TRUE, \ .property_type = &_pt_name, \ } #define PROPERTY_INFO(name, doc) \ + .meta_type = &nm_meta_type_property_info, \ + .setting_info = &nm_meta_setting_infos_editor[_CURRENT_NM_META_SETTING_TYPE], \ .property_name = N_ (name), \ .describe_doc = N_ (doc) @@ -4602,7 +4576,8 @@ static const NMMetaPropertyType _pt_gobject_enum = { "{ \"device\": \"team0\", \"runner\": {\"name\": \"roundrobin\"}, \"ports\": {\"eth1\": {}, \"eth2\": {}} }\n" \ " set team.config /etc/my-team.conf\n" -static const NMMetaPropertyInfo property_infos_802_1x[] = { +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_802_1X +static const NMMetaPropertyInfo property_infos_802_1X[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_EAP), @@ -4888,7 +4863,9 @@ static const NMMetaPropertyInfo property_infos_802_1x[] = { }, }; -static const NMMetaPropertyInfo property_infos_adsl[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_ADSL +static const NMMetaPropertyInfo property_infos_ADSL[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_ADSL_USERNAME), @@ -4930,7 +4907,9 @@ static const NMMetaPropertyInfo property_infos_adsl[] = { }, }; -static const NMMetaPropertyInfo property_infos_bluetooth[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_BLUETOOTH +static const NMMetaPropertyInfo property_infos_BLUETOOTH[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_BLUETOOTH_BDADDR), @@ -4946,7 +4925,9 @@ static const NMMetaPropertyInfo property_infos_bluetooth[] = { }, }; -static const NMMetaPropertyInfo property_infos_bond[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_BOND +static const NMMetaPropertyInfo property_infos_BOND[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_BOND_OPTIONS), @@ -4960,7 +4941,9 @@ static const NMMetaPropertyInfo property_infos_bond[] = { }, }; -static const NMMetaPropertyInfo property_infos_bridge[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_BRIDGE +static const NMMetaPropertyInfo property_infos_BRIDGE[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_MAC_ADDRESS), @@ -4996,7 +4979,9 @@ static const NMMetaPropertyInfo property_infos_bridge[] = { }, }; -static const NMMetaPropertyInfo property_infos_bridge_port[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_BRIDGE_PORT +static const NMMetaPropertyInfo property_infos_BRIDGE_PORT[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_PORT_PRIORITY), @@ -5012,7 +4997,9 @@ static const NMMetaPropertyInfo property_infos_bridge_port[] = { }, }; -static const NMMetaPropertyInfo property_infos_cdma[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_CDMA +static const NMMetaPropertyInfo property_infos_CDMA[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_CDMA_NUMBER), @@ -5040,7 +5027,9 @@ static const NMMetaPropertyInfo property_infos_cdma[] = { }, }; -static const NMMetaPropertyInfo property_infos_connection[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_CONNECTION +static const NMMetaPropertyInfo property_infos_CONNECTION[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_ID), @@ -5185,7 +5174,9 @@ static const NMMetaPropertyInfo property_infos_connection[] = { }, }; -static const NMMetaPropertyInfo property_infos_dcb[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_DCB +static const NMMetaPropertyInfo property_infos_DCB[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_DCB_APP_FCOE_FLAGS), @@ -5295,11 +5286,15 @@ static const NMMetaPropertyInfo property_infos_dcb[] = { }, }; -static const NMMetaPropertyInfo property_infos_dummy[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_DUMMY +static const NMMetaPropertyInfo property_infos_DUMMY[] = { PROPERTY_INFO_NAME(), }; -static const NMMetaPropertyInfo property_infos_gsm[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_GSM +static const NMMetaPropertyInfo property_infos_GSM[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_NUMBER), @@ -5363,7 +5358,9 @@ static const NMMetaPropertyInfo property_infos_gsm[] = { }, }; -static const NMMetaPropertyInfo property_infos_infiniband[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_INFINIBAND +static const NMMetaPropertyInfo property_infos_INFINIBAND[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_INFINIBAND_MAC_ADDRESS), @@ -5402,7 +5399,9 @@ static const NMMetaPropertyInfo property_infos_infiniband[] = { }, }; -static const NMMetaPropertyInfo property_infos_ip4_config[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_IP4_CONFIG +static const NMMetaPropertyInfo property_infos_IP4_CONFIG[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO (NM_SETTING_IP_CONFIG_METHOD, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_METHOD), @@ -5533,7 +5532,9 @@ static const NMMetaPropertyInfo property_infos_ip4_config[] = { }, }; -static const NMMetaPropertyInfo property_infos_ip6_config[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_IP6_CONFIG +static const NMMetaPropertyInfo property_infos_IP6_CONFIG[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO (NM_SETTING_IP_CONFIG_METHOD, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_METHOD), @@ -5673,7 +5674,9 @@ static const NMMetaPropertyInfo property_infos_ip6_config[] = { }, }; -static const NMMetaPropertyInfo property_infos_ip_tunnel[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_IP_TUNNEL +static const NMMetaPropertyInfo property_infos_IP_TUNNEL[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_MODE), @@ -5734,7 +5737,9 @@ static const NMMetaPropertyInfo property_infos_ip_tunnel[] = { }, }; -static const NMMetaPropertyInfo property_infos_macsec[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_MACSEC +static const NMMetaPropertyInfo property_infos_MACSEC[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_MACSEC_PARENT), @@ -5785,7 +5790,9 @@ static const NMMetaPropertyInfo property_infos_macsec[] = { }, }; -static const NMMetaPropertyInfo property_infos_macvlan[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_MACVLAN +static const NMMetaPropertyInfo property_infos_MACVLAN[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_MACVLAN_PARENT), @@ -5814,7 +5821,9 @@ static const NMMetaPropertyInfo property_infos_macvlan[] = { }, }; -static const NMMetaPropertyInfo property_infos_olpc_mesh[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_OLPC_MESH +static const NMMetaPropertyInfo property_infos_OLPC_MESH[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_OLPC_MESH_SSID), @@ -5836,7 +5845,9 @@ static const NMMetaPropertyInfo property_infos_olpc_mesh[] = { }, }; -static const NMMetaPropertyInfo property_infos_pppoe[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_PPPOE +static const NMMetaPropertyInfo property_infos_PPPOE[] = { PROPERTY_INFO_NAME (), { PROPERTY_INFO_WITH_DESC (NM_SETTING_PPPOE_SERVICE), @@ -5857,7 +5868,9 @@ static const NMMetaPropertyInfo property_infos_pppoe[] = { }, }; -static const NMMetaPropertyInfo property_infos_ppp[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_PPP +static const NMMetaPropertyInfo property_infos_PPP[] = { PROPERTY_INFO_NAME (), { PROPERTY_INFO_WITH_DESC (NM_SETTING_PPP_NOAUTH), @@ -5936,7 +5949,9 @@ static const NMMetaPropertyInfo property_infos_ppp[] = { }, }; -static const NMMetaPropertyInfo property_infos_proxy[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_PROXY +static const NMMetaPropertyInfo property_infos_PROXY[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_PROXY_METHOD), @@ -5968,7 +5983,9 @@ static const NMMetaPropertyInfo property_infos_proxy[] = { }, }; -static const NMMetaPropertyInfo property_infos_team[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_TEAM +static const NMMetaPropertyInfo property_infos_TEAM[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_CONFIG), @@ -5980,7 +5997,9 @@ static const NMMetaPropertyInfo property_infos_team[] = { }, }; -static const NMMetaPropertyInfo property_infos_team_port[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_TEAM_PORT +static const NMMetaPropertyInfo property_infos_TEAM_PORT[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_TEAM_PORT_CONFIG), @@ -5992,7 +6011,9 @@ static const NMMetaPropertyInfo property_infos_team_port[] = { }, }; -static const NMMetaPropertyInfo property_infos_serial[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_SERIAL +static const NMMetaPropertyInfo property_infos_SERIAL[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_SERIAL_BAUD), @@ -6019,7 +6040,9 @@ static const NMMetaPropertyInfo property_infos_serial[] = { }, }; -static const NMMetaPropertyInfo property_infos_tun[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_TUN +static const NMMetaPropertyInfo property_infos_TUN[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_TUN_MODE), @@ -6053,11 +6076,15 @@ static const NMMetaPropertyInfo property_infos_tun[] = { }, }; -static const NMMetaPropertyInfo property_infos_user[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_USER +static const NMMetaPropertyInfo property_infos_USER[] = { PROPERTY_INFO_NAME(), }; -static const NMMetaPropertyInfo property_infos_vlan[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_VLAN +static const NMMetaPropertyInfo property_infos_VLAN[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_VLAN_PARENT), @@ -6092,7 +6119,9 @@ static const NMMetaPropertyInfo property_infos_vlan[] = { }, }; -static const NMMetaPropertyInfo property_infos_vpn[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_VPN +static const NMMetaPropertyInfo property_infos_VPN[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_VPN_SERVICE_TYPE), @@ -6132,7 +6161,9 @@ static const NMMetaPropertyInfo property_infos_vpn[] = { }, }; -static const NMMetaPropertyInfo property_infos_vxlan[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_VXLAN +static const NMMetaPropertyInfo property_infos_VXLAN[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_VXLAN_PARENT), @@ -6200,7 +6231,9 @@ static const NMMetaPropertyInfo property_infos_vxlan[] = { }, }; -static const NMMetaPropertyInfo property_infos_wimax[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_WIMAX +static const NMMetaPropertyInfo property_infos_WIMAX[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_WIMAX_MAC_ADDRESS), @@ -6212,7 +6245,9 @@ static const NMMetaPropertyInfo property_infos_wimax[] = { }, }; -static const NMMetaPropertyInfo property_infos_wired[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_WIRED +static const NMMetaPropertyInfo property_infos_WIRED[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRED_PORT), @@ -6307,7 +6342,9 @@ static const NMMetaPropertyInfo property_infos_wired[] = { }, }; -static const NMMetaPropertyInfo property_infos_wireless[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_WIRELESS +static const NMMetaPropertyInfo property_infos_WIRELESS[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SSID), @@ -6410,7 +6447,9 @@ static const NMMetaPropertyInfo property_infos_wireless[] = { }, }; -static const NMMetaPropertyInfo property_infos_wireless_security[] = { +#undef _CURRENT_NM_META_SETTING_TYPE +#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_WIRELESS_SECURITY +static const NMMetaPropertyInfo property_infos_WIRELESS_SECURITY[] = { PROPERTY_INFO_NAME(), { PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), @@ -6536,171 +6575,133 @@ static const NMMetaPropertyInfo property_infos_wireless_security[] = { }, }; -const NMMetaSettingInfoEditor nm_meta_setting_infos_editor[_NM_META_SETTING_TYPE_NUM] = { - [NM_META_SETTING_TYPE_802_1X] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_802_1X], - .properties = property_infos_802_1x, - .properties_num = G_N_ELEMENTS (property_infos_802_1x), - }, - [NM_META_SETTING_TYPE_ADSL] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_ADSL], - .properties = property_infos_adsl, - .properties_num = G_N_ELEMENTS (property_infos_adsl), - }, - [NM_META_SETTING_TYPE_BLUETOOTH] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_BLUETOOTH], - .properties = property_infos_bluetooth, - .properties_num = G_N_ELEMENTS (property_infos_bluetooth), - }, - [NM_META_SETTING_TYPE_BOND] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_BOND], - .properties = property_infos_bond, - .properties_num = G_N_ELEMENTS (property_infos_bond), - }, - [NM_META_SETTING_TYPE_BRIDGE] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_BRIDGE], - .properties = property_infos_bridge, - .properties_num = G_N_ELEMENTS (property_infos_bridge), - }, - [NM_META_SETTING_TYPE_BRIDGE_PORT] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_BRIDGE_PORT], - .properties = property_infos_bridge_port, - .properties_num = G_N_ELEMENTS (property_infos_bridge_port), - }, - [NM_META_SETTING_TYPE_CDMA] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_CDMA], - .properties = property_infos_cdma, - .properties_num = G_N_ELEMENTS (property_infos_cdma), - }, - [NM_META_SETTING_TYPE_CONNECTION] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_CONNECTION], - .properties = property_infos_connection, - .properties_num = G_N_ELEMENTS (property_infos_connection), - }, - [NM_META_SETTING_TYPE_DCB] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_DCB], - .properties = property_infos_dcb, - .properties_num = G_N_ELEMENTS (property_infos_dcb), - }, - [NM_META_SETTING_TYPE_DUMMY] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_DUMMY], - .properties = property_infos_dummy, - .properties_num = G_N_ELEMENTS (property_infos_dummy), - }, - [NM_META_SETTING_TYPE_GSM] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_GSM], - .properties = property_infos_gsm, - .properties_num = G_N_ELEMENTS (property_infos_gsm), - }, - [NM_META_SETTING_TYPE_INFINIBAND] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_INFINIBAND], - .properties = property_infos_infiniband, - .properties_num = G_N_ELEMENTS (property_infos_infiniband), - }, - [NM_META_SETTING_TYPE_IP4_CONFIG] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_IP4_CONFIG], - .properties = property_infos_ip4_config, - .properties_num = G_N_ELEMENTS (property_infos_ip4_config), - }, - [NM_META_SETTING_TYPE_IP6_CONFIG] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_IP6_CONFIG], - .properties = property_infos_ip6_config, - .properties_num = G_N_ELEMENTS (property_infos_ip6_config), - }, - [NM_META_SETTING_TYPE_IP_TUNNEL] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_IP_TUNNEL], - .properties = property_infos_ip_tunnel, - .properties_num = G_N_ELEMENTS (property_infos_ip_tunnel), - }, - [NM_META_SETTING_TYPE_MACSEC] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_MACSEC], - .properties = property_infos_macsec, - .properties_num = G_N_ELEMENTS (property_infos_macsec), - }, - [NM_META_SETTING_TYPE_MACVLAN] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_MACVLAN], - .properties = property_infos_macvlan, - .properties_num = G_N_ELEMENTS (property_infos_macvlan), - }, - [NM_META_SETTING_TYPE_OLPC_MESH] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_OLPC_MESH], - .properties = property_infos_olpc_mesh, - .properties_num = G_N_ELEMENTS (property_infos_olpc_mesh), - }, - [NM_META_SETTING_TYPE_PPPOE] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_PPPOE], - .properties = property_infos_pppoe, - .properties_num = G_N_ELEMENTS (property_infos_pppoe), - }, - [NM_META_SETTING_TYPE_PPP] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_PPP], - .properties = property_infos_ppp, - .properties_num = G_N_ELEMENTS (property_infos_ppp), - }, - [NM_META_SETTING_TYPE_PROXY] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_PROXY], - .properties = property_infos_proxy, - .properties_num = G_N_ELEMENTS (property_infos_proxy), - }, - [NM_META_SETTING_TYPE_SERIAL] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_SERIAL], - .properties = property_infos_serial, - .properties_num = G_N_ELEMENTS (property_infos_serial), - }, - [NM_META_SETTING_TYPE_TEAM] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_TEAM], - .properties = property_infos_team, - .properties_num = G_N_ELEMENTS (property_infos_team), - }, - [NM_META_SETTING_TYPE_TEAM_PORT] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_TEAM_PORT], - .properties = property_infos_team_port, - .properties_num = G_N_ELEMENTS (property_infos_team_port), - }, - [NM_META_SETTING_TYPE_TUN] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_TUN], - .properties = property_infos_tun, - .properties_num = G_N_ELEMENTS (property_infos_tun), - }, - [NM_META_SETTING_TYPE_USER] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_USER], - .properties = property_infos_user, - .properties_num = G_N_ELEMENTS (property_infos_user), - }, - [NM_META_SETTING_TYPE_VLAN] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_VLAN], - .properties = property_infos_vlan, - .properties_num = G_N_ELEMENTS (property_infos_vlan), - }, - [NM_META_SETTING_TYPE_VPN] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_VPN], - .properties = property_infos_vpn, - .properties_num = G_N_ELEMENTS (property_infos_vpn), - }, - [NM_META_SETTING_TYPE_VXLAN] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_VXLAN], - .properties = property_infos_vxlan, - .properties_num = G_N_ELEMENTS (property_infos_vxlan), - }, - [NM_META_SETTING_TYPE_WIMAX] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_WIMAX], - .properties = property_infos_wimax, - .properties_num = G_N_ELEMENTS (property_infos_wimax), - }, - [NM_META_SETTING_TYPE_WIRED] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_WIRED], - .properties = property_infos_wired, - .properties_num = G_N_ELEMENTS (property_infos_wired), - }, - [NM_META_SETTING_TYPE_WIRELESS] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_WIRELESS], - .properties = property_infos_wireless, - .properties_num = G_N_ELEMENTS (property_infos_wireless), - }, - [NM_META_SETTING_TYPE_WIRELESS_SECURITY] = { - .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_WIRELESS_SECURITY], - .properties = property_infos_wireless_security, - .properties_num = G_N_ELEMENTS (property_infos_wireless_security), - }, +const NMMetaSettingInfoEditor nm_meta_setting_infos_editor[] = { +#define SETTING_INFO(type) \ + [NM_META_SETTING_TYPE_##type] = { \ + .meta_type = &nm_meta_type_setting_info_editor, \ + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_##type], \ + .properties = property_infos_##type, \ + .properties_num = G_N_ELEMENTS (property_infos_##type), \ + } + SETTING_INFO (802_1X), + SETTING_INFO (ADSL), + SETTING_INFO (BLUETOOTH), + SETTING_INFO (BOND), + SETTING_INFO (BRIDGE), + SETTING_INFO (BRIDGE_PORT), + SETTING_INFO (CDMA), + SETTING_INFO (CONNECTION), + SETTING_INFO (DCB), + SETTING_INFO (DUMMY), + SETTING_INFO (GSM), + SETTING_INFO (INFINIBAND), + SETTING_INFO (IP4_CONFIG), + SETTING_INFO (IP6_CONFIG), + SETTING_INFO (IP_TUNNEL), + SETTING_INFO (MACSEC), + SETTING_INFO (MACVLAN), + SETTING_INFO (OLPC_MESH), + SETTING_INFO (PPPOE), + SETTING_INFO (PPP), + SETTING_INFO (PROXY), + SETTING_INFO (SERIAL), + SETTING_INFO (TEAM), + SETTING_INFO (TEAM_PORT), + SETTING_INFO (TUN), + SETTING_INFO (USER), + SETTING_INFO (VLAN), + SETTING_INFO (VPN), + SETTING_INFO (VXLAN), + SETTING_INFO (WIMAX), + SETTING_INFO (WIRED), + SETTING_INFO (WIRELESS), + SETTING_INFO (WIRELESS_SECURITY), }; +/*****************************************************************************/ + +static const char * +_meta_type_setting_info_editor_get_name (const NMMetaAbstractInfo *abstract_info) +{ + return ((const NMMetaSettingInfoEditor *) abstract_info)->general->setting_name; +} + +static const char * +_meta_type_property_info_get_name (const NMMetaAbstractInfo *abstract_info) +{ + return ((const NMMetaPropertyInfo *) abstract_info)->property_name; +} + +static gconstpointer +_meta_type_setting_info_editor_get_fcn (const NMMetaEnvironment *environment, + gpointer environment_user_data, + const NMMetaAbstractInfo *abstract_info, + gpointer target, + NMMetaAccessorGetType get_type, + NMMetaAccessorGetFlags get_flags, + gpointer *out_to_free) +{ + nm_assert (out_to_free && !out_to_free); + g_return_val_if_reached (NULL); +} + +static gconstpointer +_meta_type_property_info_get_fcn (const NMMetaEnvironment *environment, + gpointer environment_user_data, + const NMMetaAbstractInfo *abstract_info, + gpointer target, + NMMetaAccessorGetType get_type, + NMMetaAccessorGetFlags get_flags, + gpointer *out_to_free) +{ + const NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info; + + nm_assert (out_to_free && !out_to_free); + + if (!NM_IN_SET (get_type, + NM_META_ACCESSOR_GET_TYPE_PARSABLE, + NM_META_ACCESSOR_GET_TYPE_PRETTY)) + return NULL; + + return (*out_to_free = info->property_type->get_fcn (environment, environment_user_data, + info, target, + get_type, get_flags)); +} + +static const NMMetaAbstractInfo *const* +_meta_type_setting_info_editor_get_nested (const NMMetaAbstractInfo *abstract_info, + guint *out_len, + gpointer *out_to_free) +{ + const NMMetaSettingInfoEditor *info; + + info = (const NMMetaSettingInfoEditor *) abstract_info; + + NM_SET_OUT (out_len, info->properties_num); + *out_to_free = NULL; + return (const NMMetaAbstractInfo *const*) nm_property_infos_for_setting_type (info->general->meta_type); +} + +static const NMMetaAbstractInfo *const* +_meta_type_property_info_get_nested (const NMMetaAbstractInfo *abstract_info, + guint *out_len, + gpointer *out_to_free) +{ + NM_SET_OUT (out_len, 0); + *out_to_free = NULL; + return NULL; +} + +const NMMetaType nm_meta_type_setting_info_editor = { + .type_name = "setting_info_editor", + .get_name = _meta_type_setting_info_editor_get_name, + .get_nested = _meta_type_setting_info_editor_get_nested, + .get_fcn = _meta_type_setting_info_editor_get_fcn, +}; + +const NMMetaType nm_meta_type_property_info = { + .type_name = "property_info", + .get_name = _meta_type_property_info_get_name, + .get_nested = _meta_type_property_info_get_nested, + .get_fcn = _meta_type_property_info_get_fcn, +}; diff --git a/clients/common/nm-meta-setting-desc.h b/clients/common/nm-meta-setting-desc.h index 3ee63242aa..37ed367812 100644 --- a/clients/common/nm-meta-setting-desc.h +++ b/clients/common/nm-meta-setting-desc.h @@ -24,11 +24,38 @@ #define NM_META_TEXT_HIDDEN "" +typedef enum { + NM_META_TERM_COLOR_NORMAL = 0, + NM_META_TERM_COLOR_BLACK = 1, + NM_META_TERM_COLOR_RED = 2, + NM_META_TERM_COLOR_GREEN = 3, + NM_META_TERM_COLOR_YELLOW = 4, + NM_META_TERM_COLOR_BLUE = 5, + NM_META_TERM_COLOR_MAGENTA = 6, + NM_META_TERM_COLOR_CYAN = 7, + NM_META_TERM_COLOR_WHITE = 8, +} NMMetaTermColor; + +typedef enum { + NM_META_TERM_FORMAT_NORMAL = 0, + NM_META_TERM_FORMAT_BOLD = 1, + NM_META_TERM_FORMAT_DIM = 2, + NM_META_TERM_FORMAT_UNDERLINE = 3, + NM_META_TERM_FORMAT_BLINK = 4, + NM_META_TERM_FORMAT_REVERSE = 5, + NM_META_TERM_FORMAT_HIDDEN = 6, +} NMMetaTermFormat; + typedef enum { NM_META_ACCESSOR_GET_TYPE_PRETTY, NM_META_ACCESSOR_GET_TYPE_PARSABLE, } NMMetaAccessorGetType; +typedef enum { + NM_META_ACCESSOR_GET_FLAGS_NONE = 0, + NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS = (1LL << 0), +} NMMetaAccessorGetFlags; + 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), @@ -45,36 +72,40 @@ typedef enum { NM_META_PROPERTY_TYPE_MAC_MODE_INFINIBAND, } NMMetaPropertyTypeMacMode; +typedef struct _NMMetaEnvironment NMMetaEnvironment; +typedef struct _NMMetaType NMMetaType; +typedef struct _NMMetaAbstractInfo NMMetaAbstractInfo; typedef struct _NMMetaSettingInfoEditor NMMetaSettingInfoEditor; -typedef struct _NMMetaPropertyInfo NMMetaPropertyInfo; -typedef struct _NMMetaPropertyType NMMetaPropertyType; -typedef struct _NMMetaPropertyTypData NMMetaPropertyTypData; +typedef struct _NMMetaPropertyInfo NMMetaPropertyInfo; +typedef struct _NMMetaPropertyType NMMetaPropertyType; +typedef struct _NMMetaPropertyTypData NMMetaPropertyTypData; struct _NMMetaPropertyType { - const char *(*describe_fcn) (const NMMetaSettingInfoEditor *setting_info, - const NMMetaPropertyInfo *property_info, + const char *(*describe_fcn) (const NMMetaPropertyInfo *property_info, char **out_to_free); - char *(*get_fcn) (const NMMetaSettingInfoEditor *setting_info, + char *(*get_fcn) (const NMMetaEnvironment *environment, + gpointer environment_user_data, const NMMetaPropertyInfo *property_info, NMSetting *setting, NMMetaAccessorGetType get_type, - gboolean show_secrets); - gboolean (*set_fcn) (const NMMetaSettingInfoEditor *setting_info, + NMMetaAccessorGetFlags get_flags); + gboolean (*set_fcn) (const NMMetaEnvironment *environment, + gpointer environment_user_data, const NMMetaPropertyInfo *property_info, NMSetting *setting, const char *value, GError **error); - gboolean (*remove_fcn) (const NMMetaSettingInfoEditor *setting_info, + gboolean (*remove_fcn) (const NMMetaEnvironment *environment, + gpointer environment_user_data, const NMMetaPropertyInfo *property_info, NMSetting *setting, const char *option, guint32 idx, GError **error); - const char *const*(*values_fcn) (const NMMetaSettingInfoEditor *setting_info, - const NMMetaPropertyInfo *property_info, + const char *const*(*values_fcn) (const NMMetaPropertyInfo *property_info, char ***out_to_free); }; @@ -103,6 +134,10 @@ struct _NMMetaPropertyTypData { }; struct _NMMetaPropertyInfo { + const NMMetaType *meta_type; + + const NMMetaSettingInfoEditor *setting_info; + const char *property_name; /* the property list for now must contain as first field the @@ -122,6 +157,7 @@ struct _NMMetaPropertyInfo { }; struct _NMMetaSettingInfoEditor { + const NMMetaType *meta_type; const NMMetaSettingInfo *general; /* the order of the properties matter. The first *must* be the * "name", and then the order is as they are listed by default. */ @@ -129,9 +165,57 @@ struct _NMMetaSettingInfoEditor { guint properties_num; }; +struct _NMMetaType { + const char *type_name; + const char *(*get_name) (const NMMetaAbstractInfo *abstract_info); + const NMMetaAbstractInfo *const*(*get_nested) (const NMMetaAbstractInfo *abstract_info, + guint *out_len, + gpointer *out_to_free); + gconstpointer (*get_fcn) (const NMMetaEnvironment *environment, + gpointer environment_user_data, + const NMMetaAbstractInfo *info, + gpointer target, + NMMetaAccessorGetType get_type, + NMMetaAccessorGetFlags get_flags, + gpointer *out_to_free); +}; + +struct _NMMetaAbstractInfo { + union { + const NMMetaType *meta_type; + union { + NMMetaSettingInfoEditor setting_info; + NMMetaPropertyInfo property_info; + } as; + }; +}; + +extern const NMMetaType nm_meta_type_setting_info_editor; +extern const NMMetaType nm_meta_type_property_info; + extern const NMMetaSettingInfoEditor nm_meta_setting_infos_editor[_NM_META_SETTING_TYPE_NUM]; -/* FIXME: don't expose this function on it's own, at least not from this file. */ -const char *nmc_bond_validate_mode (const char *mode, GError **error); +/*****************************************************************************/ + +typedef enum { + NM_META_ENV_WARN_LEVEL_INFO, + NM_META_ENV_WARN_LEVEL_WARN, +} NMMetaEnvWarnLevel; + +/* the settings-meta data is supposed to be independent of an actual client + * implementation. Hence, there is a need for hooks to the meta-data. + * The meta-data handlers may call back to the enviroment with certain + * actions. */ +struct _NMMetaEnvironment { + + void (*warn_fcn) (const NMMetaEnvironment *environment, + gpointer environment_user_data, + NMMetaEnvWarnLevel warn_level, + const char *fmt_l10n, /* the untranslated format string, but it is marked for translation using N_(). */ + va_list ap); + +}; + +/*****************************************************************************/ #endif /* __NM_META_SETTING_DESC_H__ */ diff --git a/clients/common/settings-docs.c.in b/clients/common/settings-docs.c.in new file mode 100644 index 0000000000..1ac7f998a0 --- /dev/null +++ b/clients/common/settings-docs.c.in @@ -0,0 +1,340 @@ +/* Generated file. Do not edit. */ + +#define DESCRIBE_DOC_NM_SETTING_OLPC_MESH_CHANNEL "Channel on which the mesh network to join is located." +#define DESCRIBE_DOC_NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS "Anycast DHCP MAC address used when requesting an IP address via DHCP. The specific anycast address used determines which DHCP server class answers the request." +#define DESCRIBE_DOC_NM_SETTING_OLPC_MESH_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_OLPC_MESH_SSID "SSID of the mesh network to join." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_BAND "802.11 frequency band of the network. One of \"a\" for 5GHz 802.11a or \"bg\" for 2.4GHz 802.11. This will lock associations to the Wi-Fi network to the specific band, i.e. if \"a\" is specified, the device will not associate with the same network in the 2.4GHz band even if the network's settings are compatible. This setting depends on specific driver capability and may not work with all drivers." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_BSSID "If specified, directs the device to only associate with the given access point. This capability is highly driver dependent and not supported by all devices. Note: this property does not control the BSSID used when creating an Ad-Hoc network and is unlikely to in the future." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_CHANNEL "Wireless channel to use for the Wi-Fi connection. The device will only join (or create for Ad-Hoc networks) a Wi-Fi network on the specified channel. Because channel numbers overlap between bands, this property also requires the \"band\" property to be set." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS "If specified, request that the device use this MAC address instead. This is known as MAC cloning or spoofing. Beside explicitly specifing a MAC address, the special values \"preserve\", \"permanent\", \"random\" and \"stable\" are supported. \"preserve\" means not to touch the MAC address on activation. \"permanent\" means to use the permanent hardware address of the device. \"random\" creates a random MAC address on each connect. \"stable\" creates a hashed MAC address based on connection.stable-id and a machine dependent key. If unspecified, the value can be overwritten via global defaults, see manual of NetworkManager.conf. If still unspecified, it defaults to \"preserve\" (older versions of NetworkManager may use a different default value). On D-Bus, this field is expressed as \"assigned-mac-address\" or the deprecated \"cloned-mac-address\"." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK "With \"cloned-mac-address\" setting \"random\" or \"stable\", by default all bits of the MAC address are scrambled and a locally-administered, unicast MAC address is created. This property allows to specify that certain bits are fixed. Note that the least significant bit of the first MAC address will always be unset to create a unicast MAC address. If the property is NULL, it is eligible to be overwritten by a default connection setting. If the value is still NULL or an empty string, the default is to create a locally-administered, unicast MAC address. If the value contains one MAC address, this address is used as mask. The set bits of the mask are to be filled with the current MAC address of the device, while the unset bits are subject to randomization. Setting \"FE:FF:FF:00:00:00\" means to preserve the OUI of the current MAC address and only randomize the lower 3 bytes using the \"random\" or \"stable\" algorithm. If the value contains one additional MAC address after the mask, this address is used instead of the current MAC address to fill the bits that shall not be randomized. For example, a value of \"FE:FF:FF:00:00:00 68:F7:28:00:00:00\" will set the OUI of the MAC address to 68:F7:28, while the lower bits are randomized. A value of \"02:00:00:00:00:00 00:00:00:00:00:00\" will create a fully scrambled globally-administered, burned-in MAC address. If the value contains more then one additional MAC addresses, one of them is chosen randomly. For example, \"02:00:00:00:00:00 00:00:00:00:00:00 02:00:00:00:00:00\" will create a fully scrambled MAC address, randomly locally or globally administered." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_HIDDEN "If TRUE, indicates this network is a non-broadcasting network that hides its SSID. In this case various workarounds may take place, such as probe-scanning the SSID for more reliable network discovery. However, these workarounds expose inherent insecurities with hidden SSID networks, and thus hidden SSID networks should be used with caution." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_MAC_ADDRESS "If specified, this connection will only apply to the Wi-Fi device whose permanent MAC address matches. This property does not change the MAC address of the device (i.e. MAC spoofing)." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST "A list of permanent MAC addresses of Wi-Fi devices to which this connection should never apply. Each MAC address should be given in the standard hex-digits-and-colons notation (eg \"00:11:22:33:44:55\")." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION "One of NM_SETTING_MAC_RANDOMIZATION_DEFAULT (0) (never randomize unless the user has set a global default to randomize and the supplicant supports randomization), NM_SETTING_MAC_RANDOMIZATION_NEVER (1) (never randomize the MAC address), or NM_SETTING_MAC_RANDOMIZATION_ALWAYS (2) (always randomize the MAC address). This property is deprecated for 'cloned-mac-address'. Deprecated: 1" +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_MODE "Wi-Fi network mode; one of \"infrastructure\", \"adhoc\" or \"ap\". If blank, infrastructure is assumed." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_MTU "If non-zero, only transmit packets of the specified size or smaller, breaking larger packets up into multiple Ethernet frames." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_POWERSAVE "One of NM_SETTING_WIRELESS_POWERSAVE_DISABLE (2) (disable Wi-Fi power saving), NM_SETTING_WIRELESS_POWERSAVE_ENABLE (3) (enable Wi-Fi power saving), NM_SETTING_WIRELESS_POWERSAVE_IGNORE (1) (don't touch currently configure setting) or NM_SETTING_WIRELESS_POWERSAVE_DEFAULT (0) (use the globally configured value). All other values are reserved." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_RATE "If non-zero, directs the device to only use the specified bitrate for communication with the access point. Units are in Kb/s, ie 5500 = 5.5 Mbit/s. This property is highly driver dependent and not all devices support setting a static bitrate." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SEEN_BSSIDS "A list of BSSIDs (each BSSID formatted as a MAC address like \"00:11:22:33:44:55\") that have been detected as part of the Wi-Fi network. NetworkManager internally tracks previously seen BSSIDs. The property is only meant for reading and reflects the BSSID list of NetworkManager. The changes you make to this property will not be preserved." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SSID "SSID of the Wi-Fi network. Must be specified." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_TX_POWER "If non-zero, directs the device to use the specified transmit power. Units are dBm. This property is highly driver dependent and not all devices support setting a static transmit power." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_AUTH_ALG "When WEP is used (ie, key-mgmt = \"none\" or \"ieee8021x\") indicate the 802.11 authentication algorithm required by the AP here. One of \"open\" for Open System, \"shared\" for Shared Key, or \"leap\" for Cisco LEAP. When using Cisco LEAP (ie, key-mgmt = \"ieee8021x\" and auth-alg = \"leap\") the \"leap-username\" and \"leap-password\" properties must be specified." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_GROUP "A list of group/broadcast encryption algorithms which prevents connections to Wi-Fi networks that do not utilize one of the algorithms in the list. For maximum compatibility leave this property empty. Each list element may be one of \"wep40\", \"wep104\", \"tkip\", or \"ccmp\"." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_KEY_MGMT "Key management used for the connection. One of \"none\" (WEP), \"ieee8021x\" (Dynamic WEP), \"wpa-none\" (Ad-Hoc WPA-PSK), \"wpa-psk\" (infrastructure WPA-PSK), or \"wpa-eap\" (WPA-Enterprise). This property must be set for any Wi-Fi connection that uses security." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD "The login password for legacy LEAP connections (ie, key-mgmt = \"ieee8021x\" and auth-alg = \"leap\")." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS "Flags indicating how to handle the \"leap-password\" property." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME "The login username for legacy LEAP connections (ie, key-mgmt = \"ieee8021x\" and auth-alg = \"leap\")." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_PAIRWISE "A list of pairwise encryption algorithms which prevents connections to Wi-Fi networks that do not utilize one of the algorithms in the list. For maximum compatibility leave this property empty. Each list element may be one of \"tkip\" or \"ccmp\"." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_PROTO "List of strings specifying the allowed WPA protocol versions to use. Each element may be one \"wpa\" (allow WPA) or \"rsn\" (allow WPA2/RSN). If not specified, both WPA and RSN connections are allowed." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_PSK "Pre-Shared-Key for WPA networks. If the key is 64-characters long, it must contain only hexadecimal characters and is interpreted as a hexadecimal WPA key. Otherwise, the key must be between 8 and 63 ASCII characters (as specified in the 802.11i standard) and is interpreted as a WPA passphrase, and is hashed to derive the actual WPA-PSK used when connecting to the Wi-Fi network." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS "Flags indicating how to handle the \"psk\" property." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS "Flags indicating how to handle the \"wep-key0\", \"wep-key1\", \"wep-key2\", and \"wep-key3\" properties." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE "Controls the interpretation of WEP keys. Allowed values are NM_WEP_KEY_TYPE_KEY (1), in which case the key is either a 10- or 26-character hexadecimal string, or a 5- or 13-character ASCII password; or NM_WEP_KEY_TYPE_PASSPHRASE (2), in which case the passphrase is provided as a string and will be hashed using the de-facto MD5 method to derive the actual WEP key." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_WEP_KEY0 "Index 0 WEP key. This is the WEP key used in most networks. See the \"wep-key-type\" property for a description of how this key is interpreted." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_WEP_KEY1 "Index 1 WEP key. This WEP index is not used by most networks. See the \"wep-key-type\" property for a description of how this key is interpreted." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_WEP_KEY2 "Index 2 WEP key. This WEP index is not used by most networks. See the \"wep-key-type\" property for a description of how this key is interpreted." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_WEP_KEY3 "Index 3 WEP key. This WEP index is not used by most networks. See the \"wep-key-type\" property for a description of how this key is interpreted." +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX "When static WEP is used (ie, key-mgmt = \"none\") and a non-default WEP key index is used by the AP, put that WEP key index here. Valid values are 0 (default key) through 3. Note that some consumer access points (like the Linksys WRT54G) number the keys 1 - 4." +#define DESCRIBE_DOC_NM_SETTING_802_1X_ALTSUBJECT_MATCHES "List of strings to be matched against the altSubjectName of the certificate presented by the authentication server. If the list is empty, no verification of the server certificate's altSubjectName is performed." +#define DESCRIBE_DOC_NM_SETTING_802_1X_ANONYMOUS_IDENTITY "Anonymous identity string for EAP authentication methods. Used as the unencrypted identity with EAP types that support different tunneled identity like EAP-TTLS." +#define DESCRIBE_DOC_NM_SETTING_802_1X_AUTH_TIMEOUT "A timeout for the authentication. Zero means the global default; if the global default is not set, the authentication timeout is 25 seconds." +#define DESCRIBE_DOC_NM_SETTING_802_1X_CA_CERT "Contains the CA certificate if used by the EAP method specified in the \"eap\" property. Certificate data is specified using a \"scheme\"; two are currently supported: blob and path. When using the blob scheme (which is backwards compatible with NM 0.7.x) this property should be set to the certificate's DER encoded data. When using the path scheme, this property should be set to the full UTF-8 encoded path of the certificate, prefixed with the string \"file://\" and ending with a terminating NUL byte. This property can be unset even if the EAP method supports CA certificates, but this allows man-in-the-middle attacks and is NOT recommended." +#define DESCRIBE_DOC_NM_SETTING_802_1X_CA_CERT_PASSWORD "The password used to access the CA certificate stored in \"ca-cert\" property. Only makes sense if the certificate is stored on a PKCS#11 token that requires a login." +#define DESCRIBE_DOC_NM_SETTING_802_1X_CA_CERT_PASSWORD_FLAGS "Flags indicating how to handle the \"ca-cert-password\" property." +#define DESCRIBE_DOC_NM_SETTING_802_1X_CA_PATH "UTF-8 encoded path to a directory containing PEM or DER formatted certificates to be added to the verification chain in addition to the certificate specified in the \"ca-cert\" property." +#define DESCRIBE_DOC_NM_SETTING_802_1X_CLIENT_CERT "Contains the client certificate if used by the EAP method specified in the \"eap\" property. Certificate data is specified using a \"scheme\"; two are currently supported: blob and path. When using the blob scheme (which is backwards compatible with NM 0.7.x) this property should be set to the certificate's DER encoded data. When using the path scheme, this property should be set to the full UTF-8 encoded path of the certificate, prefixed with the string \"file://\" and ending with a terminating NUL byte." +#define DESCRIBE_DOC_NM_SETTING_802_1X_CLIENT_CERT_PASSWORD "The password used to access the client certificate stored in \"client-cert\" property. Only makes sense if the certificate is stored on a PKCS#11 token that requires a login." +#define DESCRIBE_DOC_NM_SETTING_802_1X_CLIENT_CERT_PASSWORD_FLAGS "Flags indicating how to handle the \"client-cert-password\" property." +#define DESCRIBE_DOC_NM_SETTING_802_1X_DOMAIN_SUFFIX_MATCH "Constraint for server domain name. If set, this FQDN is used as a suffix match requirement for dNSName element(s) of the certificate presented by the authentication server. If a matching dNSName is found, this constraint is met. If no dNSName values are present, this constraint is matched against SubjectName CN using same suffix match comparison." +#define DESCRIBE_DOC_NM_SETTING_802_1X_EAP "The allowed EAP method to be used when authenticating to the network with 802.1x. Valid methods are: \"leap\", \"md5\", \"tls\", \"peap\", \"ttls\", \"pwd\", and \"fast\". Each method requires different configuration using the properties of this setting; refer to wpa_supplicant documentation for the allowed combinations." +#define DESCRIBE_DOC_NM_SETTING_802_1X_IDENTITY "Identity string for EAP authentication methods. Often the user's user or login name." +#define DESCRIBE_DOC_NM_SETTING_802_1X_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PAC_FILE "UTF-8 encoded file path containing PAC for EAP-FAST." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PASSWORD "UTF-8 encoded password used for EAP authentication methods. If both the \"password\" property and the \"password-raw\" property are specified, \"password\" is preferred." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PASSWORD_FLAGS "Flags indicating how to handle the \"password\" property." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PASSWORD_RAW "Password used for EAP authentication methods, given as a byte array to allow passwords in other encodings than UTF-8 to be used. If both the \"password\" property and the \"password-raw\" property are specified, \"password\" is preferred." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PASSWORD_RAW_FLAGS "Flags indicating how to handle the \"password-raw\" property." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PHASE1_AUTH_FLAGS "Specifies authentication flags to use in \"phase 1\" outer authentication using NMSetting8021xAuthFlags options. The invidual TLS versions can be explicitly disabled. If a certain TLS disable flag is not set, it is up to the supplicant to allow or forbid it. The TLS options map to tls_disable_tlsv1_x settings. See the wpa_supplicant documentation for more details." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING "Enables or disables in-line provisioning of EAP-FAST credentials when FAST is specified as the EAP method in the \"eap\" property. Recognized values are \"0\" (disabled), \"1\" (allow unauthenticated provisioning), \"2\" (allow authenticated provisioning), and \"3\" (allow both authenticated and unauthenticated provisioning). See the wpa_supplicant documentation for more details." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PHASE1_PEAPLABEL "Forces use of the new PEAP label during key derivation. Some RADIUS servers may require forcing the new PEAP label to interoperate with PEAPv1. Set to \"1\" to force use of the new PEAP label. See the wpa_supplicant documentation for more details." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PHASE1_PEAPVER "Forces which PEAP version is used when PEAP is set as the EAP method in the \"eap\" property. When unset, the version reported by the server will be used. Sometimes when using older RADIUS servers, it is necessary to force the client to use a particular PEAP version. To do so, this property may be set to \"0\" or \"1\" to force that specific PEAP version." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES "List of strings to be matched against the altSubjectName of the certificate presented by the authentication server during the inner \"phase 2\" authentication. If the list is empty, no verification of the server certificate's altSubjectName is performed." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PHASE2_AUTH "Specifies the allowed \"phase 2\" inner non-EAP authentication methods when an EAP method that uses an inner TLS tunnel is specified in the \"eap\" property. Recognized non-EAP \"phase 2\" methods are \"pap\", \"chap\", \"mschap\", \"mschapv2\", \"gtc\", \"otp\", \"md5\", and \"tls\". Each \"phase 2\" inner method requires specific parameters for successful authentication; see the wpa_supplicant documentation for more details." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PHASE2_AUTHEAP "Specifies the allowed \"phase 2\" inner EAP-based authentication methods when an EAP method that uses an inner TLS tunnel is specified in the \"eap\" property. Recognized EAP-based \"phase 2\" methods are \"md5\", \"mschapv2\", \"otp\", \"gtc\", and \"tls\". Each \"phase 2\" inner method requires specific parameters for successful authentication; see the wpa_supplicant documentation for more details." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PHASE2_CA_CERT "Contains the \"phase 2\" CA certificate if used by the EAP method specified in the \"phase2-auth\" or \"phase2-autheap\" properties. Certificate data is specified using a \"scheme\"; two are currently supported: blob and path. When using the blob scheme (which is backwards compatible with NM 0.7.x) this property should be set to the certificate's DER encoded data. When using the path scheme, this property should be set to the full UTF-8 encoded path of the certificate, prefixed with the string \"file://\" and ending with a terminating NUL byte. This property can be unset even if the EAP method supports CA certificates, but this allows man-in-the-middle attacks and is NOT recommended." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PHASE2_CA_CERT_PASSWORD "The password used to access the \"phase2\" CA certificate stored in \"phase2-ca-cert\" property. Only makes sense if the certificate is stored on a PKCS#11 token that requires a login." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PHASE2_CA_CERT_PASSWORD_FLAGS "Flags indicating how to handle the \"phase2-ca-cert-password\" property." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PHASE2_CA_PATH "UTF-8 encoded path to a directory containing PEM or DER formatted certificates to be added to the verification chain in addition to the certificate specified in the \"phase2-ca-cert\" property." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PHASE2_CLIENT_CERT "Contains the \"phase 2\" client certificate if used by the EAP method specified in the \"phase2-auth\" or \"phase2-autheap\" properties. Certificate data is specified using a \"scheme\"; two are currently supported: blob and path. When using the blob scheme (which is backwards compatible with NM 0.7.x) this property should be set to the certificate's DER encoded data. When using the path scheme, this property should be set to the full UTF-8 encoded path of the certificate, prefixed with the string \"file://\" and ending with a terminating NUL byte. This property can be unset even if the EAP method supports CA certificates, but this allows man-in-the-middle attacks and is NOT recommended." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PHASE2_CLIENT_CERT_PASSWORD "The password used to access the \"phase2\" client certificate stored in \"phase2-client-cert\" property. Only makes sense if the certificate is stored on a PKCS#11 token that requires a login." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PHASE2_CLIENT_CERT_PASSWORD_FLAGS "Flags indicating how to handle the \"phase2-client-cert-password\" property." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PHASE2_DOMAIN_SUFFIX_MATCH "Constraint for server domain name. If set, this FQDN is used as a suffix match requirement for dNSName element(s) of the certificate presented by the authentication server during the inner \"phase 2\" authentication. If a matching dNSName is found, this constraint is met. If no dNSName values are present, this constraint is matched against SubjectName CN using same suffix match comparison." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PHASE2_PRIVATE_KEY "Contains the \"phase 2\" inner private key when the \"phase2-auth\" or \"phase2-autheap\" property is set to \"tls\". Key data is specified using a \"scheme\"; two are currently supported: blob and path. When using the blob scheme and private keys, this property should be set to the key's encrypted PEM encoded data. When using private keys with the path scheme, this property should be set to the full UTF-8 encoded path of the key, prefixed with the string \"file://\" and ending with a terminating NUL byte. When using PKCS#12 format private keys and the blob scheme, this property should be set to the PKCS#12 data and the \"phase2-private-key-password\" property must be set to password used to decrypt the PKCS#12 certificate and key. When using PKCS#12 files and the path scheme, this property should be set to the full UTF-8 encoded path of the key, prefixed with the string \"file://\" and ending with a terminating NUL byte, and as with the blob scheme the \"phase2-private-key-password\" property must be set to the password used to decode the PKCS#12 private key and certificate." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD "The password used to decrypt the \"phase 2\" private key specified in the \"phase2-private-key\" property when the private key either uses the path scheme, or is a PKCS#12 format key." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS "Flags indicating how to handle the \"phase2-private-key-password\" property." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH "Substring to be matched against the subject of the certificate presented by the authentication server during the inner \"phase 2\" authentication. When unset, no verification of the authentication server certificate's subject is performed. This property provides little security, if any, and its use is deprecated in favor of NMSetting8021x:phase2-domain-suffix-match." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PIN "PIN used for EAP authentication methods." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PIN_FLAGS "Flags indicating how to handle the \"pin\" property." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PRIVATE_KEY "Contains the private key when the \"eap\" property is set to \"tls\". Key data is specified using a \"scheme\"; two are currently supported: blob and path. When using the blob scheme and private keys, this property should be set to the key's encrypted PEM encoded data. When using private keys with the path scheme, this property should be set to the full UTF-8 encoded path of the key, prefixed with the string \"file://\" and ending with a terminating NUL byte. When using PKCS#12 format private keys and the blob scheme, this property should be set to the PKCS#12 data and the \"private-key-password\" property must be set to password used to decrypt the PKCS#12 certificate and key. When using PKCS#12 files and the path scheme, this property should be set to the full UTF-8 encoded path of the key, prefixed with the string \"file://\" and ending with a terminating NUL byte, and as with the blob scheme the \"private-key-password\" property must be set to the password used to decode the PKCS#12 private key and certificate. WARNING: \"private-key\" is not a \"secret\" property, and thus unencrypted private key data using the BLOB scheme may be readable by unprivileged users. Private keys should always be encrypted with a private key password to prevent unauthorized access to unencrypted private key data." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD "The password used to decrypt the private key specified in the \"private-key\" property when the private key either uses the path scheme, or if the private key is a PKCS#12 format key." +#define DESCRIBE_DOC_NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS "Flags indicating how to handle the \"private-key-password\" property." +#define DESCRIBE_DOC_NM_SETTING_802_1X_SUBJECT_MATCH "Substring to be matched against the subject of the certificate presented by the authentication server. When unset, no verification of the authentication server certificate's subject is performed. This property provides little security, if any, and its use is deprecated in favor of NMSetting8021x:domain-suffix-match." +#define DESCRIBE_DOC_NM_SETTING_802_1X_SYSTEM_CA_CERTS "When TRUE, overrides the \"ca-path\" and \"phase2-ca-path\" properties using the system CA directory specified at configure time with the --system-ca-path switch. The certificates in this directory are added to the verification chain in addition to any certificates specified by the \"ca-cert\" and \"phase2-ca-cert\" properties. If the path provided with --system-ca-path is rather a file name (bundle of trusted CA certificates), it overrides \"ca-cert\" and \"phase2-ca-cert\" properties instead (sets ca_cert/ca_cert2 options for wpa_supplicant)." +#define DESCRIBE_DOC_NM_SETTING_WIRED_AUTO_NEGOTIATE "If TRUE, enforce auto-negotiation of port speed and duplex mode. If FALSE, \"speed\" and \"duplex\" properties should be both set or link configuration will be skipped." +#define DESCRIBE_DOC_NM_SETTING_WIRED_CLONED_MAC_ADDRESS "If specified, request that the device use this MAC address instead. This is known as MAC cloning or spoofing. Beside explicitly specifing a MAC address, the special values \"preserve\", \"permanent\", \"random\" and \"stable\" are supported. \"preserve\" means not to touch the MAC address on activation. \"permanent\" means to use the permanent hardware address of the device. \"random\" creates a random MAC address on each connect. \"stable\" creates a hashed MAC address based on connection.stable-id and a machine dependent key. If unspecified, the value can be overwritten via global defaults, see manual of NetworkManager.conf. If still unspecified, it defaults to \"preserve\" (older versions of NetworkManager may use a different default value). On D-Bus, this field is expressed as \"assigned-mac-address\" or the deprecated \"cloned-mac-address\"." +#define DESCRIBE_DOC_NM_SETTING_WIRED_DUPLEX "Can be specified only when \"auto-negotiate\" is \"off\". In that case, statically configures the device to use that specified duplex mode, either \"half\" or \"full\". Must be set together with the \"speed\" property if specified. Before specifying a duplex mode be sure your device supports it." +#define DESCRIBE_DOC_NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK "With \"cloned-mac-address\" setting \"random\" or \"stable\", by default all bits of the MAC address are scrambled and a locally-administered, unicast MAC address is created. This property allows to specify that certain bits are fixed. Note that the least significant bit of the first MAC address will always be unset to create a unicast MAC address. If the property is NULL, it is eligible to be overwritten by a default connection setting. If the value is still NULL or an empty string, the default is to create a locally-administered, unicast MAC address. If the value contains one MAC address, this address is used as mask. The set bits of the mask are to be filled with the current MAC address of the device, while the unset bits are subject to randomization. Setting \"FE:FF:FF:00:00:00\" means to preserve the OUI of the current MAC address and only randomize the lower 3 bytes using the \"random\" or \"stable\" algorithm. If the value contains one additional MAC address after the mask, this address is used instead of the current MAC address to fill the bits that shall not be randomized. For example, a value of \"FE:FF:FF:00:00:00 68:F7:28:00:00:00\" will set the OUI of the MAC address to 68:F7:28, while the lower bits are randomized. A value of \"02:00:00:00:00:00 00:00:00:00:00:00\" will create a fully scrambled globally-administered, burned-in MAC address. If the value contains more then one additional MAC addresses, one of them is chosen randomly. For example, \"02:00:00:00:00:00 00:00:00:00:00:00 02:00:00:00:00:00\" will create a fully scrambled MAC address, randomly locally or globally administered." +#define DESCRIBE_DOC_NM_SETTING_WIRED_MAC_ADDRESS "If specified, this connection will only apply to the Ethernet device whose permanent MAC address matches. This property does not change the MAC address of the device (i.e. MAC spoofing)." +#define DESCRIBE_DOC_NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST "If specified, this connection will never apply to the Ethernet device whose permanent MAC address matches an address in the list. Each MAC address is in the standard hex-digits-and-colons notation (00:11:22:33:44:55)." +#define DESCRIBE_DOC_NM_SETTING_WIRED_MTU "If non-zero, only transmit packets of the specified size or smaller, breaking larger packets up into multiple Ethernet frames." +#define DESCRIBE_DOC_NM_SETTING_WIRED_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_WIRED_PORT "Specific port type to use if multiple the device supports multiple attachment methods. One of \"tp\" (Twisted Pair), \"aui\" (Attachment Unit Interface), \"bnc\" (Thin Ethernet) or \"mii\" (Media Independent Interface. If the device supports only one port type, this setting is ignored." +#define DESCRIBE_DOC_NM_SETTING_WIRED_S390_NETTYPE "s390 network device type; one of \"qeth\", \"lcs\", or \"ctc\", representing the different types of virtual network devices available on s390 systems." +#define DESCRIBE_DOC_NM_SETTING_WIRED_S390_OPTIONS "Dictionary of key/value pairs of s390-specific device options. Both keys and values must be strings. Allowed keys include \"portno\", \"layer2\", \"portname\", \"protocol\", among others. Key names must contain only alphanumeric characters (ie, [a-zA-Z0-9])." +#define DESCRIBE_DOC_NM_SETTING_WIRED_S390_SUBCHANNELS "Identifies specific subchannels that this network device uses for communication with z/VM or s390 host. Like the \"mac-address\" property for non-z/VM devices, this property can be used to ensure this connection only applies to the network device that uses these subchannels. The list should contain exactly 3 strings, and each string may only be composed of hexadecimal characters and the period (.) character." +#define DESCRIBE_DOC_NM_SETTING_WIRED_SPEED "Can be set to a value grater than zero only when \"auto-negotiate\" is \"off\". In that case, statically configures the device to use that specified speed. In Mbit/s, ie 100 == 100Mbit/s. Must be set together with the \"duplex\" property when non-zero. Before specifying a speed value be sure your device supports it." +#define DESCRIBE_DOC_NM_SETTING_WIRED_WAKE_ON_LAN "The NMSettingWiredWakeOnLan options to enable. Not all devices support all options. May be any combination of NM_SETTING_WIRED_WAKE_ON_LAN_PHY (0x2), NM_SETTING_WIRED_WAKE_ON_LAN_UNICAST (0x4), NM_SETTING_WIRED_WAKE_ON_LAN_MULTICAST (0x8), NM_SETTING_WIRED_WAKE_ON_LAN_BROADCAST (0x10), NM_SETTING_WIRED_WAKE_ON_LAN_ARP (0x20), NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC (0x40) or the special values NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT (0x1) (to use global settings) and NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE (0x8000) (to disable management of Wake-on-LAN in NetworkManager)." +#define DESCRIBE_DOC_NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD "If specified, the password used with magic-packet-based Wake-on-LAN, represented as an Ethernet MAC address. If NULL, no password will be required." +#define DESCRIBE_DOC_NM_SETTING_ADSL_ENCAPSULATION "Encapsulation of ADSL connection. Can be \"vcmux\" or \"llc\"." +#define DESCRIBE_DOC_NM_SETTING_ADSL_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_ADSL_PASSWORD "Password used to authenticate with the ADSL service." +#define DESCRIBE_DOC_NM_SETTING_ADSL_PASSWORD_FLAGS "Flags indicating how to handle the \"password\" property." +#define DESCRIBE_DOC_NM_SETTING_ADSL_PROTOCOL "ADSL connection protocol. Can be \"pppoa\", \"pppoe\" or \"ipoatm\"." +#define DESCRIBE_DOC_NM_SETTING_ADSL_USERNAME "Username used to authenticate with the ADSL service." +#define DESCRIBE_DOC_NM_SETTING_ADSL_VCI "VCI of ADSL connection" +#define DESCRIBE_DOC_NM_SETTING_ADSL_VPI "VPI of ADSL connection" +#define DESCRIBE_DOC_NM_SETTING_BLUETOOTH_BDADDR "The Bluetooth address of the device." +#define DESCRIBE_DOC_NM_SETTING_BLUETOOTH_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_BLUETOOTH_TYPE "Either \"dun\" for Dial-Up Networking connections or \"panu\" for Personal Area Networking connections to devices supporting the NAP profile." +#define DESCRIBE_DOC_NM_SETTING_BOND_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_BOND_OPTIONS "Dictionary of key/value pairs of bonding options. Both keys and values must be strings. Option names must contain only alphanumeric characters (ie, [a-zA-Z0-9])." +#define DESCRIBE_DOC_NM_SETTING_BRIDGE_AGEING_TIME "The Ethernet MAC address aging time, in seconds." +#define DESCRIBE_DOC_NM_SETTING_BRIDGE_FORWARD_DELAY "The Spanning Tree Protocol (STP) forwarding delay, in seconds." +#define DESCRIBE_DOC_NM_SETTING_BRIDGE_HELLO_TIME "The Spanning Tree Protocol (STP) hello time, in seconds." +#define DESCRIBE_DOC_NM_SETTING_BRIDGE_MAC_ADDRESS "If specified, the MAC address of bridge. When creating a new bridge, this MAC address will be set. When matching an existing (outside NetworkManager created) bridge, this MAC address must match." +#define DESCRIBE_DOC_NM_SETTING_BRIDGE_MAX_AGE "The Spanning Tree Protocol (STP) maximum message age, in seconds." +#define DESCRIBE_DOC_NM_SETTING_BRIDGE_MULTICAST_SNOOPING "Controls whether IGMP snooping is enabled for this bridge. Note that if snooping was automatically disabled due to hash collisions, the system may refuse to enable the feature until the collisions are resolved." +#define DESCRIBE_DOC_NM_SETTING_BRIDGE_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_BRIDGE_PRIORITY "Sets the Spanning Tree Protocol (STP) priority for this bridge. Lower values are \"better\"; the lowest priority bridge will be elected the root bridge." +#define DESCRIBE_DOC_NM_SETTING_BRIDGE_STP "Controls whether Spanning Tree Protocol (STP) is enabled for this bridge." +#define DESCRIBE_DOC_NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE "Enables or disabled \"hairpin mode\" for the port, which allows frames to be sent back out through the port the frame was received on." +#define DESCRIBE_DOC_NM_SETTING_BRIDGE_PORT_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_BRIDGE_PORT_PATH_COST "The Spanning Tree Protocol (STP) port cost for destinations via this port." +#define DESCRIBE_DOC_NM_SETTING_BRIDGE_PORT_PRIORITY "The Spanning Tree Protocol (STP) priority of this bridge port." +#define DESCRIBE_DOC_NM_SETTING_CDMA_MTU "If non-zero, only transmit packets of the specified size or smaller, breaking larger packets up into multiple frames." +#define DESCRIBE_DOC_NM_SETTING_CDMA_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_CDMA_NUMBER "The number to dial to establish the connection to the CDMA-based mobile broadband network, if any. If not specified, the default number (#777) is used when required." +#define DESCRIBE_DOC_NM_SETTING_CDMA_PASSWORD "The password used to authenticate with the network, if required. Many providers do not require a password, or accept any password. But if a password is required, it is specified here." +#define DESCRIBE_DOC_NM_SETTING_CDMA_PASSWORD_FLAGS "Flags indicating how to handle the \"password\" property." +#define DESCRIBE_DOC_NM_SETTING_CDMA_USERNAME "The username used to authenticate with the network, if required. Many providers do not require a username, or accept any username. But if a username is required, it is specified here." +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT "Whether or not the connection should be automatically connected by NetworkManager when the resources for the connection are available. TRUE to automatically activate the connection, FALSE to require manual intervention to activate the connection." +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY "The autoconnect priority. If the connection is set to autoconnect, connections with higher priority will be preferred. Defaults to 0. The higher number means higher priority." +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES "The number of times a connection should be tried when autoctivating before giving up. Zero means forever, -1 means the global default (4 times if not overridden)." +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES "Whether or not slaves of this connection should be automatically brought up when NetworkManager activates this connection. This only has a real effect for master connections. The permitted values are: 0: leave slave connections untouched, 1: activate all the slave connections with this connection, -1: default. If -1 (default) is set, global connection.autoconnect-slaves is read to determine the real value. If it is default as well, this fallbacks to 0." +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT "If greater than zero, delay success of IP addressing until either the timeout is reached, or an IP gateway replies to a ping." +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_ID "A human readable unique identifier for the connection, like \"Work Wi-Fi\" or \"T-Mobile 3G\"." +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_INTERFACE_NAME "The name of the network interface this connection is bound to. If not set, then the connection can be attached to any interface of the appropriate type (subject to restrictions imposed by other settings). For software devices this specifies the name of the created device. For connection types where interface names cannot easily be made persistent (e.g. mobile broadband or USB Ethernet), this property should not be used. Setting this property restricts the interfaces a connection can be used with, and if interface names change or are reordered the connection may be applied to the wrong interface." +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_LLDP "Whether LLDP is enabled for the connection." +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_MASTER "Interface name of the master device or UUID of the master connection." +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_METERED "Whether the connection is metered. When updating this property on a currently activated connection, the change takes effect immediately." +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_PERMISSIONS "An array of strings defining what access a given user has to this connection. If this is NULL or empty, all users are allowed to access this connection. Otherwise a user is allowed to access this connection if and only if they are in this list. Each entry is of the form \"[type]:[id]:[reserved]\"; for example, \"user:dcbw:blah\". At this time only the \"user\" [type] is allowed. Any other values are ignored and reserved for future use. [id] is the username that this permission refers to, which may not contain the \":\" character. Any [reserved] information present must be ignored and is reserved for future use. All of [type], [id], and [reserved] must be valid UTF-8." +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_READ_ONLY "FALSE if the connection can be modified using the provided settings service's D-Bus interface with the right privileges, or TRUE if the connection is read-only and cannot be modified." +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_SECONDARIES "List of connection UUIDs that should be activated when the base connection itself is activated. Currently only VPN connections are supported." +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_SLAVE_TYPE "Setting name of the device type of this slave's master connection (eg, \"bond\"), or NULL if this connection is not a slave." +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_STABLE_ID "Token to generate stable IDs for the connection. The stable-id is used for generating IPv6 stable private addresses with ipv6.addr-gen-mode=stable-privacy. It is also used to seed the generated cloned MAC address for ethernet.cloned-mac-address=stable and wifi.cloned-mac-address=stable. Note that also the interface name of the activating connection and a per-host secret key is included into the address generation so that the same stable-id on different hosts/devices yields different addresses. If the value is unset, an ID unique for the connection is used. Specifing a stable-id allows multiple connections to generate the same addresses. Another use is to generate IDs at runtime via dynamic substitutions. The '$' character is treated special to perform dynamic substitutions at runtime. Currently supported are \"${CONNECTION}\", \"${BOOT}\", \"${RANDOM}\". These effectively create unique IDs per-connection, per-boot, or every time. Any unrecognized patterns following '$' are treated verbatim, however are reserved for future use. You are thus advised to avoid '$' or escape it as \"$$\". For example, set it to \"${CONNECTION}/${BOOT}\" to create a unique id for this connection that changes with every reboot. Note that two connections only use the same effective id if their stable-id is also identical before performing dynamic substitutions." +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_TIMESTAMP "The time, in seconds since the Unix Epoch, that the connection was last _successfully_ fully activated. NetworkManager updates the connection timestamp periodically when the connection is active to ensure that an active connection has the latest timestamp. The property is only meant for reading (changes to this property will not be preserved)." +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_TYPE "Base type of the connection. For hardware-dependent connections, should contain the setting name of the hardware-type specific setting (ie, \"802-3-ethernet\" or \"802-11-wireless\" or \"bluetooth\", etc), and for non-hardware dependent connections like VPN or otherwise, should contain the setting name of that setting type (ie, \"vpn\" or \"bridge\", etc)." +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_UUID "A universally unique identifier for the connection, for example generated with libuuid. It should be assigned when the connection is created, and never changed as long as the connection still applies to the same network. For example, it should not be changed when the \"id\" property or NMSettingIP4Config changes, but might need to be re-created when the Wi-Fi SSID, mobile broadband network provider, or \"type\" property changes. The UUID must be in the format \"2815492f-7e56-435e-b2e9-246bd7cdc664\" (ie, contains only hexadecimal characters and \"-\")." +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_ZONE "The trust level of a the connection. Free form case-insensitive string (for example \"Home\", \"Work\", \"Public\"). NULL or unspecified zone means the connection will be placed in the default zone as defined by the firewall. When updating this property on a currently activated connection, the change takes effect immediately." +#define DESCRIBE_DOC_NM_SETTING_DCB_APP_FCOE_FLAGS "Specifies the NMSettingDcbFlags for the DCB FCoE application. Flags may be any combination of NM_SETTING_DCB_FLAG_ENABLE (0x1), NM_SETTING_DCB_FLAG_ADVERTISE (0x2), and NM_SETTING_DCB_FLAG_WILLING (0x4)." +#define DESCRIBE_DOC_NM_SETTING_DCB_APP_FCOE_MODE "The FCoE controller mode; either \"fabric\" (default) or \"vn2vn\"." +#define DESCRIBE_DOC_NM_SETTING_DCB_APP_FCOE_PRIORITY "The highest User Priority (0 - 7) which FCoE frames should use, or -1 for default priority. Only used when the \"app-fcoe-flags\" property includes the NM_SETTING_DCB_FLAG_ENABLE (0x1) flag." +#define DESCRIBE_DOC_NM_SETTING_DCB_APP_FIP_FLAGS "Specifies the NMSettingDcbFlags for the DCB FIP application. Flags may be any combination of NM_SETTING_DCB_FLAG_ENABLE (0x1), NM_SETTING_DCB_FLAG_ADVERTISE (0x2), and NM_SETTING_DCB_FLAG_WILLING (0x4)." +#define DESCRIBE_DOC_NM_SETTING_DCB_APP_FIP_PRIORITY "The highest User Priority (0 - 7) which FIP frames should use, or -1 for default priority. Only used when the \"app-fip-flags\" property includes the NM_SETTING_DCB_FLAG_ENABLE (0x1) flag." +#define DESCRIBE_DOC_NM_SETTING_DCB_APP_ISCSI_FLAGS "Specifies the NMSettingDcbFlags for the DCB iSCSI application. Flags may be any combination of NM_SETTING_DCB_FLAG_ENABLE (0x1), NM_SETTING_DCB_FLAG_ADVERTISE (0x2), and NM_SETTING_DCB_FLAG_WILLING (0x4)." +#define DESCRIBE_DOC_NM_SETTING_DCB_APP_ISCSI_PRIORITY "The highest User Priority (0 - 7) which iSCSI frames should use, or -1 for default priority. Only used when the \"app-iscsi-flags\" property includes the NM_SETTING_DCB_FLAG_ENABLE (0x1) flag." +#define DESCRIBE_DOC_NM_SETTING_DCB_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_DCB_PRIORITY_BANDWIDTH "An array of 8 uint values, where the array index corresponds to the User Priority (0 - 7) and the value indicates the percentage of bandwidth of the priority's assigned group that the priority may use. The sum of all percentages for priorities which belong to the same group must total 100 percent." +#define DESCRIBE_DOC_NM_SETTING_DCB_PRIORITY_FLOW_CONTROL "An array of 8 boolean values, where the array index corresponds to the User Priority (0 - 7) and the value indicates whether or not the corresponding priority should transmit priority pause." +#define DESCRIBE_DOC_NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS "Specifies the NMSettingDcbFlags for DCB Priority Flow Control (PFC). Flags may be any combination of NM_SETTING_DCB_FLAG_ENABLE (0x1), NM_SETTING_DCB_FLAG_ADVERTISE (0x2), and NM_SETTING_DCB_FLAG_WILLING (0x4)." +#define DESCRIBE_DOC_NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH "An array of 8 uint values, where the array index corresponds to the Priority Group ID (0 - 7) and the value indicates the percentage of link bandwidth allocated to that group. Allowed values are 0 - 100, and the sum of all values must total 100 percent." +#define DESCRIBE_DOC_NM_SETTING_DCB_PRIORITY_GROUP_FLAGS "Specifies the NMSettingDcbFlags for DCB Priority Groups. Flags may be any combination of NM_SETTING_DCB_FLAG_ENABLE (0x1), NM_SETTING_DCB_FLAG_ADVERTISE (0x2), and NM_SETTING_DCB_FLAG_WILLING (0x4)." +#define DESCRIBE_DOC_NM_SETTING_DCB_PRIORITY_GROUP_ID "An array of 8 uint values, where the array index corresponds to the User Priority (0 - 7) and the value indicates the Priority Group ID. Allowed Priority Group ID values are 0 - 7 or 15 for the unrestricted group." +#define DESCRIBE_DOC_NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH "An array of 8 boolean values, where the array index corresponds to the User Priority (0 - 7) and the value indicates whether or not the priority may use all of the bandwidth allocated to its assigned group." +#define DESCRIBE_DOC_NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS "An array of 8 uint values, where the array index corresponds to the User Priority (0 - 7) and the value indicates the traffic class (0 - 7) to which the priority is mapped." +#define DESCRIBE_DOC_NM_SETTING_DUMMY_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_GENERIC_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_GSM_APN "The GPRS Access Point Name specifying the APN used when establishing a data session with the GSM-based network. The APN often determines how the user will be billed for their network usage and whether the user has access to the Internet or just a provider-specific walled-garden, so it is important to use the correct APN for the user's mobile broadband plan. The APN may only be composed of the characters a-z, 0-9, ., and - per GSM 03.60 Section 14.9." +#define DESCRIBE_DOC_NM_SETTING_GSM_DEVICE_ID "The device unique identifier (as given by the WWAN management service) which this connection applies to. If given, the connection will only apply to the specified device." +#define DESCRIBE_DOC_NM_SETTING_GSM_HOME_ONLY "When TRUE, only connections to the home network will be allowed. Connections to roaming networks will not be made." +#define DESCRIBE_DOC_NM_SETTING_GSM_MTU "If non-zero, only transmit packets of the specified size or smaller, breaking larger packets up into multiple frames." +#define DESCRIBE_DOC_NM_SETTING_GSM_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_GSM_NETWORK_ID "The Network ID (GSM LAI format, ie MCC-MNC) to force specific network registration. If the Network ID is specified, NetworkManager will attempt to force the device to register only on the specified network. This can be used to ensure that the device does not roam when direct roaming control of the device is not otherwise possible." +#define DESCRIBE_DOC_NM_SETTING_GSM_NUMBER "Number to dial when establishing a PPP data session with the GSM-based mobile broadband network. Many modems do not require PPP for connections to the mobile network and thus this property should be left blank, which allows NetworkManager to select the appropriate settings automatically." +#define DESCRIBE_DOC_NM_SETTING_GSM_PASSWORD "The password used to authenticate with the network, if required. Many providers do not require a password, or accept any password. But if a password is required, it is specified here." +#define DESCRIBE_DOC_NM_SETTING_GSM_PASSWORD_FLAGS "Flags indicating how to handle the \"password\" property." +#define DESCRIBE_DOC_NM_SETTING_GSM_PIN "If the SIM is locked with a PIN it must be unlocked before any other operations are requested. Specify the PIN here to allow operation of the device." +#define DESCRIBE_DOC_NM_SETTING_GSM_PIN_FLAGS "Flags indicating how to handle the \"pin\" property." +#define DESCRIBE_DOC_NM_SETTING_GSM_SIM_ID "The SIM card unique identifier (as given by the WWAN management service) which this connection applies to. If given, the connection will apply to any device also allowed by \"device-id\" which contains a SIM card matching the given identifier." +#define DESCRIBE_DOC_NM_SETTING_GSM_SIM_OPERATOR_ID "A MCC/MNC string like \"310260\" or \"21601\" identifying the specific mobile network operator which this connection applies to. If given, the connection will apply to any device also allowed by \"device-id\" and \"sim-id\" which contains a SIM card provisioined by the given operator." +#define DESCRIBE_DOC_NM_SETTING_GSM_USERNAME "The username used to authenticate with the network, if required. Many providers do not require a username, or accept any username. But if a username is required, it is specified here." +#define DESCRIBE_DOC_NM_SETTING_INFINIBAND_MAC_ADDRESS "If specified, this connection will only apply to the IPoIB device whose permanent MAC address matches. This property does not change the MAC address of the device (i.e. MAC spoofing)." +#define DESCRIBE_DOC_NM_SETTING_INFINIBAND_MTU "If non-zero, only transmit packets of the specified size or smaller, breaking larger packets up into multiple frames." +#define DESCRIBE_DOC_NM_SETTING_INFINIBAND_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_INFINIBAND_P_KEY "The InfiniBand P_Key to use for this device. A value of -1 means to use the default P_Key (aka \"the P_Key at index 0\"). Otherwise it is a 16-bit unsigned integer, whose high bit is set if it is a \"full membership\" P_Key." +#define DESCRIBE_DOC_NM_SETTING_INFINIBAND_PARENT "The interface name of the parent device of this device. Normally NULL, but if the \"p_key\" property is set, then you must specify the base device by setting either this property or \"mac-address\"." +#define DESCRIBE_DOC_NM_SETTING_INFINIBAND_TRANSPORT_MODE "The IP-over-InfiniBand transport mode. Either \"datagram\" or \"connected\"." +#define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT "How many additional levels of encapsulation are permitted to be prepended to packets. This property applies only to IPv6 tunnels." +#define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_FLOW_LABEL "The flow label to assign to tunnel packets. This property applies only to IPv6 tunnels." +#define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_INPUT_KEY "The key used for tunnel input packets; the property is valid only for certain tunnel modes (GRE, IP6GRE). If empty, no key is used." +#define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_LOCAL "The local endpoint of the tunnel; the value can be empty, otherwise it must contain an IPv4 or IPv6 address." +#define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_MODE "The tunneling mode, for example NM_IP_TUNNEL_MODE_IPIP (1) or NM_IP_TUNNEL_MODE_GRE (2)." +#define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_MTU "None" +#define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_OUTPUT_KEY "The key used for tunnel output packets; the property is valid only for certain tunnel modes (GRE, IP6GRE). If empty, no key is used." +#define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_PARENT "If given, specifies the parent interface name or parent connection UUID the new device will be bound to so that tunneled packets will only be routed via that interface." +#define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY "Whether to enable Path MTU Discovery on this tunnel." +#define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_REMOTE "The remote endpoint of the tunnel; the value must contain an IPv4 or IPv6 address." +#define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_TOS "The type of service (IPv4) or traffic class (IPv6) field to be set on tunneled packets." +#define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_TTL "The TTL to assign to tunneled packets. 0 is a special value meaning that packets inherit the TTL value." +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ADDRESSES "Array of IP addresses." +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DAD_TIMEOUT "Timeout in milliseconds used to check for the presence of duplicate IP addresses on the network. If an address conflict is detected, the activation will fail. A zero value means that no duplicate address detection is performed, -1 means the default value (either configuration ipvx.dad-timeout override or 3 seconds). A value greater than zero is a timeout in milliseconds." +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID "A string sent to the DHCP server to identify the local machine which the DHCP server may use to customize the DHCP lease and options." +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_FQDN "If the \"dhcp-send-hostname\" property is TRUE, then the specified FQDN will be sent to the DHCP server when acquiring a lease. This property and \"dhcp-hostname\" are mutually exclusive and cannot be set at the same time." +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME "If the \"dhcp-send-hostname\" property is TRUE, then the specified name will be sent to the DHCP server when acquiring a lease. This property and \"dhcp-fqdn\" are mutually exclusive and cannot be set at the same time." +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME "If TRUE, a hostname is sent to the DHCP server when acquiring a lease. Some DHCP servers use this hostname to update DNS databases, essentially providing a static hostname for the computer. If the \"dhcp-hostname\" property is NULL and this property is TRUE, the current persistent hostname of the computer is sent." +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_TIMEOUT "A timeout for a DHCP transaction in seconds." +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS "Array of IP addresses of DNS servers." +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_OPTIONS "Array of DNS options as described in man 5 resolv.conf. NULL means that the options are unset and left at the default. In this case NetworkManager will use default options. This is distinct from an empty list of properties." +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_PRIORITY "Intra-connection DNS priority. The relative priority to be used when determining the order of DNS servers in resolv.conf. A lower value means that servers will be on top of the file. Zero selects the default value, which is 50 for VPNs and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. For that, just specify the DNS servers in the desired order. When multiple devices have configurations with the same priority, the one with an active default route will be preferred. Note that when using dns=dnsmasq the order is meaningless since dnsmasq forwards queries to all known servers at the same time. Negative values have the special effect of excluding other configurations with a greater priority value; so in presence of at least a negative priority, only DNS servers from connections with the lowest priority value will be used." +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_SEARCH "Array of DNS search domains." +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_GATEWAY "The gateway associated with this configuration. This is only meaningful if \"addresses\" is also set." +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS "When \"method\" is set to \"auto\" and this property to TRUE, automatically configured nameservers and search domains are ignored and only nameservers and search domains specified in the \"dns\" and \"dns-search\" properties, if any, are used." +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES "When \"method\" is set to \"auto\" and this property to TRUE, automatically configured routes are ignored and only routes specified in the \"routes\" property, if any, are used." +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_MAY_FAIL "If TRUE, allow overall network configuration to proceed even if the configuration specified by this property times out. Note that at least one IP configuration must succeed or overall network configuration will still fail. For example, in IPv6-only networks, setting this property to TRUE on the NMSettingIP4Config allows the overall network configuration to succeed if IPv4 configuration fails but IPv6 configuration completes successfully." +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_METHOD "IP configuration method. NMSettingIP4Config and NMSettingIP6Config both support \"auto\", \"manual\", and \"link-local\". See the subclass-specific documentation for other values. In general, for the \"auto\" method, properties such as \"dns\" and \"routes\" specify information that is added on to the information returned from automatic configuration. The \"ignore-auto-routes\" and \"ignore-auto-dns\" properties modify this behavior. For methods that imply no upstream network, such as \"shared\" or \"link-local\", these properties must be empty. For IPv4 method \"shared\", the IP subnet can be configured by adding one manual IPv4 address or otherwise 10.42.x.0/24 is chosen." +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_NEVER_DEFAULT "If TRUE, this connection will never be the default connection for this IP type, meaning it will never be assigned the default route by NetworkManager." +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ROUTE_METRIC "The default metric for routes that don't explicitly specify a metric. The default value -1 means that the metric is choosen automatically based on the device type. The metric applies to dynamic routes, manual (static) routes that don't have an explicit metric setting, address prefix routes, and the default route. Note that for IPv6, the kernel accepts zero (0) but coerces it to 1024 (user default). Hence, setting this property to zero effectively mean setting it to 1024. For IPv4, zero is a regular value for the metric." +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ROUTES "Array of IP routes." +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE "Configure method for creating the address for use with RFC4862 IPv6 Stateless Address Autoconfiguration. The permitted values are: \"eui64\", or \"stable-privacy\". If the property is set to \"eui64\", the addresses will be generated using the interface tokens derived from hardware address. This makes the host part of the address to stay constant, making it possible to track host's presence when it changes networks. The address changes when the interface hardware is replaced. The value of \"stable-privacy\" enables use of cryptographically secure hash of a secret host-specific key along with the connection's stable-id and the network address as specified by RFC7217. This makes it impossible to use the address track host's presence, and makes the address stable when the network interface hardware is replaced. On D-Bus, the absence of an addr-gen-mode setting equals enabling \"stable-privacy\". For keyfile plugin, the absence of the setting on disk means \"eui64\" so that the property doesn't change on upgrade from older versions. Note that this setting is distinct from the Privacy Extensions as configured by \"ip6-privacy\" property and it does not affect the temporary addresses configured with this option." +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ADDRESSES "Array of IP addresses." +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DAD_TIMEOUT "Timeout in milliseconds used to check for the presence of duplicate IP addresses on the network. If an address conflict is detected, the activation will fail. A zero value means that no duplicate address detection is performed, -1 means the default value (either configuration ipvx.dad-timeout override or 3 seconds). A value greater than zero is a timeout in milliseconds." +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME "If the \"dhcp-send-hostname\" property is TRUE, then the specified name will be sent to the DHCP server when acquiring a lease. This property and \"dhcp-fqdn\" are mutually exclusive and cannot be set at the same time." +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_SEND_HOSTNAME "If TRUE, a hostname is sent to the DHCP server when acquiring a lease. Some DHCP servers use this hostname to update DNS databases, essentially providing a static hostname for the computer. If the \"dhcp-hostname\" property is NULL and this property is TRUE, the current persistent hostname of the computer is sent." +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_TIMEOUT "A timeout for a DHCP transaction in seconds." +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS "Array of IP addresses of DNS servers." +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_OPTIONS "Array of DNS options as described in man 5 resolv.conf. NULL means that the options are unset and left at the default. In this case NetworkManager will use default options. This is distinct from an empty list of properties." +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_PRIORITY "Intra-connection DNS priority. The relative priority to be used when determining the order of DNS servers in resolv.conf. A lower value means that servers will be on top of the file. Zero selects the default value, which is 50 for VPNs and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. For that, just specify the DNS servers in the desired order. When multiple devices have configurations with the same priority, the one with an active default route will be preferred. Note that when using dns=dnsmasq the order is meaningless since dnsmasq forwards queries to all known servers at the same time. Negative values have the special effect of excluding other configurations with a greater priority value; so in presence of at least a negative priority, only DNS servers from connections with the lowest priority value will be used." +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_SEARCH "Array of DNS search domains." +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_GATEWAY "The gateway associated with this configuration. This is only meaningful if \"addresses\" is also set." +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS "When \"method\" is set to \"auto\" and this property to TRUE, automatically configured nameservers and search domains are ignored and only nameservers and search domains specified in the \"dns\" and \"dns-search\" properties, if any, are used." +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES "When \"method\" is set to \"auto\" and this property to TRUE, automatically configured routes are ignored and only routes specified in the \"routes\" property, if any, are used." +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IP6_PRIVACY "Configure IPv6 Privacy Extensions for SLAAC, described in RFC4941. If enabled, it makes the kernel generate a temporary IPv6 address in addition to the public one generated from MAC address via modified EUI-64. This enhances privacy, but could cause problems in some applications, on the other hand. The permitted values are: -1: unknown, 0: disabled, 1: enabled (prefer public address), 2: enabled (prefer temporary addresses). Having a per-connection setting set to \"-1\" (unknown) means fallback to global configuration \"ipv6.ip6-privacy\". If also global configuration is unspecified or set to \"-1\", fallback to read \"/proc/sys/net/ipv6/conf/default/use_tempaddr\". Note that this setting is distinct from the Stable Privacy addresses that can be enabled with the \"addr-gen-mode\" property's \"stable-privacy\" setting as another way of avoiding host tracking with IPv6 addresses." +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_MAY_FAIL "If TRUE, allow overall network configuration to proceed even if the configuration specified by this property times out. Note that at least one IP configuration must succeed or overall network configuration will still fail. For example, in IPv6-only networks, setting this property to TRUE on the NMSettingIP4Config allows the overall network configuration to succeed if IPv4 configuration fails but IPv6 configuration completes successfully." +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_METHOD "IP configuration method. NMSettingIP4Config and NMSettingIP6Config both support \"auto\", \"manual\", and \"link-local\". See the subclass-specific documentation for other values. In general, for the \"auto\" method, properties such as \"dns\" and \"routes\" specify information that is added on to the information returned from automatic configuration. The \"ignore-auto-routes\" and \"ignore-auto-dns\" properties modify this behavior. For methods that imply no upstream network, such as \"shared\" or \"link-local\", these properties must be empty. For IPv4 method \"shared\", the IP subnet can be configured by adding one manual IPv4 address or otherwise 10.42.x.0/24 is chosen." +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_NEVER_DEFAULT "If TRUE, this connection will never be the default connection for this IP type, meaning it will never be assigned the default route by NetworkManager." +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ROUTE_METRIC "The default metric for routes that don't explicitly specify a metric. The default value -1 means that the metric is choosen automatically based on the device type. The metric applies to dynamic routes, manual (static) routes that don't have an explicit metric setting, address prefix routes, and the default route. Note that for IPv6, the kernel accepts zero (0) but coerces it to 1024 (user default). Hence, setting this property to zero effectively mean setting it to 1024. For IPv4, zero is a regular value for the metric." +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ROUTES "Array of IP routes." +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_TOKEN "Configure the token for draft-chown-6man-tokenised-ipv6-identifiers-02 IPv6 tokenized interface identifiers. Useful with eui64 addr-gen-mode." +#define DESCRIBE_DOC_NM_SETTING_MACSEC_ENCRYPT "Whether the transmitted traffic must be encrypted." +#define DESCRIBE_DOC_NM_SETTING_MACSEC_MKA_CAK "The pre-shared CAK (Connectivity Association Key) for MACsec Key Agreement." +#define DESCRIBE_DOC_NM_SETTING_MACSEC_MKA_CAK_FLAGS "Flags indicating how to handle the \"mka-cak\" property." +#define DESCRIBE_DOC_NM_SETTING_MACSEC_MKA_CKN "The pre-shared CKN (Connectivity-association Key Name) for MACsec Key Agreement." +#define DESCRIBE_DOC_NM_SETTING_MACSEC_MODE "Specifies how the CAK (Connectivity Association Key) for MKA (MACsec Key Agreement) is obtained." +#define DESCRIBE_DOC_NM_SETTING_MACSEC_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_MACSEC_PARENT "If given, specifies the parent interface name or parent connection UUID from which this MACSEC interface should be created. If this property is not specified, the connection must contain an \"802-3-ethernet\" setting with a \"mac-address\" property." +#define DESCRIBE_DOC_NM_SETTING_MACSEC_PORT "The port component of the SCI (Secure Channel Identifier), between 1 and 65534." +#define DESCRIBE_DOC_NM_SETTING_MACSEC_VALIDATION "Specifies the validation mode for incoming frames." +#define DESCRIBE_DOC_NM_SETTING_MACVLAN_MODE "The macvlan mode, which specifies the communication mechanism between multiple macvlans on the same lower device." +#define DESCRIBE_DOC_NM_SETTING_MACVLAN_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_MACVLAN_PARENT "If given, specifies the parent interface name or parent connection UUID from which this MAC-VLAN interface should be created. If this property is not specified, the connection must contain an \"802-3-ethernet\" setting with a \"mac-address\" property." +#define DESCRIBE_DOC_NM_SETTING_MACVLAN_PROMISCUOUS "Whether the interface should be put in promiscuous mode." +#define DESCRIBE_DOC_NM_SETTING_MACVLAN_TAP "Whether the interface should be a MACVTAP." +#define DESCRIBE_DOC_NM_SETTING_PPP_BAUD "If non-zero, instruct pppd to set the serial port to the specified baudrate. This value should normally be left as 0 to automatically choose the speed." +#define DESCRIBE_DOC_NM_SETTING_PPP_CRTSCTS "If TRUE, specify that pppd should set the serial port to use hardware flow control with RTS and CTS signals. This value should normally be set to FALSE." +#define DESCRIBE_DOC_NM_SETTING_PPP_LCP_ECHO_FAILURE "If non-zero, instruct pppd to presume the connection to the peer has failed if the specified number of LCP echo-requests go unanswered by the peer. The \"lcp-echo-interval\" property must also be set to a non-zero value if this property is used." +#define DESCRIBE_DOC_NM_SETTING_PPP_LCP_ECHO_INTERVAL "If non-zero, instruct pppd to send an LCP echo-request frame to the peer every n seconds (where n is the specified value). Note that some PPP peers will respond to echo requests and some will not, and it is not possible to autodetect this." +#define DESCRIBE_DOC_NM_SETTING_PPP_MPPE_STATEFUL "If TRUE, stateful MPPE is used. See pppd documentation for more information on stateful MPPE." +#define DESCRIBE_DOC_NM_SETTING_PPP_MRU "If non-zero, instruct pppd to request that the peer send packets no larger than the specified size. If non-zero, the MRU should be between 128 and 16384." +#define DESCRIBE_DOC_NM_SETTING_PPP_MTU "If non-zero, instruct pppd to send packets no larger than the specified size." +#define DESCRIBE_DOC_NM_SETTING_PPP_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_PPP_NO_VJ_COMP "If TRUE, Van Jacobsen TCP header compression will not be requested." +#define DESCRIBE_DOC_NM_SETTING_PPP_NOAUTH "If TRUE, do not require the other side (usually the PPP server) to authenticate itself to the client. If FALSE, require authentication from the remote side. In almost all cases, this should be TRUE." +#define DESCRIBE_DOC_NM_SETTING_PPP_NOBSDCOMP "If TRUE, BSD compression will not be requested." +#define DESCRIBE_DOC_NM_SETTING_PPP_NODEFLATE "If TRUE, \"deflate\" compression will not be requested." +#define DESCRIBE_DOC_NM_SETTING_PPP_REFUSE_CHAP "If TRUE, the CHAP authentication method will not be used." +#define DESCRIBE_DOC_NM_SETTING_PPP_REFUSE_EAP "If TRUE, the EAP authentication method will not be used." +#define DESCRIBE_DOC_NM_SETTING_PPP_REFUSE_MSCHAP "If TRUE, the MSCHAP authentication method will not be used." +#define DESCRIBE_DOC_NM_SETTING_PPP_REFUSE_MSCHAPV2 "If TRUE, the MSCHAPv2 authentication method will not be used." +#define DESCRIBE_DOC_NM_SETTING_PPP_REFUSE_PAP "If TRUE, the PAP authentication method will not be used." +#define DESCRIBE_DOC_NM_SETTING_PPP_REQUIRE_MPPE "If TRUE, MPPE (Microsoft Point-to-Point Encrpytion) will be required for the PPP session. If either 64-bit or 128-bit MPPE is not available the session will fail. Note that MPPE is not used on mobile broadband connections." +#define DESCRIBE_DOC_NM_SETTING_PPP_REQUIRE_MPPE_128 "If TRUE, 128-bit MPPE (Microsoft Point-to-Point Encrpytion) will be required for the PPP session, and the \"require-mppe\" property must also be set to TRUE. If 128-bit MPPE is not available the session will fail." +#define DESCRIBE_DOC_NM_SETTING_PPPOE_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_PPPOE_PASSWORD "Password used to authenticate with the PPPoE service." +#define DESCRIBE_DOC_NM_SETTING_PPPOE_PASSWORD_FLAGS "Flags indicating how to handle the \"password\" property." +#define DESCRIBE_DOC_NM_SETTING_PPPOE_SERVICE "If specified, instruct PPPoE to only initiate sessions with access concentrators that provide the specified service. For most providers, this should be left blank. It is only required if there are multiple access concentrators or a specific service is known to be required." +#define DESCRIBE_DOC_NM_SETTING_PPPOE_USERNAME "Username used to authenticate with the PPPoE service." +#define DESCRIBE_DOC_NM_SETTING_PROXY_BROWSER_ONLY "Whether the proxy configuration is for browser only." +#define DESCRIBE_DOC_NM_SETTING_PROXY_METHOD "Method for proxy configuration, Default is NM_SETTING_PROXY_METHOD_NONE (0)" +#define DESCRIBE_DOC_NM_SETTING_PROXY_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_PROXY_PAC_SCRIPT "PAC script for the connection." +#define DESCRIBE_DOC_NM_SETTING_PROXY_PAC_URL "PAC URL for obtaining PAC file." +#define DESCRIBE_DOC_NM_SETTING_SERIAL_BAUD "Speed to use for communication over the serial port. Note that this value usually has no effect for mobile broadband modems as they generally ignore speed settings and use the highest available speed." +#define DESCRIBE_DOC_NM_SETTING_SERIAL_BITS "Byte-width of the serial communication. The 8 in \"8n1\" for example." +#define DESCRIBE_DOC_NM_SETTING_SERIAL_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_SERIAL_PARITY "Parity setting of the serial port." +#define DESCRIBE_DOC_NM_SETTING_SERIAL_SEND_DELAY "Time to delay between each byte sent to the modem, in microseconds." +#define DESCRIBE_DOC_NM_SETTING_SERIAL_STOPBITS "Number of stop bits for communication on the serial port. Either 1 or 2. The 1 in \"8n1\" for example." +#define DESCRIBE_DOC_NM_SETTING_TEAM_CONFIG "The JSON configuration for the team network interface. The property should contain raw JSON configuration data suitable for teamd, because the value is passed directly to teamd. If not specified, the default configuration is used. See man teamd.conf for the format details." +#define DESCRIBE_DOC_NM_SETTING_TEAM_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_TEAM_PORT_CONFIG "The JSON configuration for the team port. The property should contain raw JSON configuration data suitable for teamd, because the value is passed directly to teamd. If not specified, the default configuration is used. See man teamd.conf for the format details." +#define DESCRIBE_DOC_NM_SETTING_TEAM_PORT_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_TUN_GROUP "The group ID which will own the device. If set to NULL everyone will be able to use the device." +#define DESCRIBE_DOC_NM_SETTING_TUN_MODE "The operating mode of the virtual device. Allowed values are NM_SETTING_TUN_MODE_TUN (1) to create a layer 3 device and NM_SETTING_TUN_MODE_TAP (2) to create an Ethernet-like layer 2 one." +#define DESCRIBE_DOC_NM_SETTING_TUN_MULTI_QUEUE "If the property is set to TRUE, the interface will support multiple file descriptors (queues) to parallelize packet sending or receiving. Otherwise, the interface will only support a single queue." +#define DESCRIBE_DOC_NM_SETTING_TUN_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_TUN_OWNER "The user ID which will own the device. If set to NULL everyone will be able to use the device." +#define DESCRIBE_DOC_NM_SETTING_TUN_PI "If TRUE the interface will prepend a 4 byte header describing the physical interface to the packets." +#define DESCRIBE_DOC_NM_SETTING_TUN_VNET_HDR "If TRUE the IFF_VNET_HDR the tunnel packets will include a virtio network header." +#define DESCRIBE_DOC_NM_SETTING_USER_DATA "A dictionary of key/value pairs with user data. This data is ignored by NetworkManager and can be used at the users discretion. The keys only support a strict ascii format, but the values can be arbitrary UTF8 strings up to a certain length." +#define DESCRIBE_DOC_NM_SETTING_USER_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_VLAN_EGRESS_PRIORITY_MAP "For outgoing packets, a list of mappings from Linux SKB priorities to 802.1p priorities. The mapping is given in the format \"from:to\" where both \"from\" and \"to\" are unsigned integers, ie \"7:3\"." +#define DESCRIBE_DOC_NM_SETTING_VLAN_FLAGS "One or more flags which control the behavior and features of the VLAN interface. Flags include NM_VLAN_FLAG_REORDER_HEADERS (0x1) (reordering of output packet headers), NM_VLAN_FLAG_GVRP (0x2) (use of the GVRP protocol), and NM_VLAN_FLAG_LOOSE_BINDING (0x4) (loose binding of the interface to its master device's operating state). NM_VLAN_FLAG_MVRP (0x8) (use of the MVRP protocol). The default value of this property is NM_VLAN_FLAG_REORDER_HEADERS, but it used to be 0. To preserve backward compatibility, the default-value in the D-Bus API continues to be 0 and a missing property on D-Bus is still considered as 0." +#define DESCRIBE_DOC_NM_SETTING_VLAN_ID "The VLAN identifier that the interface created by this connection should be assigned. The valid range is from 0 to 4094, without the reserved id 4095." +#define DESCRIBE_DOC_NM_SETTING_VLAN_INGRESS_PRIORITY_MAP "For incoming packets, a list of mappings from 802.1p priorities to Linux SKB priorities. The mapping is given in the format \"from:to\" where both \"from\" and \"to\" are unsigned integers, ie \"7:3\"." +#define DESCRIBE_DOC_NM_SETTING_VLAN_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_VLAN_PARENT "If given, specifies the parent interface name or parent connection UUID from which this VLAN interface should be created. If this property is not specified, the connection must contain an \"802-3-ethernet\" setting with a \"mac-address\" property." +#define DESCRIBE_DOC_NM_SETTING_VPN_DATA "Dictionary of key/value pairs of VPN plugin specific data. Both keys and values must be strings." +#define DESCRIBE_DOC_NM_SETTING_VPN_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_VPN_PERSISTENT "If the VPN service supports persistence, and this property is TRUE, the VPN will attempt to stay connected across link changes and outages, until explicitly disconnected." +#define DESCRIBE_DOC_NM_SETTING_VPN_SECRETS "Dictionary of key/value pairs of VPN plugin specific secrets like passwords or private keys. Both keys and values must be strings." +#define DESCRIBE_DOC_NM_SETTING_VPN_SERVICE_TYPE "D-Bus service name of the VPN plugin that this setting uses to connect to its network. i.e. org.freedesktop.NetworkManager.vpnc for the vpnc plugin." +#define DESCRIBE_DOC_NM_SETTING_VPN_TIMEOUT "Timeout for the VPN service to establish the connection. Some services may take quite a long time to connect. Value of 0 means a default timeout, which is 60 seconds (unless overriden by vpn.timeout in configuration file). Values greater than zero mean timeout in seconds." +#define DESCRIBE_DOC_NM_SETTING_VPN_USER_NAME "If the VPN connection requires a user name for authentication, that name should be provided here. If the connection is available to more than one user, and the VPN requires each user to supply a different name, then leave this property empty. If this property is empty, NetworkManager will automatically supply the username of the user which requested the VPN connection." +#define DESCRIBE_DOC_NM_SETTING_VXLAN_AGEING "Specifies the lifetime in seconds of FDB entries learnt by the kernel." +#define DESCRIBE_DOC_NM_SETTING_VXLAN_DESTINATION_PORT "Specifies the UDP destination port to communicate to the remote VXLAN tunnel endpoint." +#define DESCRIBE_DOC_NM_SETTING_VXLAN_ID "Specifies the VXLAN Network Identifer (or VXLAN Segment Identifier) to use." +#define DESCRIBE_DOC_NM_SETTING_VXLAN_L2_MISS "Specifies whether netlink LL ADDR miss notifications are generated." +#define DESCRIBE_DOC_NM_SETTING_VXLAN_L3_MISS "Specifies whether netlink IP ADDR miss notifications are generated." +#define DESCRIBE_DOC_NM_SETTING_VXLAN_LEARNING "Specifies whether unknown source link layer addresses and IP addresses are entered into the VXLAN device forwarding database." +#define DESCRIBE_DOC_NM_SETTING_VXLAN_LIMIT "Specifies the maximum number of FDB entries. A value of zero means that the kernel will store unlimited entries." +#define DESCRIBE_DOC_NM_SETTING_VXLAN_LOCAL "If given, specifies the source IP address to use in outgoing packets." +#define DESCRIBE_DOC_NM_SETTING_VXLAN_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_VXLAN_PARENT "If given, specifies the parent interface name or parent connection UUID." +#define DESCRIBE_DOC_NM_SETTING_VXLAN_PROXY "Specifies whether ARP proxy is turned on." +#define DESCRIBE_DOC_NM_SETTING_VXLAN_REMOTE "Specifies the unicast destination IP address to use in outgoing packets when the destination link layer address is not known in the VXLAN device forwarding database, or the multicast IP address to join." +#define DESCRIBE_DOC_NM_SETTING_VXLAN_RSC "Specifies whether route short circuit is turned on." +#define DESCRIBE_DOC_NM_SETTING_VXLAN_SOURCE_PORT_MAX "Specifies the maximum UDP source port to communicate to the remote VXLAN tunnel endpoint." +#define DESCRIBE_DOC_NM_SETTING_VXLAN_SOURCE_PORT_MIN "Specifies the minimum UDP source port to communicate to the remote VXLAN tunnel endpoint." +#define DESCRIBE_DOC_NM_SETTING_VXLAN_TOS "Specifies the TOS value to use in outgoing packets." +#define DESCRIBE_DOC_NM_SETTING_VXLAN_TTL "Specifies the time-to-live value to use in outgoing packets." +#define DESCRIBE_DOC_NM_SETTING_WIMAX_MAC_ADDRESS "If specified, this connection will only apply to the WiMAX device whose MAC address matches. This property does not change the MAC address of the device (known as MAC spoofing). Deprecated: 1" +#define DESCRIBE_DOC_NM_SETTING_WIMAX_NAME "The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\"." +#define DESCRIBE_DOC_NM_SETTING_WIMAX_NETWORK_NAME "Network Service Provider (NSP) name of the WiMAX network this connection should use. Deprecated: 1" diff --git a/clients/common/tests/test-general.c b/clients/common/tests/test-general.c new file mode 100644 index 0000000000..469dc57a73 --- /dev/null +++ b/clients/common/tests/test-general.c @@ -0,0 +1,145 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2017 Red Hat, Inc. + */ + +#include "nm-default.h" + +#include "NetworkManager.h" + +#include "nm-meta-setting-access.h" + +#include "nm-utils/nm-test-utils.h" + +/*****************************************************************************/ + +static void +test_client_meta_check (void) +{ + const NMMetaSettingInfoEditor *const*infos_p; + NMMetaSettingType m; + guint p; + + for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) { + const NMMetaSettingInfo *info = &nm_meta_setting_infos[m]; + GType gtype; + + g_assert (info); + g_assert (info->meta_type == m); + g_assert (info->setting_name); + g_assert (info->get_setting_gtype); + + gtype = info->get_setting_gtype (); + g_assert (gtype != NM_TYPE_SETTING); + + { + nm_auto_unref_gtypeclass GTypeClass *gclass = g_type_class_ref (gtype); + + g_assert (G_TYPE_CHECK_CLASS_TYPE (gclass, gtype)); + } + { + gs_unref_object NMSetting *setting = g_object_new (gtype, NULL); + + g_assert (NM_IS_SETTING (setting)); + g_assert (G_TYPE_CHECK_INSTANCE_TYPE (setting, gtype)); + g_assert_cmpstr (nm_setting_get_name (setting), ==, info->setting_name); + } + } + + for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) { + const NMMetaSettingInfoEditor *info = &nm_meta_setting_infos_editor[m]; + + g_assert (info); + g_assert (info->meta_type == &nm_meta_type_setting_info_editor); + 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)); + + if (info->properties_num) { + gs_unref_hashtable GHashTable *property_names = g_hash_table_new (g_str_hash, g_str_equal); + + g_assert (info->properties); + for (p = 0; p < info->properties_num; p++) { + const NMMetaPropertyInfo *pi = &info->properties[p]; + + g_assert (pi->meta_type == &nm_meta_type_property_info); + g_assert (pi->setting_info == info); + g_assert (pi->property_name); + + 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 (pi->property_type); + g_assert (pi->property_type->get_fcn); + } + } else + g_assert (!info->properties); + } + + for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) { + const NMMetaPropertyInfo *const*pis; + const NMMetaSettingInfoEditor *info = &nm_meta_setting_infos_editor[m]; + + pis = nm_property_infos_for_setting_type (m); + g_assert (pis); + + for (p = 0; p < info->properties_num; p++) + g_assert (pis[p] == &info->properties[p]); + g_assert (!pis[p]); + } + + 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_gtype (info->general->get_setting_gtype ()) == info); + + for (p = 0; p < info->properties_num; p++) { + const NMMetaPropertyInfo *pi = &info->properties[p]; + + g_assert (nm_meta_setting_info_editor_get_property_info (info, pi->property_name) == pi); + g_assert (nm_meta_property_info_find_by_name (info->general->setting_name, pi->property_name) == pi); + } + } + + infos_p = nm_meta_setting_infos_editor_p (); + g_assert (infos_p); + for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) + g_assert (infos_p[m] == &nm_meta_setting_infos_editor[m]); + g_assert (!infos_p[m]); +} + +/*****************************************************************************/ + +NMTST_DEFINE (); + +int +main (int argc, char **argv) +{ + nmtst_init (&argc, &argv, TRUE); + + g_test_add_func ("/client/meta/check", test_client_meta_check); + + return g_test_run (); +} diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index 176c0600f9..caaa1572b0 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -175,11 +175,6 @@ gssize _nm_utils_ptrarray_find_first (gconstpointer *list, gssize len, gconstpoi gssize _nm_utils_ptrarray_find_binary_search (gconstpointer *list, gsize len, gconstpointer needle, GCompareDataFunc cmpfcn, gpointer user_data); gssize _nm_utils_array_find_binary_search (gconstpointer list, gsize elem_size, gsize len, gconstpointer needle, GCompareDataFunc cmpfcn, gpointer user_data); -char **_nm_utils_strv_cleanup (char **strv, - gboolean strip_whitespace, - gboolean skip_empty, - gboolean skip_repeated); - char ** _nm_utils_strsplit_set (const char *str, const char *delimiters, int max_tokens); diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 5c5b94c667..fd94b9aeea 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -444,36 +444,6 @@ nm_utils_same_ssid (const guint8 *ssid1, gsize len1, return memcmp (ssid1, ssid2, len1) == 0 ? TRUE : FALSE; } -char ** -_nm_utils_strv_cleanup (char **strv, - gboolean strip_whitespace, - gboolean skip_empty, - gboolean skip_repeated) -{ - guint i, j; - - if (!strv || !*strv) - return strv; - - if (strip_whitespace) { - for (i = 0; strv[i]; i++) - g_strstrip (strv[i]); - } - if (!skip_empty && !skip_repeated) - return strv; - j = 0; - for (i = 0; strv[i]; i++) { - if ( (skip_empty && !*strv[i]) - || (skip_repeated && nm_utils_strv_find_first (strv, j, strv[i]) >= 0)) - g_free (strv[i]); - else - strv[j++] = strv[i]; - } - strv[j] = NULL; - return strv; -} - - gboolean _nm_utils_string_slist_validate (GSList *list, const char **valid_values) { diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index 3f836a78d7..f362968f58 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -633,6 +633,50 @@ nm_clear_g_cancellable (GCancellable **cancellable) /*****************************************************************************/ +#define NM_UTILS_LOOKUP_DEFAULT(v) return (v) +#define NM_UTILS_LOOKUP_DEFAULT_WARN(v) g_return_val_if_reached (v) +#define NM_UTILS_LOOKUP_DEFAULT_NM_ASSERT(v) { nm_assert_not_reached (); return (v); } +#define NM_UTILS_LOOKUP_ITEM(v, n) (void) 0; case v: return (n); (void) 0 +#define NM_UTILS_LOOKUP_STR_ITEM(v, n) NM_UTILS_LOOKUP_ITEM(v, ""n"") +#define NM_UTILS_LOOKUP_ITEM_IGNORE(v) (void) 0; case v: break; (void) 0 +#define NM_UTILS_LOOKUP_ITEM_IGNORE_OTHER() (void) 0; default: break; (void) 0 + +#define _NM_UTILS_LOOKUP_DEFINE(scope, fcn_name, lookup_type, result_type, unknown_val, ...) \ +scope result_type \ +fcn_name (lookup_type val) \ +{ \ + switch (val) { \ + (void) 0, \ + __VA_ARGS__ \ + (void) 0; \ + }; \ + { unknown_val; } \ +} + +#define NM_UTILS_LOOKUP_STR_DEFINE(fcn_name, lookup_type, unknown_val, ...) \ + _NM_UTILS_LOOKUP_DEFINE (, fcn_name, lookup_type, const char *, unknown_val, __VA_ARGS__) +#define NM_UTILS_LOOKUP_STR_DEFINE_STATIC(fcn_name, lookup_type, unknown_val, ...) \ + _NM_UTILS_LOOKUP_DEFINE (static, fcn_name, lookup_type, const char *, unknown_val, __VA_ARGS__) + +/* Call the string-lookup-table function @fcn_name. If the function returns + * %NULL, the numeric index is converted to string using a alloca() buffer. + * Beware: this macro uses alloca(). */ +#define NM_UTILS_LOOKUP_STR(fcn_name, idx) \ + ({ \ + typeof (idx) _idx = (idx); \ + const char *_s; \ + \ + _s = fcn_name (_idx); \ + if (!_s) { \ + _s = g_alloca (30); \ + \ + g_snprintf ((char *) _s, 30, "(%lld)", (long long) _idx); \ + } \ + _s; \ + }) + +/*****************************************************************************/ + /* check if @flags has exactly one flag (@check) set. You should call this * only with @check being a compile time constant and a power of two. */ #define NM_FLAGS_HAS(flags, check) \ diff --git a/shared/nm-utils/nm-shared-utils.c b/shared/nm-utils/nm-shared-utils.c index 413526dc2a..1a83cb9da3 100644 --- a/shared/nm-utils/nm-shared-utils.c +++ b/shared/nm-utils/nm-shared-utils.c @@ -204,6 +204,35 @@ nm_utils_strv_find_first (char **list, gssize len, const char *needle) return -1; } +char ** +_nm_utils_strv_cleanup (char **strv, + gboolean strip_whitespace, + gboolean skip_empty, + gboolean skip_repeated) +{ + guint i, j; + + if (!strv || !*strv) + return strv; + + if (strip_whitespace) { + for (i = 0; strv[i]; i++) + g_strstrip (strv[i]); + } + if (!skip_empty && !skip_repeated) + return strv; + j = 0; + for (i = 0; strv[i]; i++) { + if ( (skip_empty && !*strv[i]) + || (skip_repeated && nm_utils_strv_find_first (strv, j, strv[i]) >= 0)) + g_free (strv[i]); + else + strv[j++] = strv[i]; + } + strv[j] = NULL; + return strv; +} + /*****************************************************************************/ gint diff --git a/shared/nm-utils/nm-shared-utils.h b/shared/nm-utils/nm-shared-utils.h index b559401c8b..4d8f300c85 100644 --- a/shared/nm-utils/nm-shared-utils.h +++ b/shared/nm-utils/nm-shared-utils.h @@ -45,6 +45,11 @@ void nm_utils_strbuf_append_str (char **buf, gsize *len, const char *str); gssize nm_utils_strv_find_first (char **list, gssize len, const char *needle); +char **_nm_utils_strv_cleanup (char **strv, + gboolean strip_whitespace, + gboolean skip_empty, + gboolean skip_repeated); + /*****************************************************************************/ gint64 _nm_utils_ascii_str_to_int64 (const char *str, guint base, gint64 min, gint64 max, gint64 fallback); diff --git a/src/nm-core-utils.h b/src/nm-core-utils.h index 832d0dc760..0875dc32ca 100644 --- a/src/nm-core-utils.h +++ b/src/nm-core-utils.h @@ -223,50 +223,6 @@ fcn_name (lookup_type val, char *buf, gsize len) \ /*****************************************************************************/ -#define NM_UTILS_LOOKUP_DEFAULT(v) return (v) -#define NM_UTILS_LOOKUP_DEFAULT_WARN(v) g_return_val_if_reached (v) -#define NM_UTILS_LOOKUP_DEFAULT_NM_ASSERT(v) { nm_assert_not_reached (); return (v); } -#define NM_UTILS_LOOKUP_ITEM(v, n) (void) 0; case v: return (n); (void) 0 -#define NM_UTILS_LOOKUP_STR_ITEM(v, n) NM_UTILS_LOOKUP_ITEM(v, ""n"") -#define NM_UTILS_LOOKUP_ITEM_IGNORE(v) (void) 0; case v: break; (void) 0 -#define NM_UTILS_LOOKUP_ITEM_IGNORE_OTHER() (void) 0; default: break; (void) 0 - -#define _NM_UTILS_LOOKUP_DEFINE(scope, fcn_name, lookup_type, result_type, unknown_val, ...) \ -scope result_type \ -fcn_name (lookup_type val) \ -{ \ - switch (val) { \ - (void) 0, \ - __VA_ARGS__ \ - (void) 0; \ - }; \ - { unknown_val; } \ -} - -#define NM_UTILS_LOOKUP_STR_DEFINE(fcn_name, lookup_type, unknown_val, ...) \ - _NM_UTILS_LOOKUP_DEFINE (, fcn_name, lookup_type, const char *, unknown_val, __VA_ARGS__) -#define NM_UTILS_LOOKUP_STR_DEFINE_STATIC(fcn_name, lookup_type, unknown_val, ...) \ - _NM_UTILS_LOOKUP_DEFINE (static, fcn_name, lookup_type, const char *, unknown_val, __VA_ARGS__) - -/* Call the string-lookup-table function @fcn_name. If the function returns - * %NULL, the numeric index is converted to string using a alloca() buffer. - * Beware: this macro uses alloca(). */ -#define NM_UTILS_LOOKUP_STR(fcn_name, idx) \ - ({ \ - typeof (idx) _idx = (idx); \ - const char *_s; \ - \ - _s = fcn_name (_idx); \ - if (!_s) { \ - _s = g_alloca (30); \ - \ - g_snprintf ((char *) _s, 30, "(%lld)", (long long) _idx); \ - } \ - _s; \ - }) - -/*****************************************************************************/ - const char *nm_utils_get_ip_config_method (NMConnection *connection, GType ip_setting_type);