Commit 24852277 authored by Philipp Hörist's avatar Philipp Hörist

Move ConnectionSocks5Bytestream code to module

parent 275e719d
Pipeline #3518 passed with stages
in 2 minutes and 59 seconds
......@@ -1470,7 +1470,7 @@ class ChatControl(ChatControlBase):
app.events.remove_events(self.account, self.contact.jid, event=ev)
def _on_cancel_file_request(self, widget, file_props):
app.connections[self.account].send_file_rejection(file_props)
app.connections[self.account].get_module('Bytestream').send_file_rejection(file_props)
ev = self._get_file_props_event(file_props, 'file-request')
if ev:
app.events.remove_events(self.account, self.contact.jid, event=ev)
......
......@@ -588,7 +588,7 @@ class Connection(CommonConnection, ConnectionHandlers):
app.proxy65_manager.disconnect(self.connection)
self.terminate_sessions()
self.remove_all_transfers()
self.get_module('Bytestream').remove_all_transfers()
self._unregister_new_handlers(self.connection)
self.connection = None
......@@ -1348,7 +1348,7 @@ class Connection(CommonConnection, ConnectionHandlers):
# If we are already connected, and privacy rules are supported, send
# offline presence first as it's required by XEP-0126
if self.connected > 1 and self.get_module('PrivacyLists').supported:
self.remove_all_transfers()
self.get_module('Bytestream').remove_all_transfers()
self.get_module('Presence').send_presence(
typ='unavailable',
status=msg,
......
......@@ -30,9 +30,6 @@ import operator
import nbxmpp
from gajim.common import app
from gajim.common import helpers
from gajim.common import jingle_xtls
from gajim.common.protocol.bytestream import ConnectionSocks5Bytestream
from gajim.common.connection_handlers_events import StreamReceivedEvent
from gajim.common.connection_handlers_events import PresenceReceivedEvent
from gajim.common.connection_handlers_events import StreamConflictReceivedEvent
......@@ -181,28 +178,14 @@ class ConnectionHandlersBase:
return sess
class ConnectionHandlers(ConnectionSocks5Bytestream,
ConnectionHandlersBase):
class ConnectionHandlers(ConnectionHandlersBase):
def __init__(self):
ConnectionSocks5Bytestream.__init__(self)
ConnectionHandlersBase.__init__(self)
app.nec.register_incoming_event(PresenceReceivedEvent)
app.nec.register_incoming_event(StreamConflictReceivedEvent)
app.nec.register_incoming_event(NotificationEvent)
def _PubkeyGetCB(self, con, iq_obj):
log.info('PubkeyGetCB')
jid_from = helpers.get_full_jid_from_iq(iq_obj)
sid = iq_obj.getAttr('id')
jingle_xtls.send_cert(con, jid_from, sid)
raise nbxmpp.NodeProcessed
def _PubkeyResultCB(self, con, iq_obj):
log.info('PubkeyResultCB')
jid_from = helpers.get_full_jid_from_iq(iq_obj)
jingle_xtls.handle_new_cert(con, iq_obj, jid_from)
def _StreamCB(self, con, obj):
log.debug('StreamCB')
app.nec.push_incoming_event(StreamReceivedEvent(None,
......@@ -212,16 +195,5 @@ class ConnectionHandlers(ConnectionSocks5Bytestream,
# try to find another way to register handlers in each class
# that defines handlers
con.RegisterHandler('iq', self._bytestreamSetCB, 'set',
nbxmpp.NS_BYTESTREAM)
con.RegisterHandler('iq', self._bytestreamResultCB, 'result',
nbxmpp.NS_BYTESTREAM)
con.RegisterHandler('iq', self._bytestreamErrorCB, 'error',
nbxmpp.NS_BYTESTREAM)
con.RegisterHandler('iq', self._ResultCB, 'result')
con.RegisterHandler('unknown', self._StreamCB,
nbxmpp.NS_XMPP_STREAMS, xmlns=nbxmpp.NS_STREAMS)
con.RegisterHandler('iq', self._PubkeyGetCB, 'get',
nbxmpp.NS_PUBKEY_PUBKEY)
con.RegisterHandler('iq', self._PubkeyResultCB, 'result',
nbxmpp.NS_PUBKEY_PUBKEY)
......@@ -170,7 +170,7 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent):
def generate(self):
self.id_ = self.stanza.getID()
self.fjid = self.conn._ft_get_from(self.stanza)
self.fjid = self.conn.get_module('Bytestream')._ft_get_from(self.stanza)
self.jid = app.get_jid_without_resource(self.fjid)
if self.jingle_content:
secu = self.jingle_content.getTag('security')
......@@ -201,7 +201,7 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent):
if self.jingle_content.getAttr('creator') == 'initiator':
file_tag = desc.getTag('file')
self.file_props.sender = self.fjid
self.file_props.receiver = self.conn._ft_get_our_jid()
self.file_props.receiver = self.conn.get_module('Bytestream')._ft_get_our_jid()
else:
file_tag = desc.getTag('file')
h = file_tag.getTag('hash')
......@@ -212,7 +212,7 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent):
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()
self.file_props.sender = self.conn.get_module('Bytestream')._ft_get_our_jid()
self.file_props.receiver = self.fjid
self.file_props.type_ = 's'
for child in file_tag.getChildren():
......@@ -236,7 +236,7 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent):
self.file_props.transport_sid = self.file_props.sid
profile = si.getAttr('profile')
if profile != nbxmpp.NS_FILE:
self.conn.send_file_rejection(self.file_props, code='400',
self.conn.get_module('Bytestream').send_file_rejection(self.file_props, code='400',
typ='profile')
raise nbxmpp.NodeProcessed
feature_tag = si.getTag('feature', namespace=nbxmpp.NS_FEATURE)
......@@ -254,7 +254,7 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent):
nbxmpp.NS_IBB in values:
break
else:
self.conn.send_file_rejection(self.file_props, code='400',
self.conn.get_module('Bytestream').send_file_rejection(self.file_props, code='400',
typ='stream')
raise nbxmpp.NodeProcessed
file_tag = si.getTag('file')
......@@ -269,7 +269,7 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent):
if mime_type is not None:
self.file_props.mime_type = mime_type
self.file_props.sender = self.fjid
self.file_props.receiver = self.conn._ft_get_our_jid()
self.file_props.receiver = self.conn.get_module('Bytestream')._ft_get_our_jid()
self.file_props.request_id = self.id_
file_desc_tag = file_tag.getTag('desc')
if file_desc_tag is not None:
......
......@@ -305,7 +305,7 @@ class JingleTransportSocks5(JingleTransport):
priority = (2**16) * type_preference
proxy_cand = []
socks5conn = self.connection
proxyhosts = socks5conn._get_file_transfer_proxies_from_config(self.file_props)
proxyhosts = socks5conn.get_module('Bytestream')._get_file_transfer_proxies_from_config(self.file_props)
if proxyhosts:
self.file_props.proxyhosts = proxyhosts
......
......@@ -76,6 +76,7 @@ MODULES = [
'announce',
'ibb',
'jingle',
'bytestream',
]
_imported_modules = [] # type: List[tuple]
......
......@@ -162,7 +162,7 @@ class Discovery(BaseModule):
try:
self._con.get_module('MUC').pass_disco(from_, *args)
self._con.get_module('HTTPUpload').pass_disco(from_, *args)
self._con.pass_bytestream_disco(from_, *args)
self._con.get_module('Bytestream').pass_disco(from_, *args)
except nbxmpp.NodeProcessed:
pass
......
......@@ -53,7 +53,7 @@ class Iq(BaseModule):
jid=properties.jid.getBare(),
file_props=file_props,
error_msg=properties.error.message))
self._con.disconnect_transfer(file_props)
self._con.get_module('Bytestream').disconnect_transfer(file_props)
raise nbxmpp.NodeProcessed
if properties.error.type == Error.ITEM_NOT_FOUND:
......@@ -65,7 +65,7 @@ class Iq(BaseModule):
account=self._account,
jid=str(properties.jid),
file_props=file_props))
self._con.disconnect_transfer(file_props)
self._con.get_module('Bytestream').disconnect_transfer(file_props)
raise nbxmpp.NodeProcessed
app.nec.push_incoming_event(
......
......@@ -35,6 +35,7 @@ from nbxmpp.structs import StanzaHandler
from gajim.common import helpers
from gajim.common import app
from gajim.common import jingle_xtls
from gajim.common.modules.base import BaseModule
from gajim.common.jingle_session import JingleSession
......@@ -63,6 +64,14 @@ class Jingle(BaseModule):
typ='set',
ns=nbxmpp.NS_JINGLE,
callback=self._on_jingle_iq),
StanzaHandler(name='iq',
typ='get',
ns=nbxmpp.NS_PUBKEY_PUBKEY,
callback=self._on_pubkey_request),
StanzaHandler(name='iq',
typ='result',
ns=nbxmpp.NS_PUBKEY_PUBKEY,
callback=self._pubkey_result_received),
]
# dictionary: sessionid => JingleSession object
......@@ -84,7 +93,19 @@ class Jingle(BaseModule):
self._sessions[sid].callbacks = []
del self._sessions[sid]
def _on_jingle_iq(self, con, stanza):
def _on_pubkey_request(self, con, stanza, _properties):
jid_from = helpers.get_full_jid_from_iq(stanza)
self._log.info('Pubkey request from %s', jid_from)
sid = stanza.getAttr('id')
jingle_xtls.send_cert(con, jid_from, sid)
raise nbxmpp.NodeProcessed
def _pubkey_result_received(self, con, stanza, _properties):
jid_from = helpers.get_full_jid_from_iq(stanza)
self._log.info('Pubkey result from %s', jid_from)
jingle_xtls.handle_new_cert(con, stanza, jid_from)
def _on_jingle_iq(self, con, stanza, properties):
"""
The jingle stanza dispatcher
......
......@@ -201,7 +201,7 @@ class Presence(BaseModule):
if properties.type.is_unavailable:
# TODO: This causes problems when another
# resource signs off!
self._con.stop_all_active_file_transfers(contact)
self._con.get_module('Bytestream').stop_all_active_file_transfers(contact)
self._log_presence(properties)
@staticmethod
......
"""
Implementations of specific XMPP protocols and XEPs
"""
......@@ -327,12 +327,6 @@ class P2PClient(IdleObject):
self.RegisterHandler(*StanzaHandler(name='message',
callback=self._caller._messageCB))
self.RegisterHandler('iq', self._caller._bytestreamSetCB, 'set',
nbxmpp.NS_BYTESTREAM)
self.RegisterHandler('iq', self._caller._bytestreamResultCB, 'result',
nbxmpp.NS_BYTESTREAM)
self.RegisterHandler('iq', self._caller._bytestreamErrorCB, 'error',
nbxmpp.NS_BYTESTREAM)
self._caller._register_new_handlers(self)
......
......@@ -26,7 +26,6 @@ import nbxmpp
from gajim.common import app
from gajim.common.protocol.bytestream import ConnectionSocks5BytestreamZeroconf
from gajim.common import connection_handlers
from gajim.common.i18n import _
from gajim.common.helpers import AdditionalDataDict
......@@ -56,10 +55,8 @@ class DecryptedMessageReceivedEvent(NetworkIncomingEvent):
class ConnectionHandlersZeroconf(ConnectionSocks5BytestreamZeroconf,
connection_handlers.ConnectionHandlersBase):
class ConnectionHandlersZeroconf(connection_handlers.ConnectionHandlersBase):
def __init__(self):
ConnectionSocks5BytestreamZeroconf.__init__(self)
connection_handlers.ConnectionHandlersBase.__init__(self)
def _messageCB(self, con, stanza, properties):
......
......@@ -233,7 +233,7 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
if event.ptype == 'unavailable':
# TODO: This causes problems when another
# resource signs off!
self.stop_all_active_file_transfers(contact)
self.get_module('Bytestream').stop_all_active_file_transfers(contact)
def _on_name_conflictCB(self, alt_name):
self.disconnect()
......
......@@ -36,7 +36,7 @@ from gajim.common import app
from gajim.common import helpers
from gajim.common.i18n import _
from gajim.common.file_props import FilesProp
from gajim.common.protocol.bytestream import (is_transfer_active, is_transfer_paused,
from gajim.common.modules.bytestream import (is_transfer_active, is_transfer_paused,
is_transfer_stopped)
from gajim.gtk.dialogs import HigDialog
......@@ -363,7 +363,7 @@ class FileTransfersWindow:
file_props.file_name = file_path
file_props.type_ = 'r'
self.add_transfer(account, contact, file_props)
app.connections[account].send_file_approval(file_props)
app.connections[account].get_module('Bytestream').send_file_approval(file_props)
def on_file_request_accepted(self, account, contact, file_props):
def on_ok(account, contact, file_props, file_path):
......@@ -410,7 +410,7 @@ class FileTransfersWindow:
con = app.connections[account]
accept_cb = partial(on_ok, account, contact, file_props)
cancel_cb = partial(con.send_file_rejection, file_props)
cancel_cb = partial(con.get_module('Bytestream').send_file_rejection, file_props)
FileSaveDialog(accept_cb,
cancel_cb,
path=app.config.get('last_save_dir'),
......@@ -439,7 +439,7 @@ class FileTransfersWindow:
self.on_file_request_accepted(account, contact, file_props)
def on_response_cancel(account, file_props):
app.connections[account].send_file_rejection(file_props)
app.connections[account].get_module('Bytestream').send_file_rejection(file_props)
dialog = NonModalConfirmationDialog(prim_text, sec_text,
on_response_ok=(on_response_ok, account, contact, file_props),
......@@ -552,7 +552,7 @@ class FileTransfersWindow:
account = file_props.tt_account
if account in app.connections:
# there is a connection to the account
app.connections[account].remove_transfer(file_props)
app.connections[account].get_module('Bytestream').remove_transfer(file_props)
if file_props.type_ == 'r': # we receive a file
other = file_props.sender
else: # we send a file
......@@ -882,7 +882,7 @@ class FileTransfersWindow:
# Check if we are in a IBB transfer
if file_props.direction:
con.get_module('IBB').send_close(file_props)
con.disconnect_transfer(file_props)
con.get_module('Bytestream').disconnect_transfer(file_props)
self.set_status(file_props, 'stop')
def on_notify_ft_complete_checkbox_toggled(self, widget):
......
......@@ -2435,7 +2435,7 @@ class RosterWindow:
on_continue3(message, pep_dict)
return
# check if there is an active file transfer
from gajim.common.protocol.bytestream import is_transfer_active
from gajim.common.modules.bytestream import is_transfer_active
files_props = app.interface.instances['file_transfers'].\
files_props
transfer_active = False
......
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