core (memory/disco): getInfos now handle node + use client instead of profile in many methods

This commit is contained in:
Goffi 2017-02-12 20:43:20 +01:00
commit 3bc851abf2
16 changed files with 69 additions and 60 deletions

View file

@ -211,12 +211,13 @@ class FilePlugin(object):
@param profile: %(doc_profile)s
@return (dict): action dictionary, with progress id in case of success, else xmlui message
"""
client = self.host.getClient(profile)
if not os.path.isfile(filepath):
raise exceptions.DataError(u"The given path doesn't link to a file")
if not filename:
filename = os.path.basename(filepath) or '_'
for namespace, callback, priority, method_name in self._file_callbacks:
has_feature = yield self.host.hasFeature(namespace, peer_jid, profile)
has_feature = yield self.host.hasFeature(client, namespace, peer_jid)
if has_feature:
log.info(u"{name} method will be used to send the file".format(name=method_name))
progress_id = yield callback(peer_jid, filepath, filename, file_desc, profile)

View file

@ -71,7 +71,7 @@ class GroupBlog(object):
@defer.inlineCallbacks
def profileConnected(self, client):
try:
yield self.host.checkFeatures((NS_PUBSUB_GROUPBLOG,), profile=client.profile)
yield self.host.checkFeatures(client, (NS_PUBSUB_GROUPBLOG,))
except exceptions.FeatureNotFound:
client.server_groupblog_available = False
log.warning(_(u"Server is not able to manage item-access pubsub, we can't use group blog"))

View file

@ -254,8 +254,10 @@ class IPPlugin(object):
if self._external_ip_cache is not None:
defer.returnValue(self._external_ip_cache)
client = self.host.getClient(profile)
# we first try with XEP-0279
ip_check = yield self.host.hasFeature(NS_IP_CHECK, profile=profile)
ip_check = yield self.host.hasFeature(client, NS_IP_CHECK)
if ip_check:
log.debug(u"Server IP Check available, we use it to retrieve our IP")
client = self.host.getClient(profile)

View file

@ -101,7 +101,7 @@ class XEP_0033(object):
self.sendAndStoreMessage(mess_data, entries, profile)
log.debug("XEP-0033 took over")
raise failure.Failure(exceptions.CancelError(u'Cancelled by XEP-0033'))
d = self.host.findFeaturesSet([NS_ADDRESS], profile=profile)
d = self.host.findFeaturesSet(client, [NS_ADDRESS])
d.addCallbacks(discoCallback, lambda dummy: discoCallback(None))
return d
@ -121,8 +121,8 @@ class XEP_0033(object):
- redesign the database to save only one entry to the database
- change the messageNew signal to eventually pass more than one recipient
"""
client = self.host.getClient(profile)
def send(mess_data, skip_send=False):
client = self.host.profiles[profile]
d = defer.Deferred()
if not skip_send:
d.addCallback(client.sendMessageData)
@ -156,7 +156,7 @@ class XEP_0033(object):
defer_list = []
for type_, jid_ in entries:
d = defer.Deferred()
d.addCallback(self.host.findFeaturesSet, jid_=JID(JID(jid_).host), profile=profile)
d.addCallback(self.host.findFeaturesSet, client=client, jid_=JID(JID(jid_).host))
d.addCallbacks(discoCallback, errback, callbackArgs=[jid_], errbackArgs=[jid_])
d.callback([NS_ADDRESS])
defer_list.append(d)

View file

@ -362,8 +362,9 @@ class XEP_0045(object):
@param jid_: entity which may have a MUC service, or None for our own server
@param profile: %(doc_profile)s
"""
client = self.host.getClient(profile)
muc_service = None
services = yield self.host.findServiceEntities("conference", "text", jid_, profile=profile)
services = yield self.host.findServiceEntities(client, "conference", "text", jid_)
for service in services:
if ".irc." not in service.userhost():
# FIXME:
@ -712,7 +713,7 @@ class XEP_0045(object):
msg = D_(u"{} is not a valid JID!".format(unparsed))
self.text_cmds.feedBack(client, msg, mess_data)
return False
d = self.host.getDiscoItems(service, profile=client.profile)
d = self.host.getDiscoItems(client, service)
d.addCallback(self._showListUI, client, service)
return False

View file

@ -85,7 +85,8 @@ class XEP_0055(object):
@param profile (unicode): %(doc_profile)s
@return: list[jid.JID]
"""
d = self.host.findFeaturesSet([NS_SEARCH], profile=profile)
client = self.host.getClient(profile)
d = self.host.findFeaturesSet(client, [NS_SEARCH])
return d.addCallback(lambda set_: list(set_))

View file

@ -100,7 +100,7 @@ class XEP_0060(object):
@defer.inlineCallbacks
def profileConnected(self, client):
pubsub_services = yield self.host.findServiceEntities("pubsub", "service", profile=client.profile)
pubsub_services = yield self.host.findServiceEntities(client, "pubsub", "service")
if pubsub_services:
# we use one of the found services as our default pubsub service
client.pubsub_service = pubsub_services.pop()
@ -228,7 +228,8 @@ class XEP_0060(object):
# @param profile (str): %(doc_profile)s
# @return: deferred which fire a list of nodes
# """
# d = self.host.getDiscoItems(service, nodeIdentifier, profile_key=profile)
# client = self.host.getClient(profile)
# d = self.host.getDiscoItems(client, service, nodeIdentifier)
# d.addCallback(lambda result: [item.getAttribute('node') for item in result.toElement().children if item.hasAttribute('node')])
# return d

View file

@ -770,7 +770,7 @@ class XEP_0065(object):
except KeyError:
pass
try:
proxy = (yield self.host.findServiceEntities('proxy', 'bytestreams', profile=profile)).pop()
proxy = (yield self.host.findServiceEntities(client, 'proxy', 'bytestreams')).pop()
except (defer.CancelledError, StopIteration):
notFound(server)
iq_elt = client.IQ('get')

View file

@ -78,7 +78,7 @@ class XEP_0092(object):
d = iq_elt.send()
d.addCallback(self._gotVersion)
return d
d = self.host.checkFeature(NS_VERSION, jid_, client.profile)
d = self.host.checkFeature(client, NS_VERSION, jid_)
d.addCallback(getVersion)
reactor.callLater(TIMEOUT, d.cancel) # XXX: timeout needed because some clients don't answer the IQ
return d

View file

@ -66,7 +66,7 @@ class XEP_0115(object):
client.caps_optimize = None
if XEP_0115.cap_hash is None:
disco_d.addCallback(lambda dummy: self.host.hasFeature(NS_CAPS_OPTIMIZE, profile=profile))
disco_d.addCallback(lambda dummy: self.host.hasFeature(client, NS_CAPS_OPTIMIZE))
def updateOptimize(optimize):
client.caps_optimize = optimize
if optimize:
@ -163,6 +163,6 @@ class XEP_0115_handler(XMPPHandler):
msg = failure.value.condition if hasattr(failure.value, 'condition') else failure.getErrorMessage()
log.error(_(u"Couldn't retrieve disco info for {jid}: {error}").format(jid=from_jid.full(), error=msg))
d = self.host.getDiscoInfos(from_jid, self.profile)
d = self.host.getDiscoInfos(self.parent, from_jid)
d.addCallbacks(cb, eb)
# TODO: me must manage the full algorithm described at XEP-0115 #5.4 part 3

View file

@ -447,7 +447,7 @@ class XEP_0260(object):
log.warning(u"Jingle IBB (XEP-0261) plugin is not available, we have to close the session")
self._j.terminate(self._j.REASON_CONNECTIVITY_ERROR, session, client.profile)
else:
d = self.host.hasFeature(self._jingle_ibb.NAMESPACE, session['peer_jid'], client.profile)
d = self.host.hasFeature(client, self._jingle_ibb.NAMESPACE, session['peer_jid'])
d.addCallback(self._doFallback, session, content_name, client)
return d

View file

@ -105,7 +105,8 @@ class XEP_0277(object):
return {'available': C.BOOL_FALSE}
def getFeatures(self, profile):
d = self.host.checkFeatures([], identity=('pubsub', 'pep'), profile=profile)
client = self.host.getClient(profile)
d = self.host.checkFeatures(client, [], identity=('pubsub', 'pep'))
d.addCallbacks(self._checkFeaturesCb, self._checkFeaturesEb)
return d

View file

@ -99,7 +99,7 @@ class XEP_0280(object):
log.info(_(u"Not activating message carbons as requested in params"))
return
try:
yield self.host.checkFeatures((NS_CARBONS,), profile=client.profile)
yield self.host.checkFeatures(client, (NS_CARBONS,))
except exceptions.FeatureNotFound:
log.warning(_(u"server doesn't handle message carbons"))
else:

View file

@ -83,8 +83,9 @@ class XEP_0300(object):
@return (D(unicode, None)): best available algorithm,
or None if hashing is not possible
"""
client = self.host.getClient(profile)
for algo in reversed(XEP_0300.ALGOS):
has_feature = yield self.host.hasFeature(NS_HASHES_FUNCTIONS.format(algo), to_jid, profile)
has_feature = yield self.host.hasFeature(client, NS_HASHES_FUNCTIONS.format(algo), to_jid)
if has_feature:
log.debug(u"Best hashing algorithm found for {jid}: {algo}".format(
jid=to_jid.full(),

View file

@ -110,7 +110,7 @@ class XEP_0363(object):
try:
entity = client.http_upload_service
except AttributeError:
found_entities = yield self.host.findFeaturesSet((NS_HTTP_UPLOAD,), profile=client.profile)
found_entities = yield self.host.findFeaturesSet(client, (NS_HTTP_UPLOAD,))
try:
entity = client.http_upload_service = iter(found_entities).next()
except StopIteration: