[telepathy-gabble/master] tube-stream: fire NewConnection once the transport is connected

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Thu Apr 30 05:02:10 PDT 2009


Transport have to be connected to allow us to get access control param
from it (as the source port).
---
 src/tube-stream.c |   96 +++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 78 insertions(+), 18 deletions(-)

diff --git a/src/tube-stream.c b/src/tube-stream.c
index d33ea94..db7f235 100644
--- a/src/tube-stream.c
+++ b/src/tube-stream.c
@@ -549,9 +549,60 @@ local_new_connection_cb (GibberListener *listener,
     }
 }
 
-static gboolean
+typedef struct
+{
+  GabbleTubeStream *self;
+  TpHandle contact;
+} transport_connected_data;
+
+static transport_connected_data *
+transport_connected_data_new (GabbleTubeStream *self,
+    TpHandle contact)
+{
+  transport_connected_data *data = g_slice_new (transport_connected_data);
+  data->self = self;
+  data->contact = contact;
+  return data;
+}
+
+static void
+transport_connected_data_free (transport_connected_data *data)
+{
+  g_slice_free (transport_connected_data, data);
+}
+
+static void
+fire_new_connection (GabbleTubeStream *self,
+    GibberTransport *transport,
+    TpHandle contact)
+{
+  GValue access_control_param = {0,};
+
+  /* set a dummy value */
+  /* FIXME: this param doesn't have a meaningful value with
+   * the Localhost access control which is the only one currently
+   * implemented. We should set a not-dummy value when we'll implement
+   * other access control mechanismes. */
+  g_value_init (&access_control_param, G_TYPE_INT);
+  g_value_set_int (&access_control_param, 0);
+
+  /* fire NewConnection D-Bus signal */
+  gabble_svc_channel_type_stream_tube_emit_new_connection (self,
+      contact, &access_control_param);
+  g_value_unset (&access_control_param);
+}
+
+static void
+transport_connected_cb (GibberTransport *transport,
+    transport_connected_data *data)
+{
+  fire_new_connection (data->self, transport, data->contact);
+}
+
+static GibberTransport *
 new_connection_to_socket (GabbleTubeStream *self,
-                          GabbleBytestreamIface *bytestream)
+                          GabbleBytestreamIface *bytestream,
+                          TpHandle contact)
 {
   GabbleTubeStreamPrivate *priv = GABBLE_TUBE_STREAM_GET_PRIVATE (self);
   GibberTransport *transport;
@@ -606,7 +657,8 @@ new_connection_to_socket (GabbleTubeStream *self,
       G_CALLBACK (extra_bytestream_state_changed_cb), self);
 
   g_object_unref (transport);
-  return TRUE;
+
+  return transport;
 }
 
 static gboolean
@@ -1555,6 +1607,8 @@ gabble_tube_stream_add_bytestream (GabbleTubeIface *tube,
 {
   GabbleTubeStream *self = GABBLE_TUBE_STREAM (tube);
   GabbleTubeStreamPrivate *priv = GABBLE_TUBE_STREAM_GET_PRIVATE (self);
+  TpHandle contact;
+  GibberTransport *transport;
 
   if (priv->initiator != priv->self_handle)
     {
@@ -1565,12 +1619,12 @@ gabble_tube_stream_add_bytestream (GabbleTubeIface *tube,
       return;
     }
 
+  g_object_get (bytestream, "peer-handle", &contact, NULL);
+
   /* New bytestream, let's connect to the socket */
-  if (new_connection_to_socket (self, bytestream))
+  transport = new_connection_to_socket (self, bytestream, contact);
+  if (transport != NULL)
     {
-      TpHandle contact;
-      GValue access_control_param = {0,};
-
       if (priv->state == GABBLE_TUBE_CHANNEL_STATE_REMOTE_PENDING)
         {
           DEBUG ("Received first connection. Tube is now open");
@@ -1586,19 +1640,25 @@ gabble_tube_stream_add_bytestream (GabbleTubeIface *tube,
 
       gabble_bytestream_iface_accept (bytestream, augment_si_accept_iq, self);
 
-      g_object_get (bytestream, "peer-handle", &contact, NULL);
-
       g_signal_emit (G_OBJECT (self), signals[NEW_CONNECTION], 0, contact);
 
-      /* fire NewConnection D-Bus signal */
-      /* FIXME: this param doesn't have a meaningful value with
-       * the Localhost access control which is the only one currently
-       * implemented. We should set a not-dummy value when we'll implement
-       * other access control mechanismes. */
-      g_value_init (&access_control_param, G_TYPE_STRING);
-      g_value_set_string (&access_control_param, "");
-      gabble_svc_channel_type_stream_tube_emit_new_connection (self,
-          contact, &access_control_param);
+      if (gibber_transport_get_state (transport) == GIBBER_TRANSPORT_CONNECTED)
+        {
+          fire_new_connection (self, transport, contact);
+        }
+      else
+        {
+          /* NewConnection will be fired once the transport is connected.
+           * We can't get access_control_param (as the source port for example)
+           * until it's connected. */
+          transport_connected_data *data;
+
+          data = transport_connected_data_new (self, contact);
+
+          g_signal_connect_data (transport, "connected",
+              G_CALLBACK (transport_connected_cb), data,
+              (GClosureNotify) transport_connected_data_free, 0);
+        }
     }
   else
     {
-- 
1.5.6.5




More information about the telepathy-commits mailing list