comparison src/core/sat_main.py @ 1725:c1be6363bfab

core, plugin misc_account: set XMPP connection max retries to 0 when checking if an external account exists
author souliane <souliane@mailoo.org>
date Mon, 07 Dec 2015 19:56:12 +0100
parents 3c608d660f0b
children d17772b0fe22
comparison
equal deleted inserted replaced
1724:13e43b2cd7a2 1725:c1be6363bfab
249 249
250 def _asyncConnect(self, profile_key, password=''): 250 def _asyncConnect(self, profile_key, password=''):
251 profile = self.memory.getProfileName(profile_key) 251 profile = self.memory.getProfileName(profile_key)
252 return self.asyncConnect(profile, password) 252 return self.asyncConnect(profile, password)
253 253
254 def asyncConnect(self, profile, password=''): 254 def asyncConnect(self, profile, password='', max_retries=C.XMPP_MAX_RETRIES):
255 """Retrieve the individual parameters, authenticate the profile 255 """Retrieve the individual parameters, authenticate the profile
256 and initiate the connection to the associated XMPP server. 256 and initiate the connection to the associated XMPP server.
257 257
258 @param profile: %(doc_profile)s
258 @param password (string): the SàT profile password 259 @param password (string): the SàT profile password
259 @param profile: %(doc_profile)s 260 @param max_retries (int): max number of connection retries
260 @return (D(bool)): 261 @return (D(bool)):
261 - True if the XMPP connection was already established 262 - True if the XMPP connection was already established
262 - False if the XMPP connection has been initiated (it may still fail) 263 - False if the XMPP connection has been initiated (it may still fail)
263 @raise exceptions.PasswordError: Profile password is wrong 264 @raise exceptions.PasswordError: Profile password is wrong
264 """ 265 """
265 def connectXMPPClient(dummy=None): 266 def connectXMPPClient(dummy=None):
266 if self.isConnected(profile): 267 if self.isConnected(profile):
267 log.info(_("already connected !")) 268 log.info(_("already connected !"))
268 return True 269 return True
269 d = self._connectXMPPClient(profile) 270 d = self._connectXMPPClient(profile, max_retries)
270 return d.addCallback(lambda dummy: False) 271 return d.addCallback(lambda dummy: False)
271 272
272 d = self.memory.startSession(password, profile) 273 d = self.memory.startSession(password, profile)
273 d.addCallback(connectXMPPClient) 274 d.addCallback(connectXMPPClient)
274 return d 275 return d
275 276
276 @defer.inlineCallbacks 277 @defer.inlineCallbacks
277 def _connectXMPPClient(self, profile): 278 def _connectXMPPClient(self, profile, max_retries):
278 """This part is called from asyncConnect when we have loaded individual parameters from memory""" 279 """This part is called from asyncConnect when we have loaded individual parameters from memory"""
279 try: 280 try:
280 port = int(self.memory.getParamA(C.FORCE_PORT_PARAM, "Connection", profile_key=profile)) 281 port = int(self.memory.getParamA(C.FORCE_PORT_PARAM, "Connection", profile_key=profile))
281 except ValueError: 282 except ValueError:
282 log.debug(_("Can't parse port value, using default value")) 283 log.debug(_("Can't parse port value, using default value"))
283 port = None # will use default value 5222 or be retrieved from a DNS SRV record 284 port = None # will use default value 5222 or be retrieved from a DNS SRV record
284 285
285 password = yield self.memory.asyncGetParamA("Password", "Connection", profile_key=profile) 286 password = yield self.memory.asyncGetParamA("Password", "Connection", profile_key=profile)
286 current = self.profiles[profile] = xmpp.SatXMPPClient(self, profile, 287 current = self.profiles[profile] = xmpp.SatXMPPClient(self, profile,
287 jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key=profile)), 288 jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key=profile)),
288 password, self.memory.getParamA(C.FORCE_SERVER_PARAM, "Connection", profile_key=profile), port) 289 password, self.memory.getParamA(C.FORCE_SERVER_PARAM, "Connection", profile_key=profile),
290 port, max_retries)
289 291
290 current.messageProt = xmpp.SatMessageProtocol(self) 292 current.messageProt = xmpp.SatMessageProtocol(self)
291 current.messageProt.setHandlerParent(current) 293 current.messageProt.setHandlerParent(current)
292 294
293 current.roster = xmpp.SatRosterProtocol(self) 295 current.roster = xmpp.SatRosterProtocol(self)