Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
14:a62d7d453f22 | 15:218ec9984fa5 |
---|---|
60 from twisted.protocols.basic import FileSender | 60 from twisted.protocols.basic import FileSender |
61 from twisted.words.xish import domish | 61 from twisted.words.xish import domish |
62 import struct | 62 import struct |
63 from binascii import hexlify | 63 from binascii import hexlify |
64 import hashlib, pdb | 64 import hashlib, pdb |
65 | |
66 from zope.interface import implements | |
67 | |
68 try: | |
69 from twisted.words.protocols.xmlstream import XMPPHandler | |
70 except ImportError: | |
71 from wokkel.subprotocols import XMPPHandler | |
72 | |
73 from wokkel import disco, iwokkel | |
74 | |
75 IQ_SET = '/iq[@type="set"]' | |
76 NS_BS = 'http://jabber.org/protocol/bytestreams' | |
77 BS_REQUEST = IQ_SET + '/query[@xmlns="' + NS_BS + '"]' | |
78 | |
65 | 79 |
66 | 80 |
67 PLUGIN_INFO = { | 81 PLUGIN_INFO = { |
68 "name": "XEP 0065 Plugin", | 82 "name": "XEP 0065 Plugin", |
69 "import_name": "XEP_0065", | 83 "import_name": "XEP_0065", |
432 | 446 |
433 def clientConnectionLost(self, connector, reason): | 447 def clientConnectionLost(self, connector, reason): |
434 debug ("Socks 5 client connection lost (reason: %s)", reason) | 448 debug ("Socks 5 client connection lost (reason: %s)", reason) |
435 | 449 |
436 | 450 |
437 class XEP_0065(): | 451 class XEP_0065(XMPPHandler): |
452 implements(iwokkel.IDisco) | |
453 | |
438 def __init__(self, host): | 454 def __init__(self, host): |
439 info("Plugin XEP_0065 initialization") | 455 info("Plugin XEP_0065 initialization") |
440 self.host = host | 456 self.host = host |
441 debug("registering") | 457 debug("registering") |
442 self.server_factory = Socks5ServerFactory() | 458 self.server_factory = Socks5ServerFactory() |
443 self.server_factory.protocol.host = self.host #needed for progress CB | 459 self.server_factory.protocol.host = self.host #needed for progress CB |
444 self.client_factory = Socks5ClientFactory() | 460 self.client_factory = Socks5ClientFactory() |
445 host.add_IQ_cb("http://jabber.org/protocol/bytestreams", self.getFile) | |
446 port = int(self.host.memory.getParamV("Port", "File Transfert")) | 461 port = int(self.host.memory.getParamV("Port", "File Transfert")) |
447 info("Launching Socks5 Stream server on port %d", port) | 462 info("Launching Socks5 Stream server on port %d", port) |
448 reactor.listenTCP(port, self.server_factory) | 463 reactor.listenTCP(port, self.server_factory) |
464 | |
465 def connectionInitialized(self): | |
466 self.xmlstream.addObserver(BS_REQUEST, self.getFile) | |
467 | |
468 | |
469 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): | |
470 return [disco.DiscoFeature(NS_BS)] | |
471 | |
472 def getDiscoItems(self, requestor, target, nodeIdentifier=''): | |
473 return [] | |
474 | |
449 | 475 |
450 def setData(self, data, id): | 476 def setData(self, data, id): |
451 self.data = data | 477 self.data = data |
452 self.transfert_id = id | 478 self.transfert_id = id |
453 | 479 |
457 self.server_factory.protocol.mode = "initiator" | 483 self.server_factory.protocol.mode = "initiator" |
458 self.server_factory.protocol.filepath = filepath | 484 self.server_factory.protocol.filepath = filepath |
459 self.server_factory.protocol.filesize = size | 485 self.server_factory.protocol.filesize = size |
460 self.server_factory.protocol.transfert_id = id | 486 self.server_factory.protocol.transfert_id = id |
461 | 487 |
462 def getFile(self, stanza): | 488 def getFile(self, iq): |
463 """Get file using byte stream""" | 489 """Get file using byte stream""" |
464 SI_elem = stanza.firstChildElement() | 490 iq.handled = True |
465 IQ_id = stanza['id'] | 491 SI_elem = iq.firstChildElement() |
492 IQ_id = iq['id'] | |
466 for element in SI_elem.elements(): | 493 for element in SI_elem.elements(): |
467 if element.name == "streamhost": | 494 if element.name == "streamhost": |
468 info ("Stream proposed: host=[%s] port=[%s]", element['host'], element['port']) | 495 info ("Stream proposed: host=[%s] port=[%s]", element['host'], element['port']) |
469 factory = self.client_factory | 496 factory = self.client_factory |
470 self.server_factory.protocol.mode = "target" | 497 self.server_factory.protocol.mode = "target" |