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
This commit is contained in:
Goffi 2010-01-30 16:17:33 +11:00
commit 656bea30dd

View file

@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from logging import debug, info, error
from twisted.words.protocols.jabber import client, jid, xmlstream
from twisted.words.protocols.jabber import client, jid
from twisted.words.protocols.jabber import error as jab_error
from twisted.words.protocols.jabber.xmlstream import IQ
from twisted.internet import reactor
@ -47,7 +47,7 @@ class XEP_0077():
info("Plugin XEP_0077 initialization")
self.host = host
self.triggers = {} #used by other protocol (e.g. XEP-0100) to finish registration. key = target_jid
host.bridge.addMethod("in_band_register", ".communication", in_sign='s', out_sign='s', method=self.in_band_register)
host.bridge.addMethod("in_band_register", ".communication", in_sign='ss', out_sign='s', method=self.in_band_register)
host.bridge.addMethod("in_band_submit", ".request", in_sign='sa(ss)', out_sign='s', method=self.in_band_submit)
def addTrigger(self, target, cb):
@ -127,12 +127,16 @@ class XEP_0077():
deferred.addCallbacks(self.registrationAnswer, self.registrationFailure)
return id
def in_band_register(self, target):
def in_band_register(self, target, profile_key='@DEFAULT@'):
"""register to a target JID"""
current_jid, xmlstream = self.host.getJidNStream(profile_key)
if not xmlstream:
error ('Asking profile for an non-existant or not connected profile')
return ""
to_jid = jid.JID(target)
debug("Asking registration for [%s]" % to_jid.full())
reg_request=IQ(self.host.xmlstream,'get')
reg_request["from"]=self.host.me.full()
reg_request=IQ(xmlstream,'get')
reg_request["from"]=current_jid.full()
reg_request["to"] = to_jid.full()
query=reg_request.addElement('query', NS_REG)
reg_request.send(to_jid.full()).addCallbacks(self.reg_ok, self.reg_err)