Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0100.py @ 1049:9e24ca275ddd
plugin XEP-0100: fixes the call to log.debug (line 185)
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 04 Jun 2014 12:57:49 +0200 |
parents | 301b342c697a |
children | 069ad98b360d |
comparison
equal
deleted
inserted
replaced
1048:3f3dbb4c4fcf | 1049:9e24ca275ddd |
---|---|
37 } | 37 } |
38 | 38 |
39 WARNING_MSG = D_(u"""Be careful ! Gateways allow you to use an external IM (legacy IM), so you can see your contact as XMPP contacts. | 39 WARNING_MSG = D_(u"""Be careful ! Gateways allow you to use an external IM (legacy IM), so you can see your contact as XMPP contacts. |
40 But when you do this, all your messages go throught the external legacy IM server, it is a huge privacy issue (i.e.: all your messages throught the gateway can be monitored, recorded, analysed by the external server, most of time a private company).""") | 40 But when you do this, all your messages go throught the external legacy IM server, it is a huge privacy issue (i.e.: all your messages throught the gateway can be monitored, recorded, analysed by the external server, most of time a private company).""") |
41 | 41 |
42 GATEWAY_TIMEOUT = 10 # time to wait before cancelling a gateway disco info, in seconds | 42 GATEWAY_TIMEOUT = 10 # time to wait before cancelling a gateway disco info, in seconds |
43 | 43 |
44 TYPE_DESCRIPTIONS = { 'irc': D_("Internet Relay Chat"), | 44 TYPE_DESCRIPTIONS = {'irc': D_("Internet Relay Chat"), |
45 'xmpp': D_("XMPP"), | 45 'xmpp': D_("XMPP"), |
46 'qq': D_("Tencent QQ"), | 46 'qq': D_("Tencent QQ"), |
47 'simple': D_("SIP/SIMPLE"), | 47 'simple': D_("SIP/SIMPLE"), |
48 'icq': D_("ICQ"), | 48 'icq': D_("ICQ"), |
49 'yahoo': D_("Yahoo! Messenger"), | 49 'yahoo': D_("Yahoo! Messenger"), |
50 'gadu-gadu': D_("Gadu-Gadu"), | 50 'gadu-gadu': D_("Gadu-Gadu"), |
51 'aim': D_("AOL Instant Messenger"), | 51 'aim': D_("AOL Instant Messenger"), |
52 'msn': D_("Windows Live Messenger"), | 52 'msn': D_("Windows Live Messenger"), |
53 } | 53 } |
54 | 54 |
55 | 55 |
56 class XEP_0100(object): | 56 class XEP_0100(object): |
57 | 57 |
62 host.bridge.addMethod("findGateways", ".plugin", in_sign='ss', out_sign='s', method=self._findGateways) | 62 host.bridge.addMethod("findGateways", ".plugin", in_sign='ss', out_sign='s', method=self._findGateways) |
63 host.bridge.addMethod("gatewayRegister", ".plugin", in_sign='ss', out_sign='s', method=self._gatewayRegister) | 63 host.bridge.addMethod("gatewayRegister", ".plugin", in_sign='ss', out_sign='s', method=self._gatewayRegister) |
64 self.__menu_id = host.registerCallback(self._gatewaysMenu, with_data=True) | 64 self.__menu_id = host.registerCallback(self._gatewaysMenu, with_data=True) |
65 self.__selected_id = host.registerCallback(self._gatewaySelectedCb, with_data=True) | 65 self.__selected_id = host.registerCallback(self._gatewaySelectedCb, with_data=True) |
66 host.importMenu((D_("Service"), D_("gateways")), self._gatewaysMenu, security_limit=2, help_string=D_("Find gateways")) | 66 host.importMenu((D_("Service"), D_("gateways")), self._gatewaysMenu, security_limit=2, help_string=D_("Find gateways")) |
67 | |
68 | 67 |
69 def _gatewaysMenu(self, data, profile): | 68 def _gatewaysMenu(self, data, profile): |
70 """ XMLUI activated by menu: return Gateways UI | 69 """ XMLUI activated by menu: return Gateways UI |
71 @param profile: %(doc_profile)s | 70 @param profile: %(doc_profile)s |
72 | 71 |
166 ret.append((success, (msg, items[idx]))) | 165 ret.append((success, (msg, items[idx]))) |
167 else: | 166 else: |
168 entity = items[idx].entity | 167 entity = items[idx].entity |
169 gateways = [(identity, result.identities[identity]) for identity in result.identities if identity[0] == 'gateway'] | 168 gateways = [(identity, result.identities[identity]) for identity in result.identities if identity[0] == 'gateway'] |
170 if gateways: | 169 if gateways: |
171 log.info (_("Found gateway [%(jid)s]: %(identity_name)s") % {'jid': entity.full(), 'identity_name': ' - '.join([gateway[1] for gateway in gateways])}) | 170 log.info(_("Found gateway [%(jid)s]: %(identity_name)s") % {'jid': entity.full(), 'identity_name': ' - '.join([gateway[1] for gateway in gateways])}) |
172 ret.append((success, (entity, gateways))) | 171 ret.append((success, (entity, gateways))) |
173 else: | 172 else: |
174 log.info(_("Skipping [%(jid)s] which is not a gateway") % {'jid': entity.full()}) | 173 log.info(_("Skipping [%(jid)s] which is not a gateway") % {'jid': entity.full()}) |
175 return ret | 174 return ret |
176 | 175 |
181 log.debug(_("No gateway found")) | 180 log.debug(_("No gateway found")) |
182 return [] | 181 return [] |
183 | 182 |
184 _defers = [] | 183 _defers = [] |
185 for item in disco._items: | 184 for item in disco._items: |
186 log.debug(_("item found: %s"), item.entity) | 185 log.debug(_("item found: %s") % item.entity) |
187 _defers.append(client.disco.requestInfo(item.entity)) | 186 _defers.append(client.disco.requestInfo(item.entity)) |
188 dl = defer.DeferredList(_defers) | 187 dl = defer.DeferredList(_defers) |
189 dl.addCallback(self._infosReceived, items=disco._items, target=target, client=client) | 188 dl.addCallback(self._infosReceived, items=disco._items, target=target, client=client) |
190 reactor.callLater(GATEWAY_TIMEOUT, dl.cancel) | 189 reactor.callLater(GATEWAY_TIMEOUT, dl.cancel) |
191 return dl | 190 return dl |
192 | |
193 | 191 |
194 def _findGateways(self, target_jid_s, profile_key): | 192 def _findGateways(self, target_jid_s, profile_key): |
195 target_jid = jid.JID(target_jid_s) | 193 target_jid = jid.JID(target_jid_s) |
196 profile = self.host.memory.getProfileName(profile_key) | 194 profile = self.host.memory.getProfileName(profile_key) |
197 if not profile: | 195 if not profile: |
199 d = self.findGateways(target_jid, profile) | 197 d = self.findGateways(target_jid, profile) |
200 d.addCallback(self._gatewaysResult2XMLUI, target_jid) | 198 d.addCallback(self._gatewaysResult2XMLUI, target_jid) |
201 d.addCallback(lambda xmlui: xmlui.toXml()) | 199 d.addCallback(lambda xmlui: xmlui.toXml()) |
202 return d | 200 return d |
203 | 201 |
204 | |
205 def findGateways(self, target, profile): | 202 def findGateways(self, target, profile): |
206 """Find gateways in the target JID, using discovery protocol | 203 """Find gateways in the target JID, using discovery protocol |
207 """ | 204 """ |
208 client = self.host.getClient(profile) | 205 client = self.host.getClient(profile) |
209 log.debug(_("find gateways (target = %(target)s, profile = %(profile)s)") % {'target': target.full(), 'profile': profile}) | 206 log.debug(_("find gateways (target = %(target)s, profile = %(profile)s)") % {'target': target.full(), 'profile': profile}) |
210 d = client.disco.requestItems(target) | 207 d = client.disco.requestItems(target) |
211 d.addCallback(self._itemsReceived , target=target, client=client) | 208 d.addCallback(self._itemsReceived, target=target, client=client) |
212 return d | 209 return d |