comparison plugins/plugin_xep_0100.py @ 39:2e3411a6baad

Wix: external server management in gateways manager, SàT: bug fixes in gateway management - SàT: from twisted.words.protocols.jabber.error module imported as jab_error to avoir name colision with error log method - XEP_0100 plugin: added errback for disco info - XEP_0077 plugin: registration callback now look for "x" element (data form: see XEP-0004), and send an error message if it can't find it. - Wix: added fields for browsing external server gateways
author Goffi <goffi@goffi.org>
date Thu, 17 Dec 2009 17:29:02 +1100
parents a61beb21d16d
children 874de3020e1c
comparison
equal deleted inserted replaced
38:3e24753b9e0b 39:2e3411a6baad
19 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """ 20 """
21 21
22 from logging import debug, info, error 22 from logging import debug, info, error
23 from twisted.internet import protocol 23 from twisted.internet import protocol
24 from twisted.words.protocols.jabber import client, jid, xmlstream, error 24 from twisted.words.protocols.jabber import client, jid, xmlstream
25 from twisted.words.protocols.jabber import error as jab_error
25 import pdb 26 import pdb
26 27
27 from wokkel import disco, iwokkel 28 from wokkel import disco, iwokkel
28 29
29 PLUGIN_INFO = { 30 PLUGIN_INFO = {
41 info("Gateways plugin initialization") 42 info("Gateways plugin initialization")
42 self.host = host 43 self.host = host
43 self.__gateways = {} #dict used to construct the answer to findGateways. Key = target jid 44 self.__gateways = {} #dict used to construct the answer to findGateways. Key = target jid
44 host.bridge.addMethod("findGateways", ".communication", in_sign='s', out_sign='s', method=self.findGateways) 45 host.bridge.addMethod("findGateways", ".communication", in_sign='s', out_sign='s', method=self.findGateways)
45 host.bridge.addMethod("gatewayRegister", ".request", in_sign='ssa(ss)', out_sign='s', method=self.gatewayRegister) 46 host.bridge.addMethod("gatewayRegister", ".request", in_sign='ssa(ss)', out_sign='s', method=self.gatewayRegister)
46 47
48 def __inc_handled_items(self, request_id):
49 self.__gateways[request_id]['__handled_items']+=1
50
51 if self.__gateways[request_id]['__total_items'] == self.__gateways[request_id]['__handled_items']:
52 debug ("All items checked for id [%s]" % str(request_id))
53
54 del self.__gateways[request_id]['__total_items']
55 del self.__gateways[request_id]['__handled_items']
56 self.host.actionResultExt(request_id,"DICT_DICT",self.__gateways[request_id])
57
47 def discoInfo(self, disco, entity, request_id): 58 def discoInfo(self, disco, entity, request_id):
48 """Find disco infos about entity, to check if it is a gateway""" 59 """Find disco infos about entity, to check if it is a gateway"""
49 60
50 for identity in disco.identities: 61 for identity in disco.identities:
51 if identity[0] == 'gateway': 62 if identity[0] == 'gateway':
53 self.__gateways[request_id][entity.full()] = { 64 self.__gateways[request_id][entity.full()] = {
54 'name':disco.identities[identity], 65 'name':disco.identities[identity],
55 'type':identity[1] 66 'type':identity[1]
56 } 67 }
57 68
58 self.__gateways[request_id]['__handled_items']+=1 69 self.__inc_handled_items(request_id)
59 70
60 if self.__gateways[request_id]['__total_items'] == self.__gateways[request_id]['__handled_items']: 71 def discoInfoErr(self, failure, entity, request_id):
61 debug ("All items checked for id [%s]" % str(request_id)) 72 """Something is going wrong with disco"""
62 73 failure.trap(jab_error.StanzaError)
63 del self.__gateways[request_id]['__total_items'] 74 error("Error when discovering [%s]: %s" % (entity.full(), failure.value.condition))
64 del self.__gateways[request_id]['__handled_items'] 75 self.__inc_handled_items(request_id)
65 self.host.actionResultExt(request_id,"DICT_DICT",self.__gateways[request_id]) 76
66 77
67 def discoItems(self, disco, request_id): 78 def discoItems(self, disco, request_id):
68 """Look for items with disco protocol, and ask infos for each one""" 79 """Look for items with disco protocol, and ask infos for each one"""
69 80
70 if len(disco._items) == 0: 81 if len(disco._items) == 0:
74 85
75 self.__gateways[request_id] = {'__total_items':len(disco._items), '__handled_items':0} 86 self.__gateways[request_id] = {'__total_items':len(disco._items), '__handled_items':0}
76 for item in disco._items: 87 for item in disco._items:
77 debug ("item found: %s", item.name) 88 debug ("item found: %s", item.name)
78 self.host.disco.requestInfo(item.entity).addCallback(self.discoInfo, entity=item.entity, request_id=request_id) 89 self.host.disco.requestInfo(item.entity).addCallback(self.discoInfo, entity=item.entity, request_id=request_id)
90 self.host.disco.requestInfo(item.entity).addErrback(self.discoInfoErr, entity=item.entity, request_id=request_id)
79 91
80 def registrationSuccessful(self, target): 92 def registrationSuccessful(self, target):
81 """Called when in_band registration is ok, we must now follow the rest of procedure""" 93 """Called when in_band registration is ok, we must now follow the rest of procedure"""
82 print "Registration successful, doing the rest" 94 print "Registration successful, doing the rest"
83 self.host.addContact(target) 95 self.host.addContact(target)