From 3a8a6e4d8d8dbe2e79f61b823656cef8c3785e32 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Thu, 7 Jul 2005 20:45:24 +0000 Subject: [PATCH] new_account is back ! getRegInfo can be synchronous if we want --- src/common/connection.py | 50 ++++++++++++++++++++++++------------- src/common/xmpp/features.py | 7 ++++-- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index f40917ac8..a302f1a47 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -128,6 +128,7 @@ class Connection: self.gpg = None self.status = '' self.myVCardID = [] + self.new_account_info = None self.bookmarks = [] self.on_purpose = False self.last_incoming = time.time() @@ -623,6 +624,25 @@ class Connection: if realm == common.xmpp.NS_REGISTER: if event == common.xmpp.features.REGISTER_DATA_RECEIVED: # data is (agent, DataFrom) + if self.new_account_info and self.new_account_info['hostname'] == data[0]: + #it's a new account + req = data[1].asDict() + req['username'] = self.new_account_info['name'] + req['password'] = self.new_account_info['password'] + if not common.xmpp.features.register(self.connection, data[0], req): + self.dispatch('ERROR', (_('Error:'), self.connection.lastErr)) + return + self.connected = 0 + self.password = self.new_account_info['password'] + if USE_GPG: + self.gpg = GnuPG.GnuPG() + gajim.config.set('usegpg', True) + else: + gajim.config.set('usegpg', False) + self.dispatch('ACC_OK', (self.name, self.new_account_info)) + gajim.connections[self.name] = self + self.new_account_info = None + return self.dispatch('REGISTER_AGENT_INFO', (data[0], data[1].asDict())) def connect(self): @@ -930,7 +950,7 @@ class Connection: def request_register_agent_info(self, agent): if not self.connection: return None - common.xmpp.features.getRegInfo(self.connection, agent) + common.xmpp.features.getRegInfo(self.connection, agent, sync = False) def register_agent(self, agent, info): if not self.connection: @@ -938,7 +958,14 @@ class Connection: # FIXME: Blocking common.xmpp.features.register(self.connection, agent, info) - def new_account(self, name, config): + def new_account(self, name, config, sync = False): + if sync: + self.new_account2(name, config) + else: + t = threading.Thread(target=self.new_account2, args = (name, config)) + t.start() + + def new_account2(self, name, config): # If a connection already exist we cannot create a new account if self.connection: return @@ -976,22 +1003,11 @@ class Connection: return False gajim.log.debug('Connected to server with %s', con_type) - req = common.xmpp.features.getRegInfo(c, config['hostname']).asDict() - req['username'] = config['name'] - req['password'] = config['password'] - if not common.xmpp.features.register(c, config['hostname'], req): - self.dispatch('ERROR', (_('Error:'), c.lastErr)) - return False + c.RegisterEventHandler(self._event_dispatcher) + self.new_account_info = config + self.connection = c self.name = name - self.connected = 0 - self.password = config['password'] - if USE_GPG: - self.gpg = GnuPG.GnuPG() - gajim.config.set('usegpg', True) - else: - gajim.config.set('usegpg', False) - gajim.connections[name] = self - self.dispatch('ACC_OK', (name, config)) + common.xmpp.features.getRegInfo(c, config['hostname']) def account_changed(self, new_name): self.name = new_name diff --git a/src/common/xmpp/features.py b/src/common/xmpp/features.py index 54d8cb53b..e5065c1a5 100644 --- a/src/common/xmpp/features.py +++ b/src/common/xmpp/features.py @@ -76,7 +76,7 @@ def discoverInfo(disp,jid,node=None): return identities , features ### Registration ### jabber:iq:register ### JEP-0077 ########################### -def getRegInfo(disp,host,info={}): +def getRegInfo(disp,host,info={},sync=True): """ Gets registration form from remote host. You can pre-fill the info dictionary. F.e. if you are requesting info on registering user joey than specify @@ -84,7 +84,10 @@ def getRegInfo(disp,host,info={}): 'disp' must be connected dispatcher instance.""" iq=Iq('get',NS_REGISTER,to=host) for i in info.keys(): iq.setTagData(i,info[i]) - disp.SendAndCallForResponse(iq,_ReceivedRegInfo, {'agent': host}) + if sync: + resp=disp.SendAndWaitForResponse(iq) + _ReceivedRegInfo(disp.Dispatcher,resp, host) + else: disp.SendAndCallForResponse(iq,_ReceivedRegInfo, {'agent': host}) def _ReceivedRegInfo(con, resp, agent): iq=Iq('get',NS_REGISTER,to=agent)