Mercurial > libervia-backend
diff sat.tac @ 15:218ec9984fa5
wokkel integration part III + memory saved again
- disco handler (plugins handled)
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 31 Oct 2009 00:18:35 +0100 |
parents | a62d7d453f22 |
children | 0a024d5e0cd0 |
line wrap: on
line diff
--- a/sat.tac Fri Oct 30 20:05:25 2009 +0100 +++ b/sat.tac Sat Oct 31 00:18:35 2009 +0100 @@ -44,6 +44,11 @@ from tools.memory import Memory from glob import glob +try: + from twisted.words.protocols.xmlstream import XMPPHandler +except ImportError: + from wokkel.subprotocols import XMPPHandler + ### logging configuration FIXME: put this elsewhere ### logging.basicConfig(level=logging.DEBUG, @@ -174,6 +179,16 @@ def __init__(self, host): disco.DiscoClientProtocol.__init__(self) +class SatFallbackHandler(generic.FallbackHandler): + def __init__(self, host): + generic.FallbackHandler.__init__(self) + + def iqFallback(self, iq): + #pdb.set_trace() + print "iqFallback: xml = [%s], handled=%s" % (iq.toXml(), "True" if iq.handled else "False") + generic.FallbackHandler.iqFallback(self, iq) + + class SAT(service.Service): def __init__(self): @@ -181,7 +196,6 @@ self.memory=Memory() self.server_features=[] #XXX: temp dic, need to be transfered into self.memory in the future - self._iq_cb_map = {} #callback called when ns is found on IQ self._waiting_conf = {} #callback called when a confirmation is received self._progress_cb_map = {} #callback called when a progress is requested (key = progress id) self.plugins = {} @@ -240,12 +254,17 @@ self.presence = SatPresenceProtocol(self) self.presence.setHandlerParent(self.xmppclient) - self.fallBack = generic.FallbackHandler() + self.fallBack = SatFallbackHandler(self) self.fallBack.setHandlerParent(self.xmppclient) self.versionHandler = generic.VersionHandler(unicode(client_name), client_version) self.versionHandler.setHandlerParent(self.xmppclient) + debug ("setting plugins parents") + for plugin in self.plugins.iteritems(): + if isinstance(plugin[1], XMPPHandler): + plugin[1].setHandlerParent(self.xmppclient) + self.xmppclient.startService() def disconnect(self): @@ -260,6 +279,7 @@ self.connect() def stopService(self): + self.memory.save() info("Salut aussi à Rantanplan") def run(self): @@ -277,21 +297,16 @@ self.xmlstream = self.xmppclient.xmlstream self.me = self.xmppclient.jid #in case of the ressource has changed + self.disco = SatDiscoProtocol(self) + self.disco.setHandlerParent(self.xmppclient) + self.discoHandler = disco.DiscoHandler() + self.discoHandler.setHandlerParent(self.xmppclient) + self.roster.requestRoster() self.presence.available() - #FIXME:tmp - self.xmlstream.addObserver("/iq[@type='set' or @type='get']", self.iqCb) - ###FIXME: tmp disco ### - self.disco = SatDiscoProtocol(self) - self.disco.setHandlerParent(self.xmppclient) self.disco.requestInfo(jid.JID(self.memory.getParamV("Server", "Connection"))).addCallback(self.serverDisco) - #we now send our presence status - - # add a callback for the messages - - #reactor.callLater(2,self.sendFile,"goffi2@jabber.goffi.int/Psi", "/tmp/fakefile") def sendMessage(self,to,msg,type='chat'): @@ -363,25 +378,6 @@ ## callbacks ## - def add_IQ_cb(self, ns, cb): - """Add an IQ callback on namespace ns""" - debug ("Registered callback for namespace %s", ns) - self._iq_cb_map[ns]=cb - - def iqCb(self, stanza): - info ("iqCb") - debug ("="*20) - debug ("DEBUG:\n") - debug (stanza.toXml().encode('utf-8')) - debug ("="*20) - #FIXME: temporary ugly code - uri = stanza.firstChildElement().uri - if self._iq_cb_map.has_key(uri): - self._iq_cb_map[uri](stanza) - #TODO: manage errors stanza - - - def serverDisco(self, disco): """xep-0030 Discovery Protocol.""" for feature in disco.features: @@ -439,7 +435,3 @@ application = service.Application('SàT') service = SAT() service.setServiceParent(application) - - -#app.memory.save() #FIXME: not the best place -#debug("Good Bye")