comparison src/plugins/plugin_xep_0065.py @ 594:e629371a28d3

Fix pep8 support in src/plugins.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 18 Jan 2013 17:55:35 +0100
parents beaf6bec2fcd
children 84a6e83157c2
comparison
equal deleted inserted replaced
593:70bae685d05c 594:e629371a28d3
76 from wokkel import disco, iwokkel 76 from wokkel import disco, iwokkel
77 77
78 IQ_SET = '/iq[@type="set"]' 78 IQ_SET = '/iq[@type="set"]'
79 NS_BS = 'http://jabber.org/protocol/bytestreams' 79 NS_BS = 'http://jabber.org/protocol/bytestreams'
80 BS_REQUEST = IQ_SET + '/query[@xmlns="' + NS_BS + '"]' 80 BS_REQUEST = IQ_SET + '/query[@xmlns="' + NS_BS + '"]'
81 TIMEOUT = 60 #timeout for workflow 81 TIMEOUT = 60 # timeout for workflow
82
83
84 82
85 PLUGIN_INFO = { 83 PLUGIN_INFO = {
86 "name": "XEP 0065 Plugin", 84 "name": "XEP 0065 Plugin",
87 "import_name": "XEP-0065", 85 "import_name": "XEP-0065",
88 "type": "XEP", 86 "type": "XEP",
89 "protocols": ["XEP-0065"], 87 "protocols": ["XEP-0065"],
90 "main": "XEP_0065", 88 "main": "XEP_0065",
91 "handler": "yes", 89 "handler": "yes",
92 "description": _("""Implementation of SOCKS5 Bytestreams""") 90 "description": _("""Implementation of SOCKS5 Bytestreams""")
93 } 91 }
94 92
95 STATE_INITIAL = 0 93 STATE_INITIAL = 0
96 STATE_AUTH = 1 94 STATE_AUTH = 1
97 STATE_REQUEST = 2 95 STATE_REQUEST = 2
98 STATE_READY = 3 96 STATE_READY = 3
99 STATE_AUTH_USERPASS = 4 97 STATE_AUTH_USERPASS = 4
100 STATE_TARGET_INITIAL = 5 98 STATE_TARGET_INITIAL = 5
101 STATE_TARGET_AUTH = 6 99 STATE_TARGET_AUTH = 6
102 STATE_TARGET_REQUEST = 7 100 STATE_TARGET_REQUEST = 7
103 STATE_TARGET_READY = 8 101 STATE_TARGET_READY = 8
104 STATE_LAST = 9 102 STATE_LAST = 9
105 103
106 STATE_CONNECT_PENDING = STATE_LAST + 1 104 STATE_CONNECT_PENDING = STATE_LAST + 1
107 105
108 SOCKS5_VER = 0x05 106 SOCKS5_VER = 0x05
109 107
137 @param sid: session id 135 @param sid: session id
138 @return: hash (string)""" 136 @return: hash (string)"""
139 return hashlib.sha1((sid + from_jid.full() + to_jid.full()).encode('utf-8')).hexdigest() 137 return hashlib.sha1((sid + from_jid.full() + to_jid.full()).encode('utf-8')).hexdigest()
140 138
141 139
142
143 class SOCKSv5(protocol.Protocol, FileSender): 140 class SOCKSv5(protocol.Protocol, FileSender):
144 def __init__(self): 141 def __init__(self):
145 debug(_("Protocol init")) 142 debug(_("Protocol init"))
146 self.state = STATE_INITIAL 143 self.state = STATE_INITIAL
147 self.buf = "" 144 self.buf = ""
148 self.supportedAuthMechs = [ AUTHMECH_ANON ] 145 self.supportedAuthMechs = [AUTHMECH_ANON]
149 self.supportedAddrs = [ ADDR_DOMAINNAME ] 146 self.supportedAddrs = [ADDR_DOMAINNAME]
150 self.enabledCommands = [ CMD_CONNECT ] 147 self.enabledCommands = [CMD_CONNECT]
151 self.peersock = None 148 self.peersock = None
152 self.addressType = 0 149 self.addressType = 0
153 self.requestType = 0 150 self.requestType = 0
154 151
155 def _startNegotiation(self): 152 def _startNegotiation(self):
160 def _parseNegotiation(self): 157 def _parseNegotiation(self):
161 debug("_parseNegotiation") 158 debug("_parseNegotiation")
162 try: 159 try:
163 # Parse out data 160 # Parse out data
164 ver, nmethod = struct.unpack('!BB', self.buf[:2]) 161 ver, nmethod = struct.unpack('!BB', self.buf[:2])
165 methods = struct.unpack('%dB' % nmethod, self.buf[2:nmethod+2]) 162 methods = struct.unpack('%dB' % nmethod, self.buf[2:nmethod + 2])
166 163
167 # Ensure version is correct 164 # Ensure version is correct
168 if ver != 5: 165 if ver != 5:
169 self.transport.write(struct.pack('!BB', SOCKS5_VER, AUTHMECH_INVALID)) 166 self.transport.write(struct.pack('!BB', SOCKS5_VER, AUTHMECH_INVALID))
170 self.transport.loseConnection() 167 self.transport.loseConnection()
171 return 168 return
172 169
173 # Trim off front of the buffer 170 # Trim off front of the buffer
174 self.buf = self.buf[nmethod+2:] 171 self.buf = self.buf[nmethod + 2:]
175 172
176 # Check for supported auth mechs 173 # Check for supported auth mechs
177 for m in self.supportedAuthMechs: 174 for m in self.supportedAuthMechs:
178 if m in methods: 175 if m in methods:
179 # Update internal state, according to selected method 176 # Update internal state, according to selected method
318 315
319 def connectRequested(self, addr, port): 316 def connectRequested(self, addr, port):
320 debug("connectRequested") 317 debug("connectRequested")
321 318
322 # Check that this session is expected 319 # Check that this session is expected
323 if not self.factory.hash_sid_map.has_key(addr): 320 if addr not in self.factory.hash_sid_map:
324 #no: we refuse it 321 #no: we refuse it
325 self.sendErrorReply(REPLY_CONN_REFUSED) 322 self.sendErrorReply(REPLY_CONN_REFUSED)
326 return 323 return
327 self.sid, self.profile = self.factory.hash_sid_map[addr] 324 self.sid, self.profile = self.factory.hash_sid_map[addr]
328 client = self.factory.host.getClient(self.profile) 325 client = self.factory.host.getClient(self.profile)
372 if self.state == STATE_REQUEST: 369 if self.state == STATE_REQUEST:
373 self._parseRequest() 370 self._parseRequest()
374 if self.state == STATE_TARGET_AUTH: 371 if self.state == STATE_TARGET_AUTH:
375 ver, method = struct.unpack('!BB', buf) 372 ver, method = struct.unpack('!BB', buf)
376 self.buf = self.buf[2:] 373 self.buf = self.buf[2:]
377 if ver!=SOCKS5_VER or method!=AUTHMECH_ANON: 374 if ver != SOCKS5_VER or method != AUTHMECH_ANON:
378 self.transport.loseConnection() 375 self.transport.loseConnection()
379 else: 376 else:
380 self._makeRequest() 377 self._makeRequest()
381 if self.state == STATE_TARGET_REQUEST: 378 if self.state == STATE_TARGET_REQUEST:
382 self._parseRequestReply() 379 self._parseRequestReply()
383 380
384
385 def clientConnectionLost(self, reason): 381 def clientConnectionLost(self, reason):
386 debug("clientConnectionLost") 382 debug("clientConnectionLost")
387 self.transport.loseConnection() 383 self.transport.loseConnection()
388 384
389 def connectionLost(self, reason): 385 def connectionLost(self, reason):
390 debug("connectionLost") 386 debug("connectionLost")
391 if self.state != STATE_CONNECT_PENDING: 387 if self.state != STATE_CONNECT_PENDING:
392 self.transport.unregisterProducer() 388 self.transport.unregisterProducer()
393 if self.peersock != None: 389 if self.peersock is not None:
394 self.peersock.peersock = None 390 self.peersock.peersock = None
395 self.peersock.transport.unregisterProducer() 391 self.peersock.transport.unregisterProducer()
396 self.peersock = None 392 self.peersock = None
397 393
398 394
403 self.host = host 399 self.host = host
404 self.hash_sid_map = hash_sid_map 400 self.hash_sid_map = hash_sid_map
405 self.finishedCb = finishedCb 401 self.finishedCb = finishedCb
406 402
407 def startedConnecting(self, connector): 403 def startedConnecting(self, connector):
408 debug (_("Socks 5 server connection started")) 404 debug(_("Socks 5 server connection started"))
409 405
410 def clientConnectionLost(self, connector, reason): 406 def clientConnectionLost(self, connector, reason):
411 debug (_("Socks 5 server connection lost (reason: %s)"), reason) 407 debug(_("Socks 5 server connection lost (reason: %s)"), reason)
408
412 409
413 class Socks5ClientFactory(protocol.ClientFactory): 410 class Socks5ClientFactory(protocol.ClientFactory):
414 protocol = SOCKSv5 411 protocol = SOCKSv5
415 412
416 def __init__(self, current_stream, sid, iq_id, activateCb, finishedCb, proxy=False, profile=None): 413 def __init__(self, current_stream, sid, iq_id, activateCb, finishedCb, proxy=False, profile=None):
430 self.finishedCb = finishedCb 427 self.finishedCb = finishedCb
431 self.proxy = proxy 428 self.proxy = proxy
432 self.profile = profile 429 self.profile = profile
433 430
434 def startedConnecting(self, connector): 431 def startedConnecting(self, connector):
435 debug (_("Socks 5 client connection started")) 432 debug(_("Socks 5 client connection started"))
436 433
437 def clientConnectionLost(self, connector, reason): 434 def clientConnectionLost(self, connector, reason):
438 debug (_("Socks 5 client connection lost (reason: %s)"), reason) 435 debug(_("Socks 5 client connection lost (reason: %s)"), reason)
439 self.finishedCb(self.sid, reason.type == jab_error.ConnectionDone, self.profile) #TODO: really check if the state is actually successful 436 self.finishedCb(self.sid, reason.type == jab_error.ConnectionDone, self.profile) # TODO: really check if the state is actually successful
440 437
441 438
442 class XEP_0065(object): 439 class XEP_0065(object):
443 440
444 NAMESPACE = NS_BS 441 NAMESPACE = NS_BS
463 460
464 def __init__(self, host): 461 def __init__(self, host):
465 info(_("Plugin XEP_0065 initialization")) 462 info(_("Plugin XEP_0065 initialization"))
466 463
467 #session data 464 #session data
468 self.hash_sid_map = {} #key: hash of the transfer session, value: (session id, profile) 465 self.hash_sid_map = {} # key: hash of the transfer session, value: (session id, profile)
469 466
470 self.host = host 467 self.host = host
471 debug(_("registering")) 468 debug(_("registering"))
472 self.server_factory = Socks5ServerFactory(host, self.hash_sid_map, lambda sid, success, profile: self._killId(sid, success, profile=profile)) 469 self.server_factory = Socks5ServerFactory(host, self.hash_sid_map, lambda sid, success, profile: self._killId(sid, success, profile=profile))
473 470
484 481
485 def profileConnected(self, profile): 482 def profileConnected(self, profile):
486 client = self.host.getClient(profile) 483 client = self.host.getClient(profile)
487 if not client: 484 if not client:
488 raise ProfileNotInCacheError 485 raise ProfileNotInCacheError
489 client.xep_0065_current_stream = {} #key: stream_id, value: data(dict) 486 client.xep_0065_current_stream = {} # key: stream_id, value: data(dict)
490 487
491 def getExternalIP(self): 488 def getExternalIP(self):
492 """Return IP visible from outside, by asking to a website""" 489 """Return IP visible from outside, by asking to a website"""
493 return getPage("http://www.goffi.org/sat_tools/get_ip.php") 490 return getPage("http://www.goffi.org/sat_tools/get_ip.php")
494 491
516 assert(profile) 513 assert(profile)
517 client = self.host.getClient(profile) 514 client = self.host.getClient(profile)
518 if not client: 515 if not client:
519 warning(_("Client no more in cache")) 516 warning(_("Client no more in cache"))
520 return 517 return
521 if not client.xep_0065_current_stream.has_key(sid): 518 if sid not in client.xep_0065_current_stream:
522 warning(_("kill id called on a non existant id")) 519 warning(_("kill id called on a non existant id"))
523 return 520 return
524 if client.xep_0065_current_stream[sid].has_key("observer_cb"): 521 if "observer_cb" in client.xep_0065_current_stream[sid]:
525 xmlstream = client.xep_0065_current_stream[sid]["xmlstream"] 522 xmlstream = client.xep_0065_current_stream[sid]["xmlstream"]
526 xmlstream.removeObserver(client.xep_0065_current_stream[sid]["event_data"], client.xep_0065_current_stream[sid]["observer_cb"]) 523 xmlstream.removeObserver(client.xep_0065_current_stream[sid]["event_data"], client.xep_0065_current_stream[sid]["observer_cb"])
527 if client.xep_0065_current_stream[sid]['timer'].active(): 524 if client.xep_0065_current_stream[sid]['timer'].active():
528 client.xep_0065_current_stream[sid]['timer'].cancel() 525 client.xep_0065_current_stream[sid]['timer'].cancel()
529 if client.xep_0065_current_stream[sid].has_key("size"): 526 if "size" in client.xep_0065_current_stream[sid]:
530 self.host.removeProgressCB(sid, profile) 527 self.host.removeProgressCB(sid, profile)
531 528
532 file_obj = client.xep_0065_current_stream[sid]['file_obj'] 529 file_obj = client.xep_0065_current_stream[sid]['file_obj']
533 success_cb = client.xep_0065_current_stream[sid]['success_cb'] 530 success_cb = client.xep_0065_current_stream[sid]['success_cb']
534 failure_cb = client.xep_0065_current_stream[sid]['failure_cb'] 531 failure_cb = client.xep_0065_current_stream[sid]['failure_cb']
542 if success: 539 if success:
543 success_cb(sid, file_obj, NS_BS, profile) 540 success_cb(sid, file_obj, NS_BS, profile)
544 else: 541 else:
545 failure_cb(sid, file_obj, NS_BS, failure_reason, profile) 542 failure_cb(sid, file_obj, NS_BS, failure_reason, profile)
546 543
547 def startStream(self, file_obj, to_jid, sid, length, successCb, failureCb, size = None, profile=None): 544 def startStream(self, file_obj, to_jid, sid, length, successCb, failureCb, size=None, profile=None):
548 """Launch the stream workflow 545 """Launch the stream workflow
549 @param file_obj: file_obj to send 546 @param file_obj: file_obj to send
550 @param to_jid: JID of the recipient 547 @param to_jid: JID of the recipient
551 @param sid: Stream session id 548 @param sid: Stream session id
552 @param length: number of byte to send, or None to send until the end 549 @param length: number of byte to send, or None to send until the end
557 client = self.host.getClient(profile) 554 client = self.host.getClient(profile)
558 if not client: 555 if not client:
559 error(_("Unknown profile, this should not happen")) 556 error(_("Unknown profile, this should not happen"))
560 raise ProfileNotInCacheError 557 raise ProfileNotInCacheError
561 558
562 if length != None: 559 if length is not None:
563 error(_('stream length not managed yet')) 560 error(_('stream length not managed yet'))
564 return 561 return
565 562
566 profile_jid = client.jid 563 profile_jid = client.jid
567 xmlstream = client.xmlstream 564 xmlstream = client.xmlstream
577 data["hash"] = calculateHash(profile_jid, to_jid, sid) 574 data["hash"] = calculateHash(profile_jid, to_jid, sid)
578 self.hash_sid_map[data["hash"]] = (sid, profile) 575 self.hash_sid_map[data["hash"]] = (sid, profile)
579 if size: 576 if size:
580 data["size"] = size 577 data["size"] = size
581 self.host.registerProgressCB(sid, self.getProgress, profile) 578 self.host.registerProgressCB(sid, self.getProgress, profile)
582 iq_elt = jabber_client.IQ(xmlstream,'set') 579 iq_elt = jabber_client.IQ(xmlstream, 'set')
583 iq_elt["from"] = profile_jid.full() 580 iq_elt["from"] = profile_jid.full()
584 iq_elt["to"] = to_jid.full() 581 iq_elt["to"] = to_jid.full()
585 query_elt = iq_elt.addElement('query', NS_BS) 582 query_elt = iq_elt.addElement('query', NS_BS)
586 query_elt['mode'] = 'tcp' 583 query_elt['mode'] = 'tcp'
587 query_elt['sid'] = sid 584 query_elt['sid'] = sid
636 warning(_("Proxy jid is not the same as in parameters, this should not happen")) 633 warning(_("Proxy jid is not the same as in parameters, this should not happen"))
637 return 634 return
638 factory = Socks5ClientFactory(client.xep_0065_current_stream, sid, None, self.activateProxyStream, lambda sid, success, profile: self._killId(sid, success, profile=profile), True, profile) 635 factory = Socks5ClientFactory(client.xep_0065_current_stream, sid, None, self.activateProxyStream, lambda sid, success, profile: self._killId(sid, success, profile=profile), True, profile)
639 reactor.connectTCP(proxy_host, int(proxy_port), factory) 636 reactor.connectTCP(proxy_host, int(proxy_port), factory)
640 else: 637 else:
641 data["start_transfer_cb"](file_obj) #We now activate the stream 638 data["start_transfer_cb"](file_obj) # We now activate the stream
642 639
643 def activateProxyStream(self, sid, iq_id, start_transfer_cb, profile): 640 def activateProxyStream(self, sid, iq_id, start_transfer_cb, profile):
644 debug(_("activating stream")) 641 debug(_("activating stream"))
645 client = self.host.getClient(profile) 642 client = self.host.getClient(profile)
646 if not client: 643 if not client:
647 raise ProfileNotInCacheError 644 raise ProfileNotInCacheError
648 data = client.xep_0065_current_stream[sid] 645 data = client.xep_0065_current_stream[sid]
649 profile_jid, xmlstream = self.host.getJidNStream(profile) 646 profile_jid, xmlstream = self.host.getJidNStream(profile)
650 647
651 iq_elt = client.IQ(xmlstream,'set') 648 iq_elt = client.IQ(xmlstream, 'set')
652 iq_elt["from"] = profile_jid.full() 649 iq_elt["from"] = profile_jid.full()
653 iq_elt["to"] = self.host.memory.getParamA("Proxy", "File Transfer", profile_key=profile) 650 iq_elt["to"] = self.host.memory.getParamA("Proxy", "File Transfer", profile_key=profile)
654 query_elt = iq_elt.addElement('query', NS_BS) 651 query_elt = iq_elt.addElement('query', NS_BS)
655 query_elt['sid'] = sid 652 query_elt['sid'] = sid
656 query_elt.addElement('activate', content=data['to'].full()) 653 query_elt.addElement('activate', content=data['to'].full())
685 self.host.registerProgressCB(sid, self.getProgress, profile) 682 self.host.registerProgressCB(sid, self.getProgress, profile)
686 data["timer"] = reactor.callLater(TIMEOUT, self._timeOut, sid, profile) 683 data["timer"] = reactor.callLater(TIMEOUT, self._timeOut, sid, profile)
687 data["success_cb"] = success_cb 684 data["success_cb"] = success_cb
688 data["failure_cb"] = failure_cb 685 data["failure_cb"] = failure_cb
689 686
690
691 def streamQuery(self, iq_elt, profile): 687 def streamQuery(self, iq_elt, profile):
692 """Get file using byte stream""" 688 """Get file using byte stream"""
693 debug(_("BS stream query")) 689 debug(_("BS stream query"))
694 client = self.host.getClient(profile) 690 client = self.host.getClient(profile)
695 691
715 if not streamhost_elts: 711 if not streamhost_elts:
716 warning(_("No streamhost found in stream query %s" % sid)) 712 warning(_("No streamhost found in stream query %s" % sid))
717 self.sendBadRequestError(iq_elt['id'], iq_elt['from'], xmlstream) 713 self.sendBadRequestError(iq_elt['id'], iq_elt['from'], xmlstream)
718 return 714 return
719 715
720 streamhost_elt = streamhost_elts[0] #TODO: manage several streamhost elements case 716 streamhost_elt = streamhost_elts[0] # TODO: manage several streamhost elements case
721 sh_host = streamhost_elt.getAttribute("host") 717 sh_host = streamhost_elt.getAttribute("host")
722 sh_port = streamhost_elt.getAttribute("port") 718 sh_port = streamhost_elt.getAttribute("port")
723 sh_jid = streamhost_elt.getAttribute("jid") 719 sh_jid = streamhost_elt.getAttribute("jid")
724 if not sh_host or not sh_port or not sh_jid: 720 if not sh_host or not sh_port or not sh_jid:
725 warning(_("incomplete streamhost element")) 721 warning(_("incomplete streamhost element"))
726 self.sendBadRequestError(iq_elt['id'], iq_elt['from'], xmlstream) 722 self.sendBadRequestError(iq_elt['id'], iq_elt['from'], xmlstream)
727 return 723 return
728 724
729 client.xep_0065_current_stream[sid]["streamhost"] = (sh_host, sh_port, sh_jid) 725 client.xep_0065_current_stream[sid]["streamhost"] = (sh_host, sh_port, sh_jid)
730 726
731 info (_("Stream proposed: host=[%(host)s] port=[%(port)s]") % {'host':sh_host, 'port':sh_port}) 727 info(_("Stream proposed: host=[%(host)s] port=[%(port)s]") % {'host': sh_host, 'port': sh_port})
732 factory = Socks5ClientFactory(client.xep_0065_current_stream, sid, iq_elt["id"], self.activateStream, lambda sid, success, profile: self._killId(sid, success, profile=profile), profile=profile) 728 factory = Socks5ClientFactory(client.xep_0065_current_stream, sid, iq_elt["id"], self.activateStream, lambda sid, success, profile: self._killId(sid, success, profile=profile), profile=profile)
733 reactor.connectTCP(sh_host, int(sh_port), factory) 729 reactor.connectTCP(sh_host, int(sh_port), factory)
734 730
735 def activateStream(self, sid, iq_id, profile): 731 def activateStream(self, sid, iq_id, profile):
736 client = self.host.getClient(profile) 732 client = self.host.getClient(profile)
758 result['type'] = 'result' 754 result['type'] = 'result'
759 result['id'] = iq_id 755 result['id'] = iq_id
760 result['to'] = to_jid 756 result['to'] = to_jid
761 error_el = result.addElement('error') 757 error_el = result.addElement('error')
762 error_el['type'] = 'modify' 758 error_el['type'] = 'modify'
763 error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas','not-acceptable')) 759 error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas', 'not-acceptable'))
764 xmlstream.send(result) 760 xmlstream.send(result)
765 761
766 def sendBadRequestError(self, iq_id, to_jid, xmlstream): 762 def sendBadRequestError(self, iq_id, to_jid, xmlstream):
767 """Not acceptable error used when the stream is not expected or something is going wrong 763 """Not acceptable error used when the stream is not expected or something is going wrong
768 @param iq_id: IQ id 764 @param iq_id: IQ id
772 result['type'] = 'result' 768 result['type'] = 'result'
773 result['id'] = iq_id 769 result['id'] = iq_id
774 result['to'] = to_jid 770 result['to'] = to_jid
775 error_el = result.addElement('error') 771 error_el = result.addElement('error')
776 error_el['type'] = 'cancel' 772 error_el['type'] = 'cancel'
777 error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas','bad-request')) 773 error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas', 'bad-request'))
778 xmlstream.send(result) 774 xmlstream.send(result)
775
779 776
780 class XEP_0065_handler(XMPPHandler): 777 class XEP_0065_handler(XMPPHandler):
781 implements(iwokkel.IDisco) 778 implements(iwokkel.IDisco)
782 779
783 def __init__(self, plugin_parent): 780 def __init__(self, plugin_parent):
799 warning(_("No streamhost found in stream query")) 796 warning(_("No streamhost found in stream query"))
800 return 797 return
801 if len(streamhost_elts) != 1: 798 if len(streamhost_elts) != 1:
802 warning(_("Multiple streamhost elements in proxy not managed, keeping only the first one")) 799 warning(_("Multiple streamhost elements in proxy not managed, keeping only the first one"))
803 streamhost_elt = streamhost_elts[0] 800 streamhost_elt = streamhost_elts[0]
804 proxy = self.host.memory.setParam("Proxy", streamhost_elt.getAttribute("jid",""), "File Transfer", self.parent.profile) 801 proxy = self.host.memory.setParam("Proxy", streamhost_elt.getAttribute("jid", ""), "File Transfer", self.parent.profile)
805 proxy = self.host.memory.setParam("Proxy host", streamhost_elt.getAttribute("host",""), "File Transfer", self.parent.profile) 802 proxy = self.host.memory.setParam("Proxy host", streamhost_elt.getAttribute("host", ""), "File Transfer", self.parent.profile)
806 proxy = self.host.memory.setParam("Proxy port", streamhost_elt.getAttribute("port",""), "File Transfer", self.parent.profile) 803 proxy = self.host.memory.setParam("Proxy port", streamhost_elt.getAttribute("port", ""), "File Transfer", self.parent.profile)
807
808 804
809 def connectionInitialized(self): 805 def connectionInitialized(self):
810 def after_init(ignore): 806 def after_init(ignore):
811 proxy_ent = self.host.memory.getServerServiceEntity("proxy", "bytestreams", self.parent.profile) 807 proxy_ent = self.host.memory.getServerServiceEntity("proxy", "bytestreams", self.parent.profile)
812 if not proxy_ent: 808 if not proxy_ent:
813 debug(_("No proxy found on this server")) 809 debug(_("No proxy found on this server"))
814 return 810 return
815 iq_elt = jabber_client.IQ(self.parent.xmlstream,'get') 811 iq_elt = jabber_client.IQ(self.parent.xmlstream, 'get')
816 iq_elt["to"] = proxy_ent.full() 812 iq_elt["to"] = proxy_ent.full()
817 query_elt = iq_elt.addElement('query', NS_BS) 813 query_elt = iq_elt.addElement('query', NS_BS)
818 iq_elt.addCallback(self._proxyDataResult) 814 iq_elt.addCallback(self._proxyDataResult)
819 iq_elt.send() 815 iq_elt.send()
820 816
821 817 self.xmlstream.addObserver(BS_REQUEST, self.plugin_parent.streamQuery, profile=self.parent.profile)
822 self.xmlstream.addObserver(BS_REQUEST, self.plugin_parent.streamQuery, profile = self.parent.profile) 818 proxy = self.host.memory.getParamA("Proxy", "File Transfer", profile_key=self.parent.profile)
823 proxy = self.host.memory.getParamA("Proxy", "File Transfer", profile_key = self.parent.profile)
824 if not proxy: 819 if not proxy:
825 self.parent.client_initialized.addCallback(after_init) 820 self.parent.client_initialized.addCallback(after_init)
826 821
827
828
829 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): 822 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
830 return [disco.DiscoFeature(NS_BS)] 823 return [disco.DiscoFeature(NS_BS)]
831 824
832 def getDiscoItems(self, requestor, target, nodeIdentifier=''): 825 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
833 return [] 826 return []