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')
|
||||
self._session_terminate(reason)
|
||||
|
||||
def approve_content(self, media):
|
||||
content = self.get_content(media)
|
||||
def approve_content(self, media, name=None):
|
||||
content = self.get_content(media, name)
|
||||
if content:
|
||||
content.accepted = True
|
||||
self.on_session_state_changed(content)
|
||||
|
||||
def reject_content(self, media):
|
||||
content = self.get_content(media)
|
||||
def reject_content(self, media, name=None):
|
||||
content = self.get_content(media, name)
|
||||
if content:
|
||||
if self.state == JingleStates.active:
|
||||
self.__content_reject(content)
|
||||
|
@ -167,13 +167,14 @@ class JingleSession(object):
|
|||
reason.addChild('cancel')
|
||||
self._session_terminate(reason)
|
||||
|
||||
def get_content(self, media=None):
|
||||
def get_content(self, media=None, name=None):
|
||||
if media is None:
|
||||
return
|
||||
|
||||
for content in self.contents.values():
|
||||
if content.media == media:
|
||||
return content
|
||||
if name is None or content.name == name:
|
||||
return content
|
||||
|
||||
def add_content(self, name, content, creator='we'):
|
||||
"""
|
||||
|
|
|
@ -25,15 +25,15 @@ log = logging.getLogger('gajim.c.jingle_xtls')
|
|||
|
||||
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):
|
||||
pending_sessions[id] = session
|
||||
def key_exchange_pend(id_, content):
|
||||
pending_contents[id_] = content
|
||||
|
||||
def approve_pending_session(id):
|
||||
session = pending_sessions[id]
|
||||
session.approve_session()
|
||||
session.approve_content('file')
|
||||
def approve_pending_content(id_):
|
||||
content = pending_contents[id_]
|
||||
content.session.approve_session()
|
||||
content.session.approve_content('file', name=content.name)
|
||||
|
||||
try:
|
||||
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 += '.cert'
|
||||
|
||||
id = obj.getAttr('id')
|
||||
id_ = obj.getAttr('id')
|
||||
|
||||
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('-----END CERTIFICATE-----\n')
|
||||
|
||||
approve_pending_session(id)
|
||||
approve_pending_content(id_)
|
||||
|
||||
def send_cert_request(con, to_jid):
|
||||
iq = common.xmpp.Iq('get', to=to_jid)
|
||||
id = con.connection.getAnID()
|
||||
iq.setAttr('id', id)
|
||||
id_ = con.connection.getAnID()
|
||||
iq.setAttr('id', id_)
|
||||
pubkey = iq.setTag('pubkeys')
|
||||
pubkey.setNamespace(common.xmpp.NS_PUBKEY_PUBKEY)
|
||||
con.connection.send(iq)
|
||||
return unicode(id)
|
||||
return unicode(id_)
|
||||
|
||||
# the following code is partly due to pyopenssl examples
|
||||
|
||||
|
|
|
@ -140,16 +140,24 @@ class ConnectionBytestream:
|
|||
file_props['session-sid'])
|
||||
if not session:
|
||||
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)
|
||||
|
||||
if not session.accepted:
|
||||
if session.get_content('file').use_security:
|
||||
id_ = jingle_xtls.send_cert_request(self, file_props['sender'])
|
||||
jingle_xtls.key_exchange_pend(id_, session)
|
||||
if session.get_content('file', content.name).use_security:
|
||||
id_ = jingle_xtls.send_cert_request(self,
|
||||
file_props['sender'])
|
||||
jingle_xtls.key_exchange_pend(id_, content)
|
||||
return
|
||||
session.approve_session()
|
||||
|
||||
session.approve_content('file')
|
||||
session.approve_content('file', content.name)
|
||||
return
|
||||
|
||||
iq = xmpp.Iq(to=unicode(file_props['sender']), typ='result')
|
||||
|
|
Loading…
Reference in New Issue