Mercurial > libervia-backend
annotate src/memory/disco.py @ 1202:101c06fbda31
misc: fixed typos in README
author | Matteo Cypriani <mcy@lm7.fr> |
---|---|
date | Mon, 15 Sep 2014 14:18:27 +0200 |
parents | 7d640c303140 |
children | 8ad37c3d58a9 |
rev | line source |
---|---|
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
4 # SAT: a jabber client |
811 | 5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 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 |
771 | 20 from sat.core.i18n import _ |
951
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
21 from sat.core import exceptions |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
973
diff
changeset
|
22 from sat.core.log import getLogger |
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
973
diff
changeset
|
23 log = getLogger(__name__) |
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
|
24 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
|
25 from twisted.words.protocols.jabber.error import StanzaError |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
26 from twisted.internet import defer |
1189
7d640c303140
core (disco): added a timeout to get items
Goffi <goffi@goffi.org>
parents:
993
diff
changeset
|
27 from twisted.internet import reactor |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
28 from sat.core.constants import Const as C |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
29 from wokkel import disco |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
30 from base64 import b64encode |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
31 from hashlib import sha1 |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 PRESENCE = '/presence' |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 NS_ENTITY_CAPABILITY = 'http://jabber.org/protocol/caps' |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
36 CAPABILITY_UPDATE = PRESENCE + '/c[@xmlns="' + NS_ENTITY_CAPABILITY + '"]' |
1189
7d640c303140
core (disco): added a timeout to get items
Goffi <goffi@goffi.org>
parents:
993
diff
changeset
|
37 TIMEOUT = 15 |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 class HashGenerationError(Exception): |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 pass |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
42 |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 class ByteIdentity(object): |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
44 """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
|
45 |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 def __init__(self, identity, lang=None): |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 assert isinstance(identity, disco.DiscoIdentity) |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 self.category = identity.category.encode('utf-8') |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 self.idType = identity.type.encode('utf-8') |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 self.name = identity.name.encode('utf-8') if identity.name else '' |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
51 self.lang = lang.encode('utf-8') if lang is not None else '' |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 def __str__(self): |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 return "%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
|
55 |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
57 class Discovery(object): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
58 """ Manage capabilities of entities """ |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 def __init__(self, host): |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 self.host = host |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
62 self.hashes = {} # key: capability hash, value: disco features/identities |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
63 # TODO: save hashes in databse, remove legacy hashes |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
65 @defer.inlineCallbacks |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
66 def hasFeature(self, feature, jid_=None, profile_key=C.PROF_KEY_NONE): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
67 """Tell if an entity has the required feature |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
68 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
69 @param feature: feature namespace |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
70 @param jid_: jid of the target, or None for profile's server |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
71 @param profile_key: %(doc_profile_key)s |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
72 @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
|
73 """ |
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
|
74 disco_infos = yield self.getInfos(jid_, profile_key) |
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
|
75 defer.returnValue(feature in disco_infos.features) |
951
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
76 |
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
77 @defer.inlineCallbacks |
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
78 def checkFeature(self, feature, jid_=None, profile_key=C.PROF_KEY_NONE): |
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
79 """Like hasFeature, but raise an exception is feature is not Found |
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
80 |
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
81 @param feature: feature namespace |
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
82 @param jid_: jid of the target, or None for profile's server |
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
83 @param profile_key: %(doc_profile_key)s |
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
84 @return: None if feature is found |
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
85 |
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
86 @raise: exceptions.FeatureNotFound |
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
87 """ |
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
|
88 disco_infos = yield self.getInfos(jid_, profile_key) |
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
|
89 if not feature in disco_infos.features: |
951
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
90 raise exceptions.FeatureNotFound |
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
|
91 defer.returnValue(feature in disco_infos) |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
93 def getInfos(self, jid_=None, profile_key=C.PROF_KEY_NONE): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
94 """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
|
95 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
96 @param jid_: jid of the target, or None for profile's server |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
97 @param profile_key: %(doc_profile_key)s |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
98 @return: a Deferred which fire disco.DiscoInfo |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
99 """ |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 client = self.host.getClient(profile_key) |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
101 if jid_ is None: |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
102 jid_ = jid.JID(client.jid.host) |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
103 try: |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
104 cap_hash = self.host.memory.getEntityData(jid_, [C.ENTITY_CAP_HASH], client.profile)[C.ENTITY_CAP_HASH] |
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
|
105 disco_infos = self.hashes[cap_hash] |
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
|
106 return defer.succeed(disco_infos) |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
107 except KeyError: |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
108 # capability hash is not available, we'll compute one |
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
|
109 def infosCb(disco_infos): |
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
|
110 cap_hash = self.generateHash(disco_infos) |
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
|
111 self.hashes[cap_hash] = disco_infos |
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
|
112 self.host.memory.updateEntityData(jid_, C.ENTITY_CAP_HASH, cap_hash, client.profile) |
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
|
113 return disco_infos |
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
|
114 d = client.disco.requestInfo(jid_) |
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
|
115 d.addCallback(infosCb) |
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
|
116 return d |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
117 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
118 @defer.inlineCallbacks |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
119 def getItems(self, jid_=None, profile_key=C.PROF_KEY_NONE): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
120 """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
|
121 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
122 @param jid_: jid of the target, or None for profile's server |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
123 @param profile_key: %(doc_profile_key)s |
963
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
124 @return: a Deferred which fire disco.DiscoItems |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
125 """ |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
126 client = self.host.getClient(profile_key) |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
127 if jid_ is None: |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
128 jid_ = jid.JID(client.jid.host) |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
129 # we cache items only for our own server |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
130 try: |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
131 items = self.host.memory.getEntityData(jid_, ["DISCO_ITEMS"], client.profile)["DISCO_ITEMS"] |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
973
diff
changeset
|
132 log.debug("[%s] disco items are in cache" % jid_.full()) |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
133 except KeyError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
973
diff
changeset
|
134 log.debug("Caching [%s] disco items" % jid_.full()) |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
135 items = yield client.disco.requestItems(jid_) |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
136 self.host.memory.updateEntityData(jid_, "DISCO_ITEMS", items, client.profile) |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
137 else: |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
138 items = yield client.disco.requestItems(jid_) |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
139 |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
140 defer.returnValue(items) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
141 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
142 |
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
|
143 def _infosEb(self, failure, entity_jid): |
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
|
144 failure.trap(StanzaError) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
973
diff
changeset
|
145 log.warning(_("Error while requesting [%(jid)s]: %(error)s") % {'jid': entity_jid.full(), |
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
|
146 'error': failure.getErrorMessage()}) |
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
|
147 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
148 def findServiceEntities(self, category, type_, jid_=None, profile_key=C.PROF_KEY_NONE): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
149 """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
|
150 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
151 @param category: identity's category |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
152 @param type_: identitiy's type |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
153 @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
|
154 @param profile_key: %(doc_profile_key)s |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
155 @return: a set of entities or None if no cached data were found |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
156 """ |
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
|
157 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
|
158 |
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
|
159 def infosCb(infos, entity_jid): |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
160 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
|
161 found_entities.add(entity_jid) |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 |
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
|
163 def gotItems(items): |
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
|
164 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
|
165 for item in items: |
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
|
166 info_d = self.getInfos(item.entity, profile_key) |
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
|
167 info_d.addCallbacks(infosCb, self._infosEb, [item.entity], None, [item.entity]) |
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
|
168 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
|
169 return defer.DeferredList(defers_list) |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
170 |
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
|
171 d = self.getItems(jid_, profile_key) |
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
|
172 d.addCallback(gotItems) |
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
|
173 d.addCallback(lambda dummy: found_entities) |
1189
7d640c303140
core (disco): added a timeout to get items
Goffi <goffi@goffi.org>
parents:
993
diff
changeset
|
174 reactor.callLater(TIMEOUT, d.cancel) # 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
|
175 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
|
176 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
177 def findFeaturesSet(self, features, category=None, type_=None, jid_=None, profile_key=C.PROF_KEY_NONE): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
178 """Return entities (including jid_ and its items) offering features |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
179 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
180 @param features: iterable of features which must be present |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
181 @param category: if not None, accept only this category |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
182 @param type_: if not None, accept only this type |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
183 @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
|
184 @param profile_key: %(doc_profile_key)s |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
185 @return: a set of found entities |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
186 """ |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
187 client = self.host.getClient(profile_key) |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
188 if jid_ is None: |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
189 jid_ = jid.JID(client.jid.host) |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
190 features = set(features) |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
191 found_entities = set() |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 |
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
|
193 def infosCb(infos, entity): |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
194 if category is not None or type_ is not None: |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
195 categories = set() |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
196 types = set() |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
197 for identity in infos.identities: |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
198 id_cat, id_type = identity |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
199 categories.add(id_cat) |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
200 types.add(id_type) |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
201 if category is not None and category not in categories: |
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
|
202 return |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
203 if type_ is not None and type_ not in types: |
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
|
204 return |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
205 if features.issubset(infos.features): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
206 found_entities.add(entity) |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 |
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
|
208 def gotItems(items): |
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
|
209 defer_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
|
210 for entity in [jid_] + [item.entity for item in items]: |
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
|
211 infos_d = self.getInfos(entity, profile_key) |
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
|
212 infos_d.addCallbacks(infosCb, self._infosEb, [entity], None, [entity]) |
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
|
213 defer_list.append(infos_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
|
214 return defer.DeferredList(defer_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
|
215 |
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
|
216 d = self.getItems(jid_, profile_key) |
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
|
217 d.addCallback(gotItems) |
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
|
218 d.addCallback(lambda dummy: found_entities) |
1189
7d640c303140
core (disco): added a timeout to get items
Goffi <goffi@goffi.org>
parents:
993
diff
changeset
|
219 reactor.callLater(TIMEOUT, d.cancel) # 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
|
220 return d |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
221 |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
222 def generateHash(self, services): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
223 """ Generate a unique hash for given service |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
224 |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
225 hash algorithm is the one described in XEP-0115 |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
226 @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
|
227 |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 """ |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
229 s = [] |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
230 byte_identities = [ByteIdentity(service) for service in services if isinstance(service, disco.DiscoIdentity)] # FIXME: lang must be managed here |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
231 byte_identities.sort(key=lambda i: i.lang) |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
232 byte_identities.sort(key=lambda i: i.idType) |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
233 byte_identities.sort(key=lambda i: i.category) |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
234 for identity in byte_identities: |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
235 s.append(str(identity)) |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
236 s.append('<') |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
237 byte_features = [service.encode('utf-8') for service in services if isinstance(service, disco.DiscoFeature)] |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
238 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
|
239 for feature in byte_features: |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
240 s.append(feature) |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
241 s.append('<') |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
242 #TODO: manage XEP-0128 data form here |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
243 cap_hash = b64encode(sha1(''.join(s)).digest()) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
973
diff
changeset
|
244 log.debug(_('Capability hash generated: [%s]') % cap_hash) |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
245 return cap_hash |
963
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
246 |
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
247 @defer.inlineCallbacks |
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
248 def _discoInfos(self, entity_jid_s, profile_key=C.PROF_KEY_NONE): |
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
249 """ Discovery method for the bridge |
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
250 @param entity_jid_s: entity we want to discover |
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
251 |
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
252 @return: list of tu""" |
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
253 entity = jid.JID(entity_jid_s) |
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
254 disco_infos = yield self.getInfos(entity, profile_key) |
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
255 defer.returnValue((disco_infos.features, [(cat, type_, name or '') for (cat, type_), name in disco_infos.identities.items()])) |
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
256 |
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
257 @defer.inlineCallbacks |
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
258 def _discoItems(self, entity_jid_s, profile_key=C.PROF_KEY_NONE): |
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
259 """ Discovery method for the bridge |
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
260 @param entity_jid_s: entity we want to discover |
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
261 |
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
262 @return: list of tu""" |
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
263 entity = jid.JID(entity_jid_s) |
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
264 disco_items = yield self.getItems(entity, profile_key) |
723f28cd15c7
core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents:
961
diff
changeset
|
265 defer.returnValue([(item.entity.full(), item.nodeIdentifier or '', item.name or '') for item in disco_items]) |