Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0047.py @ 2214:4e06cd44e667
jp (pubsub/get): --service is now optional argument, and sub_id now use "-S" short option
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 29 Mar 2017 19:42:44 +0200 |
parents | 33c8c4973743 |
children | 8b37a62336c3 |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
1 #!/usr/bin/env python2 |
384
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 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
4 # SAT plugin for managing gateways (xep-0047) |
1766 | 5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
7 # 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
|
8 # 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
|
9 # 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
|
10 # (at your option) any later version. |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
12 # 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
|
13 # 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
|
14 # 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
|
15 # GNU Affero General Public License for more details. |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
17 # 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
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
771 | 20 from sat.core.i18n import _ |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
21 from sat.core.log import getLogger |
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
22 log = getLogger(__name__) |
1558
6a8dd91476f0
plugin XEP-0047: minor improvements
Goffi <goffi@goffi.org>
parents:
1524
diff
changeset
|
23 from sat.core.constants import Const as C |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
24 from sat.core import exceptions |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
25 from twisted.words.protocols.jabber import jid |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
26 from twisted.words.protocols.jabber import xmlstream |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
27 from twisted.words.protocols.jabber import error |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from twisted.internet import reactor |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
29 from twisted.internet import defer |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
30 from twisted.python import failure |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 from wokkel import disco, iwokkel |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 from zope.interface import implements |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 import base64 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 try: |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 from twisted.words.protocols.xmlstream import XMPPHandler |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 except ImportError: |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 from wokkel.subprotocols import XMPPHandler |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 MESSAGE = '/message' |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 IQ_SET = '/iq[@type="set"]' |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 NS_IBB = 'http://jabber.org/protocol/ibb' |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 IBB_OPEN = IQ_SET + '/open[@xmlns="' + NS_IBB + '"]' |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
47 IBB_CLOSE = IQ_SET + '/close[@xmlns="' + NS_IBB + '" and @sid="{}"]' |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
48 IBB_IQ_DATA = IQ_SET + '/data[@xmlns="' + NS_IBB + '" and @sid="{}"]' |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
49 IBB_MESSAGE_DATA = MESSAGE + '/data[@xmlns="' + NS_IBB + '" and @sid="{}"]' |
1628
e9936fcfaf91
plugin 0047: increased timeout to 120s
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
50 TIMEOUT = 120 # timeout for workflow |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
51 DEFER_KEY = 'finished' # key of the deferred used to track session end |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 PLUGIN_INFO = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
54 C.PI_NAME: "In-Band Bytestream Plugin", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
55 C.PI_IMPORT_NAME: "XEP-0047", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
56 C.PI_TYPE: "XEP", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
57 C.PI_PROTOCOLS: ["XEP-0047"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
58 C.PI_MAIN: "XEP_0047", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
59 C.PI_HANDLER: "yes", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
60 C.PI_DESCRIPTION: _("""Implementation of In-Band Bytestreams""") |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 } |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
63 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
64 class XEP_0047(object): |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 NAMESPACE = NS_IBB |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
66 BLOCK_SIZE = 4096 |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 def __init__(self, host): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
69 log.info(_("In-Band Bytestreams plugin initialization")) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 self.host = host |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
72 def getHandler(self, client): |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 return XEP_0047_handler(self) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
75 def profileConnected(self, client): |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
76 client.xep_0047_current_stream = {} # key: stream_id, value: data(dict) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
77 |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
78 def _timeOut(self, sid, client): |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
79 """Delete current_stream id, called after timeout |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
80 |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
81 @param sid(unicode): session id of client.xep_0047_current_stream |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
82 @param client: %(doc_client)s |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
83 """ |
1583
d46aae87c03a
plugins XEP-0047, XEP-0065, XEP-0096: fixed use of failure.condition insteand of failure.value + removed gettext use for local logs
Goffi <goffi@goffi.org>
parents:
1578
diff
changeset
|
84 log.info(u"In-Band Bytestream: TimeOut reached for id {sid} [{profile}]" |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
85 .format(sid=sid, profile=client.profile)) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
86 self._killSession(sid, client, "TIMEOUT") |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
87 |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
88 def _killSession(self, sid, client, failure_reason=None): |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
89 """Delete a current_stream id, clean up associated observers |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
90 |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
91 @param sid(unicode): session id |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
92 @param client: %(doc_client)s |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
93 @param failure_reason(None, unicode): if None the session is successful |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
94 else, will be used to call failure_cb |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
95 """ |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
96 try: |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
97 session = client.xep_0047_current_stream[sid] |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
98 except KeyError: |
1583
d46aae87c03a
plugins XEP-0047, XEP-0065, XEP-0096: fixed use of failure.condition insteand of failure.value + removed gettext use for local logs
Goffi <goffi@goffi.org>
parents:
1578
diff
changeset
|
99 log.warning(u"kill id called on a non existant id") |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 return |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
101 |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
102 try: |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
103 observer_cb = session['observer_cb'] |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
104 except KeyError: |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
105 pass |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
106 else: |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
107 client.xmlstream.removeObserver(session["event_data"], observer_cb) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
108 |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
109 if session['timer'].active(): |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
110 session['timer'].cancel() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
111 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
112 del client.xep_0047_current_stream[sid] |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
114 success = failure_reason is None |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
115 stream_d = session[DEFER_KEY] |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
116 |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 if success: |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
118 stream_d.callback(None) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 else: |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
120 stream_d.errback(failure.Failure(exceptions.DataError(failure_reason))) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
121 |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
122 def createSession(self, *args, **kwargs): |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
123 """like [_createSession] but return the session deferred instead of the whole session |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
124 |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
125 session deferred is fired when transfer is finished |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
126 """ |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
127 return self._createSession(*args, **kwargs)[DEFER_KEY] |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
128 |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
129 def _createSession(self, file_obj, to_jid, sid, profile): |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 """Called when a bytestream is imminent |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
131 |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
132 @param file_obj(file): File object where data will be written |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
133 @param to_jid(jid.JId): jid of the other peer |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
134 @param sid(unicode): session id |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
135 @param profile: %(doc_profile)s |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
136 @return (dict): session data |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
137 """ |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
138 client = self.host.getClient(profile) |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
139 if sid in client.xep_0047_current_stream: |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
140 raise exceptions.ConflictError(u'A session with this id already exists !') |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
141 session_data = client.xep_0047_current_stream[sid] = \ |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
142 {'id': sid, |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
143 DEFER_KEY: defer.Deferred(), |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
144 'to': to_jid, |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
145 'file_obj': file_obj, |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
146 'seq': -1, |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
147 'timer': reactor.callLater(TIMEOUT, self._timeOut, sid, client), |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
148 } |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
150 return session_data |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
151 |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
152 def _onIBBOpen(self, iq_elt, profile): |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
153 """"Called when an IBB <open> element is received |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
154 |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
155 @param iq_elt(domish.Element): the whole <iq> stanza |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
156 @param profile: %(doc_profile)s |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
157 """ |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
158 log.debug(_(u"IBB stream opening")) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
159 iq_elt.handled = True |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
160 client = self.host.getClient(profile) |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
161 open_elt = iq_elt.elements(NS_IBB, 'open').next() |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 block_size = open_elt.getAttribute('block-size') |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 sid = open_elt.getAttribute('sid') |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 stanza = open_elt.getAttribute('stanza', 'iq') |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
165 if not sid or not block_size or int(block_size) > 65535: |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
166 return self._sendError('not-acceptable', sid or None, iq_elt, client) |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
167 if not sid in client.xep_0047_current_stream: |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
168 log.warning(_(u"Ignoring unexpected IBB transfer: %s" % sid)) |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
169 return self._sendError('not-acceptable', sid or None, iq_elt, client) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
170 session_data = client.xep_0047_current_stream[sid] |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
171 if session_data["to"] != jid.JID(iq_elt['from']): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
172 log.warning(_("sended jid inconsistency (man in the middle attack attempt ?)")) |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
173 return self._sendError('not-acceptable', sid, iq_elt, client) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
175 # at this stage, the session looks ok and will be accepted |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
177 # we reset the timeout: |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
178 session_data["timer"].reset(TIMEOUT) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
180 # we save the xmlstream, events and observer data to allow observer removal |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
181 session_data["event_data"] = event_data = (IBB_MESSAGE_DATA if stanza == 'message' else IBB_IQ_DATA).format(sid) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
182 session_data["observer_cb"] = observer_cb = self._onIBBData |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
183 event_close = IBB_CLOSE.format(sid) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
184 # we now set the stream observer to look after data packet |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
185 # FIXME: if we never get the events, the observers stay. |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
186 # would be better to have generic observer and check id once triggered |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
187 client.xmlstream.addObserver(event_data, observer_cb, profile=profile) |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
188 client.xmlstream.addOnetimeObserver(event_close, self._onIBBClose, profile=profile) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
189 # finally, we send the accept stanza |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
190 iq_result_elt = xmlstream.toResponse(iq_elt, 'result') |
2129
6a66c8c5a567
core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
191 client.send(iq_result_elt) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
193 def _onIBBClose(self, iq_elt, profile): |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
194 """"Called when an IBB <close> element is received |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
195 |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
196 @param iq_elt(domish.Element): the whole <iq> stanza |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
197 @param profile: %(doc_profile)s |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
198 """ |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
199 iq_elt.handled = True |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
200 client = self.host.getClient(profile) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
201 log.debug(_("IBB stream closing")) |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
202 close_elt = iq_elt.elements(NS_IBB, 'close').next() |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
203 # XXX: this observer is only triggered on valid sid, so we don't need to check it |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
204 sid = close_elt['sid'] |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
205 |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
206 iq_result_elt = xmlstream.toResponse(iq_elt, 'result') |
2129
6a66c8c5a567
core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
207 client.send(iq_result_elt) |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
208 self._killSession(sid, client) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
210 def _onIBBData(self, element, profile): |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
211 """Observer called on <iq> or <message> stanzas with data element |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
212 |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
213 Manage the data elelement (check validity and write to the file_obj) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
214 @param element(domish.Element): <iq> or <message> stanza |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
215 @param profile: %(doc_profile)s |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
216 """ |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
217 element.handled = True |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
218 client = self.host.getClient(profile) |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
219 data_elt = element.elements(NS_IBB, 'data').next() |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
220 sid = data_elt['sid'] |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
222 try: |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
223 session_data = client.xep_0047_current_stream[sid] |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
224 except KeyError: |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
225 log.warning(_(u"Received data for an unknown session id")) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
226 return self._sendError('item-not-found', None, element, client) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
228 from_jid = session_data["to"] |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
229 file_obj = session_data["file_obj"] |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
231 if from_jid.full() != element['from']: |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
232 log.warning(_(u"sended jid inconsistency (man in the middle attack attempt ?)\ninitial={initial}\ngiven={given}").format(initial=from_jid, given=element['from'])) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
233 if element.name == 'iq': |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
234 self._sendError('not-acceptable', sid, element, client) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
235 return |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
237 session_data["seq"] = (session_data["seq"] + 1) % 65535 |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
238 if int(data_elt.getAttribute("seq", -1)) != session_data["seq"]: |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
239 log.warning(_(u"Sequence error")) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
240 if element.name == 'iq': |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
241 reason = 'not-acceptable' |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
242 self._sendError(reason, sid, element, client) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
243 self.terminateStream(session_data, client, reason) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
244 return |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
246 # we reset the timeout: |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
247 session_data["timer"].reset(TIMEOUT) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
249 # we can now decode the data |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 try: |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 file_obj.write(base64.b64decode(str(data_elt))) |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 except TypeError: |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
253 # The base64 data is invalid |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
254 log.warning(_(u"Invalid base64 data")) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
255 if element.name == 'iq': |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
256 self._sendError('not-acceptable', sid, element, client) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
257 self.terminateStream(session_data, client, reason) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
258 return |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
259 |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
260 # we can now ack success |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
261 if element.name == 'iq': |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
262 iq_result_elt = xmlstream.toResponse(element, 'result') |
2129
6a66c8c5a567
core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
263 client.send(iq_result_elt) |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
264 |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
265 def _sendError(self, error_condition, sid, iq_elt, client): |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
266 """Send error stanza |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
267 |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
268 @param error_condition: one of twisted.words.protocols.jabber.error.STANZA_CONDITIONS keys |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
269 @param sid(unicode,None): jingle session id, or None, if session must not be destroyed |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
270 @param iq_elt(domish.Element): full <iq> stanza |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
271 @param client: %(doc_client)s |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
272 """ |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
273 iq_elt = error.StanzaError(error_condition).toResponse(iq_elt) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
274 log.warning(u"Error while managing in-band bytestream session, cancelling: {}".format(error_condition)) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
275 if sid is not None: |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
276 self._killSession(sid, client, error_condition) |
2129
6a66c8c5a567
core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
277 client.send(iq_elt) |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
278 |
1558
6a8dd91476f0
plugin XEP-0047: minor improvements
Goffi <goffi@goffi.org>
parents:
1524
diff
changeset
|
279 def startStream(self, file_obj, to_jid, sid, block_size=None, profile=C.PROF_KEY_NONE): |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 """Launch the stream workflow |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
281 |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
282 @param file_obj(file): file_obj to send |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
283 @param to_jid(jid.JID): JID of the recipient |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
284 @param sid(unicode): Stream session id |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
285 @param block_size(int, None): size of the block (or None for default) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
286 @param profile: %(doc_profile)s |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
287 """ |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
288 session_data = self._createSession(file_obj, to_jid, sid, profile) |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
289 client = self.host.getClient(profile) |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
290 |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
291 if block_size is None: |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
292 block_size = XEP_0047.BLOCK_SIZE |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
293 assert block_size <= 65535 |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
294 session_data["block_size"] = block_size |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
295 |
1578 | 296 iq_elt = client.IQ() |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
297 iq_elt['to'] = to_jid.full() |
1578 | 298 open_elt = iq_elt.addElement((NS_IBB, 'open')) |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
299 open_elt['block-size'] = str(block_size) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
300 open_elt['sid'] = sid |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
301 open_elt['stanza'] = 'iq' # TODO: manage <message> stanza ? |
1578 | 302 args = [session_data, client] |
303 d = iq_elt.send() | |
304 d.addCallbacks(self._IQDataStreamCb, self._IQDataStreamEb, args, None, args) | |
1558
6a8dd91476f0
plugin XEP-0047: minor improvements
Goffi <goffi@goffi.org>
parents:
1524
diff
changeset
|
305 return session_data[DEFER_KEY] |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
306 |
1578 | 307 def _IQDataStreamCb(self, iq_elt, session_data, client): |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
308 """Called during the whole data streaming |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
309 |
1578 | 310 @param iq_elt(domish.Element): iq result |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
311 @param session_data(dict): data of this streaming session |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
312 @param client: %(doc_client)s |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
313 """ |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
314 session_data["timer"].reset(TIMEOUT) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
315 |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
316 buffer_ = session_data["file_obj"].read(session_data["block_size"]) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
317 if buffer_: |
1578 | 318 next_iq_elt = client.IQ() |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
319 next_iq_elt['to'] = session_data["to"].full() |
1578 | 320 data_elt = next_iq_elt.addElement((NS_IBB, 'data')) |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
321 seq = session_data['seq'] = (session_data['seq'] + 1) % 65535 |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
322 data_elt['seq'] = unicode(seq) |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
323 data_elt['sid'] = session_data['id'] |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
324 data_elt.addContent(base64.b64encode(buffer_)) |
1578 | 325 args = [session_data, client] |
326 d = next_iq_elt.send() | |
327 d.addCallbacks(self._IQDataStreamCb, self._IQDataStreamEb, args, None, args) | |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
328 else: |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
329 self.terminateStream(session_data, client) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
330 |
1578 | 331 def _IQDataStreamEb(self, failure, session_data, client): |
332 if failure.check(error.StanzaError): | |
1583
d46aae87c03a
plugins XEP-0047, XEP-0065, XEP-0096: fixed use of failure.condition insteand of failure.value + removed gettext use for local logs
Goffi <goffi@goffi.org>
parents:
1578
diff
changeset
|
333 log.warning(u"IBB transfer failed: {}".format(failure.value)) |
1578 | 334 else: |
1583
d46aae87c03a
plugins XEP-0047, XEP-0065, XEP-0096: fixed use of failure.condition insteand of failure.value + removed gettext use for local logs
Goffi <goffi@goffi.org>
parents:
1578
diff
changeset
|
335 log.error(u"IBB transfer failed: {}".format(failure.value)) |
1578 | 336 self.terminateStream(session_data, client, "IQ_ERROR") |
337 | |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
338 def terminateStream(self, session_data, client, failure_reason=None): |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
339 """Terminate the stream session |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
340 |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
341 @param session_data(dict): data of this streaming session |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
342 @param client: %(doc_client)s |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
343 @param failure_reason(unicode, None): reason of the failure, or None if steam was successful |
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
344 """ |
1578 | 345 iq_elt = client.IQ() |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
346 iq_elt['to'] = session_data["to"].full() |
1578 | 347 close_elt = iq_elt.addElement((NS_IBB, 'close')) |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
348 close_elt['sid'] = session_data['id'] |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
349 iq_elt.send() |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
350 self._killSession(session_data['id'], client, failure_reason) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
351 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
352 |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
353 class XEP_0047_handler(XMPPHandler): |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
354 implements(iwokkel.IDisco) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
355 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
356 def __init__(self, parent): |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
357 self.plugin_parent = parent |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
358 |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
359 def connectionInitialized(self): |
1524
7b0fcefd52d4
plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
360 self.xmlstream.addObserver(IBB_OPEN, self.plugin_parent._onIBBOpen, profile=self.parent.profile) |
384
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
361 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
362 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
363 return [disco.DiscoFeature(NS_IBB)] |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
364 |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
365 def getDiscoItems(self, requestor, target, nodeIdentifier=''): |
785420cd63f7
plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
366 return [] |