annotate libervia/backend/plugins/plugin_xep_0050.py @ 4258:ba28ca268f4a

plugin text syntaxes: fix empty string handling in `_remove_markups`.
author Goffi <goffi@goffi.org>
date Wed, 05 Jun 2024 22:33:37 +0200
parents 50c919dfe61b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2921
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
3 # Libervia plugin for Ad-Hoc Commands (XEP-0050)
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
4 # Copyright (C) 2009-2023 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
5
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # 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
7 # 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
8 # 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
9 # (at your option) any later version.
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
10
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # 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
12 # 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
13 # 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
14 # 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
15
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # 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
17 # 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
18
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
19
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
20 from collections import namedtuple
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
21 from uuid import uuid4
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
22 from typing import Callable
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
23
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
24 from zope.interface import implementer
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
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
26 from twisted.words.protocols.jabber.error import StanzaError
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
27 from twisted.words.protocols.jabber.xmlstream import XMPPHandler
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
28 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
29 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
30 from wokkel import disco, iwokkel, data_form
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
31 from libervia.backend.core.i18n import _, D_
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
32 from libervia.backend.core.constants import Const as C
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
33 from libervia.backend.core.log import getLogger
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
34 from libervia.backend.core.xmpp import SatXMPPClient, SatXMPPEntity
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
35 from libervia.backend.core import exceptions
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
36 from libervia.backend.memory.memory import Sessions
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
37 from libervia.backend.tools import xml_tools, utils
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
38 from libervia.backend.tools.common import data_format
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
39
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
40
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
41 log = getLogger(__name__)
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
42
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 IQ_SET = '/iq[@type="set"]'
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
45 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
46 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
47 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
48 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
49
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
50 SHOWS = {
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
51 "default": _("Online"),
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
52 "away": _("Away"),
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
53 "chat": _("Free for chat"),
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
54 "dnd": _("Do not disturb"),
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
55 "xa": _("Left"),
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
56 "disconnect": _("Disconnect"),
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
57 }
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
58
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
59 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
60 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
61 C.PI_IMPORT_NAME: "XEP-0050",
2921
a8c2d8b3453f plugin XEP-0050: make plugin usable with components + new adHocError method to easily raise error when needed
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
62 C.PI_MODES: C.PLUG_MODE_BOTH,
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
63 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
64 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
65 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
66 C.PI_HANDLER: "yes",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2921
diff changeset
67 C.PI_DESCRIPTION: _("""Implementation of Ad-Hoc Commands"""),
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
68 }
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
69
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
70
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
71 Status = namedtuple("Status", ("EXECUTING", "COMPLETED", "CANCELED"))
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
72 Action = namedtuple("Action", ("EXECUTE", "CANCEL", "NEXT", "PREV"))
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
73 Note = namedtuple("Note", ("INFO", "WARN", "ERROR"))
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
74 Error = namedtuple(
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
75 "Error",
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
76 (
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
77 "MALFORMED_ACTION",
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
78 "BAD_ACTION",
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
79 "BAD_LOCALE",
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
80 "BAD_PAYLOAD",
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
81 "BAD_SESSIONID",
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
82 "SESSION_EXPIRED",
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
83 "FORBIDDEN",
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
84 "ITEM_NOT_FOUND",
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
85 "FEATURE_NOT_IMPLEMENTED",
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
86 "INTERNAL",
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
87 ),
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
88 )
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
89
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
90
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
91 class AdHocError(Exception):
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
92 def __init__(self, error_const):
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
93 """Error to be used from callback
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
94 @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
95 """
1517
4eca4f5e21ec plugin XEP-0050: minor parentheses removal
Goffi <goffi@goffi.org>
parents: 1505
diff changeset
96 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
97 self.callback_error = error_const
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
98
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
99
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2921
diff changeset
100 @implementer(iwokkel.IDisco)
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
101 class AdHocCommand(XMPPHandler):
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
102 def __init__(
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
103 self,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
104 callback,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
105 label,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
106 node,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
107 features,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
108 timeout,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
109 allowed_jids,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
110 allowed_groups,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
111 allowed_magics,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
112 forbidden_jids,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
113 forbidden_groups,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
114 ):
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
115 XMPPHandler.__init__(self)
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
116 self.callback = callback
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
117 self.label = label
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
118 self.node = node
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
119 self.features = [disco.DiscoFeature(feature) for feature in features]
3900
6c93a18b6250 plugin XEP-0050: use coroutine + minor code readability improvments:
Goffi <goffi@goffi.org>
parents: 3530
diff changeset
120 self.allowed_jids = allowed_jids
6c93a18b6250 plugin XEP-0050: use coroutine + minor code readability improvments:
Goffi <goffi@goffi.org>
parents: 3530
diff changeset
121 self.allowed_groups = allowed_groups
6c93a18b6250 plugin XEP-0050: use coroutine + minor code readability improvments:
Goffi <goffi@goffi.org>
parents: 3530
diff changeset
122 self.allowed_magics = allowed_magics
6c93a18b6250 plugin XEP-0050: use coroutine + minor code readability improvments:
Goffi <goffi@goffi.org>
parents: 3530
diff changeset
123 self.forbidden_jids = forbidden_jids
6c93a18b6250 plugin XEP-0050: use coroutine + minor code readability improvments:
Goffi <goffi@goffi.org>
parents: 3530
diff changeset
124 self.forbidden_groups = forbidden_groups
758
86224a13cc1d plugin xep-0050: using new Sessions class
Goffi <goffi@goffi.org>
parents: 753
diff changeset
125 self.sessions = Sessions(timeout=timeout)
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
126
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
127 @property
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
128 def client(self):
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
129 return self.parent
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
130
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
131 def getName(self, xml_lang=None):
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
132 return self.label
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
133
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
134 def is_authorised(self, requestor):
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
135 if C.ENTITY_ALL in self.allowed_magics:
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
136 return True
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
137 forbidden = set(self.forbidden_jids)
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
138 for group in self.forbidden_groups:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
139 forbidden.update(self.client.roster.get_jids_from_group(group))
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
140 if requestor.userhostJID() in forbidden:
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
141 return False
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
142 allowed = set(self.allowed_jids)
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
143 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
144 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
145 allowed.update(self.client.roster.get_jids_from_group(group))
821
38bc9abd6722 plugin XEP-0050: fixed UnknownGroupError management + "@ALL@" profile for status command
Goffi <goffi@goffi.org>
parents: 811
diff changeset
146 except exceptions.UnknownGroupError:
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
147 log.warning(
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
148 _("The groups [{group}] is unknown for profile [{profile}])").format(
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
149 group=group, profile=self.client.profile
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
150 )
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
151 )
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
152 if requestor.userhostJID() in allowed:
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
153 return True
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
154 return False
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
155
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
156 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
157 if (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
158 nodeIdentifier != NS_COMMANDS
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
159 ): # 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
160 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
161 # 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
162 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
163
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
164 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
165 return []
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
166
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
167 def _sendAnswer(
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
168 self,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
169 callback_data: tuple[
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
170 tuple[domish.Element, None],
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
171 Status,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
172 list[str] | None,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
173 tuple[Note, str] | None,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
174 ],
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
175 session_id,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
176 request,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
177 ) -> None:
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
178 """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
179
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
180 @param callback_data: tuple (payload, status, actions, note) with:
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
181 - payload: usualy containing data form
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
182 - status: current status
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
183 - actions: list of allowed actions (see XEP_0050.ACTION).
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
184 First action is the default one. Default to EXECUTE
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
185 - note: optional additional note: either None or a tuple with (note type,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
186 human readable string)
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
187 @param session_id: current session id
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
188 @param request: original request (domish.Element)
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
189 @return: deferred
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
190 """
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
191 payload, status, actions, note = callback_data
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
192 assert isinstance(payload, domish.Element) or payload is None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
193 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
194 if not actions:
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
195 actions = [XEP_0050.ACTION.EXECUTE]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
196 result = domish.Element((None, "iq"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
197 result["type"] = "result"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
198 result["id"] = request["id"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
199 result["to"] = request["from"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
200 command_elt = result.addElement("command", NS_COMMANDS)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
201 command_elt["sessionid"] = session_id
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
202 command_elt["node"] = self.node
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
203 command_elt["status"] = status
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
204
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
205 if status != XEP_0050.STATUS.CANCELED:
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
206 if status != XEP_0050.STATUS.COMPLETED:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
207 actions_elt = command_elt.addElement("actions")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
208 actions_elt["execute"] = actions[0]
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
209 for action in actions:
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
210 actions_elt.addElement(action)
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
211
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
212 if note is not None:
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
213 note_type, note_mess = note
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
214 note_elt = command_elt.addElement("note", content=note_mess)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
215 note_elt["type"] = note_type
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
216
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
217 if payload is not None:
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
218 command_elt.addChild(payload)
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
219
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
220 self.client.send(result)
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
221 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
222 del self.sessions[session_id]
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
223
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
224 def _sendError(self, error_constant, session_id, request):
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
225 """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
226
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
227 @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
228 @param request: original request (domish.Element)
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
229 """
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
230 xmpp_condition, cmd_condition = error_constant
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
231 iq_elt = StanzaError(xmpp_condition).toResponse(request)
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
232 if cmd_condition:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2921
diff changeset
233 error_elt = next(iq_elt.elements(None, "error"))
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
234 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
235 self.client.send(iq_elt)
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
236 del self.sessions[session_id]
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
237
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
238 def _request_eb(self, failure_, request, session_id):
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
239 if failure_.check(AdHocError):
3315
53b229761c9d plugin XEP-0050: typo
Goffi <goffi@goffi.org>
parents: 3302
diff changeset
240 error_constant = failure_.value.callback_error
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
241 else:
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
242 log.error(f"unexpected error while handling request: {failure_}")
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
243 error_constant = XEP_0050.ERROR.INTERNAL
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
244
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
245 self._sendError(error_constant, session_id, request)
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
246
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
247 def on_request(self, command_elt, requestor, action, session_id):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
248 if not self.is_authorised(requestor):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
249 return self._sendError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
250 XEP_0050.ERROR.FORBIDDEN, session_id, command_elt.parent
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
251 )
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
252 if session_id:
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
253 try:
758
86224a13cc1d plugin xep-0050: using new Sessions class
Goffi <goffi@goffi.org>
parents: 753
diff changeset
254 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
255 except KeyError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
256 return self._sendError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
257 XEP_0050.ERROR.SESSION_EXPIRED, session_id, command_elt.parent
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
258 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
259 if session_data["requestor"] != requestor:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
260 return self._sendError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
261 XEP_0050.ERROR.FORBIDDEN, session_id, command_elt.parent
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
262 )
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
263 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
264 session_id, session_data = self.sessions.new_session()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
265 session_data["requestor"] = requestor
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
266 if action == XEP_0050.ACTION.CANCEL:
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
267 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
268 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
269 d = utils.as_deferred(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
270 self.callback,
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
271 self.client,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
272 command_elt,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
273 session_data,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
274 action,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
275 self.node,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
276 )
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
277 d.addCallback(self._sendAnswer, session_id, command_elt.parent)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
278 d.addErrback(self._request_eb, command_elt.parent, session_id)
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
279
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
280
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
281 class XEP_0050:
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
282 STATUS = Status("executing", "completed", "canceled")
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
283 ACTION = Action("execute", "cancel", "next", "prev")
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
284 NOTE = Note("info", "warn", "error")
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
285 ERROR = Error(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
286 ("bad-request", "malformed-action"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
287 ("bad-request", "bad-action"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
288 ("bad-request", "bad-locale"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
289 ("bad-request", "bad-payload"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
290 ("bad-request", "bad-sessionid"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
291 ("not-allowed", "session-expired"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
292 ("forbidden", None),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
293 ("item-not-found", None),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
294 ("feature-not-implemented", None),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
295 ("internal-server-error", None),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
296 ) # 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
297
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
298 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 944
diff changeset
299 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
300 self.host = host
763
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
301 self.requesting = Sessions()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
302 host.bridge.add_method(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
303 "ad_hoc_run",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
304 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
305 in_sign="sss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
306 out_sign="s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
307 method=self._run,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2921
diff changeset
308 async_=True,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
309 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
310 host.bridge.add_method(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
311 "ad_hoc_list",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
312 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
313 in_sign="ss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
314 out_sign="s",
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
315 method=self._list_ui,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2921
diff changeset
316 async_=True,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
317 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
318 host.bridge.add_method(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
319 "ad_hoc_sequence",
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
320 ".plugin",
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
321 in_sign="ssss",
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
322 out_sign="s",
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
323 method=self._sequence,
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
324 async_=True,
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
325 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
326 self.__requesting_id = host.register_callback(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
327 self._requesting_entity, with_data=True
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
328 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
329 host.import_menu(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
330 (D_("Service"), D_("Commands")),
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
331 self._commands_menu,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
332 security_limit=2,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
333 help_string=D_("Execute ad-hoc commands"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
334 )
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
335 host.register_namespace("commands", NS_COMMANDS)
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
336
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
337 def get_handler(self, client):
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
338 return XEP_0050_handler(self)
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
339
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
340 def profile_connected(self, client):
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
341 # 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
342 client._XEP_0050_commands = {}
2921
a8c2d8b3453f plugin XEP-0050: make plugin usable with components + new adHocError method to easily raise error when needed
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
343 if not client.is_component:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
344 self.add_ad_hoc_command(client, self._status_callback, _("Status"))
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
345
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
346 def do(
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
347 self,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
348 client,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
349 entity,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
350 node,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
351 action=ACTION.EXECUTE,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
352 session_id=None,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
353 form_values=None,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
354 timeout=30,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
355 ):
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
356 """Do an Ad-Hoc Command
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
357
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
358 @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
359 @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
360 @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
361 @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
362 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
363 @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
364 values will be passed to data_form.Form.makeFields
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
365 @return: iq result element
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
366 """
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
367 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
368 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
369 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
370 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
371 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
372 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
373 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
374
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
375 if form_values:
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
376 # 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
377 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
378 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
379 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
380 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
381 return d
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
382
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
383 def get_command_elt(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
384 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2921
diff changeset
385 return next(iq_elt.elements(NS_COMMANDS, "command"))
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
386 except StopIteration:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2921
diff changeset
387 raise exceptions.NotFound(_("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
388
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
389 def ad_hoc_error(self, error_type):
2921
a8c2d8b3453f plugin XEP-0050: make plugin usable with components + new adHocError method to easily raise error when needed
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
390 """Shortcut to raise an AdHocError
a8c2d8b3453f plugin XEP-0050: make plugin usable with components + new adHocError method to easily raise error when needed
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
391
a8c2d8b3453f plugin XEP-0050: make plugin usable with components + new adHocError method to easily raise error when needed
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
392 @param error_type(unicode): one of XEP_0050.ERROR
a8c2d8b3453f plugin XEP-0050: make plugin usable with components + new adHocError method to easily raise error when needed
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
393 """
a8c2d8b3453f plugin XEP-0050: make plugin usable with components + new adHocError method to easily raise error when needed
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
394 raise AdHocError(error_type)
a8c2d8b3453f plugin XEP-0050: make plugin usable with components + new adHocError method to easily raise error when needed
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
395
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
396 def _items_2_xmlui(self, items, no_instructions):
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
397 """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
398 # 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
399 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
400
2406
1e5b2c35964e plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents: 2364
diff changeset
401 if not no_instructions:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
402 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
403
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
404 options = [(item.nodeIdentifier, item.name) for item in items]
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 798
diff changeset
405 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
406 return form_ui
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
407
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
408 def _get_data_lvl(self, type_):
1110
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
409 """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
410
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
411 @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
412 @return: a C.XMLUI_DATA_LVL_* constant
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
413 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
414 if type_ == "error":
1110
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
415 return C.XMLUI_DATA_LVL_ERROR
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
416 elif type_ == "warn":
1110
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
417 return C.XMLUI_DATA_LVL_WARNING
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
418 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
419 if type_ != "info":
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2921
diff changeset
420 log.warning(_("Invalid note type [%s], using info") % type_)
1110
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
421 return C.XMLUI_DATA_LVL_INFO
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
422
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
423 def _merge_notes(self, notes):
1110
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
424 """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
425
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
426 @param notes (list): list of tuple (level, message)
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
427 @return: list of messages
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
428 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
429 lvl_map = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
430 C.XMLUI_DATA_LVL_INFO: "",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
431 C.XMLUI_DATA_LVL_WARNING: "%s: " % _("WARNING"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
432 C.XMLUI_DATA_LVL_ERROR: "%s: " % _("ERROR"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
433 }
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2921
diff changeset
434 return ["%s%s" % (lvl_map[lvl], msg) for lvl, msg in notes]
1110
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
435
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
436 def parse_command_answer(self, iq_elt):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
437 command_elt = self.get_command_elt(iq_elt)
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
438 data = {}
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
439 data["status"] = command_elt.getAttribute("status", XEP_0050.STATUS.EXECUTING)
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
440 data["session_id"] = command_elt.getAttribute("sessionid")
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
441 data["notes"] = notes = []
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
442 for note_elt in command_elt.elements(NS_COMMANDS, "note"):
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
443 notes.append(
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
444 (
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
445 self._get_data_lvl(note_elt.getAttribute("type", "info")),
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
446 str(note_elt),
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
447 )
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
448 )
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
449
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
450 return command_elt, data
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
451
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
452 def _commands_answer_2_xmlui(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
453 """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
454
763
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
455 @param iq_elt: command result
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
456 @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
457 @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
458 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
459 command_elt, answer_data = self.parse_command_answer(iq_elt)
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
460 status = answer_data["status"]
763
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
461 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
462 # 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
463 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
464 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
465 session_id = None
eef1f200d733 plugin XEP-0050: form returned by completed command are now managed
Goffi <goffi@goffi.org>
parents: 993
diff changeset
466 else:
eef1f200d733 plugin XEP-0050: form returned by completed command are now managed
Goffi <goffi@goffi.org>
parents: 993
diff changeset
467 return None
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
468 remote_session_id = answer_data["session_id"]
763
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
469 if remote_session_id:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
470 session_data["remote_id"] = remote_session_id
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
471 notes = answer_data["notes"]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
472 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
473 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
474 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
475 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
476 # no matching data element found
1110
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
477 if status != XEP_0050.STATUS.COMPLETED:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
478 log.warning(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
479 _("No known payload found in ad-hoc command result, aborting")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
480 )
1110
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
481 del self.requesting[session_id]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
482 return xml_tools.XMLUI(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
483 C.XMLUI_DIALOG,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
484 dialog_opt={
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
485 C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_NOTE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
486 C.XMLUI_DATA_MESS: _("No payload found"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
487 C.XMLUI_DATA_LVL: C.XMLUI_DATA_LVL_ERROR,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
488 },
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
489 )
1110
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
490 if not notes:
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
491 # 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
492 return None
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
493
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
494 # 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
495 # 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
496 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
497 return xml_tools.XMLUI(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
498 C.XMLUI_DIALOG,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
499 dialog_opt={
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
500 C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_NOTE,
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
501 C.XMLUI_DATA_MESS: "\n".join(self._merge_notes(notes)),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
502 C.XMLUI_DATA_LVL: dlg_level,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
503 },
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
504 session_id=session_id,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
505 )
1110
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
506
1071
eef1f200d733 plugin XEP-0050: form returned by completed command are now managed
Goffi <goffi@goffi.org>
parents: 993
diff changeset
507 if session_id is None:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
508 xmlui = xml_tools.data_form_elt_result_2_xmlui(data_elt)
3530
fad3b3ffa8fe plugin XEP-0050: show notes when there is a data form on completed command:
Goffi <goffi@goffi.org>
parents: 3529
diff changeset
509 if notes:
fad3b3ffa8fe plugin XEP-0050: show notes when there is a data form on completed command:
Goffi <goffi@goffi.org>
parents: 3529
diff changeset
510 for level, note in notes:
fad3b3ffa8fe plugin XEP-0050: show notes when there is a data form on completed command:
Goffi <goffi@goffi.org>
parents: 3529
diff changeset
511 if level != "info":
fad3b3ffa8fe plugin XEP-0050: show notes when there is a data form on completed command:
Goffi <goffi@goffi.org>
parents: 3529
diff changeset
512 note = f"[{level}] {note}"
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
513 xmlui.add_widget("text", note)
3530
fad3b3ffa8fe plugin XEP-0050: show notes when there is a data form on completed command:
Goffi <goffi@goffi.org>
parents: 3529
diff changeset
514 return xmlui
fad3b3ffa8fe plugin XEP-0050: show notes when there is a data form on completed command:
Goffi <goffi@goffi.org>
parents: 3529
diff changeset
515
763
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
516 form = data_form.Form.fromElement(data_elt)
1110
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
517 # we add any present note to the instructions
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
518 form.instructions.extend(self._merge_notes(notes))
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
519 return xml_tools.data_form_2_xmlui(
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
520 form, self.__requesting_id, session_id=session_id
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
521 )
763
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
522
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
523 def _requesting_entity(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
524 def serialise(ret_data):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
525 if "xmlui" in ret_data:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
526 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
527 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
528
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
529 d = self.requesting_entity(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
530 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
531 return d
1e5b2c35964e plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents: 2364
diff changeset
532
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
533 def requesting_entity(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
534 """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
535
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
536 @param data: data returned by previous XMLUI (first one must come from
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
537 self._commands_menu)
763
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
538 @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
539 @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
540 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
541 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
542 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
543 return defer.succeed({})
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
544 data_form_values = xml_tools.xmlui_result_2_data_form_result(data)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
545 client = self.host.get_client(profile)
763
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
546 # 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
547 # TODO: managed answerer errors
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
548 # 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
549 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
550 # we just had the jid, we now request it for the available commands
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
551 session_id, session_data = self.requesting.new_session(profile=client.profile)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
552 entity = jid.JID(data[xml_tools.SAT_FORM_PREFIX + "jid"])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
553 session_data["jid"] = entity
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
554 d = self.list_ui(client, entity)
763
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
555
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
556 def send_items(xmlui):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
557 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
558 return {"xmlui": xmlui}
763
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
559
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
560 d.addCallback(send_items)
763
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
561 else:
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
562 # 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
563 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
564 session_data = self.requesting.profile_get(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
565 data["session_id"], client.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
566 )
763
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
567 except KeyError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
568 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
569 # TODO: send error dialog
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
570 return defer.succeed({})
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
571 session_id = data["session_id"]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
572 entity = session_data["jid"]
763
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
573 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
574 session_data["node"]
763
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
575 # node has already been received
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
576 except KeyError:
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
577 # 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
578 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
579
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
580 # 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
581 # 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
582 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
583
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
584 # we request execute node's command
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
585 d = self.do(
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
586 client,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
587 entity,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
588 session_data["node"],
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
589 action=XEP_0050.ACTION.EXECUTE,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
590 session_id=remote_id,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
591 form_values=data_form_values,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
592 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
593 d.addCallback(self._commands_answer_2_xmlui, session_id, session_data)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
594 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
595
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
596 return d
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
597
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
598 def _commands_menu(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
599 """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
600
763
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
601 @param profile: %(doc_profile)s
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
602 """
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
603 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
604 form_ui.addText(_("Please enter target jid"), "instructions")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
605 form_ui.change_container("pairs")
763
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
606 form_ui.addLabel("jid")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
607 form_ui.addString("jid", value=self.host.get_client(profile).jid.host)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
608 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
609
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
610 def _status_callback(self, client, command_elt, session_data, action, node):
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
611 """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
612 actions = session_data.setdefault("actions", [])
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
613 actions.append(action)
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
614
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
615 if len(actions) == 1:
763
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
616 # 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
617 status = XEP_0050.STATUS.EXECUTING
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
618 form = data_form.Form("form", title=_("status selection"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
619 show_options = [
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2921
diff changeset
620 data_form.Option(name, label) for name, label in list(SHOWS.items())
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
621 ]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
622 field = data_form.Field(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
623 "list-single", "show", options=show_options, required=True
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
624 )
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
625 form.addField(field)
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
626
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
627 payload = form.toElement()
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
628 note = None
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
629
763
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
630 elif len(actions) == 2:
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
631 # 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
632 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2921
diff changeset
633 x_elt = next(command_elt.elements(data_form.NS_X_DATA, "x"))
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
634 answer_form = data_form.Form.fromElement(x_elt)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
635 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
636 except (KeyError, StopIteration):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
637 self.ad_hoc_error(XEP_0050.ERROR.BAD_PAYLOAD)
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
638 if show not in SHOWS:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
639 self.ad_hoc_error(XEP_0050.ERROR.BAD_PAYLOAD)
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
640 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
641 self.host.disconnect(client.profile)
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
642 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
643 self.host.presence_set(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
644
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
645 # job done, we can end the session
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
646 status = XEP_0050.STATUS.COMPLETED
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
647 payload = None
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2921
diff changeset
648 note = (self.NOTE.INFO, _("Status updated"))
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
649 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
650 self.ad_hoc_error(XEP_0050.ERROR.INTERNAL)
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
651
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
652 return (payload, status, None, note)
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
653
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
654 def _run(self, service_jid_s="", node="", profile_key=C.PROF_KEY_NONE):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
655 client = self.host.get_client(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
656 service_jid = jid.JID(service_jid_s) if service_jid_s else None
3900
6c93a18b6250 plugin XEP-0050: use coroutine + minor code readability improvments:
Goffi <goffi@goffi.org>
parents: 3530
diff changeset
657 d = defer.ensureDeferred(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
658 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
659 return d
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
660
3900
6c93a18b6250 plugin XEP-0050: use coroutine + minor code readability improvments:
Goffi <goffi@goffi.org>
parents: 3530
diff changeset
661 async def run(self, client, service_jid=None, node=None):
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
662 """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
663
2406
1e5b2c35964e plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents: 2364
diff changeset
664 @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
665 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
666 @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
667 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
668 @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
669 """
2406
1e5b2c35964e plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents: 2364
diff changeset
670 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
671 service_jid = jid.JID(client.jid.host)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
672 session_id, session_data = self.requesting.new_session(profile=client.profile)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
673 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
674 if node is None:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
675 xmlui = await self.list_ui(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
676 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
677 session_data["node"] = node
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
678 cb_data = await self.requesting_entity(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
679 {"session_id": session_id}, client.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
680 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
681 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
682
1e5b2c35964e plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents: 2364
diff changeset
683 xmlui.session_id = session_id
3900
6c93a18b6250 plugin XEP-0050: use coroutine + minor code readability improvments:
Goffi <goffi@goffi.org>
parents: 3530
diff changeset
684 return xmlui
2406
1e5b2c35964e plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents: 2364
diff changeset
685
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
686 def list_commands(self, client, to_jid):
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
687 """Request available commands
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
688
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
689 @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
690 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
691 @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
692 """
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
693 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
694 return d
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
695
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
696 def _list_ui(self, to_jid_s, profile_key):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
697 client = self.host.get_client(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
698 to_jid = jid.JID(to_jid_s) if to_jid_s else None
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
699 d = self.list_ui(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
700 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
701 return d
ab851b46009c plugin xep-0050 (ad-hoc commands): requesting part. first draft
Goffi <goffi@goffi.org>
parents: 758
diff changeset
702
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
703 def list_ui(self, client, to_jid, no_instructions=False):
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
704 """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
705
1e5b2c35964e plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents: 2364
diff changeset
706 @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
707 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
708 @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
709 @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
710 """
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
711 d = self.list_commands(client, to_jid)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
712 d.addCallback(self._items_2_xmlui, no_instructions)
2406
1e5b2c35964e plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents: 2364
diff changeset
713 return d
1e5b2c35964e plugin XEP-0050: renamed "requestCommandsList" method to "list" + added a run command + fixes:
Goffi <goffi@goffi.org>
parents: 2364
diff changeset
714
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
715 def _sequence(self, sequence, node, service_jid_s="", profile_key=C.PROF_KEY_NONE):
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
716 sequence = data_format.deserialise(sequence, type_check=list)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
717 client = self.host.get_client(profile_key)
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
718 service_jid = jid.JID(service_jid_s) if service_jid_s else None
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
719 d = defer.ensureDeferred(self.sequence(client, sequence, node, service_jid))
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
720 d.addCallback(lambda data: data_format.serialise(data))
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
721 return d
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
722
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
723 async def sequence(
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
724 self,
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
725 client: SatXMPPEntity,
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
726 sequence: list[dict],
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
727 node: str,
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
728 service_jid: jid.JID | None = None,
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
729 ) -> dict:
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
730 """Send a series of data to an ad-hoc service
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
731
3315
53b229761c9d plugin XEP-0050: typo
Goffi <goffi@goffi.org>
parents: 3302
diff changeset
732 @param sequence: list of values to send
53b229761c9d plugin XEP-0050: typo
Goffi <goffi@goffi.org>
parents: 3302
diff changeset
733 value are specified by a dict mapping var name to value.
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
734 @param node: node of the ad-hoc commnad
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
735 @param service_jid: jid of the ad-hoc service
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
736 None to use profile's server
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
737 @return: data received in final answer
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
738 """
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
739 assert sequence
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
740 answer_data = None
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
741 if service_jid is None:
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
742 service_jid = jid.JID(client.jid.host)
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
743
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
744 session_id = None
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
745
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
746 for data_to_send in sequence:
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
747 iq_result_elt = await self.do(
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
748 client,
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
749 service_jid,
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
750 node,
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
751 session_id=session_id,
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
752 form_values=data_to_send,
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
753 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
754 __, answer_data = self.parse_command_answer(iq_result_elt)
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
755 session_id = answer_data.pop("session_id")
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
756
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
757 assert answer_data is not None
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
758
3302
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
759 return answer_data
9d61ceeaa847 plugin XEP-0050: some modernisation + adHocSequence:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
760
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
761 def add_ad_hoc_command(
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
762 self,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
763 client: SatXMPPClient,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
764 callback: Callable,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
765 label: str,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
766 node: str | None = None,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
767 features: list[str] | None = None,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
768 timeout: int = 600,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
769 allowed_jids: list[jid.JID] | None = None,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
770 allowed_groups: list[str] | None = None,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
771 allowed_magics: list[str] | None = None,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
772 forbidden_jids: list[jid.JID] | None = None,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
773 forbidden_groups: list[str] | None = None,
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
774 ) -> str:
1110
36c1bbb8ca24 plugin XEP-0050: notes are now managed:
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
775 """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
776
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
777 @param callback: method associated with this ad-hoc command which return the
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
778 payload data (see AdHocCommand._sendAnswer), can return a deferred
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
779 @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
780 @param node: disco item node associated with this command. None to use
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
781 autogenerated node
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
782 @param features: features associated with the payload (list of strings), usualy
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
783 data form
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
784 @param timeout: delay between two requests before canceling the session (in
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
785 seconds)
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
786 @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
787 @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
788 @param allowed_magics: list of allowed magic keys, can be:
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
789 C.ENTITY_ALL: allow everybody
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
790 C.ENTITY_PROFILE_BARE: allow only the jid of the profile
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
791 C.ENTITY_ADMINS: any administrator user
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
792 @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
793 @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
794 @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
795 """
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
796 commands = client._XEP_0050_commands
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
797
1495
987e74cbb839 plugin XEP-0050: fixed crash on empty node in addAdHocCommand
Goffi <goffi@goffi.org>
parents: 1494
diff changeset
798 if node is None:
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
799 node = label.lower().replace(" ", "_")
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
800 if not node:
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
801 node = f"COMMANDS_{uuid4()}"
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
802 elif node in commands:
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
803 node = f"{node}_{uuid4()}"
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
804
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
805 if features is None:
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
806 features = [data_form.NS_X_DATA]
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
807
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
808 if allowed_jids is None:
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
809 allowed_jids = []
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
810 else:
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
811 # we don't want to modify the initial list
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
812 allowed_jids = allowed_jids.copy()
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
813 if allowed_groups is None:
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
814 allowed_groups = []
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
815 if allowed_magics is None:
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
816 allowed_magics = [C.ENTITY_PROFILE_BARE]
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
817 if forbidden_jids is None:
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
818 forbidden_jids = []
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
819 if forbidden_groups is None:
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
820 forbidden_groups = []
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
821
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
822 # TODO: manage newly created/removed profiles
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
823 if C.ENTITY_PROFILE_BARE in allowed_magics:
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
824 allowed_jids += [client.jid.userhostJID()]
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
825 # TODO: manage dynamic addition/removal of admin status once possible
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
826 if C.ENTITY_ADMINS in allowed_magics:
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
827 allowed_jids += list(self.host.memory.admin_jids)
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
828
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
829 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
830 callback,
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
831 label,
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
832 node,
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
833 features,
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
834 timeout,
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
835 allowed_jids,
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
836 allowed_groups,
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
837 allowed_magics,
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
838 forbidden_jids,
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
839 forbidden_groups,
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
840 )
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
841 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
842 commands[node] = ad_hoc_command
4184
50c919dfe61b plugin XEP-0050: small code quality improvements + add `C.ENTITY_ADMINS` magic key to allow administrators profiles
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
843 return node
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
844
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
845 def on_cmd_request(self, request, client):
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
846 request.handled = True
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
847 requestor = jid.JID(request["from"])
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2921
diff changeset
848 command_elt = next(request.elements(NS_COMMANDS, "command"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
849 action = command_elt.getAttribute("action", self.ACTION.EXECUTE)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
850 node = command_elt.getAttribute("node")
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
851 if not node:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2921
diff changeset
852 client.sendError(request, "bad-request")
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
853 return
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
854 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
855 commands = client._XEP_0050_commands
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
856 try:
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
857 command = commands[node]
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
858 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2921
diff changeset
859 client.sendError(request, "item-not-found")
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
860 return
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
861 command.on_request(command_elt, requestor, action, sessionid)
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
862
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
863
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2921
diff changeset
864 @implementer(iwokkel.IDisco)
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
865 class XEP_0050_handler(XMPPHandler):
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
866 def __init__(self, plugin_parent):
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
867 self.plugin_parent = plugin_parent
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
868
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
869 @property
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
870 def client(self):
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
871 return self.parent
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
872
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
873 def connectionInitialized(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
874 self.xmlstream.addObserver(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
875 CMD_REQUEST, self.plugin_parent.on_cmd_request, client=self.parent
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
876 )
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
877
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
878 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
879 identities = []
2667
8dd9db785ac8 plugin XEP-0050, adhoc D-Bus: Ad-Hoc improvment + remote media control:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
880 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
881 # 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
882 identities.append(ID_CMD_LIST)
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
883 return [disco.DiscoFeature(NS_COMMANDS)] + identities
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
884
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
885 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
886 ret = []
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
887 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
888 commands = self.client._XEP_0050_commands
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2921
diff changeset
889 for command in list(commands.values()):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3900
diff changeset
890 if command.is_authorised(requestor):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
891 ret.append(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
892 disco.DiscoItem(self.parent.jid, command.node, command.getName())
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2585
diff changeset
893 ) # TODO: manage name language
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
diff changeset
894 return ret