[telepathy-gabble/master] fd.o#25243: only advertise FT capability if we have a FT client

Simon McVittie simon.mcvittie at collabora.co.uk
Tue Nov 24 05:26:52 PST 2009


Originally from commit 79c625e8ac7108, but more or less rewritten for
the new capabilities code in 0.9.
---
 src/capabilities.c                                 |    2 +-
 src/ft-manager.c                                   |   42 ++++++++++++++++---
 tests/twisted/caps/advertise-contact-caps.py       |   19 +++++++++
 tests/twisted/caps/tube-caps.py                    |    2 +-
 tests/twisted/caps_helper.py                       |    3 +-
 .../file-transfer/test-caps-file-transfer.py       |   24 +----------
 6 files changed, 60 insertions(+), 32 deletions(-)

diff --git a/src/capabilities.c b/src/capabilities.c
index 4b9f44a..0a241cf 100644
--- a/src/capabilities.c
+++ b/src/capabilities.c
@@ -63,7 +63,7 @@ static const Feature self_advertised_features[] =
   { FEATURE_FIXED, NS_IBB },
   { FEATURE_FIXED, NS_TUBES },
   { FEATURE_FIXED, NS_BYTESTREAMS },
-  { FEATURE_FIXED, NS_FILE_TRANSFER },
+  { FEATURE_OPTIONAL, NS_FILE_TRANSFER },
 
   { FEATURE_OPTIONAL, NS_GOOGLE_TRANSPORT_P2P },
   { FEATURE_OPTIONAL, NS_JINGLE_TRANSPORT_ICEUDP },
diff --git a/src/ft-manager.c b/src/ft-manager.c
index 87338a3..ff70634 100644
--- a/src/ft-manager.c
+++ b/src/ft-manager.c
@@ -641,19 +641,46 @@ add_file_transfer_channel_class (GPtrArray *arr,
 }
 
 static void
-gabble_ft_manager_get_contact_caps (GabbleCapsChannelManager *manager,
+gabble_ft_manager_get_contact_caps (
+    GabbleCapsChannelManager *manager G_GNUC_UNUSED,
     TpHandle handle,
     const GabbleCapabilitySet *caps,
     GPtrArray *arr)
 {
-  GabbleFtManager *self = GABBLE_FT_MANAGER (manager);
+  if (gabble_capability_set_has (caps, NS_FILE_TRANSFER))
+    add_file_transfer_channel_class (arr, handle);
+}
 
-  g_assert (handle != 0);
+static void
+gabble_ft_manager_represent_client (
+    GabbleCapsChannelManager *manager G_GNUC_UNUSED,
+    const gchar *client_name,
+    const GPtrArray *filters,
+    const gchar * const *cap_tokens G_GNUC_UNUSED,
+    GabbleCapabilitySet *cap_set)
+{
+  guint i;
 
-  /* We always support file transfer */
-  if (handle == self->priv->connection->parent.self_handle ||
-      gabble_capability_set_has (caps, NS_FILE_TRANSFER))
-    add_file_transfer_channel_class (arr, handle);
+  for (i = 0; i < filters->len; i++)
+    {
+      GHashTable *channel_class = g_ptr_array_index (filters, i);
+
+      if (tp_strdiff (tp_asv_get_string (channel_class,
+              TP_IFACE_CHANNEL ".ChannelType"),
+            TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER))
+        continue;
+
+      if (tp_asv_get_uint32 (channel_class,
+            TP_IFACE_CHANNEL ".TargetHandleType", NULL)
+          != TP_HANDLE_TYPE_CONTACT)
+        continue;
+
+      DEBUG ("client %s supports file transfer", client_name);
+      gabble_capability_set_add (cap_set, NS_FILE_TRANSFER);
+      /* there's no point in looking at the subsequent filters if we've
+       * already added the FT capability */
+      break;
+    }
 }
 
 static void
@@ -663,4 +690,5 @@ caps_channel_manager_iface_init (gpointer g_iface,
   GabbleCapsChannelManagerIface *iface = g_iface;
 
   iface->get_contact_caps = gabble_ft_manager_get_contact_caps;
+  iface->represent_client = gabble_ft_manager_represent_client;
 }
diff --git a/tests/twisted/caps/advertise-contact-caps.py b/tests/twisted/caps/advertise-contact-caps.py
index 822d050..bb91c58 100644
--- a/tests/twisted/caps/advertise-contact-caps.py
+++ b/tests/twisted/caps/advertise-contact-caps.py
@@ -188,5 +188,24 @@ def run_test(q, bus, conn, stream):
                 ns.JINGLE_015, ns.JINGLE_RTP_VIDEO,
                 ns.JINGLE_RTP, ns.JINGLE_015_VIDEO])
 
