Mercurial > libervia-backend
annotate sat/plugins/plugin_xep_0050.py @ 2834:6cd3549e8d67
we are in dev version again
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 02 Mar 2019 18:43:09 +0100 |
parents | 003b8b4b56a7 |
children | a8c2d8b3453f |
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 |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # SAT plugin for Ad-Hoc Commands (XEP-0050) |
2771 | 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
773 | 20 from sat.core.i18n import _, D_ |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
821
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:
944
diff
changeset
|
22 from sat.core.log import getLogger |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
23 |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
24 log = getLogger(__name__) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from twisted.words.protocols.jabber import jid |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
26 from twisted.words.protocols import jabber |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 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
|
28 from twisted.internet import defer |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
29 from wokkel import disco, iwokkel, data_form |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 from sat.core import exceptions |
758
86224a13cc1d
plugin xep-0050: using new Sessions class
Goffi <goffi@goffi.org>
parents:
753
diff
changeset
|
31 from sat.memory.memory import Sessions |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 from uuid import uuid4 |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
33 from sat.tools import xml_tools |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 from zope.interface import implements |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 try: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 from twisted.words.protocols.xmlstream import XMPPHandler |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 except ImportError: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 from wokkel.subprotocols import XMPPHandler |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 from collections import namedtuple |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
45 from collections import OrderedDict # only available from python 2.7 |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 except ImportError: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 from ordereddict import OrderedDict |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 IQ_SET = '/iq[@type="set"]' |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 NS_COMMANDS = "http://jabber.org/protocol/commands" |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 ID_CMD_LIST = disco.DiscoIdentity("automation", "command-list") |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 ID_CMD_NODE = disco.DiscoIdentity("automation", "command-node") |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 CMD_REQUEST = IQ_SET + '/command[@xmlns="' + NS_COMMANDS + '"]' |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
55 SHOWS = OrderedDict( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
56 [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
57 ("default", _("Online")), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
58 ("away", _("Away")), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
59 ("chat", _("Free for chat")), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
60 ("dnd", _("Do not disturb")), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
61 ("xa", _("Left")), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
62 ("disconnect", _("Disconnect")), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
63 ] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
64 ) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 PLUGIN_INFO = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
67 C.PI_NAME: "Ad-Hoc Commands", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
68 C.PI_IMPORT_NAME: "XEP-0050", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
69 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
|
70 C.PI_PROTOCOLS: ["XEP-0050"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
71 C.PI_MAIN: "XEP_0050", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
72 C.PI_HANDLER: "yes", |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
73 C.PI_DESCRIPTION: _(u"""Implementation of Ad-Hoc Commands"""), |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 } |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 class AdHocError(Exception): |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 def __init__(self, error_const): |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 """ Error to be used from callback |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 @param error_const: one of XEP_0050.ERROR |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 """ |
1517
4eca4f5e21ec
plugin XEP-0050: minor parentheses removal
Goffi <goffi@goffi.org>
parents:
1505
diff
changeset
|
82 assert error_const in XEP_0050.ERROR |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 self.callback_error = error_const |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
85 |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 class AdHocCommand(XMPPHandler): |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 implements(iwokkel.IDisco) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
89 def __init__(self, callback, label, node, features, timeout, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
90 allowed_jids, allowed_groups, allowed_magics, forbidden_jids, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
91 forbidden_groups): |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
92 XMPPHandler.__init__(self) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 self.callback = callback |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 self.label = label |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 self.node = node |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 self.features = [disco.DiscoFeature(feature) for feature in features] |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
97 ( |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
98 self.allowed_jids, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
99 self.allowed_groups, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
100 self.allowed_magics, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
101 self.forbidden_jids, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
102 self.forbidden_groups, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
103 ) = ( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
104 allowed_jids, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
105 allowed_groups, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
106 allowed_magics, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
107 forbidden_jids, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
108 forbidden_groups, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
109 ) |
758
86224a13cc1d
plugin xep-0050: using new Sessions class
Goffi <goffi@goffi.org>
parents:
753
diff
changeset
|
110 self.sessions = Sessions(timeout=timeout) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
112 @property |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
113 def client(self): |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
114 return self.parent |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
115 |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 def getName(self, xml_lang=None): |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 return self.label |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 def isAuthorised(self, requestor): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
120 if "@ALL@" in self.allowed_magics: |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 return True |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 forbidden = set(self.forbidden_jids) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 for group in self.forbidden_groups: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 forbidden.update(self.client.roster.getJidsFromGroup(group)) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 if requestor.userhostJID() in forbidden: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 return False |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 allowed = set(self.allowed_jids) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 for group in self.allowed_groups: |
821
38bc9abd6722
plugin XEP-0050: fixed UnknownGroupError management + "@ALL@" profile for status command
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
129 try: |
38bc9abd6722
plugin XEP-0050: fixed UnknownGroupError management + "@ALL@" profile for status command
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
130 allowed.update(self.client.roster.getJidsFromGroup(group)) |
38bc9abd6722
plugin XEP-0050: fixed UnknownGroupError management + "@ALL@" profile for status command
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
131 except exceptions.UnknownGroupError: |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
132 log.warning(_(u"The groups [{group}] is unknown for profile [{profile}])") |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
133 .format(group=group, profile=self.client.profile)) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 if requestor.userhostJID() in allowed: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 return True |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 return False |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
138 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
139 if ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
140 nodeIdentifier != NS_COMMANDS |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
141 ): # FIXME: we should manage other disco nodes here |
1494
74ddb4cc2ff9
plugin XEP-0050: return disco for commands only on commands namespace
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
142 return [] |
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
|
143 # identities = [ID_CMD_LIST if self.node == NS_COMMANDS else ID_CMD_NODE] # FIXME |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 return [disco.DiscoFeature(NS_COMMANDS)] + self.features |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
146 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 return [] |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 def _sendAnswer(self, callback_data, session_id, request): |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 """ Send result of the command |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
151 |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 @param callback_data: tuple (payload, status, actions, note) with: |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
153 - payload (domish.Element, None) usualy containing data form |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 - status: current status, see XEP_0050.STATUS |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
155 - actions(list[str], None): list of allowed actions (see XEP_0050.ACTION). |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
156 First action is the default one. Default to EXECUTE |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
157 - note(tuple[str, unicode]): optional additional note: either None or a |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
158 tuple with (note type, human readable string), "note type" being in |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
159 XEP_0050.NOTE |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 @param session_id: current session id |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 @param request: original request (domish.Element) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 @return: deferred |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 """ |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 payload, status, actions, note = callback_data |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
165 assert isinstance(payload, domish.Element) or payload is None |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
166 assert status in XEP_0050.STATUS |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 if not actions: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 actions = [XEP_0050.ACTION.EXECUTE] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
169 result = domish.Element((None, "iq")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
170 result["type"] = "result" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
171 result["id"] = request["id"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
172 result["to"] = request["from"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
173 command_elt = result.addElement("command", NS_COMMANDS) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
174 command_elt["sessionid"] = session_id |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
175 command_elt["node"] = self.node |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
176 command_elt["status"] = status |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 if status != XEP_0050.STATUS.CANCELED: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 if status != XEP_0050.STATUS.COMPLETED: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
180 actions_elt = command_elt.addElement("actions") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
181 actions_elt["execute"] = actions[0] |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 for action in actions: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 actions_elt.addElement(action) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 if note is not None: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 note_type, note_mess = note |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
187 note_elt = command_elt.addElement("note", content=note_mess) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
188 note_elt["type"] = note_type |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 if payload is not None: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 command_elt.addChild(payload) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 |
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
|
193 self.client.send(result) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 if status in (XEP_0050.STATUS.COMPLETED, XEP_0050.STATUS.CANCELED): |
758
86224a13cc1d
plugin xep-0050: using new Sessions class
Goffi <goffi@goffi.org>
parents:
753
diff
changeset
|
195 del self.sessions[session_id] |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 def _sendError(self, error_constant, session_id, request): |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 """ Send error stanza |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
199 |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 @param error_constant: one of XEP_OO50.ERROR |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 @param request: original request (domish.Element) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 """ |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 xmpp_condition, cmd_condition = error_constant |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
204 iq_elt = jabber.error.StanzaError(xmpp_condition).toResponse(request) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 if cmd_condition: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 error_elt = iq_elt.elements(None, "error").next() |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 error_elt.addElement(cmd_condition, NS_COMMANDS) |
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
|
208 self.client.send(iq_elt) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 del self.sessions[session_id] |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 def onRequest(self, command_elt, requestor, action, session_id): |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 if not self.isAuthorised(requestor): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
213 return self._sendError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
214 XEP_0050.ERROR.FORBIDDEN, session_id, command_elt.parent |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
215 ) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 if session_id: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 try: |
758
86224a13cc1d
plugin xep-0050: using new Sessions class
Goffi <goffi@goffi.org>
parents:
753
diff
changeset
|
218 session_data = self.sessions[session_id] |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
220 return self._sendError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
221 XEP_0050.ERROR.SESSION_EXPIRED, session_id, command_elt.parent |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
222 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
223 if session_data["requestor"] != requestor: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
224 return self._sendError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
225 XEP_0050.ERROR.FORBIDDEN, session_id, command_elt.parent |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
226 ) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 else: |
758
86224a13cc1d
plugin xep-0050: using new Sessions class
Goffi <goffi@goffi.org>
parents:
753
diff
changeset
|
228 session_id, session_data = self.sessions.newSession() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
229 session_data["requestor"] = requestor |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 if action == XEP_0050.ACTION.CANCEL: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 d = defer.succeed((None, XEP_0050.STATUS.CANCELED, None, None)) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
233 d = defer.maybeDeferred( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
234 self.callback, |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
235 self.client, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
236 command_elt, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
237 session_data, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
238 action, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
239 self.node, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
240 ) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 d.addCallback(self._sendAnswer, session_id, command_elt.parent) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
242 d.addErrback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
243 lambda failure, request: self._sendError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
244 failure.value.callback_error, session_id, request |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
245 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
246 command_elt.parent, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
247 ) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
249 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 class XEP_0050(object): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
251 STATUS = namedtuple("Status", ("EXECUTING", "COMPLETED", "CANCELED"))( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
252 "executing", "completed", "canceled" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
253 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
254 ACTION = namedtuple("Action", ("EXECUTE", "CANCEL", "NEXT", "PREV"))( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
255 "execute", "cancel", "next", "prev" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
256 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
257 NOTE = namedtuple("Note", ("INFO", "WARN", "ERROR"))("info", "warn", "error") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
258 ERROR = namedtuple( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
259 "Error", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
260 ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
261 "MALFORMED_ACTION", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
262 "BAD_ACTION", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
263 "BAD_LOCALE", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
264 "BAD_PAYLOAD", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
265 "BAD_SESSIONID", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
266 "SESSION_EXPIRED", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
267 "FORBIDDEN", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
268 "ITEM_NOT_FOUND", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
269 "FEATURE_NOT_IMPLEMENTED", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
270 "INTERNAL", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
271 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
272 )( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
273 ("bad-request", "malformed-action"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
274 ("bad-request", "bad-action"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
275 ("bad-request", "bad-locale"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
276 ("bad-request", "bad-payload"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
277 ("bad-request", "bad-sessionid"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
278 ("not-allowed", "session-expired"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
279 ("forbidden", None), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
280 ("item-not-found", None), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
281 ("feature-not-implemented", None), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
282 ("internal-server-error", None), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
283 ) # XEP-0050 §4.4 Table 5 |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
284 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
285 def __init__(self, host): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
286 log.info(_("plugin XEP-0050 initialization")) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
287 self.host = host |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
288 self.requesting = Sessions() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
289 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
290 "adHocRun", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
291 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
292 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
293 out_sign="s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
294 method=self._run, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
295 async=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
296 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
297 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
298 "adHocList", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
299 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
300 in_sign="ss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
301 out_sign="s", |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
302 method=self._listUI, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
303 async=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
304 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
305 self.__requesting_id = host.registerCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
306 self._requestingEntity, with_data=True |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
307 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
308 host.importMenu( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
309 (D_("Service"), D_("Commands")), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
310 self._commandsMenu, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
311 security_limit=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
312 help_string=D_("Execute ad-hoc commands"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
313 ) |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
314 host.registerNamespace(u'commands', NS_COMMANDS) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
315 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
316 def getHandler(self, client): |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 return XEP_0050_handler(self) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
318 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
319 def profileConnected(self, client): |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
320 # map from node to AdHocCommand instance |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
321 client._XEP_0050_commands = {} |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
322 self.addAdHocCommand(client, self._statusCallback, _("Status")) |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
323 |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
324 def do(self, client, entity, node, action=ACTION.EXECUTE, session_id=None, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
325 form_values=None, timeout=30): |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
326 """Do an Ad-Hoc Command |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
327 |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
328 @param entity(jid.JID): entity which will execture the command |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
329 @param node(unicode): node of the command |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
330 @param action(unicode): one of XEP_0050.ACTION |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
331 @param session_id(unicode, None): id of the ad-hoc session |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
332 None if no session is involved |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
333 @param form_values(dict, None): values to use to create command form |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
334 values will be passed to data_form.Form.makeFields |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
335 @return |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
336 """ |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
337 iq_elt = client.IQ(timeout=timeout) |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
338 iq_elt["to"] = entity.full() |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
339 command_elt = iq_elt.addElement("command", NS_COMMANDS) |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
340 command_elt["node"] = node |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
341 command_elt["action"] = action |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
342 if session_id is not None: |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
343 command_elt["sessionid"] = session_id |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
344 |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
345 if form_values: |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
346 # We add the XMLUI result to the command payload |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
347 form = data_form.Form("submit") |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
348 form.makeFields(form_values) |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
349 command_elt.addChild(form.toElement()) |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
350 d = iq_elt.send() |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
351 return d |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
352 |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
353 def getCommandElt(self, iq_elt): |
753
7f98f53f6997
plugin XEP-0050: fixed getDiscoItems when no commands were added + fixed commands purge on profile disconnection
Goffi <goffi@goffi.org>
parents:
728
diff
changeset
|
354 try: |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
355 return iq_elt.elements(NS_COMMANDS, "command").next() |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
356 except StopIteration: |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
357 raise exceptions.NotFound(_(u"Missing command element")) |
753
7f98f53f6997
plugin XEP-0050: fixed getDiscoItems when no commands were added + fixed commands purge on profile disconnection
Goffi <goffi@goffi.org>
parents:
728
diff
changeset
|
358 |
2406
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
359 def _items2XMLUI(self, items, no_instructions): |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
360 """Convert discovery items to XMLUI dialog """ |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
361 # TODO: manage items on different jids |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
362 form_ui = xml_tools.XMLUI("form", submit_id=self.__requesting_id) |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
363 |
2406
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
364 if not no_instructions: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
365 form_ui.addText(_("Please select a command"), "instructions") |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
366 |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
367 options = [(item.nodeIdentifier, item.name) for item in items] |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
798
diff
changeset
|
368 form_ui.addList("node", options) |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
369 return form_ui |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
370 |
1110
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
371 def _getDataLvl(self, type_): |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
372 """Return the constant corresponding to <note/> type attribute value |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
373 |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
374 @param type_: note type (see XEP-0050 §4.3) |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
375 @return: a C.XMLUI_DATA_LVL_* constant |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
376 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
377 if type_ == "error": |
1110
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
378 return C.XMLUI_DATA_LVL_ERROR |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
379 elif type_ == "warn": |
1110
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
380 return C.XMLUI_DATA_LVL_WARNING |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
381 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
382 if type_ != "info": |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
383 log.warning(_(u"Invalid note type [%s], using info") % type_) |
1110
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
384 return C.XMLUI_DATA_LVL_INFO |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
385 |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
386 def _mergeNotes(self, notes): |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
387 """Merge notes with level prefix (e.g. "ERROR: the message") |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
388 |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
389 @param notes (list): list of tuple (level, message) |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
390 @return: list of messages |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
391 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
392 lvl_map = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
393 C.XMLUI_DATA_LVL_INFO: "", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
394 C.XMLUI_DATA_LVL_WARNING: "%s: " % _("WARNING"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
395 C.XMLUI_DATA_LVL_ERROR: "%s: " % _("ERROR"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
396 } |
1110
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
397 return [u"%s%s" % (lvl_map[lvl], msg) for lvl, msg in notes] |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
398 |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
399 def _commandsAnswer2XMLUI(self, iq_elt, session_id, session_data): |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
400 """Convert command answer to an ui for frontend |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
401 |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
402 @param iq_elt: command result |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
403 @param session_id: id of the session used with the frontend |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
404 @param profile_key: %(doc_profile_key)s |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
405 """ |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
406 command_elt = self.getCommandElt(iq_elt) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
407 status = command_elt.getAttribute("status", XEP_0050.STATUS.EXECUTING) |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
408 if status in [XEP_0050.STATUS.COMPLETED, XEP_0050.STATUS.CANCELED]: |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
409 # the command session is finished, we purge our session |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
410 del self.requesting[session_id] |
1071
eef1f200d733
plugin XEP-0050: form returned by completed command are now managed
Goffi <goffi@goffi.org>
parents:
993
diff
changeset
|
411 if status == XEP_0050.STATUS.COMPLETED: |
eef1f200d733
plugin XEP-0050: form returned by completed command are now managed
Goffi <goffi@goffi.org>
parents:
993
diff
changeset
|
412 session_id = None |
eef1f200d733
plugin XEP-0050: form returned by completed command are now managed
Goffi <goffi@goffi.org>
parents:
993
diff
changeset
|
413 else: |
eef1f200d733
plugin XEP-0050: form returned by completed command are now managed
Goffi <goffi@goffi.org>
parents:
993
diff
changeset
|
414 return None |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
415 remote_session_id = command_elt.getAttribute("sessionid") |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
416 if remote_session_id: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
417 session_data["remote_id"] = remote_session_id |
1110
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
418 notes = [] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
419 for note_elt in command_elt.elements(NS_COMMANDS, "note"): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
420 notes.append( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
421 ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
422 self._getDataLvl(note_elt.getAttribute("type", "info")), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
423 unicode(note_elt), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
424 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
425 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
426 for data_elt in command_elt.elements(data_form.NS_X_DATA, "x"): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
427 if data_elt["type"] in ("form", "result"): |
2585
0112c1f7dcf0
plugin XEP-0050: filter form received from form-processing entity, to only keep "form" and "result" types
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
428 break |
0112c1f7dcf0
plugin XEP-0050: filter form received from form-processing entity, to only keep "form" and "result" types
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
429 else: |
0112c1f7dcf0
plugin XEP-0050: filter form received from form-processing entity, to only keep "form" and "result" types
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
430 # no matching data element found |
1110
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
431 if status != XEP_0050.STATUS.COMPLETED: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
432 log.warning( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
433 _("No known payload found in ad-hoc command result, aborting") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
434 ) |
1110
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
435 del self.requesting[session_id] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
436 return xml_tools.XMLUI( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
437 C.XMLUI_DIALOG, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
438 dialog_opt={ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
439 C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_NOTE, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
440 C.XMLUI_DATA_MESS: _("No payload found"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
441 C.XMLUI_DATA_LVL: C.XMLUI_DATA_LVL_ERROR, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
442 }, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
443 ) |
1110
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
444 if not notes: |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
445 # the status is completed, and we have no note to show |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
446 return None |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
447 |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
448 # if we have only one note, we show a dialog with the level of the note |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
449 # if we have more, we show a dialog with "info" level, and all notes merged |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
450 dlg_level = notes[0][0] if len(notes) == 1 else C.XMLUI_DATA_LVL_INFO |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
451 return xml_tools.XMLUI( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
452 C.XMLUI_DIALOG, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
453 dialog_opt={ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
454 C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_NOTE, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
455 C.XMLUI_DATA_MESS: u"\n".join(self._mergeNotes(notes)), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
456 C.XMLUI_DATA_LVL: dlg_level, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
457 }, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
458 session_id=session_id, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
459 ) |
1110
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
460 |
1071
eef1f200d733
plugin XEP-0050: form returned by completed command are now managed
Goffi <goffi@goffi.org>
parents:
993
diff
changeset
|
461 if session_id is None: |
2364
918e38622a48
core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
462 return xml_tools.dataFormEltResult2XMLUI(data_elt) |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
463 form = data_form.Form.fromElement(data_elt) |
1110
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
464 # we add any present note to the instructions |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
465 form.instructions.extend(self._mergeNotes(notes)) |
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
466 return xml_tools.dataForm2XMLUI(form, self.__requesting_id, session_id=session_id) |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
467 |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
468 def _requestingEntity(self, data, profile): |
2406
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
469 def serialise(ret_data): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
470 if "xmlui" in ret_data: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
471 ret_data["xmlui"] = ret_data["xmlui"].toXml() |
2406
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
472 return ret_data |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
473 |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
474 d = self.requestingEntity(data, profile) |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
475 d.addCallback(serialise) |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
476 return d |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
477 |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
478 def requestingEntity(self, data, profile): |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
479 """Request and entity and create XMLUI accordingly. |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
480 |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
481 @param data: data returned by previous XMLUI (first one must come from |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
482 self._commandsMenu) |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
483 @param profile: %(doc_profile)s |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
484 @return: callback dict result (with "xmlui" corresponding to the answering |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
485 dialog, or empty if it's finished without error) |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
486 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
487 if C.bool(data.get("cancelled", C.BOOL_FALSE)): |
2406
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
488 return defer.succeed({}) |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
489 data_form_values = xml_tools.XMLUIResult2DataFormResult(data) |
2406
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
490 client = self.host.getClient(profile) |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
491 # TODO: cancel, prev and next are not managed |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
492 # TODO: managed answerer errors |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
493 # TODO: manage nodes with a non data form payload |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
494 if "session_id" not in data: |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
495 # we just had the jid, we now request it for the available commands |
2406
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
496 session_id, session_data = self.requesting.newSession(profile=client.profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
497 entity = jid.JID(data[xml_tools.SAT_FORM_PREFIX + "jid"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
498 session_data["jid"] = entity |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
499 d = self.listUI(client, entity) |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
500 |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
501 def sendItems(xmlui): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
502 xmlui.session_id = session_id # we need to keep track of the session |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
503 return {"xmlui": xmlui} |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
504 |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
505 d.addCallback(sendItems) |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
506 else: |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
507 # we have started a several forms sessions |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
508 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
509 session_data = self.requesting.profileGet( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
510 data["session_id"], client.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
511 ) |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
512 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
513 log.warning("session id doesn't exist, session has probably expired") |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
514 # TODO: send error dialog |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
515 return defer.succeed({}) |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
516 session_id = data["session_id"] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
517 entity = session_data["jid"] |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
518 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
519 session_data["node"] |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
520 # node has already been received |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
521 except KeyError: |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
522 # it's the first time we know the node, we save it in session data |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
523 session_data["node"] = data_form_values.pop("node") |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
524 |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
525 # remote_id is the XEP_0050 sessionid used by answering command |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
526 # while session_id is our own session id used with the frontend |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
527 remote_id = session_data.get("remote_id") |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
528 |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
529 # we request execute node's command |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
530 d = self.do(client, entity, session_data["node"], action=XEP_0050.ACTION.EXECUTE, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
531 session_id=remote_id, form_values=data_form_values) |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
532 d.addCallback(self._commandsAnswer2XMLUI, session_id, session_data) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
533 d.addCallback(lambda xmlui: {"xmlui": xmlui} if xmlui is not None else {}) |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
534 |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
535 return d |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
536 |
773 | 537 def _commandsMenu(self, menu_data, profile): |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
538 """First XMLUI activated by menu: ask for target jid |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
539 |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
540 @param profile: %(doc_profile)s |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
541 """ |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
542 form_ui = xml_tools.XMLUI("form", submit_id=self.__requesting_id) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
543 form_ui.addText(_("Please enter target jid"), "instructions") |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
798
diff
changeset
|
544 form_ui.changeContainer("pairs") |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
545 form_ui.addLabel("jid") |
1539
98f92a054539
plugins: lowered security limits for non dangerous actions. A reference documentation is in progress to choose values: http://wiki.goffi.org/wiki/Security_Limits/en
Goffi <goffi@goffi.org>
parents:
1517
diff
changeset
|
546 form_ui.addString("jid", value=self.host.getClient(profile).jid.host) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
547 return {"xmlui": form_ui.toXml()} |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
548 |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
549 def _statusCallback(self, client, command_elt, session_data, action, node): |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
550 """Ad-hoc command used to change the "show" part of status""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
551 actions = session_data.setdefault("actions", []) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
552 actions.append(action) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
553 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
554 if len(actions) == 1: |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
555 # it's our first request, we ask the desired new status |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
556 status = XEP_0050.STATUS.EXECUTING |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
557 form = data_form.Form("form", title=_("status selection")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
558 show_options = [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
559 data_form.Option(name, label) for name, label in SHOWS.items() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
560 ] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
561 field = data_form.Field( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
562 "list-single", "show", options=show_options, required=True |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
563 ) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
564 form.addField(field) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
565 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
566 payload = form.toElement() |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
567 note = None |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
568 |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
569 elif len(actions) == 2: |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
570 # we should have the answer here |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
571 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
572 x_elt = command_elt.elements(data_form.NS_X_DATA, "x").next() |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
573 answer_form = data_form.Form.fromElement(x_elt) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
574 show = answer_form["show"] |
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
|
575 except (KeyError, StopIteration): |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
576 raise AdHocError(XEP_0050.ERROR.BAD_PAYLOAD) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
577 if show not in SHOWS: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
578 raise AdHocError(XEP_0050.ERROR.BAD_PAYLOAD) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
579 if show == "disconnect": |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
580 self.host.disconnect(client.profile) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
581 else: |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
582 self.host.setPresence(show=show, profile_key=client.profile) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
583 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
584 # job done, we can end the session |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
585 form = data_form.Form("form", title=_(u"Updated")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
586 form.addField(data_form.Field("fixed", u"Status updated")) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
587 status = XEP_0050.STATUS.COMPLETED |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
588 payload = None |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
589 note = (self.NOTE.INFO, _(u"Status updated")) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
590 else: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
591 raise AdHocError(XEP_0050.ERROR.INTERNAL) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
592 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
593 return (payload, status, None, note) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
594 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
595 def _run(self, service_jid_s="", node="", profile_key=C.PROF_KEY_NONE): |
2406
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
596 client = self.host.getClient(profile_key) |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
597 service_jid = jid.JID(service_jid_s) if service_jid_s else None |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
598 d = self.run(client, service_jid, node or None) |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
599 d.addCallback(lambda xmlui: xmlui.toXml()) |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
600 return d |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
601 |
2406
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
602 @defer.inlineCallbacks |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
603 def run(self, client, service_jid=None, node=None): |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
604 """run an ad-hoc command |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
605 |
2406
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
606 @param service_jid(jid.JID, None): jid of the ad-hoc service |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
607 None to use profile's server |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
608 @param node(unicode, None): node of the ad-hoc commnad |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
609 None to get initial list |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
610 @return(unicode): command page XMLUI |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
611 """ |
2406
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
612 if service_jid is None: |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
613 service_jid = jid.JID(client.jid.host) |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
614 session_id, session_data = self.requesting.newSession(profile=client.profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
615 session_data["jid"] = service_jid |
2406
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
616 if node is None: |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
617 xmlui = yield self.listUI(client, service_jid) |
2406
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
618 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
619 session_data["node"] = node |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
620 cb_data = yield self.requestingEntity( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
621 {"session_id": session_id}, client.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
622 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
623 xmlui = cb_data["xmlui"] |
2406
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
624 |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
625 xmlui.session_id = session_id |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
626 defer.returnValue(xmlui) |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
627 |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
628 def list(self, client, to_jid): |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
629 """Request available commands |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
630 |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
631 @param to_jid(jid.JID, None): the entity answering the commands |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
632 None to use profile's server |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
633 @return D(disco.DiscoItems): found commands |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
634 """ |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
635 d = self.host.getDiscoItems(client, to_jid, NS_COMMANDS) |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
636 return d |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
637 |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
638 def _listUI(self, to_jid_s, profile_key): |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
639 client = self.host.getClient(profile_key) |
2406
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
640 to_jid = jid.JID(to_jid_s) if to_jid_s else None |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
641 d = self.listUI(client, to_jid, no_instructions=True) |
2406
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
642 d.addCallback(lambda xmlui: xmlui.toXml()) |
763
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
643 return d |
ab851b46009c
plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents:
758
diff
changeset
|
644 |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
645 def listUI(self, client, to_jid, no_instructions=False): |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
646 """Request available commands and generate XMLUI |
2406
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
647 |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
648 @param to_jid(jid.JID, None): the entity answering the commands |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
649 None to use profile's server |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
650 @param no_instructions(bool): if True, don't add instructions widget |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
651 @return D(xml_tools.XMLUI): UI with the commands |
2406
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
652 """ |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
653 d = self.list(client, to_jid) |
2406
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
654 d.addCallback(self._items2XMLUI, no_instructions) |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
655 return d |
1e5b2c35964e
plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents:
2364
diff
changeset
|
656 |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
657 def addAdHocCommand(self, client, callback, label, node=None, features=None, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
658 timeout=600, allowed_jids=None, allowed_groups=None, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
659 allowed_magics=None, forbidden_jids=None, forbidden_groups=None, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
660 ): |
1110
36c1bbb8ca24
plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents:
1079
diff
changeset
|
661 """Add an ad-hoc command for the current profile |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
662 |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
663 @param callback: method associated with this ad-hoc command which return the |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
664 payload data (see AdHocCommand._sendAnswer), can return a |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
665 deferred |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
666 @param label: label associated with this command on the main menu |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
667 @param node: disco item node associated with this command. None to use |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
668 autogenerated node |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
669 @param features: features associated with the payload (list of strings), usualy |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
670 data form |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
671 @param timeout: delay between two requests before canceling the session (in |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
672 seconds) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
673 @param allowed_jids: list of allowed entities |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
674 @param allowed_groups: list of allowed roster groups |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
675 @param allowed_magics: list of allowed magic keys, can be: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
676 @ALL@: allow everybody |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
677 @PROFILE_BAREJID@: allow only the jid of the profile |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
678 @param forbidden_jids: black list of entities which can't access this command |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
679 @param forbidden_groups: black list of groups which can't access this command |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
680 @return: node of the added command, useful to remove the command later |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
681 """ |
821
38bc9abd6722
plugin XEP-0050: fixed UnknownGroupError management + "@ALL@" profile for status command
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
682 # FIXME: "@ALL@" for profile_key seems useless and dangerous |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
683 |
1495
987e74cbb839
plugin XEP-0050: fixed crash on empty node in addAdHocCommand
Goffi <goffi@goffi.org>
parents:
1494
diff
changeset
|
684 if node is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
685 node = "%s_%s" % ("COMMANDS", uuid4()) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
686 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
687 if features is None: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
688 features = [data_form.NS_X_DATA] |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
689 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
690 if allowed_jids is None: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
691 allowed_jids = [] |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
692 if allowed_groups is None: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
693 allowed_groups = [] |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
694 if allowed_magics is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
695 allowed_magics = ["@PROFILE_BAREJID@"] |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
696 if forbidden_jids is None: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
697 forbidden_jids = [] |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
698 if forbidden_groups is None: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
699 forbidden_groups = [] |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
700 |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
701 # TODO: manage newly created/removed profiles |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
702 _allowed_jids = ( |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
703 (allowed_jids + [client.jid.userhostJID()]) |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
704 if "@PROFILE_BAREJID@" in allowed_magics |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
705 else allowed_jids |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
706 ) |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
707 ad_hoc_command = AdHocCommand( |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
708 callback, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
709 label, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
710 node, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
711 features, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
712 timeout, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
713 _allowed_jids, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
714 allowed_groups, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
715 allowed_magics, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
716 forbidden_jids, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
717 forbidden_groups, |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
718 ) |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
719 ad_hoc_command.setHandlerParent(client) |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
720 commands = client._XEP_0050_commands |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
721 commands[node] = ad_hoc_command |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
722 |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
723 def onCmdRequest(self, request, client): |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
724 request.handled = True |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
725 requestor = jid.JID(request["from"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
726 command_elt = request.elements(NS_COMMANDS, "command").next() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
727 action = command_elt.getAttribute("action", self.ACTION.EXECUTE) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
728 node = command_elt.getAttribute("node") |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
729 if not node: |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
730 client.sendError(request, u"bad-request") |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
731 return |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
732 sessionid = command_elt.getAttribute("sessionid") |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
733 commands = client._XEP_0050_commands |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
734 try: |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
735 command = commands[node] |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
736 except KeyError: |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
737 client.sendError(request, u"item-not-found") |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
738 return |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
739 command.onRequest(command_elt, requestor, action, sessionid) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
740 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
741 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
742 class XEP_0050_handler(XMPPHandler): |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
743 implements(iwokkel.IDisco) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
744 |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
745 def __init__(self, plugin_parent): |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
746 self.plugin_parent = plugin_parent |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
747 |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
748 @property |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
749 def client(self): |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
750 return self.parent |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
751 |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
752 def connectionInitialized(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
753 self.xmlstream.addObserver( |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
754 CMD_REQUEST, self.plugin_parent.onCmdRequest, client=self.parent |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
755 ) |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
756 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
757 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
758 identities = [] |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
759 if nodeIdentifier == NS_COMMANDS and self.client._XEP_0050_commands: |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
760 # we only add the identity if we have registred commands |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
761 identities.append(ID_CMD_LIST) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
762 return [disco.DiscoFeature(NS_COMMANDS)] + identities |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
763 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
764 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
765 ret = [] |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
766 if nodeIdentifier == NS_COMMANDS: |
2667
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
767 commands = self.client._XEP_0050_commands |
8dd9db785ac8
plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
768 for command in commands.values(): |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
769 if command.isAuthorised(requestor): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
770 ret.append( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
771 disco.DiscoItem(self.parent.jid, command.node, command.getName()) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2585
diff
changeset
|
772 ) # TODO: manage name language |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
773 return ret |