plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:

while client.jid is fine in a client context, for components it's not the right jid to use: it is the jid of the component itself while the file transfer/jingle session entity may be established with this jid + a local part (e.g. if client is files.example.net, session may be established with louise@files.example.net, in which case "from" is louise@files.example.net, while client.jid will be files.example.net).

As a consequence, using client.jid was causing trouble with components.
This patch fixes it for jingle and plugins linked to file transfer by keeping a "local_jid" variable in the session, where the jid from the original "from" attribute is used.
This commit is contained in:
Goffi 2019-04-28 08:55:13 +02:00
commit a3c67e1072

View file

@ -131,10 +131,11 @@ class XEP_0047(object):
"""
return self._createSession(*args, **kwargs)[DEFER_KEY]
def _createSession(self, client, stream_object, to_jid, sid):
def _createSession(self, client, stream_object, local_jid, to_jid, sid):
"""Called when a bytestream is imminent
@param stream_object(IConsumer): stream object where data will be written
@param local_jid(jid.JID): same as [startStream]
@param to_jid(jid.JId): jid of the other peer
@param sid(unicode): session id
@return (dict): session data
@ -144,6 +145,7 @@ class XEP_0047(object):
session_data = client.xep_0047_current_stream[sid] = {
"id": sid,
DEFER_KEY: defer.Deferred(),
"local_jid": local_jid,
"to": to_jid,
"stream_object": stream_object,
"seq": -1,
@ -285,15 +287,19 @@ class XEP_0047(object):
self._killSession(sid, client, error_condition)
client.send(iq_elt)
def startStream(self, client, stream_object, to_jid, sid, block_size=None):
def startStream(self, client, stream_object, local_jid, to_jid, sid, block_size=None):
"""Launch the stream workflow
@param stream_object(ifaces.IStreamProducer): stream object to send
@param local_jid(jid.JID): jid to use as local jid
This is needed for client which can be addressed with a different jid than
client.jid if a local part is used (e.g. piotr@file.example.net where
client.jid would be file.example.net)
@param to_jid(jid.JID): JID of the recipient
@param sid(unicode): Stream session id
@param block_size(int, None): size of the block (or None for default)
"""
session_data = self._createSession(client, stream_object, to_jid, sid)
session_data = self._createSession(client, stream_object, local_jid, to_jid, sid)
if block_size is None:
block_size = XEP_0047.BLOCK_SIZE
@ -301,6 +307,7 @@ class XEP_0047(object):
session_data["block_size"] = block_size
iq_elt = client.IQ()
iq_elt["from"] = local_jid.full()
iq_elt["to"] = to_jid.full()
open_elt = iq_elt.addElement((NS_IBB, "open"))
open_elt["block-size"] = str(block_size)
@ -323,6 +330,7 @@ class XEP_0047(object):
buffer_ = session_data["stream_object"].read(session_data["block_size"])
if buffer_:
next_iq_elt = client.IQ()
next_iq_elt["from"] = session_data["local_jid"].full()
next_iq_elt["to"] = session_data["to"].full()
data_elt = next_iq_elt.addElement((NS_IBB, "data"))
seq = session_data["seq"] = (session_data["seq"] + 1) % 65535
@ -350,6 +358,7 @@ class XEP_0047(object):
@param failure_reason(unicode, None): reason of the failure, or None if steam was successful
"""
iq_elt = client.IQ()
iq_elt["from"] = session_data["local_jid"].full()
iq_elt["to"] = session_data["to"].full()
close_elt = iq_elt.addElement((NS_IBB, "close"))
close_elt["sid"] = session_data["id"]