From 4f4f9807a43f24d04e0f5ef58ebff5cd9b782fde Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 4 Nov 2022 15:00:56 +0100 Subject: [PATCH 1/5] libnm: use NMStrBuf in "gen-metadata-nm-settings-libnm-core.c" It's more convenient to use, because we don't need to keep track (and free) the allocated string. --- .../gen-metadata-nm-settings-libnm-core.c | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.c b/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.c index eeadb19c32..526ea96fa7 100644 --- a/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.c +++ b/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.c @@ -2,18 +2,23 @@ #include "libnm-core-impl/nm-default-libnm-core.h" +#include "libnm-glib-aux/nm-str-buf.h" #include "libnm-core-intern/nm-meta-setting-base.h" #include "libnm-core-intern/nm-core-internal.h" #define INDENT 4 -static char * -_xml_escape_attribute(const char *value) +static const char * +_xml_escape_attr(NMStrBuf *sbuf, const char *value) { gs_free char *s = NULL; + nm_str_buf_reset(sbuf); s = g_markup_escape_text(value, -1); - return g_strdup_printf("\"%s\"", s); + nm_str_buf_append_c(sbuf, '"'); + nm_str_buf_append(sbuf, s); + nm_str_buf_append_c(sbuf, '"'); + return nm_str_buf_get_str(sbuf); } static const char * @@ -28,16 +33,15 @@ _indent_level(guint num_spaces) int main(int argc, char *argv[]) { + nm_auto_str_buf NMStrBuf sbuf1 = NM_STR_BUF_INIT(NM_UTILS_GET_NEXT_REALLOC_SIZE_1000, FALSE); const NMSettInfoSetting *sett_info_settings = nmtst_sett_info_settings(); NMMetaSettingType meta_type; g_print("\n"); for (meta_type = 0; meta_type < _NM_META_SETTING_TYPE_NUM; meta_type++) { - const NMSettInfoSetting *sis = &sett_info_settings[meta_type]; - const NMMetaSettingInfo *msi = &nm_meta_setting_infos[meta_type]; - nm_auto_unref_gtypeclass NMSettingClass *klass = NULL; - gs_free char *tmp_s1 = NULL; - gs_free char *tmp_s2 = NULL; + const NMSettInfoSetting *sis = &sett_info_settings[meta_type]; + const NMMetaSettingInfo *msi = &nm_meta_setting_infos[meta_type]; + nm_auto_unref_gtypeclass NMSettingClass *klass = NULL; guint prop_idx; GType gtype; @@ -45,23 +49,20 @@ main(int argc, char *argv[]) klass = g_type_class_ref(gtype); g_print("%ssetting_name))); + g_print(" name=%s", _xml_escape_attr(&sbuf1, msi->setting_name)); g_print(" >\n"); for (prop_idx = 0; prop_idx < sis->property_infos_len; prop_idx++) { - const NMSettInfoProperty *sip = &sis->property_infos[prop_idx]; - gs_free char *tmp2 = NULL; - gs_free char *tmp3 = NULL; + const NMSettInfoProperty *sip = &sis->property_infos[prop_idx]; g_print("%sname))); + g_print(" name=%s", _xml_escape_attr(&sbuf1, sip->name)); if (sip->is_deprecated) g_print("\n%sis-deprecated=\"1\"", _indent_level(2 * INDENT + 10)); if (sip->property_type->dbus_type) { - g_print( - "\n%sdbus-type=%s", - _indent_level(2 * INDENT + 10), - (tmp3 = _xml_escape_attribute((const char *) sip->property_type->dbus_type))); + g_print("\n%sdbus-type=%s", + _indent_level(2 * INDENT + 10), + _xml_escape_attr(&sbuf1, (const char *) sip->property_type->dbus_type)); } if (sip->dbus_deprecated) { nm_assert(sip->property_type->dbus_type); From 7d9f65ebc4759c42deb78f56035fb066a839d319 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 4 Nov 2022 15:03:24 +0100 Subject: [PATCH 2/5] libnm: add code comment in "gen-metadata-nm-settings-libnm-core.xml" --- .../gen-metadata-nm-settings-libnm-core.c | 31 +++++++++++++++++++ ...gen-metadata-nm-settings-libnm-core.xml.in | 30 ++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.c b/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.c index 526ea96fa7..ee74cdce45 100644 --- a/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.c +++ b/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.c @@ -37,6 +37,37 @@ main(int argc, char *argv[]) const NMSettInfoSetting *sett_info_settings = nmtst_sett_info_settings(); NMMetaSettingType meta_type; + g_print("\n"); g_print("\n"); for (meta_type = 0; meta_type < _NM_META_SETTING_TYPE_NUM; meta_type++) { const NMSettInfoSetting *sis = &sett_info_settings[meta_type]; diff --git a/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.xml.in b/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.xml.in index dfda03ac07..9db824833e 100644 --- a/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.xml.in +++ b/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.xml.in @@ -1,3 +1,33 @@ + Date: Fri, 4 Nov 2022 15:04:27 +0100 Subject: [PATCH 3/5] libnm: show gprop-data,is-secret,is-secret-flags in "gen-metadata-nm-settings-libnm-core.xml" --- .../gen-metadata-nm-settings-libnm-core.c | 20 +- ...gen-metadata-nm-settings-libnm-core.xml.in | 2039 +++++++++++++---- 2 files changed, 1555 insertions(+), 504 deletions(-) diff --git a/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.c b/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.c index ee74cdce45..8f5b0ede27 100644 --- a/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.c +++ b/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.c @@ -62,11 +62,15 @@ main(int argc, char *argv[]) " Attributes:\n" " \"name\": the name of the property.\n" " \"is-deprecated\": whether this property is deprecated.\n" + " \"is-secret\": whether this property is a secret.\n" + " \"is-secret-flags\": whether this property is a secret flags property.\n" " \"dbus-type\": if this property is exposed on D-Bus. In that case, this\n" " is the D-Bus type format. Also, \"name\" is the actual name of the field\n" " \"dbus-deprecated\": if this property is on D-Bus and that representation is\n" " deprecated. This usually means, that there is a replacement D-Bus property\n" " that should be used instead.\n" + " \"gprop-type\": if this is a GObject property in the NMSetting class, this\n" + " is the GParamSpec.value_type of the property.\n" " -->\n"); g_print("\n"); for (meta_type = 0; meta_type < _NM_META_SETTING_TYPE_NUM; meta_type++) { @@ -90,6 +94,13 @@ main(int argc, char *argv[]) g_print(" name=%s", _xml_escape_attr(&sbuf1, sip->name)); if (sip->is_deprecated) g_print("\n%sis-deprecated=\"1\"", _indent_level(2 * INDENT + 10)); + if (sip->param_spec && NM_FLAGS_HAS(sip->param_spec->flags, NM_SETTING_PARAM_SECRET)) { + g_print("\n%sis-secret=\"1\"", _indent_level(2 * INDENT + 10)); + } + if (sip->param_spec + && G_PARAM_SPEC_VALUE_TYPE(sip->param_spec) == NM_TYPE_SETTING_SECRET_FLAGS) { + g_print("\n%sis-secret-flags=\"1\"", _indent_level(2 * INDENT + 10)); + } if (sip->property_type->dbus_type) { g_print("\n%sdbus-type=%s", _indent_level(2 * INDENT + 10), @@ -99,7 +110,14 @@ main(int argc, char *argv[]) nm_assert(sip->property_type->dbus_type); g_print("\n%sdbus-deprecated=\"1\"", _indent_level(2 * INDENT + 10)); } - g_print(" />\n"); + if (sip->param_spec) { + nm_assert(nm_streq(sip->name, sip->param_spec->name)); + g_print("\n%sgprop-type=%s", + _indent_level(2 * INDENT + 10), + _xml_escape_attr(&sbuf1, + g_type_name(G_PARAM_SPEC_VALUE_TYPE(sip->param_spec)))); + } + g_print("\n%s/>\n", _indent_level(2 * INDENT + 10)); } g_print("%s\n", _indent_level(INDENT)); diff --git a/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.xml.in b/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.xml.in index 9db824833e..0b8853e611 100644 --- a/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.xml.in +++ b/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.xml.in @@ -22,1144 +22,2177 @@ Attributes: "name": the name of the property. "is-deprecated": whether this property is deprecated. + "is-secret": whether this property is a secret. + "is-secret-flags": whether this property is a secret flags property. "dbus-type": if this property is exposed on D-Bus. In that case, this is the D-Bus type format. Also, "name" is the actual name of the field "dbus-deprecated": if this property is on D-Bus and that representation is deprecated. This usually means, that there is a replacement D-Bus property that should be used instead. + "gprop-type": if this is a GObject property in the NMSetting class, this + is the GParamSpec.value_type of the property. --> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="ay" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="ay" + gprop-type="GBytes" + /> + dbus-type="i" + gprop-type="NMTernary" + /> + dbus-type="s" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="ay" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-deprecated="1" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="ay" + gprop-type="gchararray" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-deprecated="1" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="ay" + gprop-type="GBytes" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="s" + gprop-type="gchararray" + /> + is-secret="1" + dbus-type="s" + gprop-type="gchararray" + /> + is-secret-flags="1" + dbus-type="u" + gprop-type="NMSettingSecretFlags" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="as" + gprop-type="GStrv" + /> + is-secret="1" + dbus-type="s" + gprop-type="gchararray" + /> + is-secret-flags="1" + dbus-type="u" + gprop-type="NMSettingSecretFlags" + /> + is-secret-flags="1" + dbus-type="u" + gprop-type="NMSettingSecretFlags" + /> + dbus-type="u" + gprop-type="NMWepKeyType" + /> + is-secret="1" + dbus-type="s" + gprop-type="gchararray" + /> + is-secret="1" + dbus-type="s" + gprop-type="gchararray" + /> + is-secret="1" + dbus-type="s" + gprop-type="gchararray" + /> + is-secret="1" + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="ay" + gprop-type="GBytes" + /> + is-secret="1" + dbus-type="s" + gprop-type="gchararray" + /> + is-secret-flags="1" + dbus-type="u" + gprop-type="NMSettingSecretFlags" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="ay" + gprop-type="GBytes" + /> + is-secret="1" + dbus-type="s" + gprop-type="gchararray" + /> + is-secret-flags="1" + dbus-type="u" + gprop-type="NMSettingSecretFlags" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="s" + gprop-type="gchararray" + /> + is-secret="1" + dbus-type="s" + gprop-type="gchararray" + /> + is-secret-flags="1" + dbus-type="u" + gprop-type="NMSettingSecretFlags" + /> + is-secret="1" + dbus-type="ay" + gprop-type="GBytes" + /> + is-secret-flags="1" + dbus-type="u" + gprop-type="NMSettingSecretFlags" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="ay" + gprop-type="GBytes" + /> + is-secret="1" + dbus-type="s" + gprop-type="gchararray" + /> + is-secret-flags="1" + dbus-type="u" + gprop-type="NMSettingSecretFlags" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="ay" + gprop-type="GBytes" + /> + is-secret="1" + dbus-type="s" + gprop-type="gchararray" + /> + is-secret-flags="1" + dbus-type="u" + gprop-type="NMSettingSecretFlags" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="ay" + gprop-type="GBytes" + /> + is-secret="1" + dbus-type="s" + gprop-type="gchararray" + /> + is-secret-flags="1" + dbus-type="u" + gprop-type="NMSettingSecretFlags" + /> + dbus-type="s" + gprop-type="gchararray" + /> + is-secret="1" + dbus-type="s" + gprop-type="gchararray" + /> + is-secret-flags="1" + dbus-type="u" + gprop-type="NMSettingSecretFlags" + /> + dbus-type="ay" + gprop-type="GBytes" + /> + is-secret="1" + dbus-type="s" + gprop-type="gchararray" + /> + is-secret-flags="1" + dbus-type="u" + gprop-type="NMSettingSecretFlags" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="i" + gprop-type="NMTernary" + /> + dbus-type="s" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-deprecated="1" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="ay" + gprop-type="gchararray" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="a{ss}" + gprop-type="GHashTable" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + is-secret="1" + dbus-type="s" + gprop-type="gchararray" + /> + is-secret-flags="1" + dbus-type="u" + gprop-type="NMSettingSecretFlags" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="ay" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-deprecated="1" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="a{ss}" + gprop-type="GHashTable" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="ay" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-deprecated="1" + /> + dbus-type="ay" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="t" + gprop-type="guint64" + /> + dbus-type="t" + gprop-type="guint64" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="t" + gprop-type="guint64" + /> + dbus-type="t" + gprop-type="guint64" + /> + dbus-type="t" + gprop-type="guint64" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="t" + gprop-type="guint64" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="aa{sv}" + gprop-type="GPtrArray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="aa{sv}" + gprop-type="GPtrArray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + is-secret="1" + dbus-type="s" + gprop-type="gchararray" + /> + is-secret-flags="1" + dbus-type="u" + gprop-type="NMSettingSecretFlags" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="i" + gprop-type="NMSettingConnectionAutoconnectSlaves" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="i" + gprop-type="NMMetered" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="t" + gprop-type="guint64" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="NMSettingDcbFlags" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="u" + gprop-type="NMSettingDcbFlags" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="u" + gprop-type="NMSettingDcbFlags" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="au" + gprop-type="GArray" + /> + dbus-type="au" + gprop-type="GArray" + /> + dbus-type="u" + gprop-type="NMSettingDcbFlags" + /> + dbus-type="au" + gprop-type="GArray" + /> + dbus-type="u" + gprop-type="NMSettingDcbFlags" + /> + dbus-type="au" + gprop-type="GArray" + /> + dbus-type="au" + gprop-type="GArray" + /> + dbus-type="au" + gprop-type="GArray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-deprecated="1" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-deprecated="1" + /> + dbus-type="s" + gprop-type="gchararray" + /> + is-secret="1" + dbus-type="s" + gprop-type="gchararray" + /> + is-secret-flags="1" + dbus-type="u" + gprop-type="NMSettingSecretFlags" + /> + is-secret="1" + dbus-type="s" + gprop-type="gchararray" + /> + is-secret-flags="1" + dbus-type="u" + gprop-type="NMSettingSecretFlags" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="i" + gprop-type="NMTernary" + /> + dbus-type="i" + gprop-type="NMTernary" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="i" + gprop-type="NMTernary" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="ay" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="aa{sv}" + /> + dbus-deprecated="1" + /> + dbus-deprecated="1" + gprop-type="GPtrArray" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-deprecated="1" + gprop-type="GStrv" + /> + dbus-type="as" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="aa{sv}" + /> + dbus-type="x" + gprop-type="gint64" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-deprecated="1" + gprop-type="GPtrArray" + /> + dbus-type="aa{sv}" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="aa{sv}" + /> + dbus-deprecated="1" + gprop-type="GPtrArray" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-deprecated="1" + gprop-type="GStrv" + /> + dbus-type="as" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="i" + gprop-type="NMSettingIP6ConfigPrivacy" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="aa{sv}" + /> + dbus-type="x" + gprop-type="gint64" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-deprecated="1" + gprop-type="GPtrArray" + /> + dbus-type="aa{sv}" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + is-secret="1" + dbus-type="s" + gprop-type="gchararray" + /> + is-secret-flags="1" + dbus-type="u" + gprop-type="NMSettingSecretFlags" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="a{ss}" + gprop-type="GHashTable" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + is-secret="1" + dbus-type="s" + gprop-type="gchararray" + /> + is-secret-flags="1" + dbus-type="u" + gprop-type="NMSettingSecretFlags" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="y" + gprop-type="NMSettingSerialParity" + /> + dbus-type="t" + gprop-type="guint64" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="i" + gprop-type="NMTernary" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="aa{sv}" + gprop-type="GPtrArray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="aa{sv}" + gprop-type="GPtrArray" + /> + dbus-type="aa{sv}" + gprop-type="GPtrArray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-deprecated="1" + /> + dbus-type="aa{sv}" + gprop-type="GPtrArray" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="aa{sv}" + gprop-type="GPtrArray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="a{ss}" + gprop-type="GHashTable" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-type="u" + gprop-type="NMVlanFlags" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="as" + gprop-type="GStrv" + /> + dbus-deprecated="1" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="a{ss}" + gprop-type="GHashTable" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + is-secret="1" + dbus-type="a{ss}" + gprop-type="GHashTable" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="ay" + gprop-type="GBytes" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="ay" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="i" + gprop-type="NMTernary" + /> + dbus-type="i" + gprop-type="NMTernary" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="b" + gprop-type="gboolean" + /> + dbus-type="aa{sv}" + /> + is-secret="1" + dbus-type="s" + gprop-type="gchararray" + /> + is-secret-flags="1" + dbus-type="u" + gprop-type="NMSettingSecretFlags" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="s" + gprop-type="gchararray" + /> + dbus-type="i" + gprop-type="gint" + /> + dbus-type="u" + gprop-type="guint" + /> + dbus-type="u" + gprop-type="guint" + /> From fd2d66953c8a7a1ed8dbb24b33cb9fbe57e38254 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 4 Nov 2022 16:51:41 +0100 Subject: [PATCH 4/5] libnm: show NMSetting gtype in "gen-metadata-nm-settings-libnm-core.xml" --- .../gen-metadata-nm-settings-libnm-core.c | 11 +- ...gen-metadata-nm-settings-libnm-core.xml.in | 214 +++++++++++++----- 2 files changed, 170 insertions(+), 55 deletions(-) diff --git a/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.c b/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.c index 8f5b0ede27..2d4f4406cb 100644 --- a/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.c +++ b/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.c @@ -59,7 +59,11 @@ main(int argc, char *argv[]) " NetworkManager. Whether and how it is represented in nmcli or keyfile, may differ.\n" " The XML however aims to provide information for various backends.\n" "\n" - " Attributes:\n" + " Attributes:\n" + " \"name\": the name of the setting.\n" + " \"gtype\": the typename of the NMSetting class in libnm.\n" + "\n" + " Attributes:\n" " \"name\": the name of the property.\n" " \"is-deprecated\": whether this property is deprecated.\n" " \"is-secret\": whether this property is a secret.\n" @@ -85,7 +89,10 @@ main(int argc, char *argv[]) g_print("%ssetting_name)); - g_print(" >\n"); + g_print("\n%sgtype=%s", + _indent_level(INDENT + 9), + _xml_escape_attr(&sbuf1, g_type_name(gtype))); + g_print("\n%s>\n", _indent_level(INDENT + 9)); for (prop_idx = 0; prop_idx < sis->property_infos_len; prop_idx++) { const NMSettInfoProperty *sip = &sis->property_infos[prop_idx]; diff --git a/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.xml.in b/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.xml.in index 0b8853e611..3fce88347d 100644 --- a/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.xml.in +++ b/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.xml.in @@ -19,7 +19,11 @@ NetworkManager. Whether and how it is represented in nmcli or keyfile, may differ. The XML however aims to provide information for various backends. - Attributes: + Attributes: + "name": the name of the setting. + "gtype": the typename of the NMSetting class in libnm. + + Attributes: "name": the name of the property. "is-deprecated": whether this property is deprecated. "is-secret": whether this property is a secret. @@ -33,7 +37,9 @@ is the GParamSpec.value_type of the property. --> - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1282,7 +1332,9 @@ dbus-type="aa{sv}" /> - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + Date: Fri, 4 Nov 2022 17:06:35 +0100 Subject: [PATCH 5/5] libnm: add nm_utils_ensure_gtypes() helper to API "gen-metadata-nm-settings-libnm-core.xml" now contains also the names of the NMSetting types, like "NMSettingConnection". That can be useful to create NMSetting instances generically (that is, without knowing the C API that gets called). So you might be tempted to run #!/bin/python import gi gi.require_version("NM", "1.0") from gi.repository import GObject, NM connection = NM.SimpleConnection() # NM.utils_ensure_gtypes() gtype_name = "NMSetting6Lowpan" gtype = GObject.type_from_name(gtype_name) setting = GObject.new(gtype) connection.add_setting(setting) However, without NM.utils_ensure_gtypes() that would not work, because the GType is not yet created. For a user who doesn't know a priory all setting types, it's not entirely clear how to make this work. Well, a GObject introspection user could iterate over al NM.Setting* names and try to instantiate the classes. However, that is still cumbersome, and not accessible to a C user (without GI) and the currently loaded libnm library may be newer and have unknown setting types. In particular plain C user would need to know to call all the right nm_setting_*_get_type(), functions, so it needs to know all the existing 52 type getters (and cannot support those from a newer libnm version). With nm_utils_ensure_gtypes(), the user can get the typename and create instances generically only using g_type_from_name(). Possible alternatives: - libnm also has _nm_utils_init() which runs as __attribute__((constructor)). We could also always instantiate all GType there. However, I don't like running non-trivial, absolutely necessary code before main(). - hook nm_setting_get_type() to create all GType for the NMSetting subclasses too. The problem is, that it's not entirely trivial to avoid deadlock. - hook nm_connection_get_type() to create all NMSetting types. That would not deadlock, but it still is questionable whether we should automatically, at non-obvious times instantiate all GTypes. --- src/libnm-client-impl/libnm.ver | 1 + src/libnm-core-impl/nm-utils.c | 21 +++++++++++++++++++++ src/libnm-core-public/nm-utils.h | 3 +++ 3 files changed, 25 insertions(+) diff --git a/src/libnm-client-impl/libnm.ver b/src/libnm-client-impl/libnm.ver index 8207ee13b6..5c7890f01b 100644 --- a/src/libnm-client-impl/libnm.ver +++ b/src/libnm-client-impl/libnm.ver @@ -1851,4 +1851,5 @@ global: nm_client_wait_shutdown_finish; nm_setting_ip_config_get_dhcp_iaid; nm_setting_ovs_interface_get_ofport_request; + nm_utils_ensure_gtypes; } libnm_1_40_0; diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index 6550dc38d3..7d7565a91e 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -5633,3 +5633,24 @@ _nm_utils_validate_dhcp_hostname_flags(NMDhcpHostnameFlags flags, int addr_famil return TRUE; } + +/*****************************************************************************/ + +/** + * nm_utils_ensure_gtypes: + * + * This ensures that all NMSetting GTypes are created. For example, + * after this call, g_type_from_name("NMSettingConnection") will work. + * + * This cannot fail and does nothing if the type already exists. + * + * Since: 1.42 + */ +void +nm_utils_ensure_gtypes(void) +{ + NMMetaSettingType meta_type; + + for (meta_type = 0; meta_type < _NM_META_SETTING_TYPE_NUM; meta_type++) + nm_meta_setting_infos[meta_type].get_setting_gtype(); +} diff --git a/src/libnm-core-public/nm-utils.h b/src/libnm-core-public/nm-utils.h index 5faed75a36..3897915567 100644 --- a/src/libnm-core-public/nm-utils.h +++ b/src/libnm-core-public/nm-utils.h @@ -250,6 +250,9 @@ NM_AVAILABLE_IN_1_16 gboolean nm_utils_base64secret_decode(const char *base64_key, gsize required_key_len, guint8 *out_key); +NM_AVAILABLE_IN_1_42 +void nm_utils_ensure_gtypes(void); + G_END_DECLS #endif /* __NM_UTILS_H__ */