1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 17:19:39 +02:00

Add XMPPConnection.getStreamId()

and remove getConnectionID().

Also make streamId a field of AbstractXMPPConnection. Most XMPP
connection types have a streamId, it appears to be optional when BOSH
is used though.
This commit is contained in:
Florian Schmaus 2015-01-28 17:14:33 +01:00
parent 612ca1ad9d
commit 5a56ff011b
5 changed files with 28 additions and 53 deletions

View file

@ -168,6 +168,11 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
protected boolean connected = false;
/**
* The stream ID, see RFC 6120 § 4.7.3
*/
protected String streamId;
/**
*
*/
@ -354,9 +359,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
return port;
}
@Override
public abstract String getConnectionID();
@Override
public abstract boolean isSecureConnection();
@ -382,10 +384,16 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
* @return a reference to this object, to chain <code>connect()</code> with <code>login()</code>.
*/
public synchronized AbstractXMPPConnection connect() throws SmackException, IOException, XMPPException {
// Check if not already connected
throwAlreadyConnectedExceptionIfAppropriate();
// Reset the connection state
saslAuthentication.init();
saslFeatureReceived.init();
lastFeaturesReceived.init();
streamId = null;
// Perform the actual connection to the XMPP service
connectInternal();
return this;
}
@ -501,6 +509,14 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
return user;
}
@Override
public String getStreamId() {
if (!isConnected()) {
return null;
}
return streamId;
}
// TODO remove this suppression once "disable legacy session" code has been removed from Smack
@SuppressWarnings("deprecation")
protected void bindResourceAndEstablishSession(String resource) throws XMPPErrorException,

View file

@ -98,14 +98,14 @@ public interface XMPPConnection {
public String getUser();
/**
* Returns the connection ID for this connection, which is the value set by the server
* when opening a XMPP stream. If the server does not set a connection ID, this value
* will be null. This value will be <tt>null</tt> if not connected to the server.
* Returns the stream ID for this connection, which is the value set by the server
* when opening a XMPP stream. This value will be <tt>null</tt> if not connected to the server.
*
* @return the ID of this connection returned from the XMPP server or <tt>null</tt> if
* not connected to the server.
* @see <a href="http://xmpp.org/rfcs/rfc6120.html#streams-attr-id">RFC 6120 § 4.7.3. id</a>
*/
public String getConnectionID();
public String getStreamId();
/**
* Returns true if currently connected to the XMPP server.

View file

@ -48,8 +48,6 @@ public class DummyConnection extends AbstractXMPPConnection {
private boolean reconnect = false;
private String connectionID;
private final BlockingQueue<TopLevelStreamElement> queue = new LinkedBlockingQueue<TopLevelStreamElement>();
public static ConnectionConfiguration.Builder<?,?> getDummyConfigurationBuilder() {
@ -77,7 +75,7 @@ public class DummyConnection extends AbstractXMPPConnection {
@Override
protected void connectInternal() {
connected = true;
connectionID = "dummy-" + new Random(new Date().getTime()).nextInt();
streamId = "dummy-" + new Random(new Date().getTime()).nextInt();
if (reconnect) {
notifyReconnection();
@ -87,24 +85,12 @@ public class DummyConnection extends AbstractXMPPConnection {
@Override
protected void shutdown() {
user = null;
connectionID = null;
authenticated = false;
callConnectionClosedListener();
reconnect = true;
}
@Override
public String getConnectionID() {
if (!isConnected()) {
return null;
}
if (connectionID == null) {
connectionID = "dummy-" + new Random(new Date().getTime()).nextInt();
}
return connectionID;
}
@Override
public boolean isSecureConnection() {
return false;