Mercurial > libervia-backend
annotate sat/plugins/plugin_xep_0095.py @ 2910:b2f323237fce
jp, plugin merge-requests: used u'' as default for item id in pubsub arguments + fixed some required arguments:
u"" is now used as defaut item id instead of node, as it needs to be serialised anyway. This is temporary solution, as empty string can be used for item id (not forbidden by XEP-0060), but for now this is not handled correctly in jp/SàT (see https://bugs.goffi.org/bugs/view/289). Correct solution will probably need to use a special key in extra to mark empty string in id.
Added/removed some required values for node or item when it made sense.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 14 Apr 2019 08:21:51 +0200 |
parents | 003b8b4b56a7 |
children | ab2696e34d29 |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
1 #!/usr/bin/env python2 |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
41fdaeb005bc
plugins: Stream initiation (xep-0095) 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 xep-0095 |
2771 | 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) 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. |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) 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. |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) 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/>. |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
771 | 20 from sat.core.i18n import _ |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
21 from sat.core.constants import Const as C |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
22 from sat.core.log import getLogger |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
23 |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
24 log = getLogger(__name__) |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
25 from sat.core import exceptions |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
26 from twisted.words.protocols.jabber import xmlstream |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
27 from twisted.words.protocols.jabber import error |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
28 from zope.interface import implements |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
29 from wokkel import disco |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
30 from wokkel import iwokkel |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 import uuid |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 PLUGIN_INFO = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
35 C.PI_NAME: "XEP 0095 Plugin", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
36 C.PI_IMPORT_NAME: "XEP-0095", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
37 C.PI_TYPE: "XEP", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
38 C.PI_PROTOCOLS: ["XEP-0095"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
39 C.PI_MAIN: "XEP_0095", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
40 C.PI_HANDLER: "yes", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
41 C.PI_DESCRIPTION: _("""Implementation of Stream Initiation"""), |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 } |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
44 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
45 IQ_SET = '/iq[@type="set"]' |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
46 NS_SI = "http://jabber.org/protocol/si" |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
47 SI_REQUEST = IQ_SET + '/si[@xmlns="' + NS_SI + '"]' |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
48 SI_PROFILE_HEADER = "http://jabber.org/protocol/si/profile/" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
49 SI_ERROR_CONDITIONS = ("bad-profile", "no-valid-streams") |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
50 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
51 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
52 class XEP_0095(object): |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 def __init__(self, host): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
54 log.info(_("Plugin XEP_0095 initialization")) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 self.host = host |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
56 self.si_profiles = {} # key: SI profile, value: callback |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
57 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
58 def getHandler(self, client): |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
59 return XEP_0095_handler(self) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 def registerSIProfile(self, si_profile, callback): |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 """Add a callback for a SI Profile |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
63 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
64 @param si_profile(unicode): SI profile name (e.g. file-transfer) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
65 @param callback(callable): method to call when the profile name is asked |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
66 """ |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
67 self.si_profiles[si_profile] = callback |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
69 def unregisterSIProfile(self, si_profile): |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
70 try: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
71 del self.si_profiles[si_profile] |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
72 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
73 log.error( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
74 u"Trying to unregister SI profile [{}] which was not registered".format( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
75 si_profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
76 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
77 ) |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
78 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
79 def streamInit(self, iq_elt, client): |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 """This method is called on stream initiation (XEP-0095 #3.2) |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
81 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
82 @param iq_elt: IQ element |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
83 """ |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
84 log.info(_("XEP-0095 Stream initiation")) |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
85 iq_elt.handled = True |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
86 si_elt = iq_elt.elements(NS_SI, "si").next() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
87 si_id = si_elt["id"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
88 si_mime_type = iq_elt.getAttribute("mime-type", "application/octet-stream") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
89 si_profile = si_elt["profile"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
90 si_profile_key = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
91 si_profile[len(SI_PROFILE_HEADER) :] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
92 if si_profile.startswith(SI_PROFILE_HEADER) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
93 else si_profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
94 ) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
95 if si_profile_key in self.si_profiles: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
96 # We know this SI profile, we call the callback |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
97 self.si_profiles[si_profile_key](client, iq_elt, si_id, si_mime_type, si_elt) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
99 # We don't know this profile, we send an error |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
100 self.sendError(client, iq_elt, "bad-profile") |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
102 def sendError(self, client, request, condition): |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
103 """Send IQ error as a result |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
105 @param request(domish.Element): original IQ request |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
106 @param condition(str): error condition |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
107 """ |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
108 if condition in SI_ERROR_CONDITIONS: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
109 si_condition = condition |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
110 condition = "bad-request" |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
111 else: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
112 si_condition = None |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
113 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
114 iq_error_elt = error.StanzaError(condition).toResponse(request) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
115 if si_condition is not None: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
116 iq_error_elt.error.addElement((NS_SI, si_condition)) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
117 |
2129
6a66c8c5a567
core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
118 client.send(iq_error_elt) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
119 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
120 def acceptStream(self, client, iq_elt, feature_elt, misc_elts=None): |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
121 """Send the accept stream initiation answer |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
122 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
123 @param iq_elt(domish.Element): initial SI request |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
124 @param feature_elt(domish.Element): 'feature' element containing stream method to use |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
125 @param misc_elts(list[domish.Element]): list of elements to add |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 """ |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
127 log.info(_("sending stream initiation accept answer")) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
128 if misc_elts is None: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
129 misc_elts = [] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
130 result_elt = xmlstream.toResponse(iq_elt, "result") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
131 si_elt = result_elt.addElement((NS_SI, "si")) |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
132 si_elt.addChild(feature_elt) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
133 for elt in misc_elts: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
134 si_elt.addChild(elt) |
2129
6a66c8c5a567
core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
135 client.send(result_elt) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
137 def _parseOfferResult(self, iq_elt): |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
138 try: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
139 si_elt = iq_elt.elements(NS_SI, "si").next() |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
140 except StopIteration: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
141 log.warning(u"No <si/> element found in result while expected") |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
142 raise exceptions.DataError |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
143 return (iq_elt, si_elt) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
144 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
145 def proposeStream( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
146 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
147 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
148 to_jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
149 si_profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
150 feature_elt, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
151 misc_elts, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
152 mime_type="application/octet-stream", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
153 ): |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
154 """Propose a stream initiation |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
156 @param to_jid(jid.JID): recipient |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
157 @param si_profile(unicode): Stream initiation profile (XEP-0095) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
158 @param feature_elt(domish.Element): feature element, according to XEP-0020 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
159 @param misc_elts(list[domish.Element]): list of elements to add |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
160 @param mime_type(unicode): stream mime type |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
161 @return (tuple): tuple with: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
162 - session id (unicode) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
163 - (D(domish_elt, domish_elt): offer deferred which returl a tuple |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
164 with iq_elt and si_elt |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
165 """ |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
166 offer = client.IQ() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
167 sid = str(uuid.uuid4()) |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
168 log.debug(_(u"Stream Session ID: %s") % offer["id"]) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
170 offer["from"] = client.jid.full() |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 offer["to"] = to_jid.full() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
172 si = offer.addElement("si", NS_SI) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
173 si["id"] = sid |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 si["mime-type"] = mime_type |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 si["profile"] = si_profile |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 for elt in misc_elts: |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 si.addChild(elt) |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 si.addChild(feature_elt) |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
180 offer_d = offer.send() |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
181 offer_d.addCallback(self._parseOfferResult) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
182 return sid, offer_d |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
184 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
185 class XEP_0095_handler(xmlstream.XMPPHandler): |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 implements(iwokkel.IDisco) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
187 |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 def __init__(self, plugin_parent): |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 self.plugin_parent = plugin_parent |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 self.host = plugin_parent.host |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 def connectionInitialized(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
193 self.xmlstream.addObserver( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
194 SI_REQUEST, self.plugin_parent.streamInit, client=self.parent |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
195 ) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
197 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
198 return [disco.DiscoFeature(NS_SI)] + [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
199 disco.DiscoFeature( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
200 u"http://jabber.org/protocol/si/profile/{}".format(profile_name) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
201 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
202 for profile_name in self.plugin_parent.si_profiles |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
203 ] |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
205 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 return [] |