[Telepathy-commits] [telepathy-salut/master] move caps_req_stanza_callback from salut-connection to salut-disco

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Thu Feb 26 11:20:26 PST 2009


---
 src/salut-connection.c |  174 -----------------------------------------------
 src/salut-disco.c      |  177 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 177 insertions(+), 174 deletions(-)

diff --git a/src/salut-connection.c b/src/salut-connection.c
index 471203c..af2d284 100644
--- a/src/salut-connection.c
+++ b/src/salut-connection.c
@@ -45,7 +45,6 @@
 #include "salut-avahi-discovery-client.h"
 #include "salut-caps-channel-manager.h"
 #include "salut-caps-hash.h"
-#include "salut-capabilities.h"
 #include "salut-contact-channel.h"
 #include "salut-contact.h"
 #include "salut-contact-manager.h"
@@ -266,170 +265,6 @@ static void connection_capabilities_update_cb (SalutPresenceCache *cache,
     TpHandle handle, GHashTable *old_enhanced_caps,
     GHashTable *new_enhanced_caps, gpointer user_data);
 
-static gboolean
-caps_req_stanza_filter (SalutXmppConnectionManager *mgr,
-                        GibberXmppConnection *conn,
-                        GibberXmppStanza *stanza,
-                        SalutContact *contact,
-                        gpointer user_data)
-{
-  GibberStanzaSubType sub_type;
-  GibberXmppNode *query;
-
-  gibber_xmpp_stanza_get_type_info (stanza, NULL, &sub_type);
-
-  if (sub_type != GIBBER_STANZA_SUB_TYPE_GET)
-    return FALSE;
-
-  query = gibber_xmpp_node_get_child_ns (stanza->node, "query", NS_DISCO_INFO);
-
-  if (!query)
-    return FALSE;
-
-  return TRUE;
-}
-
-static void
-caps_req_stanza_callback (SalutXmppConnectionManager *mgr,
-                          GibberXmppConnection *conn,
-                          GibberXmppStanza *stanza,
-                          SalutContact *contact,
-                          gpointer user_data)
-{
-  SalutConnection *self = SALUT_CONNECTION (user_data);
-  SalutConnectionPrivate *priv = SALUT_CONNECTION_GET_PRIVATE (self);
-  TpBaseConnection *base_conn = TP_BASE_CONNECTION (self);
-  GibberXmppNode *iq, *result_iq, *query, *result_query;
-  const gchar *node;
-  const gchar *suffix;
-  GSList *i;
-  gchar *caps_hash;
-  TpHandleRepoIface *contact_repo;
-  const gchar *jid_from, *jid_to;
-
-  contact_repo = tp_base_connection_get_handles (base_conn,
-      TP_HANDLE_TYPE_CONTACT);
-  jid_from = tp_handle_inspect (contact_repo, base_conn->self_handle);
-  jid_to = tp_handle_inspect (contact_repo, contact->handle);
-
-  iq = stanza->node;
-  query = gibber_xmpp_node_get_child_ns (iq, "query", NS_DISCO_INFO);
-
-  if (query != NULL)
-    {
-      node = gibber_xmpp_node_get_attribute (query, "node");
-      if (node != NULL)
-        {
-          if (0 != strncmp (node, GIBBER_TELEPATHY_NS_CAPS "#",
-                strlen (GIBBER_TELEPATHY_NS_CAPS) + 1))
-            suffix = "";
-          else if (strlen (node) < strlen (GIBBER_TELEPATHY_NS_CAPS) + 2)
-            suffix = "";
-          else
-            suffix = node + strlen (GIBBER_TELEPATHY_NS_CAPS) + 1;
-        }
-      else
-        {
-          node = "";
-          suffix = "";
-        }
-    }
-  else
-    {
-      node = "";
-      suffix = "";
-    }
-
-  DEBUG ("got disco request for node %s", node);
-
-  /* Salut only supports XEP-0115 version 1.5. Bundles from old version 1.3 are
-   * not implemented. */
-  caps_hash = caps_hash_compute_from_self_presence (priv->self);
-
-  if (!tp_strdiff (suffix, caps_hash))
-    {
-      GibberXmppStanza *result;
-      GSList *features = capabilities_get_features (
-          priv->self->per_channel_manager_caps);
-
-      /* Every entity MUST have at least one identity (XEP-0030). Salut publishs
-       * one identity. If you change the identity here, you also need to change
-       * caps_hash_compute_from_self_presence(). */
-      result = gibber_xmpp_stanza_build (GIBBER_STANZA_TYPE_IQ,
-          GIBBER_STANZA_SUB_TYPE_RESULT,
-          jid_from, jid_to,
-          GIBBER_NODE, "query",
-            GIBBER_NODE_XMLNS, NS_DISCO_INFO,
-            GIBBER_NODE_ATTRIBUTE, "node", node,
-            GIBBER_NODE, "identity",
-              GIBBER_NODE_ATTRIBUTE, "category", "client",
-              GIBBER_NODE_ATTRIBUTE, "name", PACKAGE_STRING,
-              /* FIXME: maybe we should add a connection property allowing to
-               * set the type attribute instead of hardcoding "pc". */
-              GIBBER_NODE_ATTRIBUTE, "type", "pc",
-            GIBBER_NODE_END,
-          GIBBER_NODE_END,
-          GIBBER_STANZA_END);
-
-      result_iq = result->node;
-      result_query = gibber_xmpp_node_get_child_ns (result_iq, "query", NULL);
-
-
-      for (i = features; NULL != i; i = i->next)
-        {
-          const Feature *feature = (const Feature *) i->data;
-          GibberXmppNode *feature_node;
-
-          feature_node = gibber_xmpp_node_add_child (result_query, "feature");
-          gibber_xmpp_node_set_attribute (feature_node, "var", feature->ns);
-        }
-      g_slist_free (features);
-
-      DEBUG ("sending disco response");
-
-      if (!gibber_xmpp_connection_send (conn, result, NULL))
-        {
-          DEBUG ("sending disco response failed");
-        }
-
-      g_object_unref (result);
-    }
-  else
-    {
-      GibberXmppStanza *result;
-
-      /* Return <item-not-found>. It is possible that the remote contact
-       * requested an old version (old hash) of our capabilities. In the
-       * meantime, it will have gotten a new hash, and query the new hash
-       * anyway. */
-      result = gibber_xmpp_stanza_build (GIBBER_STANZA_TYPE_IQ,
-          GIBBER_STANZA_SUB_TYPE_ERROR,
-          jid_from, jid_to,
-          GIBBER_NODE, "query",
-            GIBBER_NODE_XMLNS, NS_DISCO_INFO,
-            GIBBER_NODE_ATTRIBUTE, "node", node,
-            GIBBER_NODE, "error",
-              GIBBER_NODE_ATTRIBUTE, "type", "cancel",
-              GIBBER_NODE, "item-not-found",
-                GIBBER_NODE_XMLNS, GIBBER_XMPP_NS_STANZAS,
-              GIBBER_NODE_END,
-            GIBBER_NODE_END,
-          GIBBER_NODE_END,
-          GIBBER_STANZA_END);
-
-      DEBUG ("sending item-not-found as disco response");
-
-      if (!gibber_xmpp_connection_send (conn, result, NULL))
-        {
-          DEBUG ("sending item-not-found failed");
-        }
-
-      g_object_unref (result);
-    }
-  g_free (caps_hash);
-}
-
-
 static void
 salut_connection_init (SalutConnection *obj)
 {
@@ -476,11 +311,6 @@ salut_connection_constructor (GType type,
   self = SALUT_CONNECTION (obj);
   priv = SALUT_CONNECTION_GET_PRIVATE(self);
 
-  /* receive discovery requests */
-  salut_xmpp_connection_manager_add_stanza_filter (
-      priv->xmpp_connection_manager, NULL,
-      caps_req_stanza_filter, caps_req_stanza_callback, self);
-
   self->disco = salut_disco_new (self, priv->xmpp_connection_manager);
   self->presence_cache = salut_presence_cache_new (self);
   g_signal_connect (self->presence_cache, "capabilities-update", G_CALLBACK
@@ -1010,10 +840,6 @@ salut_connection_dispose (GObject *object)
     priv->self = NULL;
   }
 
-  salut_xmpp_connection_manager_remove_stanza_filter (
-      priv->xmpp_connection_manager, NULL,
-      caps_req_stanza_filter, caps_req_stanza_callback, self);
-
 #ifdef ENABLE_OLPC
   salut_xmpp_connection_manager_remove_stanza_filter (
       priv->xmpp_connection_manager, NULL,
diff --git a/src/salut-disco.c b/src/salut-disco.c
index 48e9da0..99e594b 100644
--- a/src/salut-disco.c
+++ b/src/salut-disco.c
@@ -35,6 +35,8 @@
 #define DEBUG_FLAG DEBUG_DISCO
 
 #include "debug.h"
+#include "salut-capabilities.h"
+#include "salut-caps-hash.h"
 #include "salut-connection.h"
 #include "salut-xmpp-connection-manager.h"
 #include "salut-signals-marshal.h"
@@ -397,6 +399,172 @@ salut_disco_set_property (GObject     *object,
     }
 }
 
+static gboolean
+caps_req_stanza_filter (SalutXmppConnectionManager *mgr,
+                        GibberXmppConnection *conn,
+                        GibberXmppStanza *stanza,
+                        SalutContact *contact,
+                        gpointer user_data)
+{
+  GibberStanzaSubType sub_type;
+  GibberXmppNode *query;
+
+  gibber_xmpp_stanza_get_type_info (stanza, NULL, &sub_type);
+
+  if (sub_type != GIBBER_STANZA_SUB_TYPE_GET)
+    return FALSE;
+
+  query = gibber_xmpp_node_get_child_ns (stanza->node, "query", NS_DISCO_INFO);
+
+  if (!query)
+    return FALSE;
+
+  return TRUE;
+}
+
+static void
+caps_req_stanza_callback (SalutXmppConnectionManager *mgr,
+                          GibberXmppConnection *conn,
+                          GibberXmppStanza *stanza,
+                          SalutContact *contact,
+                          gpointer user_data)
+{
+  SalutDisco *self = SALUT_DISCO (user_data);
+  SalutDiscoPrivate *priv = SALUT_DISCO_GET_PRIVATE (self);
+  TpBaseConnection *base_conn = TP_BASE_CONNECTION (priv->connection);
+  GibberXmppNode *iq, *result_iq, *query, *result_query;
+  const gchar *node;
+  const gchar *suffix;
+  GSList *i;
+  gchar *caps_hash;
+  TpHandleRepoIface *contact_repo;
+  const gchar *jid_from, *jid_to;
+  SalutSelf *salut_self;
+
+  contact_repo = tp_base_connection_get_handles (base_conn,
+      TP_HANDLE_TYPE_CONTACT);
+  jid_from = tp_handle_inspect (contact_repo, base_conn->self_handle);
+  jid_to = tp_handle_inspect (contact_repo, contact->handle);
+
+  iq = stanza->node;
+  query = gibber_xmpp_node_get_child_ns (iq, "query", NS_DISCO_INFO);
+
+  if (query != NULL)
+    {
+      node = gibber_xmpp_node_get_attribute (query, "node");
+      if (node != NULL)
+        {
+          if (0 != strncmp (node, GIBBER_TELEPATHY_NS_CAPS "#",
+                strlen (GIBBER_TELEPATHY_NS_CAPS) + 1))
+            suffix = "";
+          else if (strlen (node) < strlen (GIBBER_TELEPATHY_NS_CAPS) + 2)
+            suffix = "";
+          else
+            suffix = node + strlen (GIBBER_TELEPATHY_NS_CAPS) + 1;
+        }
+      else
+        {
+          node = "";
+          suffix = "";
+        }
+    }
+  else
+    {
+      node = "";
+      suffix = "";
+    }
+
+  DEBUG ("got disco request for node %s", node);
+
+  g_object_get (priv->connection, "self", &salut_self, NULL);
+  /* Salut only supports XEP-0115 version 1.5. Bundles from old version 1.3 are
+   * not implemented. */
+  caps_hash = caps_hash_compute_from_self_presence (salut_self);
+
+  if (!tp_strdiff (suffix, caps_hash))
+    {
+      GibberXmppStanza *result;
+      GSList *features = capabilities_get_features (
+          salut_self->per_channel_manager_caps);
+
+      /* Every entity MUST have at least one identity (XEP-0030). Salut publishs
+       * one identity. If you change the identity here, you also need to change
+       * caps_hash_compute_from_self_presence(). */
+      result = gibber_xmpp_stanza_build (GIBBER_STANZA_TYPE_IQ,
+          GIBBER_STANZA_SUB_TYPE_RESULT,
+          jid_from, jid_to,
+          GIBBER_NODE, "query",
+            GIBBER_NODE_XMLNS, NS_DISCO_INFO,
+            GIBBER_NODE_ATTRIBUTE, "node", node,
+            GIBBER_NODE, "identity",
+              GIBBER_NODE_ATTRIBUTE, "category", "client",
+              GIBBER_NODE_ATTRIBUTE, "name", PACKAGE_STRING,
+              /* FIXME: maybe we should add a connection property allowing to
+               * set the type attribute instead of hardcoding "pc". */
+              GIBBER_NODE_ATTRIBUTE, "type", "pc",
+            GIBBER_NODE_END,
+          GIBBER_NODE_END,
+          GIBBER_STANZA_END);
+
+      result_iq = result->node;
+      result_query = gibber_xmpp_node_get_child_ns (result_iq, "query", NULL);
+
+
+      for (i = features; NULL != i; i = i->next)
+        {
+          const Feature *feature = (const Feature *) i->data;
+          GibberXmppNode *feature_node;
+
+          feature_node = gibber_xmpp_node_add_child (result_query, "feature");
+          gibber_xmpp_node_set_attribute (feature_node, "var", feature->ns);
+        }
+      g_slist_free (features);
+
+      DEBUG ("sending disco response");
+
+      if (!gibber_xmpp_connection_send (conn, result, NULL))
+        {
+          DEBUG ("sending disco response failed");
+        }
+
+      g_object_unref (result);
+    }
+  else
+    {
+      GibberXmppStanza *result;
+
+      /* Return <item-not-found>. It is possible that the remote contact
+       * requested an old version (old hash) of our capabilities. In the
+       * meantime, it will have gotten a new hash, and query the new hash
+       * anyway. */
+      result = gibber_xmpp_stanza_build (GIBBER_STANZA_TYPE_IQ,
+          GIBBER_STANZA_SUB_TYPE_ERROR,
+          jid_from, jid_to,
+          GIBBER_NODE, "query",
+            GIBBER_NODE_XMLNS, NS_DISCO_INFO,
+            GIBBER_NODE_ATTRIBUTE, "node", node,
+            GIBBER_NODE, "error",
+              GIBBER_NODE_ATTRIBUTE, "type", "cancel",
+              GIBBER_NODE, "item-not-found",
+                GIBBER_NODE_XMLNS, GIBBER_XMPP_NS_STANZAS,
+              GIBBER_NODE_END,
+            GIBBER_NODE_END,
+          GIBBER_NODE_END,
+          GIBBER_STANZA_END);
+
+      DEBUG ("sending item-not-found as disco response");
+
+      if (!gibber_xmpp_connection_send (conn, result, NULL))
+        {
+          DEBUG ("sending item-not-found failed");
+        }
+
+      g_object_unref (result);
+    }
+  g_free (caps_hash);
+  g_object_unref (salut_self);
+}
+
 static GObject *
 salut_disco_constructor (GType type, guint n_props,
                           GObjectConstructParam *props)
@@ -413,6 +581,11 @@ salut_disco_constructor (GType type, guint n_props,
   g_signal_connect (priv->xmpp_connection_manager, "new-connection",
       G_CALLBACK (xmpp_connection_manager_new_connection_cb), obj);
 
+  /* receive discovery requests */
+  salut_xmpp_connection_manager_add_stanza_filter (
+      priv->xmpp_connection_manager, NULL,
+      caps_req_stanza_filter, caps_req_stanza_callback, obj);
+
   return obj;
 }
 
@@ -431,6 +604,10 @@ salut_disco_dispose (GObject *object)
 
   DEBUG ("dispose called");
 
+  salut_xmpp_connection_manager_remove_stanza_filter (
+      priv->xmpp_connection_manager, NULL,
+      caps_req_stanza_filter, caps_req_stanza_callback, self);
+
   if (priv->xmpp_connection_manager != NULL)
     {
       g_signal_handlers_disconnect_matched (priv->xmpp_connection_manager,
-- 
1.5.6.5




More information about the telepathy-commits mailing list