1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-22 02:27:58 +01: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

@ -95,11 +95,6 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
private PipedWriter readerPipe;
private Thread readerConsumer;
/**
* The BOSH equivalent of the stream ID which is used for DIGEST authentication.
*/
protected String authID = null;
/**
* The session ID for the BOSH session with the connection manager.
*/
@ -147,7 +142,6 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
client = null;
}
sessionID = null;
authID = null;
// Initialize BOSH client
BOSHClientConfig.Builder cfgBuilder = BOSHClientConfig.Builder
@ -206,16 +200,6 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
callConnectionConnectedListener();
}
public String getConnectionID() {
if (!connected) {
return null;
} else if (authID != null) {
return authID;
} else {
return sessionID;
}
}
public boolean isSecureConnection() {
// TODO: Implement SSL usage
return false;
@ -298,7 +282,6 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
@Override
protected void shutdown() {
setWasAuthenticated();
authID = null;
sessionID = null;
done = true;
authenticated = false;
@ -525,8 +508,8 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
if (sessionID == null) {
sessionID = body.getAttribute(BodyQName.create(XMPPBOSHConnection.BOSH_URI, "sid"));
}
if (authID == null) {
authID = body.getAttribute(BodyQName.create(XMPPBOSHConnection.BOSH_URI, "authid"));
if (streamId == null) {
streamId = body.getAttribute(BodyQName.create(XMPPBOSHConnection.BOSH_URI, "authid"));
}
final XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);

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;

View file

@ -144,8 +144,6 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
*/
private Socket socket;
private String connectionID = null;
/**
*
*/
@ -298,14 +296,6 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
serviceName).build());
}
@Override
public String getConnectionID() {
if (!isConnected()) {
return null;
}
return connectionID;
}
@Override
protected void throwNotConnectedExceptionIfAppropriate() throws NotConnectedException {
if (packetWriter == null) {
@ -893,7 +883,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
if (localpart != null) {
from = XmppStringUtils.completeJidFrom(localpart, to);
}
String id = getConnectionID();
String id = getStreamId();
send(new StreamOpen(to, from, id));
try {
packetReader.parser = PacketParserUtils.newXmppParser(reader);
@ -956,7 +946,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
case "stream":
// We found an opening stream.
if ("jabber:client".equals(parser.getNamespace(null))) {
connectionID = parser.getAttributeValue("", "id");
streamId = parser.getAttributeValue("", "id");
String reportedServiceName = parser.getAttributeValue("", "from");
assert(reportedServiceName.equals(config.getServiceName()));
}