]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
_dbus_asv_add_unix_fd: add
authorLuca Boccassi <bluca@debian.org>
Mon, 20 Mar 2023 02:35:10 +0000 (02:35 +0000)
committerLuca Boccassi <bluca@debian.org>
Tue, 8 Aug 2023 11:24:20 +0000 (12:24 +0100)
Add a new helper to add unix FDs to arrays. Will be used for
GetConnectionCredentials().

Signed-off-by: Luca Boccassi <bluca@debian.org>
dbus/dbus-asv-util.c
dbus/dbus-asv-util.h

index ace8f5030d2606b7b2feddb34a3355f72b76ce90..5ac0ef2be1e41801ef4aadb4e9205c0ca28ef582 100644 (file)
@@ -376,3 +376,42 @@ _dbus_asv_add_byte_array (DBusMessageIter *arr_iter,
   return _dbus_asv_add_fixed_array (arr_iter, key, DBUS_TYPE_BYTE, value,
                                     n_elements);
 }
+
+/**
+ * Create a new entry in an a{sv} (map from string to variant)
+ * with a Unix file descriptor as value.
+ *
+ * If this function fails, the a{sv} must be abandoned, for instance
+ * with _dbus_asv_abandon().
+ *
+ * The FD remains owned by the caller regardless of the result returned
+ * by this function.
+ *
+ * @param arr_iter the iterator which is appending to the array
+ * @param key a UTF-8 key for the map
+ * @param value the value
+ * @returns #TRUE on success, or #FALSE if not enough memory
+ */
+dbus_bool_t
+_dbus_asv_add_unix_fd (DBusMessageIter *arr_iter,
+                       const char *key,
+                       int value)
+{
+  DBusMessageIter entry_iter, var_iter;
+
+  if (!_dbus_asv_open_entry (arr_iter, &entry_iter, key,
+                             DBUS_TYPE_UNIX_FD_AS_STRING, &var_iter))
+    return FALSE;
+
+  if (!dbus_message_iter_append_basic (&var_iter, DBUS_TYPE_UNIX_FD,
+                                       &value))
+    {
+      _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 da1ef25bd37b161601c058d9b95175ded1151ce2..466885aba8acfdcec8d21e2254745352a240a468 100644 (file)
@@ -67,5 +67,8 @@ dbus_bool_t  _dbus_asv_close_entry       (DBusMessageIter *arr_iter,
 void         _dbus_asv_abandon_entry     (DBusMessageIter *arr_iter,
                                           DBusMessageIter *entry_iter,
                                           DBusMessageIter *var_iter);
+dbus_bool_t  _dbus_asv_add_unix_fd       (DBusMessageIter *arr_iter,
+                                          const char      *key,
+                                          int              value);
 
 #endif