Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0095.py @ 1069:8e1f30aa3975
core (XMLUI): data form result now manage generic data set
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 14 Jun 2014 17:24:16 +0200 |
parents | 301b342c697a |
children | 069ad98b360d |
rev | line source |
---|---|
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
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 |
811 | 5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 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__) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from twisted.words.xish import domish |
941
c6d8fc63b1db
core, plugins: host.getClient now raise an exception instead of returning None when no profile is found, plugins have been adapted consequently and a bit cleaned
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
25 from twisted.words.protocols.jabber import client |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 import uuid |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from zope.interface import implements |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 try: |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 from twisted.words.protocols.xmlstream import XMPPHandler |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 except ImportError: |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 from wokkel.subprotocols import XMPPHandler |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 from wokkel import disco, iwokkel |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 IQ_SET = '/iq[@type="set"]' |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 NS_SI = 'http://jabber.org/protocol/si' |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 SI_REQUEST = IQ_SET + '/si[@xmlns="' + NS_SI + '"]' |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 SI_PROFILE_HEADER = "http://jabber.org/protocol/si/profile/" |
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 PLUGIN_INFO = { |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
43 "name": "XEP 0095 Plugin", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
44 "import_name": "XEP-0095", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
45 "type": "XEP", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
46 "protocols": ["XEP-0095"], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
47 "main": "XEP_0095", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
48 "handler": "yes", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
49 "description": _("""Implementation of Stream Initiation""") |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 } |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
52 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
53 class XEP_0095(object): |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 def __init__(self, host): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
56 log.info(_("Plugin XEP_0095 initialization")) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 self.host = host |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
58 self.si_profiles = {} # key: SI profile, value: callback |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
59 |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 def getHandler(self, profile): |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
61 return XEP_0095_handler(self) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 def registerSIProfile(self, si_profile, callback): |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 """Add a callback for a SI Profile |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 param si_profile: SI profile name (e.g. file-transfer) |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 param callback: method to call when the profile name is asked""" |
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 |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 def streamInit(self, iq_el, profile): |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 """This method is called on stream initiation (XEP-0095 #3.2) |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 @param iq_el: IQ element |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 @param profile: %(doc_profile)s""" |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
73 log.info(_("XEP-0095 Stream initiation")) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
74 iq_el.handled = True |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 si_el = iq_el.firstChildElement() |
398 | 76 si_id = si_el.getAttribute('id') |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 si_mime_type = iq_el.getAttribute('mime-type', 'application/octet-stream') |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 si_profile = si_el.getAttribute('profile') |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
79 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
|
80 if si_profile_key in self.si_profiles: |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 #We know this SI profile, we call the callback |
398 | 82 self.si_profiles[si_profile_key](iq_el['id'], iq_el['from'], si_id, si_mime_type, si_el, profile) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 else: |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 #We don't know this profile, we send an error |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 self.sendBadProfileError(iq_el['id'], iq_el['from'], profile) |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
87 def sendRejectedError(self, iq_id, to_jid, reason='Offer Declined', profile=C.PROF_KEY_NONE): |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 """Helper method to send when the stream is rejected |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
89 @param iq_id: IQ id |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 @param to_jid: recipient |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 @param reason: human readable reason (string) |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 @param profile: %(doc_profile)s""" |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
93 self.sendError(iq_id, to_jid, 403, 'cancel', {'text': reason}, profile=profile) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
95 def sendBadProfileError(self, iq_id, to_jid, profile): |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 """Helper method to send when we don't know the SI profile |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
97 @param iq_id: IQ id |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 @param to_jid: recipient |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 @param profile: %(doc_profile)s""" |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
100 self.sendError(iq_id, to_jid, 400, 'modify', profile=profile) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
102 def sendBadRequestError(self, iq_id, to_jid, profile): |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 """Helper method to send when we don't know the SI profile |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
104 @param iq_id: IQ id |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 @param to_jid: recipient |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 @param profile: %(doc_profile)s""" |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
107 self.sendError(iq_id, to_jid, 400, 'cancel', profile=profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
108 |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
109 def sendFailedError(self, iq_id, to_jid, profile): |
391 | 110 """Helper method to send when we transfer failed |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
111 @param iq_id: IQ id |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 @param to_jid: recipient |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 @param profile: %(doc_profile)s""" |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
114 self.sendError(iq_id, to_jid, 500, 'cancel', {'custom': 'failed'}, profile=profile) # as there is no lerror code for failed transfer, we use 500 (undefined-condition) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
115 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
116 def sendError(self, iq_id, to_jid, err_code, err_type='cancel', data={}, profile=C.PROF_KEY_NONE): |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 """Send IQ error as a result |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
118 @param iq_id: IQ id |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 @param to_jid: recipient |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 @param err_code: error err_code (see XEP-0095 #4.2) |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 @param err_type: one of cancel, modify |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 @param data: error specific data (dictionary) |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 @param profile: %(doc_profile)s |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 """ |
941
c6d8fc63b1db
core, plugins: host.getClient now raise an exception instead of returning None when no profile is found, plugins have been adapted consequently and a bit cleaned
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
125 client_ = self.host.getClient(profile) |
536
a31abb97310d
core, plugins: fixed bad namespace in stanza creation
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
126 result = domish.Element((None, 'iq')) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 result['type'] = 'result' |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
128 result['id'] = iq_id |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
129 result['to'] = to_jid |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 error_el = result.addElement('error') |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
131 error_el['err_code'] = str(err_code) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 error_el['type'] = err_type |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
133 if err_code == 400 and err_type == 'cancel': |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
134 error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas', 'bad-request')) |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
135 error_el.addElement((NS_SI, 'no-valid-streams')) |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
136 elif err_code == 400 and err_type == 'modify': |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
137 error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas', 'bad-request')) |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
138 error_el.addElement((NS_SI, 'bad-profile')) |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
139 elif err_code == 403 and err_type == 'cancel': |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
140 error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas', 'forbidden')) |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
141 if 'text' in data: |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
142 error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas', 'text'), content=data['text']) |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
143 elif err_code == 500 and err_type == 'cancel': |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
144 condition_el = error_el.addElement((NS_SI, 'undefined-condition')) |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
145 if 'custom' in data and data['custom'] == 'failed': |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 condition_el.addContent('Stream failed') |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 |
941
c6d8fc63b1db
core, plugins: host.getClient now raise an exception instead of returning None when no profile is found, plugins have been adapted consequently and a bit cleaned
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
148 client_.xmlstream.send(result) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
150 def acceptStream(self, iq_id, to_jid, feature_elt, misc_elts=[], profile=C.PROF_KEY_NONE): |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 """Send the accept stream initiation answer |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
152 @param iq_id: IQ id |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 @param feature_elt: domish element 'feature' containing stream method to use |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 @param misc_elts: list of domish element to add |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 @param profile: %(doc_profile)s""" |
536
a31abb97310d
core, plugins: fixed bad namespace in stanza creation
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
156 _client = self.host.getClient(profile) |
a31abb97310d
core, plugins: fixed bad namespace in stanza creation
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
157 assert(_client) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
158 log.info(_("sending stream initiation accept answer")) |
536
a31abb97310d
core, plugins: fixed bad namespace in stanza creation
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
159 result = domish.Element((None, 'iq')) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 result['type'] = 'result' |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
161 result['id'] = iq_id |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
162 result['to'] = to_jid |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 si = result.addElement('si', NS_SI) |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 si.addChild(feature_elt) |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 for elt in misc_elts: |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 si.addChild(elt) |
536
a31abb97310d
core, plugins: fixed bad namespace in stanza creation
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
167 _client.xmlstream.send(result) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
169 def proposeStream(self, to_jid, si_profile, feature_elt, misc_elts, mime_type='application/octet-stream', profile_key=C.PROF_KEY_NONE): |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 """Propose a stream initiation |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 @param to_jid: recipient (JID) |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 @param si_profile: Stream initiation profile (XEP-0095) |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 @param feature_elt: feature domish element, according to XEP-0020 |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 @param misc_elts: list of domish element to add for this profile |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 @param mime_type: stream mime type |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 @param profile: %(doc_profile)s |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 @return: session id, offer""" |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 current_jid, xmlstream = self.host.getJidNStream(profile_key) |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 if not xmlstream: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
180 log.error(_('Asking for an non-existant or not connected profile')) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 return "" |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
182 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
183 offer = client.IQ(xmlstream, 'set') |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
184 sid = str(uuid.uuid4()) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
185 log.debug(_("Stream Session ID: %s") % offer["id"]) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 offer["from"] = current_jid.full() |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 offer["to"] = to_jid.full() |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
189 si = offer.addElement('si', NS_SI) |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 si['id'] = sid |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 si["mime-type"] = mime_type |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 si["profile"] = si_profile |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 for elt in misc_elts: |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 si.addChild(elt) |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 si.addChild(feature_elt) |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 offer.send() |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 return sid, offer |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
200 |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 class XEP_0095_handler(XMPPHandler): |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 implements(iwokkel.IDisco) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
203 |
385
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 def __init__(self, plugin_parent): |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 self.plugin_parent = plugin_parent |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 self.host = plugin_parent.host |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 def connectionInitialized(self): |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
209 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
|
210 |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 return [disco.DiscoFeature(NS_SI)] + [disco.DiscoFeature("http://jabber.org/protocol/si/profile/%s" % profile_name) for profile_name in self.plugin_parent.si_profiles] |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 def getDiscoItems(self, requestor, target, nodeIdentifier=''): |
41fdaeb005bc
plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 return [] |