plugins XEP-0065, XEP-0260: fixed session creation order: session is created earlied, and file object associated in a second time if needed

This commit is contained in:
Goffi 2015-12-17 22:37:58 +01:00
commit 84fbbbc299

View file

@ -1148,7 +1148,8 @@ class XEP_0065(object):
"""Create a session_data associated to hash
@param session_hash(str): hash of the session
@param file_obj(file): file-like object
@param file_obj(file, None): file-like object
None if it will be filled later
@param profile: %(doc_profile)s
return (dict): session data
"""
@ -1157,10 +1158,13 @@ class XEP_0065(object):
session_d = defer.Deferred()
session_d.addBoth(self.killSession, session_hash, None, client)
session_data = client._s5b_sessions[session_hash] = {
"file": file_obj,
DEFER_KEY: session_d,
TIMER_KEY: reactor.callLater(TIMEOUT, self._timeOut, session_hash, client),
}
if file_obj is not None:
session_data['file'] = file_obj
if session_hash in self.hash_profiles_map:
# The only case when 2 profiles want to register the same hash
# is when they are on the same instance
@ -1181,6 +1185,12 @@ class XEP_0065(object):
return session_data
def associateFileObj(self, session_hash, file_obj, profile):
"""Associate a file obj with a session"""
session_data = self.getSession(session_hash, profile)
assert 'file' not in session_data
session_data['file'] = file_obj
def streamQuery(self, iq_elt, profile):
log.debug(u"BS stream query")
client = self.host.getClient(profile)