[PATCH] Registration Support Check

Hi,

Smack 2.2.1’‘s AccountManager checks if the server allows registrations by asking for the registration form and wait for a reply with a timeout (the Smack developers seem to like timeouts, they’'re used totally unnecessary all over the place).

However, it would be much better if Smack would check for the register feature tag at login. I’‘ve created a patch that does exactly that, I’'ve appended it here.

--- ../smack-dev-2.2.1/source/org/jivesoftware/smack/AccountManager.java     2006-06-12 23:13:16.000000000 +0200
+++ source/org/jivesoftware/smack/AccountManager.java     2006-07-27 16:26:31.000000000 +0200
@@ -35,37 +35,43 @@
*/
public class AccountManager { private XMPPConnection connection;private Registration info = null;
+    private boolean accountCreationSupported = false; /** * Creates a new AccountManager instance. * * @param connection a connection to a XMPP server. */
public AccountManager(XMPPConnection connection) {
    this.connection = connection;
}
+    +    void setSupportsAccountCreation(boolean accountCreationSupported) {
+        this.accountCreationSupported = accountCreationSupported;
+    } /*** Returns true if the server supports creating new accounts. Many servers require
* that you not be currently authenticated when creating new accounts, so the safest
* behavior is to only create new accounts before having logged in to a server.
*
* @return true if the server support creating new accounts.
*/
public boolean supportsAccountCreation() {
-        try {
+/*        try {
if (info == null) {
getRegistrationInfo();
}
return info.getType() != IQ.Type.ERROR;
}
catch (XMPPException xe) {
return false;
-        }
+        }*/
+        return accountCreationSupported;
} /*** Returns an Iterator for the (String) names of the required account attributes. * All attributes must be set when creating new accounts. The standard
--- ../smack-dev-2.2.1/source/org/jivesoftware/smack/PacketReader.java     2006-06-12 23:13:15.000000000 +0200
+++ source/org/jivesoftware/smack/PacketReader.java     2006-07-27 16:26:14.000000000 +0200
@@ -491,10 +491,13 @@
                }
                else if (parser.getName().equals("compression")) {
                    // The server supports stream compression
                    connection.setAvailableCompressionMethods(parseCompressionMethods(parser));
                }
+                else if (parser.getName().equals("register")) {
+                    connection.getAccountManager().setSupportsAccountCreation(true);
+                }
            }
            else if (eventType == XmlPullParser.END_TAG) {
                if (parser.getName().equals("features")) {
                    done = true;
                }

Thanks, I’'ve filed this as SMACK-160.

Regards,

Matt

Hey guys,

The enhancement has been included. You can test it in the next nightly build.

Thanks,

– Gato