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
|
|
@ -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'])
|
||||
|
|
|
|||
Loading…
Reference in a new issue