merge
This commit is contained in:
commit
c51fb07d09
|
@ -38,6 +38,7 @@ from jingle_session import JingleSession, JingleStates
|
|||
if gajim.HAVE_FARSIGHT:
|
||||
from jingle_rtp import JingleAudio, JingleVideo
|
||||
from jingle_ft import JingleFileTransfer
|
||||
from jingle_transport import JingleTransportSocks5, JingleTransportIBB
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger('gajim.c.jingle')
|
||||
|
@ -78,11 +79,11 @@ class ConnectionJingle(object):
|
|||
"""
|
||||
# get data
|
||||
jid = helpers.get_full_jid_from_iq(stanza)
|
||||
id = stanza.getID()
|
||||
id_ = stanza.getID()
|
||||
|
||||
if (jid, id) in self.__iq_responses.keys():
|
||||
self.__iq_responses[(jid, id)].on_stanza(stanza)
|
||||
del self.__iq_responses[(jid, id)]
|
||||
if (jid, id_) in self.__iq_responses.keys():
|
||||
self.__iq_responses[(jid, id_)].on_stanza(stanza)
|
||||
del self.__iq_responses[(jid, id_)]
|
||||
raise xmpp.NodeProcessed
|
||||
|
||||
jingle = stanza.getTag('jingle')
|
||||
|
@ -93,7 +94,7 @@ class ConnectionJingle(object):
|
|||
else:
|
||||
sid = None
|
||||
for sesn in self._sessions.values():
|
||||
if id in sesn.iq_ids:
|
||||
if id_ in sesn.iq_ids:
|
||||
sesn.on_stanza(stanza)
|
||||
return
|
||||
|
||||
|
@ -101,14 +102,15 @@ class ConnectionJingle(object):
|
|||
if sid not in self._sessions:
|
||||
#TODO: tie-breaking and other things...
|
||||
newjingle = JingleSession(con=self, weinitiate=False, jid=jid,
|
||||
iq_id=id, sid=sid)
|
||||
iq_id=id_, sid=sid)
|
||||
self._sessions[sid] = newjingle
|
||||
|
||||
# we already have such session in dispatcher...
|
||||
self._sessions[sid].collect_iq_id(id)
|
||||
self._sessions[sid].collect_iq_id(id_)
|
||||
self._sessions[sid].on_stanza(stanza)
|
||||
# Delete invalid/unneeded sessions
|
||||
if sid in self._sessions and self._sessions[sid].state == JingleStates.ended:
|
||||
if sid in self._sessions and \
|
||||
self._sessions[sid].state == JingleStates.ended:
|
||||
self.delete_jingle_session(sid)
|
||||
|
||||
raise xmpp.NodeProcessed
|
||||
|
@ -142,16 +144,20 @@ class ConnectionJingle(object):
|
|||
def start_file_transfer(self, jid, file_props):
|
||||
logger.info("start file transfer with file: %s" % file_props)
|
||||
contact = gajim.contacts.get_contact_with_highest_priority(self.name,
|
||||
gajim.get_jid_without_resource(jid))
|
||||
gajim.get_jid_without_resource(jid))
|
||||
if contact is None:
|
||||
return
|
||||
use_security = contact.supports(xmpp.NS_JINGLE_XTLS)
|
||||
jingle = JingleSession(self, weinitiate=True, jid=jid)
|
||||
self._sessions[jingle.sid] = jingle
|
||||
file_props['sid'] = jingle.sid
|
||||
c = JingleFileTransfer(jingle, file_props=file_props,
|
||||
use_security=use_security)
|
||||
c.hash_algo = self.__hash_support(contact)
|
||||
if contact.supports(xmpp.NS_JINGLE_BYTESTREAM):
|
||||
transport = JingleTransportSocks5()
|
||||
elif contact.supports(xmpp.NS_JINGLE_IBB):
|
||||
transport = JingleTransportIBB()
|
||||
c = JingleFileTransfer(jingle, transport=transport,
|
||||
file_props=file_props, use_security=use_security)
|
||||
c.hash_algo = self.__hash_support(contact)
|
||||
jingle.add_content('file' + helpers.get_random_string_16(), c)
|
||||
jingle.start_session()
|
||||
return c.transport.sid
|
||||
|
@ -172,13 +178,16 @@ class ConnectionJingle(object):
|
|||
|
||||
def iter_jingle_sessions(self, jid, sid=None, media=None):
|
||||
if sid:
|
||||
return (session for session in self._sessions.values() if session.sid == sid)
|
||||
sessions = (session for session in self._sessions.values() if session.peerjid == jid)
|
||||
return (session for session in self._sessions.values() if \
|
||||
session.sid == sid)
|
||||
sessions = (session for session in self._sessions.values() if \
|
||||
session.peerjid == jid)
|
||||
if media:
|
||||
if media not in ('audio', 'video', 'file'):
|
||||
return tuple()
|
||||
else:
|
||||
return (session for session in sessions if session.get_content(media))
|
||||
return (session for session in sessions if \
|
||||
session.get_content(media))
|
||||
else:
|
||||
return sessions
|
||||
|
||||
|
|
|
@ -22,7 +22,8 @@ Handles Jingle File Transfer (XEP 0234)
|
|||
import gajim
|
||||
import xmpp
|
||||
from jingle_content import contents, JingleContent
|
||||
from jingle_transport import JingleTransportICEUDP, JingleTransportSocks5, JingleTransportIBB, TransportType
|
||||
from jingle_transport import JingleTransportICEUDP, JingleTransportSocks5
|
||||
from jingle_transport import JingleTransportIBB, TransportType
|
||||
from common import helpers
|
||||
from common.socks5 import Socks5ReceiverClient, Socks5SenderClient
|
||||
from common.connection_handlers_events import FileRequestReceivedEvent
|
||||
|
@ -150,9 +151,9 @@ class JingleFileTransfer(JingleContent):
|
|||
|
||||
self.file_props['streamhosts'] = self.transport.remote_candidates
|
||||
for host in self.file_props['streamhosts']:
|
||||
host['initiator'] = self.session.initiator
|
||||
host['target'] = self.session.responder
|
||||
host['sid'] = self.file_props['sid']
|
||||
host['initiator'] = self.session.initiator
|
||||
host['target'] = self.session.responder
|
||||
host['sid'] = self.file_props['sid']
|
||||
|
||||
response = stanza.buildReply('result')
|
||||
response.delChild(response.getQuery())
|
||||
|
@ -161,15 +162,15 @@ class JingleFileTransfer(JingleContent):
|
|||
if not gajim.socks5queue.get_file_props(
|
||||
self.session.connection.name, self.file_props['sid']):
|
||||
gajim.socks5queue.add_file_props(self.session.connection.name,
|
||||
self.file_props)
|
||||
self.file_props)
|
||||
fingerprint = None
|
||||
if self.use_security:
|
||||
fingerprint = 'client'
|
||||
if self.transport.type == TransportType.SOCKS5:
|
||||
gajim.socks5queue.connect_to_hosts(self.session.connection.name,
|
||||
self.file_props['sid'], self.send_candidate_used,
|
||||
self._on_connect_error, fingerprint=fingerprint,
|
||||
receiving=False)
|
||||
self.file_props['sid'], self.send_candidate_used,
|
||||
self._on_connect_error, fingerprint=fingerprint,
|
||||
receiving=False)
|
||||
elif self.transport.type == TransportType.IBB:
|
||||
self.state = STATE_TRANSFERING
|
||||
self.__start_IBB_transfer(self.session.connection)
|
||||
|
@ -286,11 +287,11 @@ class JingleFileTransfer(JingleContent):
|
|||
def __start_IBB_transfer(self, con):
|
||||
con.files_props[self.file_props['sid']] = self.file_props
|
||||
fp = open(self.file_props['file-name'], 'r')
|
||||
con.OpenStream( self.transport.sid, self.session.peerjid,
|
||||
fp, blocksize=4096)
|
||||
con.OpenStream( self.transport.sid, self.session.peerjid, fp,
|
||||
blocksize=4096)
|
||||
|
||||
def __transport_setup(self, stanza=None, content=None, error=None
|
||||
, action=None):
|
||||
def __transport_setup(self, stanza=None, content=None, error=None,
|
||||
action=None):
|
||||
# Sets up a few transport specific things for the file transfer
|
||||
if self.transport.type == TransportType.SOCKS5:
|
||||
self._listen_host()
|
||||
|
@ -377,7 +378,7 @@ class JingleFileTransfer(JingleContent):
|
|||
receiver = self.file_props['receiver']
|
||||
sender = self.file_props['sender']
|
||||
sha_str = helpers.get_auth_sha(self.file_props['sid'], sender,
|
||||
receiver)
|
||||
receiver)
|
||||
self.file_props['sha_str'] = sha_str
|
||||
|
||||
port = gajim.config.get('file_transfers_port')
|
||||
|
@ -388,15 +389,15 @@ class JingleFileTransfer(JingleContent):
|
|||
|
||||
if self.weinitiate:
|
||||
listener = gajim.socks5queue.start_listener(port, sha_str,
|
||||
self._store_socks5_sid, self.file_props,
|
||||
fingerprint=fingerprint, type='sender')
|
||||
self._store_socks5_sid, self.file_props,
|
||||
fingerprint=fingerprint, type='sender')
|
||||
else:
|
||||
listener = gajim.socks5queue.start_listener(port, sha_str,
|
||||
self._store_socks5_sid, self.file_props,
|
||||
fingerprint=fingerprint, type='receiver')
|
||||
self._store_socks5_sid, self.file_props,
|
||||
fingerprint=fingerprint, type='receiver')
|
||||
|
||||
if not listener:
|
||||
# send error message, notify the user
|
||||
# send error message, notify the user
|
||||
return
|
||||
def isOurCandUsed(self):
|
||||
'''
|
||||
|
@ -467,21 +468,18 @@ class JingleFileTransfer(JingleContent):
|
|||
gajim.socks5queue.idx += 1
|
||||
idx = gajim.socks5queue.idx
|
||||
sockobj = Socks5SenderClient(gajim.idlequeue, idx,
|
||||
gajim.socks5queue,
|
||||
_sock=None,
|
||||
host=str(streamhost_used['host']),
|
||||
port=int(streamhost_used['port']),
|
||||
fingerprint=None,
|
||||
connected=False,
|
||||
file_props=self.file_props)
|
||||
gajim.socks5queue, _sock=None,
|
||||
host=str(streamhost_used['host']),
|
||||
port=int(streamhost_used['port']), fingerprint=None,
|
||||
connected=False, file_props=self.file_props)
|
||||
else:
|
||||
sockobj = Socks5ReceiverClient(gajim.idlequeue, streamhost_used,
|
||||
sid=self.file_props['sid'],
|
||||
file_props=self.file_props, fingerprint=None)
|
||||
sockobj.proxy = True
|
||||
sockobj.streamhost = streamhost_used
|
||||
gajim.socks5queue.add_sockobj(self.session.connection.name,
|
||||
sockobj, 'sender')
|
||||
sockobj.streamhost = streamhost_used
|
||||
gajim.socks5queue.add_sockobj(self.session.connection.name,
|
||||
sockobj, 'sender')
|
||||
streamhost_used['idx'] = sockobj.queue_idx
|
||||
# If we offered the nominated candidate used, we activate
|
||||
# the proxy
|
||||
|
|
|
@ -957,13 +957,17 @@ class ConnectionIBBytestream(ConnectionBytestream):
|
|||
log.debug('StreamCloseHandler called sid->%s' % sid)
|
||||
# look in sending files
|
||||
if sid in self.files_props.keys():
|
||||
conn.send(stanza.buildReply('result'))
|
||||
reply = stanza.buildReply('result')
|
||||
reply.delChild('close')
|
||||
conn.send(reply)
|
||||
gajim.socks5queue.complete_transfer_cb(self.name, self.files_props[sid])
|
||||
del self.files_props[sid]
|
||||
# look in receiving files
|
||||
elif gajim.socks5queue.get_file_props(self.name, sid):
|
||||
file_props = gajim.socks5queue.get_file_props(self.name, sid)
|
||||
conn.send(stanza.buildReply('result'))
|
||||
reply = stanza.buildReply('result')
|
||||
reply.delChild('close')
|
||||
conn.send(reply)
|
||||
file_props['fp'].close()
|
||||
gajim.socks5queue.complete_transfer_cb(self.name, file_props)
|
||||
gajim.socks5queue.remove_file_props(self.name, sid)
|
||||
|
@ -1003,6 +1007,7 @@ class ConnectionIBBytestream(ConnectionBytestream):
|
|||
if stanza.getTag('data'):
|
||||
if self.IBBMessageHandler(conn, stanza):
|
||||
reply = stanza.buildReply('result')
|
||||
reply.delChild('data')
|
||||
conn.send(reply)
|
||||
raise xmpp.NodeProcessed
|
||||
elif syn_id == self.last_sent_ibb_id:
|
||||
|
|
Loading…
Reference in New Issue