[telepathy-gabble/master] Calculate caps hashes from gabble_presence_get_caps()

Simon McVittie simon.mcvittie at collabora.co.uk
Tue Sep 8 04:10:03 PDT 2009


Originally by Will Thompson, with some merging and corrections.

Regressions:
* capabilities for specific services in stream and D-Bus tube stopped
  working
---
 src/capabilities.c |   29 ---------------------
 src/capabilities.h |    9 ------
 src/caps-hash.c    |   13 +---------
 src/connection.c   |   71 +++++++++++++++++++--------------------------------
 4 files changed, 28 insertions(+), 94 deletions(-)

diff --git a/src/capabilities.c b/src/capabilities.c
index c08742e..a291d24 100644
--- a/src/capabilities.c
+++ b/src/capabilities.c
@@ -101,35 +101,6 @@ gabble_capabilities_get_bundle_video_v1 ()
   return video_v1_caps;
 }
 
-GSList *
-capabilities_get_features (GabblePresenceCapabilities caps,
-                           GHashTable *per_channel_manager_caps)
-{
-  GHashTableIter channel_manager_iter;
-  GSList *features = NULL;
-  const Feature *i;
-
-  for (i = self_advertised_features; NULL != i->ns; i++)
-    if ((i->caps & caps) == i->caps)
-      features = g_slist_append (features, (gpointer) i);
-
-  if (per_channel_manager_caps != NULL)
-    {
-      gpointer manager;
-      gpointer cap;
-
-      g_hash_table_iter_init (&channel_manager_iter, per_channel_manager_caps);
-      while (g_hash_table_iter_next (&channel_manager_iter,
-                 &manager, &cap))
-        {
-          gabble_caps_channel_manager_get_feature_list (manager, cap,
-              &features);
-        }
-    }
-
-  return features;
-}
-
 static gboolean
 omits_content_creators (LmMessageNode *identity)
 {
diff --git a/src/capabilities.h b/src/capabilities.h
index 22fa8eb..fb11476 100644
--- a/src/capabilities.h
+++ b/src/capabilities.h
@@ -81,15 +81,6 @@ const GabbleCapabilitySet *gabble_capabilities_get_bundle_voice_v1 (void);
 const GabbleCapabilitySet *gabble_capabilities_get_bundle_video_v1 (void);
 
 /*
- * capabilities_get_features
- *
- * Return a linked list of const Feature structs corresponding to the given
- * GabblePresenceCapabilities.
- */
-GSList *capabilities_get_features (GabblePresenceCapabilities caps,
-    GHashTable *per_channel_manager_caps);
-
-/*
  * capabilities_fill_cache
  *
  * Fill up the given GabblePresenceCache with known feature nodes
diff --git a/src/caps-hash.c b/src/caps-hash.c
index c51fa03..21d96f1 100644
--- a/src/caps-hash.c
+++ b/src/caps-hash.c
@@ -359,20 +359,10 @@ gchar *
 caps_hash_compute_from_self_presence (GabbleConnection *self)
 {
   GabblePresence *presence = self->self_presence;
-  GSList *features_list = capabilities_get_features (presence->caps,
-      presence->per_channel_manager_caps);
-  GPtrArray *features = g_ptr_array_new ();
+  GPtrArray *features = gabble_presence_get_caps (presence);
   GPtrArray *identities = g_ptr_array_new ();
   GPtrArray *dataforms = g_ptr_array_new ();
   gchar *str;
-  GSList *i;
-
-  /* get our features list  */
-  for (i = features_list; NULL != i; i = i->next)
-    {
-      const Feature *feat = (const Feature *) i->data;
-      g_ptr_array_add (features, g_strdup (feat->ns));
-    }
 
   /* XEP-0030 requires at least 1 identity. We don't need more. */
   g_ptr_array_add (identities, g_strdup ("client/pc//" PACKAGE_STRING));
@@ -382,7 +372,6 @@ caps_hash_compute_from_self_presence (GabbleConnection *self)
   str = caps_hash_compute (features, identities, dataforms);
 
   gabble_presence_free_xep0115_hash (features, identities, dataforms);
-  g_slist_free (features_list);
 
   return str;
 }
