wokkel integration part III + memory saved again
- disco handler (plugins handled)
This commit is contained in:
parent
af75e43558
commit
fe0cf89f64
2 changed files with 86 additions and 42 deletions
|
|
@ -63,6 +63,20 @@ import struct
|
|||
from binascii import hexlify
|
||||
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 = {
|
||||
"name": "XEP 0065 Plugin",
|
||||
|
|
@ -434,7 +448,9 @@ class Socks5ClientFactory(protocol.ClientFactory):
|
|||
debug ("Socks 5 client connection lost (reason: %s)", reason)
|
||||
|
||||
|
||||
class XEP_0065():
|
||||
class XEP_0065(XMPPHandler):
|
||||
implements(iwokkel.IDisco)
|
||||
|
||||
def __init__(self, host):
|
||||
info("Plugin XEP_0065 initialization")
|
||||
self.host = host
|
||||
|
|
@ -442,10 +458,20 @@ class XEP_0065():
|
|||
self.server_factory = Socks5ServerFactory()
|
||||
self.server_factory.protocol.host = self.host #needed for progress CB
|
||||
self.client_factory = Socks5ClientFactory()
|
||||
host.add_IQ_cb("http://jabber.org/protocol/bytestreams", self.getFile)
|
||||
port = int(self.host.memory.getParamV("Port", "File Transfert"))
|
||||
info("Launching Socks5 Stream server on port %d", port)
|
||||
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):
|
||||
self.data = data
|
||||
|
|
@ -459,10 +485,11 @@ class XEP_0065():
|
|||
self.server_factory.protocol.filesize = size
|
||||
self.server_factory.protocol.transfert_id = id
|
||||
|
||||
def getFile(self, stanza):
|
||||
def getFile(self, iq):
|
||||
"""Get file using byte stream"""
|
||||
SI_elem = stanza.firstChildElement()
|
||||
IQ_id = stanza['id']
|
||||
iq.handled = True
|
||||
SI_elem = iq.firstChildElement()
|
||||
IQ_id = iq['id']
|
||||
for element in SI_elem.elements():
|
||||
if element.name == "streamhost":
|
||||
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 ???
|
||||
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 = {
|
||||
"name": "XEP 0096 Plugin",
|
||||
"import_name": "XEP_0096",
|
||||
|
|
@ -36,16 +49,28 @@ PLUGIN_INFO = {
|
|||
"description": """Implementation of SI File Transfert"""
|
||||
}
|
||||
|
||||
class XEP_0096:
|
||||
class XEP_0096(XMPPHandler):
|
||||
implements(iwokkel.IDisco)
|
||||
|
||||
def __init__(self, host):
|
||||
info("Plugin XEP_0096 initialization")
|
||||
self.host = host
|
||||
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)
|
||||
|
||||
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):
|
||||
info ("XEP-0096 management")
|
||||
IQ.handled=True
|
||||
SI_elem = IQ.firstChildElement()
|
||||
debug(SI_elem.toXml())
|
||||
filename = ""
|
||||
|
|
|
|||
Loading…
Reference in a new issue