Mercurial > libervia-backend
annotate sat/plugins/plugin_xep_0115.py @ 2622:8fb99ed47db4
core: lines limit
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 27 Jun 2018 07:50:35 +0200 |
parents | e70023e84974 |
children | 56f94936df1e |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
1 #!/usr/bin/env python2 |
282
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 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
4 # SAT plugin for managing xep-0115 |
2483 | 5 # Copyright (C) 2009-2018 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 _ |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
21 from sat.core.constants import Const as C |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
978
diff
changeset
|
22 from sat.core.log import getLogger |
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
978
diff
changeset
|
23 log = getLogger(__name__) |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from twisted.words.xish import domish |
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
|
25 from twisted.words.protocols.jabber import jid |
1244
c3884a63efde
plugin XEP-0115: better disco error handling
souliane <souliane@mailoo.org>
parents:
1232
diff
changeset
|
26 from twisted.internet import defer, error |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from zope.interface import implements |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from wokkel import disco, iwokkel |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 try: |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 from twisted.words.protocols.xmlstream import XMPPHandler |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 except ImportError: |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 from wokkel.subprotocols import XMPPHandler |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 PRESENCE = '/presence' |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 NS_ENTITY_CAPABILITY = 'http://jabber.org/protocol/caps' |
953 | 37 NS_CAPS_OPTIMIZE = 'http://jabber.org/protocol/caps#optimize' |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
38 CAPABILITY_UPDATE = PRESENCE + '/c[@xmlns="' + NS_ENTITY_CAPABILITY + '"]' |
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 PLUGIN_INFO = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
41 C.PI_NAME: "XEP 0115 Plugin", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
42 C.PI_IMPORT_NAME: "XEP-0115", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
43 C.PI_TYPE: "XEP", |
2504
67cc54b01a12
plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
44 C.PI_MODES: C.PLUG_MODE_BOTH, |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
45 C.PI_PROTOCOLS: ["XEP-0115"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
46 C.PI_DEPENDENCIES: [], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
47 C.PI_MAIN: "XEP_0115", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
48 C.PI_HANDLER: "yes", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
49 C.PI_DESCRIPTION: _("""Implementation of entity capabilities""") |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 } |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
52 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
53 class XEP_0115(object): |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
54 cap_hash = None # capabilities hash is class variable as it is common to all profiles |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 def __init__(self, host): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
978
diff
changeset
|
57 log.info(_("Plugin XEP_0115 initialization")) |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 self.host = host |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
59 host.trigger.add("Presence send", self._presenceTrigger) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
60 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
61 def getHandler(self, client): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
62 return XEP_0115_handler(self, client.profile) |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 |
2533
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
64 @defer.inlineCallbacks |
2543
60758de1c227
plugin XEP-0115: fixed caps initial check
Goffi <goffi@goffi.org>
parents:
2533
diff
changeset
|
65 def _prepareCaps(self, client): |
2533
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
66 # we have to calculate hash for client |
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
67 # because disco infos/identities may change between clients |
957
2eb4fef29795
plulgin XEP-0115: fixed caps_optimize init
Goffi <goffi@goffi.org>
parents:
953
diff
changeset
|
68 |
2533
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
69 # optimize check |
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
70 client._caps_optimize = yield self.host.hasFeature(client, NS_CAPS_OPTIMIZE) |
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
71 if client._caps_optimize: |
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
72 log.info(_(u"Caps optimisation enabled")) |
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
73 client._caps_sent = False |
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
74 else: |
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
75 log.warning(_(u"Caps optimisation not available")) |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
76 |
2533
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
77 # hash generation |
962
b280cf4cdf25
plugin XEP-0115: fixed bad disco_infos construction
Goffi <goffi@goffi.org>
parents:
957
diff
changeset
|
78 _infos = yield client.discoHandler.info(client.jid, client.jid, '') |
b280cf4cdf25
plugin XEP-0115: fixed bad disco_infos construction
Goffi <goffi@goffi.org>
parents:
957
diff
changeset
|
79 disco_infos = disco.DiscoInfo() |
b280cf4cdf25
plugin XEP-0115: fixed bad disco_infos construction
Goffi <goffi@goffi.org>
parents:
957
diff
changeset
|
80 for item in _infos: |
b280cf4cdf25
plugin XEP-0115: fixed bad disco_infos construction
Goffi <goffi@goffi.org>
parents:
957
diff
changeset
|
81 disco_infos.append(item) |
2533
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
82 cap_hash = client._caps_hash = self.host.memory.disco.generateHash(disco_infos) |
2587
e70023e84974
core (disco): fixed disco capabilities (empty disco was used)
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
83 log.info(u"Our capability hash has been generated: [{cap_hash}]".format( |
2533
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
84 cap_hash = cap_hash)) |
2587
e70023e84974
core (disco): fixed disco capabilities (empty disco was used)
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
85 log.debug(u"Generating capability domish.Element") |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
86 c_elt = domish.Element((NS_ENTITY_CAPABILITY, 'c')) |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
87 c_elt['hash'] = 'sha-1' |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
88 c_elt['node'] = C.APP_URL |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
89 c_elt['ver'] = cap_hash |
2533
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
90 client._caps_elt = c_elt |
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
91 if client._caps_optimize: |
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
92 client._caps_sent = False |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
93 if cap_hash not in self.host.memory.disco.hashes: |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
94 self.host.memory.disco.hashes[cap_hash] = disco_infos |
2533
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
95 self.host.memory.updateEntityData(client.jid, C.ENTITY_CAP_HASH, cap_hash, profile_key=client.profile) |
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
96 |
2543
60758de1c227
plugin XEP-0115: fixed caps initial check
Goffi <goffi@goffi.org>
parents:
2533
diff
changeset
|
97 def _presenceAddElt(self, client, obj): |
2533
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
98 if client._caps_optimize: |
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
99 if client._caps_sent: |
2543
60758de1c227
plugin XEP-0115: fixed caps initial check
Goffi <goffi@goffi.org>
parents:
2533
diff
changeset
|
100 return |
2533
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
101 client.caps_sent = True |
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
102 obj.addChild(client._caps_elt) |
2543
60758de1c227
plugin XEP-0115: fixed caps initial check
Goffi <goffi@goffi.org>
parents:
2533
diff
changeset
|
103 |
60758de1c227
plugin XEP-0115: fixed caps initial check
Goffi <goffi@goffi.org>
parents:
2533
diff
changeset
|
104 def _presenceTrigger(self, client, obj, presence_d): |
60758de1c227
plugin XEP-0115: fixed caps initial check
Goffi <goffi@goffi.org>
parents:
2533
diff
changeset
|
105 if not hasattr(client, "_caps_optimize"): |
60758de1c227
plugin XEP-0115: fixed caps initial check
Goffi <goffi@goffi.org>
parents:
2533
diff
changeset
|
106 presence_d.addCallback(lambda __: self._prepareCaps(client)) |
60758de1c227
plugin XEP-0115: fixed caps initial check
Goffi <goffi@goffi.org>
parents:
2533
diff
changeset
|
107 |
60758de1c227
plugin XEP-0115: fixed caps initial check
Goffi <goffi@goffi.org>
parents:
2533
diff
changeset
|
108 presence_d.addCallback(lambda __: self._presenceAddElt(client, obj)) |
2533
8d82a62fa098
core (disco), plugin XEP-0115: client use + capabilities hash improvment:
Goffi <goffi@goffi.org>
parents:
2504
diff
changeset
|
109 return True |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
110 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
111 |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 class XEP_0115_handler(XMPPHandler): |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 implements(iwokkel.IDisco) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
114 |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 def __init__(self, plugin_parent, profile): |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 self.plugin_parent = plugin_parent |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 self.host = plugin_parent.host |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 self.profile = profile |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 def connectionInitialized(self): |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 self.xmlstream.addObserver(CAPABILITY_UPDATE, self.update) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
122 |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |
953 | 124 return [disco.DiscoFeature(NS_ENTITY_CAPABILITY), disco.DiscoFeature(NS_CAPS_OPTIMIZE)] |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 def getDiscoItems(self, requestor, target, nodeIdentifier=''): |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 return [] |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 def update(self, presence): |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 """ |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 Manage the capabilities of the entity |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
132 |
1244
c3884a63efde
plugin XEP-0115: better disco error handling
souliane <souliane@mailoo.org>
parents:
1232
diff
changeset
|
133 Check if we know the version of this capabilities and get the capabilities if necessary |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 """ |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 from_jid = jid.JID(presence['from']) |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
136 c_elem = presence.elements(NS_ENTITY_CAPABILITY, 'c').next() |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 try: |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
138 c_ver = c_elem['ver'] |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
139 c_hash = c_elem['hash'] |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
140 c_node = c_elem['node'] |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 except KeyError: |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
142 log.warning(_(u'Received invalid capabilities tag: %s') % c_elem.toXml()) |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 return |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
144 |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
145 if c_ver in self.host.memory.disco.hashes: |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
146 # we already know the hash, we update the jid entity |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
147 log.debug(u"hash [%(hash)s] already in cache, updating entity [%(jid)s]" % {'hash': c_ver, 'jid': from_jid.full()}) |
1315
be3a301540c0
core (memory): updateEntityData now accept a "silent" argument to avoid sending signal to frontends when updating an attribute with "signalOnUpdate" flag.
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
148 self.host.memory.updateEntityData(from_jid, C.ENTITY_CAP_HASH, c_ver, profile_key=self.profile) |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
149 return |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
150 |
1244
c3884a63efde
plugin XEP-0115: better disco error handling
souliane <souliane@mailoo.org>
parents:
1232
diff
changeset
|
151 if c_hash != 'sha-1': # unknown hash method |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
152 log.warning(_(u'Unknown hash method for entity capabilities: [%(hash_method)s] (entity: %(jid)s, node: %(node)s)') % {'hash_method':c_hash, 'jid': from_jid, 'node': c_node}) |
1244
c3884a63efde
plugin XEP-0115: better disco error handling
souliane <souliane@mailoo.org>
parents:
1232
diff
changeset
|
153 |
c3884a63efde
plugin XEP-0115: better disco error handling
souliane <souliane@mailoo.org>
parents:
1232
diff
changeset
|
154 def cb(dummy): |
c3884a63efde
plugin XEP-0115: better disco error handling
souliane <souliane@mailoo.org>
parents:
1232
diff
changeset
|
155 computed_hash = self.host.memory.getEntityDatum(from_jid, C.ENTITY_CAP_HASH, self.profile) |
c3884a63efde
plugin XEP-0115: better disco error handling
souliane <souliane@mailoo.org>
parents:
1232
diff
changeset
|
156 if computed_hash != c_ver: |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
157 log.warning(_(u'Computed hash differ from given hash:\ngiven: [%(given_hash)s]\ncomputed: [%(computed_hash)s]\n(entity: %(jid)s, node: %(node)s)') % {'given_hash':c_ver, 'computed_hash': computed_hash, 'jid': from_jid, 'node': c_node}) |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
158 |
1244
c3884a63efde
plugin XEP-0115: better disco error handling
souliane <souliane@mailoo.org>
parents:
1232
diff
changeset
|
159 def eb(failure): |
c3884a63efde
plugin XEP-0115: better disco error handling
souliane <souliane@mailoo.org>
parents:
1232
diff
changeset
|
160 if isinstance(failure.value, error.ConnectionDone): |
c3884a63efde
plugin XEP-0115: better disco error handling
souliane <souliane@mailoo.org>
parents:
1232
diff
changeset
|
161 return |
c3884a63efde
plugin XEP-0115: better disco error handling
souliane <souliane@mailoo.org>
parents:
1232
diff
changeset
|
162 msg = failure.value.condition if hasattr(failure.value, 'condition') else failure.getErrorMessage() |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
163 log.error(_(u"Couldn't retrieve disco info for {jid}: {error}").format(jid=from_jid.full(), error=msg)) |
1244
c3884a63efde
plugin XEP-0115: better disco error handling
souliane <souliane@mailoo.org>
parents:
1232
diff
changeset
|
164 |
2148
a543eda2c923
core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
165 d = self.host.getDiscoInfos(self.parent, from_jid) |
1244
c3884a63efde
plugin XEP-0115: better disco error handling
souliane <souliane@mailoo.org>
parents:
1232
diff
changeset
|
166 d.addCallbacks(cb, eb) |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
167 # TODO: me must manage the full algorithm described at XEP-0115 #5.4 part 3 |