Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0115.py @ 587:952322b1d490
Remove trailing whitespaces.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 18 Jan 2013 17:55:34 +0100 |
parents | ca13633d3b6b |
children | beaf6bec2fcd |
comparison
equal
deleted
inserted
replaced
586:6a718ede8be1 | 587:952322b1d490 |
---|---|
69 self.name = identity.name.encode('utf-8') if identity.name else '' | 69 self.name = identity.name.encode('utf-8') if identity.name else '' |
70 self.lang = lang.encode('utf-8') if lang else '' | 70 self.lang = lang.encode('utf-8') if lang else '' |
71 | 71 |
72 def __str__(self): | 72 def __str__(self): |
73 return "%s/%s/%s/%s" % (self.category, self.idType, self.lang, self.name) | 73 return "%s/%s/%s/%s" % (self.category, self.idType, self.lang, self.name) |
74 | 74 |
75 | 75 |
76 class XEP_0115(): | 76 class XEP_0115(): |
77 cap_hash = None #capabilities hash is class variable as it is common to all profiles | 77 cap_hash = None #capabilities hash is class variable as it is common to all profiles |
78 #TODO: this code is really dirty, need to clean it and try to move it to Wokkel | 78 #TODO: this code is really dirty, need to clean it and try to move it to Wokkel |
79 | 79 |
81 info(_("Plugin XEP_0115 initialization")) | 81 info(_("Plugin XEP_0115 initialization")) |
82 self.host = host | 82 self.host = host |
83 host.trigger.add("Disco Handled", self.checkHash) | 83 host.trigger.add("Disco Handled", self.checkHash) |
84 self.hash_cache = PersistentBinaryDict(NS_ENTITY_CAPABILITY) #key = hash or jid, value = features | 84 self.hash_cache = PersistentBinaryDict(NS_ENTITY_CAPABILITY) #key = hash or jid, value = features |
85 self.hash_cache.load() | 85 self.hash_cache.load() |
86 self.jid_hash = {} #jid to hash mapping, map to a discoInfo features if the hash method is unknown | 86 self.jid_hash = {} #jid to hash mapping, map to a discoInfo features if the hash method is unknown |
87 | 87 |
88 def checkHash(self, profile): | 88 def checkHash(self, profile): |
89 if not XEP_0115.cap_hash: | 89 if not XEP_0115.cap_hash: |
90 XEP_0115.cap_hash = self.generateHash(profile) | 90 XEP_0115.cap_hash = self.generateHash(profile) |
91 else: | 91 else: |
92 self.presenceHack(profile) | 92 self.presenceHack(profile) |
93 return True | 93 return True |
94 | 94 |
95 def getHandler(self, profile): | 95 def getHandler(self, profile): |
96 return XEP_0115_handler(self, profile) | 96 return XEP_0115_handler(self, profile) |
97 | 97 |
98 def presenceHack(self, profile): | 98 def presenceHack(self, profile): |
99 """modify SatPresenceProtocol to add capabilities data""" | 99 """modify SatPresenceProtocol to add capabilities data""" |
125 | 125 |
126 client = self.host.getClient(profile_key) | 126 client = self.host.getClient(profile_key) |
127 if not client: | 127 if not client: |
128 error ('Requesting hash for an inexistant client') | 128 error ('Requesting hash for an inexistant client') |
129 raise HashGenerationError | 129 raise HashGenerationError |
130 | 130 |
131 def generateHash_2(services, profile): | 131 def generateHash_2(services, profile): |
132 _s=[] | 132 _s=[] |
133 byte_identities = [ByteIdentity(identity) for identity in filter(lambda x:isinstance(x,disco.DiscoIdentity),services)] #FIXME: lang must be managed here | 133 byte_identities = [ByteIdentity(identity) for identity in filter(lambda x:isinstance(x,disco.DiscoIdentity),services)] #FIXME: lang must be managed here |
134 byte_identities.sort(key=lambda i:i.lang) | 134 byte_identities.sort(key=lambda i:i.lang) |
135 byte_identities.sort(key=lambda i:i.idType) | 135 byte_identities.sort(key=lambda i:i.idType) |
144 _s.append('<') | 144 _s.append('<') |
145 #TODO: manage XEP-0128 data form here | 145 #TODO: manage XEP-0128 data form here |
146 XEP_0115.cap_hash = b64encode(sha1(''.join(_s)).digest()) | 146 XEP_0115.cap_hash = b64encode(sha1(''.join(_s)).digest()) |
147 debug(_('Capability hash generated: [%s]') % XEP_0115.cap_hash) | 147 debug(_('Capability hash generated: [%s]') % XEP_0115.cap_hash) |
148 self.presenceHack(profile) | 148 self.presenceHack(profile) |
149 | 149 |
150 services = client.discoHandler.info(client.jid, client.jid, '').addCallback(generateHash_2, profile) | 150 services = client.discoHandler.info(client.jid, client.jid, '').addCallback(generateHash_2, profile) |
151 | 151 |
152 class XEP_0115_handler(XMPPHandler): | 152 class XEP_0115_handler(XMPPHandler): |
153 implements(iwokkel.IDisco) | 153 implements(iwokkel.IDisco) |
154 | 154 |
155 def __init__(self, plugin_parent, profile): | 155 def __init__(self, plugin_parent, profile): |
156 self.plugin_parent = plugin_parent | 156 self.plugin_parent = plugin_parent |
157 self.host = plugin_parent.host | 157 self.host = plugin_parent.host |
158 self.profile = profile | 158 self.profile = profile |
159 | 159 |
160 def connectionInitialized(self): | 160 def connectionInitialized(self): |
161 self.xmlstream.addObserver(CAPABILITY_UPDATE, self.update) | 161 self.xmlstream.addObserver(CAPABILITY_UPDATE, self.update) |
162 | 162 |
163 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): | 163 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |
164 return [disco.DiscoFeature(NS_ENTITY_CAPABILITY)] | 164 return [disco.DiscoFeature(NS_ENTITY_CAPABILITY)] |
165 | 165 |
166 def getDiscoItems(self, requestor, target, nodeIdentifier=''): | 166 def getDiscoItems(self, requestor, target, nodeIdentifier=''): |
167 return [] | 167 return [] |