# HG changeset patch # User souliane # Date 1403511793 -7200 # Node ID 8e0072754413f67311fe65bd3eac4323863707f8 # Parent b29452cab50b7a040b2bf80502eafe2888eb8fcb core, plugins, stdui, frontends: fixes handling of "Force server" and "Force port" parameters: - do not save a "guessed" value, they must stay empty until the user explicitely sets them - add constant XMPP_C2S_PORT (default value 5222) diff -r b29452cab50b -r 8e0072754413 frontends/src/jp/cmd_profile.py --- a/frontends/src/jp/cmd_profile.py Mon Jun 23 00:44:10 2014 +0200 +++ b/frontends/src/jp/cmd_profile.py Mon Jun 23 10:23:13 2014 +0200 @@ -95,7 +95,6 @@ def _profile_created(self): self.host.bridge.setParam("JabberID", self.args.jid, "Connection" ,profile_key=self.args.profile) - self.host.bridge.setParam(C.FORCE_SERVER_PARAM, JID(self.args.jid).domain, "Connection", profile_key=self.args.profile) self.host.bridge.setParam("Password", self.args.password, "Connection", profile_key=self.args.profile) self.host.quit() diff -r b29452cab50b -r 8e0072754413 frontends/src/primitivus/profile_manager.py --- a/frontends/src/primitivus/profile_manager.py Mon Jun 23 00:44:10 2014 +0200 +++ b/frontends/src/primitivus/profile_manager.py Mon Jun 23 10:23:13 2014 +0200 @@ -167,7 +167,6 @@ if old_jid != new_jid: self.host.bridge.setParam("JabberID", new_jid, "Connection", profile_key=profile) - self.host.bridge.setParam(C.FORCE_SERVER_PARAM, JID(new_jid).domain, "Connection", profile_key=profile) if old_pass != new_pass: self.host.bridge.setParam("Password", new_pass, "Connection", profile_key=profile) self.host.plug_profile(profile) diff -r b29452cab50b -r 8e0072754413 frontends/src/wix/profile_manager.py --- a/frontends/src/wix/profile_manager.py Mon Jun 23 00:44:10 2014 +0200 +++ b/frontends/src/wix/profile_manager.py Mon Jun 23 10:23:13 2014 +0200 @@ -174,7 +174,6 @@ if old_jid != new_jid: log.debug(_('Saving new JID and server')) self.host.bridge.setParam("JabberID", new_jid, "Connection", profile_key=profile) - self.host.bridge.setParam(C.FORCE_SERVER_PARAM, JID(new_jid).domain, "Connection", profile_key=profile) if old_pass != new_pass: log.debug(_('Saving new password')) self.host.bridge.setParam("Password", new_pass, "Connection", profile_key=profile) diff -r b29452cab50b -r 8e0072754413 frontends/src/wix/xmlui.py --- a/frontends/src/wix/xmlui.py Mon Jun 23 00:44:10 2014 +0200 +++ b/frontends/src/wix/xmlui.py Mon Jun 23 10:23:13 2014 +0200 @@ -315,14 +315,6 @@ def onParamChange(self, ctrl): super(XMLUI, self).onParamChange(ctrl) - ### FIXME # Some hacks for better presentation, should be generic # FIXME ### - param_name = ctrl._xmlui_name.split(Const.SAT_PARAM_SEPARATOR)[1] - if (ctrl._param_category, param_name) == ('Connection', 'JabberID'): - domain = JID(ctrl._xmluiGetValue()).domain - for widget in (ctl['control'] for ctl in self.ctrl_list.values()): - if (widget._param_category, widget._param_name) == ('Connection', C.FORCE_SERVER_PARAM): - widget.SetValue(domain) - break def onFormSubmitted(self, event): """Called when submit button is clicked""" diff -r b29452cab50b -r 8e0072754413 src/core/constants.py --- a/src/core/constants.py Mon Jun 23 00:44:10 2014 +0200 +++ b/src/core/constants.py Mon Jun 23 10:23:13 2014 +0200 @@ -36,6 +36,10 @@ APP_URL = 'http://salut-a-toi.org' + # Protocol + XMPP_C2S_PORT = 5222 + + ## Parameters ## NO_SECURITY_LIMIT = -1 INDIVIDUAL = "individual" diff -r b29452cab50b -r 8e0072754413 src/core/sat_main.py --- a/src/core/sat_main.py Mon Jun 23 00:44:10 2014 +0200 +++ b/src/core/sat_main.py Mon Jun 23 10:23:13 2014 +0200 @@ -223,7 +223,7 @@ port = int(self.memory.getParamA(C.FORCE_PORT_PARAM, "Connection", profile_key=profile)) except ValueError: log.error(_("Can't parse port value, using default value")) - port = 5222 + port = None # will use default value 5222 or be retrieved from a DNS SRV record password = yield self.memory.asyncGetParamA("Password", "Connection", profile_key=profile) current = self.profiles[profile] = xmpp.SatXMPPClient(self, profile, diff -r b29452cab50b -r 8e0072754413 src/core/xmpp.py --- a/src/core/xmpp.py Mon Jun 23 00:44:10 2014 +0200 +++ b/src/core/xmpp.py Mon Jun 23 10:23:13 2014 +0200 @@ -36,10 +36,10 @@ class SatXMPPClient(client.XMPPClient): implements(iwokkel.IDisco) - def __init__(self, host_app, profile, user_jid, password, host=None, port=5222): + def __init__(self, host_app, profile, user_jid, password, host=None, port=C.XMPP_C2S_PORT): # XXX: DNS SRV records are checked when the host is not specified. # If no SRV record is found, the host is directly extracted from the JID. - client.XMPPClient.__init__(self, user_jid, password, host or None, port or 5222) + client.XMPPClient.__init__(self, user_jid, password, host or None, port or C.XMPP_C2S_PORT) self.factory.clientConnectionLost = self.connectionLost self.__connected = False self.profile = profile diff -r b29452cab50b -r 8e0072754413 src/plugins/plugin_misc_account.py --- a/src/plugins/plugin_misc_account.py Mon Jun 23 00:44:10 2014 +0200 +++ b/src/plugins/plugin_misc_account.py Mon Jun 23 10:23:13 2014 +0200 @@ -192,8 +192,6 @@ #FIXME: values must be in a config file instead of hardcoded self.host.memory.setParam("JabberID", "%s@%s/%s" % (profile, self.getConfig('new_account_domain'), self.getConfig('new_account_resource')), "Connection", profile_key=profile) - self.host.memory.setParam(C.FORCE_SERVER_PARAM, self.getConfig('new_account_server'), - "Connection", profile_key=profile) self.host.memory.setParam("Password", password, "Connection", profile_key=profile) diff -r b29452cab50b -r 8e0072754413 src/plugins/plugin_misc_register_account.py --- a/src/plugins/plugin_misc_register_account.py Mon Jun 23 00:44:10 2014 +0200 +++ b/src/plugins/plugin_misc_register_account.py Mon Jun 23 10:23:13 2014 +0200 @@ -59,19 +59,20 @@ try: session_data[param] = data["%s%s%s%s" % (SAT_FORM_PREFIX, "Connection", SAT_PARAM_SEPARATOR, param)] except KeyError: - if param == C.FORCE_PORT_PARAM: - session_data[param] = 5222 + if param in (C.FORCE_PORT_PARAM, C.FORCE_SERVER_PARAM): + session_data[param] = '' - for param in ('JabberID', 'Password', C.FORCE_SERVER_PARAM): + for param in ('JabberID', 'Password'): if not session_data[param]: form_ui = xml_tools.XMLUI("popup", title=D_("Missing values")) - form_ui.addText(D_("No user, password or server given: can't register new account.")) + form_ui.addText(D_("No user JID or password given: can't register new account.")) return {'xmlui': form_ui.toXml()} - user = jid.parse(session_data['JabberID'])[0] + session_data['user'], host, resource = jid.parse(session_data['JabberID']) + session_data['server'] = session_data[C.FORCE_SERVER_PARAM] or host session_id, dummy = self._sessions.newSession(session_data, profile) form_ui = xml_tools.XMLUI("form", title=D_("Register new account"), submit_id=self.__register_account_id, session_id=session_id) - form_ui.addText(D_("Do you want to register a new XMPP account [%(user)s] on server %(server)s ?") % {'user': user, 'server': session_data[C.FORCE_SERVER_PARAM]}) + form_ui.addText(D_("Do you want to register a new XMPP account [%(user)s] on server %(server)s ?") % {'user': session_data['user'], 'server': session_data['server']}) return {'xmlui': form_ui.toXml()} def _registerConfirmation(self, data, profile): @@ -83,12 +84,11 @@ self.host.memory.setParam(C.FORCE_SERVER_PARAM, session_data[C.FORCE_SERVER_PARAM], "Connection", profile_key=profile) self.host.memory.setParam(C.FORCE_PORT_PARAM, session_data[C.FORCE_PORT_PARAM], "Connection", profile_key=profile) - user = jid.parse(session_data['JabberID'])[0] - d = self._registerNewAccount(user, session_data["Password"], None, session_data[C.FORCE_SERVER_PARAM], profile_key=profile) + d = self._registerNewAccount(session_data['user'], session_data["Password"], None, session_data['server'], profile_key=profile) del self._sessions[data['session_id']] return d - def _registerNewAccount(self, user, password, email, host, port=5222, profile_key=C.PROF_KEY_NONE): + def _registerNewAccount(self, user, password, email, host, port=C.XMPP_C2S_PORT, profile_key=C.PROF_KEY_NONE): """Connect to a server and create a new account using in-band registration. @param user: login of the account @param password: password of the account @@ -101,7 +101,7 @@ d = defer.Deferred() serverRegistrer = xmlstream.XmlStreamFactory(xmpp.RegisteringAuthenticator(self, host, user, password, email, d, profile)) - connector = reactor.connectTCP(host, port, serverRegistrer) + connector = reactor.connectTCP(host, port or C.XMPP_C2S_PORT, serverRegistrer) serverRegistrer.clientConnectionLost = lambda conn, reason: connector.disconnect() def cb(dummy): diff -r b29452cab50b -r 8e0072754413 src/stdui/ui_profile_manager.py --- a/src/stdui/ui_profile_manager.py Mon Jun 23 00:44:10 2014 +0200 +++ b/src/stdui/ui_profile_manager.py Mon Jun 23 10:23:13 2014 +0200 @@ -24,6 +24,7 @@ from sat.memory.crypto import PasswordHasher from sat.memory.memory import ProfileSessions from twisted.internet import defer +from twisted.words.protocols.jabber import jid class ProfileManager(object): @@ -111,6 +112,8 @@ session_data = self._sessions.profileGetUnique(profile) if not session_data: server = self.host.memory.getParamA(C.FORCE_SERVER_PARAM, "Connection", profile_key=profile) + if not server: + server = jid.parse(self.host.memory.getParamA('JabberID', "Connection", profile_key=profile))[1] session_id, session_data = self._sessions.newSession({'count': 0, 'server': server}, profile) if session_data['count'] > 2: # 3 attempts with a new password after the initial try self._sessions.profileDelUnique(profile)