]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-tp-tube.c
empathy_tp_tube_new_stream_tube: allow NULL as parameters. Fixes #575817
[empathy.git] / libempathy / empathy-tp-tube.c
index afa6c1007030202fdeb79607a103d6b467402784..bde84fbed7f9f99776784d9ec5e4716e4ed7cf14 100644 (file)
 #define DEBUG_FLAG EMPATHY_DEBUG_TP
 #include "empathy-debug.h"
 
+typedef struct {
+  TpSocketAddressType type;
+  EmpatyTpTubeAcceptStreamTubeCb *callback;
+  gpointer user_data;
+} EmpathyTpTubeAcceptData;
+
+static EmpathyTpTubeAcceptData *
+new_empathy_tp_tube_accept_data (TpSocketAddressType type,
+  EmpatyTpTubeAcceptStreamTubeCb *callback, gpointer user_data)
+{
+  EmpathyTpTubeAcceptData *r;
+
+  r = g_slice_new0 (EmpathyTpTubeAcceptData);
+  r->type = type;
+  r->callback = callback;
+  r->user_data = user_data;
+
+  return r;
+}
+
+static void
+free_empathy_tp_tube_accept_data (gpointer data)
+{
+  g_slice_free (EmpathyTpTubeAcceptData, data);
+}
+
+
 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyTpTube)
 typedef struct
 {
@@ -40,6 +67,7 @@ typedef struct
   guint initiator;
   guint type;
   gchar *service;
+  /* FIXME readd support for parameters.. */
   GHashTable *parameters;
   guint state;
   EmpathyContact *initiator_contact;
@@ -182,6 +210,8 @@ tp_tube_finalize (GObject *object)
       g_object_unref (priv->factory);
 
   g_free (priv->service);
+
+  if (priv->parameters != NULL)
   g_hash_table_destroy (priv->parameters);
 
   G_OBJECT_CLASS (empathy_tp_tube_parent_class)->finalize (object);
@@ -241,7 +271,8 @@ empathy_tp_tube_new_stream_tube (EmpathyContact *contact,
                                  TpSocketAddressType type,
                                  const gchar *hostname,
                                  guint port,
-                                 const gchar *service)
+                                 const gchar *service,
+                                 GHashTable *parameters)
 {
   MissionControl *mc;
   McAccount *account;
@@ -261,7 +292,7 @@ empathy_tp_tube_new_stream_tube (EmpathyContact *contact,
   g_return_val_if_fail (hostname != NULL, NULL);
   g_return_val_if_fail (service != NULL, NULL);
 
-  mc = empathy_mission_control_new ();
+  mc = empathy_mission_control_dup_singleton ();
   account = empathy_contact_get_account (contact);
   connection = mission_control_get_tpconnection (mc, account, NULL);
   g_object_unref (mc);
@@ -316,9 +347,16 @@ empathy_tp_tube_new_stream_tube (EmpathyContact *contact,
   dbus_g_type_struct_set (address, 0, hostname, 1, port, G_MAXUINT);
   control_param = tp_g_value_slice_new (G_TYPE_STRING);
 
+  if (parameters == NULL)
+    /* Pass an empty dict as parameters */
+    parameters = g_hash_table_new (g_str_hash, g_str_equal);
+  else
+    g_hash_table_ref (parameters);
+
   if (!emp_cli_channel_type_stream_tube_run_offer_stream_tube (
         TP_PROXY(channel), -1, type, address,
-        TP_SOCKET_ACCESS_CONTROL_LOCALHOST, control_param, &error, NULL))
+        TP_SOCKET_ACCESS_CONTROL_LOCALHOST, control_param, parameters,
+        &error, NULL))
     {
       DEBUG ("Couldn't offer tube: %s", error->message);
       g_clear_error (&error);
@@ -337,6 +375,7 @@ OUT:
   tp_g_value_slice_free (address);
   tp_g_value_slice_free (control_param);
   g_object_unref (connection);
+  g_hash_table_unref (parameters);
 
   return tube;
 }
@@ -348,74 +387,57 @@ tp_tube_accept_stream_cb (TpProxy *proxy,
                           gpointer user_data,
                           GObject *weak_object)
 {
+  EmpathyTpTube *tube = EMPATHY_TP_TUBE (weak_object);
+  EmpathyTpTubeAcceptData *data = (EmpathyTpTubeAcceptData *)user_data;
+  EmpathyTpTubeAddress eaddress;
+
+  eaddress.type = data->type;
+
   if (error)
+    {
       DEBUG ("Error accepting tube: %s", error->message);
+      data->callback (tube, NULL, error, data->user_data);
+      return;
+    }
+
+  switch (eaddress.type)
+    {
+      case TP_SOCKET_ADDRESS_TYPE_UNIX:
+      case TP_SOCKET_ADDRESS_TYPE_ABSTRACT_UNIX:
+        eaddress.a.socket.path = g_value_get_boxed (address);
+        break;
+     case TP_SOCKET_ADDRESS_TYPE_IPV4:
+     case TP_SOCKET_ADDRESS_TYPE_IPV6:
+        dbus_g_type_struct_get (address,
+          0, &eaddress.a.inet.hostname,
+          1, &eaddress.a.inet.port, G_MAXUINT);
+        break;
+    }
+
+   data->callback (tube, &eaddress, NULL, data->user_data);
 }
 
 void
 empathy_tp_tube_accept_stream_tube (EmpathyTpTube *tube,
-                                    TpSocketAddressType type)
+  TpSocketAddressType type, EmpatyTpTubeAcceptStreamTubeCb *callback,
+  gpointer user_data)
 {
   EmpathyTpTubePriv *priv = GET_PRIV (tube);
   GValue *control_param;
+  EmpathyTpTubeAcceptData *data;
 
   g_return_if_fail (EMPATHY_IS_TP_TUBE (tube));
 
   DEBUG ("Accepting stream tube");
-
+  /* FIXME allow other acls */
   control_param = tp_g_value_slice_new (G_TYPE_STRING);
+
+  data = new_empathy_tp_tube_accept_data (type, callback, user_data);
+
   emp_cli_channel_type_stream_tube_call_accept_stream_tube (
      TP_PROXY (priv->channel), -1, type, TP_SOCKET_ACCESS_CONTROL_LOCALHOST,
-     control_param, tp_tube_accept_stream_cb, NULL, NULL, G_OBJECT (tube));
+     control_param, tp_tube_accept_stream_cb, data,
+     free_empathy_tp_tube_accept_data, G_OBJECT (tube));
 
   tp_g_value_slice_free (control_param);
 }
