[Telepathy-commits] [telepathy-gabble/master] Fix Bug #13891: listen for D-Bus connection from the local application before returning from the AcceptDBusTube method call

Alban Crequy alban.crequy at collabora.co.uk
Wed Oct 22 06:10:54 PDT 2008


20080808180848-a41c0-daef0909c8153077b122dc7c67dbe242cdb0fcf0.gz
---
 src/tube-dbus.c     |   34 +++++++++++++++++++++++++++++++---
 src/tube-dbus.h     |    2 ++
 src/tubes-channel.c |    8 +++++---
 3 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/src/tube-dbus.c b/src/tube-dbus.c
index d3a5772..5dd2f75 100644
--- a/src/tube-dbus.c
+++ b/src/tube-dbus.c
@@ -280,8 +280,21 @@ do_close (GabbleTubeDBus *self)
     }
 }
 
-static void
-tube_dbus_open (GabbleTubeDBus *self)
+/* There is two step to enable receiving a D-Bus connection from the local
+ * application:
+ * - listen on the socket
+ * - add the socket in the mainloop
+ *
+ * We need to know the socket path to return from the AcceptDBusTube D-Bus
+ * call but the socket in the mainloop must be added only when we are ready
+ * to receive connections, that is when the bytestream is fully open with the
+ * remote contact.
+ *
+ * See also Bug 13891:
+ * https://bugs.freedesktop.org/show_bug.cgi?id=13891
+ * */
+void
+gabble_tube_dbus_listen (GabbleTubeDBus *self)
 {
 #define SERVER_LISTEN_MAX_TRIES 5
   GabbleTubeDBusPrivate *priv = GABBLE_TUBE_DBUS_GET_PRIVATE (self);
@@ -326,7 +339,22 @@ tube_dbus_open (GabbleTubeDBus *self)
 
   dbus_server_set_new_connection_function (priv->dbus_srv, new_connection_cb,
       self, NULL);
-  dbus_server_setup_with_g_main (priv->dbus_srv, NULL);
+}
+
+static void
+tube_dbus_open (GabbleTubeDBus *self)
+{
+  GabbleTubeDBusPrivate *priv = GABBLE_TUBE_DBUS_GET_PRIVATE (self);
+
+  if (priv->dbus_srv_addr == NULL)
+    {
+      gabble_tube_dbus_listen (self);
+    }
+
+  if (priv->dbus_srv_addr != NULL)
+    {
+      dbus_server_setup_with_g_main (priv->dbus_srv, NULL);
+    }
 }
 
 static void
diff --git a/src/tube-dbus.h b/src/tube-dbus.h
index 5d232fe..c8a3258 100644
--- a/src/tube-dbus.h
+++ b/src/tube-dbus.h
@@ -72,6 +72,8 @@ gboolean gabble_tube_dbus_remove_name (GabbleTubeDBus *tube, TpHandle handle);
 gboolean gabble_tube_dbus_handle_in_names (GabbleTubeDBus *tube,
     TpHandle handle);
 
+void gabble_tube_dbus_listen (GabbleTubeDBus *self);
+
 /* Only extern for the benefit of tests/test-dtube-unique-names.c */
 gchar *_gabble_generate_dbus_unique_name (const gchar *nick);
 
diff --git a/src/tubes-channel.c b/src/tubes-channel.c
index 8c9495d..c849bd5 100644
--- a/src/tubes-channel.c
+++ b/src/tubes-channel.c
@@ -52,6 +52,7 @@
 #include "presence.h"
 #include "tube-iface.h"
 #include "tube-stream.h"
+#include "tube-dbus.h"
 #include "util.h"
 
 #ifdef HAVE_DBUS_TUBE
@@ -1912,10 +1913,11 @@ gabble_tubes_channel_accept_d_bus_tube (TpSvcChannelTypeTubes *iface,
 
   add_yourself_in_dbus_names (self, id);
 
+  /* The address is known only after we start to listen on the connection,
+   * so we need to listen now. However, connections are accepted only when
+   * the bytestream is fully initialised. See also Bug #13891. */
+  gabble_tube_dbus_listen (GABBLE_TUBE_DBUS (tube));
   g_object_get (tube, "dbus-address", &addr, NULL);
-  /* FIXME: This is broken in 1-1 D-Bus tubes because tube_open will be called
-   * only when the bytestream is fully initialised.
-   * So now we return a NULL string. Bug #13891 on fd.o */
   tp_svc_channel_type_tubes_return_from_accept_d_bus_tube (context, addr);
   g_free (addr);
 #else
-- 
1.5.6.5




More information about the Telepathy-commits mailing list