Register handlers in CommonConnection class
This commit is contained in:
parent
1399c41d59
commit
f3d5babc65
|
@ -101,6 +101,9 @@ class CommonConnection:
|
||||||
self.time_to_reconnect = None
|
self.time_to_reconnect = None
|
||||||
self._reconnect_timer_source = None
|
self._reconnect_timer_source = None
|
||||||
|
|
||||||
|
# If handlers have been registered
|
||||||
|
self.handlers_registered = False
|
||||||
|
|
||||||
self.pep = {}
|
self.pep = {}
|
||||||
# Do we continue connection when we get roster (send presence,get vcard..)
|
# Do we continue connection when we get roster (send presence,get vcard..)
|
||||||
self.continue_connect_info = None
|
self.continue_connect_info = None
|
||||||
|
@ -124,6 +127,24 @@ class CommonConnection:
|
||||||
|
|
||||||
self.get_config_values_or_default()
|
self.get_config_values_or_default()
|
||||||
|
|
||||||
|
def _register_new_handlers(self, con):
|
||||||
|
for handler in modules.get_handlers(self):
|
||||||
|
if len(handler) == 5:
|
||||||
|
name, func, typ, ns, priority = handler
|
||||||
|
con.RegisterHandler(name, func, typ, ns, priority=priority)
|
||||||
|
else:
|
||||||
|
con.RegisterHandler(*handler)
|
||||||
|
self.handlers_registered = True
|
||||||
|
|
||||||
|
def _unregister_new_handlers(self, con):
|
||||||
|
if not con:
|
||||||
|
return
|
||||||
|
for handler in modules.get_handlers(self):
|
||||||
|
if len(handler) > 4:
|
||||||
|
handler = handler[:4]
|
||||||
|
con.UnregisterHandler(*handler)
|
||||||
|
self.handlers_registered = False
|
||||||
|
|
||||||
def _compute_resource(self):
|
def _compute_resource(self):
|
||||||
resource = app.config.get_per('accounts', self.name, 'resource')
|
resource = app.config.get_per('accounts', self.name, 'resource')
|
||||||
# All valid resource substitution strings should be added to this hash.
|
# All valid resource substitution strings should be added to this hash.
|
||||||
|
@ -484,6 +505,7 @@ class CommonConnection:
|
||||||
self._change_from_invisible()
|
self._change_from_invisible()
|
||||||
self._update_status(show, msg, idle_time=idle_time)
|
self._update_status(show, msg, idle_time=idle_time)
|
||||||
|
|
||||||
|
|
||||||
class Connection(CommonConnection, ConnectionHandlers):
|
class Connection(CommonConnection, ConnectionHandlers):
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
CommonConnection.__init__(self, name)
|
CommonConnection.__init__(self, name)
|
||||||
|
@ -658,7 +680,7 @@ class Connection(CommonConnection, ConnectionHandlers):
|
||||||
app.proxy65_manager.disconnect(self.connection)
|
app.proxy65_manager.disconnect(self.connection)
|
||||||
self.terminate_sessions()
|
self.terminate_sessions()
|
||||||
self.remove_all_transfers()
|
self.remove_all_transfers()
|
||||||
ConnectionHandlers._unregister_handlers(self)
|
self._unregister_new_handlers(self.connection)
|
||||||
self.connection = None
|
self.connection = None
|
||||||
|
|
||||||
def _set_reconnect_timer(self):
|
def _set_reconnect_timer(self):
|
||||||
|
@ -1331,6 +1353,7 @@ class Connection(CommonConnection, ConnectionHandlers):
|
||||||
conn=self,
|
conn=self,
|
||||||
connection_type=con_type))
|
connection_type=con_type))
|
||||||
ConnectionHandlers._register_handlers(self, con, con_type)
|
ConnectionHandlers._register_handlers(self, con, con_type)
|
||||||
|
self._register_new_handlers(con)
|
||||||
|
|
||||||
def _on_auth_successful(self):
|
def _on_auth_successful(self):
|
||||||
if self._unregister_account:
|
if self._unregister_account:
|
||||||
|
|
|
@ -33,7 +33,6 @@ from gajim.common import app
|
||||||
from gajim.common import ged
|
from gajim.common import ged
|
||||||
from gajim.common import helpers
|
from gajim.common import helpers
|
||||||
from gajim.common import jingle_xtls
|
from gajim.common import jingle_xtls
|
||||||
from gajim.common import modules
|
|
||||||
from gajim.common.nec import NetworkEvent
|
from gajim.common.nec import NetworkEvent
|
||||||
from gajim.common.caps_cache import muc_caps_cache
|
from gajim.common.caps_cache import muc_caps_cache
|
||||||
from gajim.common.connection_handlers_events import *
|
from gajim.common.connection_handlers_events import *
|
||||||
|
@ -263,9 +262,6 @@ class ConnectionHandlers(ConnectionSocks5Bytestream,
|
||||||
|
|
||||||
self.continue_connect_info = None
|
self.continue_connect_info = None
|
||||||
|
|
||||||
# If handlers have been registered
|
|
||||||
self.handlers_registered = False
|
|
||||||
|
|
||||||
app.nec.register_incoming_event(StreamConflictReceivedEvent)
|
app.nec.register_incoming_event(StreamConflictReceivedEvent)
|
||||||
app.nec.register_incoming_event(NotificationEvent)
|
app.nec.register_incoming_event(NotificationEvent)
|
||||||
|
|
||||||
|
@ -409,20 +405,3 @@ class ConnectionHandlers(ConnectionSocks5Bytestream,
|
||||||
nbxmpp.NS_PUBKEY_PUBKEY)
|
nbxmpp.NS_PUBKEY_PUBKEY)
|
||||||
con.RegisterHandler('iq', self._PubkeyResultCB, 'result',
|
con.RegisterHandler('iq', self._PubkeyResultCB, 'result',
|
||||||
nbxmpp.NS_PUBKEY_PUBKEY)
|
nbxmpp.NS_PUBKEY_PUBKEY)
|
||||||
|
|
||||||
for handler in modules.get_handlers(self):
|
|
||||||
if len(handler) == 5:
|
|
||||||
name, func, typ, ns, priority = handler
|
|
||||||
con.RegisterHandler(name, func, typ, ns, priority=priority)
|
|
||||||
else:
|
|
||||||
con.RegisterHandler(*handler)
|
|
||||||
self.handlers_registered = True
|
|
||||||
|
|
||||||
def _unregister_handlers(self):
|
|
||||||
if not self.connection:
|
|
||||||
return
|
|
||||||
for handler in modules.get_handlers(self):
|
|
||||||
if len(handler) > 4:
|
|
||||||
handler = handler[:4]
|
|
||||||
self.connection.UnregisterHandler(*handler)
|
|
||||||
self.handlers_registered = False
|
|
||||||
|
|
|
@ -288,6 +288,7 @@ class P2PClient(IdleObject):
|
||||||
del self.conn_holder.ids_of_awaiting_messages[self.fd]
|
del self.conn_holder.ids_of_awaiting_messages[self.fd]
|
||||||
self.conn_holder.remove_connection(self.sock_hash)
|
self.conn_holder.remove_connection(self.sock_hash)
|
||||||
if 'Dispatcher' in self.__dict__:
|
if 'Dispatcher' in self.__dict__:
|
||||||
|
self._caller._unregister_new_handlers(self)
|
||||||
self.Dispatcher.PlugOut()
|
self.Dispatcher.PlugOut()
|
||||||
if 'P2PConnection' in self.__dict__:
|
if 'P2PConnection' in self.__dict__:
|
||||||
self.P2PConnection.PlugOut()
|
self.P2PConnection.PlugOut()
|
||||||
|
@ -338,6 +339,8 @@ class P2PClient(IdleObject):
|
||||||
self.RegisterHandler('iq', self._caller._JingleCB, 'error')
|
self.RegisterHandler('iq', self._caller._JingleCB, 'error')
|
||||||
self.RegisterHandler('iq', self._caller._JingleCB, 'set',
|
self.RegisterHandler('iq', self._caller._JingleCB, 'set',
|
||||||
nbxmpp.NS_JINGLE)
|
nbxmpp.NS_JINGLE)
|
||||||
|
self._caller._register_new_handlers(self)
|
||||||
|
|
||||||
|
|
||||||
class P2PConnection(IdleObject, PlugIn):
|
class P2PConnection(IdleObject, PlugIn):
|
||||||
def __init__(self, sock_hash, _sock, addresses=None, caller=None,
|
def __init__(self, sock_hash, _sock, addresses=None, caller=None,
|
||||||
|
|
Loading…
Reference in New Issue