From 52bb3c1f86f5afe19ed2cfd69481a96f352ada6e Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 15 Jan 2018 16:31:53 +0000 Subject: [PATCH 5/8] bus_transaction_send: Take sender and destination connections We'll need this if we want to stamp optional header fields on the message according to the preferences of the recipient(s). Signed-off-by: Simon McVittie --- bus/connection.c | 25 +++++++++++++------------ bus/connection.h | 3 ++- bus/dispatch.c | 7 +++---- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/bus/connection.c b/bus/connection.c index 91b1966e..87f2f8a9 100644 --- a/bus/connection.c +++ b/bus/connection.c @@ -2311,7 +2311,7 @@ bus_transaction_capture (BusTransaction *transaction, { DBusConnection *recipient = link->data; - if (!bus_transaction_send (transaction, recipient, message)) + if (!bus_transaction_send (transaction, sender, recipient, message)) goto out; } @@ -2420,12 +2420,13 @@ bus_transaction_send_from_driver (BusTransaction *transaction, return TRUE; } - return bus_transaction_send (transaction, connection, message); + return bus_transaction_send (transaction, NULL, connection, message); } dbus_bool_t bus_transaction_send (BusTransaction *transaction, - DBusConnection *connection, + DBusConnection *sender, + DBusConnection *destination, DBusMessage *message) { MessageToSend *to_send; @@ -2442,15 +2443,15 @@ bus_transaction_send (BusTransaction *transaction, dbus_message_get_member (message) : "(unset)", dbus_message_get_error_name (message) ? dbus_message_get_error_name (message) : "(unset)", - dbus_connection_get_is_connected (connection) ? + dbus_connection_get_is_connected (destination) ? "" : " (disconnected)"); _dbus_assert (dbus_message_get_sender (message) != NULL); - if (!dbus_connection_get_is_connected (connection)) - return TRUE; /* silently ignore disconnected connections */ + if (!dbus_connection_get_is_connected (destination)) + return TRUE; /* silently ignore disconnected destinations */ - d = BUS_CONNECTION_DATA (connection); + d = BUS_CONNECTION_DATA (destination); _dbus_assert (d != NULL); to_send = dbus_new (MessageToSend, 1); @@ -2459,7 +2460,7 @@ bus_transaction_send (BusTransaction *transaction, return FALSE; } - to_send->preallocated = dbus_connection_preallocate_send (connection); + to_send->preallocated = dbus_connection_preallocate_send (destination); if (to_send->preallocated == NULL) { dbus_free (to_send); @@ -2474,13 +2475,13 @@ bus_transaction_send (BusTransaction *transaction, if (!_dbus_list_prepend (&d->transaction_messages, to_send)) { - message_to_send_free (connection, to_send); + message_to_send_free (destination, to_send); return FALSE; } _dbus_verbose ("prepended message\n"); - /* See if we already had this connection in the list + /* See if we already had this destination in the list * for this transaction. If we have a pending message, * then we should already be in transaction->connections */ @@ -2500,10 +2501,10 @@ bus_transaction_send (BusTransaction *transaction, if (link == NULL) { - if (!_dbus_list_prepend (&transaction->connections, connection)) + if (!_dbus_list_prepend (&transaction->connections, destination)) { _dbus_list_remove (&d->transaction_messages, to_send); - message_to_send_free (connection, to_send); + message_to_send_free (destination, to_send); return FALSE; } } diff --git a/bus/connection.h b/bus/connection.h index 9e253ae5..141fb0c0 100644 --- a/bus/connection.h +++ b/bus/connection.h @@ -132,7 +132,8 @@ typedef void (* BusTransactionCancelFunction) (void *data); BusTransaction* bus_transaction_new (BusContext *context); BusContext* bus_transaction_get_context (BusTransaction *transaction); dbus_bool_t bus_transaction_send (BusTransaction *transaction, - DBusConnection *connection, + DBusConnection *sender, + DBusConnection *destination, DBusMessage *message); dbus_bool_t bus_transaction_capture (BusTransaction *transaction, DBusConnection *connection, diff --git a/bus/dispatch.c b/bus/dispatch.c index 4ae98b5e..b16ad2b3 100644 --- a/bus/dispatch.c +++ b/bus/dispatch.c @@ -108,9 +108,7 @@ send_one_message (DBusConnection *connection, return TRUE; /* don't send it but don't return an error either */ } - if (!bus_transaction_send (transaction, - connection, - message)) + if (!bus_transaction_send (transaction, sender, connection, message)) { BUS_SET_OOM (error); return FALSE; @@ -165,7 +163,8 @@ bus_dispatch_matches (BusTransaction *transaction, } /* Dispatch the message */ - if (!bus_transaction_send (transaction, addressed_recipient, message)) + if (!bus_transaction_send (transaction, sender, addressed_recipient, + message)) { BUS_SET_OOM (error); return FALSE; -- 2.15.1