aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-05-08 03:55:47 +0300
committerGravatar Vitaly Takmazov2016-05-08 03:55:47 +0300
commit768951b8c25abf34f6045cf2f352c64f7d2ecc37 (patch)
tree1ba2def4df5230a64a47591279afd0d7c9ee3788 /src/main/java/com/juick/xmpp/s2s/ConnectionIn.java
parent388716986b483e99e5140ca1557cd38632b5115b (diff)
fix connection in
Diffstat (limited to 'src/main/java/com/juick/xmpp/s2s/ConnectionIn.java')
-rw-r--r--src/main/java/com/juick/xmpp/s2s/ConnectionIn.java47
1 files changed, 23 insertions, 24 deletions
diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java b/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java
index 85c64db3..8fa773b7 100644
--- a/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java
+++ b/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java
@@ -24,7 +24,7 @@ import java.util.logging.Logger;
*
* @author ugnich
*/
-public class ConnectionIn extends Connection {
+public class ConnectionIn extends Connection implements Runnable {
private static final Logger LOGGER = Logger.getLogger(ConnectionIn.class.getName());
@@ -36,14 +36,13 @@ public class ConnectionIn extends Connection {
super();
this.socket = socket;
streamID = UUID.randomUUID().toString();
+ restartParser();
}
- public void parseStream() {
+ @Override
+ public void run() {
LOGGER.info("STREAM FROM ? " + streamID + " START");
try {
- parser.setInput(new InputStreamReader(socket.getInputStream()));
- writer = new OutputStreamWriter(socket.getOutputStream());
-
parser.next(); // stream:stream
updateTsRemoteData();
if (!parser.getName().equals("stream")
@@ -106,25 +105,6 @@ public class ConnectionIn extends Connection {
sendStanza("<db:verify from='" + vto + "' to='" + vfrom + "' id='" + vid + "' type='invalid'/>");
LOGGER.warning("STREAM FROM " + vfrom + " " + streamID + " DIALBACK VERIFY INVALID");
}
- } else if (!isSecured() && tag.equals("starttls")) {
- LOGGER.info("STREAM " + streamID + " SECURING");
- sendStanza("<proceed xmlns=\"" + NS_TLS + "\" />");
- try {
- socket = sc.getSocketFactory().createSocket(socket, socket.getInetAddress().getHostAddress(),
- socket.getPort(), true);
- ((SSLSocket) socket).setUseClientMode(false);
- ((SSLSocket) socket).startHandshake();
- setSecured(true);
- LOGGER.info("STREAM " + streamID + " SECURED");
- restartParser();
- } catch (SSLException sex) {
- LOGGER.warning("STREAM " + streamID + " SSL ERROR");
- sendStanza("<failed xmlns\"" + NS_TLS + "\" />");
- XMPPComponent.removeConnectionIn(this);
- closeConnection();
- }
- } else if (isSecured() && tag.equals("stream") && parser.getNamespace().equals(NS_STREAM)) {
- sendOpenStream(true);
} else if (tag.equals("presence") && checkFromTo(parser)) {
Presence p = Presence.parse(parser, null);
if (p != null && (p.type == null || !p.type.equals(Presence.Type.error))) {
@@ -147,6 +127,25 @@ public class ConnectionIn extends Connection {
LOGGER.info("STREAM " + streamID + ": " + xml);
XMPPComponent.connRouter.sendStanza(xml);
}
+ } else if (!isSecured() && tag.equals("starttls")) {
+ LOGGER.info("STREAM " + streamID + " SECURING");
+ sendStanza("<proceed xmlns=\"" + NS_TLS + "\" />");
+ try {
+ socket = sc.getSocketFactory().createSocket(socket, socket.getInetAddress().getHostAddress(),
+ socket.getPort(), true);
+ ((SSLSocket) socket).setUseClientMode(false);
+ ((SSLSocket) socket).startHandshake();
+ setSecured(true);
+ LOGGER.info("STREAM " + streamID + " SECURED");
+ restartParser();
+ } catch (SSLException sex) {
+ LOGGER.warning("STREAM " + streamID + " SSL ERROR");
+ sendStanza("<failed xmlns\"" + NS_TLS + "\" />");
+ XMPPComponent.removeConnectionIn(this);
+ closeConnection();
+ }
+ } else if (isSecured() && tag.equals("stream") && parser.getNamespace().equals(NS_STREAM)) {
+ sendOpenStream(true);
} else {
LOGGER.info("STREAM " + streamID + ": " + XmlUtils.parseToString(parser, true));
}