Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0095.py @ 2473:447c3de6b9e5
plugin merge-requests: fixed "set" method
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 13 Jan 2018 10:12:15 +0100 |
parents | 8b37a62336c3 |
children | 0046283a285d |
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 |
2414
8b37a62336c3
misc: date update (yes it's a bit late :p )
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
5 # Copyright (C) 2009-2017 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 |
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
23 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
|
24 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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 from wokkel import iwokkel |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 import uuid |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 |
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 PLUGIN_INFO = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 C.PI_HANDLER: "yes", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
40 C.PI_DESCRIPTION: _("""Implementation of Stream Initiation""") |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 } |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
43 |
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
|
44 IQ_SET = '/iq[@type="set"]' |
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 NS_SI = 'http://jabber.org/protocol/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
|
46 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
|
47 SI_PROFILE_HEADER = "http://jabber.org/protocol/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
|
48 SI_ERROR_CONDITIONS = ('bad-profile', 'no-valid-streams') |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
49 |
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 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
51 class XEP_0095(object): |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 |
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: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
73 log.error(u"Trying to unregister SI profile [{}] which was not registered".format(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
|
74 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
75 def streamInit(self, iq_elt, profile): |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 """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
|
77 |
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 @param iq_elt: IQ element |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 @param profile: %(doc_profile)s""" |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
80 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
|
81 iq_elt.handled = True |
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 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
|
83 si_id = si_elt['id'] |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
84 si_mime_type = iq_elt.getAttribute('mime-type', 'application/octet-stream') |
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 si_profile = si_elt['profile'] |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
86 si_profile_key = si_profile[len(SI_PROFILE_HEADER):] if si_profile.startswith(SI_PROFILE_HEADER) else si_profile |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
87 if si_profile_key in self.si_profiles: |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 #We know this SI profile, we call the callback |
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
|
89 self.si_profiles[si_profile_key](iq_elt, si_id, si_mime_type, si_elt, profile) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 else: |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 #We don't know this profile, we send an error |
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
|
92 self.sendError(iq_elt, 'bad-profile', profile) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 |
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
|
94 def sendError(self, request, condition, 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
|
95 """Send IQ error as a result |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 |
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
|
97 @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
|
98 @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
|
99 @param profile: %(doc_profile)s |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
100 """ |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
101 client = self.host.getClient(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
|
102 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
|
103 si_condition = 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
|
104 condition = 'bad-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
|
105 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
|
106 si_condition = None |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
107 |
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
|
108 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
|
109 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
|
110 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
|
111 |
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
|
112 client.send(iq_error_elt) |
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 def acceptStream(self, iq_elt, feature_elt, misc_elts=None, profile=C.PROF_KEY_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
|
115 """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
|
116 |
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 @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
|
118 @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
|
119 @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
|
120 @param profile: %(doc_profile)s |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 """ |
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
|
122 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
|
123 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
|
124 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
|
125 client = self.host.getClient(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
|
126 result_elt = xmlstream.toResponse(iq_elt, 'result') |
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 si_elt = result_elt.addElement((NS_SI, '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
|
128 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
|
129 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
|
130 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
|
131 client.send(result_elt) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 |
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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 |
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 |
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 def proposeStream(self, to_jid, si_profile, feature_elt, misc_elts, mime_type='application/octet-stream', profile=C.PROF_KEY_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
|
143 """Propose a stream initiation |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 |
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
|
145 @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
|
146 @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
|
147 @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
|
148 @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
|
149 @param mime_type(unicode): stream mime type |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 @param profile: %(doc_profile)s |
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
|
151 @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
|
152 - 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
|
153 - (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
|
154 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
|
155 """ |
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 client = self.host.getClient(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
|
157 offer = client.IQ() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
158 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
|
159 log.debug(_(u"Stream Session ID: %s") % offer["id"]) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 |
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
|
161 offer["from"] = client.jid.full() |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 offer["to"] = to_jid.full() |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
163 si = offer.addElement('si', NS_SI) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 si['id'] = sid |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 si["mime-type"] = mime_type |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 si["profile"] = si_profile |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 for elt in misc_elts: |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 si.addChild(elt) |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 si.addChild(feature_elt) |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 |
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
|
171 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
|
172 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
|
173 return sid, offer_d |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
175 |
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
|
176 class XEP_0095_handler(xmlstream.XMPPHandler): |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 implements(iwokkel.IDisco) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
178 |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 def __init__(self, plugin_parent): |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 self.plugin_parent = plugin_parent |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 self.host = plugin_parent.host |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 def connectionInitialized(self): |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
184 self.xmlstream.addObserver(SI_REQUEST, self.plugin_parent.streamInit, profile=self.parent.profile) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |
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
|
187 return [disco.DiscoFeature(NS_SI)] + [disco.DiscoFeature(u"http://jabber.org/protocol/si/profile/{}".format(profile_name)) for profile_name in self.plugin_parent.si_profiles] |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 def getDiscoItems(self, requestor, target, nodeIdentifier=''): |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 return [] |