annotate src/plugins/plugin_xep_0065.py @ 1525:49d33cb48207

plugin file: first draft: This plugin will be used to manage file transfers, and choose the best available method. It embed a class dedicated to files: SatFile, which act as a file objects but manage some high level stuffs (like progression).
author Goffi <goffi@goffi.org>
date Fri, 25 Sep 2015 19:19:12 +0200
parents 3265a2639182
children 7cc29634b6ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #!/usr/bin/python
goffi@necton2
parents:
diff changeset
2 #-*- coding: utf-8 -*-
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
3
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
4 # SAT plugin for managing xep-0065
0
goffi@necton2
parents:
diff changeset
5
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
6 # Copyright (C)
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
7 # 2002, 2003, 2004 Dave Smith (dizzyd@jabber.org)
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
8 # 2007, 2008 Fabio Forno (xmpp:ff@jabber.bluendo.com)
1396
069ad98b360d 2015 copyright dates update
Goffi <goffi@goffi.org>
parents: 1226
diff changeset
9 # 2009, 2010, 2011, 2012, 2013, 2014, 2015 Jérôme Poisson (goffi@goffi.org)
0
goffi@necton2
parents:
diff changeset
10
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
11 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
12 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
13 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
14 # (at your option) any later version.
0
goffi@necton2
parents:
diff changeset
15
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
16 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
19 # GNU Affero General Public License for more details.
0
goffi@necton2
parents:
diff changeset
20
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
21 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
0
goffi@necton2
parents:
diff changeset
23
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
24 # --
0
goffi@necton2
parents:
diff changeset
25
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
26 # This program is based on proxy65 (http://code.google.com/p/proxy65),
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
27 # originaly written by David Smith and modified by Fabio Forno.
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
28 # It is sublicensed under AGPL v3 (or any later version) as allowed by the original
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
29 # license.
0
goffi@necton2
parents:
diff changeset
30
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
31 # --
0
goffi@necton2
parents:
diff changeset
32
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
33 # Here is a copy of the original license:
0
goffi@necton2
parents:
diff changeset
34
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
35 # Copyright (C)
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
36 # 2002-2004 Dave Smith (dizzyd@jabber.org)
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
37 # 2007-2008 Fabio Forno (xmpp:ff@jabber.bluendo.com)
0
goffi@necton2
parents:
diff changeset
38
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
39 # Permission is hereby granted, free of charge, to any person obtaining a copy
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
40 # of this software and associated documentation files (the "Software"), to deal
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
41 # in the Software without restriction, including without limitation the rights
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
42 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
43 # copies of the Software, and to permit persons to whom the Software is
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
44 # furnished to do so, subject to the following conditions:
0
goffi@necton2
parents:
diff changeset
45
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
46 # The above copyright notice and this permission notice shall be included in
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
47 # all copies or substantial portions of the Software.
0
goffi@necton2
parents:
diff changeset
48
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
49 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
50 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
51 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
52 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
53 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
54 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
55 # THE SOFTWARE.
0
goffi@necton2
parents:
diff changeset
56
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 742
diff changeset
57 from sat.core.i18n import _
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
58 from sat.core.log import getLogger
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
59 log = getLogger(__name__)
0
goffi@necton2
parents:
diff changeset
60 from twisted.internet import protocol, reactor
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
61 from twisted.internet import error
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
62 from twisted.words.protocols.jabber import jid, client as jabber_client
0
goffi@necton2
parents:
diff changeset
63 from twisted.protocols.basic import FileSender
goffi@necton2
parents:
diff changeset
64 from twisted.words.xish import domish
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
65 from twisted.web.client import getPage
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
66 from sat.core.exceptions import ProfileNotInCacheError
0
goffi@necton2
parents:
diff changeset
67 import struct
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
68 import hashlib
0
goffi@necton2
parents:
diff changeset
69
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 9
diff changeset
70 from zope.interface import implements
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 9
diff changeset
71
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 9
diff changeset
72 try:
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 9
diff changeset
73 from twisted.words.protocols.xmlstream import XMPPHandler
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 9
diff changeset
74 except ImportError:
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 9
diff changeset
75 from wokkel.subprotocols import XMPPHandler
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 9
diff changeset
76
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 9
diff changeset
77 from wokkel import disco, iwokkel
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 9
diff changeset
78
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 9
diff changeset
79 IQ_SET = '/iq[@type="set"]'
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 9
diff changeset
80 NS_BS = 'http://jabber.org/protocol/bytestreams'
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 9
diff changeset
81 BS_REQUEST = IQ_SET + '/query[@xmlns="' + NS_BS + '"]'
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
82 TIMEOUT = 60 # timeout for workflow
0
goffi@necton2
parents:
diff changeset
83
goffi@necton2
parents:
diff changeset
84 PLUGIN_INFO = {
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
85 "name": "XEP 0065 Plugin",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
86 "import_name": "XEP-0065",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
87 "type": "XEP",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
88 "protocols": ["XEP-0065"],
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
89 "main": "XEP_0065",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
90 "handler": "yes",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
91 "description": _("""Implementation of SOCKS5 Bytestreams""")
0
goffi@necton2
parents:
diff changeset
92 }
goffi@necton2
parents:
diff changeset
93
goffi@necton2
parents:
diff changeset
94 STATE_INITIAL = 0
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
95 STATE_AUTH = 1
0
goffi@necton2
parents:
diff changeset
96 STATE_REQUEST = 2
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
97 STATE_READY = 3
0
goffi@necton2
parents:
diff changeset
98 STATE_AUTH_USERPASS = 4
goffi@necton2
parents:
diff changeset
99 STATE_TARGET_INITIAL = 5
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
100 STATE_TARGET_AUTH = 6
0
goffi@necton2
parents:
diff changeset
101 STATE_TARGET_REQUEST = 7
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
102 STATE_TARGET_READY = 8
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
103 STATE_LAST = 9
0
goffi@necton2
parents:
diff changeset
104
goffi@necton2
parents:
diff changeset
105 STATE_CONNECT_PENDING = STATE_LAST + 1
goffi@necton2
parents:
diff changeset
106
goffi@necton2
parents:
diff changeset
107 SOCKS5_VER = 0x05
goffi@necton2
parents:
diff changeset
108
goffi@necton2
parents:
diff changeset
109 ADDR_IPV4 = 0x01
goffi@necton2
parents:
diff changeset
110 ADDR_DOMAINNAME = 0x03
goffi@necton2
parents:
diff changeset
111 ADDR_IPV6 = 0x04
goffi@necton2
parents:
diff changeset
112
goffi@necton2
parents:
diff changeset
113 CMD_CONNECT = 0x01
goffi@necton2
parents:
diff changeset
114 CMD_BIND = 0x02
goffi@necton2
parents:
diff changeset
115 CMD_UDPASSOC = 0x03
goffi@necton2
parents:
diff changeset
116
goffi@necton2
parents:
diff changeset
117 AUTHMECH_ANON = 0x00
goffi@necton2
parents:
diff changeset
118 AUTHMECH_USERPASS = 0x02
goffi@necton2
parents:
diff changeset
119 AUTHMECH_INVALID = 0xFF
goffi@necton2
parents:
diff changeset
120
goffi@necton2
parents:
diff changeset
121 REPLY_SUCCESS = 0x00
goffi@necton2
parents:
diff changeset
122 REPLY_GENERAL_FAILUR = 0x01
goffi@necton2
parents:
diff changeset
123 REPLY_CONN_NOT_ALLOWED = 0x02
goffi@necton2
parents:
diff changeset
124 REPLY_NETWORK_UNREACHABLE = 0x03
goffi@necton2
parents:
diff changeset
125 REPLY_HOST_UNREACHABLE = 0x04
goffi@necton2
parents:
diff changeset
126 REPLY_CONN_REFUSED = 0x05
goffi@necton2
parents:
diff changeset
127 REPLY_TTL_EXPIRED = 0x06
goffi@necton2
parents:
diff changeset
128 REPLY_CMD_NOT_SUPPORTED = 0x07
goffi@necton2
parents:
diff changeset
129 REPLY_ADDR_NOT_SUPPORTED = 0x08
goffi@necton2
parents:
diff changeset
130
goffi@necton2
parents:
diff changeset
131
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
132 def calculateHash(from_jid, to_jid, sid):
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
133 """Calculate SHA1 Hash according to XEP-0065
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
134 @param from_jid: jid of the requester
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
135 @param to_jid: jid of the target
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
136 @param sid: session id
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
137 @return: hash (string)"""
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
138 return hashlib.sha1((sid + from_jid.full() + to_jid.full()).encode('utf-8')).hexdigest()
0
goffi@necton2
parents:
diff changeset
139
goffi@necton2
parents:
diff changeset
140
goffi@necton2
parents:
diff changeset
141 class SOCKSv5(protocol.Protocol, FileSender):
goffi@necton2
parents:
diff changeset
142 def __init__(self):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
143 log.debug(_("Protocol init"))
0
goffi@necton2
parents:
diff changeset
144 self.state = STATE_INITIAL
goffi@necton2
parents:
diff changeset
145 self.buf = ""
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
146 self.supportedAuthMechs = [AUTHMECH_ANON]
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
147 self.supportedAddrs = [ADDR_DOMAINNAME]
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
148 self.enabledCommands = [CMD_CONNECT]
0
goffi@necton2
parents:
diff changeset
149 self.peersock = None
goffi@necton2
parents:
diff changeset
150 self.addressType = 0
goffi@necton2
parents:
diff changeset
151 self.requestType = 0
goffi@necton2
parents:
diff changeset
152
goffi@necton2
parents:
diff changeset
153 def _startNegotiation(self):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
154 log.debug("_startNegotiation")
0
goffi@necton2
parents:
diff changeset
155 self.state = STATE_TARGET_AUTH
goffi@necton2
parents:
diff changeset
156 self.transport.write(struct.pack('!3B', SOCKS5_VER, 1, AUTHMECH_ANON))
goffi@necton2
parents:
diff changeset
157
goffi@necton2
parents:
diff changeset
158 def _parseNegotiation(self):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
159 log.debug("_parseNegotiation")
0
goffi@necton2
parents:
diff changeset
160 try:
goffi@necton2
parents:
diff changeset
161 # Parse out data
goffi@necton2
parents:
diff changeset
162 ver, nmethod = struct.unpack('!BB', self.buf[:2])
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
163 methods = struct.unpack('%dB' % nmethod, self.buf[2:nmethod + 2])
0
goffi@necton2
parents:
diff changeset
164
goffi@necton2
parents:
diff changeset
165 # Ensure version is correct
goffi@necton2
parents:
diff changeset
166 if ver != 5:
goffi@necton2
parents:
diff changeset
167 self.transport.write(struct.pack('!BB', SOCKS5_VER, AUTHMECH_INVALID))
goffi@necton2
parents:
diff changeset
168 self.transport.loseConnection()
goffi@necton2
parents:
diff changeset
169 return
goffi@necton2
parents:
diff changeset
170
goffi@necton2
parents:
diff changeset
171 # Trim off front of the buffer
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
172 self.buf = self.buf[nmethod + 2:]
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
173
0
goffi@necton2
parents:
diff changeset
174 # Check for supported auth mechs
goffi@necton2
parents:
diff changeset
175 for m in self.supportedAuthMechs:
goffi@necton2
parents:
diff changeset
176 if m in methods:
goffi@necton2
parents:
diff changeset
177 # Update internal state, according to selected method
goffi@necton2
parents:
diff changeset
178 if m == AUTHMECH_ANON:
goffi@necton2
parents:
diff changeset
179 self.state = STATE_REQUEST
goffi@necton2
parents:
diff changeset
180 elif m == AUTHMECH_USERPASS:
goffi@necton2
parents:
diff changeset
181 self.state = STATE_AUTH_USERPASS
goffi@necton2
parents:
diff changeset
182 # Complete negotiation w/ this method
goffi@necton2
parents:
diff changeset
183 self.transport.write(struct.pack('!BB', SOCKS5_VER, m))
goffi@necton2
parents:
diff changeset
184 return
goffi@necton2
parents:
diff changeset
185
goffi@necton2
parents:
diff changeset
186 # No supported mechs found, notify client and close the connection
goffi@necton2
parents:
diff changeset
187 self.transport.write(struct.pack('!BB', SOCKS5_VER, AUTHMECH_INVALID))
goffi@necton2
parents:
diff changeset
188 self.transport.loseConnection()
goffi@necton2
parents:
diff changeset
189 except struct.error:
goffi@necton2
parents:
diff changeset
190 pass
goffi@necton2
parents:
diff changeset
191
goffi@necton2
parents:
diff changeset
192 def _parseUserPass(self):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
193 log.debug("_parseUserPass")
0
goffi@necton2
parents:
diff changeset
194 try:
goffi@necton2
parents:
diff changeset
195 # Parse out data
goffi@necton2
parents:
diff changeset
196 ver, ulen = struct.unpack('BB', self.buf[:2])
goffi@necton2
parents:
diff changeset
197 uname, = struct.unpack('%ds' % ulen, self.buf[2:ulen + 2])
goffi@necton2
parents:
diff changeset
198 plen, = struct.unpack('B', self.buf[ulen + 2])
goffi@necton2
parents:
diff changeset
199 password, = struct.unpack('%ds' % plen, self.buf[ulen + 3:ulen + 3 + plen])
goffi@necton2
parents:
diff changeset
200 # Trim off fron of the buffer
goffi@necton2
parents:
diff changeset
201 self.buf = self.buf[3 + ulen + plen:]
goffi@necton2
parents:
diff changeset
202 # Fire event to authenticate user
goffi@necton2
parents:
diff changeset
203 if self.authenticateUserPass(uname, password):
goffi@necton2
parents:
diff changeset
204 # Signal success
goffi@necton2
parents:
diff changeset
205 self.state = STATE_REQUEST
goffi@necton2
parents:
diff changeset
206 self.transport.write(struct.pack('!BB', SOCKS5_VER, 0x00))
goffi@necton2
parents:
diff changeset
207 else:
goffi@necton2
parents:
diff changeset
208 # Signal failure
goffi@necton2
parents:
diff changeset
209 self.transport.write(struct.pack('!BB', SOCKS5_VER, 0x01))
goffi@necton2
parents:
diff changeset
210 self.transport.loseConnection()
goffi@necton2
parents:
diff changeset
211 except struct.error:
goffi@necton2
parents:
diff changeset
212 pass
goffi@necton2
parents:
diff changeset
213
goffi@necton2
parents:
diff changeset
214 def sendErrorReply(self, errorcode):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
215 log.debug("sendErrorReply")
0
goffi@necton2
parents:
diff changeset
216 # Any other address types are not supported
goffi@necton2
parents:
diff changeset
217 result = struct.pack('!BBBBIH', SOCKS5_VER, errorcode, 0, 1, 0, 0)
goffi@necton2
parents:
diff changeset
218 self.transport.write(result)
goffi@necton2
parents:
diff changeset
219 self.transport.loseConnection()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
220
0
goffi@necton2
parents:
diff changeset
221 def _parseRequest(self):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
222 log.debug("_parseRequest")
0
goffi@necton2
parents:
diff changeset
223 try:
goffi@necton2
parents:
diff changeset
224 # Parse out data and trim buffer accordingly
goffi@necton2
parents:
diff changeset
225 ver, cmd, rsvd, self.addressType = struct.unpack('!BBBB', self.buf[:4])
goffi@necton2
parents:
diff changeset
226
goffi@necton2
parents:
diff changeset
227 # Ensure we actually support the requested address type
goffi@necton2
parents:
diff changeset
228 if self.addressType not in self.supportedAddrs:
goffi@necton2
parents:
diff changeset
229 self.sendErrorReply(REPLY_ADDR_NOT_SUPPORTED)
goffi@necton2
parents:
diff changeset
230 return
goffi@necton2
parents:
diff changeset
231
goffi@necton2
parents:
diff changeset
232 # Deal with addresses
goffi@necton2
parents:
diff changeset
233 if self.addressType == ADDR_IPV4:
goffi@necton2
parents:
diff changeset
234 addr, port = struct.unpack('!IH', self.buf[4:10])
goffi@necton2
parents:
diff changeset
235 self.buf = self.buf[10:]
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
236 elif self.addressType == ADDR_DOMAINNAME:
0
goffi@necton2
parents:
diff changeset
237 nlen = ord(self.buf[4])
goffi@necton2
parents:
diff changeset
238 addr, port = struct.unpack('!%dsH' % nlen, self.buf[5:])
goffi@necton2
parents:
diff changeset
239 self.buf = self.buf[7 + len(addr):]
goffi@necton2
parents:
diff changeset
240 else:
goffi@necton2
parents:
diff changeset
241 # Any other address types are not supported
goffi@necton2
parents:
diff changeset
242 self.sendErrorReply(REPLY_ADDR_NOT_SUPPORTED)
goffi@necton2
parents:
diff changeset
243 return
goffi@necton2
parents:
diff changeset
244
goffi@necton2
parents:
diff changeset
245 # Ensure command is supported
goffi@necton2
parents:
diff changeset
246 if cmd not in self.enabledCommands:
goffi@necton2
parents:
diff changeset
247 # Send a not supported error
goffi@necton2
parents:
diff changeset
248 self.sendErrorReply(REPLY_CMD_NOT_SUPPORTED)
goffi@necton2
parents:
diff changeset
249 return
goffi@necton2
parents:
diff changeset
250
goffi@necton2
parents:
diff changeset
251 # Process the command
goffi@necton2
parents:
diff changeset
252 if cmd == CMD_CONNECT:
goffi@necton2
parents:
diff changeset
253 self.connectRequested(addr, port)
goffi@necton2
parents:
diff changeset
254 elif cmd == CMD_BIND:
goffi@necton2
parents:
diff changeset
255 self.bindRequested(addr, port)
goffi@necton2
parents:
diff changeset
256 else:
goffi@necton2
parents:
diff changeset
257 # Any other command is not supported
goffi@necton2
parents:
diff changeset
258 self.sendErrorReply(REPLY_CMD_NOT_SUPPORTED)
goffi@necton2
parents:
diff changeset
259
941
c6d8fc63b1db core, plugins: host.getClient now raise an exception instead of returning None when no profile is found, plugins have been adapted consequently and a bit cleaned
Goffi <goffi@goffi.org>
parents: 811
diff changeset
260 except struct.error:
0
goffi@necton2
parents:
diff changeset
261 return None
goffi@necton2
parents:
diff changeset
262
goffi@necton2
parents:
diff changeset
263 def _makeRequest(self):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
264 log.debug("_makeRequest")
0
goffi@necton2
parents:
diff changeset
265 self.state = STATE_TARGET_REQUEST
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
266 sha1 = calculateHash(self.data["from"], self.data["to"], self.sid)
0
goffi@necton2
parents:
diff changeset
267 request = struct.pack('!5B%dsH' % len(sha1), SOCKS5_VER, CMD_CONNECT, 0, ADDR_DOMAINNAME, len(sha1), sha1, 0)
goffi@necton2
parents:
diff changeset
268 self.transport.write(request)
goffi@necton2
parents:
diff changeset
269
goffi@necton2
parents:
diff changeset
270 def _parseRequestReply(self):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
271 log.debug("_parseRequestReply")
0
goffi@necton2
parents:
diff changeset
272 try:
goffi@necton2
parents:
diff changeset
273 ver, rep, rsvd, self.addressType = struct.unpack('!BBBB', self.buf[:4])
goffi@necton2
parents:
diff changeset
274 # Ensure we actually support the requested address type
goffi@necton2
parents:
diff changeset
275 if self.addressType not in self.supportedAddrs:
goffi@necton2
parents:
diff changeset
276 self.sendErrorReply(REPLY_ADDR_NOT_SUPPORTED)
goffi@necton2
parents:
diff changeset
277 return
goffi@necton2
parents:
diff changeset
278
goffi@necton2
parents:
diff changeset
279 # Deal with addresses
goffi@necton2
parents:
diff changeset
280 if self.addressType == ADDR_IPV4:
goffi@necton2
parents:
diff changeset
281 addr, port = struct.unpack('!IH', self.buf[4:10])
goffi@necton2
parents:
diff changeset
282 self.buf = self.buf[10:]
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
283 elif self.addressType == ADDR_DOMAINNAME:
0
goffi@necton2
parents:
diff changeset
284 nlen = ord(self.buf[4])
goffi@necton2
parents:
diff changeset
285 addr, port = struct.unpack('!%dsH' % nlen, self.buf[5:])
goffi@necton2
parents:
diff changeset
286 self.buf = self.buf[7 + len(addr):]
goffi@necton2
parents:
diff changeset
287 else:
goffi@necton2
parents:
diff changeset
288 # Any other address types are not supported
goffi@necton2
parents:
diff changeset
289 self.sendErrorReply(REPLY_ADDR_NOT_SUPPORTED)
goffi@necton2
parents:
diff changeset
290 return
goffi@necton2
parents:
diff changeset
291
goffi@necton2
parents:
diff changeset
292 # Ensure reply is OK
goffi@necton2
parents:
diff changeset
293 if rep != REPLY_SUCCESS:
goffi@necton2
parents:
diff changeset
294 self.loseConnection()
goffi@necton2
parents:
diff changeset
295 return
goffi@necton2
parents:
diff changeset
296
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
297 if self.factory.proxy:
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
298 self.state = STATE_READY
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
299 self.factory.activateCb(self.sid, self.factory.iq_id, self.startTransfer, self.profile)
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
300 else:
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
301 self.state = STATE_TARGET_READY
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
302 self.factory.activateCb(self.sid, self.factory.iq_id, self.profile)
0
goffi@necton2
parents:
diff changeset
303
941
c6d8fc63b1db core, plugins: host.getClient now raise an exception instead of returning None when no profile is found, plugins have been adapted consequently and a bit cleaned
Goffi <goffi@goffi.org>
parents: 811
diff changeset
304 except struct.error:
0
goffi@necton2
parents:
diff changeset
305 return None
goffi@necton2
parents:
diff changeset
306
goffi@necton2
parents:
diff changeset
307 def connectionMade(self):
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
308 log.debug(u"connectionMade (mode = %s)" % "requester" if isinstance(self.factory, Socks5ServerFactory) else "target")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
309
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
310 if isinstance(self.factory, Socks5ClientFactory):
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
311 self.sid = self.factory.sid
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
312 self.profile = self.factory.profile
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
313 self.data = self.factory.data
0
goffi@necton2
parents:
diff changeset
314 self.state = STATE_TARGET_INITIAL
goffi@necton2
parents:
diff changeset
315 self._startNegotiation()
goffi@necton2
parents:
diff changeset
316
goffi@necton2
parents:
diff changeset
317 def connectRequested(self, addr, port):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
318 log.debug("connectRequested")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
319
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
320 # Check that this session is expected
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
321 if addr not in self.factory.hash_sid_map:
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
322 #no: we refuse it
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
323 self.sendErrorReply(REPLY_CONN_REFUSED)
0
goffi@necton2
parents:
diff changeset
324 return
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
325 self.sid, self.profile = self.factory.hash_sid_map[addr]
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
326 client = self.factory.host.getClient(self.profile)
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
327 client.xep_0065_current_stream[self.sid]["start_transfer_cb"] = self.startTransfer
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
328 self.connectCompleted(addr, 0)
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
329 self.transport.stopReading()
0
goffi@necton2
parents:
diff changeset
330
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
331 def startTransfer(self, file_obj):
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
332 """Callback called when the result iq is received"""
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
333 d = self.beginFileTransfer(file_obj, self.transport)
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
334 d.addCallback(self.fileTransfered)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
335
0
goffi@necton2
parents:
diff changeset
336 def fileTransfered(self, d):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
337 log.info(_("File transfer completed, closing connection"))
0
goffi@necton2
parents:
diff changeset
338 self.transport.loseConnection()
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
339 self.factory.finishedCb(self.sid, True, self.profile)
0
goffi@necton2
parents:
diff changeset
340
goffi@necton2
parents:
diff changeset
341 def connectCompleted(self, remotehost, remoteport):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
342 log.debug("connectCompleted")
0
goffi@necton2
parents:
diff changeset
343 if self.addressType == ADDR_IPV4:
goffi@necton2
parents:
diff changeset
344 result = struct.pack('!BBBBIH', SOCKS5_VER, REPLY_SUCCESS, 0, 1, remotehost, remoteport)
goffi@necton2
parents:
diff changeset
345 elif self.addressType == ADDR_DOMAINNAME:
goffi@necton2
parents:
diff changeset
346 result = struct.pack('!BBBBB%dsH' % len(remotehost), SOCKS5_VER, REPLY_SUCCESS, 0,
goffi@necton2
parents:
diff changeset
347 ADDR_DOMAINNAME, len(remotehost), remotehost, remoteport)
goffi@necton2
parents:
diff changeset
348 self.transport.write(result)
goffi@necton2
parents:
diff changeset
349 self.state = STATE_READY
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
350
0
goffi@necton2
parents:
diff changeset
351 def bindRequested(self, addr, port):
goffi@necton2
parents:
diff changeset
352 pass
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
353
0
goffi@necton2
parents:
diff changeset
354 def authenticateUserPass(self, user, passwd):
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
355 # FIXME: implement authentication and remove the debug printing a password
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
356 log.debug(u"User/pass: %s/%s" % (user, passwd))
0
goffi@necton2
parents:
diff changeset
357 return True
goffi@necton2
parents:
diff changeset
358
goffi@necton2
parents:
diff changeset
359 def dataReceived(self, buf):
goffi@necton2
parents:
diff changeset
360 if self.state == STATE_TARGET_READY:
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
361 self.data["file_obj"].write(buf)
0
goffi@necton2
parents:
diff changeset
362 return
goffi@necton2
parents:
diff changeset
363
goffi@necton2
parents:
diff changeset
364 self.buf = self.buf + buf
goffi@necton2
parents:
diff changeset
365 if self.state == STATE_INITIAL:
goffi@necton2
parents:
diff changeset
366 self._parseNegotiation()
goffi@necton2
parents:
diff changeset
367 if self.state == STATE_AUTH_USERPASS:
goffi@necton2
parents:
diff changeset
368 self._parseUserPass()
goffi@necton2
parents:
diff changeset
369 if self.state == STATE_REQUEST:
goffi@necton2
parents:
diff changeset
370 self._parseRequest()
goffi@necton2
parents:
diff changeset
371 if self.state == STATE_TARGET_AUTH:
goffi@necton2
parents:
diff changeset
372 ver, method = struct.unpack('!BB', buf)
goffi@necton2
parents:
diff changeset
373 self.buf = self.buf[2:]
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
374 if ver != SOCKS5_VER or method != AUTHMECH_ANON:
0
goffi@necton2
parents:
diff changeset
375 self.transport.loseConnection()
goffi@necton2
parents:
diff changeset
376 else:
goffi@necton2
parents:
diff changeset
377 self._makeRequest()
goffi@necton2
parents:
diff changeset
378 if self.state == STATE_TARGET_REQUEST:
goffi@necton2
parents:
diff changeset
379 self._parseRequestReply()
goffi@necton2
parents:
diff changeset
380
goffi@necton2
parents:
diff changeset
381 def clientConnectionLost(self, reason):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
382 log.debug("clientConnectionLost")
0
goffi@necton2
parents:
diff changeset
383 self.transport.loseConnection()
goffi@necton2
parents:
diff changeset
384
goffi@necton2
parents:
diff changeset
385 def connectionLost(self, reason):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
386 log.debug("connectionLost")
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
387 if self.state != STATE_CONNECT_PENDING:
0
goffi@necton2
parents:
diff changeset
388 self.transport.unregisterProducer()
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
389 if self.peersock is not None:
0
goffi@necton2
parents:
diff changeset
390 self.peersock.peersock = None
goffi@necton2
parents:
diff changeset
391 self.peersock.transport.unregisterProducer()
goffi@necton2
parents:
diff changeset
392 self.peersock = None
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
393
0
goffi@necton2
parents:
diff changeset
394
goffi@necton2
parents:
diff changeset
395 class Socks5ServerFactory(protocol.ServerFactory):
goffi@necton2
parents:
diff changeset
396 protocol = SOCKSv5
goffi@necton2
parents:
diff changeset
397
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
398 def __init__(self, host, hash_sid_map, finishedCb):
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
399 self.host = host
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
400 self.hash_sid_map = hash_sid_map
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
401 self.finishedCb = finishedCb
0
goffi@necton2
parents:
diff changeset
402
goffi@necton2
parents:
diff changeset
403 def startedConnecting(self, connector):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
404 log.debug(_("Socks 5 server connection started"))
0
goffi@necton2
parents:
diff changeset
405
goffi@necton2
parents:
diff changeset
406 def clientConnectionLost(self, connector, reason):
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
407 log.debug(_(u"Socks 5 server connection lost (reason: %s)") % reason)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
408
0
goffi@necton2
parents:
diff changeset
409
goffi@necton2
parents:
diff changeset
410 class Socks5ClientFactory(protocol.ClientFactory):
goffi@necton2
parents:
diff changeset
411 protocol = SOCKSv5
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
412
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
413 def __init__(self, current_stream, sid, iq_id, activateCb, finishedCb, proxy=False, profile=None):
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
414 """Init the Client Factory
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
415 @param current_stream: current streams data
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
416 @param sid: Session ID
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
417 @param iq_id: iq id used to initiate the stream
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
418 @param activateCb: method to call to activate the stream
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
419 @param finishedCb: method to call when the stream session is finished
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
420 @param proxy: True if we are connecting throught a proxy (and we are a requester)
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
421 @param profile: %(doc_profile)s"""
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
422 assert(profile)
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
423 self.data = current_stream[sid]
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
424 self.sid = sid
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
425 self.iq_id = iq_id
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
426 self.activateCb = activateCb
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
427 self.finishedCb = finishedCb
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
428 self.proxy = proxy
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
429 self.profile = profile
0
goffi@necton2
parents:
diff changeset
430
goffi@necton2
parents:
diff changeset
431 def startedConnecting(self, connector):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
432 log.debug(_("Socks 5 client connection started"))
0
goffi@necton2
parents:
diff changeset
433
goffi@necton2
parents:
diff changeset
434 def clientConnectionLost(self, connector, reason):
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
435 log.debug(_(u"Socks 5 client connection lost (reason: %s)") % reason)
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
436 self.finishedCb(self.sid, reason.type == error.ConnectionDone, self.profile) # TODO: really check if the state is actually successful
0
goffi@necton2
parents:
diff changeset
437
goffi@necton2
parents:
diff changeset
438
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
439 class XEP_0065(object):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
440
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
441 NAMESPACE = NS_BS
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
442
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
443 params = """
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
444 <params>
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
445 <general>
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
446 <category name="File Transfer">
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
447 <param name="IP" value='0.0.0.0' default_cb='yes' type="string" />
1226
72f25d671368 memory (params): use more generic param attribute "constraint" instead of "min" and "max"
souliane <souliane@mailoo.org>
parents: 1220
diff changeset
448 <param name="Port" value="28915" type="int" constraint="1;65535" />
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
449 </category>
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
450 </general>
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
451 <individual>
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
452 <category name="File Transfer">
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
453 <param name="Proxy" value="" type="string" />
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
454 <param name="Proxy host" value="" type="string" />
1226
72f25d671368 memory (params): use more generic param attribute "constraint" instead of "min" and "max"
souliane <souliane@mailoo.org>
parents: 1220
diff changeset
455 <param name="Proxy port" value="" type="int" constraint="1;65535" />
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
456 </category>
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
457 </individual>
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
458 </params>
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
459 """
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
460
0
goffi@necton2
parents:
diff changeset
461 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
462 log.info(_("Plugin XEP_0065 initialization"))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
463
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
464 #session data
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
465 self.hash_sid_map = {} # key: hash of the transfer session, value: (session id, profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
466
0
goffi@necton2
parents:
diff changeset
467 self.host = host
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
468 log.debug(_("registering"))
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
469 self.server_factory = Socks5ServerFactory(host, self.hash_sid_map, lambda sid, success, profile: self._killId(sid, success, profile=profile))
21
633c5ed65701 parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents: 20
diff changeset
470
633c5ed65701 parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents: 20
diff changeset
471 #parameters
662
4f747d7fde8c core: importParams renamed to updateParams: it now updates the parameter instead of appending children if it find an existing one.
Goffi <goffi@goffi.org>
parents: 641
diff changeset
472 host.memory.updateParams(XEP_0065.params)
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
473 host.memory.setDefault("IP", "File Transfer", self.getExternalIP)
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
474 port = int(self.host.memory.getParamA("Port", "File Transfer"))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
475
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
476 log.info(_("Launching Socks5 Stream server on port %d") % port)
0
goffi@necton2
parents:
diff changeset
477 reactor.listenTCP(port, self.server_factory)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
478
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 69
diff changeset
479 def getHandler(self, profile):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
480 return XEP_0065_handler(self)
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
481
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
482 def profileConnected(self, profile):
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
483 client = self.host.getClient(profile)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
484 client.xep_0065_current_stream = {} # key: stream_id, value: data(dict)
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
485
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
486 def getExternalIP(self):
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
487 """Return IP visible from outside, by asking to a website"""
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
488 return getPage("http://www.goffi.org/sat_tools/get_ip.php")
0
goffi@necton2
parents:
diff changeset
489
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
490 def getProgress(self, sid, data, profile):
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
491 """Fill data with position of current transfer"""
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
492 client = self.host.getClient(profile)
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
493 try:
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
494 file_obj = client.xep_0065_current_stream[sid]["file_obj"]
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
495 data["position"] = str(file_obj.tell())
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
496 data["size"] = str(client.xep_0065_current_stream[sid]["size"])
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
497 except:
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
498 pass
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
499
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
500 def _timeOut(self, sid, profile):
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
501 """Delecte current_stream id, called after timeout
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
502 @param id: id of client.xep_0065_current_stream"""
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
503 log.info(_("Socks5 Bytestream: TimeOut reached for id %(sid)s [%(profile)s]")
638
6821fc06a324 misc: a few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 609
diff changeset
504 % {"sid": sid, "profile": profile})
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
505 self._killId(sid, False, "TIMEOUT", profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
506
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
507 def _killId(self, sid, success=False, failure_reason="UNKNOWN", profile=None):
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
508 """Delete an current_stream id, clean up associated observers
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
509 @param sid: id of client.xep_0065_current_stream"""
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
510 assert(profile)
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
511 client = self.host.getClient(profile)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
512 if sid not in client.xep_0065_current_stream:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
513 log.warning(_("kill id called on a non existant id"))
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
514 return
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
515 if "observer_cb" in client.xep_0065_current_stream[sid]:
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
516 xmlstream = client.xep_0065_current_stream[sid]["xmlstream"]
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
517 xmlstream.removeObserver(client.xep_0065_current_stream[sid]["event_data"], client.xep_0065_current_stream[sid]["observer_cb"])
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
518 if client.xep_0065_current_stream[sid]['timer'].active():
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
519 client.xep_0065_current_stream[sid]['timer'].cancel()
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
520 if "size" in client.xep_0065_current_stream[sid]:
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
521 self.host.removeProgressCB(sid, profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
522
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
523 file_obj = client.xep_0065_current_stream[sid]['file_obj']
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
524 success_cb = client.xep_0065_current_stream[sid]['success_cb']
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
525 failure_cb = client.xep_0065_current_stream[sid]['failure_cb']
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
526
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
527 session_hash = client.xep_0065_current_stream[sid].get('hash')
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
528 del client.xep_0065_current_stream[sid]
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
529 if session_hash in self.hash_sid_map:
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
530 #FIXME: check that self.hash_sid_map is correctly cleaned in all cases (timeout, normal flow, etc).
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
531 del self.hash_sid_map[session_hash]
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
532
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
533 if success:
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
534 success_cb(sid, file_obj, NS_BS, profile)
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
535 else:
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
536 failure_cb(sid, file_obj, NS_BS, failure_reason, profile)
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
537
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
538 def startStream(self, file_obj, to_jid, sid, length, successCb, failureCb, size=None, profile=None):
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
539 """Launch the stream workflow
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
540 @param file_obj: file_obj to send
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
541 @param to_jid: JID of the recipient
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
542 @param sid: Stream session id
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
543 @param length: number of byte to send, or None to send until the end
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
544 @param successCb: method to call when stream successfuly finished
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
545 @param failureCb: method to call when something goes wrong
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
546 @param profile: %(doc_profile)s"""
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
547 assert(profile)
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
548 client = self.host.getClient(profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
549
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
550 if length is not None:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
551 log.error(_('stream length not managed yet'))
585
9902ec2d8d9b Remove useless trailing semicolons.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
552 return
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
553
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
554 profile_jid = client.jid
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
555 xmlstream = client.xmlstream
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
556
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
557 data = client.xep_0065_current_stream[sid] = {}
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
558 data["timer"] = reactor.callLater(TIMEOUT, self._timeOut, sid, profile)
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
559 data["file_obj"] = file_obj
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
560 data["from"] = profile_jid
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
561 data["to"] = to_jid
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
562 data["success_cb"] = successCb
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
563 data["failure_cb"] = failureCb
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
564 data["xmlstream"] = xmlstream
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
565 data["hash"] = calculateHash(profile_jid, to_jid, sid)
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
566 self.hash_sid_map[data["hash"]] = (sid, profile)
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
567 if size:
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
568 data["size"] = size
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
569 self.host.registerProgressCB(sid, self.getProgress, profile)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
570 iq_elt = jabber_client.IQ(xmlstream, 'set')
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
571 iq_elt["from"] = profile_jid.full()
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
572 iq_elt["to"] = to_jid.full()
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
573 query_elt = iq_elt.addElement('query', NS_BS)
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
574 query_elt['mode'] = 'tcp'
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
575 query_elt['sid'] = sid
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
576 #first streamhost: direct connection
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
577 streamhost = query_elt.addElement('streamhost')
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
578 streamhost['host'] = self.host.memory.getParamA("IP", "File Transfer")
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
579 streamhost['port'] = self.host.memory.getParamA("Port", "File Transfer")
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
580 streamhost['jid'] = profile_jid.full()
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
581
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
582 #second streamhost: mediated connection, using proxy
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
583 streamhost = query_elt.addElement('streamhost')
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
584 streamhost['host'] = self.host.memory.getParamA("Proxy host", "File Transfer", profile_key=profile)
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
585 streamhost['port'] = self.host.memory.getParamA("Proxy port", "File Transfer", profile_key=profile)
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
586 streamhost['jid'] = self.host.memory.getParamA("Proxy", "File Transfer", profile_key=profile)
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
587
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
588 iq_elt.addCallback(self.iqResult, sid, profile)
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
589 iq_elt.send()
0
goffi@necton2
parents:
diff changeset
590
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
591 def iqResult(self, sid, profile, iq_elt):
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
592 """Called when the result of open iq is received"""
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
593 if iq_elt["type"] == "error":
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
594 log.warning(_("Transfer failed"))
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
595 return
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
596 client = self.host.getClient(profile)
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
597 try:
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
598 data = client.xep_0065_current_stream[sid]
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
599 file_obj = data["file_obj"]
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
600 timer = data["timer"]
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
601 except KeyError:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
602 log.error(_("Internal error, can't do transfer"))
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
603 return
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
604
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
605 if timer.active():
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
606 timer.cancel()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
607
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
608 profile_jid, xmlstream = self.host.getJidNStream(profile)
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
609 query_elt = iq_elt.firstChildElement()
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
610 streamhost_elts = filter(lambda elt: elt.name == 'streamhost-used', query_elt.elements())
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
611 if not streamhost_elts:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
612 log.warning(_("No streamhost found in stream query"))
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
613 return
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
614
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
615 streamhost_jid = streamhost_elts[0]['jid']
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
616 if streamhost_jid != profile_jid.full():
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
617 log.debug(_("A proxy server is used"))
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
618 proxy_host = self.host.memory.getParamA("Proxy host", "File Transfer", profile_key=profile)
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
619 proxy_port = self.host.memory.getParamA("Proxy port", "File Transfer", profile_key=profile)
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
620 proxy_jid = self.host.memory.getParamA("Proxy", "File Transfer", profile_key=profile)
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
621 if proxy_jid != streamhost_jid:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
622 log.warning(_("Proxy jid is not the same as in parameters, this should not happen"))
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
623 return
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
624 factory = Socks5ClientFactory(client.xep_0065_current_stream, sid, None, self.activateProxyStream, lambda sid, success, profile: self._killId(sid, success, profile=profile), True, profile)
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
625 reactor.connectTCP(proxy_host, int(proxy_port), factory)
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
626 else:
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
627 data["start_transfer_cb"](file_obj) # We now activate the stream
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
628
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
629 def activateProxyStream(self, sid, iq_id, start_transfer_cb, profile):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
630 log.debug(_("activating stream"))
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
631 client = self.host.getClient(profile)
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
632 data = client.xep_0065_current_stream[sid]
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
633 profile_jid, xmlstream = self.host.getJidNStream(profile)
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
634
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
635 iq_elt = client.IQ(xmlstream, 'set')
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
636 iq_elt["from"] = profile_jid.full()
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
637 iq_elt["to"] = self.host.memory.getParamA("Proxy", "File Transfer", profile_key=profile)
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
638 query_elt = iq_elt.addElement('query', NS_BS)
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
639 query_elt['sid'] = sid
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
640 query_elt.addElement('activate', content=data['to'].full())
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
641 iq_elt.addCallback(self.proxyResult, sid, start_transfer_cb, data['file_obj'])
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
642 iq_elt.send()
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
643
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
644 def proxyResult(self, sid, start_transfer_cb, file_obj, iq_elt):
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
645 if iq_elt['type'] == 'error':
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
646 log.warning(_("Can't activate the proxy stream"))
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
647 return
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
648 else:
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
649 start_transfer_cb(file_obj)
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
650
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
651 def prepareToReceive(self, from_jid, sid, file_obj, size, success_cb, failure_cb, profile):
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
652 """Called when a bytestream is imminent
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
653 @param from_jid: jid of the sender
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
654 @param sid: Stream id
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
655 @param file_obj: File object where data will be written
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
656 @param size: full size of the data, or None if unknown
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
657 @param success_cb: method to call when successfuly finished
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
658 @param failure_cb: method to call when something goes wrong
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
659 @param profile: %(doc_profile)s"""
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
660 client = self.host.getClient(profile)
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
661 data = client.xep_0065_current_stream[sid] = {}
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
662 data["from"] = from_jid
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
663 data["file_obj"] = file_obj
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
664 data["seq"] = -1
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
665 if size:
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
666 data["size"] = size
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
667 self.host.registerProgressCB(sid, self.getProgress, profile)
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
668 data["timer"] = reactor.callLater(TIMEOUT, self._timeOut, sid, profile)
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
669 data["success_cb"] = success_cb
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
670 data["failure_cb"] = failure_cb
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
671
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
672 def streamQuery(self, iq_elt, profile):
0
goffi@necton2
parents:
diff changeset
673 """Get file using byte stream"""
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
674 log.debug(_("BS stream query"))
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
675 client = self.host.getClient(profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
676
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
677 if not client:
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
678 raise ProfileNotInCacheError
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
679
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
680 xmlstream = client.xmlstream
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
681
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
682 iq_elt.handled = True
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
683 query_elt = iq_elt.firstChildElement()
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
684 sid = query_elt.getAttribute("sid")
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
685 streamhost_elts = filter(lambda elt: elt.name == 'streamhost', query_elt.elements())
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
686
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
687 if not sid in client.xep_0065_current_stream:
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
688 log.warning(_(u"Ignoring unexpected BS transfer: %s" % sid))
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
689 self.sendNotAcceptableError(iq_elt['id'], iq_elt['from'], xmlstream)
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
690 return
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
691
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
692 client.xep_0065_current_stream[sid]['timer'].cancel()
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
693 client.xep_0065_current_stream[sid]["to"] = jid.JID(iq_elt["to"])
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
694 client.xep_0065_current_stream[sid]["xmlstream"] = xmlstream
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
695
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
696 if not streamhost_elts:
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
697 log.warning(_(u"No streamhost found in stream query %s" % sid))
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
698 self.sendBadRequestError(iq_elt['id'], iq_elt['from'], xmlstream)
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
699 return
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
700
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
701 streamhost_elt = streamhost_elts[0] # TODO: manage several streamhost elements case
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
702 sh_host = streamhost_elt.getAttribute("host")
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
703 sh_port = streamhost_elt.getAttribute("port")
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
704 sh_jid = streamhost_elt.getAttribute("jid")
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
705 if not sh_host or not sh_port or not sh_jid:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
706 log.warning(_("incomplete streamhost element"))
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
707 self.sendBadRequestError(iq_elt['id'], iq_elt['from'], xmlstream)
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
708 return
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
709
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
710 client.xep_0065_current_stream[sid]["streamhost"] = (sh_host, sh_port, sh_jid)
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
711
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
712 log.info(_("Stream proposed: host=[%(host)s] port=[%(port)s]") % {'host': sh_host, 'port': sh_port})
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
713 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)
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
714 reactor.connectTCP(sh_host, int(sh_port), factory)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
715
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
716 def activateStream(self, sid, iq_id, profile):
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
717 client = self.host.getClient(profile)
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
718 log.debug(_("activating stream"))
536
a31abb97310d core, plugins: fixed bad namespace in stanza creation
Goffi <goffi@goffi.org>
parents: 480
diff changeset
719 result = domish.Element((None, 'iq'))
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
720 data = client.xep_0065_current_stream[sid]
0
goffi@necton2
parents:
diff changeset
721 result['type'] = 'result'
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
722 result['id'] = iq_id
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
723 result['from'] = data["to"].full()
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
724 result['to'] = data["from"].full()
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
725 query = result.addElement('query', NS_BS)
0
goffi@necton2
parents:
diff changeset
726 query['sid'] = sid
goffi@necton2
parents:
diff changeset
727 streamhost = query.addElement('streamhost-used')
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
728 streamhost['jid'] = data["streamhost"][2]
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
729 data["xmlstream"].send(result)
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
730
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
731 def sendNotAcceptableError(self, iq_id, to_jid, xmlstream):
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
732 """Not acceptable error used when the stream is not expected or something is going wrong
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
733 @param iq_id: IQ id
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
734 @param to_jid: addressee
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
735 @param xmlstream: XML stream to use to send the error"""
536
a31abb97310d core, plugins: fixed bad namespace in stanza creation
Goffi <goffi@goffi.org>
parents: 480
diff changeset
736 result = domish.Element((None, 'iq'))
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
737 result['type'] = 'result'
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
738 result['id'] = iq_id
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
739 result['to'] = to_jid
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
740 error_el = result.addElement('error')
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
741 error_el['type'] = 'modify'
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
742 error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas', 'not-acceptable'))
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
743 xmlstream.send(result)
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
744
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
745 def sendBadRequestError(self, iq_id, to_jid, xmlstream):
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
746 """Not acceptable error used when the stream is not expected or something is going wrong
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
747 @param iq_id: IQ id
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
748 @param to_jid: addressee
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
749 @param xmlstream: XML stream to use to send the error"""
536
a31abb97310d core, plugins: fixed bad namespace in stanza creation
Goffi <goffi@goffi.org>
parents: 480
diff changeset
750 result = domish.Element((None, 'iq'))
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
751 result['type'] = 'result'
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
752 result['id'] = iq_id
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
753 result['to'] = to_jid
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
754 error_el = result.addElement('error')
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
755 error_el['type'] = 'cancel'
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
756 error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas', 'bad-request'))
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 60
diff changeset
757 xmlstream.send(result)
0
goffi@necton2
parents:
diff changeset
758
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
759
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 60
diff changeset
760 class XEP_0065_handler(XMPPHandler):
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 60
diff changeset
761 implements(iwokkel.IDisco)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
762
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 60
diff changeset
763 def __init__(self, plugin_parent):
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 60
diff changeset
764 self.plugin_parent = plugin_parent
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 60
diff changeset
765 self.host = plugin_parent.host
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
766
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
767 def _proxyDataResult(self, iq_elt):
1199
96fb74a4714d misc: fixed some typos
Matteo Cypriani <mcy@lm7.fr>
parents: 1179
diff changeset
768 """Called with the information about proxy according to XEP-0065 #4
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
769 Params should be filled with these infos"""
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
770 if iq_elt["type"] == "error":
1199
96fb74a4714d misc: fixed some typos
Matteo Cypriani <mcy@lm7.fr>
parents: 1179
diff changeset
771 log.warning(_("Can't determine proxy information"))
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
772 return
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
773 query_elt = iq_elt.firstChildElement()
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
774 if query_elt.name != "query":
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
775 log.warning(_("Bad answer received from proxy"))
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
776 return
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
777 streamhost_elts = filter(lambda elt: elt.name == 'streamhost', query_elt.elements())
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
778 if not streamhost_elts:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
779 log.warning(_("No streamhost found in stream query"))
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
780 return
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
781 if len(streamhost_elts) != 1:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
782 log.warning(_("Multiple streamhost elements in proxy not managed, keeping only the first one"))
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
783 streamhost_elt = streamhost_elts[0]
941
c6d8fc63b1db core, plugins: host.getClient now raise an exception instead of returning None when no profile is found, plugins have been adapted consequently and a bit cleaned
Goffi <goffi@goffi.org>
parents: 811
diff changeset
784 self.host.memory.setParam("Proxy", streamhost_elt.getAttribute("jid", ""),
c6d8fc63b1db core, plugins: host.getClient now raise an exception instead of returning None when no profile is found, plugins have been adapted consequently and a bit cleaned
Goffi <goffi@goffi.org>
parents: 811
diff changeset
785 "File Transfer", profile_key=self.parent.profile)
c6d8fc63b1db core, plugins: host.getClient now raise an exception instead of returning None when no profile is found, plugins have been adapted consequently and a bit cleaned
Goffi <goffi@goffi.org>
parents: 811
diff changeset
786 self.host.memory.setParam("Proxy host", streamhost_elt.getAttribute("host", ""),
c6d8fc63b1db core, plugins: host.getClient now raise an exception instead of returning None when no profile is found, plugins have been adapted consequently and a bit cleaned
Goffi <goffi@goffi.org>
parents: 811
diff changeset
787 "File Transfer", profile_key=self.parent.profile)
c6d8fc63b1db core, plugins: host.getClient now raise an exception instead of returning None when no profile is found, plugins have been adapted consequently and a bit cleaned
Goffi <goffi@goffi.org>
parents: 811
diff changeset
788 self.host.memory.setParam("Proxy port", streamhost_elt.getAttribute("port", ""),
641
49587e170f53 core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents: 638
diff changeset
789 "File Transfer", profile_key=self.parent.profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
790
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 60
diff changeset
791 def connectionInitialized(self):
956
132de9d487ac plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents: 944
diff changeset
792 def connection_ok(dummy):
132de9d487ac plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents: 944
diff changeset
793 self.xmlstream.addObserver(BS_REQUEST, self.plugin_parent.streamQuery, profile=self.parent.profile)
132de9d487ac plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents: 944
diff changeset
794 proxy = self.host.memory.getParamA("Proxy", "File Transfer", profile_key=self.parent.profile)
132de9d487ac plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents: 944
diff changeset
795 if not proxy:
132de9d487ac plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents: 944
diff changeset
796 def proxiesFound(entities):
132de9d487ac plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents: 944
diff changeset
797 try:
132de9d487ac plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents: 944
diff changeset
798 proxy_ent = entities.pop()
132de9d487ac plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents: 944
diff changeset
799 except KeyError:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
800 log.info(_("No proxy found on this server"))
956
132de9d487ac plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents: 944
diff changeset
801 return
132de9d487ac plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents: 944
diff changeset
802 iq_elt = jabber_client.IQ(self.parent.xmlstream, 'get')
132de9d487ac plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents: 944
diff changeset
803 iq_elt["to"] = proxy_ent.full()
132de9d487ac plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents: 944
diff changeset
804 iq_elt.addElement('query', NS_BS)
132de9d487ac plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents: 944
diff changeset
805 iq_elt.addCallback(self._proxyDataResult)
132de9d487ac plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents: 944
diff changeset
806 iq_elt.send()
132de9d487ac plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents: 944
diff changeset
807 d = self.host.findServiceEntities("proxy", "bytestreams", profile_key=self.parent.profile)
132de9d487ac plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents: 944
diff changeset
808 d.addCallback(proxiesFound)
132de9d487ac plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents: 944
diff changeset
809 self.parent.getConnectionDeferred().addCallback(connection_ok)
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
810
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
811
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 60
diff changeset
812 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 60
diff changeset
813 return [disco.DiscoFeature(NS_BS)]
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 60
diff changeset
814
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 60
diff changeset
815 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 60
diff changeset
816 return []