changeset 1088:b29452cab50b

core, memory, plugins, stdui, frontends: look for DNS SRV records when server is not specified: - fix bug 3 - modify "Connection" params: - rename "Server" to "Force server" and "Port" to "Force port" - set the default value to empty string for both
author souliane <souliane@mailoo.org>
date Mon, 23 Jun 2014 00:44:10 +0200
parents b3b7a2863060
children 8e0072754413
files frontends/src/jp/cmd_profile.py frontends/src/primitivus/profile_manager.py frontends/src/wix/profile_manager.py frontends/src/wix/xmlui.py src/core/constants.py src/core/sat_main.py src/core/xmpp.py src/memory/params.py src/plugins/plugin_misc_account.py src/plugins/plugin_misc_register_account.py src/stdui/ui_profile_manager.py
diffstat 11 files changed, 26 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/jp/cmd_profile.py	Wed Jun 25 14:01:58 2014 +0200
+++ b/frontends/src/jp/cmd_profile.py	Mon Jun 23 00:44:10 2014 +0200
@@ -95,7 +95,7 @@
 
     def _profile_created(self):
         self.host.bridge.setParam("JabberID", self.args.jid, "Connection" ,profile_key=self.args.profile)
-        self.host.bridge.setParam("Server", JID(self.args.jid).domain, "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()
 
--- a/frontends/src/primitivus/profile_manager.py	Wed Jun 25 14:01:58 2014 +0200
+++ b/frontends/src/primitivus/profile_manager.py	Mon Jun 23 00:44:10 2014 +0200
@@ -167,7 +167,7 @@
 
         if old_jid != new_jid:
             self.host.bridge.setParam("JabberID", new_jid, "Connection", profile_key=profile)
-            self.host.bridge.setParam("Server", JID(new_jid).domain, "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)
--- a/frontends/src/wix/profile_manager.py	Wed Jun 25 14:01:58 2014 +0200
+++ b/frontends/src/wix/profile_manager.py	Mon Jun 23 00:44:10 2014 +0200
@@ -174,7 +174,7 @@
         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("Server", JID(new_jid).domain, "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)
--- a/frontends/src/wix/xmlui.py	Wed Jun 25 14:01:58 2014 +0200
+++ b/frontends/src/wix/xmlui.py	Mon Jun 23 00:44:10 2014 +0200
@@ -320,7 +320,7 @@
         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', 'Server'):
+                if (widget._param_category, widget._param_name) == ('Connection', C.FORCE_SERVER_PARAM):
                     widget.SetValue(domain)
                     break
 
--- a/src/core/constants.py	Wed Jun 25 14:01:58 2014 +0200
+++ b/src/core/constants.py	Mon Jun 23 00:44:10 2014 +0200
@@ -40,6 +40,9 @@
     NO_SECURITY_LIMIT = -1
     INDIVIDUAL = "individual"
     GENERAL = "general"
+    # Parameters related to connection
+    FORCE_SERVER_PARAM = "Force server"
+    FORCE_PORT_PARAM = "Force port"
     # Parameters related to encryption
     PROFILE_PASS_PATH = ('General', 'Password')
     MEMORY_CRYPTO_NAMESPACE = 'crypto'  # for the private persistent binary dict
--- a/src/core/sat_main.py	Wed Jun 25 14:01:58 2014 +0200
+++ b/src/core/sat_main.py	Mon Jun 23 00:44:10 2014 +0200
@@ -220,7 +220,7 @@
     def _connectXMPPClient(self, profile):
         """This part is called from asyncConnect when we have loaded individual parameters from memory"""
         try:
-            port = int(self.memory.getParamA("Port", "Connection", profile_key=profile))
+            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
@@ -228,7 +228,7 @@
         password = yield self.memory.asyncGetParamA("Password", "Connection", profile_key=profile)
         current = self.profiles[profile] = xmpp.SatXMPPClient(self, profile,
             jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key=profile)),
-            password, self.memory.getParamA("Server", "Connection", profile_key=profile), port)
+            password, self.memory.getParamA(C.FORCE_SERVER_PARAM, "Connection", profile_key=profile), port)
 
         current.messageProt = xmpp.SatMessageProtocol(self)
         current.messageProt.setHandlerParent(current)
--- a/src/core/xmpp.py	Wed Jun 25 14:01:58 2014 +0200
+++ b/src/core/xmpp.py	Mon Jun 23 00:44:10 2014 +0200
@@ -37,7 +37,9 @@
     implements(iwokkel.IDisco)
 
     def __init__(self, host_app, profile, user_jid, password, host=None, port=5222):
