wokkel integration part III + memory saved again
- disco handler (plugins handled)
This commit is contained in:
parent
af75e43558
commit
fe0cf89f64
3 changed files with 86 additions and 42 deletions
|
|
@ -63,6 +63,20 @@ import struct
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
import hashlib, pdb
|
import hashlib, pdb
|
||||||
|
|
||||||
|
from zope.interface import implements
|
||||||
|
|
||||||
|
try:
|
||||||
|
from twisted.words.protocols.xmlstream import XMPPHandler
|
||||||
|
except ImportError:
|
||||||
|
from wokkel.subprotocols import XMPPHandler
|
||||||
|
|
||||||
|
from wokkel import disco, iwokkel
|
||||||
|
|
||||||
|
IQ_SET = '/iq[@type="set"]'
|
||||||
|
NS_BS = 'http://jabber.org/protocol/bytestreams'
|
||||||
|
BS_REQUEST = IQ_SET + '/query[@xmlns="' + NS_BS + '"]'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PLUGIN_INFO = {
|
PLUGIN_INFO = {
|
||||||
"name": "XEP 0065 Plugin",
|
"name": "XEP 0065 Plugin",
|
||||||
|
|
@ -434,7 +448,9 @@ class Socks5ClientFactory(protocol.ClientFactory):
|
||||||
debug ("Socks 5 client connection lost (reason: %s)", reason)
|
debug ("Socks 5 client connection lost (reason: %s)", reason)
|
||||||
|
|
||||||
|
|
||||||
class XEP_0065():
|
class XEP_0065(XMPPHandler):
|
||||||
|
implements(iwokkel.IDisco)
|
||||||
|
|
||||||
def __init__(self, host):
|
def __init__(self, host):
|
||||||
info("Plugin XEP_0065 initialization")
|
info("Plugin XEP_0065 initialization")
|
||||||
self.host = host
|
self.host = host
|
||||||
|
|
@ -442,11 +458,21 @@ class XEP_0065():
|
||||||
self.server_factory = Socks5ServerFactory()
|
self.server_factory = Socks5ServerFactory()
|
||||||
self.server_factory.protocol.host = self.host #needed for progress CB
|
self.server_factory.protocol.host = self.host #needed for progress CB
|
||||||
self.client_factory = Socks5ClientFactory()
|
self.client_factory = Socks5ClientFactory()
|
||||||
host.add_IQ_cb("http://jabber.org/protocol/bytestreams", self.getFile)
|
|
||||||
port = int(self.host.memory.getParamV("Port", "File Transfert"))
|
port = int(self.host.memory.getParamV("Port", "File Transfert"))
|
||||||
info("Launching Socks5 Stream server on port %d", port)
|
info("Launching Socks5 Stream server on port %d", port)
|
||||||
reactor.listenTCP(port, self.server_factory)
|
reactor.listenTCP(port, self.server_factory)
|
||||||
|
|
||||||
|
def connectionInitialized(self):
|
||||||
|
self.xmlstream.addObserver(BS_REQUEST, self.getFile)
|
||||||
|
|
||||||
|
|
||||||
|
def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
|
||||||
|
return [disco.DiscoFeature(NS_BS)]
|
||||||
|
|
||||||
|
def getDiscoItems(self, requestor, target, nodeIdentifier=''):
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
def setData(self, data, id):
|
def setData(self, data, id):
|
||||||
self.data = data
|
self.data = data
|
||||||
self.transfert_id = id
|
self.transfert_id = id
|
||||||
|
|
@ -459,10 +485,11 @@ class XEP_0065():
|
||||||
self.server_factory.protocol.filesize = size
|
self.server_factory.protocol.filesize = size
|
||||||
self.server_factory.protocol.transfert_id = id
|
self.server_factory.protocol.transfert_id = id
|
||||||
|
|
||||||
def getFile(self, stanza):
|
def getFile(self, iq):
|
||||||
"""Get file using byte stream"""
|
"""Get file using byte stream"""
|
||||||
SI_elem = stanza.firstChildElement()
|
iq.handled = True
|
||||||
IQ_id = stanza['id']
|
SI_elem = iq.firstChildElement()
|
||||||
|
IQ_id = iq['id']
|
||||||
for element in SI_elem.elements():
|
for element in SI_elem.elements():
|
||||||
if element.name == "streamhost":
|
if element.name == "streamhost":
|
||||||
info ("Stream proposed: host=[%s] port=[%s]", element['host'], element['port'])
|
info ("Stream proposed: host=[%s] port=[%s]", element['host'], element['port'])
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,19 @@ import os.path
|
||||||
from twisted.internet import reactor #FIXME best way ???
|
from twisted.internet import reactor #FIXME best way ???
|
||||||
import pdb
|
import pdb
|
||||||
|
|
||||||
|
from zope.interface import implements
|
||||||
|
|
||||||
|
try:
|
||||||
|
from twisted.words.protocols.xmlstream import XMPPHandler
|
||||||
|
except ImportError:
|
||||||
|
from wokkel.subprotocols import XMPPHandler
|
||||||
|
|
||||||
|
from wokkel import disco, iwokkel
|
||||||
|
|
||||||
|
IQ_SET = '/iq[@type="set"]'
|
||||||
|
NS_SI = 'http://jabber.org/protocol/si'
|
||||||
|
SI_REQUEST = IQ_SET + '/si[@xmlns="' + NS_SI + '"]'
|
||||||
|
|
||||||
PLUGIN_INFO = {
|
PLUGIN_INFO = {
|
||||||
"name": "XEP 0096 Plugin",
|
"name": "XEP 0096 Plugin",
|
||||||
"import_name": "XEP_0096",
|
"import_name": "XEP_0096",
|
||||||
|
|
@ -36,16 +49,28 @@ PLUGIN_INFO = {
|
||||||
"description": """Implementation of SI File Transfert"""
|
"description": """Implementation of SI File Transfert"""
|
||||||
}
|
}
|
||||||
|
|
||||||
class XEP_0096:
|
class XEP_0096(XMPPHandler):
|
||||||
|
implements(iwokkel.IDisco)
|
||||||
|
|
||||||
def __init__(self, host):
|
def __init__(self, host):
|
||||||
info("Plugin XEP_0096 initialization")
|
info("Plugin XEP_0096 initialization")
|
||||||
self.host = host
|
self.host = host
|
||||||
self._waiting_for_approval = {}
|
self._waiting_for_approval = {}
|
||||||
host.add_IQ_cb("http://jabber.org/protocol/si", self.xep_96)
|
|
||||||
host.bridge.addMethod("sendFile", ".communication", in_sign='ss', out_sign='s', method=self.sendFile)
|
host.bridge.addMethod("sendFile", ".communication", in_sign='ss', out_sign='s', method=self.sendFile)
|
||||||
|
|
||||||
|
def connectionInitialized(self):
|
||||||
|
self.xmlstream.addObserver(SI_REQUEST, self.xep_96)
|
||||||
|
|
||||||
|
|
||||||
|
def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
|
||||||
|
return [disco.DiscoFeature(NS_SI)]
|
||||||
|
|
||||||
|
def getDiscoItems(self, requestor, target, nodeIdentifier=''):
|
||||||
|
return []
|
||||||
|
|
||||||
def xep_96(self, IQ):
|
def xep_96(self, IQ):
|
||||||
info ("XEP-0096 management")
|
info ("XEP-0096 management")
|
||||||
|
IQ.handled=True
|
||||||
SI_elem = IQ.firstChildElement()
|
SI_elem = IQ.firstChildElement()
|
||||||
debug(SI_elem.toXml())
|
debug(SI_elem.toXml())
|
||||||
filename = ""
|
filename = ""
|
||||||
|
|
|
||||||
62
sat.tac
62
sat.tac
|
|
@ -44,6 +44,11 @@ import os.path
|
||||||
from tools.memory import Memory
|
from tools.memory import Memory
|
||||||
from glob import glob
|
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 configuration FIXME: put this elsewhere ###
|
||||||
logging.basicConfig(level=logging.DEBUG,
|
logging.basicConfig(level=logging.DEBUG,
|
||||||
|
|
@ -174,6 +179,16 @@ class SatDiscoProtocol(disco.DiscoClientProtocol):
|
||||||
def __init__(self, host):
|
def __init__(self, host):
|
||||||
disco.DiscoClientProtocol.__init__(self)
|
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):
|
class SAT(service.Service):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
@ -181,7 +196,6 @@ class SAT(service.Service):
|
||||||
self.memory=Memory()
|
self.memory=Memory()
|
||||||
self.server_features=[] #XXX: temp dic, need to be transfered into self.memory in the future
|
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._waiting_conf = {} #callback called when a confirmation is received
|
||||||
self._progress_cb_map = {} #callback called when a progress is requested (key = progress id)
|
self._progress_cb_map = {} #callback called when a progress is requested (key = progress id)
|
||||||
self.plugins = {}
|
self.plugins = {}
|
||||||
|
|
@ -240,12 +254,17 @@ class SAT(service.Service):
|
||||||
self.presence = SatPresenceProtocol(self)
|
self.presence = SatPresenceProtocol(self)
|
||||||
self.presence.setHandlerParent(self.xmppclient)
|
self.presence.setHandlerParent(self.xmppclient)
|
||||||
|
|
||||||
self.fallBack = generic.FallbackHandler()
|
self.fallBack = SatFallbackHandler(self)
|
||||||
self.fallBack.setHandlerParent(self.xmppclient)
|
self.fallBack.setHandlerParent(self.xmppclient)
|
||||||
|
|
||||||
self.versionHandler = generic.VersionHandler(unicode(client_name), client_version)
|
self.versionHandler = generic.VersionHandler(unicode(client_name), client_version)
|
||||||
self.versionHandler.setHandlerParent(self.xmppclient)
|
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()
|
self.xmppclient.startService()
|
||||||
|
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
|
|
@ -260,6 +279,7 @@ class SAT(service.Service):
|
||||||
self.connect()
|
self.connect()
|
||||||
|
|
||||||
def stopService(self):
|
def stopService(self):
|
||||||
|
self.memory.save()
|
||||||
info("Salut aussi à Rantanplan")
|
info("Salut aussi à Rantanplan")
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
@ -277,21 +297,16 @@ class SAT(service.Service):
|
||||||
self.xmlstream = self.xmppclient.xmlstream
|
self.xmlstream = self.xmppclient.xmlstream
|
||||||
self.me = self.xmppclient.jid #in case of the ressource has changed
|
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.roster.requestRoster()
|
||||||
|
|
||||||
self.presence.available()
|
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)
|
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'):
|
def sendMessage(self,to,msg,type='chat'):
|
||||||
|
|
@ -363,25 +378,6 @@ class SAT(service.Service):
|
||||||
|
|
||||||
## callbacks ##
|
## 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):
|
def serverDisco(self, disco):
|
||||||
"""xep-0030 Discovery Protocol."""
|
"""xep-0030 Discovery Protocol."""
|
||||||
for feature in disco.features:
|
for feature in disco.features:
|
||||||
|
|
@ -439,7 +435,3 @@ class SAT(service.Service):
|
||||||
application = service.Application('SàT')
|
application = service.Application('SàT')
|
||||||
service = SAT()
|
service = SAT()
|
||||||
service.setServiceParent(application)
|
service.setServiceParent(application)
|
||||||
|
|
||||||
|
|
||||||
#app.memory.save() #FIXME: not the best place
|
|
||||||
#debug("Good Bye")
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue