From f216e81432ddf04889202c33a6e68113f94d7611 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Thu, 3 Apr 2003 21:56:22 +0000 Subject: 2003-04-03 Havoc Pennington * bus/activation.c (load_directory): fix up memleaks (bus_activation_entry_free): free the entry * dbus/dbus-bus.c (dbus_bus_acquire_service): return an error if we get one from the message bus; fix memleaks. * dbus/dbus-message.c (dbus_set_error_from_message): new function --- dbus/dbus-message.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'dbus/dbus-message.c') diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index 39ed3942..46c4c406 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -2381,6 +2381,45 @@ dbus_message_sender_is (DBusMessage *message, return FALSE; } +/** + * Sets a #DBusError based on the contents of the given + * message. The error is only set if the message + * is an error message, as in dbus_message_get_is_error(). + * The name of the error is set to the name of the message, + * and the error message is set to the first argument + * if the argument exists and is a string. + * + * The return value indicates whether the error was set (the error is + * set if and only if the message is an error message). + * So you can check for an error reply and convert it to DBusError + * in one go. + * + * @param error the error to set + * @param message the message to set it from + * @returns #TRUE if dbus_message_get_is_error() returns #TRUE for the message + */ +dbus_bool_t +dbus_set_error_from_message (DBusError *error, + DBusMessage *message) +{ + char *str; + + if (!dbus_message_get_is_error (message)) + return FALSE; + + str = NULL; + dbus_message_get_args (message, NULL, + DBUS_TYPE_STRING, &str, + DBUS_TYPE_INVALID); + + dbus_set_error (error, dbus_message_get_name (message), + str ? "%s" : NULL, str); + + dbus_free (str); + + return TRUE; +} + /** @} */ /** -- cgit