diff --git a/sat/core/sat_main.py b/sat/core/sat_main.py index 56731f8e..33571832 100644 --- a/sat/core/sat_main.py +++ b/sat/core/sat_main.py @@ -1095,6 +1095,9 @@ class SAT(service.Service): def checkFeatures(self, *args, **kwargs): return self.memory.disco.checkFeatures(*args, **kwargs) + def hasIdentity(self, *args, **kwargs): + return self.memory.disco.hasIdentity(*args, **kwargs) + def getDiscoInfos(self, *args, **kwargs): return self.memory.disco.getInfos(*args, **kwargs) diff --git a/sat/memory/disco.py b/sat/memory/disco.py index 2af9cc8b..d387a28e 100755 --- a/sat/memory/disco.py +++ b/sat/memory/disco.py @@ -17,11 +17,12 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from typing import Optional from sat.core.i18n import _ from sat.core import exceptions from sat.core.log import getLogger +from sat.core.core_types import SatXMPPEntity -log = getLogger(__name__) from twisted.words.protocols.jabber import jid from twisted.words.protocols.jabber.error import StanzaError from twisted.internet import defer @@ -35,6 +36,9 @@ from base64 import b64encode from hashlib import sha1 +log = getLogger(__name__) + + TIMEOUT = 15 CAP_HASH_ERROR = "ERROR" @@ -162,6 +166,25 @@ class Discovery(object): if identity is not None and identity not in disco_infos.identities: raise failure.Failure(exceptions.FeatureNotFound()) + async def hasIdentity( + self, + client: SatXMPPEntity, + category: str, + type_: str, + jid_: Optional[jid.JID] = None, + node: str = "" + ) -> bool: + """Tell if an entity has the requested identity + + @param category: identity category + @param type_: identity type + @param jid_: jid of the target, or None for profile's server + @param node(unicode): optional node to use for disco request + @return: True if the entity has the given identity + """ + disco_infos = await self.getInfos(client, jid_, node) + return (category, type_) in disco_infos.identities + def getInfos(self, client, jid_=None, node="", use_cache=True): """get disco infos from jid_, filling capability hash if needed