ability to accept correct content by its name, not only by it's media
This commit is contained in:
parent
286d788da0
commit
f951df7ead
|
@ -142,14 +142,14 @@ class JingleSession(object):
|
||||||
reason.addChild('decline')
|
reason.addChild('decline')
|
||||||
self._session_terminate(reason)
|
self._session_terminate(reason)
|
||||||
|
|
||||||
def approve_content(self, media):
|
def approve_content(self, media, name=None):
|
||||||
content = self.get_content(media)
|
content = self.get_content(media, name)
|
||||||
if content:
|
if content:
|
||||||
content.accepted = True
|
content.accepted = True
|
||||||
self.on_session_state_changed(content)
|
self.on_session_state_changed(content)
|
||||||
|
|
||||||
def reject_content(self, media):
|
def reject_content(self, media, name=None):
|
||||||
content = self.get_content(media)
|
content = self.get_content(media, name)
|
||||||
if content:
|
if content:
|
||||||
if self.state == JingleStates.active:
|
if self.state == JingleStates.active:
|
||||||
self.__content_reject(content)
|
self.__content_reject(content)
|
||||||
|
@ -167,12 +167,13 @@ class JingleSession(object):
|
||||||
reason.addChild('cancel')
|
reason.addChild('cancel')
|
||||||
self._session_terminate(reason)
|
self._session_terminate(reason)
|
||||||
|
|
||||||
def get_content(self, media=None):
|
def get_content(self, media=None, name=None):
|
||||||
if media is None:
|
if media is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
for content in self.contents.values():
|
for content in self.contents.values():
|
||||||
if content.media == media:
|
if content.media == media:
|
||||||
|
if name is None or content.name == name:
|
||||||
return content
|
return content
|
||||||
|
|
||||||
def add_content(self, name, content, creator='we'):
|
def add_content(self, name, content, creator='we'):
|
||||||
|
|
|
@ -25,15 +25,15 @@ log = logging.getLogger('gajim.c.jingle_xtls')
|
||||||
|
|
||||||
PYOPENSSL_PRESENT = False
|
PYOPENSSL_PRESENT = False
|
||||||
|
|
||||||
pending_sessions = {} # key-exchange id -> session, accept that session once key-exchange completes
|
pending_contents = {} # key-exchange id -> session, accept that session once key-exchange completes
|
||||||
|
|
||||||
def key_exchange_pend(id, session):
|
def key_exchange_pend(id_, content):
|
||||||
pending_sessions[id] = session
|
pending_contents[id_] = content
|
||||||
|
|
||||||
def approve_pending_session(id):
|
def approve_pending_content(id_):
|
||||||
session = pending_sessions[id]
|
content = pending_contents[id_]
|
||||||
session.approve_session()
|
content.session.approve_session()
|
||||||
session.approve_content('file')
|
content.session.approve_content('file', name=content.name)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import OpenSSL
|
import OpenSSL
|
||||||
|
@ -133,7 +133,7 @@ def handle_new_cert(con, obj, jid_from):
|
||||||
certpath = os.path.join(os.path.expanduser(gajim.MY_PEER_CERTS_PATH), jid)
|
certpath = os.path.join(os.path.expanduser(gajim.MY_PEER_CERTS_PATH), jid)
|
||||||
certpath += '.cert'
|
certpath += '.cert'
|
||||||
|
|
||||||
id = obj.getAttr('id')
|
id_ = obj.getAttr('id')
|
||||||
|
|
||||||
x509cert = obj.getTag('pubkeys').getTag('keyinfo').getTag('x509cert')
|
x509cert = obj.getTag('pubkeys').getTag('keyinfo').getTag('x509cert')
|
||||||
|
|
||||||
|
@ -144,16 +144,16 @@ def handle_new_cert(con, obj, jid_from):
|
||||||
f.write(cert)
|
f.write(cert)
|
||||||
f.write('-----END CERTIFICATE-----\n')
|
f.write('-----END CERTIFICATE-----\n')
|
||||||
|
|
||||||
approve_pending_session(id)
|
approve_pending_content(id_)
|
||||||
|
|
||||||
def send_cert_request(con, to_jid):
|
def send_cert_request(con, to_jid):
|
||||||
iq = common.xmpp.Iq('get', to=to_jid)
|
iq = common.xmpp.Iq('get', to=to_jid)
|
||||||
id = con.connection.getAnID()
|
id_ = con.connection.getAnID()
|
||||||
iq.setAttr('id', id)
|
iq.setAttr('id', id_)
|
||||||
pubkey = iq.setTag('pubkeys')
|
pubkey = iq.setTag('pubkeys')
|
||||||
pubkey.setNamespace(common.xmpp.NS_PUBKEY_PUBKEY)
|
pubkey.setNamespace(common.xmpp.NS_PUBKEY_PUBKEY)
|
||||||
con.connection.send(iq)
|
con.connection.send(iq)
|
||||||
return unicode(id)
|
return unicode(id_)
|
||||||
|
|
||||||
# the following code is partly due to pyopenssl examples
|
# the following code is partly due to pyopenssl examples
|
||||||
|
|
||||||
|
|
|
@ -140,16 +140,24 @@ class ConnectionBytestream:
|
||||||
file_props['session-sid'])
|
file_props['session-sid'])
|
||||||
if not session:
|
if not session:
|
||||||
return
|
return
|
||||||
|
content = None
|
||||||
|
for c in session.contents.values():
|
||||||
|
if c.transport.sid == file_props['sid']:
|
||||||
|
content = c
|
||||||
|
break
|
||||||
|
if not content:
|
||||||
|
return
|
||||||
gajim.socks5queue.add_file_props(self.name, file_props)
|
gajim.socks5queue.add_file_props(self.name, file_props)
|
||||||
|
|
||||||
if not session.accepted:
|
if not session.accepted:
|
||||||
if session.get_content('file').use_security:
|
if session.get_content('file', content.name).use_security:
|
||||||
id_ = jingle_xtls.send_cert_request(self, file_props['sender'])
|
id_ = jingle_xtls.send_cert_request(self,
|
||||||
jingle_xtls.key_exchange_pend(id_, session)
|
file_props['sender'])
|
||||||
|
jingle_xtls.key_exchange_pend(id_, content)
|
||||||
return
|
return
|
||||||
session.approve_session()
|
session.approve_session()
|
||||||
|
|
||||||
session.approve_content('file')
|
session.approve_content('file', content.name)
|
||||||
return
|
return
|
||||||
|
|
||||||
iq = xmpp.Iq(to=unicode(file_props['sender']), typ='result')
|
iq = xmpp.Iq(to=unicode(file_props['sender']), typ='result')
|
||||||
|
|
Loading…
Reference in New Issue