summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/com')
-rw-r--r--src/com/isode/stroke/client/Client.java12
-rw-r--r--src/com/isode/stroke/client/ClientError.java2
-rw-r--r--src/com/isode/stroke/client/ClientOptions.java51
-rw-r--r--src/com/isode/stroke/client/ClientSession.java61
-rw-r--r--src/com/isode/stroke/client/ClientSessionStanzaChannel.java28
-rw-r--r--src/com/isode/stroke/client/CoreClient.java136
6 files changed, 141 insertions, 149 deletions
diff --git a/src/com/isode/stroke/client/Client.java b/src/com/isode/stroke/client/Client.java
index 4478deb..b3eb2c9 100644
--- a/src/com/isode/stroke/client/Client.java
+++ b/src/com/isode/stroke/client/Client.java
@@ -25,11 +25,11 @@ import com.isode.stroke.queries.responders.SoftwareVersionResponder;
public class Client extends CoreClient {
- private MUCManager mucManager;
- private MUCRegistry mucRegistry;
- private DirectedPresenceSender directedPresenceSender;
- private StanzaChannelPresenceSender stanzaChannelPresenceSender;
- private SoftwareVersionResponder softwareVersionResponder;
+ private final MUCManager mucManager;
+ private final MUCRegistry mucRegistry;
+ private final DirectedPresenceSender directedPresenceSender;
+ private final StanzaChannelPresenceSender stanzaChannelPresenceSender;
+ private final SoftwareVersionResponder softwareVersionResponder;
/**
* Constructor.
@@ -47,7 +47,7 @@ public class Client extends CoreClient {
* @param networkFactories An implementation of network interaction, must
* not be null.
*/
- public Client(JID jid, String password, NetworkFactories networkFactories) {
+ public Client(final JID jid, final String password, final NetworkFactories networkFactories) {
super(jid, password, networkFactories);
stanzaChannelPresenceSender = new StanzaChannelPresenceSender(getStanzaChannel());
directedPresenceSender = new DirectedPresenceSender(stanzaChannelPresenceSender);
diff --git a/src/com/isode/stroke/client/ClientError.java b/src/com/isode/stroke/client/ClientError.java
index 0981781..de2db49 100644
--- a/src/com/isode/stroke/client/ClientError.java
+++ b/src/com/isode/stroke/client/ClientError.java
@@ -47,7 +47,7 @@ public class ClientError {
InvalidServerIdentityError,
};
- ClientError(Type type) {
+ ClientError(final Type type) {
type_ = type;
}
diff --git a/src/com/isode/stroke/client/ClientOptions.java b/src/com/isode/stroke/client/ClientOptions.java
index 4090d1f..4144214 100644
--- a/src/com/isode/stroke/client/ClientOptions.java
+++ b/src/com/isode/stroke/client/ClientOptions.java
@@ -12,32 +12,6 @@ package com.isode.stroke.client;
* Options for a client connection
*/
public class ClientOptions {
-
- public enum UseTLS {
-
- NeverUseTLS,
- UseTLSWhenAvailable,
- RequireTLS
- }
-
- public ClientOptions() {
- useStreamCompression = true;
- useTLS = UseTLS.UseTLSWhenAvailable;
- useStreamResumption = false;
- allowPLAINWithoutTLS = false;
- useAcks = true;
- manualHostname = "";
- manualPort = -1;
- }
-
- @Override
- public String toString() {
- return
- "useStreamCompression:" + useStreamCompression +
- "; useStreamResumption:" + useStreamResumption +
- "; " + useTLS;
- }
-
/**
* Whether ZLib stream compression should be used when available.
*
@@ -83,5 +57,28 @@ public class ClientOptions {
*/
public int manualPort;
-
+
+ public enum UseTLS {
+ NeverUseTLS,
+ UseTLSWhenAvailable,
+ RequireTLS
+ }
+
+ public ClientOptions() {
+ useStreamCompression = true;
+ useTLS = UseTLS.UseTLSWhenAvailable;
+ useStreamResumption = false;
+ allowPLAINWithoutTLS = false;
+ useAcks = true;
+ manualHostname = "";
+ manualPort = -1;
+ }
+
+ @Override
+ public String toString() {
+ return
+ "useStreamCompression:" + useStreamCompression +
+ "; useStreamResumption:" + useStreamResumption +
+ "; " + useTLS;
+ }
}
diff --git a/src/com/isode/stroke/client/ClientSession.java b/src/com/isode/stroke/client/ClientSession.java
index a00ed67..aac453d 100644
--- a/src/com/isode/stroke/client/ClientSession.java
+++ b/src/com/isode/stroke/client/ClientSession.java
@@ -51,6 +51,12 @@ import com.isode.stroke.tls.ServerIdentityVerifier;
import java.util.UUID;
public class ClientSession {
+ public final Signal onNeedCredentials = new Signal();
+ public final Signal onInitialized = new Signal();
+ public final Signal1<com.isode.stroke.base.Error> onFinished = new Signal1<com.isode.stroke.base.Error>();
+ public final Signal1<Stanza> onStanzaReceived = new Signal1<Stanza>();
+ public final Signal1<Stanza> onStanzaAcked = new Signal1<Stanza>();
+
private SignalConnection streamElementReceivedConnection;
private SignalConnection streamStreamStartReceivedConnection;
private SignalConnection streamClosedConnection;
@@ -58,6 +64,22 @@ public class ClientSession {
private SignalConnection stanzaAckOnRequestConnection_;
private SignalConnection stanzaAckOnAckedConnection_;
private SignalConnection stanzaResponderAckConnection_;
+ private JID localJID;
+ private State state;
+ private SessionStream stream;
+ private boolean allowPLAINOverNonTLS;
+ private boolean useStreamCompression;
+ private UseTLS useTLS;
+ private boolean useAcks;
+ private boolean needSessionStart;
+ private boolean needResourceBind;
+ private boolean needAcking;
+ private boolean rosterVersioningSupported;
+ private ClientAuthenticator authenticator;
+ private StanzaAckRequester stanzaAckRequester_;
+ private StanzaAckResponder stanzaAckResponder_;
+ private com.isode.stroke.base.Error error_;
+ private CertificateTrustChecker certificateTrustChecker;
public enum State {
@@ -273,13 +295,13 @@ public class ClientSession {
if (ack.isValid()) {
stanzaAckRequester_.handleAckReceived(ack.getHandledStanzasCount());
}
- else {
+ //else {
//logger_.warning("Got invalid ack from server"); /*FIXME: Do we want logging here?
- }
+ //}
}
- else {
+ //else {
//logger_.warning("Ignoring ack"); /*FIXME: Do we want logging here?*/
- }
+ //}
}
else if (element instanceof StreamError) {
finishSession(Error.Type.StreamError);
@@ -565,7 +587,7 @@ public class ClientSession {
private void finishSession(com.isode.stroke.base.Error error) {
state = State.Finishing;
error_ = error;
- assert(stream.isOpen());
+ assert stream.isOpen();
if (stanzaAckResponder_ != null) {
stanzaAckResponder_.handleAckRequestReceived();
}
@@ -585,18 +607,6 @@ public class ClientSession {
stream.writeElement(new StanzaAck(handledStanzasCount));
}
- public final Signal onNeedCredentials = new Signal();
- public final Signal onInitialized = new Signal();
- public final Signal1<com.isode.stroke.base.Error> onFinished = new Signal1<com.isode.stroke.base.Error>();
- public final Signal1<Stanza> onStanzaReceived = new Signal1<Stanza>();
- public final Signal1<Stanza> onStanzaAcked = new Signal1<Stanza>();
-
-
-
-
-
-
-
private JID getRemoteJID() {
return new JID("", localJID.getDomain());
}
@@ -610,20 +620,5 @@ public class ClientSession {
"; error_=" + error_;
}
- private JID localJID;
- private State state;
- private SessionStream stream;
- private boolean allowPLAINOverNonTLS;
- private boolean useStreamCompression;
- private UseTLS useTLS;
- private boolean useAcks;
- private boolean needSessionStart;
- private boolean needResourceBind;
- private boolean needAcking;
- private boolean rosterVersioningSupported;
- private ClientAuthenticator authenticator;
- private StanzaAckRequester stanzaAckRequester_;
- private StanzaAckResponder stanzaAckResponder_;
- private com.isode.stroke.base.Error error_;
- private CertificateTrustChecker certificateTrustChecker;
+
}
diff --git a/src/com/isode/stroke/client/ClientSessionStanzaChannel.java b/src/com/isode/stroke/client/ClientSessionStanzaChannel.java
index 531ff62..e870dda 100644
--- a/src/com/isode/stroke/client/ClientSessionStanzaChannel.java
+++ b/src/com/isode/stroke/client/ClientSessionStanzaChannel.java
@@ -22,12 +22,15 @@ import java.util.logging.Logger;
* StanzaChannel implementation around a ClientSession.
*/
public class ClientSessionStanzaChannel extends StanzaChannel {
+ private final IDGenerator idGenerator = new IDGenerator();
+ private ClientSession session;
+ private static final Logger logger_ = Logger.getLogger(ClientSessionStanzaChannel.class.getName());
private SignalConnection sessionInitializedConnection;
private SignalConnection sessionFinishedConnection;
private SignalConnection sessionStanzaReceivedConnection;
private SignalConnection sessionStanzaAckedConnection;
- public void setSession(ClientSession session) {
+ public void setSession(final ClientSession session) {
assert this.session == null;
this.session = session;
sessionInitializedConnection = session.onInitialized.connect(new Slot() {
@@ -36,9 +39,9 @@ public class ClientSessionStanzaChannel extends StanzaChannel {
handleSessionInitialized();
}
});
- sessionFinishedConnection = session.onFinished.connect(new Slot1<com.isode.stroke.base.Error>() {
+ sessionFinishedConnection = session.onFinished.connect(new Slot1<Error>() {
- public void call(com.isode.stroke.base.Error p1) {
+ public void call(Error p1) {
handleSessionFinished(p1);
}
});
@@ -56,15 +59,15 @@ public class ClientSessionStanzaChannel extends StanzaChannel {
});
}
- public void sendIQ(IQ iq) {
+ public void sendIQ(final IQ iq) {
send(iq);
}
- public void sendMessage(Message message) {
+ public void sendMessage(final Message message) {
send(message);
}
- public void sendPresence(Presence presence) {
+ public void sendPresence(final Presence presence) {
send(presence);
}
@@ -83,7 +86,7 @@ public class ClientSessionStanzaChannel extends StanzaChannel {
return idGenerator.generateID();
}
- private void send(Stanza stanza) {
+ private void send(final Stanza stanza) {
if (!isAvailable()) {
logger_.warning("Warning: Client: Trying to send a stanza while disconnected.");
return;
@@ -91,7 +94,8 @@ public class ClientSessionStanzaChannel extends StanzaChannel {
session.sendStanza(stanza);
}
- private void handleSessionFinished(Error error) {
+ // NOPMD, ignore that Error isn't used.
+ private void handleSessionFinished(final Error error) {
sessionFinishedConnection.disconnect();
sessionStanzaReceivedConnection.disconnect();
sessionStanzaAckedConnection.disconnect();
@@ -100,7 +104,7 @@ public class ClientSessionStanzaChannel extends StanzaChannel {
onAvailableChanged.emit(false);
}
- private void handleStanza(Stanza stanza) {
+ private void handleStanza(final Stanza stanza) {
if (stanza instanceof Message) {
onMessageReceived.emit((Message)stanza);
}
@@ -112,14 +116,12 @@ public class ClientSessionStanzaChannel extends StanzaChannel {
}
}
- private void handleStanzaAcked(Stanza stanza) {
+ private void handleStanzaAcked(final Stanza stanza) {
onStanzaAcked.emit(stanza);
}
private void handleSessionInitialized() {
onAvailableChanged.emit(true);
}
- private IDGenerator idGenerator = new IDGenerator();
- private ClientSession session;
- private static final Logger logger_ = Logger.getLogger(ClientSessionStanzaChannel.class.getName());
+
}
diff --git a/src/com/isode/stroke/client/CoreClient.java b/src/com/isode/stroke/client/CoreClient.java
index ead4889..c332f27 100644
--- a/src/com/isode/stroke/client/CoreClient.java
+++ b/src/com/isode/stroke/client/CoreClient.java
@@ -9,12 +9,10 @@
package com.isode.stroke.client;
import com.isode.stroke.base.NotNull;
-import com.isode.stroke.client.ClientSession.UseTLS;
import com.isode.stroke.elements.Message;
import com.isode.stroke.elements.Presence;
import com.isode.stroke.elements.Stanza;
import com.isode.stroke.elements.StreamType;
-import com.isode.stroke.eventloop.EventLoop;
import com.isode.stroke.jid.JID;
import com.isode.stroke.network.Connection;
import com.isode.stroke.network.ConnectionFactory;
@@ -48,6 +46,62 @@ import com.isode.stroke.tls.PlatformTLSFactories;
* functionality and interfaces, and is better suited for most needs.
*/
public class CoreClient {
+ /**
+ * The user should add a listener to this signal, which will be called when
+ * the client was disconnected from tne network.
+ *
+ * <p>If the disconnection was due to a non-recoverable error, the type
+ * of error will be passed as a parameter.
+ */
+ public final Signal1<ClientError> onDisconnected = new Signal1<ClientError>();
+
+ /**
+ * The user should add a listener to this signal, which will be called when
+ * the connection is established with the server.
+ */
+ public final Signal onConnected = new Signal();
+
+ /**
+ * The user may add a listener to this signal, which will be called when
+ * data are received from the server. Useful for observing protocol exchange.
+ */
+ public final Signal1<String> onDataRead = new Signal1<String>();
+
+ /**
+ * The user may add a listener to this signal, which will be called when
+ * data are sent to the server. Useful for observing protocol exchange.
+ */
+ public final Signal1<String> onDataWritten = new Signal1<String>();
+
+ /**
+ * Called when a message stanza is received.
+ */
+ public final Signal1<Message> onMessageReceived = new Signal1<Message>();
+ /**
+ * Called when a presence stanza is received.
+ */
+ public final Signal1<Presence> onPresenceReceived = new Signal1<Presence>();
+ /**
+ * Called when a stanza has been received and acked by a server supporting XEP-0198.
+ */
+ public final Signal1<Stanza> onStanzaAcked = new Signal1<Stanza>();
+ private JID jid_;
+ private String password_;
+ private ClientSessionStanzaChannel stanzaChannel_;
+ private IQRouter iqRouter_;
+ private Connector connector_;
+ //private ConnectionFactory connectionFactory_;
+ private FullPayloadParserFactoryCollection payloadParserFactories_ = new FullPayloadParserFactoryCollection();
+ private FullPayloadSerializerCollection payloadSerializers_ = new FullPayloadSerializerCollection();
+ private Connection connection_;
+ private BasicSessionStream sessionStream_;
+ private ClientSession session_;
+ private CertificateWithKey certificate_;
+ private boolean disconnectRequested_;
+ private ClientOptions options;
+ private CertificateTrustChecker certificateTrustChecker;
+ private NetworkFactories networkFactories;
+ private PlatformTLSFactories tlsFactories;
private SignalConnection sessionStreamDataReadConnection_;
private SignalConnection sessionStreamDataWrittenConnection_;
private SignalConnection sessionFinishedConnection_;
@@ -70,7 +124,7 @@ public class CoreClient {
* @param networkFactories An implementation of network interaction, must
* not be null.
*/
- public CoreClient(JID jid, String password, NetworkFactories networkFactories) {
+ public CoreClient(final JID jid, final String password, final NetworkFactories networkFactories) {
jid_ = jid;
password_ = password;
disconnectRequested_ = false;
@@ -128,7 +182,7 @@ public class CoreClient {
*
* @param o Client options to use in the connection, must not be null
*/
- public void connect(ClientOptions o) {
+ public void connect(final ClientOptions o) {
forceReset();
disconnectRequested_ = false;
assert (connector_ == null);
@@ -180,7 +234,7 @@ public class CoreClient {
session_.start();
}
- void handleConnectorFinished(Connection connection, com.isode.stroke.base.Error error) {
+ void handleConnectorFinished(final Connection connection, final com.isode.stroke.base.Error error) {
resetConnector();
if (connection == null) {
@@ -236,7 +290,7 @@ public class CoreClient {
}
}
- public void setCertificate(CertificateWithKey certificate) {
+ public void setCertificate(final CertificateWithKey certificate) {
certificate_ = certificate;
}
@@ -250,11 +304,11 @@ public class CoreClient {
* @param checker a CertificateTrustChecker that will be called when
* the server sends a TLS certificate that does not validate.
*/
- public void setCertificateTrustChecker(CertificateTrustChecker checker) {
+ public void setCertificateTrustChecker(final CertificateTrustChecker checker) {
certificateTrustChecker = checker;
}
- private void handleSessionFinished(com.isode.stroke.base.Error error) {
+ private void handleSessionFinished(final com.isode.stroke.base.Error error) {
sessionFinishedConnection_.disconnect();
sessionNeedCredentialsConnection_.disconnect();
session_ = null;
@@ -370,25 +424,25 @@ public class CoreClient {
session_.sendCredentials(password_);
}
- private void handleDataRead(String data) {
+ private void handleDataRead(final String data) {
onDataRead.emit(data);
}
- private void handleDataWritten(String data) {
+ private void handleDataWritten(final String data) {
onDataWritten.emit(data);
}
- private void handleStanzaChannelAvailableChanged(boolean available) {
+ private void handleStanzaChannelAvailableChanged(final boolean available) {
if (available) {
onConnected.emit();
}
}
- public void sendMessage(Message message) {
+ public void sendMessage(final Message message) {
stanzaChannel_.sendMessage(message);
}
- public void sendPresence(Presence presence) {
+ public void sendPresence(final Presence presence) {
stanzaChannel_.sendPresence(presence);
}
@@ -481,60 +535,4 @@ public class CoreClient {
"; session " + (isAvailable() ? "" : "un") + "available";
}
- /**
- * The user should add a listener to this signal, which will be called when
- * the client was disconnected from tne network.
- *
- * <p>If the disconnection was due to a non-recoverable error, the type
- * of error will be passed as a parameter.
- */
- public final Signal1<ClientError> onDisconnected = new Signal1<ClientError>();
-
- /**
- * The user should add a listener to this signal, which will be called when
- * the connection is established with the server.
- */
- public final Signal onConnected = new Signal();
-
- /**
- * The user may add a listener to this signal, which will be called when
- * data are received from the server. Useful for observing protocol exchange.
- */
- public final Signal1<String> onDataRead = new Signal1<String>();
-
- /**
- * The user may add a listener to this signal, which will be called when
- * data are sent to the server. Useful for observing protocol exchange.
- */
- public final Signal1<String> onDataWritten = new Signal1<String>();
-
- /**
- * Called when a message stanza is received.
- */
- public final Signal1<Message> onMessageReceived = new Signal1<Message>();
- /**
- * Called when a presence stanza is received.
- */
- public final Signal1<Presence> onPresenceReceived = new Signal1<Presence>();
- /**
- * Called when a stanza has been received and acked by a server supporting XEP-0198.
- */
- public final Signal1<Stanza> onStanzaAcked = new Signal1<Stanza>();
- private JID jid_;
- private String password_;
- private ClientSessionStanzaChannel stanzaChannel_;
- private IQRouter iqRouter_;
- private Connector connector_;
- private ConnectionFactory connectionFactory_;
- private FullPayloadParserFactoryCollection payloadParserFactories_ = new FullPayloadParserFactoryCollection();
- private FullPayloadSerializerCollection payloadSerializers_ = new FullPayloadSerializerCollection();
- private Connection connection_;
- private BasicSessionStream sessionStream_;
- private ClientSession session_;
- private CertificateWithKey certificate_;
- private boolean disconnectRequested_;
- private ClientOptions options;
- private CertificateTrustChecker certificateTrustChecker;
- private NetworkFactories networkFactories;
- private PlatformTLSFactories tlsFactories;
}