diff --git a/src/connection.c b/src/connection.c
index c0eb652..c06d5bb 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1580,20 +1580,6 @@ _gabble_connection_acknowledge_set_iq (GabbleConnection *conn,
     }
 }
 
-/* Send @message on @self; ignore errors, other than logging @complaint on
- * failure.
- */
-static void
-_gabble_connection_send_or_complain (GabbleConnection *self,
-    LmMessage *message,
-    const gchar *complaint)
-{
-  if (!lm_connection_send (self->lmconn, message, NULL))
-    {
-      DEBUG ("%s", complaint);
-    }
-}
-
 /**
  * _gabble_connection_send_iq_error
  *
@@ -1660,8 +1646,8 @@ connection_iq_disco_cb (LmMessageHandler *handler,
   LmMessage *result;
   LmMessageNode *iq, *result_iq, *query, *result_query, *identity;
   const gchar *node, *suffix;
-  GSList *features;
-  GSList *i;
+  GabbleCapabilitySet *features;
+  guint i;
   gchar *caps_hash;
 
   if (lm_message_get_sub_type (message) != LM_MESSAGE_SUB_TYPE_GET)
@@ -1709,41 +1695,24 @@ connection_iq_disco_cb (LmMessageHandler *handler,
   lm_message_node_set_attribute (identity, "name", PACKAGE_STRING);
   lm_message_node_set_attribute (identity, "type", "pc");
 
-  features = capabilities_get_features (self->self_presence->caps,
-      self->self_presence->per_channel_manager_caps);
+  caps_hash = caps_hash_compute_from_self_presence (self);
 
   /* If node is not NULL, it can be either a caps bundle as defined in the
    * legacy XEP-0115 version 1.3 or an hash as defined in XEP-0115 version
    * 1.5. */
-
-  caps_hash = caps_hash_compute_from_self_presence (self);
-
+  /* FIXME: We shouldn't have to copy the sets here */
   if (node == NULL || !tp_strdiff (suffix, caps_hash))
-    {
-      for (i = features; NULL != i; i = i->next)
-        {
-          const Feature *feature = (const Feature *) i->data;
-
-          add_feature_node (result_query, feature->ns);
-        }
-
-      NODE_DEBUG (result_iq, "sending disco response");
-      _gabble_connection_send_or_complain (self, result,
-          "sending disco response failed");
-    }
+    features = gabble_presence_get_caps (self->self_presence);
   else if (!tp_strdiff (suffix, BUNDLE_VOICE_V1))
-    {
-      add_feature_node (result_query, NS_GOOGLE_FEAT_VOICE);
-      _gabble_connection_send_or_complain (self, result,
-          "sending disco response failed");
-    }
+    features = gabble_capability_set_copy (
+        gabble_capabilities_get_bundle_voice_v1 ());
   else if (!tp_strdiff (suffix, BUNDLE_VIDEO_V1))
-    {
-      add_feature_node (result_query, NS_GOOGLE_FEAT_VIDEO);
-      _gabble_connection_send_or_complain (self, result,
-          "sending disco response failed");
-    }
+    features = gabble_capability_set_copy (
+        gabble_capabilities_get_bundle_video_v1 ());
   else
+    features = NULL;
+
+  if (features == NULL)
     {
       /* Return <item-not-found>. It is possible that the remote contact
        * requested an old version (old hash) of our capabilities. In the
@@ -1752,10 +1721,24 @@ connection_iq_disco_cb (LmMessageHandler *handler,
       _gabble_connection_send_iq_error (self, message,
           XMPP_ERROR_ITEM_NOT_FOUND, NULL);
     }
+  else
+    {
+      for (i = 0; i < features->len; i++)
+        add_feature_node (result_query, g_ptr_array_index (features, i));
+
+      NODE_DEBUG (result_iq, "sending disco response");
+
+      if (!lm_connection_send (self->lmconn, result, NULL))
+        {
+          DEBUG ("sending disco response failed");
+        }
+
+      gabble_capability_set_free (features);
+    }
+
   g_free (caps_hash);
 
   lm_message_unref (result);
-  g_slist_free (features);
 
   return LM_HANDLER_RESULT_REMOVE_MESSAGE;
 }
-- 
1.5.6.5




More information about the telepathy-commits mailing list