From b34152e9f5f75f48515a07346c8812f5d11c5072 Mon Sep 17 00:00:00 2001 From: Gaston Dombiak Date: Thu, 3 Aug 2006 17:04:01 +0000 Subject: [PATCH] Use stream feature to discover whether in-band registration is available. SMACK-160 git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@4797 b35dd754-fafc-0310-a699-88a17e54d16e --- .../jivesoftware/smack/AccountManager.java | 34 +++++++++++++++++-- .../org/jivesoftware/smack/PacketReader.java | 3 ++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/source/org/jivesoftware/smack/AccountManager.java b/source/org/jivesoftware/smack/AccountManager.java index d68b1f5a0..ff2bc71b9 100644 --- a/source/org/jivesoftware/smack/AccountManager.java +++ b/source/org/jivesoftware/smack/AccountManager.java @@ -28,7 +28,10 @@ import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.Registration; import org.jivesoftware.smack.util.StringUtils; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; /** * Allows creation and management of accounts on an XMPP server. @@ -41,6 +44,14 @@ public class AccountManager { private XMPPConnection connection; private Registration info = null; + /** + * Flag that indicates whether the server supports In-Band Registration. + * In-Band Registration may be advertised as a stream feature. If no stream feature + * was advertised from the server then try sending an IQ packet to discover if In-Band + * Registration is available. + */ + private boolean accountCreationSupported = false; + /** * Creates a new AccountManager instance. * @@ -50,6 +61,17 @@ public class AccountManager { this.connection = connection; } + /** + * Sets whether the server supports In-Band Registration. In-Band Registration may be + * advertised as a stream feature. If no stream feature was advertised from the server + * then try sending an IQ packet to discover if In-Band Registration is available. + * + * @param accountCreationSupported true if the server supports In-Band Registration. + */ + 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 @@ -58,11 +80,19 @@ public class AccountManager { * @return true if the server support creating new accounts. */ public boolean supportsAccountCreation() { + // Check if we already know that the server supports creating new accounts + if (accountCreationSupported) { + return true; + } + // No information is known yet (e.g. no stream feature was received from the server + // indicating that it supports creating new accounts) so send an IQ packet as a way + // to discover if this feature is supported try { if (info == null) { getRegistrationInfo(); + accountCreationSupported = info.getType() != IQ.Type.ERROR; } - return info.getType() != IQ.Type.ERROR; + return accountCreationSupported; } catch (XMPPException xe) { return false; diff --git a/source/org/jivesoftware/smack/PacketReader.java b/source/org/jivesoftware/smack/PacketReader.java index 0cc02900b..47616c106 100644 --- a/source/org/jivesoftware/smack/PacketReader.java +++ b/source/org/jivesoftware/smack/PacketReader.java @@ -470,6 +470,9 @@ class PacketReader { // 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")) {