comparison plugins/plugin_xep_0100.py @ 64:d46f849664aa

SàT: multi-profile, plugins updated - core: 2 new convenient methods: getJidNStream and getClient - new param in plugin info: "handler" to know if there is a handler to plug on profiles clients - plugins with handler now use an other class which is returned to profile client with the new method "getHandler" and pluged when connecting
author Goffi <goffi@goffi.org>
date Sat, 30 Jan 2010 16:17:33 +1100
parents a5b5fb5fc9fd
children d35c5edab53f
comparison
equal deleted inserted replaced
63:0db25931b60d 64:d46f849664aa
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 24 from twisted.words.protocols.jabber import client, jid
25 from twisted.words.protocols.jabber import error as jab_error 25 from twisted.words.protocols.jabber import error as jab_error
26 import pdb 26 import pdb
27 27
28 from wokkel import disco, iwokkel 28 from wokkel import disco, iwokkel
29 29
74 failure.trap(jab_error.StanzaError) 74 failure.trap(jab_error.StanzaError)
75 error("Error when discovering [%s]: %s" % (entity.full(), failure.value.condition)) 75 error("Error when discovering [%s]: %s" % (entity.full(), failure.value.condition))
76 self.__inc_handled_items(request_id) 76 self.__inc_handled_items(request_id)
77 77
78 78
79 def discoItems(self, disco, request_id, target): 79 def discoItems(self, disco, request_id, target, client):
80 """Look for items with disco protocol, and ask infos for each one""" 80 """Look for items with disco protocol, and ask infos for each one"""
81 #FIXME: target is used as we can't find the original iq node (parent is None) 81 #FIXME: target is used as we can't find the original iq node (parent is None)
82 # an other way would avoid this useless parameter (is there a way with wokkel ?) 82 # an other way would avoid this useless parameter (is there a way with wokkel ?)
83 if len(disco._items) == 0: 83 if len(disco._items) == 0:
84 debug ("No gateway found") 84 debug ("No gateway found")
86 return 86 return
87 87
88 self.__gateways[request_id] = {'__total_items':len(disco._items), '__handled_items':0, '__private__':{'target':target.full()}} 88 self.__gateways[request_id] = {'__total_items':len(disco._items), '__handled_items':0, '__private__':{'target':target.full()}}
89 for item in disco._items: 89 for item in disco._items:
90 debug ("item found: %s", item.name) 90 debug ("item found: %s", item.name)
91 self.host.disco.requestInfo(item.entity).addCallback(self.discoInfo, entity=item.entity, request_id=request_id) 91 client.disco.requestInfo(item.entity).addCallback(self.discoInfo, entity=item.entity, request_id=request_id)
92 self.host.disco.requestInfo(item.entity).addErrback(self.discoInfoErr, entity=item.entity, request_id=request_id) 92 client.disco.requestInfo(item.entity).addErrback(self.discoInfoErr, entity=item.entity, request_id=request_id)
93 93
94 def registrationSuccessful(self, target): 94 def registrationSuccessful(self, target):
95 """Called when in_band registration is ok, we must now follow the rest of procedure""" 95 """Called when in_band registration is ok, we must now follow the rest of procedure"""
96 print "Registration successful, doing the rest" 96 print "Registration successful, doing the rest"
97 self.host.addContact(target) 97 self.host.addContact(target)
101 """Register gateway using in-band registration, then log-in to gateway""" 101 """Register gateway using in-band registration, then log-in to gateway"""
102 if action == 'SUBMIT': 102 if action == 'SUBMIT':
103 self.host.plugins["XEP_0077"].addTrigger(target, self.registrationSuccessful) 103 self.host.plugins["XEP_0077"].addTrigger(target, self.registrationSuccessful)
104 return self.host.plugins["XEP_0077"].in_band_submit(action, target, fields) 104 return self.host.plugins["XEP_0077"].in_band_submit(action, target, fields)
105 105
106 def findGateways(self, target): 106 def findGateways(self, target, profile_key='@DEFAULT@'):
107 """Find gateways in the target JID, using discovery protocol 107 """Find gateways in the target JID, using discovery protocol
108 Return an id used for retrieving the list of gateways 108 Return an id used for retrieving the list of gateways
109 """ 109 """
110 client = self.host.getClient(profile_key)
111 assert(client)
110 to_jid = jid.JID(target) 112 to_jid = jid.JID(target)
111 debug ("find gateways (target = %s)" % to_jid.full()) 113 debug ("find gateways (target = %s)" % to_jid.full())
112 request_id = self.host.get_next_id() 114 request_id = self.host.get_next_id()
113 self.host.disco.requestItems(to_jid).addCallback(self.discoItems, request_id=request_id, target = to_jid) 115 client.disco.requestItems(to_jid).addCallback(self.discoItems, request_id=request_id, target = to_jid, client = client)
114 return request_id 116 return request_id