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