wokkel integration part III + memory saved again
- disco handler (plugins handled)
This commit is contained in:
parent
af75e43558
commit
fe0cf89f64
1 changed files with 86 additions and 42 deletions
62
sat.tac
62
sat.tac
|
|
@ -44,6 +44,11 @@ import os.path
|
|||
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 @@ class SatDiscoProtocol(disco.DiscoClientProtocol):
|
|||
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 @@ class SAT(service.Service):
|
|||
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 @@ class SAT(service.Service):
|
|||
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 @@ class SAT(service.Service):
|
|||
self.connect()
|
||||
|
||||
def stopService(self):
|
||||
self.memory.save()
|
||||
info("Salut aussi à Rantanplan")
|
||||
|
||||
def run(self):
|
||||
|
|
@ -277,21 +297,16 @@ class SAT(service.Service):
|
|||
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 @@ class SAT(service.Service):
|
|||
|
||||
## 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 @@ class SAT(service.Service):
|
|||
application = service.Application('SàT')
|
||||
service = SAT()
|
||||
service.setServiceParent(application)
|
||||
|
||||
|
||||
#app.memory.save() #FIXME: not the best place
|
||||
#debug("Good Bye")
|
||||
|
|
|
|||
Loading…
Reference in a new issue