summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2018-06-18 18:46:52 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2018-07-11 16:16:22 +0200
commitd7382fbe93c60dfe133e14f6289eb82c1303f76b (patch)
tree524db9c48c835fd2cd48c076c4e2b28ff0abf3ca
parent634b2d1ce2687d724add893836f06beacd5a3700 (diff)
downloadNetworkManager-d7382fbe93c60dfe133e14f6289eb82c1303f76b.tar.gz
nm-utils: add _nm_utils_format_variant_attributes_full()
-rw-r--r--libnm-core/nm-utils-private.h6
-rw-r--r--libnm-core/nm-utils.c80
2 files changed, 53 insertions, 33 deletions
diff --git a/libnm-core/nm-utils-private.h b/libnm-core/nm-utils-private.h
index 5d0f83868e..58539cb301 100644
--- a/libnm-core/nm-utils-private.h
+++ b/libnm-core/nm-utils-private.h
@@ -83,6 +83,12 @@ char * _nm_utils_hwaddr_canonical_or_invalid (const char *mac, gssize lengt
GPtrArray * _nm_utils_team_link_watchers_from_variant (GVariant *value);
GVariant * _nm_utils_team_link_watchers_to_variant (GPtrArray *link_watchers);
+void _nm_utils_format_variant_attributes_full (GString *str,
+ const NMUtilsNamedValue *values,
+ guint num_values,
+ char attr_separator,
+ char key_value_separator);
+
/* JSON to GValue conversion macros */
typedef struct {
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c
index 62da974f19..9247d7f8a0 100644
--- a/libnm-core/nm-utils.c
+++ b/libnm-core/nm-utils.c
@@ -6156,44 +6156,21 @@ next:
return g_steal_pointer (&ht);
}
-/*
- * nm_utils_format_variant_attributes:
- * @attributes: (element-type utf8 GVariant): a #GHashTable mapping attribute names to #GVariant values
- * @attr_separator: the attribute separator character
- * @key_value_separator: character separating key and values
- *
- * Format attributes to a string.
- *
- * Returns: (transfer full): the string representing attributes, or %NULL
- * in case there are no attributes
- *
- * Since: 1.8
- */
-char *
-nm_utils_format_variant_attributes (GHashTable *attributes,
- char attr_separator,
- char key_value_separator)
+void
+_nm_utils_format_variant_attributes_full (GString *str,
+ const NMUtilsNamedValue *values,
+ guint num_values,
+ char attr_separator,
+ char key_value_separator)
{
- GString *str = NULL;
- GVariant *variant;
- char sep = 0;
const char *name, *value;
+ GVariant *variant;
char *escaped;
char buf[64];
- gs_free NMUtilsNamedValue *values = NULL;
- guint i, len;
-
- g_return_val_if_fail (attr_separator, NULL);
- g_return_val_if_fail (key_value_separator, NULL);
-
- if (!attributes || !g_hash_table_size (attributes))
- return NULL;
-
- values = nm_utils_named_values_from_str_dict (attributes, &len);
-
- str = g_string_new ("");
+ char sep = 0;
+ guint i;
- for (i = 0; i < len; i++) {
+ for (i = 0; i < num_values; i++) {
name = values[i].name;
variant = (GVariant *) values[i].value_ptr;
value = NULL;
@@ -6226,7 +6203,44 @@ nm_utils_format_variant_attributes (GHashTable *attributes,
sep = attr_separator;
}
+}
+/*
+ * nm_utils_format_variant_attributes:
+ * @attributes: (element-type utf8 GVariant): a #GHashTable mapping attribute names to #GVariant values
+ * @attr_separator: the attribute separator character
+ * @key_value_separator: character separating key and values
+ *
+ * Format attributes to a string.
+ *
+ * Returns: (transfer full): the string representing attributes, or %NULL
+ * in case there are no attributes
+ *
+ * Since: 1.8
+ */
+char *
+nm_utils_format_variant_attributes (GHashTable *attributes,
+ char attr_separator,
+ char key_value_separator)
+{
+ GString *str = NULL;
+ gs_free NMUtilsNamedValue *values = NULL;
+ guint len;
+
+ g_return_val_if_fail (attr_separator, NULL);
+ g_return_val_if_fail (key_value_separator, NULL);
+
+ if (!attributes || !g_hash_table_size (attributes))
+ return NULL;
+
+ values = nm_utils_named_values_from_str_dict (attributes, &len);
+
+ str = g_string_new ("");
+ _nm_utils_format_variant_attributes_full (str,
+ values,
+ len,
+ attr_separator,
+ key_value_separator);
return g_string_free (str, FALSE);
}