From 546a114cde1c7df4012023d1435b38bcbc8147d5 Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 12 Aug 2010 12:30:36 +0800 Subject: [PATCH] =?UTF-8?q?S=C3=A0T:=20plugin=200077=20&=200100:=20fixed?= =?UTF-8?q?=20profile=20management?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/plugin_xep_0077.py | 11 ++++++----- plugins/plugin_xep_0100.py | 16 +++++++++------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/plugins/plugin_xep_0077.py b/plugins/plugin_xep_0077.py index e9a51bcd..7d718b3d 100755 --- a/plugins/plugin_xep_0077.py +++ b/plugins/plugin_xep_0077.py @@ -50,9 +50,9 @@ class XEP_0077(): 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): + def addTrigger(self, target, cb, profile): """Add a callback which is called when registration to target is successful""" - self.triggers[target] = cb + self.triggers[target] = (cb, profile) def reg_ok(self, answer): """Called after the first get IQ""" @@ -99,7 +99,8 @@ class XEP_0077(): answer_data={"message":_("Registration successfull")} self.host.bridge.actionResult(answer_type, answer['id'], answer_data) if self.triggers.has_key(answer["from"]): - self.triggers[answer["from"]](answer["from"]) + callback,profile = self.triggers[answer["from"]] + callback(answer["from"], profile) del self.triggers[answer["from"]] def registrationFailure(self, failure): @@ -117,9 +118,9 @@ class XEP_0077(): if self.triggers.has_key(answer["from"]): del self.triggers[answer["from"]] - def in_band_submit(self, action, target, fields): + def in_band_submit(self, action, target, fields, profile): """Submit a form for registration, using data_form""" - id, deferred = self.host.submitForm(action, target, fields) + id, deferred = self.host.submitForm(action, target, fields, profile) if action == 'CANCEL': deferred.addCallbacks(self.unregistrationAnswer, self.unregistrationFailure) else: diff --git a/plugins/plugin_xep_0100.py b/plugins/plugin_xep_0100.py index e29b98ee..d8303b9e 100755 --- a/plugins/plugin_xep_0100.py +++ b/plugins/plugin_xep_0100.py @@ -44,7 +44,7 @@ class XEP_0100(): self.host = host self.__gateways = {} #dict used to construct the answer to findGateways. Key = target jid host.bridge.addMethod("findGateways", ".communication", in_sign='ss', out_sign='s', method=self.findGateways) - host.bridge.addMethod("gatewayRegister", ".request", in_sign='ssa(ss)', out_sign='s', method=self.gatewayRegister) + host.bridge.addMethod("gatewayRegister", ".request", in_sign='ssa(ss)s', out_sign='s', method=self.gatewayRegister) def __inc_handled_items(self, request_id): self.__gateways[request_id]['__handled_items']+=1 @@ -97,17 +97,19 @@ class XEP_0100(): self.host.bridge.actionResult("ERROR", request_id, message_data) - def registrationSuccessful(self, target): + def registrationSuccessful(self, target, profile): """Called when in_band registration is ok, we must now follow the rest of procedure""" debug (_("Registration successful, doing the rest")) - self.host.addContact(target) - self.host.setPresence(target) + self.host.addContact(target, profile) + self.host.setPresence(target, profile) - def gatewayRegister(self, action, target, fields): + def gatewayRegister(self, action, target, fields, profile_key='@DEFAULT@'): """Register gateway using in-band registration, then log-in to gateway""" + profile = self.host.memory.getProfileName(profile_key) + assert(profile) #FIXME: return an error here if action == 'SUBMIT': - self.host.plugins["XEP_0077"].addTrigger(target, self.registrationSuccessful) - return self.host.plugins["XEP_0077"].in_band_submit(action, target, fields) + self.host.plugins["XEP_0077"].addTrigger(target, self.registrationSuccessful, profile) + return self.host.plugins["XEP_0077"].in_band_submit(action, target, fields, profile) def findGateways(self, target, profile_key='@DEFAULT@'): """Find gateways in the target JID, using discovery protocol