diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 56150b20c..c456e3510 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -1602,6 +1602,12 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, 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 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, 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) diff --git a/src/common/stanza_session.py b/src/common/stanza_session.py index aada6c4ef..6145db44e 100644 --- a/src/common/stanza_session.py +++ b/src/common/stanza_session.py @@ -55,6 +55,25 @@ class StanzaSession(object): 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 @@ class StanzaSession(object): # 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 @@ class EncryptedStanzaSession(StanzaSession): return result def terminate_e2e(self): - self.status = None - -# -# ffd7076498744578d10edabfe7f4a866 -# -# ** Base64 encoded encrypted terminate form ** -# ** Base64 encoded old MAC key ** -# ** Base64 encoded a_mac ** -# -# + self.terminate() -# -# -# -# urn:xmpp:ssn -# -# 1 -# -# + self.enable_encryption = False + + def acknowledge_termination(self): + StanzaSession.acknowledge_termination(self) + + self.enable_encryption = False