[Telepathy-commits] [telepathy-gabble/master] JingleSession: ignore session-accept accepting streams we're in the middle of removing

Senko Rasic senko.rasic at collabora.co.uk
Tue Jan 20 00:41:56 PST 2009


---
 src/jingle-session.c                               |    9 ++++
 tests/twisted/jingle/jingletest.py                 |   44 ++++++++++++--------
 .../twisted/jingle/test-content-adding-removal.py  |   32 ++++++++++++--
 3 files changed, 62 insertions(+), 23 deletions(-)

diff --git a/src/jingle-session.c b/src/jingle-session.c
index 133f3c5..68a1299 100644
--- a/src/jingle-session.c
+++ b/src/jingle-session.c
@@ -715,6 +715,7 @@ _each_content_accept (GabbleJingleSession *sess, GabbleJingleContent *c,
     LmMessageNode *content_node ,GError **error)
 {
   GabbleJingleSessionPrivate *priv = GABBLE_JINGLE_SESSION_GET_PRIVATE (sess);
+  JingleContentState state;
 
   if (c == NULL)
     {
@@ -723,6 +724,14 @@ _each_content_accept (GabbleJingleSession *sess, GabbleJingleContent *c,
       return;
     }
 
+  g_object_get (c, "state", &state, NULL);
+  if (state != JINGLE_CONTENT_STATE_SENT)
+    {
+      const gchar *name = lm_message_node_get_attribute (content_node, "name");
+      DEBUG ("ignoring content \"%s\"s acceptance for content not in SENT state", name);
+      return;
+    }
+
   gabble_jingle_content_parse_accept (c, content_node,
       JINGLE_IS_GOOGLE_DIALECT (priv->dialect), error);
 }
diff --git a/tests/twisted/jingle/jingletest.py b/tests/twisted/jingle/jingletest.py
index 3d224dd..c3f17de 100644
--- a/tests/twisted/jingle/jingletest.py
+++ b/tests/twisted/jingle/jingletest.py
@@ -187,7 +187,27 @@ class JingleTest:
         self.stream.send(iq.toXml())
 
 
-    def outgoing_call_reply(self, session_id, accept):
+    def outgoing_call_reply(self, session_id, accept, with_video=False):
+
+        def create_content_node(name, type, codecs):
+            content = domish.Element((None, 'content'))
+            content['creator'] = 'initiator'
+            content['name'] = name
+            content['senders'] = 'both'
+
+            desc = domish.Element(("http://jabber.org/protocol/jingle/description/" + type, 'description'))
+            for codec, id, rate in codecs:
+                p = domish.Element((None, 'payload-type'))
+                p['name'] = codec
+                p['id'] = str(id)
+                p['rate'] = str(rate)
+                desc.addChild(p)
+            content.addChild(desc)
+
+            xport = domish.Element(("http://www.google.com/transport/p2p", 'transport'))
+            content.addChild(xport)
+            return content
+
         self.session_id = session_id
         self.direction = 'outgoing'
 
@@ -197,24 +217,12 @@ class JingleTest:
 
         iq, jingle = self._jingle_stanza('session-accept')
 
-        content = domish.Element((None, 'content'))
-        content['creator'] = 'initiator'
-        content['name'] = 'stream1'
-        content['senders'] = 'both'
-        jingle.addChild(content)
-
-        desc = domish.Element(("http://jabber.org/protocol/jingle/description/audio", 'description'))
-        for codec, id, rate in self.audio_codecs:
-            p = domish.Element((None, 'payload-type'))
-            p['name'] = codec
-            p['id'] = str(id)
-            p['rate'] = str(rate)
-            desc.addChild(p)
-
-        content.addChild(desc)
+        jingle.addChild(create_content_node('stream1', 'audio',
+            self.audio_codecs))
 
-        xport = domish.Element(("http://www.google.com/transport/p2p", 'transport'))
-        content.addChild(xport)
+        if with_video:
+            jingle.addChild(create_content_node('stream2', 'video',
+                self.video_codecs))
 
         self.stream.send(iq.toXml())
 
diff --git a/tests/twisted/jingle/test-content-adding-removal.py b/tests/twisted/jingle/test-content-adding-removal.py
index 118e9d9..28ca897 100644
--- a/tests/twisted/jingle/test-content-adding-removal.py
+++ b/tests/twisted/jingle/test-content-adding-removal.py
@@ -9,7 +9,7 @@ from gabbletest import exec_test, make_result_iq, sync_stream, \
         send_error_reply
 from servicetest import make_channel_proxy, unwrap, tp_path_prefix, \
         call_async, EventPattern
-from twisted.words.xish import domish
+from twisted.words.xish import domish, xpath
 import jingletest
 import gabbletest
 import dbus
@@ -70,20 +70,43 @@ def test(q, bus, conn, stream):
     stream_handler = make_channel_proxy(conn, e.args[0], 'Media.StreamHandler')
 
     stream_handler.NewNativeCandidate("fake", jt.get_remote_transports_dbus())
+
+    # Before sending the initiate, request another stream
+
+    media_iface.RequestStreams(handle, [1]) # 0 == MEDIA_STREAM_TYPE_VIDEO
+
+    e = q.expect('dbus-signal', signal='NewStreamHandler')
+    stream_id2 = e.args[1]
+
+    stream_handler2 = make_channel_proxy(conn, e.args[0], 'Media.StreamHandler')
+
+    # We set both streams as ready, which will trigger the session invite
     stream_handler.Ready(jt.get_audio_codecs_dbus())
     stream_handler.StreamState(2)
+    stream_handler2.Ready(jt.get_audio_codecs_dbus())
+    stream_handler2.StreamState(2)
+
+    # We changed our mind locally, don't want video
+    media_iface.RemoveStreams([stream_id2])
 
     e = q.expect('stream-iq')
     assert e.query.name == 'jingle'
     assert e.query['action'] == 'session-initiate'
     stream.send(gabbletest.make_result_iq(stream, e.stanza))
-    # send_error_reply(stream, e.stanza)
 
-    jt.outgoing_call_reply(e.query['sid'], True)
+    e2 = q.expect('stream-iq', predicate=lambda x:
+        xpath.queryForNodes("/iq/jingle[@action='content-remove']",
+            x.stanza))
 
+    jt.outgoing_call_reply(e.query['sid'], True, with_video=True)
     q.expect('stream-iq', iq_type='result')
 
-    # Now we want another stream!
+    # Only now the remote end removes the video stream; if gabble mistakenly
+    # marked it as accepted on session acceptance, it'll crash right about
+    # now. If it's good, stream will be really removed, and we can proceed.
+    stream.send(gabbletest.make_result_iq(stream, e2.stanza))
+
+    q.expect('dbus-signal', signal='StreamRemoved')
 
     media_iface.RequestStreams(handle, [1]) # 1 == MEDIA_STREAM_TYPE_VIDEO
 
@@ -148,7 +171,6 @@ def test(q, bus, conn, stream):
     assert (tp_path_prefix + e.path) == path
 
     # Test completed, close the connection
-
     conn.Disconnect()
     q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
 
-- 
1.5.6.5




More information about the Telepathy-commits mailing list