mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 04:22:05 +01:00
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
This commit is contained in:
parent
84cc5fb1c6
commit
b34152e9f5
2 changed files with 35 additions and 2 deletions
|
@ -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;
|
||||
|
|
|
@ -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")) {
|
||||
|
|
Loading…
Reference in a new issue