Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0465.py @ 4320:9658c534287e
plugin XEP-0215, XEP-0376: fix bad calls to `hasFeature`:
`hasFeature` was called like blocking code, missing the `await`. This has been fixed, and
is now using the `memory.disco.has_feature` version.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 30 Sep 2024 14:14:38 +0200 |
parents | 0d7bb4df2343 |
children |
rev | line source |
---|---|
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 # Libervia plugin for XEP-0465 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 from typing import Optional, List, Dict, Union |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from twisted.words.protocols.jabber.xmlstream import XMPPHandler |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from twisted.words.protocols.jabber import jid |
4008
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
23 from twisted.words.protocols.jabber import error |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from twisted.words.xish import domish |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from zope.interface import implementer |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from wokkel import disco, iwokkel |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
28 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
|
29 from libervia.backend.core.i18n import _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
30 from libervia.backend.core.log import getLogger |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
31 from libervia.backend.core import exceptions |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
32 from libervia.backend.core.core_types import SatXMPPEntity |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
33 from libervia.backend.tools import utils |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
34 from libervia.backend.tools.common import data_format |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 log = getLogger(__name__) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 PLUGIN_INFO = { |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 C.PI_NAME: "Pubsub Public Subscriptions", |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 C.PI_IMPORT_NAME: "XEP-0465", |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 C.PI_TYPE: C.PLUG_TYPE_XEP, |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 C.PI_MODES: C.PLUG_MODE_BOTH, |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 C.PI_PROTOCOLS: ["XEP-0465"], |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0376"], |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 C.PI_MAIN: "XEP_0465", |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 C.PI_HANDLER: "yes", |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 C.PI_DESCRIPTION: _("""Pubsub Public Subscriptions implementation"""), |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 } |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 NS_PPS = "urn:xmpp:pps:0" |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 NS_PPS_SUBSCRIPTIONS = "urn:xmpp:pps:subscriptions:0" |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 NS_PPS_SUBSCRIBERS = "urn:xmpp:pps:subscribers:0" |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 SUBSCRIBERS_NODE_PREFIX = f"{NS_PPS_SUBSCRIBERS}/" |
4008
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
54 NOT_IMPLEMENTED_MSG = ( |
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
55 "The service at {service!s} doesn't seem to support Pubsub Public Subscriptions " |
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
56 "(XEP-0465), please request support from your service administrator." |
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
57 ) |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 class XEP_0465: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 def __init__(self, host): |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 log.info(_("Pubsub Public Subscriptions initialization")) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4008
diff
changeset
|
64 host.register_namespace("pps", NS_PPS) |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 self.host = host |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4008
diff
changeset
|
66 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4008
diff
changeset
|
67 "ps_public_subscriptions_get", |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 ".plugin", |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 in_sign="sss", |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 out_sign="s", |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 method=self._subscriptions, |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 async_=True, |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4008
diff
changeset
|
74 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4008
diff
changeset
|
75 "ps_public_subscriptions_get", |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 ".plugin", |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 in_sign="sss", |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 out_sign="s", |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 method=self._subscriptions, |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 async_=True, |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4008
diff
changeset
|
82 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4008
diff
changeset
|
83 "ps_public_node_subscriptions_get", |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 ".plugin", |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 in_sign="sss", |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 out_sign="a{ss}", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4008
diff
changeset
|
87 method=self._get_public_node_subscriptions, |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 async_=True, |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 ) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4008
diff
changeset
|
91 def get_handler(self, client): |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 return XEP_0465_Handler() |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 @property |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 def subscriptions_node(self) -> str: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 return NS_PPS_SUBSCRIPTIONS |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 @property |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 def subscribers_node_prefix(self) -> str: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 return SUBSCRIBERS_NODE_PREFIX |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4008
diff
changeset
|
102 def build_subscription_elt(self, node: str, service: jid.JID) -> domish.Element: |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 """Generate a <subscriptions> element |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 This is the element that a service returns on public subscriptions request |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 """ |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 subscription_elt = domish.Element((NS_PPS, "subscription")) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 subscription_elt["node"] = node |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 subscription_elt["service"] = service.full() |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 return subscription_elt |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4008
diff
changeset
|
112 def build_subscriber_elt(self, subscriber: jid.JID) -> domish.Element: |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 """Generate a <subscriber> element |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 This is the element that a service returns on node public subscriptions request |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 """ |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 subscriber_elt = domish.Element((NS_PPS, "subscriber")) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 subscriber_elt["jid"] = subscriber.full() |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 return subscriber_elt |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 @utils.ensure_deferred |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 async def _subscriptions( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
123 self, service="", nodeIdentifier="", profile_key=C.PROF_KEY_NONE |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 ) -> str: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4008
diff
changeset
|
125 client = self.host.get_client(profile_key) |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 service = None if not service else jid.JID(service) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 subs = await self.subscriptions(client, service, nodeIdentifier or None) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 return data_format.serialise(subs) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 async def subscriptions( |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 self, |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 client: SatXMPPEntity, |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 service: Optional[jid.JID] = None, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
134 node: Optional[str] = None, |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 ) -> List[Dict[str, Union[str, bool]]]: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 """Retrieve public subscriptions from a service |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 @param service(jid.JID): PubSub service |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 @param nodeIdentifier(unicode, None): node to filter |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 None to get all subscriptions |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 """ |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 if service is None: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 service = client.jid.userhostJID() |
4008
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
144 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4008
diff
changeset
|
145 items, __ = await self.host.plugins["XEP-0060"].get_items( |
4008
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
146 client, service, NS_PPS_SUBSCRIPTIONS |
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
147 ) |
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
148 except error.StanzaError as e: |
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
149 if e.condition == "forbidden": |
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
150 log.warning(NOT_IMPLEMENTED_MSG.format(service=service)) |
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
151 return [] |
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
152 else: |
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
153 raise e |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 ret = [] |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 for item in items: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 try: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 subscription_elt = next(item.elements(NS_PPS, "subscription")) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 except StopIteration: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 log.warning(f"no <subscription> element found: {item.toXml()}") |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 continue |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 try: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 sub_dict = { |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 "service": subscription_elt["service"], |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 "node": subscription_elt["node"], |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 "subscriber": service.full(), |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 "state": subscription_elt.getAttribute("subscription", "subscribed"), |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 } |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 except KeyError: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
170 log.warning(f"invalid <subscription> element: {subscription_elt.toXml()}") |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 continue |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 if node is not None and sub_dict["node"] != node: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 # if not is specified, we filter out any other node |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 # FIXME: should node filtering be done by server? |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 continue |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 ret.append(sub_dict) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 return ret |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 @utils.ensure_deferred |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4008
diff
changeset
|
180 async def _get_public_node_subscriptions( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
181 self, service: str, node: str, profile_key: str |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 ) -> Dict[str, str]: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4008
diff
changeset
|
183 client = self.host.get_client(profile_key) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4008
diff
changeset
|
184 subs = await self.get_public_node_subscriptions( |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 client, jid.JID(service) if service else None, node |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 ) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 return {j.full(): a for j, a in subs.items()} |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4008
diff
changeset
|
189 def get_public_subscribers_node(self, node: str) -> str: |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 """Return prefixed node to retrieve public subscribers""" |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 return f"{NS_PPS_SUBSCRIBERS}/{node}" |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4008
diff
changeset
|
193 async def get_public_node_subscriptions( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
194 self, client: SatXMPPEntity, service: Optional[jid.JID], nodeIdentifier: str |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 ) -> Dict[jid.JID, str]: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 """Retrieve public subscriptions to a node |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 @param nodeIdentifier(unicode): node to get subscriptions from |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 """ |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 if not nodeIdentifier: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 raise exceptions.DataError("node identifier can't be empty") |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 if service is None: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 service = client.jid.userhostJID() |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4008
diff
changeset
|
206 subscribers_node = self.get_public_subscribers_node(nodeIdentifier) |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 |
4008
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
208 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4008
diff
changeset
|
209 items, __ = await self.host.plugins["XEP-0060"].get_items( |
4008
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
210 client, service, subscribers_node |
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
211 ) |
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
212 except error.StanzaError as e: |
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
213 if e.condition == "forbidden": |
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
214 log.warning(NOT_IMPLEMENTED_MSG.format(service=service)) |
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
215 return {} |
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
216 else: |
56e5b18f4d06
plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
217 raise e |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
218 ret = {} |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 for item in items: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 try: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 subscriber_elt = next(item.elements(NS_PPS, "subscriber")) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 except StopIteration: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 log.warning(f"no <subscriber> element found: {item.toXml()}") |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 continue |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
225 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
226 try: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 ret[jid.JID(subscriber_elt["jid"])] = "subscribed" |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 except (KeyError, RuntimeError): |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
229 log.warning(f"invalid <subscriber> element: {subscriber_elt.toXml()}") |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 continue |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 return ret |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4008
diff
changeset
|
233 def set_public_opt(self, options: Optional[dict] = None) -> dict: |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 """Set option to make a subscription public |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 @param options: dict where the option must be set |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 if None, a new dict will be created |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 @return: the options dict |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 """ |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 if options is None: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 options = {} |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
243 options[f"{{{NS_PPS}}}public"] = True |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 return options |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
246 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 @implementer(iwokkel.IDisco) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 class XEP_0465_Handler(XMPPHandler): |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
249 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 def getDiscoInfo(self, requestor, service, nodeIdentifier=""): |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 return [disco.DiscoFeature(NS_PPS)] |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 def getDiscoItems(self, requestor, service, nodeIdentifier=""): |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 return [] |