annotate libervia/backend/plugins/plugin_xep_0100.py @ 4304:92a886f31581 default tip @

doc (components): new Email gateway documentation: fix 449
author Goffi <goffi@goffi.org>
date Fri, 06 Sep 2024 18:07:44 +0200
parents 7ded09452875
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
4 # SAT plugin for managing gateways (xep-0100)
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
10 # (at your option) any later version.
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
15 # GNU Affero General Public License for more details.
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
diff changeset
19
4300
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
20 from typing import cast
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
21 from pydantic import BaseModel, Field
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
22 from twisted.internet import defer, reactor
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
23 from twisted.words.protocols.jabber import jid
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
24 from wokkel import disco
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
25
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
26 from libervia.backend.core import exceptions
4300
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
27 from libervia.backend.core.constants import Const as C
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
28 from libervia.backend.core.core_types import SatXMPPEntity
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
29 from libervia.backend.core.i18n import D_, _
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
30 from libervia.backend.core.log import getLogger
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
31 from libervia.backend.models.core import DiscoIdentity
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
32 from libervia.backend.models.types import StrictJIDType
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
33 from libervia.backend.tools import xml_tools
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
34
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
35 log = getLogger(__name__)
4300
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
36
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
diff changeset
37
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
diff changeset
38 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
39 C.PI_NAME: "Gateways Plugin",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
40 C.PI_IMPORT_NAME: "XEP-0100",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
41 C.PI_TYPE: "XEP",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
42 C.PI_PROTOCOLS: ["XEP-0100"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
43 C.PI_DEPENDENCIES: ["XEP-0077"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
44 C.PI_MAIN: "XEP_0100",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
45 C.PI_DESCRIPTION: _("""Implementation of Gateways protocol"""),
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
diff changeset
46 }
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
diff changeset
47
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
48 WARNING_MSG = D_(
4300
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
49 "Please exercise caution. Gateways facilitate the use of external instant messaging "
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
50 "platforms (legacy IM), enabling you to view your contacts as XMPP contacts. "
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
51 "However, this process routes all messages through the external legacy IM server, "
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
52 "raising significant privacy concerns. Specifically, it is possible for the external "
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
53 "server, often operated by a private company, to monitor, record, and analyze all "
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
54 "messages that traverse the gateway."
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
55 )
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
56
1049
9e24ca275ddd plugin XEP-0100: fixes the call to log.debug (line 185)
souliane <souliane@mailoo.org>
parents: 993
diff changeset
57 GATEWAY_TIMEOUT = 10 # time to wait before cancelling a gateway disco info, in seconds
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
58
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
59 TYPE_DESCRIPTIONS = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
60 "irc": D_("Internet Relay Chat"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
61 "xmpp": D_("XMPP"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
62 "qq": D_("Tencent QQ"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
63 "simple": D_("SIP/SIMPLE"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
64 "icq": D_("ICQ"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
65 "yahoo": D_("Yahoo! Messenger"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
66 "gadu-gadu": D_("Gadu-Gadu"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
67 "aim": D_("AOL Instant Messenger"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 "msn": D_("Windows Live Messenger"),
4300
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
69 "smtp": D_("Email"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 }
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
71
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
72
4300
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
73 class GatewayData(BaseModel):
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
74 entity: StrictJIDType
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
75 identities: list[DiscoIdentity]
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
76
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
77
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
78 class FoundGateways(BaseModel):
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
79 available: list[GatewayData]
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
80 unavailable: list[StrictJIDType] = Field(
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
81 description="Gateways registered but not answering."
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
82 )
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
83
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
84
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
85 class XEP_0100(object):
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
diff changeset
86 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
87 log.info(_("Gateways plugin initialization"))
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
diff changeset
88 self.host = host
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
89 self.__gateways = (
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
90 {}
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
91 ) # dict used to construct the answer to gateways_find. Key = target jid
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
92 host.bridge.add_method(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
93 "gateways_find",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
94 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
95 in_sign="ss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
96 out_sign="s",
4300
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
97 method=self._gateways_find,
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
98 )
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
99 host.bridge.add_method(
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
100 "gateways_find_xmlui",
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
101 ".plugin",
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
102 in_sign="ss",
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
103 out_sign="s",
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
104 method=self._gateways_find_xmlui,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
105 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
106 host.bridge.add_method(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
107 "gateway_register",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
108 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
109 in_sign="ss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
110 out_sign="s",
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
111 method=self._gateway_register,
4300
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
112 async_=True,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
113 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
114 self.__menu_id = host.register_callback(self._gateways_menu, with_data=True)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
115 self.__selected_id = host.register_callback(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
116 self._gateway_selected_cb, with_data=True
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
117 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
118 host.import_menu(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
119 (D_("Service"), D_("Gateways")),
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
120 self._gateways_menu,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
121 security_limit=1,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
122 help_string=D_("Find gateways"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
123 )
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
124
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
125 def _gateways_menu(self, data, profile):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
126 """XMLUI activated by menu: return Gateways UI
1635
591e04f0103c plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents: 1539
diff changeset
127
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
128 @param profile: %(doc_profile)s
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
129 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
130 client = self.host.get_client(profile)
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
131 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
132 jid_ = jid.JID(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
133 data.get(xml_tools.form_escape("external_jid"), client.jid.host)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
134 )
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
135 except RuntimeError:
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
136 raise exceptions.DataError(_("Invalid JID"))
4300
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
137 d = self.gateways_find_raw(jid_, profile)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
138 d.addCallback(self._gateways_result_2_xmlui, jid_)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
139 d.addCallback(lambda xmlui: {"xmlui": xmlui.toXml()})
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
140 return d
39
2e3411a6baad Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents: 37
diff changeset
141
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
142 def _gateways_result_2_xmlui(self, result, entity):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
143 xmlui = xml_tools.XMLUI(title=_("Gateways manager (%s)") % entity.full())
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
144 xmlui.addText(_(WARNING_MSG))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
145 xmlui.addDivider("dash")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
146 adv_list = xmlui.change_container(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
147 "advanced_list",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
148 columns=3,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
149 selectable="single",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
150 callback_id=self.__selected_id,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
151 )
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
152 for success, gateway_data in result:
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
153 if not success:
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
154 fail_cond, disco_item = gateway_data
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
155 xmlui.addJid(disco_item.entity)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
156 xmlui.addText(_("Failed (%s)") % fail_cond)
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
157 xmlui.addEmpty()
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
158 else:
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
159 jid_, data = gateway_data
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
160 for datum in data:
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
161 identity, name = datum
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
162 adv_list.set_row_index(jid_.full())
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
163 xmlui.addJid(jid_)
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
164 xmlui.addText(name)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
165 xmlui.addText(self._get_identity_desc(identity))
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
166 adv_list.end()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
167 xmlui.addDivider("blank")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
168 xmlui.change_container("advanced_list", columns=3)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
169 xmlui.addLabel(_("Use external XMPP server"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
170 xmlui.addString("external_jid")
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
171 xmlui.addButton(self.__menu_id, _("Go !"), fields_back=("external_jid",))
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
172 return xmlui
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
173
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
174 def _gateway_selected_cb(self, data, profile):
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
175 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
176 target_jid = jid.JID(data["index"])
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
177 except (KeyError, RuntimeError):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
178 log.warning(_("No gateway index selected"))
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
179 return {}
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
180
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
181 d = self.gateway_register(target_jid, profile)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
182 d.addCallback(lambda xmlui: {"xmlui": xmlui.toXml()})
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
183 return d
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
184
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
185 def _get_identity_desc(self, identity):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
186 """Return a human readable description of identity
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
187 @param identity: tuple as returned by Disco identities (category, type)
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
188
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
189 """
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
190 category, type_ = identity
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
191 if category != "gateway":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
192 log.error(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
193 _(
4300
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
194 'INTERNAL ERROR: identity category should always be "gateway" in '
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
195 '_getTypeString, got "%s"'
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
196 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
197 % category
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
198 )
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
199 try:
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
200 return _(TYPE_DESCRIPTIONS[type_])
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
201 except KeyError:
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
202 return _("Unknown IM")
39
2e3411a6baad Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents: 37
diff changeset
203
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
204 def _registration_successful(self, jid_, profile):
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
205 """Called when in_band registration is ok, we must now follow the rest of procedure"""
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
206 log.debug(_("Registration successful, doing the rest"))
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
207 self.host.contact_add(jid_, profile_key=profile)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
208 self.host.presence_set(jid_, profile_key=profile)
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
209
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
210 def _gateway_register(self, target_jid_s, profile_key=C.PROF_KEY_NONE):
4300
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
211 client = self.host.get_client(profile_key)
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
212 d = self.gateway_register(client, jid.JID(target_jid_s))
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
213 d.addCallback(lambda xmlui: xmlui.toXml())
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
214 return d
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
215
4300
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
216 def gateway_register(
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
217 self, client: SatXMPPEntity, target_jid: jid.JID
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
218 ) -> defer.Deferred:
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
219 """Register gateway using in-band registration, then log-in to gateway"""
4300
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
220 return defer.ensureDeferred(
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
221 self.host.plugins["XEP-0077"].in_band_register(
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
222 client, target_jid, self._registration_successful
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
223 )
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
224 )
4300
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
225
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
226 def _gateways_find(self, target_jid_s: str, profile_key: str) -> defer.Deferred[str]:
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
227 client = self.host.get_client(profile_key)
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
228 target_jid = jid.JID(target_jid_s) if target_jid_s else client.server_jid
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
229 d = defer.ensureDeferred(self.gateways_find(client, target_jid))
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
230 d.addCallback(lambda found_gateways: found_gateways.model_dump_json())
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
231 # The Deferred will actually return a str due to `model_dump_json`, but type
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
232 # checker doesn't get that.
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
233 d = cast(defer.Deferred[str], d)
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
234 return d
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
235
4300
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
236 async def gateways_find(
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
237 self, client: SatXMPPEntity, target: jid.JID
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
238 ) -> FoundGateways:
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
239 """Find gateways and convert FoundGateways instance."""
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
240 gateways_data = await self.gateways_find_raw(client, target)
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
241 available = []
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
242 unavailable = []
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
243 for gw_available, data in gateways_data:
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
244 if gw_available:
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
245 data = cast(tuple[jid.JID, list[tuple[tuple[str, str], str]]], data)
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
246 identities = []
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
247 for (category, type_), name in data[1]:
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
248 identities.append(
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
249 DiscoIdentity(name=name, category=category, type=type_)
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
250 )
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
251 available.append(GatewayData(entity=data[0], identities=identities))
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
252 else:
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
253 disco_item = cast(disco.DiscoItem, data[1])
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
254 unavailable.append(disco_item.entity)
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
255 return FoundGateways(available=available, unavailable=unavailable)
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
diff changeset
256
4300
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
257 def _gateways_find_xmlui(
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
258 self, target_jid_s: str, profile_key: str
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
259 ) -> defer.Deferred[str]:
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
260 target_jid = jid.JID(target_jid_s)
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
261 client = self.host.get_client(profile_key)
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
262 d = defer.ensureDeferred(self.gateways_find_raw(client, target_jid))
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
263 d.addCallback(self._gateways_result_2_xmlui, target_jid)
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
264 d.addCallback(lambda xmlui: xmlui.toXml())
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
265 d = cast(defer.Deferred[str], d)
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
266 return d
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
267
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
268 async def gateways_find_raw(self, client: SatXMPPEntity, target: jid.JID) -> list:
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
269 """Find gateways in the target JID, using discovery protocol"""
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
270 log.debug(
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
271 _("find gateways (target = {target}, profile = {profile})").format(
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
272 target=target.full(), profile=client.profile
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
273 )
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
274 )
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
275 disco = await client.disco.requestItems(target)
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
276 if len(disco._items) == 0:
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
277 log.debug(_("No gateway found"))
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
278 return []
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
279
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
280 defers_ = []
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
281 for item in disco._items:
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
282 log.debug(_("item found: {}").format(item.entity))
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
283 defers_.append(client.disco.requestInfo(item.entity))
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
284 deferred_list = defer.DeferredList(defers_)
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
285 dl_result = await deferred_list
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
286 reactor.callLater(GATEWAY_TIMEOUT, deferred_list.cancel)
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
287 items = disco._items
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
288 ret = []
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
289 for idx, (success, result) in enumerate(dl_result):
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
290 if not success:
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
291 if isinstance(result.value, defer.CancelledError):
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
292 msg = _("Timeout")
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
293 else:
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
294 try:
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
295 msg = result.value.condition
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
296 except AttributeError:
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
297 msg = str(result)
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
298 ret.append((success, (msg, items[idx])))
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
299 else:
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
300 entity = items[idx].entity
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
301 gateways = [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
302 (identity, result.identities[identity])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
303 for identity in result.identities
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
304 if identity[0] == "gateway"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
305 ]
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
306 if gateways:
4300
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
307 log.debug(
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
308 _("Found gateway [{jid}]: {identity_name}").format(
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
309 jid=entity.full(),
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
310 identity_name=" - ".join(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
311 [gateway[1] for gateway in gateways]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
312 ),
4300
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
313 )
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
314 )
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
315 ret.append((success, (entity, gateways)))
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 771
diff changeset
316 else:
4300
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
317 log.debug(
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
318 _("Skipping [{jid}] which is not a gateway").format(
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
319 jid=entity.full()
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
320 )
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
321 )
102
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 69
diff changeset
322
4300
7ded09452875 plugin XEP-0077, XEP-0100: Adapt to component, and modernize:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
323 return ret