comparison sat/plugins/plugin_xep_0166.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 945e53cde9b2
children ab2696e34d29
comparison
equal deleted inserted replaced
2926:4cd7545c4ebb 2927:69e4716d6268
119 119
120 ## helpers methods to build stanzas ## 120 ## helpers methods to build stanzas ##
121 121
122 def _buildJingleElt(self, client, session, action): 122 def _buildJingleElt(self, client, session, action):
123 iq_elt = client.IQ("set") 123 iq_elt = client.IQ("set")
124 iq_elt["from"] = client.jid.full() 124 iq_elt["from"] = session['local_jid'].full()
125 iq_elt["to"] = session["peer_jid"].full() 125 iq_elt["to"] = session["peer_jid"].full()
126 jingle_elt = iq_elt.addElement("jingle", NS_JINGLE) 126 jingle_elt = iq_elt.addElement("jingle", NS_JINGLE)
127 jingle_elt["sid"] = session["id"] 127 jingle_elt["sid"] = session["id"]
128 jingle_elt["action"] = action 128 jingle_elt["action"] = action
129 return iq_elt, jingle_elt 129 return iq_elt, jingle_elt
351 - app_args(list): args to pass to the application plugin 351 - app_args(list): args to pass to the application plugin
352 - app_kwargs(dict): keyword args to pass to the application plugin 352 - app_kwargs(dict): keyword args to pass to the application plugin
353 @return D(unicode): jingle session id 353 @return D(unicode): jingle session id
354 """ 354 """
355 assert contents # there must be at least one content 355 assert contents # there must be at least one content
356 if peer_jid == client.jid: 356 if (peer_jid == client.jid
357 or client.is_component and peer_jid.host == client.jid.host):
357 raise ValueError(_(u"You can't do a jingle session with yourself")) 358 raise ValueError(_(u"You can't do a jingle session with yourself"))
358 initiator = client.jid 359 initiator = client.jid
359 sid = unicode(uuid.uuid4()) 360 sid = unicode(uuid.uuid4())
360 # TODO: session cleaning after timeout ? 361 # TODO: session cleaning after timeout ?
361 session = client.jingle_sessions[sid] = { 362 session = client.jingle_sessions[sid] = {
362 "id": sid, 363 "id": sid,
363 "state": STATE_PENDING, 364 "state": STATE_PENDING,
364 "initiator": initiator, 365 "initiator": initiator,
365 "role": XEP_0166.ROLE_INITIATOR, 366 "role": XEP_0166.ROLE_INITIATOR,
367 "local_jid": client.jid,
366 "peer_jid": peer_jid, 368 "peer_jid": peer_jid,
367 "started": time.time(), 369 "started": time.time(),
368 "contents": {}, 370 "contents": {},
369 } 371 }
370 iq_elt, jingle_elt = self._buildJingleElt( 372 iq_elt, jingle_elt = self._buildJingleElt(
536 session = client.jingle_sessions[sid] = { 538 session = client.jingle_sessions[sid] = {
537 "id": sid, 539 "id": sid,
538 "state": STATE_PENDING, 540 "state": STATE_PENDING,
539 "initiator": peer_jid, 541 "initiator": peer_jid,
540 "role": XEP_0166.ROLE_RESPONDER, 542 "role": XEP_0166.ROLE_RESPONDER,
543 # we store local_jid using request['to'] because for a component the jid
544 # used may not be client.jid (if a local part is used).
545 "local_jid": jid.JID(request['to']),
541 "peer_jid": peer_jid, 546 "peer_jid": peer_jid,
542 "started": time.time(), 547 "started": time.time(),
543 } 548 }
544 else: 549 else:
545 if session["peer_jid"] != peer_jid: 550 if session["peer_jid"] != peer_jid:
830 return self.terminate(client, XEP_0166.REASON_DECLINE, session) 835 return self.terminate(client, XEP_0166.REASON_DECLINE, session)
831 836
832 iq_elt, jingle_elt = self._buildJingleElt( 837 iq_elt, jingle_elt = self._buildJingleElt(
833 client, session, XEP_0166.A_SESSION_ACCEPT 838 client, session, XEP_0166.A_SESSION_ACCEPT
834 ) 839 )
835 jingle_elt["responder"] = client.jid.full() 840 jingle_elt["responder"] = session['local_jid'].full()
836 841
837 # contents 842 # contents
838 843
839 def addElement(domish_elt, content_elt): 844 def addElement(domish_elt, content_elt):
840 content_elt.addChild(domish_elt) 845 content_elt.addChild(domish_elt)