From c5d6c72cc5d28660a01308bbd7e6abaa718f9527 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 9 Jun 2017 15:57:30 +0100 Subject: [PATCH] _dbus_asv_add_object_path: Add Signed-off-by: Simon McVittie Reviewed-by: Philip Withnall Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354 --- dbus/dbus-asv-util.c | 36 ++++++++++++++++++++++++++++++++++++ dbus/dbus-asv-util.h | 3 +++ 2 files changed, 39 insertions(+) diff --git a/dbus/dbus-asv-util.c b/dbus/dbus-asv-util.c index fbb2e51e..09c9fb56 100644 --- a/dbus/dbus-asv-util.c +++ b/dbus/dbus-asv-util.c @@ -261,6 +261,42 @@ _dbus_asv_add_string (DBusMessageIter *arr_iter, /** * Create a new entry in an a{sv} (map from string to variant) + * with an object-path 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 + * @returns #TRUE on success, or #FALSE if not enough memory + */ +dbus_bool_t +_dbus_asv_add_object_path (DBusMessageIter *arr_iter, + const char *key, + const char *value) +{ + DBusMessageIter entry_iter, var_iter; + + if (!_dbus_asv_open_entry (arr_iter, &entry_iter, key, + DBUS_TYPE_OBJECT_PATH_AS_STRING, &var_iter)) + return FALSE; + + if (!dbus_message_iter_append_basic (&var_iter, DBUS_TYPE_OBJECT_PATH, + &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; +} + +/** + * 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 diff --git a/dbus/dbus-asv-util.h b/dbus/dbus-asv-util.h index a439008f..37d94060 100644 --- a/dbus/dbus-asv-util.h +++ b/dbus/dbus-asv-util.h @@ -42,6 +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_object_path (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, -- 2.13.3