def __init__(self, xmpp, thoonk, default_config={}, features=[]): self.xmpp = xmpp self.thoonk = thoonk self.default_config = default_config self.redis = thoonk.redis self.features = self.process_features(features) self.thoonk.register_handler('publish_notice', self.thoonk_publish) self.thoonk.register_handler('retract_notice', self.thoonk_retract) self.thoonk.register_handler('create_notice', self.thoonk_create) self.thoonk.register_handler('delete_notice', self.thoonk_delete) #self.xmpp.registerHandler(Callback('pubsub create', StanzaPath("iq@type=set/pubsub/create"), self.handleCreateNode)) #self.xmpp.registerHandler(Callback('pubsub configure', StanzaPath("iq@type=set/pubsub_owner/configure"), self.handleConfigureNode)) #self.xmpp.registerHandler(Callback('pubsub delete', StanzaPath('iq@type=set/pubsub_owner/delete'), self.handleDeleteNode)) self.xmpp.registerHandler( Callback('pubsub publish', StanzaPath("iq@type=set/pubsub/publish"), self.handlePublish)) #self.xmpp.registerHandler(Callback('pubsub getitems', StanzaPath('iq@type=get/pubsub/items'), self.handleGetItems)) #self.xmpp.registerHandler(Callback('pubsub delete item', StanzaPath('iq@type=set/pubsub/retract'), self.handleRetractItem)) #self.xmpp.registerHandler(Callback('pubsub get configure', StanzaPath('iq@type=get/pubsub_owner/configure'), self.handleGetNodeConfig)) #self.xmpp.registerHandler(Callback('pubsub defaultconfig', StanzaPath('iq@type=get/pubsub_owner/default'), self.handleGetDefaultConfig)) self.xmpp.registerHandler( Callback('pubsub subscribe', StanzaPath('iq@type=set/pubsub/subscribe'), self.handleSubscribe)) self.xmpp.registerHandler( Callback('pubsub unsubscribe', StanzaPath('iq@type=set/pubsub/unsubscribe'), self.handleUnsubscribe)) self.xmpp.registerHandler( Callback('pubsub getsubs', StanzaPath('iq@type=get/pubsub/subscriptions'), self.handleGetSubscriptions)) #TODO: registerHandler for handleSetAffilation, handleGetAffilation, handleGetSubscriptions self.xmpp.add_event_handler("got_offline", self.handleGotOffline) keys = self.redis.keys('xmpp.sub_expires.presence.{*}') for key in keys: subs = self.redis.smembers(key) for sub in subs: node, subid = sub.split('\x00') logging.info("Cleaning up stale subscription %s %s" % (node, subid)) self.unsubscribe(node, subid)
def test007publishitem(self): """Publishing item""" item = ET.Element('{http://netflint.net/protocol/test}test') w = Waiter('wait publish', StanzaPath('message/pubsub_event/items')) self.xmpp2.registerHandler(w) result = self.xmpp1['xep_0060'].setItem(self.pshost, "testnode2", (('test1', item), )) msg = w.wait(5) # got to get a result in 5 seconds self.failUnless(msg != False, "Account #2 did not get message event") self.failUnless(result)
def test009deleteitem(self): """Deleting item""" w = Waiter('wait retract', StanzaPath('message/pubsub_event/items@node=testnode2')) self.xmpp2.registerHandler(w) result = self.xmpp1['xep_0060'].deleteItem(self.pshost, "testnode2", "test1") self.failUnless(result, "Got error when deleting item.") msg = w.wait(1) self.failUnless(msg != False, "Did not get retract notice.")
def test014publishcollection(self): """Publishing item to collection child""" item = ET.Element('{http://netflint.net/protocol/test}test') w = Waiter('wait publish2', StanzaPath('message/pubsub_event/items@node=testnode2')) self.xmpp1.registerHandler(w) result = self.xmpp2['xep_0060'].setItem(self.pshost, "testnode2", (('test2', item), )) msg = w.wait(5) # got to get a result in 5 seconds self.failUnless( msg != False, "Account #1 did not get message event: perhaps node was advertised incorrectly?" ) self.failUnless(result)
def __init__(self, xmpp, dbfile, settings, rest, overridedefault=None): self.admin = None self.admin_loggedin = False self.camp_init = False self.xmpp = xmpp self.dbfile = dbfile self.db = None self.nodeplugins = [] self.config = {'settings': settings, 'rest': rest} if overridedefault is None: self.config['defaultnodeconfig'] = {} else: self.config['defaultnodeconfig'] = overridedefault self.default_config = self.getDefaultConfig() self.admins = [] self.node_classes = { 'leaf': BaseNode, 'collection': CollectionNode, 'queue': QueueNode, 'job': JobNode2 } self.nodes = NodeCache(self) self.adhoc = PubsubAdhoc(self) if self.config['rest']['enabled']: self.http = HTTPD(self) self.presence_expire = {} #self.xmpp.registerHandler(Callback('pubsub publish', MatchXMLMask("<iq xmlns='%s' type='set'><pubsub xmlns='http://jabber.org/protocol/pubsub'><publish xmlns='http://jabber.org/protocol/pubsub' /></pubsub></iq>" % self.xmpp.default_ns), self.handlePublish)) self.xmpp.registerHandler( Callback('pubsub state', StanzaPath('iq@type=set/psstate'), self.handleSetState)) self.xmpp.registerHandler( Callback('pubsub publish', StanzaPath("iq@type=set/pubsub/publish"), self.handlePublish)) self.xmpp.registerHandler( Callback('pubsub create', StanzaPath("iq@type=set/pubsub/create"), self.handleCreateNode)) self.xmpp.registerHandler( Callback('pubsub configure', StanzaPath("iq@type=set/pubsub_owner/configure"), self.handleConfigureNode)) self.xmpp.registerHandler( Callback('pubsub delete', StanzaPath('iq@type=set/pubsub_owner/delete'), self.handleDeleteNode)) self.xmpp.registerHandler( Callback('pubsub getitems', StanzaPath('iq@type=get/pubsub/items'), self.handleGetItems)) self.xmpp.registerHandler( Callback('pubsub delete item', StanzaPath('iq@type=set/pubsub/retract'), self.handleRetractItem)) #self.xmpp.registerHandler(Callback('pubsub configure', MatchXMLMask("<iq xmlns='%s' type='set'><pubsub xmlns='http://jabber.org/protocol/pubsub#owner'><configure xmlns='http://jabber.org/protocol/pubsub#owner' /></pubsub></iq>" % self.xmpp.default_ns), self.handleConfigureNode)) self.xmpp.registerHandler( Callback( 'pubsub get configure', MatchXMLMask( "<iq xmlns='%s' type='get'><pubsub xmlns='http://jabber.org/protocol/pubsub#owner'><configure xmlns='http://jabber.org/protocol/pubsub#owner' /></pubsub></iq>" % self.xmpp.default_ns), self.handleGetNodeConfig)) self.xmpp.registerHandler( Callback( 'pubsub defaultconfig', MatchXMLMask( "<iq xmlns='%s' type='get'><pubsub xmlns='http://jabber.org/protocol/pubsub#owner'><default xmlns='http://jabber.org/protocol/pubsub#owner' /></pubsub></iq>" % self.xmpp.default_ns), self.handleGetDefaultConfig)) self.xmpp.registerHandler( Callback( 'pubsub subscribe', MatchXMLMask( "<iq xmlns='%s' type='set'><pubsub xmlns='http://jabber.org/protocol/pubsub'><subscribe xmlns='http://jabber.org/protocol/pubsub' /></pubsub></iq>" % self.xmpp.default_ns), self.handleSubscribe)) self.xmpp.registerHandler( Callback( 'pubsub unsubscribe', MatchXMLMask( "<iq xmlns='%s' type='set'><pubsub xmlns='http://jabber.org/protocol/pubsub'><unsubscribe xmlns='http://jabber.org/protocol/pubsub' /></pubsub></iq>" % self.xmpp.default_ns), self.handleUnsubscribe)) self.xmpp.add_event_handler("session_start", self.start) self.xmpp.add_event_handler("changed_subscription", self.handleXMPPPresenceSubscription) self.xmpp.add_event_handler("got_online", self.handleGotOnline) self.xmpp.add_event_handler("got_offline", self.handleGotOffline) self.xmpp.add_event_handler("message", self.handleIncomingMessage) self.xmpp.add_event_handler("got_presence_probe", self.handleXMPPPresenceProbe)