Mercurial > libervia-backend
diff sat/plugins/plugin_xep_0047.py @ 2927:69e4716d6268
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.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 28 Apr 2019 08:55:13 +0200 |
parents | 003b8b4b56a7 |
children | ab2696e34d29 |
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0047.py Sun Apr 28 08:55:13 2019 +0200 +++ b/sat/plugins/plugin_xep_0047.py Sun Apr 28 08:55:13 2019 +0200 @@ -131,10 +131,11 @@ """ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ @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"]