mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-27 19:19:54 +00:00
Can now pass a name to add_handler so that the handler can be reliably removed later.
Updated uses of add_handler to include a name.
This commit is contained in:
parent
fec8578cf6
commit
b5a14a0190
8 changed files with 24 additions and 19 deletions
|
@ -175,7 +175,7 @@ class ClientXMPP(basexmpp, XMLStream):
|
||||||
|
|
||||||
def handler_starttls(self, xml):
|
def handler_starttls(self, xml):
|
||||||
if not self.authenticated and self.ssl_support:
|
if not self.authenticated and self.ssl_support:
|
||||||
self.add_handler("<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls' />", self.handler_tls_start, instream=True)
|
self.add_handler("<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls' />", self.handler_tls_start, name='TLS Proceed', instream=True)
|
||||||
self.sendXML(xml)
|
self.sendXML(xml)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
@ -191,8 +191,8 @@ class ClientXMPP(basexmpp, XMLStream):
|
||||||
if '{urn:ietf:params:xml:ns:xmpp-tls}starttls' in self.features:
|
if '{urn:ietf:params:xml:ns:xmpp-tls}starttls' in self.features:
|
||||||
return False
|
return False
|
||||||
logging.debug("Starting SASL Auth")
|
logging.debug("Starting SASL Auth")
|
||||||
self.add_handler("<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_auth_success, instream=True)
|
self.add_handler("<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_auth_success, name='SASL Sucess', instream=True)
|
||||||
self.add_handler("<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_auth_fail, instream=True)
|
self.add_handler("<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_auth_fail, name='SASL Failure', instream=True)
|
||||||
sasl_mechs = xml.findall('{urn:ietf:params:xml:ns:xmpp-sasl}mechanism')
|
sasl_mechs = xml.findall('{urn:ietf:params:xml:ns:xmpp-sasl}mechanism')
|
||||||
if len(sasl_mechs):
|
if len(sasl_mechs):
|
||||||
for sasl_mech in sasl_mechs:
|
for sasl_mech in sasl_mechs:
|
||||||
|
|
|
@ -118,9 +118,11 @@ class basexmpp(object):
|
||||||
self.id += 1
|
self.id += 1
|
||||||
return self.getId()
|
return self.getId()
|
||||||
|
|
||||||
def add_handler(self, mask, pointer, disposable=False, threaded=False, filter=False, instream=False):
|
def add_handler(self, mask, pointer, name=None, disposable=False, threaded=False, filter=False, instream=False):
|
||||||
#logging.warning("Deprecated add_handler used for %s: %s." % (mask, pointer))
|
# threaded is no longer needed, but leaving it for backwards compatibility for now
|
||||||
self.registerHandler(XMLCallback('add_handler_%s' % self.getNewId(), MatchXMLMask(mask), pointer, threaded, disposable, instream))
|
if name is None:
|
||||||
|
name = 'add_handler_%s' % self.getNewId()
|
||||||
|
self.registerHandler(XMLCallback(name, MatchXMLMask(mask), pointer, threaded, disposable, instream))
|
||||||
|
|
||||||
def getId(self):
|
def getId(self):
|
||||||
return "%x".upper() % self.id
|
return "%x".upper() % self.id
|
||||||
|
|
|
@ -29,7 +29,7 @@ class old_0004(base.base_plugin):
|
||||||
def plugin_init(self):
|
def plugin_init(self):
|
||||||
self.xep = '0004'
|
self.xep = '0004'
|
||||||
self.description = '*Deprecated Data Forms'
|
self.description = '*Deprecated Data Forms'
|
||||||
self.xmpp.add_handler("<message><x xmlns='jabber:x:data' /></message>", self.handler_message_xform)
|
self.xmpp.add_handler("<message><x xmlns='jabber:x:data' /></message>", self.handler_message_xform, name='Old Message Form')
|
||||||
|
|
||||||
def post_init(self):
|
def post_init(self):
|
||||||
base.base_plugin.post_init(self)
|
base.base_plugin.post_init(self)
|
||||||
|
|
|
@ -178,9 +178,12 @@ class xep_0009(base.base_plugin):
|
||||||
def plugin_init(self):
|
def plugin_init(self):
|
||||||
self.xep = '0009'
|
self.xep = '0009'
|
||||||
self.description = 'Jabber-RPC'
|
self.description = 'Jabber-RPC'
|
||||||
self.xmpp.add_handler("<iq type='set'><query xmlns='jabber:iq:rpc' /></iq>", self._callMethod)
|
self.xmpp.add_handler("<iq type='set'><query xmlns='jabber:iq:rpc' /></iq>",
|
||||||
self.xmpp.add_handler("<iq type='result'><query xmlns='jabber:iq:rpc' /></iq>", self._callResult)
|
self._callMethod, name='Jabber RPC Call')
|
||||||
self.xmpp.add_handler("<iq type='error'><query xmlns='jabber:iq:rpc' /></iq>", self._callError)
|
self.xmpp.add_handler("<iq type='result'><query xmlns='jabber:iq:rpc' /></iq>",
|
||||||
|
self._callResult, name='Jabber RPC Result')
|
||||||
|
self.xmpp.add_handler("<iq type='error'><query xmlns='jabber:iq:rpc' /></iq>",
|
||||||
|
self._callError, name='Jabber RPC Error')
|
||||||
self.entries = {}
|
self.entries = {}
|
||||||
self.activeCalls = []
|
self.activeCalls = []
|
||||||
|
|
||||||
|
|
|
@ -32,11 +32,11 @@ class xep_0050(base.base_plugin):
|
||||||
def plugin_init(self):
|
def plugin_init(self):
|
||||||
self.xep = '0050'
|
self.xep = '0050'
|
||||||
self.description = 'Ad-Hoc Commands'
|
self.description = 'Ad-Hoc Commands'
|
||||||
self.xmpp.add_handler("<iq type='set' xmlns='%s'><command xmlns='http://jabber.org/protocol/commands' action='__None__'/></iq>" % self.xmpp.default_ns, self.handler_command)
|
self.xmpp.add_handler("<iq type='set' xmlns='%s'><command xmlns='http://jabber.org/protocol/commands' action='__None__'/></iq>" % self.xmpp.default_ns, self.handler_command, name='Ad-Hoc None')
|
||||||
self.xmpp.add_handler("<iq type='set' xmlns='%s'><command xmlns='http://jabber.org/protocol/commands' action='execute'/></iq>" % self.xmpp.default_ns, self.handler_command)
|
self.xmpp.add_handler("<iq type='set' xmlns='%s'><command xmlns='http://jabber.org/protocol/commands' action='execute'/></iq>" % self.xmpp.default_ns, self.handler_command, name='Ad-Hoc Execute')
|
||||||
self.xmpp.add_handler("<iq type='set' xmlns='%s'><command xmlns='http://jabber.org/protocol/commands' action='next'/></iq>" % self.xmpp.default_ns, self.handler_command_next, threaded=True)
|
self.xmpp.add_handler("<iq type='set' xmlns='%s'><command xmlns='http://jabber.org/protocol/commands' action='next'/></iq>" % self.xmpp.default_ns, self.handler_command_next, name='Ad-Hoc Next', threaded=True)
|
||||||
self.xmpp.add_handler("<iq type='set' xmlns='%s'><command xmlns='http://jabber.org/protocol/commands' action='cancel'/></iq>" % self.xmpp.default_ns, self.handler_command_cancel)
|
self.xmpp.add_handler("<iq type='set' xmlns='%s'><command xmlns='http://jabber.org/protocol/commands' action='cancel'/></iq>" % self.xmpp.default_ns, self.handler_command_cancel, name='Ad-Hoc Cancel')
|
||||||
self.xmpp.add_handler("<iq type='set' xmlns='%s'><command xmlns='http://jabber.org/protocol/commands' action='complete'/></iq>" % self.xmpp.default_ns, self.handler_command_complete)
|
self.xmpp.add_handler("<iq type='set' xmlns='%s'><command xmlns='http://jabber.org/protocol/commands' action='complete'/></iq>" % self.xmpp.default_ns, self.handler_command_complete, name='Ad-Hoc Complete')
|
||||||
self.commands = {}
|
self.commands = {}
|
||||||
self.sessions = {}
|
self.sessions = {}
|
||||||
self.sd = self.xmpp.plugin['xep_0030']
|
self.sd = self.xmpp.plugin['xep_0030']
|
||||||
|
|
|
@ -30,7 +30,7 @@ class xep_0092(base.base_plugin):
|
||||||
self.xep = "0092"
|
self.xep = "0092"
|
||||||
self.name = self.config.get('name', 'SleekXMPP')
|
self.name = self.config.get('name', 'SleekXMPP')
|
||||||
self.version = self.config.get('version', '0.1-dev')
|
self.version = self.config.get('version', '0.1-dev')
|
||||||
self.xmpp.add_handler("<iq type='get' xmlns='%s'><query xmlns='jabber:iq:version' /></iq>" % self.xmpp.default_ns, self.report_version)
|
self.xmpp.add_handler("<iq type='get' xmlns='%s'><query xmlns='jabber:iq:version' /></iq>" % self.xmpp.default_ns, self.report_version, name='Sofware Version')
|
||||||
|
|
||||||
def post_init(self):
|
def post_init(self):
|
||||||
base.base_plugin.post_init(self)
|
base.base_plugin.post_init(self)
|
||||||
|
|
|
@ -29,7 +29,7 @@ class xep_0199(base.base_plugin):
|
||||||
def plugin_init(self):
|
def plugin_init(self):
|
||||||
self.description = "XMPP Ping"
|
self.description = "XMPP Ping"
|
||||||
self.xep = "0199"
|
self.xep = "0199"
|
||||||
self.xmpp.add_handler("<iq type='get' xmlns='%s'><ping xmlns='http://www.xmpp.org/extensions/xep-0199.html#ns'/></iq>" % self.xmpp.default_ns, self.handler_ping)
|
self.xmpp.add_handler("<iq type='get' xmlns='%s'><ping xmlns='http://www.xmpp.org/extensions/xep-0199.html#ns'/></iq>" % self.xmpp.default_ns, self.handler_ping, name='XMPP Ping')
|
||||||
self.running = False
|
self.running = False
|
||||||
#if self.config.get('keepalive', True):
|
#if self.config.get('keepalive', True):
|
||||||
#self.xmpp.add_event_handler('session_start', self.handler_pingserver, threaded=True)
|
#self.xmpp.add_event_handler('session_start', self.handler_pingserver, threaded=True)
|
||||||
|
|
|
@ -34,9 +34,9 @@ class testps(sleekxmpp.ClientXMPP):
|
||||||
self.registerPlugin('xep_0030')
|
self.registerPlugin('xep_0030')
|
||||||
self.registerPlugin('xep_0060')
|
self.registerPlugin('xep_0060')
|
||||||
self.registerPlugin('xep_0092')
|
self.registerPlugin('xep_0092')
|
||||||
self.add_handler("<message xmlns='jabber:client'><event xmlns='http://jabber.org/protocol/pubsub#event' /></message>", self.pubsubEventHandler, threaded=True)
|
self.add_handler("<message xmlns='jabber:client'><event xmlns='http://jabber.org/protocol/pubsub#event' /></message>", self.pubsubEventHandler, name='Pubsub Event', threaded=True)
|
||||||
self.add_event_handler("session_start", self.start, threaded=True)
|
self.add_event_handler("session_start", self.start, threaded=True)
|
||||||
self.add_handler("<iq type='error' />", self.handleError)
|
self.add_handler("<iq type='error' />", self.handleError, name='Iq Error')
|
||||||
self.events = Queue.Queue()
|
self.events = Queue.Queue()
|
||||||
self.default_config = None
|
self.default_config = None
|
||||||
self.ps = self.plugin['xep_0060']
|
self.ps = self.plugin['xep_0060']
|
||||||
|
|
Loading…
Reference in a new issue