diff 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
line wrap: on
line diff
--- a/plugins/plugin_xep_0077.py	Fri Jan 29 14:17:15 2010 +1100
+++ b/plugins/plugin_xep_0077.py	Sat Jan 30 16:17:33 2010 +1100
@@ -20,7 +20,7 @@
 """
 
 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 @@
         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 @@
             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)