annotate src/plugins/plugin_xep_0047.py @ 1852:569c48e4cf0d

plugin blog import: mb_data handle unicode only, so comments_service must be a unicode and not a JID
author Goffi <goffi@goffi.org>
date Wed, 24 Feb 2016 16:11:36 +0100
parents d17772b0fe22
children 2daf7b4c6756
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1628
diff changeset
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
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 638
diff changeset
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 = {
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
54 "name": "In-Band Bytestream Plugin",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
55 "import_name": "XEP-0047",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
56 "type": "XEP",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
57 "protocols": ["XEP-0047"],
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
58 "main": "XEP_0047",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
59 "handler": "yes",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
60 "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
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
72 def getHandler(self, profile):
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
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
75 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
76 client = self.host.getClient(profile)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
77 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
78
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
79 def _timeOut(self, sid, client):
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
80 """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
81
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
82 @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
83 @param client: %(doc_client)s
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
84 """
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
85 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
86 .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
87 self._killSession(sid, client, "TIMEOUT")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
88
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
89 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
90 """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
91
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
92 @param sid(unicode): session id
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
93 @param client: %(doc_client)s
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
94 @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
95 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
96 """
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
97 try:
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
98 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
99 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
100 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
101 return
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
102
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
103 try:
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
104 observer_cb = session['observer_cb']
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
105 except KeyError:
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
106 pass
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
107 else:
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
108 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
109
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
110 if session['timer'].active():
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
111 session['timer'].cancel()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
112
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
113 del client.xep_0047_current_stream[sid]
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
114
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
115 success = failure_reason is None
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
116 stream_d = session[DEFER_KEY]
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
117
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
118 if success:
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
119 stream_d.callback(None)
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
120 else:
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
121 stream_d.errback(failure.Failure(exceptions.DataError(failure_reason)))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
122
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
123 def createSession(self, *args, **kwargs):
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
124 """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
125
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
126 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
127 """
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
128 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
129
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
130 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
131 """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
132
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
133 @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
134 @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
135 @param sid(unicode): session id
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
136 @param profile: %(doc_profile)s
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
137 @return (dict): session data
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
138 """
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
139 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
140 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
141 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
142 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
143 {'id': sid,
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
144 DEFER_KEY: defer.Deferred(),
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
145 'to': to_jid,
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
146 'file_obj': file_obj,
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
147 'seq': -1,
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
148 '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
149 }
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
150
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
151 return session_data
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
152
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
153 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
154 """"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
155
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
156 @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
157 @param profile: %(doc_profile)s
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
158 """
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
159 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
160 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
161 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
162 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
163 block_size = open_elt.getAttribute('block-size')
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
164 sid = open_elt.getAttribute('sid')
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
165 stanza = open_elt.getAttribute('stanza', 'iq')
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
166 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
167 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
168 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
169 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
170 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
171 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
172 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
173 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
174 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
175
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
176 # 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
177
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
178 # we reset the timeout:
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
179 session_data["timer"].reset(TIMEOUT)
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
180
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
181 # 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
182 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
183 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
184 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
185 # 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
186 # 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
187 # 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
188 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
189 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
190 # 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
191 iq_result_elt = xmlstream.toResponse(iq_elt, 'result')
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
192 client.xmlstream.send(iq_result_elt)
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
193
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
194 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
195 """"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
196
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
197 @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
198 @param profile: %(doc_profile)s
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
199 """
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
200 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
201 client = self.host.getClient(profile)
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
202 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
203 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
204 # 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
205 sid = close_elt['sid']
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
206
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
207 iq_result_elt = xmlstream.toResponse(iq_elt, 'result')
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
208 client.xmlstream.send(iq_result_elt)
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
209 self._killSession(sid, client)
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
210
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
211 def _onIBBData(self, element, profile):
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
212 """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
213
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
214 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
215 @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
216 @param profile: %(doc_profile)s
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
217 """
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
218 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
219 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
220 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
221 sid = data_elt['sid']
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
222
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
223 try:
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
224 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
225 except KeyError:
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
226 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
227 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
228
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
229 from_jid = session_data["to"]
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
230 file_obj = session_data["file_obj"]
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
231
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
232 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
233 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
234 if element.name == 'iq':
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
235 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
236 return
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
237
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
238 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
239 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
240 log.warning(_(u"Sequence error"))
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
241 if element.name == 'iq':
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
242 reason = 'not-acceptable'
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
243 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
244 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
245 return
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
246
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
247 # we reset the timeout:
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
248 session_data["timer"].reset(TIMEOUT)
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
249
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
250 # we can now decode the data
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
251 try:
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
252 file_obj.write(base64.b64decode(str(data_elt)))
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
253 except TypeError:
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
254 # The base64 data is invalid
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
255 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
256 if element.name == 'iq':
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
257 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
258 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
259 return
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
260
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
261 # we can now ack success
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
262 if element.name == 'iq':
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
263 iq_result_elt = xmlstream.toResponse(element, 'result')
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
264 client.xmlstream.send(iq_result_elt)
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
265
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
266 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
267 """Send error stanza
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
268
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
269 @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
270 @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
271 @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
272 @param client: %(doc_client)s
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
273 """
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
274 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
275 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
276 if sid is not None:
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
277 self._killSession(sid, client, error_condition)
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
278 client.xmlstream.send(iq_elt)
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
279
1558
6a8dd91476f0 plugin XEP-0047: minor improvements
Goffi <goffi@goffi.org>
parents: 1524
diff changeset
280 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
281 """Launch the stream workflow
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
282
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
283 @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
284 @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
285 @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
286 @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
287 @param profile: %(doc_profile)s
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
288 """
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
289 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
290 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
291
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
292 if block_size is None:
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
293 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
294 assert block_size <= 65535
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
295 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
296
1578
7fef6cdf5953 plugin XEP-0047: some cleaning
Goffi <goffi@goffi.org>
parents: 1558
diff changeset
297 iq_elt = client.IQ()
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
298 iq_elt['to'] = to_jid.full()
1578
7fef6cdf5953 plugin XEP-0047: some cleaning
Goffi <goffi@goffi.org>
parents: 1558
diff changeset
299 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
300 open_elt['block-size'] = str(block_size)
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
301 open_elt['sid'] = sid
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
302 open_elt['stanza'] = 'iq' # TODO: manage <message> stanza ?
1578
7fef6cdf5953 plugin XEP-0047: some cleaning
Goffi <goffi@goffi.org>
parents: 1558
diff changeset
303 args = [session_data, client]
7fef6cdf5953 plugin XEP-0047: some cleaning
Goffi <goffi@goffi.org>
parents: 1558
diff changeset
304 d = iq_elt.send()
7fef6cdf5953 plugin XEP-0047: some cleaning
Goffi <goffi@goffi.org>
parents: 1558
diff changeset
305 d.addCallbacks(self._IQDataStreamCb, self._IQDataStreamEb, args, None, args)
1558
6a8dd91476f0 plugin XEP-0047: minor improvements
Goffi <goffi@goffi.org>
parents: 1524
diff changeset
306 return session_data[DEFER_KEY]
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
307
1578
7fef6cdf5953 plugin XEP-0047: some cleaning
Goffi <goffi@goffi.org>
parents: 1558
diff changeset
308 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
309 """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
310
1578
7fef6cdf5953 plugin XEP-0047: some cleaning
Goffi <goffi@goffi.org>
parents: 1558
diff changeset
311 @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
312 @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
313 @param client: %(doc_client)s
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
314 """
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
315 session_data["timer"].reset(TIMEOUT)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
316
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
317 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
318 if buffer_:
1578
7fef6cdf5953 plugin XEP-0047: some cleaning
Goffi <goffi@goffi.org>
parents: 1558
diff changeset
319 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
320 next_iq_elt['to'] = session_data["to"].full()
1578
7fef6cdf5953 plugin XEP-0047: some cleaning
Goffi <goffi@goffi.org>
parents: 1558
diff changeset
321 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
322 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
323 data_elt['seq'] = unicode(seq)
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
324 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
325 data_elt.addContent(base64.b64encode(buffer_))
1578
7fef6cdf5953 plugin XEP-0047: some cleaning
Goffi <goffi@goffi.org>
parents: 1558
diff changeset
326 args = [session_data, client]
7fef6cdf5953 plugin XEP-0047: some cleaning
Goffi <goffi@goffi.org>
parents: 1558
diff changeset
327 d = next_iq_elt.send()
7fef6cdf5953 plugin XEP-0047: some cleaning
Goffi <goffi@goffi.org>
parents: 1558
diff changeset
328 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
329 else:
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
330 self.terminateStream(session_data, client)
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
331
1578
7fef6cdf5953 plugin XEP-0047: some cleaning
Goffi <goffi@goffi.org>
parents: 1558
diff changeset
332 def _IQDataStreamEb(self, failure, session_data, client):
7fef6cdf5953 plugin XEP-0047: some cleaning
Goffi <goffi@goffi.org>
parents: 1558
diff changeset
333 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
334 log.warning(u"IBB transfer failed: {}".format(failure.value))
1578
7fef6cdf5953 plugin XEP-0047: some cleaning
Goffi <goffi@goffi.org>
parents: 1558
diff changeset
335 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
336 log.error(u"IBB transfer failed: {}".format(failure.value))
1578
7fef6cdf5953 plugin XEP-0047: some cleaning
Goffi <goffi@goffi.org>
parents: 1558
diff changeset
337 self.terminateStream(session_data, client, "IQ_ERROR")
7fef6cdf5953 plugin XEP-0047: some cleaning
Goffi <goffi@goffi.org>
parents: 1558
diff changeset
338
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
339 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
340 """Terminate the stream session
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
341
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
342 @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
343 @param client: %(doc_client)s
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
344 @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
345 """
1578
7fef6cdf5953 plugin XEP-0047: some cleaning
Goffi <goffi@goffi.org>
parents: 1558
diff changeset
346 iq_elt = client.IQ()
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
347 iq_elt['to'] = session_data["to"].full()
1578
7fef6cdf5953 plugin XEP-0047: some cleaning
Goffi <goffi@goffi.org>
parents: 1558
diff changeset
348 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
349 close_elt['sid'] = session_data['id']
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
350 iq_elt.send()
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
351 self._killSession(session_data['id'], client, failure_reason)
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
352
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
353
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
354 class XEP_0047_handler(XMPPHandler):
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
355 implements(iwokkel.IDisco)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
356
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
357 def __init__(self, parent):
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
358 self.plugin_parent = parent
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
359
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
360 def connectionInitialized(self):
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
361 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
362
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
363 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
364 return [disco.DiscoFeature(NS_IBB)]
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
365
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
366 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
367 return []