SàT: multi-profile, plugins updated

- core: 2 new convenient methods: getJidNStream and getClient
- new param in plugin info: "handler" to know if there is a handler to plug on profiles clients
- plugins with handler now use an other class which is returned to profile client with the new method "getHandler" and pluged when connecting
This commit is contained in:
Goffi 2010-01-30 16:17:33 +11:00
commit 656bea30dd

View file

@ -85,6 +85,7 @@ PLUGIN_INFO = {
"type": "XEP",
"protocols": ["XEP-0065"],
"main": "XEP_0065",
"handler": "yes",
"description": """Implementation of SOCKS5 Bytestreams"""
}
@ -312,7 +313,7 @@ class SOCKSv5(protocol.Protocol, FileSender):
debug("Saving file in %s.", self.data["dest_path"])
self.dest_file = open(self.data["dest_path"], 'w')
self.state = STATE_TARGET_READY
self.activateCB(self.target_jid, self.initiator_jid, self.sid, self.IQ_id)
self.activateCB(self.target_jid, self.initiator_jid, self.sid, self.IQ_id, self.xmlstream)
except struct.error, why:
@ -450,8 +451,7 @@ class Socks5ClientFactory(protocol.ClientFactory):
debug ("Socks 5 client connection lost (reason: %s)", reason)
class XEP_0065(XMPPHandler):
implements(iwokkel.IDisco)
class XEP_0065():
params = """
<params>
@ -480,20 +480,12 @@ class XEP_0065(XMPPHandler):
info("Launching Socks5 Stream server on port %d", port)
reactor.listenTCP(port, self.server_factory)
def getHandler(self):
return XEP_0065_handler(self)
def getExternalIP(self):
"""Return IP visible from outside, by asking to a website"""
return getPage("http://www.goffi.org/sat_tools/get_ip.php")
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
@ -507,8 +499,10 @@ class XEP_0065(XMPPHandler):
self.server_factory.protocol.filesize = size
self.server_factory.protocol.transfert_id = id
def getFile(self, iq):
def getFile(self, iq, profile_key='@DEFAULT@'):
"""Get file using byte stream"""
client = self.host.getClient(profile_key)
assert(client)
iq.handled = True
SI_elem = iq.firstChildElement()
IQ_id = iq['id']
@ -518,17 +512,18 @@ class XEP_0065(XMPPHandler):
factory = self.client_factory
self.server_factory.protocol.mode = "target"
factory.protocol.host = self.host #needed for progress CB
factory.protocol.xmlstream = client.xmlstream
factory.protocol.data = self.data
factory.protocol.transfert_id = self.transfert_id
factory.protocol.filesize = self.data["size"]
factory.protocol.sid = SI_elem['sid']
factory.protocol.initiator_jid = element['jid']
factory.protocol.target_jid = self.host.me.full()
factory.protocol.target_jid = client.jid.full()
factory.protocol.IQ_id = IQ_id
factory.protocol.activateCB = self.activateStream
reactor.connectTCP(element['host'], int(element['port']), factory)
def activateStream(self, from_jid, to_jid, sid, IQ_id):
def activateStream(self, from_jid, to_jid, sid, IQ_id, xmlstream):
debug("activating stream")
result = domish.Element(('', 'iq'))
result['type'] = 'result'
@ -539,5 +534,21 @@ class XEP_0065(XMPPHandler):
query['sid'] = sid
streamhost = query.addElement('streamhost-used')
streamhost['jid'] = to_jid #FIXME: use real streamhost
self.host.xmlstream.send(result)
xmlstream.send(result)
class XEP_0065_handler(XMPPHandler):
implements(iwokkel.IDisco)
def __init__(self, plugin_parent):
self.plugin_parent = plugin_parent
self.host = plugin_parent.host
def connectionInitialized(self):
self.xmlstream.addObserver(BS_REQUEST, self.plugin_parent.getFile)
def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
return [disco.DiscoFeature(NS_BS)]
def getDiscoItems(self, requestor, target, nodeIdentifier=''):
return []