Mercurial > libervia-backend
annotate libervia/backend/memory/disco.py @ 4348:35d41de5b2aa @
doc (component): document use of Gateway Relayed Encryption:
fix 455
| author | Goffi <goffi@goffi.org> |
|---|---|
| date | Mon, 13 Jan 2025 01:23:22 +0100 |
| parents | 17fa953c8cd7 |
| children | 1bedcc6712e9 |
| rev | line source |
|---|---|
| 3028 | 1 #!/usr/bin/env python3 |
| 3137 | 2 |
|
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
|
4306
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
4 # Libervia XMPP client |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
5 # Copyright (C) 2009-2024 Jérôme Poisson (goffi@goffi.org) |
|
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
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. |
|
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
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. |
|
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
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/>. |
|
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
|
4306
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
20 from typing import Iterable, Optional, cast |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
21 |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
22 from twisted.internet.interfaces import IReactorCore |
|
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
23 from libervia.backend.core.i18n import _ |
|
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
24 from libervia.backend.core import exceptions |
|
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
25 from libervia.backend.core.log import getLogger |
|
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
26 from libervia.backend.core.core_types import SatXMPPEntity |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
27 |
|
941
c6d8fc63b1db
core, plugins: host.getClient now raise an exception instead of returning None when no profile is found, plugins have been adapted consequently and a bit cleaned
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
28 from twisted.words.protocols.jabber import jid |
|
973
4a8903021fda
core (disco): findFeaturesSet and findServiceEntities don't use inlineCallbacks anymore, that allow a better error management (no more anonying debugger raise when discoInfo fails in debug mode)
Goffi <goffi@goffi.org>
parents:
963
diff
changeset
|
29 from twisted.words.protocols.jabber.error import StanzaError |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
30 from twisted.internet import defer |
|
1189
7d640c303140
core (disco): added a timeout to get items
Goffi <goffi@goffi.org>
parents:
993
diff
changeset
|
31 from twisted.internet import reactor |
|
1493
1285c714a6cc
core (disco): use of failure.Failure when raising FeatureNotFound to avoid a jump in debugger in debug mode
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
32 from twisted.python import failure |
|
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
33 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
|
34 from libervia.backend.tools import xml_tools |
|
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
35 from libervia.backend.memory import persistent |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
36 from wokkel import disco |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
37 from base64 import b64encode |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
38 from hashlib import sha1 |
|
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 |
|
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
|
3718
16e36f0dd1cb
memory (disco), core (main): new `hasIdentity` method
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
41 log = getLogger(__name__) |
|
16e36f0dd1cb
memory (disco), core (main): new `hasIdentity` method
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
42 |
|
16e36f0dd1cb
memory (disco), core (main): new `hasIdentity` method
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
43 |
|
1189
7d640c303140
core (disco): added a timeout to get items
Goffi <goffi@goffi.org>
parents:
993
diff
changeset
|
44 TIMEOUT = 15 |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
45 CAP_HASH_ERROR = "ERROR" |
|
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
46 |
|
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 |
|
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 class HashGenerationError(Exception): |
|
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 pass |
|
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 |
|
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
51 |
|
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 class ByteIdentity(object): |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
53 """This class manage identity as bytes (needed for i;octet sort), it is used for the hash generation""" |
|
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 |
|
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 def __init__(self, identity, lang=None): |
|
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 assert isinstance(identity, disco.DiscoIdentity) |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
57 self.category = identity.category.encode("utf-8") |
|
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
58 self.idType = identity.type.encode("utf-8") |
| 3028 | 59 self.name = identity.name.encode("utf-8") if identity.name else b"" |
| 60 self.lang = lang.encode("utf-8") if lang is not None else b"" | |
|
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 |
| 3028 | 62 def __bytes__(self): |
| 63 return b"%s/%s/%s/%s" % (self.category, self.idType, self.lang, self.name) | |
|
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
64 |
|
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 |
|
1684
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
66 class HashManager(object): |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
67 """map object which manage hashes |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
68 |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
69 persistent storage is update when a new hash is added |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
70 """ |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
71 |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
72 def __init__(self, persistent): |
|
1752
cbcc223c323a
core (disco): display a warning when a disco info/items request failed, and return empty DiscoInfo/DiscoITems
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
73 self.hashes = { |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
74 CAP_HASH_ERROR: disco.DiscoInfo() # used when we can't get disco infos |
|
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
75 } |
|
1684
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
76 self.persistent = persistent |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
77 |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
78 def __getitem__(self, key): |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
79 return self.hashes[key] |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
80 |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
81 def __setitem__(self, hash_, disco_info): |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
82 if hash_ in self.hashes: |
| 3028 | 83 log.debug("ignoring hash set: it is already known") |
|
1684
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
84 return |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
85 self.hashes[hash_] = disco_info |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
86 self.persistent[hash_] = disco_info.toElement().toXml() |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
87 |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
88 def __contains__(self, hash_): |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
89 return self.hashes.__contains__(hash_) |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
90 |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
91 def load(self): |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
92 def fill_hashes(hashes): |
| 3028 | 93 for hash_, xml in hashes.items(): |
|
1684
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
94 element = xml_tools.ElementParser()(xml) |
|
2587
e70023e84974
core (disco): fixed disco capabilities (empty disco was used)
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
95 disco_info = disco.DiscoInfo.fromElement(element) |
|
3250
e4d3ba75b1b2
core (memory/disco): fixed types of disco extensions:
Goffi <goffi@goffi.org>
parents:
3194
diff
changeset
|
96 for ext_form in disco_info.extensions.values(): |
|
e4d3ba75b1b2
core (memory/disco): fixed types of disco extensions:
Goffi <goffi@goffi.org>
parents:
3194
diff
changeset
|
97 # wokkel doesn't call typeCheck on reception, so we do it here |
|
e4d3ba75b1b2
core (memory/disco): fixed types of disco extensions:
Goffi <goffi@goffi.org>
parents:
3194
diff
changeset
|
98 ext_form.typeCheck() |
|
2587
e70023e84974
core (disco): fixed disco capabilities (empty disco was used)
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
99 if not disco_info.features and not disco_info.identities: |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
100 log.warning( |
|
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
101 _( |
| 3028 | 102 "no feature/identity found in disco element (hash: {cap_hash}), ignoring: {xml}" |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
103 ).format(cap_hash=hash_, xml=xml) |
|
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
104 ) |
|
2587
e70023e84974
core (disco): fixed disco capabilities (empty disco was used)
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
105 else: |
|
e70023e84974
core (disco): fixed disco capabilities (empty disco was used)
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
106 self.hashes[hash_] = disco_info |
|
e70023e84974
core (disco): fixed disco capabilities (empty disco was used)
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
107 |
| 3028 | 108 log.info("Disco hashes loaded") |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
109 |
|
1684
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
110 d = self.persistent.load() |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
111 d.addCallback(fill_hashes) |
|
1684
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
112 return d |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
113 |
|
1752
cbcc223c323a
core (disco): display a warning when a disco info/items request failed, and return empty DiscoInfo/DiscoITems
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
114 |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
115 class Discovery(object): |
|
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
116 """Manage capabilities of entities""" |
|
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 |
|
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 def __init__(self, host): |
|
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 self.host = host |
|
1684
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
120 # TODO: remove legacy hashes |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
121 |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
122 def load(self): |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
123 """Load persistent hashes""" |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
124 self.hashes = HashManager(persistent.PersistentDict("disco")) |
|
373ce871b0f3
core (disco): disco hashes are now stored in database to avoid doing the same disco request on next load
Goffi <goffi@goffi.org>
parents:
1675
diff
changeset
|
125 return self.hashes.load() |
|
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 |
|
4306
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
127 async def has_feature( |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
128 self, |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
129 client: SatXMPPEntity, |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
130 feature: str, |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
131 jid_: jid.JID | None = None, |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
132 node: str = "", |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
133 ) -> bool: |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
134 """Tell if an entity has the required feature |
|
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
135 |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
136 @param feature: feature namespace |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
137 @param jid_: jid of the target, or None for profile's server |
|
4327
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4306
diff
changeset
|
138 @param node: optional node to use for disco request |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
139 @return: a Deferred which fire a boolean (True if feature is available) |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
140 """ |
|
4306
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
141 disco_infos = await self.get_infos(client, jid_, node) |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
142 return feature in disco_infos.features |
|
951
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
143 |
|
4306
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
144 async def check_feature( |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
145 self, |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
146 client: SatXMPPEntity, |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
147 feature: str, |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
148 jid_: jid.JID | None = None, |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
149 node: str = "", |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
150 ) -> None: |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
151 """Like has_feature, but raise an exception is feature is not Found |
|
951
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
152 |
|
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
153 @param feature: feature namespace |
|
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
154 @param jid_: jid of the target, or None for profile's server |
|
4306
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
155 @param node: optional node to use for disco request |
|
951
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
156 |
|
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
157 @raise: exceptions.FeatureNotFound |
|
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
158 """ |
|
4306
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
159 disco_infos = await self.get_infos(client, jid_, node) |
|
973
4a8903021fda
core (disco): findFeaturesSet and findServiceEntities don't use inlineCallbacks anymore, that allow a better error management (no more anonying debugger raise when discoInfo fails in debug mode)
Goffi <goffi@goffi.org>
parents:
963
diff
changeset
|
160 if not feature in disco_infos.features: |
|
4306
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
161 raise exceptions.FeatureNotFound() |
|
1491
704ca56f5ca9
core (disco): added checkFeatures to check several features at once + identities are now managed with a tuple in findFeaturesSet and checkFeatures
Goffi <goffi@goffi.org>
parents:
1484
diff
changeset
|
162 |
|
4306
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
163 async def check_features( |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
164 self, |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
165 client: SatXMPPEntity, |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
166 features: Iterable[str], |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
167 jid_: jid.JID | None = None, |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
168 identity: tuple[str, str] | None = None, |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
169 node: str = "", |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
170 ) -> None: |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
171 """Like check_feature, but check several features at once, and check also identity |
|
1491
704ca56f5ca9
core (disco): added checkFeatures to check several features at once + identities are now managed with a tuple in findFeaturesSet and checkFeatures
Goffi <goffi@goffi.org>
parents:
1484
diff
changeset
|
172 |
|
4306
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
173 @param features: features to check |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
174 @param jid_: jid of the target, or None for profile's server |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
175 @param node: optional node to use for disco request |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
176 @param identity: if not None, the entity must have an identity with this |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
177 (category, type) tuple |
|
1491
704ca56f5ca9
core (disco): added checkFeatures to check several features at once + identities are now managed with a tuple in findFeaturesSet and checkFeatures
Goffi <goffi@goffi.org>
parents:
1484
diff
changeset
|
178 |
|
704ca56f5ca9
core (disco): added checkFeatures to check several features at once + identities are now managed with a tuple in findFeaturesSet and checkFeatures
Goffi <goffi@goffi.org>
parents:
1484
diff
changeset
|
179 @raise: exceptions.FeatureNotFound |
|
704ca56f5ca9
core (disco): added checkFeatures to check several features at once + identities are now managed with a tuple in findFeaturesSet and checkFeatures
Goffi <goffi@goffi.org>
parents:
1484
diff
changeset
|
180 """ |
|
4306
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
181 disco_infos = await self.get_infos(client, jid_, node) |
|
1491
704ca56f5ca9
core (disco): added checkFeatures to check several features at once + identities are now managed with a tuple in findFeaturesSet and checkFeatures
Goffi <goffi@goffi.org>
parents:
1484
diff
changeset
|
182 if not set(features).issubset(disco_infos.features): |
|
4306
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
183 raise exceptions.FeatureNotFound() |
|
1491
704ca56f5ca9
core (disco): added checkFeatures to check several features at once + identities are now managed with a tuple in findFeaturesSet and checkFeatures
Goffi <goffi@goffi.org>
parents:
1484
diff
changeset
|
184 |
|
704ca56f5ca9
core (disco): added checkFeatures to check several features at once + identities are now managed with a tuple in findFeaturesSet and checkFeatures
Goffi <goffi@goffi.org>
parents:
1484
diff
changeset
|
185 if identity is not None and identity not in disco_infos.identities: |
|
4306
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
186 raise exceptions.FeatureNotFound() |
|
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
188 async def has_identity( |
|
3718
16e36f0dd1cb
memory (disco), core (main): new `hasIdentity` method
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
189 self, |
|
16e36f0dd1cb
memory (disco), core (main): new `hasIdentity` method
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
190 client: SatXMPPEntity, |
|
16e36f0dd1cb
memory (disco), core (main): new `hasIdentity` method
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
191 category: str, |
|
16e36f0dd1cb
memory (disco), core (main): new `hasIdentity` method
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
192 type_: str, |
|
16e36f0dd1cb
memory (disco), core (main): new `hasIdentity` method
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
193 jid_: Optional[jid.JID] = None, |
|
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
194 node: str = "", |
|
3718
16e36f0dd1cb
memory (disco), core (main): new `hasIdentity` method
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
195 ) -> bool: |
|
16e36f0dd1cb
memory (disco), core (main): new `hasIdentity` method
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
196 """Tell if an entity has the requested identity |
|
16e36f0dd1cb
memory (disco), core (main): new `hasIdentity` method
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
197 |
|
16e36f0dd1cb
memory (disco), core (main): new `hasIdentity` method
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
198 @param category: identity category |
|
16e36f0dd1cb
memory (disco), core (main): new `hasIdentity` method
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
199 @param type_: identity type |
|
16e36f0dd1cb
memory (disco), core (main): new `hasIdentity` method
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
200 @param jid_: jid of the target, or None for profile's server |
|
16e36f0dd1cb
memory (disco), core (main): new `hasIdentity` method
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
201 @param node(unicode): optional node to use for disco request |
|
16e36f0dd1cb
memory (disco), core (main): new `hasIdentity` method
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
202 @return: True if the entity has the given identity |
|
16e36f0dd1cb
memory (disco), core (main): new `hasIdentity` method
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
203 """ |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
204 disco_infos = await self.get_infos(client, jid_, node) |
|
3718
16e36f0dd1cb
memory (disco), core (main): new `hasIdentity` method
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
205 return (category, type_) in disco_infos.identities |
|
16e36f0dd1cb
memory (disco), core (main): new `hasIdentity` method
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
206 |
|
4342
17fa953c8cd7
core (types): improve `SatXMPPEntity` core type and type hints.
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
207 def get_infos( |
|
17fa953c8cd7
core (types): improve `SatXMPPEntity` core type and type hints.
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
208 self, |
|
17fa953c8cd7
core (types): improve `SatXMPPEntity` core type and type hints.
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
209 client: SatXMPPEntity, |
|
17fa953c8cd7
core (types): improve `SatXMPPEntity` core type and type hints.
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
210 jid_: jid.JID|None=None, |
|
17fa953c8cd7
core (types): improve `SatXMPPEntity` core type and type hints.
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
211 node: str="", |
|
17fa953c8cd7
core (types): improve `SatXMPPEntity` core type and type hints.
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
212 use_cache: bool=True |
|
17fa953c8cd7
core (types): improve `SatXMPPEntity` core type and type hints.
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
213 ) -> defer.Deferred[disco.DiscoInfo]: |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
214 """get disco infos from jid_, filling capability hash if needed |
|
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
215 |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
216 @param jid_: jid of the target, or None for profile's server |
|
4342
17fa953c8cd7
core (types): improve `SatXMPPEntity` core type and type hints.
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
217 @param node: optional node to use for disco request |
|
17fa953c8cd7
core (types): improve `SatXMPPEntity` core type and type hints.
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
218 @param use_cache: if True, use cached data if available |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
219 @return: a Deferred which fire disco.DiscoInfo |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
220 """ |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
221 if jid_ is None: |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
222 jid_ = jid.JID(client.jid.host) |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
223 try: |
|
2342
f047d5410040
core (memory/disco): added use_cache parameter to discoInfos/discoItems (set to False to ignore cache)
Goffi <goffi@goffi.org>
parents:
2150
diff
changeset
|
224 if not use_cache: |
|
f047d5410040
core (memory/disco): added use_cache parameter to discoInfos/discoItems (set to False to ignore cache)
Goffi <goffi@goffi.org>
parents:
2150
diff
changeset
|
225 # we ignore cache, so we pretend we haven't found it |
|
f047d5410040
core (memory/disco): added use_cache parameter to discoInfos/discoItems (set to False to ignore cache)
Goffi <goffi@goffi.org>
parents:
2150
diff
changeset
|
226 raise KeyError |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
227 cap_hash = self.host.memory.entity_data_get( |
|
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3250
diff
changeset
|
228 client, jid_, [C.ENTITY_CAP_HASH] |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
229 )[C.ENTITY_CAP_HASH] |
|
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1216
diff
changeset
|
230 except (KeyError, exceptions.UnknownEntityError): |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
231 # capability hash is not available, we'll compute one |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
232 def infos_cb(disco_infos): |
|
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
233 cap_hash = self.generate_hash(disco_infos) |
|
3250
e4d3ba75b1b2
core (memory/disco): fixed types of disco extensions:
Goffi <goffi@goffi.org>
parents:
3194
diff
changeset
|
234 for ext_form in disco_infos.extensions.values(): |
|
e4d3ba75b1b2
core (memory/disco): fixed types of disco extensions:
Goffi <goffi@goffi.org>
parents:
3194
diff
changeset
|
235 # wokkel doesn't call typeCheck on reception, so we do it here |
|
e4d3ba75b1b2
core (memory/disco): fixed types of disco extensions:
Goffi <goffi@goffi.org>
parents:
3194
diff
changeset
|
236 # to avoid ending up with incorrect types. We have to do it after |
|
e4d3ba75b1b2
core (memory/disco): fixed types of disco extensions:
Goffi <goffi@goffi.org>
parents:
3194
diff
changeset
|
237 # the hash has been generated (str value is needed to compute the |
|
e4d3ba75b1b2
core (memory/disco): fixed types of disco extensions:
Goffi <goffi@goffi.org>
parents:
3194
diff
changeset
|
238 # hash) |
|
e4d3ba75b1b2
core (memory/disco): fixed types of disco extensions:
Goffi <goffi@goffi.org>
parents:
3194
diff
changeset
|
239 ext_form.typeCheck() |
|
973
4a8903021fda
core (disco): findFeaturesSet and findServiceEntities don't use inlineCallbacks anymore, that allow a better error management (no more anonying debugger raise when discoInfo fails in debug mode)
Goffi <goffi@goffi.org>
parents:
963
diff
changeset
|
240 self.hashes[cap_hash] = disco_infos |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
241 self.host.memory.update_entity_data( |
|
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3250
diff
changeset
|
242 client, jid_, C.ENTITY_CAP_HASH, cap_hash |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
243 ) |
|
973
4a8903021fda
core (disco): findFeaturesSet and findServiceEntities don't use inlineCallbacks anymore, that allow a better error management (no more anonying debugger raise when discoInfo fails in debug mode)
Goffi <goffi@goffi.org>
parents:
963
diff
changeset
|
244 return disco_infos |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
245 |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
246 def infos_eb(fail): |
|
1752
cbcc223c323a
core (disco): display a warning when a disco info/items request failed, and return empty DiscoInfo/DiscoITems
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
247 if fail.check(defer.CancelledError): |
| 3028 | 248 reason = "request time-out" |
|
3152
7ce31f347ca3
core (memory/disco): fixed failure creation in infosEb
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
249 fail = failure.Failure(exceptions.TimeOutError(str(fail.value))) |
|
1752
cbcc223c323a
core (disco): display a warning when a disco info/items request failed, and return empty DiscoInfo/DiscoITems
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
250 else: |
|
cbcc223c323a
core (disco): display a warning when a disco info/items request failed, and return empty DiscoInfo/DiscoITems
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
251 try: |
| 3028 | 252 reason = str(fail.value) |
|
1752
cbcc223c323a
core (disco): display a warning when a disco info/items request failed, and return empty DiscoInfo/DiscoITems
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
253 except AttributeError: |
| 3028 | 254 reason = str(fail) |
|
2768
cb34af35af6f
core (disco): client.disco.requestInfo failure are re-raised:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
255 |
|
cb34af35af6f
core (disco): client.disco.requestInfo failure are re-raised:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
256 log.warning( |
|
3194
12486cd4fa8b
core (memory/disco): minor log message change
Goffi <goffi@goffi.org>
parents:
3156
diff
changeset
|
257 "can't request disco infos from {jid}: {reason}".format( |
|
2768
cb34af35af6f
core (disco): client.disco.requestInfo failure are re-raised:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
258 jid=jid_.full(), reason=reason |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
259 ) |
|
2768
cb34af35af6f
core (disco): client.disco.requestInfo failure are re-raised:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
260 ) |
|
cb34af35af6f
core (disco): client.disco.requestInfo failure are re-raised:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
261 |
|
cb34af35af6f
core (disco): client.disco.requestInfo failure are re-raised:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
262 # XXX we set empty disco in cache, to avoid getting an error or waiting |
|
cb34af35af6f
core (disco): client.disco.requestInfo failure are re-raised:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
263 # for a timeout again the next time |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
264 self.host.memory.update_entity_data( |
|
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3250
diff
changeset
|
265 client, jid_, C.ENTITY_CAP_HASH, CAP_HASH_ERROR |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
266 ) |
|
2768
cb34af35af6f
core (disco): client.disco.requestInfo failure are re-raised:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
267 raise fail |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
268 |
|
2148
a543eda2c923
core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents:
2096
diff
changeset
|
269 d = client.disco.requestInfo(jid_, nodeIdentifier=node) |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
270 d.addCallback(infos_cb) |
|
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
271 d.addErrback(infos_eb) |
|
973
4a8903021fda
core (disco): findFeaturesSet and findServiceEntities don't use inlineCallbacks anymore, that allow a better error management (no more anonying debugger raise when discoInfo fails in debug mode)
Goffi <goffi@goffi.org>
parents:
963
diff
changeset
|
272 return d |
|
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1216
diff
changeset
|
273 else: |
|
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1216
diff
changeset
|
274 disco_infos = self.hashes[cap_hash] |
|
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1216
diff
changeset
|
275 return defer.succeed(disco_infos) |
|
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
276 |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
277 @defer.inlineCallbacks |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
278 def get_items(self, client, jid_=None, node="", use_cache=True): |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
279 """get disco items from jid_, cache them for our own server |
|
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
280 |
|
2148
a543eda2c923
core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents:
2096
diff
changeset
|
281 @param jid_(jid.JID): jid of the target, or None for profile's server |
|
a543eda2c923
core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents:
2096
diff
changeset
|
282 @param node(unicode): optional node to use for disco request |
|
2342
f047d5410040
core (memory/disco): added use_cache parameter to discoInfos/discoItems (set to False to ignore cache)
Goffi <goffi@goffi.org>
parents:
2150
diff
changeset
|
283 @param use_cache(bool): if True, use cached data if available |
|
963
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
284 @return: a Deferred which fire disco.DiscoItems |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
285 """ |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
286 if jid_ is None: |
|
3750
193b56ef58e0
core (disco): use new `client.server_jid` property in `getItems`
Goffi <goffi@goffi.org>
parents:
3718
diff
changeset
|
287 jid_ = client.server_jid |
|
2407
cf9b276f4a08
core (disco): do not cache disco items when node is set
Goffi <goffi@goffi.org>
parents:
2342
diff
changeset
|
288 |
|
3750
193b56ef58e0
core (disco): use new `client.server_jid` property in `getItems`
Goffi <goffi@goffi.org>
parents:
3718
diff
changeset
|
289 if jid_ == client.server_jid and not node: |
|
2407
cf9b276f4a08
core (disco): do not cache disco items when node is set
Goffi <goffi@goffi.org>
parents:
2342
diff
changeset
|
290 # we cache items only for our own server and if node is not set |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
291 try: |
|
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
292 items = self.host.memory.entity_data_get(client, jid_, ["DISCO_ITEMS"])[ |
|
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
293 "DISCO_ITEMS" |
|
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
294 ] |
| 3028 | 295 log.debug("[%s] disco items are in cache" % jid_.full()) |
|
2342
f047d5410040
core (memory/disco): added use_cache parameter to discoInfos/discoItems (set to False to ignore cache)
Goffi <goffi@goffi.org>
parents:
2150
diff
changeset
|
296 if not use_cache: |
|
f047d5410040
core (memory/disco): added use_cache parameter to discoInfos/discoItems (set to False to ignore cache)
Goffi <goffi@goffi.org>
parents:
2150
diff
changeset
|
297 # we ignore cache, so we pretend we haven't found it |
|
f047d5410040
core (memory/disco): added use_cache parameter to discoInfos/discoItems (set to False to ignore cache)
Goffi <goffi@goffi.org>
parents:
2150
diff
changeset
|
298 raise KeyError |
|
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1216
diff
changeset
|
299 except (KeyError, exceptions.UnknownEntityError): |
| 3028 | 300 log.debug("Caching [%s] disco items" % jid_.full()) |
|
2148
a543eda2c923
core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents:
2096
diff
changeset
|
301 items = yield client.disco.requestItems(jid_, nodeIdentifier=node) |
|
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
302 self.host.memory.update_entity_data(client, jid_, "DISCO_ITEMS", items) |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
303 else: |
|
1752
cbcc223c323a
core (disco): display a warning when a disco info/items request failed, and return empty DiscoInfo/DiscoITems
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
304 try: |
|
2148
a543eda2c923
core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents:
2096
diff
changeset
|
305 items = yield client.disco.requestItems(jid_, nodeIdentifier=node) |
|
1752
cbcc223c323a
core (disco): display a warning when a disco info/items request failed, and return empty DiscoInfo/DiscoITems
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
306 except StanzaError as e: |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
307 log.warning( |
| 3028 | 308 "Error while requesting items for {jid}: {reason}".format( |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
309 jid=jid_.full(), reason=e.condition |
|
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
310 ) |
|
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
311 ) |
|
1752
cbcc223c323a
core (disco): display a warning when a disco info/items request failed, and return empty DiscoInfo/DiscoITems
Goffi <goffi@goffi.org>
parents:
1684
diff
changeset
|
312 items = disco.DiscoItems() |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
313 |
|
4341
e9971a4b0627
remove uses of twisted.internet.defer.returnValue
Povilas Kanapickas <povilas@radix.lt>
parents:
4327
diff
changeset
|
314 return items |
|
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
315 |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
316 def _infos_eb(self, failure_, entity_jid): |
|
1493
1285c714a6cc
core (disco): use of failure.Failure when raising FeatureNotFound to avoid a jump in debugger in debug mode
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
317 failure_.trap(StanzaError) |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
318 log.warning( |
| 3028 | 319 _("Error while requesting [%(jid)s]: %(error)s") |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
320 % {"jid": entity_jid.full(), "error": failure_.getErrorMessage()} |
|
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
321 ) |
|
973
4a8903021fda
core (disco): findFeaturesSet and findServiceEntities don't use inlineCallbacks anymore, that allow a better error management (no more anonying debugger raise when discoInfo fails in debug mode)
Goffi <goffi@goffi.org>
parents:
963
diff
changeset
|
322 |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
323 def find_service_entity(self, client, category, type_, jid_=None): |
|
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
324 """Helper method to find first available entity from find_service_entities |
|
2431
a9fac72825a2
memory (disco): added findServiceEntity helper method to get first service of a kind
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
325 |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
326 args are the same as for [find_service_entities] |
|
2431
a9fac72825a2
memory (disco): added findServiceEntity helper method to get first service of a kind
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
327 @return (jid.JID, None): found entity |
|
a9fac72825a2
memory (disco): added findServiceEntity helper method to get first service of a kind
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
328 """ |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
329 d = self.host.find_service_entities(client, category, type_) |
|
2431
a9fac72825a2
memory (disco): added findServiceEntity helper method to get first service of a kind
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
330 d.addCallback(lambda entities: entities.pop() if entities else None) |
|
a9fac72825a2
memory (disco): added findServiceEntity helper method to get first service of a kind
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
331 return d |
|
a9fac72825a2
memory (disco): added findServiceEntity helper method to get first service of a kind
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
332 |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
333 def find_service_entities(self, client, category, type_, jid_=None): |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
334 """Return all available items of an entity which correspond to (category, type_) |
|
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
335 |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
336 @param category: identity's category |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
337 @param type_: identitiy's type |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
338 @param jid_: the jid of the target server (None for profile's server) |
|
1460
c7fd121a6180
core: getProfileName no raise ProfileUnknownError + minor doc fixes
Goffi <goffi@goffi.org>
parents:
1416
diff
changeset
|
339 @return: a set of found entities |
|
1675
fd143578fe89
plugin XEP-0065: fixed bad error handling
Goffi <goffi@goffi.org>
parents:
1552
diff
changeset
|
340 @raise defer.CancelledError: the request timed out |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
341 """ |
|
973
4a8903021fda
core (disco): findFeaturesSet and findServiceEntities don't use inlineCallbacks anymore, that allow a better error management (no more anonying debugger raise when discoInfo fails in debug mode)
Goffi <goffi@goffi.org>
parents:
963
diff
changeset
|
342 found_entities = set() |
|
4a8903021fda
core (disco): findFeaturesSet and findServiceEntities don't use inlineCallbacks anymore, that allow a better error management (no more anonying debugger raise when discoInfo fails in debug mode)
Goffi <goffi@goffi.org>
parents:
963
diff
changeset
|
343 |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
344 def infos_cb(infos, entity_jid): |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
345 if (category, type_) in infos.identities: |
|
973
4a8903021fda
core (disco): findFeaturesSet and findServiceEntities don't use inlineCallbacks anymore, that allow a better error management (no more anonying debugger raise when discoInfo fails in debug mode)
Goffi <goffi@goffi.org>
parents:
963
diff
changeset
|
346 found_entities.add(entity_jid) |
|
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
347 |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
348 def got_items(items): |
|
973
4a8903021fda
core (disco): findFeaturesSet and findServiceEntities don't use inlineCallbacks anymore, that allow a better error management (no more anonying debugger raise when discoInfo fails in debug mode)
Goffi <goffi@goffi.org>
parents:
963
diff
changeset
|
349 defers_list = [] |
|
4a8903021fda
core (disco): findFeaturesSet and findServiceEntities don't use inlineCallbacks anymore, that allow a better error management (no more anonying debugger raise when discoInfo fails in debug mode)
Goffi <goffi@goffi.org>
parents:
963
diff
changeset
|
350 for item in items: |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
351 info_d = self.get_infos(client, item.entity) |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
352 info_d.addCallbacks( |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
353 infos_cb, self._infos_eb, [item.entity], None, [item.entity] |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
354 ) |
|
973
4a8903021fda
core (disco): findFeaturesSet and findServiceEntities don't use inlineCallbacks anymore, that allow a better error management (no more anonying debugger raise when discoInfo fails in debug mode)
Goffi <goffi@goffi.org>
parents:
963
diff
changeset
|
355 defers_list.append(info_d) |
|
4a8903021fda
core (disco): findFeaturesSet and findServiceEntities don't use inlineCallbacks anymore, that allow a better error management (no more anonying debugger raise when discoInfo fails in debug mode)
Goffi <goffi@goffi.org>
parents:
963
diff
changeset
|
356 return defer.DeferredList(defers_list) |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
357 |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
358 d = self.get_items(client, jid_) |
|
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
359 d.addCallback(got_items) |
|
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2712
diff
changeset
|
360 d.addCallback(lambda __: found_entities) |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
361 reactor.callLater( |
|
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
362 TIMEOUT, d.cancel |
|
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
363 ) # FIXME: one bad service make a general timeout |
|
973
4a8903021fda
core (disco): findFeaturesSet and findServiceEntities don't use inlineCallbacks anymore, that allow a better error management (no more anonying debugger raise when discoInfo fails in debug mode)
Goffi <goffi@goffi.org>
parents:
963
diff
changeset
|
364 return d |
|
4a8903021fda
core (disco): findFeaturesSet and findServiceEntities don't use inlineCallbacks anymore, that allow a better error management (no more anonying debugger raise when discoInfo fails in debug mode)
Goffi <goffi@goffi.org>
parents:
963
diff
changeset
|
365 |
|
4306
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
366 async def find_features_set( |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
367 self, |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
368 client: SatXMPPEntity, |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
369 features: Iterable[str], |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
370 identity: tuple[str, str] | None = None, |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
371 jid_: jid.JID | None = None, |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
372 ) -> set[jid.JID]: |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
373 """Return entities (including jid_ and its items) offering features |
|
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
374 |
|
4306
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
375 @param client: Client session. |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
376 @param features: iterable of features which must be present |
|
4306
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
377 @param identity: if not None, accept only this (category/type) identity |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
378 @param jid_: the jid of the target server (None for profile's server) |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
379 @return: a set of found entities |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
380 """ |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
381 if jid_ is None: |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
382 jid_ = jid.JID(client.jid.host) |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
383 features = set(features) |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
384 found_entities = set() |
|
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
385 |
|
4306
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
386 def infos_cb(infos: disco.DiscoInfo, entity: jid.JID) -> None: |
|
2533
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
387 if entity is None: |
|
4306
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
388 log.warning(_("Received an item without JID")) |
|
2533
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
389 return |
|
1491
704ca56f5ca9
core (disco): added checkFeatures to check several features at once + identities are now managed with a tuple in findFeaturesSet and checkFeatures
Goffi <goffi@goffi.org>
parents:
1484
diff
changeset
|
390 if identity is not None and identity not in infos.identities: |
|
704ca56f5ca9
core (disco): added checkFeatures to check several features at once + identities are now managed with a tuple in findFeaturesSet and checkFeatures
Goffi <goffi@goffi.org>
parents:
1484
diff
changeset
|
391 return |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
392 if features.issubset(infos.features): |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
393 found_entities.add(entity) |
|
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
394 |
|
4306
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
395 items = await self.get_items(client, jid_) |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
396 defer_list = [] |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
397 for entity in [jid_] + [item.entity for item in items]: |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
398 infos_d = self.get_infos(client, entity) |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
399 infos_d.addCallbacks(infos_cb, self._infos_eb, [entity], None, [entity]) |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
400 infos_d.addTimeout(TIMEOUT, cast(IReactorCore, reactor)) |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
401 defer_list.append(infos_d) |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
402 await defer.DeferredList(defer_list) |
|
94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
403 return found_entities |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
404 |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
405 def generate_hash(self, services): |
|
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
406 """Generate a unique hash for given service |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
407 |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
408 hash algorithm is the one described in XEP-0115 |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
409 @param services: iterable of disco.DiscoIdentity/disco.DiscoFeature, as returned by discoHandler.info |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
410 |
|
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
411 """ |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
412 s = [] |
|
2830
770ec685ff1f
core (disco): added missing disco extensions when generating the cap hash.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
413 # identities |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
414 byte_identities = [ |
|
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
415 ByteIdentity(service) |
|
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
416 for service in services |
|
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
417 if isinstance(service, disco.DiscoIdentity) |
|
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
418 ] # FIXME: lang must be managed here |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
419 byte_identities.sort(key=lambda i: i.lang) |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
420 byte_identities.sort(key=lambda i: i.idType) |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
421 byte_identities.sort(key=lambda i: i.category) |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
422 for identity in byte_identities: |
| 3028 | 423 s.append(bytes(identity)) |
| 424 s.append(b"<") | |
|
2830
770ec685ff1f
core (disco): added missing disco extensions when generating the cap hash.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
425 # features |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
426 byte_features = [ |
|
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
427 service.encode("utf-8") |
|
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
428 for service in services |
|
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
429 if isinstance(service, disco.DiscoFeature) |
|
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
430 ] |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
431 byte_features.sort() # XXX: the default sort has the same behaviour as the requested RFC 4790 i;octet sort |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
432 for feature in byte_features: |
|
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
433 s.append(feature) |
| 3028 | 434 s.append(b"<") |
|
2830
770ec685ff1f
core (disco): added missing disco extensions when generating the cap hash.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
435 |
|
770ec685ff1f
core (disco): added missing disco extensions when generating the cap hash.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
436 # extensions |
| 3028 | 437 ext = list(services.extensions.values()) |
|
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
438 ext.sort(key=lambda f: f.formNamespace.encode("utf-8")) |
|
2830
770ec685ff1f
core (disco): added missing disco extensions when generating the cap hash.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
439 for extension in ext: |
|
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
440 s.append(extension.formNamespace.encode("utf-8")) |
| 3028 | 441 s.append(b"<") |
|
2830
770ec685ff1f
core (disco): added missing disco extensions when generating the cap hash.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
442 fields = extension.fieldList |
|
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
443 fields.sort(key=lambda f: f.var.encode("utf-8")) |
|
2830
770ec685ff1f
core (disco): added missing disco extensions when generating the cap hash.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
444 for field in fields: |
|
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
445 s.append(field.var.encode("utf-8")) |
| 3028 | 446 s.append(b"<") |
|
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
447 values = [v.encode("utf-8") for v in field.values] |
|
2830
770ec685ff1f
core (disco): added missing disco extensions when generating the cap hash.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
448 values.sort() |
|
770ec685ff1f
core (disco): added missing disco extensions when generating the cap hash.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
449 for value in values: |
|
770ec685ff1f
core (disco): added missing disco extensions when generating the cap hash.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
450 s.append(value) |
| 3028 | 451 s.append(b"<") |
|
2830
770ec685ff1f
core (disco): added missing disco extensions when generating the cap hash.
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
452 |
|
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
453 cap_hash = b64encode(sha1(b"".join(s)).digest()).decode("utf-8") |
| 3028 | 454 log.debug(_("Capability hash generated: [{cap_hash}]").format(cap_hash=cap_hash)) |
|
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
455 return cap_hash |
|
963
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
456 |
|
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
457 @defer.inlineCallbacks |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
458 def _disco_infos( |
| 3028 | 459 self, entity_jid_s, node="", use_cache=True, profile_key=C.PROF_KEY_NONE |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
460 ): |
|
3250
e4d3ba75b1b2
core (memory/disco): fixed types of disco extensions:
Goffi <goffi@goffi.org>
parents:
3194
diff
changeset
|
461 """Discovery method for the bridge |
|
963
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
462 @param entity_jid_s: entity we want to discover |
|
2342
f047d5410040
core (memory/disco): added use_cache parameter to discoInfos/discoItems (set to False to ignore cache)
Goffi <goffi@goffi.org>
parents:
2150
diff
changeset
|
463 @param use_cache(bool): if True, use cached data if available |
|
2150
91347fe95384
core(memory.disco), bridge: discoInfos and discoItems now handle node
Goffi <goffi@goffi.org>
parents:
2148
diff
changeset
|
464 @param node(unicode): optional node to use |
|
963
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
465 |
|
1552
e0bde0d0b321
core (disco): use of “profile” instead of “profile_key” in several disco methods
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
466 @return: list of tuples |
|
e0bde0d0b321
core (disco): use of “profile” instead of “profile_key” in several disco methods
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
467 """ |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
468 client = self.host.get_client(profile_key) |
|
963
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
469 entity = jid.JID(entity_jid_s) |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
470 disco_infos = yield self.get_infos(client, entity, node, use_cache) |
|
1414
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
471 extensions = {} |
|
2712
c3f59c1dcb0a
core (memory/disco): normalise booleans in extensions
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
472 # FIXME: should extensions be serialised using tools.common.data_format? |
| 3028 | 473 for form_type, form in list(disco_infos.extensions.items()): |
|
1414
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
474 fields = [] |
|
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
475 for field in form.fieldList: |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
476 data = {"type": field.fieldType} |
|
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
477 for attr in ("var", "label", "desc"): |
|
1414
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
478 value = getattr(field, attr) |
|
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
479 if value is not None: |
|
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
480 data[attr] = value |
|
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
481 |
|
1416
a419da93afef
core (disco): fixed bad indentation in _discoInfos (used by bridge)
Goffi <goffi@goffi.org>
parents:
1414
diff
changeset
|
482 values = [field.value] if field.value is not None else field.values |
| 3028 | 483 if field.fieldType == "boolean": |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
484 values = [C.bool_const(v) for v in values] |
|
1416
a419da93afef
core (disco): fixed bad indentation in _discoInfos (used by bridge)
Goffi <goffi@goffi.org>
parents:
1414
diff
changeset
|
485 fields.append((data, values)) |
|
1414
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
486 |
|
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
487 extensions[form_type or ""] = fields |
|
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
488 |
|
4341
e9971a4b0627
remove uses of twisted.internet.defer.returnValue
Povilas Kanapickas <povilas@radix.lt>
parents:
4327
diff
changeset
|
489 return ( |
|
e9971a4b0627
remove uses of twisted.internet.defer.returnValue
Povilas Kanapickas <povilas@radix.lt>
parents:
4327
diff
changeset
|
490 [str(f) for f in disco_infos.features], |
|
e9971a4b0627
remove uses of twisted.internet.defer.returnValue
Povilas Kanapickas <povilas@radix.lt>
parents:
4327
diff
changeset
|
491 [ |
|
e9971a4b0627
remove uses of twisted.internet.defer.returnValue
Povilas Kanapickas <povilas@radix.lt>
parents:
4327
diff
changeset
|
492 (cat, type_, name or "") |
|
e9971a4b0627
remove uses of twisted.internet.defer.returnValue
Povilas Kanapickas <povilas@radix.lt>
parents:
4327
diff
changeset
|
493 for (cat, type_), name in list(disco_infos.identities.items()) |
|
e9971a4b0627
remove uses of twisted.internet.defer.returnValue
Povilas Kanapickas <povilas@radix.lt>
parents:
4327
diff
changeset
|
494 ], |
|
e9971a4b0627
remove uses of twisted.internet.defer.returnValue
Povilas Kanapickas <povilas@radix.lt>
parents:
4327
diff
changeset
|
495 extensions, |
|
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
496 ) |
|
963
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
497 |
|
2148
a543eda2c923
core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents:
2096
diff
changeset
|
498 def items2tuples(self, disco_items): |
|
a543eda2c923
core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents:
2096
diff
changeset
|
499 """convert disco items to tuple of strings |
|
a543eda2c923
core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents:
2096
diff
changeset
|
500 |
|
a543eda2c923
core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents:
2096
diff
changeset
|
501 @param disco_items(iterable[disco.DiscoItem]): items |
|
a543eda2c923
core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents:
2096
diff
changeset
|
502 @return G(tuple[unicode,unicode,unicode]): serialised items |
|
a543eda2c923
core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents:
2096
diff
changeset
|
503 """ |
|
a543eda2c923
core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents:
2096
diff
changeset
|
504 for item in disco_items: |
|
a543eda2c923
core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents:
2096
diff
changeset
|
505 if not item.entity: |
| 3028 | 506 log.warning(_("invalid item (no jid)")) |
|
2148
a543eda2c923
core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents:
2096
diff
changeset
|
507 continue |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
508 yield (item.entity.full(), item.nodeIdentifier or "", item.name or "") |
|
2148
a543eda2c923
core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents:
2096
diff
changeset
|
509 |
|
963
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
510 @defer.inlineCallbacks |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
511 def _disco_items( |
| 3028 | 512 self, entity_jid_s, node="", use_cache=True, profile_key=C.PROF_KEY_NONE |
|
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2587
diff
changeset
|
513 ): |
|
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
514 """Discovery method for the bridge |
|
2148
a543eda2c923
core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents:
2096
diff
changeset
|
515 |
|
963
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
516 @param entity_jid_s: entity we want to discover |
|
2150
91347fe95384
core(memory.disco), bridge: discoInfos and discoItems now handle node
Goffi <goffi@goffi.org>
parents:
2148
diff
changeset
|
517 @param node(unicode): optional node to use |
|
2342
f047d5410040
core (memory/disco): added use_cache parameter to discoInfos/discoItems (set to False to ignore cache)
Goffi <goffi@goffi.org>
parents:
2150
diff
changeset
|
518 @param use_cache(bool): if True, use cached data if available |
|
1552
e0bde0d0b321
core (disco): use of “profile” instead of “profile_key” in several disco methods
Goffi <goffi@goffi.org>
parents:
1493
diff
changeset
|
519 @return: list of tuples""" |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
520 client = self.host.get_client(profile_key) |
|
963
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
521 entity = jid.JID(entity_jid_s) |
|
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3751
diff
changeset
|
522 disco_items = yield self.get_items(client, entity, node, use_cache) |
|
4341
e9971a4b0627
remove uses of twisted.internet.defer.returnValue
Povilas Kanapickas <povilas@radix.lt>
parents:
4327
diff
changeset
|
523 return list(self.items2tuples(disco_items)) |
