comparison plugins/plugin_xep_0065.py @ 69:86f1f7f6d332

i18n first draft - gettext support added in SàT - first draft of french translation - added README with a HOWTO for translators
author Goffi <goffi@goffi.org>
date Wed, 03 Mar 2010 17:12:23 +1100
parents d46f849664aa
children f271fff3a713
comparison
equal deleted inserted replaced
68:9b842086d915 69:86f1f7f6d332
84 "import_name": "XEP_0065", 84 "import_name": "XEP_0065",
85 "type": "XEP", 85 "type": "XEP",
86 "protocols": ["XEP-0065"], 86 "protocols": ["XEP-0065"],
87 "main": "XEP_0065", 87 "main": "XEP_0065",
88 "handler": "yes", 88 "handler": "yes",
89 "description": """Implementation of SOCKS5 Bytestreams""" 89 "description": _("""Implementation of SOCKS5 Bytestreams""")
90 } 90 }
91 91
92 STATE_INITIAL = 0 92 STATE_INITIAL = 0
93 STATE_AUTH = 1 93 STATE_AUTH = 1
94 STATE_REQUEST = 2 94 STATE_REQUEST = 2
130 130
131 131
132 132
133 class SOCKSv5(protocol.Protocol, FileSender): 133 class SOCKSv5(protocol.Protocol, FileSender):
134 def __init__(self): 134 def __init__(self):
135 debug("Protocol init") 135 debug(_("Protocol init"))
136 self.state = STATE_INITIAL 136 self.state = STATE_INITIAL
137 self.buf = "" 137 self.buf = ""
138 self.supportedAuthMechs = [ AUTHMECH_ANON ] 138 self.supportedAuthMechs = [ AUTHMECH_ANON ]
139 self.supportedAddrs = [ ADDR_DOMAINNAME ] 139 self.supportedAddrs = [ ADDR_DOMAINNAME ]
140 self.enabledCommands = [ CMD_CONNECT ] 140 self.enabledCommands = [ CMD_CONNECT ]
212 result = struct.pack('!BBBBIH', SOCKS5_VER, errorcode, 0, 1, 0, 0) 212 result = struct.pack('!BBBBIH', SOCKS5_VER, errorcode, 0, 1, 0, 0)
213 self.transport.write(result) 213 self.transport.write(result)
214 self.transport.loseConnection() 214 self.transport.loseConnection()
215 215
216 def addConnection(self, address, connection): 216 def addConnection(self, address, connection):
217 info("Adding connection: %s, %s", address, connection) 217 info(_("Adding connection: %(address)s, %(connection)s") % {'address':address, 'connection':connection})
218 olist = self.pendingConns.get(address, []) 218 olist = self.pendingConns.get(address, [])
219 if len(olist) <= 1: 219 if len(olist) <= 1:
220 olist.append(connection) 220 olist.append(connection)
221 self.pendingConns[address] = olist 221 self.pendingConns[address] = olist
222 return True 222 return True
308 # Ensure reply is OK 308 # Ensure reply is OK
309 if rep != REPLY_SUCCESS: 309 if rep != REPLY_SUCCESS:
310 self.loseConnection() 310 self.loseConnection()
311 return 311 return
312 312
313 debug("Saving file in %s.", self.data["dest_path"]) 313 debug(_("Saving file in %s."), self.data["dest_path"])
314 self.dest_file = open(self.data["dest_path"], 'w') 314 self.dest_file = open(self.data["dest_path"], 'w')
315 self.state = STATE_TARGET_READY 315 self.state = STATE_TARGET_READY
316 self.activateCB(self.target_jid, self.initiator_jid, self.sid, self.IQ_id, self.xmlstream) 316 self.activateCB(self.target_jid, self.initiator_jid, self.sid, self.IQ_id, self.xmlstream)
317 317
318 318
326 if self.mode == "target": 326 if self.mode == "target":
327 self.state = STATE_TARGET_INITIAL 327 self.state = STATE_TARGET_INITIAL
328 self._startNegotiation() 328 self._startNegotiation()
329 329
330 def connectRequested(self, addr, port): 330 def connectRequested(self, addr, port):
331 debug(("connectRequested")) 331 debug("connectRequested")
332 # Check for special connect to the namespace -- this signifies that the client 332 # Check for special connect to the namespace -- this signifies that the client
333 # is just checking to ensure it can connect to the streamhost 333 # is just checking to ensure it can connect to the streamhost
334 if addr == "http://jabber.org/protocol/bytestreams": 334 if addr == "http://jabber.org/protocol/bytestreams":
335 self.connectCompleted(addr, 0) 335 self.connectCompleted(addr, 0)
336 self.transport.loseConnection() 336 self.transport.loseConnection()
359 data["position"] = str(self.dest_file.tell()) 359 data["position"] = str(self.dest_file.tell())
360 except (ValueError, AttributeError): 360 except (ValueError, AttributeError):
361 data["position"] = "" 361 data["position"] = ""
362 362
363 def fileTransfered(self, d): 363 def fileTransfered(self, d):
364 info("File transfer completed, closing connection") 364 info(_("File transfer completed, closing connection"))
365 self.transport.loseConnection() 365 self.transport.loseConnection()
366 366
367 def updateTransfered(self, data): 367 def updateTransfered(self, data):
368 self.transfered+=len(data) 368 self.transfered+=len(data)
369 return data 369 return data
433 protocol = SOCKSv5 433 protocol = SOCKSv5
434 protocol.mode = "initiator" #FIXME: Q&D way, fix it 434 protocol.mode = "initiator" #FIXME: Q&D way, fix it
435 435
436 436
437 def startedConnecting(self, connector): 437 def startedConnecting(self, connector):
438 debug ("Socks 5 server connection started") 438 debug (_("Socks 5 server connection started"))
439 439
440 def clientConnectionLost(self, connector, reason): 440 def clientConnectionLost(self, connector, reason):
441 debug ("Socks 5 server connection lost (reason: %s)", reason) 441 debug (_("Socks 5 server connection lost (reason: %s)"), reason)
442 442
443 class Socks5ClientFactory(protocol.ClientFactory): 443 class Socks5ClientFactory(protocol.ClientFactory):
444 protocol = SOCKSv5 444 protocol = SOCKSv5
445 protocol.mode = "target" #FIXME: Q&D way, fix it 445 protocol.mode = "target" #FIXME: Q&D way, fix it
446 446
447 def startedConnecting(self, connector): 447 def startedConnecting(self, connector):
448 debug ("Socks 5 client connection started") 448 debug (_("Socks 5 client connection started"))
449 449
450 def clientConnectionLost(self, connector, reason): 450 def clientConnectionLost(self, connector, reason):
451 debug ("Socks 5 client connection lost (reason: %s)", reason) 451 debug (_("Socks 5 client connection lost (reason: %s)"), reason)
452 452
453 453
454 class XEP_0065(): 454 class XEP_0065():
455 455
456 params = """ 456 params = """
463 </general> 463 </general>
464 </params> 464 </params>
465 """ 465 """
466 466
467 def __init__(self, host): 467 def __init__(self, host):
468 info("Plugin XEP_0065 initialization") 468 info(_("Plugin XEP_0065 initialization"))
469 self.host = host 469 self.host = host
470 debug("registering") 470 debug(_("registering"))
471 self.server_factory = Socks5ServerFactory() 471 self.server_factory = Socks5ServerFactory()
472 self.server_factory.protocol.host = self.host #needed for progress CB 472 self.server_factory.protocol.host = self.host #needed for progress CB
473 self.client_factory = Socks5ClientFactory() 473 self.client_factory = Socks5ClientFactory()
474 474
475 #parameters 475 #parameters
476 host.memory.importParams(XEP_0065.params) 476 host.memory.importParams(XEP_0065.params)
477 host.memory.setDefault("IP", "File Transfert", self.getExternalIP) 477 host.memory.setDefault("IP", "File Transfert", self.getExternalIP)
478 478
479 port = int(self.host.memory.getParamA("Port", "File Transfert")) 479 port = int(self.host.memory.getParamA("Port", "File Transfert"))
480 info("Launching Socks5 Stream server on port %d", port) 480 info(_("Launching Socks5 Stream server on port %d"), port)
481 reactor.listenTCP(port, self.server_factory) 481 reactor.listenTCP(port, self.server_factory)
482 482
483 def getHandler(self): 483 def getHandler(self):
484 return XEP_0065_handler(self) 484 return XEP_0065_handler(self)
485 485
491 self.data = data 491 self.data = data
492 self.transfert_id = id 492 self.transfert_id = id
493 493
494 def sendFile(self, id, filepath, size): 494 def sendFile(self, id, filepath, size):
495 #lauching socks5 initiator 495 #lauching socks5 initiator
496 debug("Launching socks5 initiator") 496 debug(_("Launching socks5 initiator"))
497 self.server_factory.protocol.mode = "initiator" 497 self.server_factory.protocol.mode = "initiator"
498 self.server_factory.protocol.filepath = filepath 498 self.server_factory.protocol.filepath = filepath
499 self.server_factory.protocol.filesize = size 499 self.server_factory.protocol.filesize = size
500 self.server_factory.protocol.transfert_id = id 500 self.server_factory.protocol.transfert_id = id
501 501
506 iq.handled = True 506 iq.handled = True
507 SI_elem = iq.firstChildElement() 507 SI_elem = iq.firstChildElement()
508 IQ_id = iq['id'] 508 IQ_id = iq['id']
509 for element in SI_elem.elements(): 509 for element in SI_elem.elements():
510 if element.name == "streamhost": 510 if element.name == "streamhost":
511 info ("Stream proposed: host=[%s] port=[%s]", element['host'], element['port']) 511 info (_("Stream proposed: host=[%(host)s] port=[%(post)s]") % {'host':element['host'], 'port':element['port']})
512 factory = self.client_factory 512 factory = self.client_factory
513 self.server_factory.protocol.mode = "target" 513 self.server_factory.protocol.mode = "target"
514 factory.protocol.host = self.host #needed for progress CB 514 factory.protocol.host = self.host #needed for progress CB
515 factory.protocol.xmlstream = client.xmlstream 515 factory.protocol.xmlstream = client.xmlstream
516 factory.protocol.data = self.data 516 factory.protocol.data = self.data
522 factory.protocol.IQ_id = IQ_id 522 factory.protocol.IQ_id = IQ_id
523 factory.protocol.activateCB = self.activateStream 523 factory.protocol.activateCB = self.activateStream
524 reactor.connectTCP(element['host'], int(element['port']), factory) 524 reactor.connectTCP(element['host'], int(element['port']), factory)
525 525
526 def activateStream(self, from_jid, to_jid, sid, IQ_id, xmlstream): 526 def activateStream(self, from_jid, to_jid, sid, IQ_id, xmlstream):
527 debug("activating stream") 527 debug(_("activating stream"))
528 result = domish.Element(('', 'iq')) 528 result = domish.Element(('', 'iq'))
529 result['type'] = 'result' 529 result['type'] = 'result'
530 result['id'] = IQ_id 530 result['id'] = IQ_id
531 result['from'] = from_jid 531 result['from'] = from_jid
532 result['to'] = to_jid 532 result['to'] = to_jid