]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
New a{sv} helper for using byte arrays as the variant
authorTyler Hicks <tyhicks@canonical.com>
Thu, 13 Mar 2014 22:37:38 +0000 (17:37 -0500)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Wed, 18 Feb 2015 10:35:05 +0000 (10:35 +0000)
Create a new helper for using a byte array as the value in the mapping
from string to variant.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=75113
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89041
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
dbus/dbus-asv-util.c
dbus/dbus-asv-util.h

index 583e41fa1102deea3fce63e39cbcef9f6f67f359..d3ac5e9cc15dd8fa3133ace234c55fa1862f7d1c 100644 (file)
@@ -258,3 +258,57 @@ _dbus_asv_add_string (DBusMessageIter *arr_iter,
 
   return TRUE;
 }
+
+/**
+ * Create a new entry in an a{sv} (map from string to variant)
+ * with a byte array value.
+ *
+ * If this function fails, the a{sv} must be abandoned, for instance
+ * with _dbus_asv_abandon().
+ *
+ * @param arr_iter the iterator which is appending to the array
+ * @param key a UTF-8 key for the map
+ * @param value the value
+ * @param n_elements the number of elements to append
+ * @returns #TRUE on success, or #FALSE if not enough memory
+ */
+dbus_bool_t
+_dbus_asv_add_byte_array (DBusMessageIter *arr_iter,
+                          const char      *key,
+                          const void      *value,
+                          int              n_elements)
+{
+  DBusMessageIter entry_iter;
+  DBusMessageIter var_iter;
+  DBusMessageIter byte_array_iter;
+
+  if (!_dbus_asv_open_entry (arr_iter, &entry_iter, key, "ay", &var_iter))
+    return FALSE;
+
+  if (!dbus_message_iter_open_container (&var_iter, DBUS_TYPE_ARRAY,
+                                         DBUS_TYPE_BYTE_AS_STRING,
+                                         &byte_array_iter))
+    {
+      _dbus_asv_abandon_entry (arr_iter, &entry_iter, &var_iter);
+      return FALSE;
+    }
+
+  if (!dbus_message_iter_append_fixed_array (&byte_array_iter, DBUS_TYPE_BYTE,
+                                             &value, n_elements))
+    {
+      dbus_message_iter_abandon_container (&var_iter, &byte_array_iter);
+      _dbus_asv_abandon_entry (arr_iter, &entry_iter, &var_iter);
+      return FALSE;
+    }
+
+  if (!dbus_message_iter_close_container (&var_iter, &byte_array_iter))
+    {
+      _dbus_asv_abandon_entry (arr_iter, &entry_iter, &var_iter);
+      return FALSE;
+    }
+
+  if (!_dbus_asv_close_entry (arr_iter, &entry_iter, &var_iter))
+    return FALSE;
+
+  return TRUE;
+}
index 0337260ab99a81dd2e8e5de5e568596a43d2ee88..277ab8076b13c6d88dfd9522195e9d8bfee7f212 100644 (file)
@@ -42,5 +42,9 @@ dbus_bool_t  _dbus_asv_add_uint32        (DBusMessageIter *arr_iter,
 dbus_bool_t  _dbus_asv_add_string        (DBusMessageIter *arr_iter,
                                           const char      *key,
                                           const char      *value);
+dbus_bool_t  _dbus_asv_add_byte_array    (DBusMessageIter *arr_iter,
+                                          const char      *key,
+                                          const void      *value,
+                                          int              n_elements);
 
 #endif