mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-07-21 10:14:41 +00:00
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.
This commit is contained in:
parent
d0d35aa278
commit
ee946ca27d
|
@ -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, \
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue