comparison src/privilege.py @ 400:371e72871e19

privilege: fill hash_map before jid_caps to avoid KeyError in getAutoSubscribers
author Goffi <goffi@goffi.org>
date Tue, 07 May 2019 08:25:31 +0200
parents dabee42494ac
children
comparison
equal deleted inserted replaced
399:2521c53bc359 400:371e72871e19
253 # no capabilities, we don't go further 253 # no capabilities, we don't go further
254 return 254 return
255 255
256 # FIXME: hash is not checked (cf. XEP-0115) 256 # FIXME: hash is not checked (cf. XEP-0115)
257 disco_tuple = (hash_, ver) 257 disco_tuple = (hash_, ver)
258 jid_caps = self.caps_map.setdefault(from_jid_bare, {})
259 if from_jid.resource not in jid_caps:
260 jid_caps[from_jid.resource] = disco_tuple
261 258
262 if disco_tuple not in self.hash_map: 259 if disco_tuple not in self.hash_map:
263 # first time we se this hash, what is behind it? 260 # first time we se this hash, what is behind it?
264 infos = yield self.requestInfo(from_jid) 261 infos = yield self.requestInfo(from_jid)
265 self.hash_map[disco_tuple] = { 262 self.hash_map[disco_tuple] = {
266 'notify': {f[:-7] for f in infos.features if f.endswith('+notify')}, 263 'notify': {f[:-7] for f in infos.features if f.endswith('+notify')},
267 'infos': infos 264 'infos': infos
268 } 265 }
266
267 # jid_caps must be filled only after hash_map is set, to be sure that
268 # the hash data is available in getAutoSubscribers
269 jid_caps = self.caps_map.setdefault(from_jid_bare, {})
270 if from_jid.resource not in jid_caps:
271 jid_caps[from_jid.resource] = disco_tuple
269 272
270 # nodes are the nodes subscribed with +notify 273 # nodes are the nodes subscribed with +notify
271 nodes = tuple(self.hash_map[disco_tuple]['notify']) 274 nodes = tuple(self.hash_map[disco_tuple]['notify'])
272 if not nodes: 275 if not nodes:
273 return 276 return
299 if roster_item.subscriptionFrom: 302 if roster_item.subscriptionFrom:
300 try: 303 try:
301 online_resources = self.caps_map[roster_jid] 304 online_resources = self.caps_map[roster_jid]
302 except KeyError: 305 except KeyError:
303 continue 306 continue
304 for res, hash_ in online_resources.iteritems(): 307 for res, disco_tuple in online_resources.iteritems():
305 notify = self.hash_map[hash_]['notify'] 308 notify = self.hash_map[disco_tuple]['notify']
306 if nodeIdentifier in notify: 309 if nodeIdentifier in notify:
307 full_jid = jid.JID(tuple=(roster_jid.user, roster_jid.host, res)) 310 full_jid = jid.JID(tuple=(roster_jid.user, roster_jid.host, res))
308 auto_subscribers.append(full_jid) 311 auto_subscribers.append(full_jid)
309 defer.returnValue(auto_subscribers) 312 defer.returnValue(auto_subscribers)