Author: bct Date: 2007-06-27 00:52:50 +0200 (Wed, 27 Jun 2007) New Revision: 8321
Modified: branches/e2e_encryption/src/common/connection_handlers.py branches/e2e_encryption/src/common/stanza_session.py Log: properly terminate sessions
Modified: branches/e2e_encryption/src/common/connection_handlers.py =================================================================== --- branches/e2e_encryption/src/common/connection_handlers.py 2007-06-26 21:39:22 UTC (rev 8320) +++ branches/e2e_encryption/src/common/connection_handlers.py 2007-06-26 22:52:50 UTC (rev 8321) @@ -1602,6 +1602,12 @@ except KeyError: return None
+ def delete_session(self, jid, thread_id): + del self.sessions[jid][thread_id] + + if not self.sessions[jid]: + del self.sessions[jid] + def move_session(self, original_jid, thread_id, to_resource): session = self.sessions[original_jid][thread_id]
@@ -1616,7 +1622,8 @@ self.sessions[new_jid][thread_id] = session
def find_null_session(self, jid): - '''returns the session between this connecting and 'jid' that we last sent a message in.''' + '''returns the session between this connecting and 'jid' that we last sent a message in. +this is needed to handle clients that don't support threads; see XEP-0201.''' all = self.sessions[jid].values() null_sessions = filter(lambda s: not s.received_thread_id, all) null_sessions.sort(key=lambda s: s.last_send)
Modified: branches/e2e_encryption/src/common/stanza_session.py =================================================================== --- branches/e2e_encryption/src/common/stanza_session.py 2007-06-26 21:39:22 UTC (rev 8320) +++ branches/e2e_encryption/src/common/stanza_session.py 2007-06-26 22:52:50 UTC (rev 8321) @@ -55,6 +55,25 @@
self.last_send = time.time()
+ def terminate(self): + msg = xmpp.Message() + feature = msg.NT.feature + feature.setNamespace(xmpp.NS_FEATURE) + + x = xmpp.DataForm(typ='submit') + x.addChild(node=xmpp.DataField(name='FORM_TYPE', value='urn:xmpp:ssn')) + x.addChild(node=xmpp.DataField(name='terminate', value='1')) + + feature.addChild(node=x) + + self.send(msg) + + self.status = None + + def acknowledge_termination(self): + # we could send an acknowledgement message here, but we won't. + self.status = None + # an encrypted stanza negotiation has several states. i've represented them as the following values in the 'status' # attribute of the session object:
@@ -74,9 +93,6 @@ # an encrypted session has been successfully negotiated. messages of # any of the types listed in 'encryptable_stanzas' should be encrypted # before they're sent. -# 6. 'sent-terminate': -# this client has sent a termination notice and is waiting for -# acknowledgement.
# the transition between these states is handled in gajim.py's # handle_session_negotiation method. @@ -623,22 +639,11 @@ return result
def terminate_e2e(self): - self.status = None - -#<message from='alice@example.org/pda' to='bob@example.com/laptop'> -# <thread>ffd7076498744578d10edabfe7f4a866</thread> -# <c xmlns='http://www.xmpp.org/extensions/xep-0200.html#ns'> -# <data> ** Base64 encoded encrypted terminate form ** </data> -# <old> ** Base64 encoded old MAC key ** </old> -# <mac> ** Base64 encoded a_mac ** </mac> -# </c> -#</message> + self.terminate()
-# <feature xmlns='http://jabber.org/protocol/feature-neg'> -# <x xmlns='jabber:x:data' type='submit'> -# <field var='FORM_TYPE'> -# <value>urn:xmpp:ssn</value> -# </field> -# <field var='terminate'><value>1</value></field> -# </x> -# </feature> + self.enable_encryption = False + + def acknowledge_termination(self): + StanzaSession.acknowledge_termination(self) + + self.enable_encryption = False