[telepathy-haze/master] Fix circular channel creation

Felipe Contreras felipe.contreras at gmail.com
Sat Jan 9 05:41:52 PST 2010


A plugin might listen for the "conversation-created" signal, and attempt
to write to the conversaton. The signal would be triggered in
purple_conversation_new, at which point haze_im_channel_constructor
hasn't finished, and therefore new_im_channel hasn't inserted the
conversation into the channels hashtable.

The result is a new attempt to create the channel and a segmentation
fault occurs.

This is triggered by msn-pecan which does exactly that to notify the
user that the contact doesn't have him on the contact list (reverse
subscription).

Signed-off-by: Felipe Contreras <felipe.contreras at gmail.com>
Signed-off-by: Will Thompson <will.thompson at collabora.co.uk>
---
 src/im-channel-factory.c |    2 ++
 src/im-channel.c         |   21 ++++++++++++++++-----
 src/im-channel.h         |    2 ++
 3 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/im-channel-factory.c b/src/im-channel-factory.c
index 66906aa..88520ac 100644
--- a/src/im-channel-factory.c
+++ b/src/im-channel-factory.c
@@ -295,6 +295,8 @@ new_im_channel (HazeImChannelFactory *self,
 
     g_hash_table_insert (self->priv->channels, GINT_TO_POINTER (handle), chan);
 
+    haze_im_channel_start (chan);
+
     if (request_token != NULL)
         requests = g_slist_prepend (requests, request_token);
 
diff --git a/src/im-channel.c b/src/im-channel.c
index 2dd17e2..c48ff50 100644
--- a/src/im-channel.c
+++ b/src/im-channel.c
@@ -564,7 +564,6 @@ haze_im_channel_constructor (GType type, guint n_props,
     HazeIMChannelPrivate *priv;
     TpHandleRepoIface *contact_handles;
     TpBaseConnection *conn;
-    const char *recipient;
     DBusGConnection *bus;
 
     obj = G_OBJECT_CLASS (haze_im_channel_parent_class)->
@@ -587,10 +586,6 @@ haze_im_channel_constructor (GType type, guint n_props,
     bus = tp_get_bus ();
     dbus_g_connection_register_g_object (bus, priv->object_path, obj);
 
-    recipient = tp_handle_inspect(contact_handles, priv->handle);
-    priv->conv = purple_conversation_new (PURPLE_CONV_TYPE_IM,
-                                          priv->conn->account,
-                                          recipient);
     priv->closed = FALSE;
     priv->dispose_has_run = FALSE;
 
@@ -733,6 +728,22 @@ haze_im_channel_init (HazeIMChannel *self)
                                               HazeIMChannelPrivate);
 }
 
+void
+haze_im_channel_start (HazeIMChannel *self)
+{
+    const char *recipient;
+    HazeIMChannelPrivate *priv = self->priv;
+    TpHandleRepoIface *contact_handles;
+    TpBaseConnection *base_conn = (TpBaseConnection *) priv->conn;
+
+    contact_handles = tp_base_connection_get_handles (base_conn,
+        TP_HANDLE_TYPE_CONTACT);
+    recipient = tp_handle_inspect(contact_handles, priv->handle);
+    priv->conv = purple_conversation_new (PURPLE_CONV_TYPE_IM,
+                                          priv->conn->account,
+                                          recipient);
+}
+
 static TpMessage *
 _make_message (HazeIMChannel *self,
                char *text_plain,
diff --git a/src/im-channel.h b/src/im-channel.h
index 4581280..59105c7 100644
--- a/src/im-channel.h
+++ b/src/im-channel.h
@@ -80,6 +80,8 @@ struct _HazeConversationUiData
 #define PURPLE_CONV_GET_HAZE_UI_DATA(conv) \
     ((HazeConversationUiData *) conv->ui_data)
 
+void haze_im_channel_start (HazeIMChannel *self);
+
 void haze_im_channel_receive (HazeIMChannel *self, const char *xhtml_message,
     PurpleMessageFlags flags, time_t mtime);
 
-- 
1.5.6.5



More information about the telepathy-commits mailing list