annotate src/plugins/plugin_xep_0047.py @ 1572:6a6fe840c3a6

quick frontend: fixed resources display in quickContactList
author Goffi <goffi@goffi.org>
date Sun, 08 Nov 2015 15:16:14 +0100
parents 6a8dd91476f0
children 7fef6cdf5953
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)
1396
069ad98b360d 2015 copyright dates update
Goffi <goffi@goffi.org>
parents: 993
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 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 client as jabber_client
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 jid
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 xmlstream
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
28 from twisted.words.protocols.jabber import error
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
29 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
30 from twisted.internet import defer
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
31 from twisted.python import failure
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
32
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
33 from wokkel import disco, iwokkel
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
34
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
35 from zope.interface import implements
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
36
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
37 import base64
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
38
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
39 try:
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
40 from twisted.words.protocols.xmlstream import XMPPHandler
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
41 except ImportError:
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
42 from wokkel.subprotocols import XMPPHandler
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
43
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
44 MESSAGE = '/message'
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
45 IQ_SET = '/iq[@type="set"]'
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
46 NS_IBB = 'http://jabber.org/protocol/ibb'
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
47 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
48 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
49 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
50 IBB_MESSAGE_DATA = MESSAGE + '/data[@xmlns="' + NS_IBB + '" and @sid="{}"]'
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
51 TIMEOUT = 60 # timeout for workflow
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
52 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
53
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
54 PLUGIN_INFO = {
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
55 "name": "In-Band Bytestream Plugin",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
56 "import_name": "XEP-0047",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
57 "type": "XEP",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
58 "protocols": ["XEP-0047"],
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
59 "main": "XEP_0047",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
60 "handler": "yes",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
61 "description": _("""Implementation of In-Band Bytestreams""")
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
62 }
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
63
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
64
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
65 class XEP_0047(object):
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
66 NAMESPACE = NS_IBB
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
67 BLOCK_SIZE = 4096
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
68
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
69 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
70 log.info(_("In-Band Bytestreams plugin initialization"))
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
71 self.host = host
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
72
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
73 def getHandler(self, profile):
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
74 return XEP_0047_handler(self)
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
75
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
76 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
77 client = self.host.getClient(profile)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
78 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
79
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
80 def _timeOut(self, sid, client):
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
81 """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
82
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
83 @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
84 @param client: %(doc_client)s
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
85 """
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
86 log.info(_("In-Band Bytestream: TimeOut reached for id {sid} [{profile}]")
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
87 .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
88 self._killSession(sid, client, "TIMEOUT")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
89
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
90 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
91 """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
92
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
93 @param sid(unicode): session id
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
94 @param client: %(doc_client)s
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
95 @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
96 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
97 """
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
98 try:
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
99 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
100 except KeyError:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
101 log.warning(_("kill id called on a non existant id"))
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
102 return
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
103
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
104 try:
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
105 observer_cb = session['observer_cb']
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
106 except KeyError:
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
107 pass
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
108 else:
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
109 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
110
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
111 if session['timer'].active():
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
112 session['timer'].cancel()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
113
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
114 del client.xep_0047_current_stream[sid]
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
115
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
116 success = failure_reason is None
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
117 stream_d = session[DEFER_KEY]
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
118
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
119 if success:
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
120 stream_d.callback(None)
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
121 else:
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
122 stream_d.errback(failure.Failure(exceptions.DataError(failure_reason)))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
123
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
124 def createSession(self, *args, **kwargs):
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
125 """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
126
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
127 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
128 """
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
129 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
130
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
131 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
132 """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
133
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
134 @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
135 @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
136 @param sid(unicode): session id
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
137 @param profile: %(doc_profile)s
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
138 @return (dict): session data
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
139 """
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
140 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
141 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
142 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
143 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
144 {'id': sid,
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
145 DEFER_KEY: defer.Deferred(),
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
146 'to': to_jid,
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
147 'file_obj': file_obj,
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
148 'seq': -1,
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
149 '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
150 }
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
151
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
152 return session_data
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
153
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
154 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
155 """"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
156
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
157 @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
158 @param profile: %(doc_profile)s
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
159 """
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
160 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
161 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
162 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
163 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
164 block_size = open_elt.getAttribute('block-size')
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
165 sid = open_elt.getAttribute('sid')
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
166 stanza = open_elt.getAttribute('stanza', 'iq')
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
167 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
168 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
169 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
170 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
171 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
172 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
173 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
174 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
175 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
176
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
177 # 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
178
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
179 # we reset the timeout:
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
180 session_data["timer"].reset(TIMEOUT)
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
181
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
182 # 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
183 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
184 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
185 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
186 # 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
187 # 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
188 # 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
189 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
190 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
191 # 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
192 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
193 client.xmlstream.send(iq_result_elt)
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
194
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
195 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
196 """"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
197
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
198 @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
199 @param profile: %(doc_profile)s
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
200 """
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
201 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
202 client = self.host.getClient(profile)
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
203 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
204 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
205 # 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
206 sid = close_elt['sid']
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
207
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
208 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
209 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
210 self._killSession(sid, client)
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
211
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
212 def _onIBBData(self, element, profile):
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
213 """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
214
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
215 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
216 @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
217 @param profile: %(doc_profile)s
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
218 """
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
219 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
220 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
221 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
222 sid = data_elt['sid']
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
223
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
224 try:
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
225 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
226 except KeyError:
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
227 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
228 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
229
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
230 from_jid = session_data["to"]
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
231 file_obj = session_data["file_obj"]
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
232
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
233 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
234 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
235 if element.name == 'iq':
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
236 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
237 return
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
238
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
239 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
240 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
241 log.warning(_(u"Sequence error"))
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
242 if element.name == 'iq':
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
243 reason = 'not-acceptable'
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
244 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
245 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
246 return
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
247
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
248 # we reset the timeout:
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
249 session_data["timer"].reset(TIMEOUT)
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
250
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
251 # we can now decode the data
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
252 try:
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
253 file_obj.write(base64.b64decode(str(data_elt)))
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
254 except TypeError:
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
255 # The base64 data is invalid
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
256 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
257 if element.name == 'iq':
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
258 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
259 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
260 return
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
261
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
262 # we can now ack success
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
263 if element.name == 'iq':
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
264 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
265 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
266
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
267 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
268 """Send error stanza
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
269
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
270 @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
271 @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
272 @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
273 @param client: %(doc_client)s
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
274 """
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
275 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
276 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
277 if sid is not None:
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
278 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
279 client.xmlstream.send(iq_elt)
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
280
1558
6a8dd91476f0 plugin XEP-0047: minor improvements
Goffi <goffi@goffi.org>
parents: 1524
diff changeset
281 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
282 """Launch the stream workflow
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
283
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
284 @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
285 @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
286 @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
287 @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
288 @param profile: %(doc_profile)s
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
289 """
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
290 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
291 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
292
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
293 if block_size is None:
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
294 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
295 assert block_size <= 65535
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
296 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
297
1558
6a8dd91476f0 plugin XEP-0047: minor improvements
Goffi <goffi@goffi.org>
parents: 1524
diff changeset
298 iq_elt = jabber_client.IQ(client.xmlstream, 'set') # FIXME: use client.IQ here
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
299 iq_elt['from'] = client.jid.full()
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
300 iq_elt['to'] = to_jid.full()
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
301 open_elt = iq_elt.addElement('open', NS_IBB)
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
302 open_elt['block-size'] = str(block_size)
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
303 open_elt['sid'] = sid
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
304 open_elt['stanza'] = 'iq' # TODO: manage <message> stanza ?
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
305 iq_elt.addCallback(self._IQDataStream, session_data, client)
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
306 iq_elt.send()
1558
6a8dd91476f0 plugin XEP-0047: minor improvements
Goffi <goffi@goffi.org>
parents: 1524
diff changeset
307 return session_data[DEFER_KEY]
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
308
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
309 def _IQDataStream(self, session_data, client, iq_elt):
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
310 """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
311
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 @param iq_elt(domish.Element): iq result
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
315 """
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
316 if iq_elt['type'] == 'error':
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
317 log.warning(_(u"IBB transfer failed: {}").format(iq_elt))
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
318 self.terminateStream(session_data, client, "IQ_ERROR")
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
319 return
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
320
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
321 session_data["timer"].reset(TIMEOUT)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
322
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
323 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
324 if buffer_:
1558
6a8dd91476f0 plugin XEP-0047: minor improvements
Goffi <goffi@goffi.org>
parents: 1524
diff changeset
325 next_iq_elt = jabber_client.IQ(client.xmlstream, 'set') # FIXME: use client.IQ here
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
326 next_iq_elt['to'] = session_data["to"].full()
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
327 data_elt = next_iq_elt.addElement('data', NS_IBB)
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
328 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
329 data_elt['seq'] = unicode(seq)
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
330 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
331 data_elt.addContent(base64.b64encode(buffer_))
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
332 next_iq_elt.addCallback(self._IQDataStream, session_data, client)
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
333 next_iq_elt.send()
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
334 else:
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
335 self.terminateStream(session_data, client)
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
336
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
337 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
338 """Terminate the stream session
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
339
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
340 @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
341 @param client: %(doc_client)s
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
342 @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
343 """
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
344 iq_elt = jabber_client.IQ(client.xmlstream, 'set')
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
345 iq_elt['to'] = session_data["to"].full()
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
346 close_elt = iq_elt.addElement('close', NS_IBB)
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
347 close_elt['sid'] = session_data['id']
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
348 iq_elt.send()
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
349 self._killSession(session_data['id'], client, failure_reason)
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
350
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
351
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
352 class XEP_0047_handler(XMPPHandler):
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
353 implements(iwokkel.IDisco)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
354
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
355 def __init__(self, parent):
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
356 self.plugin_parent = parent
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
357
384
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
358 def connectionInitialized(self):
1524
7b0fcefd52d4 plugin XEP-0047, XEP-0096: In-Band Bystream plugin cleaning:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
359 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
360
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
361 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
362 return [disco.DiscoFeature(NS_IBB)]
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
363
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
364 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
785420cd63f7 plugins: In-Band Bytestreams (XEP-0047) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
365 return []