comparison src/plugins/plugin_xep_0115.py @ 953:4a577b170809

plugin xep-0115: caps optimisation
author Goffi <goffi@goffi.org>
date Mon, 31 Mar 2014 12:24:20 +0200
parents e1842ebcb2f3
children 2eb4fef29795
comparison
equal deleted inserted replaced
952:91836a647515 953:4a577b170809
31 except ImportError: 31 except ImportError:
32 from wokkel.subprotocols import XMPPHandler 32 from wokkel.subprotocols import XMPPHandler
33 33
34 PRESENCE = '/presence' 34 PRESENCE = '/presence'
35 NS_ENTITY_CAPABILITY = 'http://jabber.org/protocol/caps' 35 NS_ENTITY_CAPABILITY = 'http://jabber.org/protocol/caps'
36 NS_CAPS_OPTIMIZE = 'http://jabber.org/protocol/caps#optimize'
36 CAPABILITY_UPDATE = PRESENCE + '/c[@xmlns="' + NS_ENTITY_CAPABILITY + '"]' 37 CAPABILITY_UPDATE = PRESENCE + '/c[@xmlns="' + NS_ENTITY_CAPABILITY + '"]'
37 38
38 PLUGIN_INFO = { 39 PLUGIN_INFO = {
39 "name": "XEP 0115 Plugin", 40 "name": "XEP 0115 Plugin",
40 "import_name": "XEP-0115", 41 "import_name": "XEP-0115",
59 def getHandler(self, profile): 60 def getHandler(self, profile):
60 return XEP_0115_handler(self, profile) 61 return XEP_0115_handler(self, profile)
61 62
62 def _checkHash(self, disco_d, profile): 63 def _checkHash(self, disco_d, profile):
63 if XEP_0115.cap_hash is None: 64 if XEP_0115.cap_hash is None:
65 disco_d.addCallback(lambda dummy: self.host.hasFeature(NS_CAPS_OPTIMIZE, profile_key=profile))
66 def updateOptimize(optimize):
67 client = self.host.getClient(profile)
68 client.caps_optimize = optimize
69 if optimize:
70 info(_("Caps optimisation enabled"))
71 client.caps_sent = False
72 else:
73 warning(_("Caps optimisation not available"))
74 disco_d.addCallback(updateOptimize)
64 disco_d.addCallback(lambda dummy: self.recalculateHash(profile)) 75 disco_d.addCallback(lambda dummy: self.recalculateHash(profile))
65 return True 76 return True
66 77
67 def _presenceTrigger(self, obj): 78 def _presenceTrigger(self, client, obj):
68 if XEP_0115.cap_hash is not None: 79 if XEP_0115.cap_hash is not None:
80 if client.caps_optimize:
81 if client.caps_sent:
82 return True
83 client.caps_sent = True
69 obj.addChild(XEP_0115.c_elt) 84 obj.addChild(XEP_0115.c_elt)
70 return True 85 return True
71 86
72 @defer.inlineCallbacks 87 @defer.inlineCallbacks
73 def recalculateHash(self, profile): 88 def recalculateHash(self, profile):
80 c_elt['hash'] = 'sha-1' 95 c_elt['hash'] = 'sha-1'
81 c_elt['node'] = C.APP_URL 96 c_elt['node'] = C.APP_URL
82 c_elt['ver'] = cap_hash 97 c_elt['ver'] = cap_hash
83 XEP_0115.cap_hash = cap_hash 98 XEP_0115.cap_hash = cap_hash
84 XEP_0115.c_elt = c_elt 99 XEP_0115.c_elt = c_elt
100 if client.caps_optimize:
101 client.caps_sent = False
85 if cap_hash not in self.host.memory.disco.hashes: 102 if cap_hash not in self.host.memory.disco.hashes:
86 self.host.memory.disco.hashes[cap_hash] = disco_infos 103 self.host.memory.disco.hashes[cap_hash] = disco_infos
87 self.host.memory.updateEntityData(client.jid, C.ENTITY_CAP_HASH, cap_hash, profile) 104 self.host.memory.updateEntityData(client.jid, C.ENTITY_CAP_HASH, cap_hash, profile)
88 105
89 106
97 114
98 def connectionInitialized(self): 115 def connectionInitialized(self):
99 self.xmlstream.addObserver(CAPABILITY_UPDATE, self.update) 116 self.xmlstream.addObserver(CAPABILITY_UPDATE, self.update)
100 117
101 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): 118 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
102 return [disco.DiscoFeature(NS_ENTITY_CAPABILITY)] 119 return [disco.DiscoFeature(NS_ENTITY_CAPABILITY), disco.DiscoFeature(NS_CAPS_OPTIMIZE)]
103 120
104 def getDiscoItems(self, requestor, target, nodeIdentifier=''): 121 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
105 return [] 122 return []
106 123
107 @defer.inlineCallbacks 124 @defer.inlineCallbacks