annotate sat/plugins/plugin_xep_0095.py @ 2603:5d4ac5415b40

plugins schema, merge-requests, tickets: convert labels from textbox to list only when "labels_as_list" is set in extra parameters.
author Goffi <goffi@goffi.org>
date Fri, 01 Jun 2018 12:21:23 +0200
parents 26edcf3a30eb
children 56f94936df1e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
2483
0046283a285d dates update
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
5 # Copyright (C) 2009-2018 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
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
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
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
75 def streamInit(self, iq_elt, client):
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
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
79 """
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
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
89 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
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
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
92 self.sendError(client, iq_elt, 'bad-profile')
385
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
93
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
94 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
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 """
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 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
101 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
102 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
103 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
104 si_condition = None
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
105
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
106 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
107 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
108 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
109
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
110 client.send(iq_error_elt)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
111
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
112 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
113 """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
114
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 @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
116 @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
117 @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
118 """
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
119 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
120 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
121 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
122 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
123 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
124 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
125 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
126 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
127 client.send(result_elt)
385
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
128
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
129 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
130 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
131 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
132 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
133 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
134 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
135 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
136
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
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
138 def proposeStream(self, client, to_jid, si_profile, feature_elt, misc_elts, mime_type='application/octet-stream'):
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
139 """Propose a stream initiation
385
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
140
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
141 @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
142 @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
143 @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
144 @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
145 @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
146 @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
147 - 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
148 - (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
149 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
150 """
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 offer = client.IQ()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
152 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
153 log.debug(_(u"Stream Session ID: %s") % offer["id"])
385
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
154
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
155 offer["from"] = client.jid.full()
385
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
156 offer["to"] = to_jid.full()
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
157 si = offer.addElement('si', NS_SI)
385
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
158 si['id'] = sid
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
159 si["mime-type"] = mime_type
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
160 si["profile"] = si_profile
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
161 for elt in misc_elts:
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
162 si.addChild(elt)
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
163 si.addChild(feature_elt)
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
164
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
165 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
166 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
167 return sid, offer_d
385
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
168
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
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 class XEP_0095_handler(xmlstream.XMPPHandler):
385
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
171 implements(iwokkel.IDisco)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
172
385
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
173 def __init__(self, plugin_parent):
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
174 self.plugin_parent = plugin_parent
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
175 self.host = plugin_parent.host
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
176
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
177 def connectionInitialized(self):
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
178 self.xmlstream.addObserver(SI_REQUEST, self.plugin_parent.streamInit, client=self.parent)
385
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
179
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
180 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
181 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
182
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
183 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
41fdaeb005bc plugins: Stream initiation (xep-0095) implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
184 return []