diff src/plugins/plugin_xep_0077.py @ 538:2c4016921403

core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles - added profile argument to askConfirmation, actionResult, actionResultExt, entityDataUpdated, confirmationAnswer, getProgress - core, frontends: fixed calls/signals according to new bridge API - user of proper profile namespace for progression indicators and dialogs - memory: getParam* now return bool when param type is bool - memory: added getStringParam* to return string instead of typed value - core, memory, storage, quick_frontend: getHistory now manage properly multi-profiles - plugins XEP-0047, XEP-0054, XEP-0065, XEP-0077, XEP-0096; multi-profiles proper handling
author Goffi <goffi@goffi.org>
date Sat, 10 Nov 2012 16:38:16 +0100
parents 2a072735e459
children caad23285a38
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0077.py	Sun Nov 04 23:53:26 2012 +0100
+++ b/src/plugins/plugin_xep_0077.py	Sat Nov 10 16:38:16 2012 +0100
@@ -54,7 +54,7 @@
         """Add a callback which is called when registration to target is successful"""
         self.triggers[target] = (cb, profile)
     
-    def reg_ok(self, answer):
+    def reg_ok(self, answer, profile):
         """Called after the first get IQ"""
         try:
             x_elem = filter (lambda x:x.name == "x", answer.firstChildElement().elements())[0] #We only want the "x" element (data form)
@@ -63,47 +63,47 @@
             #TODO: manage registration without data form
             answer_data={"reason": "unmanaged", "message":_("This gateway can't be managed by SàT, sorry :(")}
             answer_type = "ERROR"
-            self.host.bridge.actionResult(answer_type, answer['id'], answer_data)
+            self.host.bridge.actionResult(answer_type, answer['id'], answer_data, profile)
             return
         
         form = data_form.Form.fromElement(x_elem)
         xml_data = dataForm2xml(form)
-        self.host.bridge.actionResult("XMLUI", answer['id'], {"target":answer["from"], "type":"registration", "xml":xml_data})
+        self.host.bridge.actionResult("XMLUI", answer['id'], {"target":answer["from"], "type":"registration", "xml":xml_data}, profile)
 
-    def reg_err(self, failure):
+    def reg_err(self, failure, profile):
         """Called when something is wrong with registration"""
         info (_("Registration failure: %s") % str(failure.value))
         answer_data = {}
         answer_data['reason'] = 'unknown'
         answer_data={"message":"%s [code: %s]" % (failure.value.condition, unicode(failure.value))}
         answer_type = "ERROR"
-        self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data)
+        self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data, profile)
    
-    def unregistrationAnswer(self, answer):
+    def unregistrationAnswer(self, answer, profile):
         debug (_("registration answer: %s") % answer.toXml())
         answer_type = "SUCCESS"
         answer_data={"message":_("Your are now unregistred")}
-        self.host.bridge.actionResult(answer_type, answer['id'], answer_data)
+        self.host.bridge.actionResult(answer_type, answer['id'], answer_data, profile)
         
-    def unregistrationFailure(self, failure):
+    def unregistrationFailure(self, failure, profile):
         info (_("Unregistration failure: %s") % str(failure.value))
         answer_type = "ERROR"
         answer_data = {}
         answer_data['reason'] = 'unknown'
         answer_data={"message":_("Unregistration failed: %s") % failure.value.condition}
-        self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data)
+        self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data, profile)
     
-    def registrationAnswer(self, answer):
+    def registrationAnswer(self, answer, profile):
         debug (_("registration answer: %s") % answer.toXml())
         answer_type = "SUCCESS"
         answer_data={"message":_("Registration successfull")}
-        self.host.bridge.actionResult(answer_type, answer['id'], answer_data)
+        self.host.bridge.actionResult(answer_type, answer['id'], answer_data, profile)
         if self.triggers.has_key(answer["from"]):
             callback,profile = self.triggers[answer["from"]]
             callback(answer["from"], profile)
             del self.triggers[answer["from"]]
         
-    def registrationFailure(self, failure):
+    def registrationFailure(self, failure, profile):
         info (_("Registration failure: %s") % str(failure.value))
         print failure.value.stanza.toXml()
         answer_type = "ERROR"
@@ -114,7 +114,7 @@
         else:
             answer_data['reason'] = 'unknown'
             answer_data={"message":_("Registration failed")}
-        self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data)
+        self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data, profile)
         if self.triggers.has_key(answer["from"]):
             del self.triggers[answer["from"]]
 
@@ -122,22 +122,22 @@
         """Submit a form for registration, using data_form"""
         id, deferred = self.host.submitForm(action, target, fields, profile)
         if action == 'CANCEL':
-            deferred.addCallbacks(self.unregistrationAnswer, self.unregistrationFailure)
+            deferred.addCallbacks(self.unregistrationAnswer, self.unregistrationFailure, callbackArgs=[profile], errbackArgs=[profile])
         else:    
-            deferred.addCallbacks(self.registrationAnswer, self.registrationFailure)
+            deferred.addCallbacks(self.registrationAnswer, self.registrationFailure, callbackArgs=[profile], errbackArgs=[profile])
         return id
     
     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:
+        client = self.host.getClient(profile_key)
+        if not client:
             error (_('Asking 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(xmlstream,'get')
-        reg_request["from"]=current_jid.full()
+        reg_request=IQ(client.xmlstream,'get')
+        reg_request["from"]=client.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)
+        reg_request.send(to_jid.full()).addCallbacks(self.reg_ok, self.reg_err, callbackArgs=[profile], errbackArgs=[profile])
         return reg_request["id"]