diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2020-07-07 18:03:48 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2020-07-08 09:43:06 +0200 |
commit | ee946ca27d432a7eef3b223e8c8d48f05fa4d8c2 (patch) | |
tree | 6d2963763421298531c7368fe9e897c776674693 | |
parent | d0d35aa278da490408f33ee90e30d556e22bc647 (diff) | |
download | NetworkManager-ee946ca27d432a7eef3b223e8c8d48f05fa4d8c2.tar.gz |
libnm-core: pass variant-attribute-spec to format function
The output of nm_utils_format_variant_attributes() must be accepted by
nm_utils_parse_variant_attributes(), producing the initial attributes.
The latter has a special handling of some attributes, depending on the
input NMVariantAttributeSpec list. For example, if the
NMVariantAttributeSpec is a boolean with the 'no_value' flag, the
parser doesn't look for a value.
Pass the NMVariantAttributeSpec list to the format function so that it
can behave in the same way as the parse one.
-rw-r--r-- | libnm-core/nm-utils-private.h | 10 | ||||
-rw-r--r-- | libnm-core/nm-utils.c | 3 | ||||
-rw-r--r-- | shared/nm-glib-aux/nm-shared-utils.c | 15 | ||||
-rw-r--r-- | shared/nm-glib-aux/nm-shared-utils.h | 14 |
4 files changed, 31 insertions, 11 deletions
diff --git a/libnm-core/nm-utils-private.h b/libnm-core/nm-utils-private.h index dd3785be0f..75e8b5bd86 100644 --- a/libnm-core/nm-utils-private.h +++ b/libnm-core/nm-utils-private.h @@ -13,16 +13,6 @@ #include "nm-setting-private.h" #include "nm-setting-ip-config.h" -struct _NMVariantAttributeSpec { - char *name; - const GVariantType *type; - bool v4:1; - bool v6:1; - bool no_value:1; - bool consumes_rest:1; - char str_type; -}; - #define NM_VARIANT_ATTRIBUTE_SPEC_DEFINE(_name, _type, ...) \ (&((const NMVariantAttributeSpec) { \ .name = _name, \ diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 3803c124e1..85f7b4a673 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -2895,7 +2895,7 @@ nm_utils_sriov_vf_to_str (const NMSriovVF *vf, gboolean omit_index, GError **err if (num_attrs > 0) { if (!omit_index) g_string_append_c (str, ' '); - _nm_utils_format_variant_attributes_full (str, values, num_attrs, ' ', '='); + _nm_utils_format_variant_attributes_full (str, values, num_attrs, NULL, ' ', '='); } vlan_ids = nm_sriov_vf_get_vlan_ids (vf, &num_vlans); @@ -5808,6 +5808,7 @@ nm_utils_format_variant_attributes (GHashTable *attributes, char key_value_separator) { return _nm_utils_format_variant_attributes (attributes, + NULL, attr_separator, key_value_separator); } diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c index fa85c66217..e6be79649f 100644 --- a/shared/nm-glib-aux/nm-shared-utils.c +++ b/shared/nm-glib-aux/nm-shared-utils.c @@ -5021,9 +5021,11 @@ void _nm_utils_format_variant_attributes_full (GString *str, const NMUtilsNamedValue *values, guint num_values, + const NMVariantAttributeSpec *const *spec, char attr_separator, char key_value_separator) { + const NMVariantAttributeSpec *const *s; const char *name, *value; GVariant *variant; char *escaped; @@ -5035,6 +5037,17 @@ _nm_utils_format_variant_attributes_full (GString *str, name = values[i].name; variant = values[i].value_ptr; value = NULL; + s = NULL; + + if (spec) { + for (s = spec; *s; s++) { + if (nm_streq0 ((*s)->name, name)) + break; + } + + if (!*s) + continue; + } if (g_variant_is_of_type (variant, G_VARIANT_TYPE_UINT32)) value = nm_sprintf_buf (buf, "%u", g_variant_get_uint32 (variant)); @@ -5074,6 +5087,7 @@ _nm_utils_format_variant_attributes_full (GString *str, char * _nm_utils_format_variant_attributes (GHashTable *attributes, + const NMVariantAttributeSpec *const *spec, char attr_separator, char key_value_separator) { @@ -5100,6 +5114,7 @@ _nm_utils_format_variant_attributes (GHashTable *attributes, _nm_utils_format_variant_attributes_full (str, values, len, + spec, attr_separator, key_value_separator); return g_string_free (str, FALSE); diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h index 52f5146e30..ac091d8230 100644 --- a/shared/nm-glib-aux/nm-shared-utils.h +++ b/shared/nm-glib-aux/nm-shared-utils.h @@ -2068,13 +2068,27 @@ nm_strvarray_set_strv (GArray **array, const char *const*strv) /*****************************************************************************/ +struct _NMVariantAttributeSpec { + char *name; + const GVariantType *type; + bool v4:1; + bool v6:1; + bool no_value:1; + bool consumes_rest:1; + char str_type; +}; + +typedef struct _NMVariantAttributeSpec NMVariantAttributeSpec; + void _nm_utils_format_variant_attributes_full (GString *str, const NMUtilsNamedValue *values, guint num_values, + const NMVariantAttributeSpec *const *spec, char attr_separator, char key_value_separator); char *_nm_utils_format_variant_attributes (GHashTable *attributes, + const NMVariantAttributeSpec *const *spec, char attr_separator, char key_value_separator); |