Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0047.py @ 585:9902ec2d8d9b
Remove useless trailing semicolons.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 18 Jan 2013 17:53:08 +0100 |
parents | ca13633d3b6b |
children | 952322b1d490 |
rev | line source |
---|---|
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 """ |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 SAT plugin for managing gateways (xep-0047) |
572 | 6 Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 This program is free software: you can redistribute it and/or modify |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 (at your option) any later version. |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 This program is distributed in the hope that it will be useful, |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
16 GNU Affero General Public License for more details. |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 """ |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from logging import debug, info, warning, error |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
23 from twisted.words.protocols.jabber import client as jabber_client, jid |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from twisted.words.xish import domish |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 import twisted.internet.error |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from twisted.internet import reactor |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
27 from sat.core.exceptions import ProfileNotInCacheError |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 from wokkel import disco, iwokkel |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 from zope.interface import implements |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 import base64 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 try: |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 from twisted.words.protocols.xmlstream import XMPPHandler |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 except ImportError: |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 from wokkel.subprotocols import XMPPHandler |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 MESSAGE = '/message' |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 IQ_SET = '/iq[@type="set"]' |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 NS_IBB = 'http://jabber.org/protocol/ibb' |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 IBB_OPEN = IQ_SET + '/open[@xmlns="' + NS_IBB + '"]' |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 IBB_CLOSE = IQ_SET + '/close[@xmlns="' + NS_IBB + '" and @sid="%s"]' |
404
6a1c6c41b91b
plugin xep-0047: removed gajim workaround as gajim has been fixed
Goffi <goffi@goffi.org>
parents:
403
diff
changeset
|
45 IBB_IQ_DATA = IQ_SET + '/data[@xmlns="' + NS_IBB + '" and @sid="%s"]' |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 IBB_MESSAGE_DATA = MESSAGE + '/data[@xmlns="' + NS_IBB + '" and @sid="%s"]' |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 TIMEOUT = 60 #timeout for workflow |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 BLOCK_SIZE = 4096 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 PLUGIN_INFO = { |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 "name": "In-Band Bytestream Plugin", |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 "import_name": "XEP-0047", |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 "type": "XEP", |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 "protocols": ["XEP-0047"], |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 "main": "XEP_0047", |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 "handler": "yes", |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 "description": _("""Implementation of In-Band Bytestreams""") |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 } |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 class XEP_0047(): |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 NAMESPACE = NS_IBB |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 def __init__(self, host): |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 info(_("In-Band Bytestreams plugin initialization")) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 self.host = host |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 def getHandler(self, profile): |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 return XEP_0047_handler(self) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
70 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
|
71 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
|
72 if not client: |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
73 raise ProfileNotInCacheError |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
74 client.xep_0047_current_stream = {} #key: stream_id, value: data(dict) |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
75 |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
76 def _timeOut(self, sid, profile): |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 """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
|
78 @param id: id of client.xep_0047_current_stream""" |
585
9902ec2d8d9b
Remove useless trailing semicolons.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
79 info(_("In-Band 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
|
80 self._killId(sid, False, "TIMEOUT", profile) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
82 def _killId(self, sid, success=False, failure_reason="UNKNOWN", profile=None): |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 """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
|
84 @param sid: id of client.xep_0047_current_stream""" |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
85 assert(profile) |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
86 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
|
87 if not client: |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
88 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
|
89 return |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
90 if not client.xep_0047_current_stream.has_key(sid): |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 warning(_("kill id called on a non existant id")) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 return |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
93 if client.xep_0047_current_stream[sid].has_key("observer_cb"): |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
94 client.xmlstream.removeObserver(client.xep_0047_current_stream[sid]["event_data"], client.xep_0047_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
|
95 if client.xep_0047_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
|
96 client.xep_0047_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
|
97 if client.xep_0047_current_stream[sid].has_key("size"): |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
98 self.host.removeProgressCB(sid, profile) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
100 file_obj = client.xep_0047_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
|
101 success_cb = client.xep_0047_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
|
102 failure_cb = client.xep_0047_current_stream[sid]['failure_cb'] |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
104 del client.xep_0047_current_stream[sid] |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 if success: |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
107 success_cb(sid, file_obj, NS_IBB, profile) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 else: |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
109 failure_cb(sid, file_obj, NS_IBB, failure_reason, profile) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
111 def getProgress(self, sid, data, profile): |
391 | 112 """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
|
113 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
|
114 if not client: |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
115 raise ProfileNotInCacheError |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 try: |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
117 file_obj = client.xep_0047_current_stream[sid]["file_obj"] |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 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
|
119 data["size"] = str(client.xep_0047_current_stream[sid]["size"]) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 except: |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 pass |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
123 def prepareToReceive(self, from_jid, sid, file_obj, size, success_cb, failure_cb, profile): |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 """Called when a bytestream is imminent |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 @param from_jid: jid of the sender |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
126 @param sid: Stream id |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
127 @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:
391
diff
changeset
|
128 @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:
391
diff
changeset
|
129 @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
|
130 @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
|
131 @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
|
132 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
|
133 if not client: |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
134 raise ProfileNotInCacheError |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
135 data = client.xep_0047_current_stream[sid] = {} |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 data["from"] = from_jid |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 data["file_obj"] = file_obj |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 data["seq"] = -1 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 if size: |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 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
|
141 self.host.registerProgressCB(sid, self.getProgress, profile) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 data["timer"] = reactor.callLater(TIMEOUT, self._timeOut, sid) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 data["success_cb"] = success_cb |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 data["failure_cb"] = failure_cb |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 def streamOpening(self, IQ, profile): |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 debug(_("IBB stream opening")) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 IQ.handled=True |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
149 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
|
150 if not client: |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
151 raise ProfileNotInCacheError |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 open_elt = IQ.firstChildElement() |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 block_size = open_elt.getAttribute('block-size') |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 sid = open_elt.getAttribute('sid') |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 stanza = open_elt.getAttribute('stanza', 'iq') |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 if not sid or not block_size or int(block_size)>65535: |
391 | 157 warning(_("malformed IBB transfer: %s" % IQ['id'])) |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
158 self.sendNotAcceptableError(IQ['id'], IQ['from'], client.xmlstream) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 return |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
160 if not sid in client.xep_0047_current_stream: |
391 | 161 warning(_("Ignoring unexpected IBB transfer: %s" % sid)) |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
162 self.sendNotAcceptableError(IQ['id'], IQ['from'], client.xmlstream) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 return |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
164 if client.xep_0047_current_stream[sid]["from"] != jid.JID(IQ['from']): |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 warning(_("sended jid inconsistency (man in the middle attack attempt ?)")) |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
166 self.sendNotAcceptableError(IQ['id'], IQ['from'], client.xmlstream) |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
167 self._killId(sid, False, "PROTOCOL_ERROR", profile=profile) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 return |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 #at this stage, the session looks ok and will be accepted |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 #we reset the timeout: |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
173 client.xep_0047_current_stream[sid]["timer"].reset(TIMEOUT) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 #we save the xmlstream, events and observer data to allow observer removal |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
176 client.xep_0047_current_stream[sid]["event_data"] = event_data = (IBB_MESSAGE_DATA if stanza=='message' else IBB_IQ_DATA) % sid |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
177 client.xep_0047_current_stream[sid]["observer_cb"] = observer_cb = self.messageData if stanza=='message' else self.iqData |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 event_close = IBB_CLOSE % sid |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 #we now set the stream observer to look after data packet |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
180 client.xmlstream.addObserver(event_data, observer_cb, profile = profile) |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
181 client.xmlstream.addOnetimeObserver(event_close, self.streamClosing, profile = profile) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 #finally, we send the accept stanza |
536
a31abb97310d
core, plugins: fixed bad namespace in stanza creation
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
183 result = domish.Element((None, 'iq')) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 result['type'] = 'result' |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 result['id'] = IQ['id'] |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 result['to'] = IQ['from'] |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
187 client.xmlstream.send(result) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 def streamClosing(self, IQ, profile): |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 IQ.handled=True |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
191 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
|
192 if not client: |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
193 raise ProfileNotInCacheError |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 debug(_("IBB stream closing")) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 data_elt = IQ.firstChildElement() |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 sid = data_elt.getAttribute('sid') |
536
a31abb97310d
core, plugins: fixed bad namespace in stanza creation
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
197 result = domish.Element((None, 'iq')) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 result['type'] = 'result' |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 result['id'] = IQ['id'] |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 result['to'] = IQ['from'] |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
201 client.xmlstream.send(result) |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
202 self._killId(sid, success=True, profile=profile) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 def iqData(self, IQ, profile): |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 IQ.handled=True |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
206 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
|
207 if not client: |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
208 raise ProfileNotInCacheError |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 data_elt = IQ.firstChildElement() |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
211 if self._manageDataElt(data_elt, 'iq', IQ['id'], jid.JID(IQ['from']), profile): |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 #and send a success answer |
536
a31abb97310d
core, plugins: fixed bad namespace in stanza creation
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
213 result = domish.Element((None, 'iq')) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 result['type'] = 'result' |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 result['id'] = IQ['id'] |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 result['to'] = IQ['from'] |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
217 |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
218 client.xmlstream.send(result) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 def messageData(self, message_elt, profile): |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 data_elt = message_elt.firstChildElement() |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 sid = message_elt.getAttribute('id','') |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
223 self._manageDataElt(message_elt, 'message', sid, jid.JID(message_elt['from']), profile) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
225 def _manageDataElt(self, data_elt, stanza, sid, stanza_from_jid, profile): |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
226 """Manage the data elelement (check validity and write to the file_obj) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 @param data_elt: "data" domish element |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 @return: True if success""" |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
229 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
|
230 if not client: |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
231 raise ProfileNotInCacheError |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 sid = data_elt.getAttribute('sid') |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
233 if sid not in client.xep_0047_current_stream: |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 error(_("Received data for an unknown session id")) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 return False |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
237 from_jid = client.xep_0047_current_stream[sid]["from"] |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
238 file_obj = client.xep_0047_current_stream[sid]["file_obj"] |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 if stanza_from_jid != from_jid: |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 warning(_("sended jid inconsistency (man in the middle attack attempt ?)")) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 if stanza=='iq': |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
243 self.sendNotAcceptableError(sid, from_jid, client.xmlstream) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 return False |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
246 client.xep_0047_current_stream[sid]["seq"]+=1 |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
247 if int(data_elt.getAttribute("seq",-1)) != client.xep_0047_current_stream[sid]["seq"]: |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 warning(_("Sequence error")) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
249 if stanza=='iq': |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
250 self.sendNotAcceptableError(data_elt["id"], from_jid, client.xmlstream) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 return False |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 #we reset the timeout: |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
254 client.xep_0047_current_stream[sid]["timer"].reset(TIMEOUT) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 #we can now decode the data |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 try: |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 file_obj.write(base64.b64decode(str(data_elt))) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
259 except TypeError: |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 #The base64 data is invalid |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
261 warning(_("Invalid base64 data")) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
262 if stanza=='iq': |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
263 self.sendNotAcceptableError(data_elt["id"], from_jid, client.xmlstream) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
264 return False |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
265 return True |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
266 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
267 def sendNotAcceptableError(self, iq_id, to_jid, xmlstream): |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
268 """Not acceptable error used when the stream is not expected or something is going wrong |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 @param iq_id: IQ id |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 @param to_jid: addressee |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
271 @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
|
272 result = domish.Element((None, 'iq')) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
273 result['type'] = 'result' |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
274 result['id'] = iq_id |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
275 result['to'] = to_jid |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
276 error_el = result.addElement('error') |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
277 error_el['type'] = 'cancel' |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
278 error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas','not-acceptable')) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
279 xmlstream.send(result) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
281 def startStream(self, file_obj, to_jid, sid, length, successCb, failureCb, size = None, profile=None): |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
282 """Launch the stream workflow |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
283 @param file_obj: file_obj to send |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
284 @param to_jid: JID of the recipient |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
285 @param sid: Stream session id |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
286 @param length: number of byte to send, or None to send until the end |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
287 @param successCb: method to call when stream successfuly finished |
389 | 288 @param failureCb: method to call when something goes wrong |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
289 @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
|
290 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
|
291 if not client: |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
292 raise ProfileNotInCacheError |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
293 if length != None: |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
294 error(_('stream length not managed yet')) |
585
9902ec2d8d9b
Remove useless trailing semicolons.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
295 return |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
296 data = client.xep_0047_current_stream[sid] = {} |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
297 data["timer"] = reactor.callLater(TIMEOUT, self._timeOut, sid) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
298 data["file_obj"] = file_obj |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
299 data["to"] = to_jid |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
300 data["success_cb"] = successCb |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
301 data["failure_cb"] = failureCb |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
302 data["block_size"] = BLOCK_SIZE |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
303 if size: |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
304 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
|
305 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
|
306 iq_elt = jabber_client.IQ(client.xmlstream,'set') |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
307 iq_elt['from'] = client.jid.full() |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
308 iq_elt['to'] = to_jid.full() |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
309 open_elt = iq_elt.addElement('open',NS_IBB) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
310 open_elt['block-size'] = str(BLOCK_SIZE) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
311 open_elt['sid'] = sid |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
312 open_elt['stanza'] = 'iq' |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
313 iq_elt.addCallback(self.iqResult, sid, 0, length, profile) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
314 iq_elt.send() |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
315 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
316 def iqResult(self, sid, seq, length, profile, iq_elt): |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 """Called when the result of open iq is received""" |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
318 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
|
319 if not client: |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
320 raise ProfileNotInCacheError |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
321 data = client.xep_0047_current_stream[sid] |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
322 if iq_elt["type"] == "error": |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
323 warning(_("Transfer failed")) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
324 self.terminateStream(sid, "IQ_ERROR") |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
325 return |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
326 |
403
c513328ade9d
plugins XEP-0047 and XEP-0065: timout bug fix
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
327 if data['timer'].active(): |
c513328ade9d
plugins XEP-0047 and XEP-0065: timout bug fix
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
328 data['timer'].cancel() |
c513328ade9d
plugins XEP-0047 and XEP-0065: timout bug fix
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
329 |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
330 buffer = data["file_obj"].read(data["block_size"]) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
331 if buffer: |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
332 next_iq_elt = jabber_client.IQ(client.xmlstream,'set') |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
333 next_iq_elt['to'] = data["to"].full() |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
334 data_elt = next_iq_elt.addElement('data', NS_IBB) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
335 data_elt['seq'] = str(seq) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
336 data_elt['sid'] = sid |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
337 data_elt.addContent(base64.b64encode(buffer)) |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
338 next_iq_elt.addCallback(self.iqResult, sid, seq+1, length, profile) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
339 next_iq_elt.send() |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
340 else: |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
341 self.terminateStream(sid, profile=profile) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
342 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
343 def terminateStream(self, sid, failure_reason = None, profile=None): |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
344 """Terminate the stream session |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
345 @param to_jid: recipient |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
346 @param sid: Session id |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
347 @param file_obj: file object used |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
348 @param xmlstream: XML stream used with this session |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
349 @param progress_cb: True if we have to remove the progress callback |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
350 @param callback: method to call after finishing |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
351 @param failure_reason: reason of the failure, or None if steam was successful""" |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
352 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
|
353 if not client: |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
354 raise ProfileNotInCacheError |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
355 data = client.xep_0047_current_stream[sid] |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
356 iq_elt = jabber_client.IQ(client.xmlstream,'set') |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
357 iq_elt['to'] = data["to"].full() |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
358 close_elt = iq_elt.addElement('close',NS_IBB) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
359 close_elt['sid'] = sid |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
360 iq_elt.send() |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
361 self.host.removeProgressCB(sid, profile) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
362 if failure_reason: |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
363 self._killId(sid, False, failure_reason, profile=profile) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
364 else: |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
365 self._killId(sid, True, profile=profile) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
366 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
367 class XEP_0047_handler(XMPPHandler): |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
368 implements(iwokkel.IDisco) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
369 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
370 def __init__(self,parent): |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
371 self.plugin_parent = parent |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
372 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
373 def connectionInitialized(self): |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
374 self.xmlstream.addObserver(IBB_OPEN, self.plugin_parent.streamOpening, profile = self.parent.profile) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
375 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
376 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
377 return [disco.DiscoFeature(NS_IBB)] |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
378 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
379 def getDiscoItems(self, requestor, target, nodeIdentifier=''): |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
380 return [] |