Mercurial > libervia-backend
diff src/plugins/plugin_xep_0065.py @ 587:952322b1d490
Remove trailing whitespaces.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 18 Jan 2013 17:55:34 +0100 |
parents | 9902ec2d8d9b |
children | beaf6bec2fcd |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0065.py Fri Jan 18 17:55:27 2013 +0100 +++ b/src/plugins/plugin_xep_0065.py Fri Jan 18 17:55:34 2013 +0100 @@ -32,7 +32,7 @@ Here is a copy of the original license: -Copyright (C) +Copyright (C) 2002-2004 Dave Smith (dizzyd@jabber.org) 2007-2008 Fabio Forno (xmpp:ff@jabber.bluendo.com) @@ -172,7 +172,7 @@ # Trim off front of the buffer self.buf = self.buf[nmethod+2:] - + # Check for supported auth mechs for m in self.supportedAuthMechs: if m in methods: @@ -219,7 +219,7 @@ result = struct.pack('!BBBBIH', SOCKS5_VER, errorcode, 0, 1, 0, 0) self.transport.write(result) self.transport.loseConnection() - + def _parseRequest(self): debug("_parseRequest") try: @@ -235,7 +235,7 @@ if self.addressType == ADDR_IPV4: addr, port = struct.unpack('!IH', self.buf[4:10]) self.buf = self.buf[10:] - elif self.addressType == ADDR_DOMAINNAME: + elif self.addressType == ADDR_DOMAINNAME: nlen = ord(self.buf[4]) addr, port = struct.unpack('!%dsH' % nlen, self.buf[5:]) self.buf = self.buf[7 + len(addr):] @@ -282,7 +282,7 @@ if self.addressType == ADDR_IPV4: addr, port = struct.unpack('!IH', self.buf[4:10]) self.buf = self.buf[10:] - elif self.addressType == ADDR_DOMAINNAME: + elif self.addressType == ADDR_DOMAINNAME: nlen = ord(self.buf[4]) addr, port = struct.unpack('!%dsH' % nlen, self.buf[5:]) self.buf = self.buf[7 + len(addr):] @@ -308,7 +308,7 @@ def connectionMade(self): debug("connectionMade (mode = %s)" % "requester" if isinstance(self.factory, Socks5ServerFactory) else "target") - + if isinstance(self.factory, Socks5ClientFactory): self.sid = self.factory.sid self.profile = self.factory.profile @@ -318,7 +318,7 @@ def connectRequested(self, addr, port): debug("connectRequested") - + # Check that this session is expected if not self.factory.hash_sid_map.has_key(addr): #no: we refuse it @@ -336,7 +336,7 @@ """Callback called when the result iq is received""" d = self.beginFileTransfer(file_obj, self.transport) d.addCallback(self.fileTransfered) - + def fileTransfered(self, d): info(_("File transfer completed, closing connection")) self.transport.loseConnection() @@ -351,10 +351,10 @@ ADDR_DOMAINNAME, len(remotehost), remotehost, remoteport) self.transport.write(result) self.state = STATE_READY - + def bindRequested(self, addr, port): pass - + def authenticateUserPass(self, user, passwd): debug("User/pass: %s/%s", user, passwd) return True @@ -440,7 +440,7 @@ class XEP_0065(): - + NAMESPACE = NS_BS params = """ @@ -463,10 +463,10 @@ def __init__(self, host): info(_("Plugin XEP_0065 initialization")) - + #session data self.hash_sid_map = {} #key: hash of the transfer session, value: (session id, profile) - + self.host = host debug(_("registering")) self.server_factory = Socks5ServerFactory(host, self.hash_sid_map, lambda sid, success, profile: self._killId(sid, success, profile=profile)) @@ -475,13 +475,13 @@ host.memory.importParams(XEP_0065.params) host.memory.setDefault("IP", "File Transfer", self.getExternalIP) port = int(self.host.memory.getParamA("Port", "File Transfer")) - + info(_("Launching Socks5 Stream server on port %d"), port) reactor.listenTCP(port, self.server_factory) - + def getHandler(self, profile): - return XEP_0065_handler(self) - + return XEP_0065_handler(self) + def profileConnected(self, profile): client = self.host.getClient(profile) if not client: @@ -503,13 +503,13 @@ data["size"] = str(client.xep_0065_current_stream[sid]["size"]) except: pass - + def _timeOut(self, sid, profile): """Delecte current_stream id, called after timeout @param id: id of client.xep_0065_current_stream""" info(_("Socks5 Bytestream: TimeOut reached for id %s [%s]") % (sid, profile)) self._killId(sid, False, "TIMEOUT", profile) - + def _killId(self, sid, success=False, failure_reason="UNKNOWN", profile=None): """Delete an current_stream id, clean up associated observers @param sid: id of client.xep_0065_current_stream""" @@ -528,11 +528,11 @@ client.xep_0065_current_stream[sid]['timer'].cancel() if client.xep_0065_current_stream[sid].has_key("size"): self.host.removeProgressCB(sid, profile) - + file_obj = client.xep_0065_current_stream[sid]['file_obj'] success_cb = client.xep_0065_current_stream[sid]['success_cb'] failure_cb = client.xep_0065_current_stream[sid]['failure_cb'] - + session_hash = client.xep_0065_current_stream[sid].get('hash') del client.xep_0065_current_stream[sid] if session_hash in self.hash_sid_map: @@ -558,14 +558,14 @@ if not client: error(_("Unknown profile, this should not happen")) raise ProfileNotInCacheError - + if length != None: error(_('stream length not managed yet')) return - + profile_jid = client.jid xmlstream = client.xmlstream - + data = client.xep_0065_current_stream[sid] = {} data["timer"] = reactor.callLater(TIMEOUT, self._timeOut, sid, profile) data["file_obj"] = file_obj @@ -615,10 +615,10 @@ except KeyError: error(_("Internal error, can't do transfer")) return - + if timer.active(): timer.cancel() - + profile_jid, xmlstream = self.host.getJidNStream(profile) query_elt = iq_elt.firstChildElement() streamhost_elts = filter(lambda elt: elt.name == 'streamhost-used', query_elt.elements()) @@ -686,23 +686,23 @@ data["timer"] = reactor.callLater(TIMEOUT, self._timeOut, sid, profile) data["success_cb"] = success_cb data["failure_cb"] = failure_cb - - + + def streamQuery(self, iq_elt, profile): """Get file using byte stream""" debug(_("BS stream query")) client = self.host.getClient(profile) - + if not client: raise ProfileNotInCacheError - + xmlstream = client.xmlstream iq_elt.handled = True query_elt = iq_elt.firstChildElement() sid = query_elt.getAttribute("sid") streamhost_elts = filter(lambda elt: elt.name == 'streamhost', query_elt.elements()) - + if not sid in client.xep_0065_current_stream: warning(_("Ignoring unexpected BS transfer: %s" % sid)) self.sendNotAcceptableError(iq_elt['id'], iq_elt['from'], xmlstream) @@ -731,7 +731,7 @@ info (_("Stream proposed: host=[%(host)s] port=[%(port)s]") % {'host':sh_host, 'port':sh_port}) 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) reactor.connectTCP(sh_host, int(sh_port), factory) - + def activateStream(self, sid, iq_id, profile): client = self.host.getClient(profile) if not client: @@ -757,7 +757,7 @@ result = domish.Element((None, 'iq')) result['type'] = 'result' result['id'] = iq_id - result['to'] = to_jid + result['to'] = to_jid error_el = result.addElement('error') error_el['type'] = 'modify' error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas','not-acceptable')) @@ -771,7 +771,7 @@ result = domish.Element((None, 'iq')) result['type'] = 'result' result['id'] = iq_id - result['to'] = to_jid + result['to'] = to_jid error_el = result.addElement('error') error_el['type'] = 'cancel' error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas','bad-request')) @@ -779,7 +779,7 @@ class XEP_0065_handler(XMPPHandler): implements(iwokkel.IDisco) - + def __init__(self, plugin_parent): self.plugin_parent = plugin_parent self.host = plugin_parent.host @@ -805,7 +805,7 @@ proxy = self.host.memory.setParam("Proxy host", streamhost_elt.getAttribute("host",""), "File Transfer", self.parent.profile) proxy = self.host.memory.setParam("Proxy port", streamhost_elt.getAttribute("port",""), "File Transfer", self.parent.profile) - + def connectionInitialized(self): def after_init(ignore): proxy_ent = self.host.memory.getServerServiceEntity("proxy", "bytestreams", self.parent.profile) @@ -823,7 +823,7 @@ proxy = self.host.memory.getParamA("Proxy", "File Transfer", profile_key = self.parent.profile) if not proxy: self.parent.client_initialized.addCallback(after_init) - + def getDiscoInfo(self, requestor, target, nodeIdentifier=''):