summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlban Crequy <alban.crequy@collabora.co.uk>2012-05-29 17:57:39 +0000
committerRodrigo Moya <rodrigo@gnome-db.org>2012-05-30 22:14:58 +0200
commita9bd9ca0976015ac2099f4edd000bc085932f7b3 (patch)
tree8e43ae135271ccfce1d39f10919f86c440da691c
parent5b7012c756bc3e35ca95b8c1e7ec4cb64989302c (diff)
downloaddbus-a9bd9ca0976015ac2099f4edd000bc085932f7b3.tar.gz
compatibility proxy: send messages both ways
-rw-r--r--bus/connection.c67
-rw-r--r--bus/connection.h5
-rw-r--r--bus/dispatch.c10
3 files changed, 80 insertions, 2 deletions
diff --git a/bus/connection.c b/bus/connection.c
index 6c4e4aca..3a1749f6 100644
--- a/bus/connection.c
+++ b/bus/connection.c
@@ -191,6 +191,26 @@ adjust_connections_for_uid (BusConnections *connections,
}
}
+static DBusHandlerResult
+proxy_connection_message_filter (DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data)
+{
+ DBusConnection *source_connection = user_data;
+
+ if (dbus_message_get_destination (message) == NULL &&
+ dbus_message_is_signal (message,
+ DBUS_INTERFACE_LOCAL,
+ "Disconnected"))
+ {
+ dbus_connection_close (source_connection);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ dbus_connection_send (source_connection, message, NULL);
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
void
bus_connection_disconnected (DBusConnection *connection)
{
@@ -204,6 +224,14 @@ bus_connection_disconnected (DBusConnection *connection)
_dbus_verbose ("%s disconnected, dropping all service ownership and releasing\n",
d->name ? d->name : "(inactive)");
+ if (d->proxy_connection)
+ {
+ dbus_connection_remove_filter (d->proxy_connection,
+ proxy_connection_message_filter, connection);
+ dbus_connection_close (d->proxy_connection);
+ d->proxy_connection = NULL;
+ }
+
/* Delete our match rules */
if (d->n_match_rules > 0)
{
@@ -316,6 +344,18 @@ bus_connection_disconnected (DBusConnection *connection)
dbus_connection_unref (connection);
}
+DBusConnection *
+bus_connection_get_proxy_connection (DBusConnection *connection)
+{
+ BusConnectionData *d;
+
+ d = BUS_CONNECTION_DATA (connection);
+
+ _dbus_assert (d != NULL);
+
+ return d->proxy_connection;
+}
+
static dbus_bool_t
add_connection_watch (DBusWatch *watch,
void *data)
@@ -649,6 +689,33 @@ bus_connections_setup_connection (BusConnections *connections,
dbus_error_free (&error);
goto out;
}
+
+ dbus_connection_set_route_peer_messages (d->proxy_connection, TRUE);
+
+ /* Hack to reuse 'd' in proxy_connection, so the watch functions
+ * could get the loop through connection_get_loop() */
+ if (!dbus_connection_set_data (d->proxy_connection,
+ connection_data_slot,
+ d, free_connection_data))
+ {
+ goto out;
+ }
+ dbus_connection_set_dispatch_status_function (d->proxy_connection,
+ dispatch_status_function,
+ bus_context_get_loop (connections->context), NULL);
+
+ if (!dbus_connection_add_filter(d->proxy_connection,
+ proxy_connection_message_filter, connection, NULL))
+ goto out;
+
+
+ if (!dbus_connection_set_watch_functions (d->proxy_connection,
+ add_connection_watch,
+ remove_connection_watch,
+ toggle_connection_watch,
+ d->proxy_connection,
+ NULL))
+ goto out;
}
}
diff --git a/bus/connection.h b/bus/connection.h
index c9360212..ca93d8a3 100644
--- a/bus/connection.h
+++ b/bus/connection.h
@@ -103,8 +103,9 @@ dbus_bool_t bus_connection_complete (DBusConnection *connection,
const DBusString *name,
DBusError *error);
-/* called by dispatch.c when the connection is dropped */
-void bus_connection_disconnected (DBusConnection *connection);
+/* called by dispatch.c */
+void bus_connection_disconnected (DBusConnection *connection);
+DBusConnection *bus_connection_get_proxy_connection (DBusConnection *connection);
dbus_bool_t bus_connection_is_in_unix_group (DBusConnection *connection,
unsigned long gid);
diff --git a/bus/dispatch.c b/bus/dispatch.c
index fdda8ba8..4feae056 100644
--- a/bus/dispatch.c
+++ b/bus/dispatch.c
@@ -193,6 +193,7 @@ bus_dispatch (DBusConnection *connection,
BusContext *context;
DBusHandlerResult result;
DBusConnection *addressed_recipient;
+ DBusConnection *proxy_connection;
result = DBUS_HANDLER_RESULT_HANDLED;
@@ -254,6 +255,15 @@ bus_dispatch (DBusConnection *connection,
}
}
+ /* Directly send the message to the proxy without analysing it */
+ proxy_connection = bus_connection_get_proxy_connection (connection);
+ if (proxy_connection)
+ {
+ if (!dbus_connection_send (proxy_connection, message, NULL))
+ BUS_SET_OOM (&error);
+ goto out;
+ }
+
/* Create our transaction */
transaction = bus_transaction_new (context);
if (transaction == NULL)