Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0065.py @ 958:9393dc29aaf3
core (XMPP): added warning when a contact ins roster is not subscribed from or to
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 31 Mar 2014 17:07:25 +0200 |
parents | 132de9d487ac |
children | 301b342c697a |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
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 | 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) |
811 | 9 # 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org) |
0 | 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 | 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 | 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 | 23 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
24 # -- |
0 | 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 | 30 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
31 # -- |
0 | 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 | 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 | 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 | 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 | 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 | 56 |
771 | 57 from sat.core.i18n import _ |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
58 from logging import debug, info, warning, error |
0 | 59 from twisted.internet import protocol, reactor |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
60 from twisted.internet import error as jab_error |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
61 from twisted.words.protocols.jabber import jid, client as jabber_client |
0 | 62 from twisted.protocols.basic import FileSender |
63 from twisted.words.xish import domish | |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
64 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
|
65 from sat.core.exceptions import ProfileNotInCacheError |
0 | 66 import struct |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
67 import hashlib |
0 | 68 |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
69 from zope.interface import implements |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
70 |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
71 try: |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
72 from twisted.words.protocols.xmlstream import XMPPHandler |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
73 except ImportError: |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
74 from wokkel.subprotocols import XMPPHandler |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
75 |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
76 from wokkel import disco, iwokkel |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
77 |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
78 IQ_SET = '/iq[@type="set"]' |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
79 NS_BS = 'http://jabber.org/protocol/bytestreams' |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
80 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
|
81 TIMEOUT = 60 # timeout for workflow |
0 | 82 |
83 PLUGIN_INFO = { | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
84 "name": "XEP 0065 Plugin", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
85 "import_name": "XEP-0065", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
86 "type": "XEP", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
87 "protocols": ["XEP-0065"], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
88 "main": "XEP_0065", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
89 "handler": "yes", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
90 "description": _("""Implementation of SOCKS5 Bytestreams""") |
0 | 91 } |
92 | |
93 STATE_INITIAL = 0 | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
94 STATE_AUTH = 1 |
0 | 95 STATE_REQUEST = 2 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
96 STATE_READY = 3 |
0 | 97 STATE_AUTH_USERPASS = 4 |
98 STATE_TARGET_INITIAL = 5 | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
99 STATE_TARGET_AUTH = 6 |
0 | 100 STATE_TARGET_REQUEST = 7 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
101 STATE_TARGET_READY = 8 |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
102 STATE_LAST = 9 |
0 | 103 |
104 STATE_CONNECT_PENDING = STATE_LAST + 1 | |
105 | |
106 SOCKS5_VER = 0x05 | |
107 | |
108 ADDR_IPV4 = 0x01 | |
109 ADDR_DOMAINNAME = 0x03 | |
110 ADDR_IPV6 = 0x04 | |
111 | |
112 CMD_CONNECT = 0x01 | |
113 CMD_BIND = 0x02 | |
114 CMD_UDPASSOC = 0x03 | |
115 | |
116 AUTHMECH_ANON = 0x00 | |
117 AUTHMECH_USERPASS = 0x02 | |
118 AUTHMECH_INVALID = 0xFF | |
119 | |
120 REPLY_SUCCESS = 0x00 | |
121 REPLY_GENERAL_FAILUR = 0x01 | |
122 REPLY_CONN_NOT_ALLOWED = 0x02 | |
123 REPLY_NETWORK_UNREACHABLE = 0x03 | |
124 REPLY_HOST_UNREACHABLE = 0x04 | |
125 REPLY_CONN_REFUSED = 0x05 | |
126 REPLY_TTL_EXPIRED = 0x06 | |
127 REPLY_CMD_NOT_SUPPORTED = 0x07 | |
128 REPLY_ADDR_NOT_SUPPORTED = 0x08 | |
129 | |
130 | |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
131 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
|
132 """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
|
133 @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
|
134 @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
|
135 @param sid: session id |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
136 @return: hash (string)""" |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
137 return hashlib.sha1((sid + from_jid.full() + to_jid.full()).encode('utf-8')).hexdigest() |
0 | 138 |
139 | |
140 class SOCKSv5(protocol.Protocol, FileSender): | |
141 def __init__(self): | |
69 | 142 debug(_("Protocol init")) |
0 | 143 self.state = STATE_INITIAL |
144 self.buf = "" | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
145 self.supportedAuthMechs = [AUTHMECH_ANON] |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
146 self.supportedAddrs = [ADDR_DOMAINNAME] |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
147 self.enabledCommands = [CMD_CONNECT] |
0 | 148 self.peersock = None |
149 self.addressType = 0 | |
150 self.requestType = 0 | |
151 | |
152 def _startNegotiation(self): | |
153 debug("_startNegotiation") | |
154 self.state = STATE_TARGET_AUTH | |
155 self.transport.write(struct.pack('!3B', SOCKS5_VER, 1, AUTHMECH_ANON)) | |
156 | |
157 def _parseNegotiation(self): | |
158 debug("_parseNegotiation") | |
159 try: | |
160 # Parse out data | |
161 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
|
162 methods = struct.unpack('%dB' % nmethod, self.buf[2:nmethod + 2]) |
0 | 163 |
164 # Ensure version is correct | |
165 if ver != 5: | |
166 self.transport.write(struct.pack('!BB', SOCKS5_VER, AUTHMECH_INVALID)) | |
167 self.transport.loseConnection() | |
168 return | |
169 | |
170 # Trim off front of the buffer | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
171 self.buf = self.buf[nmethod + 2:] |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
172 |
0 | 173 # Check for supported auth mechs |
174 for m in self.supportedAuthMechs: | |
175 if m in methods: | |
176 # Update internal state, according to selected method | |
177 if m == AUTHMECH_ANON: | |
178 self.state = STATE_REQUEST | |
179 elif m == AUTHMECH_USERPASS: | |
180 self.state = STATE_AUTH_USERPASS | |
181 # Complete negotiation w/ this method | |
182 self.transport.write(struct.pack('!BB', SOCKS5_VER, m)) | |
183 return | |
184 | |
185 # No supported mechs found, notify client and close the connection | |
186 self.transport.write(struct.pack('!BB', SOCKS5_VER, AUTHMECH_INVALID)) | |
187 self.transport.loseConnection() | |
188 except struct.error: | |
189 pass | |
190 | |
191 def _parseUserPass(self): | |
192 debug("_parseUserPass") | |
193 try: | |
194 # Parse out data | |
195 ver, ulen = struct.unpack('BB', self.buf[:2]) | |
196 uname, = struct.unpack('%ds' % ulen, self.buf[2:ulen + 2]) | |
197 plen, = struct.unpack('B', self.buf[ulen + 2]) | |
198 password, = struct.unpack('%ds' % plen, self.buf[ulen + 3:ulen + 3 + plen]) | |
199 # Trim off fron of the buffer | |
200 self.buf = self.buf[3 + ulen + plen:] | |
201 # Fire event to authenticate user | |
202 if self.authenticateUserPass(uname, password): | |
203 # Signal success | |
204 self.state = STATE_REQUEST | |
205 self.transport.write(struct.pack('!BB', SOCKS5_VER, 0x00)) | |
206 else: | |
207 # Signal failure | |
208 self.transport.write(struct.pack('!BB', SOCKS5_VER, 0x01)) | |
209 self.transport.loseConnection() | |
210 except struct.error: | |
211 pass | |
212 | |
213 def sendErrorReply(self, errorcode): | |
214 debug("sendErrorReply") | |
215 # Any other address types are not supported | |
216 result = struct.pack('!BBBBIH', SOCKS5_VER, errorcode, 0, 1, 0, 0) | |
217 self.transport.write(result) | |
218 self.transport.loseConnection() | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
219 |
0 | 220 def _parseRequest(self): |
221 debug("_parseRequest") | |
222 try: | |
223 # Parse out data and trim buffer accordingly | |
224 ver, cmd, rsvd, self.addressType = struct.unpack('!BBBB', self.buf[:4]) | |
225 | |
226 # Ensure we actually support the requested address type | |
227 if self.addressType not in self.supportedAddrs: | |
228 self.sendErrorReply(REPLY_ADDR_NOT_SUPPORTED) | |
229 return | |
230 | |
231 # Deal with addresses | |
232 if self.addressType == ADDR_IPV4: | |
233 addr, port = struct.unpack('!IH', self.buf[4:10]) | |
234 self.buf = self.buf[10:] | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
235 elif self.addressType == ADDR_DOMAINNAME: |
0 | 236 nlen = ord(self.buf[4]) |
237 addr, port = struct.unpack('!%dsH' % nlen, self.buf[5:]) | |
238 self.buf = self.buf[7 + len(addr):] | |
239 else: | |
240 # Any other address types are not supported | |
241 self.sendErrorReply(REPLY_ADDR_NOT_SUPPORTED) | |
242 return | |
243 | |
244 # Ensure command is supported | |
245 if cmd not in self.enabledCommands: | |
246 # Send a not supported error | |
247 self.sendErrorReply(REPLY_CMD_NOT_SUPPORTED) | |
248 return | |
249 | |
250 # Process the command | |
251 if cmd == CMD_CONNECT: | |
252 self.connectRequested(addr, port) | |
253 elif cmd == CMD_BIND: | |
254 self.bindRequested(addr, port) | |
255 else: | |
256 # Any other command is not supported | |
257 self.sendErrorReply(REPLY_CMD_NOT_SUPPORTED) | |
258 | |
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
|
259 except struct.error: |
0 | 260 return None |
261 | |
262 def _makeRequest(self): | |
263 debug("_makeRequest") | |
264 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
|
265 sha1 = calculateHash(self.data["from"], self.data["to"], self.sid) |
0 | 266 request = struct.pack('!5B%dsH' % len(sha1), SOCKS5_VER, CMD_CONNECT, 0, ADDR_DOMAINNAME, len(sha1), sha1, 0) |
267 self.transport.write(request) | |
268 | |
269 def _parseRequestReply(self): | |
270 debug("_parseRequestReply") | |
271 try: | |
272 ver, rep, rsvd, self.addressType = struct.unpack('!BBBB', self.buf[:4]) | |
273 # Ensure we actually support the requested address type | |
274 if self.addressType not in self.supportedAddrs: | |
275 self.sendErrorReply(REPLY_ADDR_NOT_SUPPORTED) | |
276 return | |
277 | |
278 # Deal with addresses | |
279 if self.addressType == ADDR_IPV4: | |
280 addr, port = struct.unpack('!IH', self.buf[4:10]) | |
281 self.buf = self.buf[10:] | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
282 elif self.addressType == ADDR_DOMAINNAME: |
0 | 283 nlen = ord(self.buf[4]) |
284 addr, port = struct.unpack('!%dsH' % nlen, self.buf[5:]) | |
285 self.buf = self.buf[7 + len(addr):] | |
286 else: | |
287 # Any other address types are not supported | |
288 self.sendErrorReply(REPLY_ADDR_NOT_SUPPORTED) | |
289 return | |
290 | |
291 # Ensure reply is OK | |
292 if rep != REPLY_SUCCESS: | |
293 self.loseConnection() | |
294 return | |
295 | |
398 | 296 if self.factory.proxy: |
297 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
|
298 self.factory.activateCb(self.sid, self.factory.iq_id, self.startTransfer, self.profile) |
398 | 299 else: |
300 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
|
301 self.factory.activateCb(self.sid, self.factory.iq_id, self.profile) |
0 | 302 |
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
|
303 except struct.error: |
0 | 304 return None |
305 | |
306 def connectionMade(self): | |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
307 debug("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
|
308 |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
309 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
|
310 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
|
311 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
|
312 self.data = self.factory.data |
0 | 313 self.state = STATE_TARGET_INITIAL |
314 self._startNegotiation() | |
315 | |
316 def connectRequested(self, addr, port): | |
69 | 317 debug("connectRequested") |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
318 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
319 # Check that this session is expected |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
320 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
|
321 #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
|
322 self.sendErrorReply(REPLY_CONN_REFUSED) |
0 | 323 return |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
324 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
|
325 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
|
326 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
|
327 self.connectCompleted(addr, 0) |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
328 self.transport.stopReading() |
0 | 329 |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
330 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
|
331 """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
|
332 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
|
333 d.addCallback(self.fileTransfered) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
334 |
0 | 335 def fileTransfered(self, d): |
69 | 336 info(_("File transfer completed, closing connection")) |
0 | 337 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
|
338 self.factory.finishedCb(self.sid, True, self.profile) |
0 | 339 |
340 def connectCompleted(self, remotehost, remoteport): | |
341 debug("connectCompleted") | |
342 if self.addressType == ADDR_IPV4: | |
343 result = struct.pack('!BBBBIH', SOCKS5_VER, REPLY_SUCCESS, 0, 1, remotehost, remoteport) | |
344 elif self.addressType == ADDR_DOMAINNAME: | |
345 result = struct.pack('!BBBBB%dsH' % len(remotehost), SOCKS5_VER, REPLY_SUCCESS, 0, | |
346 ADDR_DOMAINNAME, len(remotehost), remotehost, remoteport) | |
347 self.transport.write(result) | |
348 self.state = STATE_READY | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
349 |
0 | 350 def bindRequested(self, addr, port): |
351 pass | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
352 |
0 | 353 def authenticateUserPass(self, user, passwd): |
354 debug("User/pass: %s/%s", user, passwd) | |
355 return True | |
356 | |
357 def dataReceived(self, buf): | |
358 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
|
359 self.data["file_obj"].write(buf) |
0 | 360 return |
361 | |
362 self.buf = self.buf + buf | |
363 if self.state == STATE_INITIAL: | |
364 self._parseNegotiation() | |
365 if self.state == STATE_AUTH_USERPASS: | |
366 self._parseUserPass() | |
367 if self.state == STATE_REQUEST: | |
368 self._parseRequest() | |
369 if self.state == STATE_TARGET_AUTH: | |
370 ver, method = struct.unpack('!BB', buf) | |
371 self.buf = self.buf[2:] | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
372 if ver != SOCKS5_VER or method != AUTHMECH_ANON: |
0 | 373 self.transport.loseConnection() |
374 else: | |
375 self._makeRequest() | |
376 if self.state == STATE_TARGET_REQUEST: | |
377 self._parseRequestReply() | |
378 | |
379 def clientConnectionLost(self, reason): | |
380 debug("clientConnectionLost") | |
381 self.transport.loseConnection() | |
382 | |
383 def connectionLost(self, reason): | |
384 debug("connectionLost") | |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
385 if self.state != STATE_CONNECT_PENDING: |
0 | 386 self.transport.unregisterProducer() |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
387 if self.peersock is not None: |
0 | 388 self.peersock.peersock = None |
389 self.peersock.transport.unregisterProducer() | |
390 self.peersock = None | |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
391 |
0 | 392 |
393 class Socks5ServerFactory(protocol.ServerFactory): | |
394 protocol = SOCKSv5 | |
395 | |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
396 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
|
397 self.host = host |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
398 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
|
399 self.finishedCb = finishedCb |
0 | 400 |
401 def startedConnecting(self, connector): | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
402 debug(_("Socks 5 server connection started")) |
0 | 403 |
404 def clientConnectionLost(self, connector, reason): | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
405 debug(_("Socks 5 server connection lost (reason: %s)"), reason) |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
406 |
0 | 407 |
408 class Socks5ClientFactory(protocol.ClientFactory): | |
409 protocol = SOCKSv5 | |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
410 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
411 def __init__(self, current_stream, sid, iq_id, activateCb, finishedCb, proxy=False, profile=None): |
398 | 412 """Init the Client Factory |
413 @param current_stream: current streams data | |
414 @param sid: Session ID | |
415 @param iq_id: iq id used to initiate the stream | |
416 @param activateCb: method to call to activate the stream | |
417 @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
|
418 @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
|
419 @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
|
420 assert(profile) |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
421 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
|
422 self.sid = sid |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
423 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
|
424 self.activateCb = activateCb |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
425 self.finishedCb = finishedCb |
398 | 426 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
|
427 self.profile = profile |
0 | 428 |
429 def startedConnecting(self, connector): | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
430 debug(_("Socks 5 client connection started")) |
0 | 431 |
432 def clientConnectionLost(self, connector, reason): | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
433 debug(_("Socks 5 client connection lost (reason: %s)"), reason) |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
434 self.finishedCb(self.sid, reason.type == jab_error.ConnectionDone, self.profile) # TODO: really check if the state is actually successful |
0 | 435 |
436 | |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
437 class XEP_0065(object): |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
438 |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
439 NAMESPACE = NS_BS |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
440 |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
441 params = """ |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
442 <params> |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
443 <general> |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
444 <category name="File Transfer"> |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
445 <param name="IP" value='0.0.0.0' default_cb='yes' type="string" /> |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
446 <param name="Port" value="28915" type="string" /> |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
447 </category> |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
448 </general> |
398 | 449 <individual> |
450 <category name="File Transfer"> | |
451 <param name="Proxy" value="" type="string" /> | |
452 <param name="Proxy host" value="" type="string" /> | |
453 <param name="Proxy port" value="" type="string" /> | |
454 </category> | |
455 </individual> | |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
456 </params> |
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
457 """ |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
458 |
0 | 459 def __init__(self, host): |
69 | 460 info(_("Plugin XEP_0065 initialization")) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
461 |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
462 #session data |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
463 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
|
464 |
0 | 465 self.host = host |
69 | 466 debug(_("registering")) |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
467 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
|
468 |
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
469 #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
|
470 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
|
471 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
|
472 port = int(self.host.memory.getParamA("Port", "File Transfer")) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
473 |
69 | 474 info(_("Launching Socks5 Stream server on port %d"), port) |
0 | 475 reactor.listenTCP(port, self.server_factory) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
476 |
72 | 477 def getHandler(self, profile): |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
478 return XEP_0065_handler(self) |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
479 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
480 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
|
481 client = self.host.getClient(profile) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
482 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
|
483 |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
484 def getExternalIP(self): |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
485 """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
|
486 return getPage("http://www.goffi.org/sat_tools/get_ip.php") |
0 | 487 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
488 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
|
489 """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
|
490 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
|
491 try: |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
492 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
|
493 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
|
494 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
|
495 except: |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
496 pass |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
497 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
498 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
|
499 """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
|
500 @param id: id of client.xep_0065_current_stream""" |
638
6821fc06a324
misc: a few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
501 info(_("Socks5 Bytestream: TimeOut reached for id %(sid)s [%(profile)s]") |
6821fc06a324
misc: a few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
502 % {"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
|
503 self._killId(sid, False, "TIMEOUT", profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
504 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
505 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
|
506 """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
|
507 @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
|
508 assert(profile) |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
509 client = self.host.getClient(profile) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
510 if sid not in client.xep_0065_current_stream: |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
511 warning(_("kill id called on a non existant id")) |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
512 return |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
513 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
|
514 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
|
515 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
|
516 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
|
517 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
|
518 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
|
519 self.host.removeProgressCB(sid, profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
520 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
521 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
|
522 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
|
523 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
|
524 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
525 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
|
526 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
|
527 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
|
528 #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
|
529 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
|
530 |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
531 if success: |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
532 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
|
533 else: |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
534 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
|
535 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
536 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
|
537 """Launch the stream workflow |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
538 @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
|
539 @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
|
540 @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
|
541 @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
|
542 @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
|
543 @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
|
544 @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
|
545 assert(profile) |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
546 client = self.host.getClient(profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
547 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
548 if length is not None: |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
549 error(_('stream length not managed yet')) |
585
9902ec2d8d9b
Remove useless trailing semicolons.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
550 return |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
551 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
552 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
|
553 xmlstream = client.xmlstream |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
554 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
555 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
|
556 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
|
557 data["file_obj"] = file_obj |
398 | 558 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
|
559 data["to"] = to_jid |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
560 data["success_cb"] = successCb |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
561 data["failure_cb"] = failureCb |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
562 data["xmlstream"] = xmlstream |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
563 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
|
564 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
|
565 if size: |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
566 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
|
567 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
|
568 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
|
569 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
|
570 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
|
571 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
|
572 query_elt['mode'] = 'tcp' |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
573 query_elt['sid'] = sid |
398 | 574 #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
|
575 streamhost = query_elt.addElement('streamhost') |
398 | 576 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
|
577 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
|
578 streamhost['jid'] = profile_jid.full() |
398 | 579 |
580 #second streamhost: mediated connection, using proxy | |
581 streamhost = query_elt.addElement('streamhost') | |
582 streamhost['host'] = self.host.memory.getParamA("Proxy host", "File Transfer", profile_key=profile) | |
583 streamhost['port'] = self.host.memory.getParamA("Proxy port", "File Transfer", profile_key=profile) | |
584 streamhost['jid'] = self.host.memory.getParamA("Proxy", "File Transfer", profile_key=profile) | |
585 | |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
586 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
|
587 iq_elt.send() |
0 | 588 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
589 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
|
590 """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
|
591 if iq_elt["type"] == "error": |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
592 warning(_("Transfer failed")) |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
593 return |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
594 client = self.host.getClient(profile) |
398 | 595 try: |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
596 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
|
597 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
|
598 timer = data["timer"] |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
599 except KeyError: |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
600 error(_("Internal error, can't do transfer")) |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
601 return |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
602 |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
603 if timer.active(): |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
604 timer.cancel() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
605 |
398 | 606 profile_jid, xmlstream = self.host.getJidNStream(profile) |
607 query_elt = iq_elt.firstChildElement() | |
608 streamhost_elts = filter(lambda elt: elt.name == 'streamhost-used', query_elt.elements()) | |
609 if not streamhost_elts: | |
610 warning(_("No streamhost found in stream query")) | |
611 return | |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
612 |
398 | 613 streamhost_jid = streamhost_elts[0]['jid'] |
614 if streamhost_jid != profile_jid.full(): | |
615 debug(_("A proxy server is used")) | |
616 proxy_host = self.host.memory.getParamA("Proxy host", "File Transfer", profile_key=profile) | |
617 proxy_port = self.host.memory.getParamA("Proxy port", "File Transfer", profile_key=profile) | |
618 proxy_jid = self.host.memory.getParamA("Proxy", "File Transfer", profile_key=profile) | |
619 if proxy_jid != streamhost_jid: | |
620 warning(_("Proxy jid is not the same as in parameters, this should not happen")) | |
621 return | |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
622 factory = Socks5ClientFactory(client.xep_0065_current_stream, sid, None, self.activateProxyStream, lambda sid, success, profile: self._killId(sid, success, profile=profile), True, profile) |
398 | 623 reactor.connectTCP(proxy_host, int(proxy_port), factory) |
624 else: | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
625 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
|
626 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
627 def activateProxyStream(self, sid, iq_id, start_transfer_cb, profile): |
398 | 628 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
|
629 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
|
630 data = client.xep_0065_current_stream[sid] |
398 | 631 profile_jid, xmlstream = self.host.getJidNStream(profile) |
632 | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
633 iq_elt = client.IQ(xmlstream, 'set') |
398 | 634 iq_elt["from"] = profile_jid.full() |
635 iq_elt["to"] = self.host.memory.getParamA("Proxy", "File Transfer", profile_key=profile) | |
636 query_elt = iq_elt.addElement('query', NS_BS) | |
637 query_elt['sid'] = sid | |
638 query_elt.addElement('activate', content=data['to'].full()) | |
639 iq_elt.addCallback(self.proxyResult, sid, start_transfer_cb, data['file_obj']) | |
640 iq_elt.send() | |
641 | |
642 def proxyResult(self, sid, start_transfer_cb, file_obj, iq_elt): | |
643 if iq_elt['type'] == 'error': | |
644 warning(_("Can't activate the proxy stream")) | |
645 return | |
646 else: | |
647 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
|
648 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
649 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
|
650 """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
|
651 @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
|
652 @param sid: Stream id |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
653 @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
|
654 @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
|
655 @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
|
656 @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
|
657 @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
|
658 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
|
659 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
|
660 data["from"] = from_jid |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
661 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
|
662 data["seq"] = -1 |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
663 if size: |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
664 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
|
665 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
|
666 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
|
667 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
|
668 data["failure_cb"] = failure_cb |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
669 |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
670 def streamQuery(self, iq_elt, profile): |
0 | 671 """Get file using byte stream""" |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
672 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
|
673 client = self.host.getClient(profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
674 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
675 if not client: |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
676 raise ProfileNotInCacheError |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
677 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
678 xmlstream = client.xmlstream |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
679 |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
680 iq_elt.handled = True |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
681 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
|
682 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
|
683 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
|
684 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
685 if not sid in client.xep_0065_current_stream: |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
686 warning(_("Ignoring unexpected BS transfer: %s" % sid)) |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
687 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
|
688 return |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
689 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
690 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
|
691 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
|
692 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
|
693 |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
694 if not streamhost_elts: |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
695 warning(_("No streamhost found in stream query %s" % sid)) |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
696 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
|
697 return |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
698 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
699 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
|
700 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
|
701 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
|
702 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
|
703 if not sh_host or not sh_port or not sh_jid: |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
704 warning(_("incomplete streamhost element")) |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
705 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
|
706 return |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
707 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
708 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
|
709 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
710 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
|
711 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
|
712 reactor.connectTCP(sh_host, int(sh_port), factory) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
713 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
714 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
|
715 client = self.host.getClient(profile) |
69 | 716 debug(_("activating stream")) |
536
a31abb97310d
core, plugins: fixed bad namespace in stanza creation
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
717 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
|
718 data = client.xep_0065_current_stream[sid] |
0 | 719 result['type'] = 'result' |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
720 result['id'] = iq_id |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
721 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
|
722 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
|
723 query = result.addElement('query', NS_BS) |
0 | 724 query['sid'] = sid |
725 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
|
726 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
|
727 data["xmlstream"].send(result) |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
728 |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
729 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
|
730 """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
|
731 @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
|
732 @param to_jid: addressee |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
733 @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
|
734 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
|
735 result['type'] = 'result' |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
736 result['id'] = iq_id |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
737 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
|
738 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
|
739 error_el['type'] = 'modify' |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
740 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
|
741 xmlstream.send(result) |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
742 |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
743 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
|
744 """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
|
745 @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
|
746 @param to_jid: addressee |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
747 @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
|
748 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
|
749 result['type'] = 'result' |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
750 result['id'] = iq_id |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
751 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
|
752 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
|
753 error_el['type'] = 'cancel' |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
754 error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas', 'bad-request')) |
64 | 755 xmlstream.send(result) |
0 | 756 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
757 |
64 | 758 class XEP_0065_handler(XMPPHandler): |
759 implements(iwokkel.IDisco) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
760 |
64 | 761 def __init__(self, plugin_parent): |
762 self.plugin_parent = plugin_parent | |
763 self.host = plugin_parent.host | |
398 | 764 |
765 def _proxyDataResult(self, iq_elt): | |
766 """Called with the informations about proxy according to XEP-0065 #4 | |
767 Params should be filled with these infos""" | |
768 if iq_elt["type"] == "error": | |
769 warning(_("Can't determine proxy informations")) | |
770 return | |
771 query_elt = iq_elt.firstChildElement() | |
772 if query_elt.name != "query": | |
773 warning(_("Bad answer received from proxy")) | |
774 return | |
775 streamhost_elts = filter(lambda elt: elt.name == 'streamhost', query_elt.elements()) | |
776 if not streamhost_elts: | |
777 warning(_("No streamhost found in stream query")) | |
778 return | |
779 if len(streamhost_elts) != 1: | |
780 warning(_("Multiple streamhost elements in proxy not managed, keeping only the first one")) | |
781 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
|
782 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
|
783 "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
|
784 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
|
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 port", streamhost_elt.getAttribute("port", ""), |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
638
diff
changeset
|
787 "File Transfer", profile_key=self.parent.profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
788 |
64 | 789 def connectionInitialized(self): |
956
132de9d487ac
plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
790 def connection_ok(dummy): |
132de9d487ac
plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
791 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
|
792 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
|
793 if not proxy: |
132de9d487ac
plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
794 def proxiesFound(entities): |
132de9d487ac
plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
795 try: |
132de9d487ac
plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
796 proxy_ent = entities.pop() |
132de9d487ac
plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
797 except KeyError: |
132de9d487ac
plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
798 info(_("No proxy found on this server")) |
132de9d487ac
plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
799 return |
132de9d487ac
plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
800 iq_elt = jabber_client.IQ(self.parent.xmlstream, 'get') |
132de9d487ac
plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
801 iq_elt["to"] = proxy_ent.full() |
132de9d487ac
plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
802 iq_elt.addElement('query', NS_BS) |
132de9d487ac
plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
803 iq_elt.addCallback(self._proxyDataResult) |
132de9d487ac
plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
804 iq_elt.send() |
132de9d487ac
plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
805 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
|
806 d.addCallback(proxiesFound) |
132de9d487ac
plugin XEP-0065: fixed initialisation sequence
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
807 self.parent.getConnectionDeferred().addCallback(connection_ok) |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
808 |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
809 |
64 | 810 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |
811 return [disco.DiscoFeature(NS_BS)] | |
812 | |
813 def getDiscoItems(self, requestor, target, nodeIdentifier=''): | |
814 return [] |