-        client.XMPPClient.__init__(self, user_jid, password, host, 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)
         self.factory.clientConnectionLost = self.connectionLost
         self.__connected = False
         self.profile = profile
--- a/src/memory/params.py	Wed Jun 25 14:01:58 2014 +0200
+++ b/src/memory/params.py	Mon Jun 23 00:44:10 2014 +0200
@@ -49,8 +49,8 @@
             <param name="JabberID" value="name@example.org/SàT" type="string" />
             <param name="Password" value="" type="password" />
             <param name="Priority" value="50" type="string" />
-            <param name="Server" value="example.org" type="string" />
-            <param name="Port" value="5222" type="string" />
+            <param name="%(force_server_param)s" value="" type="string" />
+            <param name="%(force_port_param)s" value="" type="string" />
             <param name="NewAccount" label="%(label_NewAccount)s" type="button" callback_id="registerNewAccount"/>
             <param name="autoconnect" label="%(label_autoconnect)s" value="true" type="bool" />
             <param name="autodisconnect" label="%(label_autodisconnect)s" value="false"  type="bool" />
@@ -66,7 +66,9 @@
         'label_NewAccount': _("Register new account"),
         'label_autoconnect': _('Connect on frontend startup'),
         'label_autodisconnect': _('Disconnect on frontend closure'),
-        'category_misc': _("Misc")
+        'category_misc': _("Misc"),
+        'force_server_param': C.FORCE_SERVER_PARAM,
+        'force_port_param': C.FORCE_PORT_PARAM,
     }
 
     def load_default_params(self):
--- a/src/plugins/plugin_misc_account.py	Wed Jun 25 14:01:58 2014 +0200
+++ b/src/plugins/plugin_misc_account.py	Mon Jun 23 00:44:10 2014 +0200
@@ -192,7 +192,7 @@
             #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("Server", self.getConfig('new_account_server'),
+            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)
--- a/src/plugins/plugin_misc_register_account.py	Wed Jun 25 14:01:58 2014 +0200
+++ b/src/plugins/plugin_misc_register_account.py	Mon Jun 23 00:44:10 2014 +0200
@@ -55,14 +55,14 @@
     def registerNewAccountCB(self, data, profile):
         """Called when the use click on the "New account" button."""
         session_data = {}
-        for param in ('JabberID', 'Password', 'Port', 'Server'):
+        for param in ('JabberID', 'Password', C.FORCE_PORT_PARAM, C.FORCE_SERVER_PARAM):
             try:
                 session_data[param] = data["%s%s%s%s" % (SAT_FORM_PREFIX, "Connection", SAT_PARAM_SEPARATOR, param)]
             except KeyError:
-                if param == 'Port':
+                if param == C.FORCE_PORT_PARAM:
                     session_data[param] = 5222
 
-        for param in ('JabberID', 'Password', 'Server'):
+        for param in ('JabberID', 'Password', C.FORCE_SERVER_PARAM):
             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."))
@@ -71,7 +71,7 @@
         user = jid.parse(session_data['JabberID'])[0]
         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['Server']})
+        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]})
         return  {'xmlui': form_ui.toXml()}
 
     def _registerConfirmation(self, data, profile):
@@ -80,11 +80,11 @@
 
         self.host.memory.setParam("JabberID", session_data["JabberID"], "Connection", profile_key=profile)
         self.host.memory.setParam("Password", session_data["Password"], "Connection", profile_key=profile)
-        self.host.memory.setParam("Server", session_data["Server"], "Connection", profile_key=profile)
-        self.host.memory.setParam("Port", session_data["Port"], "Connection", profile_key=profile)
+        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["Server"], profile_key=profile)
+        d = self._registerNewAccount(user, session_data["Password"], None, session_data[C.FORCE_SERVER_PARAM], profile_key=profile)
         del self._sessions[data['session_id']]
         return d
 
--- a/src/stdui/ui_profile_manager.py	Wed Jun 25 14:01:58 2014 +0200
+++ b/src/stdui/ui_profile_manager.py	Mon Jun 23 00:44:10 2014 +0200
@@ -110,7 +110,7 @@
     def _changeXMPPPassword(self, data, profile):
         session_data = self._sessions.profileGetUnique(profile)
         if not session_data:
-            server = self.host.memory.getParamA("Server", "Connection", profile_key=profile)
+            server = self.host.memory.getParamA(C.FORCE_SERVER_PARAM, "Connection", profile_key=profile)
             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)