+    # Remove KCall to simplify subsequent checks
+    conn.ContactCapabilities.UpdateCapabilities([
+        (cs.CLIENT + '.KCall', [], []),
+        ])
+    (disco_response, namespaces, _) = receive_presence_and_ask_caps(q, stream,
+            False)
+    check_caps(namespaces, [])
+
+    # Support file transfer
+    conn.ContactCapabilities.UpdateCapabilities([
+        (cs.CLIENT + '.FileReceiver', [{
+            cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_FILE_TRANSFER,
+            cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT,
+            }], []),
+        ])
+    (disco_response, namespaces, _) = receive_presence_and_ask_caps(q, stream,
+            False)
+    check_caps(namespaces, [ns.FILE_TRANSFER])
+
 if __name__ == '__main__':
     exec_test(run_test)
diff --git a/tests/twisted/caps/tube-caps.py b/tests/twisted/caps/tube-caps.py
index 41913a1..8ef66d1 100644
--- a/tests/twisted/caps/tube-caps.py
+++ b/tests/twisted/caps/tube-caps.py
@@ -244,7 +244,7 @@ def test_tube_caps_to_contact(q, bus, conn, stream):
         [(text_fixed_properties, text_allowed_properties),
          (stream_tube_fixed_properties, stream_tube_allowed_properties),
          (dbus_tube_fixed_properties, dbus_tube_allowed_properties),
-         (ft_fixed_properties, ft_allowed_properties)]})
+         ]})
     daap_caps = dbus.Dictionary({self_handle:
         [(text_fixed_properties, text_allowed_properties),
         (stream_tube_fixed_properties, stream_tube_allowed_properties),
diff --git a/tests/twisted/caps_helper.py b/tests/twisted/caps_helper.py
index 3708fea..0626e59 100644
--- a/tests/twisted/caps_helper.py
+++ b/tests/twisted/caps_helper.py
@@ -43,9 +43,10 @@ JINGLE_CAPS = [
 VARIABLE_CAPS = (
     JINGLE_CAPS +
     [
+    ns.FILE_TRANSFER,
+
     # FIXME: currently we always advertise these, but in future we should
     # only advertise them if >= 1 client supports them:
-    # ns.FILE_TRANSFER,
     # ns.TUBES,
 
     # there is an unlimited set of these; only the ones actually relevant to
diff --git a/tests/twisted/file-transfer/test-caps-file-transfer.py b/tests/twisted/file-transfer/test-caps-file-transfer.py
index 1197ee8..f58a238 100644
--- a/tests/twisted/file-transfer/test-caps-file-transfer.py
+++ b/tests/twisted/file-transfer/test-caps-file-transfer.py
@@ -98,27 +98,6 @@ def test_ft_caps_from_contact(q, bus, conn, stream, contact, contact_handle, cli
     assert caps_via_contacts_iface == caps[contact_handle], \
                                     caps_via_contacts_iface
 
-
-def test_ft_caps_to_contact(q, bus, conn, stream):
-    basic_caps = dbus.Dictionary({1:
-        [(text_fixed_properties, text_allowed_properties),
-         (stream_tube_fixed_properties, stream_tube_allowed_properties),
-         (dbus_tube_fixed_properties, dbus_tube_allowed_properties),
-         (ft_fixed_properties, ft_allowed_properties)]})
-
-    conn_caps_iface = dbus.Interface(conn, cs.CONN_IFACE_CONTACT_CAPS)
-    conn_contacts_iface = dbus.Interface(conn, cs.CONN_IFACE_CONTACTS)
-
-    # Check our own caps
-    caps = conn_caps_iface.GetContactCapabilities([1])
-    assertEquals(basic_caps, caps)
-
-    # check the Contacts interface give the same caps
-    caps_via_contacts_iface = conn_contacts_iface.GetContactAttributes(
-            [1], [cs.CONN_IFACE_CONTACT_CAPS], False) \
-            [1][cs.CONN_IFACE_CONTACT_CAPS + '/caps']
-    assertEquals(caps[1], caps_via_contacts_iface)
-
 def test(q, bus, conn, stream):
     conn.Connect()
     q.expect('dbus-signal', signal='StatusChanged',
@@ -129,7 +108,8 @@ def test(q, bus, conn, stream):
     test_ft_caps_from_contact(q, bus, conn, stream, 'bilbo1 at foo.com/Foo',
         2L, client)
 
-    test_ft_caps_to_contact(q, bus, conn, stream)
+    # our own capabilities, formerly tested here, are now in
+    # tests/twisted/caps/advertise-contact-capabilities.py
 
 if __name__ == '__main__':
     exec_test(test)
-- 
1.5.6.5




More information about the telepathy-commits mailing list