-
-void
-empathy_tp_tube_get_socket (EmpathyTpTube *tube,
-                            gchar **hostname,
-                            guint *port)
-{
-  EmpathyTpTubePriv *priv = GET_PRIV (tube);
-  GValue *address;
-  guint address_type;
-  gchar *ret_hostname = NULL;
-  guint ret_port;
-  GError *error = NULL;
-
-  g_assert_not_reached ();
-
-  g_return_if_fail (EMPATHY_IS_TP_TUBE (tube));
-  g_return_if_fail (hostname != NULL || port != NULL);
-
-  DEBUG ("Getting stream tube socket address");
-
-  if (!tp_cli_channel_type_tubes_run_get_stream_tube_socket_address (priv->channel,
-      -1, 0, &address_type, &address, &error, NULL))
-    {
-      DEBUG ("Couldn't get socket address: %s", error->message);
-      g_clear_error (&error);
-      return;
-    }
-
-  switch (address_type)
-    {
-    case TP_SOCKET_ADDRESS_TYPE_UNIX:
-    case TP_SOCKET_ADDRESS_TYPE_ABSTRACT_UNIX:
-        dbus_g_type_struct_get (address, 0, &ret_hostname, G_MAXUINT);
-        break;
-    case TP_SOCKET_ADDRESS_TYPE_IPV4:
-    case TP_SOCKET_ADDRESS_TYPE_IPV6:
-        dbus_g_type_struct_get (address, 0, &ret_hostname, 1, &ret_port, G_MAXUINT);    
-        break;
-    }
-
-  if (hostname) {
-       *hostname = g_strdup (ret_hostname);
-  }
-  if (port) {
-       *port = ret_port;
-  }
-  g_boxed_free (G_TYPE_VALUE, address);
-}
-