[Telepathy-commits] [telepathy-gabble/master] Handle clients that send us unsupported stream methods

Marco Barisione marco at barisione.org
Tue Jan 6 08:41:34 PST 2009


---
 src/bytestream-factory.c                |   30 ++++++++++++++++++++++++------
 tests/twisted/tubes/test-si-fallback.py |    6 +++++-
 2 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/src/bytestream-factory.c b/src/bytestream-factory.c
index 3338287..63f7379 100644
--- a/src/bytestream-factory.c
+++ b/src/bytestream-factory.c
@@ -539,6 +539,13 @@ gabble_bytestream_factory_make_stream_init_iq (const gchar *full_jid,
       ')', NULL);
 }
 
+static gboolean
+stream_method_supported (const gchar *stream_method)
+{
+  return !tp_strdiff (stream_method, NS_IBB) ||
+         !tp_strdiff (stream_method, NS_BYTESTREAMS);
+}
+
 /**
  * bytestream_factory_iq_si_cb:
  *
@@ -614,8 +621,9 @@ bytestream_factory_iq_si_cb (LmMessageHandler *handler,
     {
       if (multiple)
         {
-          gabble_bytestream_multiple_add_stream_method (
-              GABBLE_BYTESTREAM_MULTIPLE (bytestream), l->data);
+          if (stream_method_supported (l->data))
+            gabble_bytestream_multiple_add_stream_method (
+                GABBLE_BYTESTREAM_MULTIPLE (bytestream), l->data);
         }
       else
         {
@@ -1340,6 +1348,7 @@ gabble_bytestream_factory_create_multiple (GabbleBytestreamFactory *self,
 
 static GabbleBytestreamIface *
 streaminit_get_multiple_bytestream (GabbleBytestreamFactory *self,
+                                    LmMessage *reply_msg,
                                     LmMessageNode *si,
                                     const gchar *stream_id,
                                     TpHandle peer_handle,
@@ -1348,6 +1357,7 @@ streaminit_get_multiple_bytestream (GabbleBytestreamFactory *self,
   /* If the other client supports si-multiple we have directly a list of
    * supported methods inside <value/> tags */
   LmMessageNode *value;
+  const gchar *stream_method;
   GabbleBytestreamIface *bytestream = NULL;
 
   for (value = si->children; value; value = value->next)
@@ -1355,6 +1365,15 @@ streaminit_get_multiple_bytestream (GabbleBytestreamFactory *self,
       if (tp_strdiff (value->name, "value"))
         continue;
 
+      stream_method = lm_message_node_get_value (value);
+
+      if (!stream_method_supported (stream_method))
+        {
+          NODE_DEBUG (reply_msg->node,
+              "got a SI reply with an unsupported stream method");
+          continue;
+        }
+
       /* If there is at least a <value/> we create a multiple bytestream and
        * add the supported methods to it */
       if (!bytestream)
@@ -1364,8 +1383,7 @@ streaminit_get_multiple_bytestream (GabbleBytestreamFactory *self,
                GABBLE_BYTESTREAM_STATE_INITIATING));
 
       gabble_bytestream_multiple_add_stream_method (
-          GABBLE_BYTESTREAM_MULTIPLE (bytestream),
-          lm_message_node_get_value (value));
+          GABBLE_BYTESTREAM_MULTIPLE (bytestream), stream_method);
     }
 
   return bytestream;
@@ -1488,8 +1506,8 @@ streaminit_reply_cb (GabbleConnection *conn,
     }
 
   /* Try to build a multiple bytestream with fallback methods */
-  bytestream = streaminit_get_multiple_bytestream (self, si, data->stream_id,
-      peer_handle, peer_resource);
+  bytestream = streaminit_get_multiple_bytestream (self, reply_msg, si,
+      data->stream_id, peer_handle, peer_resource);
 
   if (bytestream == NULL)
     /* The other client doesn't suppport si-multiple, use the normal XEP-095
diff --git a/tests/twisted/tubes/test-si-fallback.py b/tests/twisted/tubes/test-si-fallback.py
index ba6b4ef..8a7e39e 100644
--- a/tests/twisted/tubes/test-si-fallback.py
+++ b/tests/twisted/tubes/test-si-fallback.py
@@ -145,6 +145,9 @@ def test(q, bus, conn, stream):
     value.addContent(NS_BYTESTREAMS)
     option = field.addElement((None, 'option'))
     value = option.addElement((None, 'value'))
+    value.addContent("invalid-stream-method")
+    option = field.addElement((None, 'option'))
+    value = option.addElement((None, 'value'))
     value.addContent(NS_IBB)
 
     stream_node = si.addElement((NS_TUBES, 'stream'))
@@ -188,7 +191,6 @@ def test(q, bus, conn, stream):
     event = q.expect('stream-iq', iq_type='error', to='bob at localhost/Bob')
 
     # Then try with IBB
-
     iq = IQ(stream, 'set')
     iq['to'] = 'test at localhost/Resource'
     iq['from'] = 'bob at localhost/Bob'
@@ -303,6 +305,8 @@ def test(q, bus, conn, stream):
     result['to'] = 'test at localhost/Resource'
     res_si = result.addElement((NS_SI, 'si'))
     res_value = res_si.addElement(('', 'value'))
+    res_value.addContent('invalid-stream-method')
+    res_value = res_si.addElement(('', 'value'))
     res_value.addContent(NS_BYTESTREAMS)
     res_value = res_si.addElement(('', 'value'))
     res_value.addContent(NS_IBB)
-- 
1.5.6.5




More information about the Telepathy-commits mailing list