Commit 275e719d authored by Philipp Hörist's avatar Philipp Hörist

Move ConnectionJingle code to module

parent 16751610
......@@ -594,7 +594,7 @@ class ChatControl(ChatControlBase):
self._set_jingle_state('video', state, sid=sid, reason=reason)
def _get_audio_content(self):
session = app.connections[self.account].get_jingle_session(
session = app.connections[self.account].get_module('Jingle').get_jingle_session(
self.contact.get_full_jid(), self.audio_sid)
return session.get_content('audio')
......@@ -757,8 +757,8 @@ class ChatControl(ChatControlBase):
return
setattr(self, jingle_type + '_sid', None)
setattr(self, jingle_type + '_state', self.JINGLE_STATE_NULL)
session = app.connections[self.account].get_jingle_session(
self.contact.get_full_jid(), sid)
session = app.connections[self.account].get_module('Jingle').get_jingle_session(
self.contact.get_full_jid(), sid)
if session:
content = session.get_content(jingle_type)
if content:
......@@ -790,7 +790,7 @@ class ChatControl(ChatControlBase):
in_da = self.xml.get_object('incoming_drawingarea')
in_da.realize()
in_xid = in_da.get_window().get_xid()
sid = app.connections[self.account].start_video(
sid = app.connections[self.account].get_module('Jingle').start_video(
self.contact.get_full_jid(), in_xid, out_xid)
else:
sid = getattr(app.connections[self.account],
......
......@@ -189,7 +189,7 @@ class StandardCommonChatCommands(CommandContainer):
for tone in sequence:
if not (tone in ("*", "#") or tone.isdigit()):
raise CommandError(_("%s is not a valid tone") % tone)
gjs = self.connection.get_jingle_session
gjs = self.connection.get_module('Jingle').get_jingle_session
session = gjs(self.full_jid, self.audio_sid)
content = session.get_content("audio")
content.batch_dtmf(sequence)
......
......@@ -32,7 +32,6 @@ import nbxmpp
from gajim.common import app
from gajim.common import helpers
from gajim.common import jingle_xtls
from gajim.common.jingle import ConnectionJingle
from gajim.common.protocol.bytestream import ConnectionSocks5Bytestream
from gajim.common.connection_handlers_events import StreamReceivedEvent
from gajim.common.connection_handlers_events import PresenceReceivedEvent
......@@ -183,11 +182,9 @@ class ConnectionHandlersBase:
return sess
class ConnectionHandlers(ConnectionSocks5Bytestream,
ConnectionHandlersBase,
ConnectionJingle):
ConnectionHandlersBase):
def __init__(self):
ConnectionSocks5Bytestream.__init__(self)
ConnectionJingle.__init__(self)
ConnectionHandlersBase.__init__(self)
app.nec.register_incoming_event(PresenceReceivedEvent)
......@@ -221,9 +218,6 @@ class ConnectionHandlers(ConnectionSocks5Bytestream,
nbxmpp.NS_BYTESTREAM)
con.RegisterHandler('iq', self._bytestreamErrorCB, 'error',
nbxmpp.NS_BYTESTREAM)
con.RegisterHandler('iq', self._JingleCB, 'result')
con.RegisterHandler('iq', self._JingleCB, 'error')
con.RegisterHandler('iq', self._JingleCB, 'set', nbxmpp.NS_JINGLE)
con.RegisterHandler('iq', self._ResultCB, 'result')
con.RegisterHandler('unknown', self._StreamCB,
nbxmpp.NS_XMPP_STREAMS, xmlns=nbxmpp.NS_STREAMS)
......
......@@ -209,7 +209,7 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent):
n = file_tag.getTag('name')
n = n.getData() if n else None
pjid = app.get_jid_without_resource(self.fjid)
file_info = self.conn.get_file_info(
file_info = self.conn.get_module('Jingle').get_file_info(
pjid, hash_=h, name=n, account=self.conn.name)
self.file_props.file_name = file_info['file-name']
self.file_props.sender = self.conn._ft_get_our_jid()
......
......@@ -219,7 +219,7 @@ class JingleContent:
'date' : self.file_props.date,
'peerjid' : pjid
}
self.session.connection.set_file_info(file_info)
self.session.connection.get_module('Jingle').set_file_info(file_info)
desc = file_tag.setTag('desc')
if self.file_props.desc:
desc.setData(self.file_props.desc)
......
......@@ -161,7 +161,7 @@ class JingleFileTransfer(JingleContent):
'date' : self.file_props.date,
'peerjid' : pjid
}
self.session.connection.set_file_info(file_info)
self.session.connection.get_module('Jingle').set_file_info(file_info)
def _compute_hash(self):
# Caculates the hash and returns a xep-300 hash stanza
......
......@@ -538,7 +538,7 @@ class JingleSession:
# If we are not receiving a file
# Check if there's already a session with this user:
if contents[0].media != 'file':
for session in self.connection.iter_jingle_sessions(self.peerjid):
for session in self.connection.get_module('Jingle').iter_jingle_sessions(self.peerjid):
if session is not self:
reason = nbxmpp.Node('reason')
alternative_session = reason.setTag('alternative-session')
......@@ -557,8 +557,8 @@ class JingleSession:
n = request.getTag('file').getTag('name')
n = n.getData() if n else None
pjid = app.get_jid_without_resource(self.peerjid)
file_info = self.connection.get_file_info(pjid, hash_data, n,
self.connection.name)
file_info = self.connection.get_module('Jingle').get_file_info(
pjid, hash_data, n, self.connection.name)
if not file_info:
log.warning('The peer %s is requesting a ' \
'file that we dont have or ' \
......@@ -598,7 +598,7 @@ class JingleSession:
cn.on_stanza(stanza, content, error, action)
def __on_session_terminate(self, stanza, jingle, error, action):
self.connection.delete_jingle_session(self.sid)
self.connection.get_module('Jingle').delete_jingle_session(self.sid)
reason, text = self.__reason_from_stanza(jingle)
if reason not in ('success', 'cancel', 'decline'):
self.__dispatch_error(reason, text)
......@@ -776,7 +776,7 @@ class JingleSession:
text = '%s (%s)' % (reason, text)
else:
text = reason
self.connection.delete_jingle_session(self.sid)
self.connection.get_module('Jingle').delete_jingle_session(self.sid)
app.nec.push_incoming_event(JingleDisconnectedReceivedEvent(None,
conn=self.connection,
jingle_session=self,
......
......@@ -326,8 +326,8 @@ class JingleTransportSocks5(JingleTransport):
self._add_candidates(proxy_cand)
def get_content(self):
sesn = self.connection.get_jingle_session(self.ourjid,
self.file_props.sid)
sesn = self.connection.get_module('Jingle').get_jingle_session(
self.ourjid, self.file_props.sid)
for content in sesn.contents.values():
if content.transport == self:
return content
......@@ -337,8 +337,8 @@ class JingleTransportSocks5(JingleTransport):
# send activate request to proxy, send activated confirmation to peer
if not self.connection:
return
sesn = self.connection.get_jingle_session(self.ourjid,
self.file_props.sid)
sesn = self.connection.get_module('Jingle').get_jingle_session(
self.ourjid, self.file_props.sid)
if sesn is None:
return
......
......@@ -75,6 +75,7 @@ MODULES = [
'vcard_temp',
'announce',
'ibb',
'jingle',
]
_imported_modules = [] # type: List[tuple]
......
......@@ -174,7 +174,7 @@ class IBB(BaseModule):
peerjid = file_props.receiver
else:
peerjid = file_props.sender
session = self._con.get_jingle_session(
session = self._con.get_module('Jingle').get_jingle_session(
peerjid, file_props.sid, 'file')
# According to the xep, the initiator also cancels
# the jingle session if there are no more files to send using IBB
......
......@@ -31,24 +31,40 @@ Handles the jingle signalling protocol
import logging
import nbxmpp
from nbxmpp.structs import StanzaHandler
from gajim.common import helpers
from gajim.common import app
from gajim.common.modules.base import BaseModule
from gajim.common.jingle_session import JingleSession, JingleStates
from gajim.common.jingle_session import JingleSession
from gajim.common.jingle_session import JingleStates
from gajim.common.jingle_ft import JingleFileTransfer
from gajim.common.jingle_transport import JingleTransportSocks5, JingleTransportIBB
from gajim.common.jingle_transport import JingleTransportSocks5
from gajim.common.jingle_transport import JingleTransportIBB
if app.is_installed('FARSTREAM'):
from gajim.common.jingle_rtp import JingleAudio, JingleVideo
logger = logging.getLogger('gajim.c.jingle')
logger = logging.getLogger('gajim.c.m.jingle')
class Jingle(BaseModule):
def __init__(self, con):
BaseModule.__init__(self, con)
class ConnectionJingle:
"""
This object depends on that it is a part of Connection class.
"""
self.handlers = [
StanzaHandler(name='iq',
typ='result',
callback=self._on_jingle_iq),
StanzaHandler(name='iq',
typ='error',
callback=self._on_jingle_iq),
StanzaHandler(name='iq',
typ='set',
ns=nbxmpp.NS_JINGLE,
callback=self._on_jingle_iq),
]
def __init__(self):
# dictionary: sessionid => JingleSession object
self._sessions = {}
......@@ -68,7 +84,7 @@ class ConnectionJingle:
self._sessions[sid].callbacks = []
del self._sessions[sid]
def _JingleCB(self, con, stanza):
def _on_jingle_iq(self, con, stanza):
"""
The jingle stanza dispatcher
......@@ -103,7 +119,7 @@ class ConnectionJingle:
# do we need to create a new jingle object
if sid not in self._sessions:
#TODO: tie-breaking and other things...
newjingle = JingleSession(con=self, weinitiate=False, jid=jid,
newjingle = JingleSession(self._con, weinitiate=False, jid=jid,
iq_id=id_, sid=sid)
self._sessions[sid] = newjingle
# we already have such session in dispatcher...
......@@ -122,7 +138,7 @@ class ConnectionJingle:
if jingle:
jingle.add_content('voice', JingleAudio(jingle))
else:
jingle = JingleSession(self, weinitiate=True, jid=jid)
jingle = JingleSession(self._con, weinitiate=True, jid=jid)
self._sessions[jingle.sid] = jingle
jingle.add_content('voice', JingleAudio(jingle))
jingle.start_session()
......@@ -136,7 +152,7 @@ class ConnectionJingle:
jingle.add_content('video', JingleVideo(jingle, in_xid=in_xid,
out_xid=out_xid))
else:
jingle = JingleSession(self, weinitiate=True, jid=jid)
jingle = JingleSession(self._con, weinitiate=True, jid=jid)
self._sessions[jingle.sid] = jingle
jingle.add_content('video', JingleVideo(jingle, in_xid=in_xid,
out_xid=out_xid))
......@@ -145,16 +161,16 @@ class ConnectionJingle:
def start_file_transfer(self, jid, file_props, request=False):
logger.info("start file transfer with file: %s", file_props)
contact = app.contacts.get_contact_with_highest_priority(self.name,
app.get_jid_without_resource(jid))
if app.contacts.is_gc_contact(self.name, jid):
contact = app.contacts.get_contact_with_highest_priority(
self._account, app.get_jid_without_resource(jid))
if app.contacts.is_gc_contact(self._account, jid):
gcc = jid.split('/')
if len(gcc) == 2:
contact = app.contacts.get_gc_contact(self.name, gcc[0], gcc[1])
contact = app.contacts.get_gc_contact(self._account, gcc[0], gcc[1])
if contact is None:
return
use_security = contact.supports(nbxmpp.NS_JINGLE_XTLS)
jingle = JingleSession(self, weinitiate=True, jid=jid, werequest=request)
jingle = JingleSession(self._con, weinitiate=True, jid=jid, werequest=request)
# this is a file transfer
jingle.session_type_ft = True
self._sessions[jingle.sid] = jingle
......@@ -233,3 +249,7 @@ class ConnectionJingle:
if session.peerjid == jid and session.get_content(media):
return session
return None
def get_instance(*args, **kwargs):
return Jingle(*args, **kwargs), 'Jingle'
......@@ -111,8 +111,8 @@ class ConnectionBytestream:
# file transfer initiated by a jingle session
log.info("send_file_approval: jingle session accept")
session = self.get_jingle_session(file_props.sender,
file_props.sid)
session = self.get_module('Jingle').get_jingle_session(
file_props.sender, file_props.sid)
if not session:
return
content = None
......
......@@ -333,10 +333,6 @@ class P2PClient(IdleObject):
nbxmpp.NS_BYTESTREAM)
self.RegisterHandler('iq', self._caller._bytestreamErrorCB, 'error',
nbxmpp.NS_BYTESTREAM)
self.RegisterHandler('iq', self._caller._JingleCB, 'result')
self.RegisterHandler('iq', self._caller._JingleCB, 'error')
self.RegisterHandler('iq', self._caller._JingleCB, 'set',
nbxmpp.NS_JINGLE)
self._caller._register_new_handlers(self)
......
......@@ -57,11 +57,9 @@ class DecryptedMessageReceivedEvent(NetworkIncomingEvent):
class ConnectionHandlersZeroconf(ConnectionSocks5BytestreamZeroconf,
connection_handlers.ConnectionHandlersBase,
connection_handlers.ConnectionJingle):
connection_handlers.ConnectionHandlersBase):
def __init__(self):
ConnectionSocks5BytestreamZeroconf.__init__(self)
connection_handlers.ConnectionJingle.__init__(self)
connection_handlers.ConnectionHandlersBase.__init__(self)
def _messageCB(self, con, stanza, properties):
......
......@@ -1344,8 +1344,8 @@ class VoIPCallReceivedDialog:
def on_voip_call_received_messagedialog_response(self, dialog, response):
# we've got response from user, either stop connecting or accept the call
session = app.connections[self.account].get_jingle_session(self.fjid,
self.sid)
session = app.connections[self.account].get_module('Jingle').get_jingle_session(
self.fjid, self.sid)
if not session:
dialog.destroy()
return
......
......@@ -310,9 +310,8 @@ class FileTransfersWindow:
new_file_props.date = file_props.date
new_file_props.hash_ = file_props.hash_
new_file_props.type_ = 'r'
tsid = app.connections[account].start_file_transfer(fjid,
new_file_props,
True)
tsid = app.connections[account].get_module('Jingle').start_file_transfer(
fjid, new_file_props, True)
new_file_props.transport_sid = tsid
self.add_transfer(account, contact, new_file_props)
......@@ -352,8 +351,8 @@ class FileTransfersWindow:
if file_props is None:
return False
app.connections[account].start_file_transfer(contact.get_full_jid(),
file_props)
app.connections[account].get_module('Jingle').start_file_transfer(
contact.get_full_jid(), file_props)
self.add_transfer(account, contact, file_props)
return True
......
......@@ -742,8 +742,8 @@ class Interface:
file_props.sid, file_props.received_len)
def __compare_hashes(self, account, file_props):
session = app.connections[account].get_jingle_session(jid=None,
sid=file_props.sid)
session = app.connections[account].get_module('Jingle').get_jingle_session(
jid=None, sid=file_props.sid)
ft_win = self.instances['file_transfers']
h = Hashes2()
try:
......@@ -794,8 +794,8 @@ class Interface:
self.popup_ft_result(account, jid, file_props)
if file_props.error == 0:
ft.set_status(file_props, 'ok')
session = app.connections[account].get_jingle_session(jid=None,
sid=file_props.sid)
session = app.connections[account].get_module('Jingle').get_jingle_session(
jid=None, sid=file_props.sid)
# End jingle session
# TODO: only if there are no other parallel downloads in this session
if session:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment