comparison plugins/plugin_xep_0077.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 86f1f7f6d332
comparison
equal deleted inserted replaced
63:0db25931b60d 64:d46f849664aa
18 You should have received a copy of the GNU General Public License 18 You should have received a copy of the GNU General Public License
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.words.protocols.jabber import client, jid, xmlstream 23 from twisted.words.protocols.jabber import client, jid
24 from twisted.words.protocols.jabber import error as jab_error 24 from twisted.words.protocols.jabber import error as jab_error
25 from twisted.words.protocols.jabber.xmlstream import IQ 25 from twisted.words.protocols.jabber.xmlstream import IQ
26 from twisted.internet import reactor 26 from twisted.internet import reactor
27 from tools.xml_tools import XMLTools 27 from tools.xml_tools import XMLTools
28 import pdb 28 import pdb
45 45
46 def __init__(self, host): 46 def __init__(self, host):
47 info("Plugin XEP_0077 initialization") 47 info("Plugin XEP_0077 initialization")
48 self.host = host 48 self.host = host
49 self.triggers = {} #used by other protocol (e.g. XEP-0100) to finish registration. key = target_jid 49 self.triggers = {} #used by other protocol (e.g. XEP-0100) to finish registration. key = target_jid
50 host.bridge.addMethod("in_band_register", ".communication", in_sign='s', out_sign='s', method=self.in_band_register) 50 host.bridge.addMethod("in_band_register", ".communication", in_sign='ss', out_sign='s', method=self.in_band_register)
51 host.bridge.addMethod("in_band_submit", ".request", in_sign='sa(ss)', out_sign='s', method=self.in_band_submit) 51 host.bridge.addMethod("in_band_submit", ".request", in_sign='sa(ss)', out_sign='s', method=self.in_band_submit)
52 52
53 def addTrigger(self, target, cb): 53 def addTrigger(self, target, cb):
54 """Add a callback which is called when registration to target is successful""" 54 """Add a callback which is called when registration to target is successful"""
55 self.triggers[target] = cb 55 self.triggers[target] = cb
125 deferred.addCallbacks(self.unregistrationAnswer, self.unregistrationFailure) 125 deferred.addCallbacks(self.unregistrationAnswer, self.unregistrationFailure)
126 else: 126 else:
127 deferred.addCallbacks(self.registrationAnswer, self.registrationFailure) 127 deferred.addCallbacks(self.registrationAnswer, self.registrationFailure)
128 return id 128 return id
129 129
130 def in_band_register(self, target): 130 def in_band_register(self, target, profile_key='@DEFAULT@'):
131 """register to a target JID""" 131 """register to a target JID"""
132 current_jid, xmlstream = self.host.getJidNStream(profile_key)
133 if not xmlstream:
134 error ('Asking profile for an non-existant or not connected profile')
135 return ""
132 to_jid = jid.JID(target) 136 to_jid = jid.JID(target)
133 debug("Asking registration for [%s]" % to_jid.full()) 137 debug("Asking registration for [%s]" % to_jid.full())
134 reg_request=IQ(self.host.xmlstream,'get') 138 reg_request=IQ(xmlstream,'get')
135 reg_request["from"]=self.host.me.full() 139 reg_request["from"]=current_jid.full()
136 reg_request["to"] = to_jid.full() 140 reg_request["to"] = to_jid.full()
137 query=reg_request.addElement('query', NS_REG) 141 query=reg_request.addElement('query', NS_REG)
138 reg_request.send(to_jid.full()).addCallbacks(self.reg_ok, self.reg_err) 142 reg_request.send(to_jid.full()).addCallbacks(self.reg_ok, self.reg_err)
139 return reg_request["id"] 143 return reg_request["id"]