[telepathy-gabble/master] pass a jid instead of a handle to pubsub handlers

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Fri Sep 25 02:29:41 PDT 2009


---
 src/conn-aliasing.c |   12 ++++++++++-
 src/conn-aliasing.h |    2 +-
 src/conn-location.c |   15 ++++++++++---
 src/conn-location.h |    2 +-
 src/conn-olpc.c     |   53 ++++++++++++++++++++++++++++++++++++++++++--------
 src/conn-olpc.h     |    8 +++---
 src/pubsub.c        |   17 ++-------------
 src/pubsub.h        |    4 +-
 8 files changed, 77 insertions(+), 36 deletions(-)

diff --git a/src/conn-aliasing.c b/src/conn-aliasing.c
index 3a19fcf..e8932b5 100644
--- a/src/conn-aliasing.c
+++ b/src/conn-aliasing.c
@@ -661,9 +661,19 @@ _grab_nickname (GabbleConnection *self,
 gboolean
 gabble_conn_aliasing_pep_nick_event_handler (GabbleConnection *conn,
                                              LmMessage *msg,
-                                             TpHandle handle)
+                                             const gchar *from)
 {
+  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
+      (TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
   LmMessageNode *node;
+  TpHandle handle;
+
+  handle = tp_handle_ensure (contact_repo, from, NULL, NULL);
+  if (handle == 0)
+    {
+      DEBUG ("Invalid from: %s", from);
+      return FALSE;
+    }
 
   node = lm_message_node_find_child (msg->node, "item");
   if (NULL == node)
diff --git a/src/conn-aliasing.h b/src/conn-aliasing.h
index c84a024..5c81081 100644
--- a/src/conn-aliasing.h
+++ b/src/conn-aliasing.h
@@ -31,7 +31,7 @@ void conn_aliasing_init (GabbleConnection *conn);
 void conn_aliasing_iface_init (gpointer g_iface, gpointer iface_data);
 
 gboolean gabble_conn_aliasing_pep_nick_event_handler (GabbleConnection *conn,
-    LmMessage *msg, TpHandle handle);
+    LmMessage *msg, const gchar *from);
 
 void gabble_conn_aliasing_nickname_updated (GObject *object,
     TpHandle handle, gpointer user_data);
diff --git a/src/conn-location.c b/src/conn-location.c
index 184a236..3bd76a3 100644
--- a/src/conn-location.c
+++ b/src/conn-location.c
@@ -513,17 +513,24 @@ update_location_from_msg (GabbleConnection *conn,
 gboolean
 geolocation_event_handler (GabbleConnection *conn,
                            LmMessage *msg,
-                           TpHandle handle)
+                           const gchar *from)
 {
+  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
+      (TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
   TpBaseConnection *base = (TpBaseConnection *) conn;
-  const gchar *from;
+  TpHandle handle;
+
+  handle = tp_handle_ensure (contact_repo, from, NULL, NULL);
+  if (handle == 0)
+    {
+      DEBUG ("Invalid from: %s", from);
+      return FALSE;
+    }
 
   if (handle == base->self_handle)
     /* Ignore echoed pubsub notifications */
     return TRUE;
 
-  from = lm_message_node_get_attribute (msg->node, "from");
-
   return update_location_from_msg (conn, from, msg);
 }
 
diff --git a/src/conn-location.h b/src/conn-location.h
index eb3e358..e53a28c 100644
--- a/src/conn-location.h
+++ b/src/conn-location.h
@@ -15,7 +15,7 @@ gboolean conn_location_properties_setter (GObject *object, GQuark interface,
     GQuark name, const GValue *value, gpointer setter_data, GError **error);
 
 gboolean geolocation_event_handler (GabbleConnection *conn,
-    LmMessage *msg, TpHandle handle);
+    LmMessage *msg, const gchar *from);
 
 void conn_location_init (GabbleConnection *conn);
 
diff --git a/src/conn-olpc.c b/src/conn-olpc.c
index 7623a4e..2579b7c 100644
--- a/src/conn-olpc.c
+++ b/src/conn-olpc.c
@@ -562,11 +562,21 @@ olpc_buddy_info_set_properties (GabbleSvcOLPCBuddyInfo *iface,
 gboolean
 olpc_buddy_info_properties_event_handler (GabbleConnection *conn,
                                           LmMessage *msg,
-                                          TpHandle handle)
+                                          const gchar *from)
 {
+  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
+      (TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
   GHashTable *properties;
   LmMessageNode *node;
   TpBaseConnection *base = (TpBaseConnection *) conn;
+  TpHandle handle;
+
+  handle = tp_handle_ensure (contact_repo, from, NULL, NULL);
+  if (handle == 0)
+    {
+      DEBUG ("Invalid from: %s", from);
+      return FALSE;
+    }
 
   if (handle == base->self_handle)
     /* Ignore echoed pubsub notifications */
@@ -1171,10 +1181,20 @@ olpc_buddy_info_set_activities (GabbleSvcOLPCBuddyInfo *iface,
 gboolean
 olpc_buddy_info_activities_event_handler (GabbleConnection *conn,
                                           LmMessage *msg,
-                                          TpHandle handle)
+                                          const gchar *from)
 {
+  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
+      (TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
   GPtrArray *activities;
   TpBaseConnection *base = (TpBaseConnection *) conn;
+  TpHandle handle;
+
+  handle = tp_handle_ensure (contact_repo, from, NULL, NULL);
+  if (handle == 0)
+    {
+      DEBUG ("Invalid from: %s", from);
+      return FALSE;
+    }
 
   if (handle == base->self_handle)
     /* Ignore echoed pubsub notifications */
@@ -1498,18 +1518,26 @@ olpc_buddy_info_set_current_activity (GabbleSvcOLPCBuddyInfo *iface,
 gboolean
 olpc_buddy_info_current_activity_event_handler (GabbleConnection *conn,
                                                 LmMessage *msg,
-                                                TpHandle handle)
+                                                const gchar *from)
 {
+  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
+      (TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
   TpBaseConnection *base = (TpBaseConnection *) conn;
   LmMessageNode *node;
-  const gchar *from;
   GabbleOlpcActivity *activity;
+  TpHandle handle;
+
+  handle = tp_handle_ensure (contact_repo, from, NULL, NULL);
+  if (handle == 0)
+    {
+      DEBUG ("Invalid from: %s", from);
+      return FALSE;
+    }
 
   if (handle == base->self_handle)
     /* Ignore echoed pubsub notifications */
     return TRUE;
 
-  from = lm_message_node_get_attribute (msg->node, "from");
   node = lm_message_node_find_child (msg->node, "activity");
 
   activity = extract_current_activity (conn, node, from, TRUE);
@@ -2064,17 +2092,24 @@ update_activities_properties (GabbleConnection *conn,
 gboolean
 olpc_activities_properties_event_handler (GabbleConnection *conn,
                                           LmMessage *msg,
-                                          TpHandle handle)
+                                          const gchar *from)
 {
+  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
+      (TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
   TpBaseConnection *base = (TpBaseConnection *) conn;
-  const gchar *from;
+  TpHandle handle;
+
+  handle = tp_handle_ensure (contact_repo, from, NULL, NULL);
+  if (handle == 0)
+    {
+      DEBUG ("Invalid from: %s", from);
+      return FALSE;
+    }
 
   if (handle == base->self_handle)
     /* Ignore echoed pubsub notifications */
     return TRUE;
 
-  from = lm_message_node_get_attribute (msg->node, "from");
-
   return update_activities_properties (conn, from, msg);
 }
 
diff --git a/src/conn-olpc.h b/src/conn-olpc.h
index f125e9a..62fbd23 100644
--- a/src/conn-olpc.h
+++ b/src/conn-olpc.h
@@ -30,19 +30,19 @@ olpc_buddy_info_iface_init (gpointer g_iface, gpointer iface_data);
 
 gboolean
 olpc_buddy_info_properties_event_handler (GabbleConnection *conn,
-    LmMessage *msg, TpHandle handle);
+    LmMessage *msg, const gchar *from);
 
 gboolean
 olpc_buddy_info_activities_event_handler (GabbleConnection *conn,
-    LmMessage *msg, TpHandle handle);
+    LmMessage *msg, const gchar *from);
 
 gboolean
 olpc_buddy_info_current_activity_event_handler (GabbleConnection *conn,
-    LmMessage *msg, TpHandle handle);
+    LmMessage *msg, const gchar *from);
 
 gboolean
 olpc_activities_properties_event_handler (GabbleConnection *conn,
-    LmMessage *msg, TpHandle handle);
+    LmMessage *msg, const gchar *from);
 
 void gabble_connection_connected_olpc (GabbleConnection *conn);
 
diff --git a/src/pubsub.c b/src/pubsub.c
index d72b9e5..fccd29e 100644
--- a/src/pubsub.c
+++ b/src/pubsub.c
@@ -50,7 +50,7 @@ static const GabblePubsubEventHandler pubsub_event_handlers[] =
 
 static gboolean
 gabble_pubsub_event_handler (GabbleConnection *conn, LmMessage *msg,
-    TpHandle handle)
+    const gchar *from)
 {
   const GabblePubsubEventHandler *i;
   LmMessageNode *item_node;
@@ -82,7 +82,7 @@ gabble_pubsub_event_handler (GabbleConnection *conn, LmMessage *msg,
     {
       if (strcmp (i->ns, event_ns) == 0)
         {
-          i->handle_function (conn, msg, handle);
+          i->handle_function (conn, msg, from);
           return TRUE;
         }
     }
@@ -153,10 +153,7 @@ pubsub_msg_event_cb (LmMessageHandler *handler,
                  gpointer user_data)
 {
   GabbleConnection *conn = GABBLE_CONNECTION (user_data);
-  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
-      (TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
   LmMessageNode *node;
-  TpHandle handle;
   const gchar *event_ns, *from;
 
   node = lm_message_node_get_child (message->node, "event");
@@ -181,15 +178,7 @@ pubsub_msg_event_cb (LmMessageHandler *handler,
       return LM_HANDLER_RESULT_REMOVE_MESSAGE;
     }
 
-  handle = tp_handle_ensure (contact_repo, from, NULL, NULL);
-  if (handle == 0)
-    {
-      return LM_HANDLER_RESULT_REMOVE_MESSAGE;
-    }
-
-  gabble_pubsub_event_handler (conn, message, handle);
-
-  tp_handle_unref (contact_repo, handle);
+  gabble_pubsub_event_handler (conn, message, from);
 
   return LM_HANDLER_RESULT_REMOVE_MESSAGE;
 }
diff --git a/src/pubsub.h b/src/pubsub.h
index 2ecc403..0e69929 100644
--- a/src/pubsub.h
+++ b/src/pubsub.h
@@ -25,8 +25,8 @@
 G_BEGIN_DECLS
 
 typedef gboolean (* GabblePubsubEventHandlerFunction) (GabbleConnection *conn,
-                                                       LmMessage *msg,
-                                                       TpHandle handle);
+    LmMessage *msg,
+    const gchar *from);
 
 gboolean
 pubsub_query (GabbleConnection *conn, const gchar *jid, const gchar *ns,
-- 
1.5.6.5




More information about the telepathy-commits mailing list