Mercurial > libervia-backend
diff plugins/plugin_xep_0065.py @ 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 | 63ab3d8058f4 |
children | f2a745ca0fbc |
line wrap: on
line diff
--- a/plugins/plugin_xep_0065.py Fri Oct 30 20:05:25 2009 +0100 +++ b/plugins/plugin_xep_0065.py Sat Oct 31 00:18:35 2009 +0100 @@ -63,6 +63,20 @@ 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 @@ 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 @@ 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 @@ 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'])