aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/xmpp/s2s/ConnectionOut.java')
-rw-r--r--src/main/java/com/juick/xmpp/s2s/ConnectionOut.java41
1 files changed, 19 insertions, 22 deletions
diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java b/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java
index 4ebeffb6..68851da1 100644
--- a/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java
+++ b/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java
@@ -2,26 +2,17 @@ package com.juick.xmpp.s2s;
import com.juick.xmpp.extensions.StreamFeatures;
import com.juick.xmpp.utils.XmlUtils;
+import org.xmlpull.v1.XmlPullParser;
+import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLSocket;
import java.io.EOFException;
import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
import java.net.InetAddress;
-import java.net.InetSocketAddress;
import java.net.Socket;
-import java.nio.channels.AsynchronousSocketChannel;
-import java.nio.channels.Channels;
-import java.nio.channels.CompletionHandler;
-import java.util.concurrent.ExecutionException;
+import java.net.UnknownHostException;
import java.util.logging.Level;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
-import javax.net.ssl.SSLException;
-import javax.net.ssl.SSLSocket;
-
/**
* @author ugnich
*/
@@ -45,8 +36,8 @@ public class ConnectionOut extends Connection implements Runnable {
}
void sendOpenStream() throws IOException {
- sendStanza("<?xml version='1.0'?><stream:stream xmlns='jabber:server' " +
- "xmlns:stream='http://etherx.jabber.org/streams' xmlns:db='jabber:server:dialback' from='" +
+ sendStanza("<?xml version='1.0'?><stream:stream xmlns='jabber:server' id='" + streamID +
+ "' xmlns:stream='http://etherx.jabber.org/streams' xmlns:db='jabber:server:dialback' from='" +
XMPPComponent.HOSTNAME + "' to='" + to + "' version='1.0'>");
}
@@ -63,10 +54,12 @@ public class ConnectionOut extends Connection implements Runnable {
LOGGER.info("STREAM TO " + to + " START");
try {
HostnamePort addr = DNSQueries.getServerAddress(to);
- socket = new Socket(InetAddress.getByName(addr.hostname), addr.port);
- parser.setInput(new InputStreamReader(socket.getInputStream()));
-
- writer = new OutputStreamWriter(socket.getOutputStream());
+ try {
+ socket = new Socket(InetAddress.getByName(addr.hostname), addr.port);
+ } catch (UnknownHostException e) {
+ socket = new Socket(InetAddress.getByName("talk.google.com"), 5269);
+ }
+ restartParser();
sendOpenStream();
@@ -78,6 +71,10 @@ public class ConnectionOut extends Connection implements Runnable {
LOGGER.info("STREAM TO " + to + " " + streamID + " OPEN");
XMPPComponent.addConnectionOut(ConnectionOut.this);
+ boolean xmppversionnew = parser.getAttributeValue(null, "version") != null;
+ if (!xmppversionnew) {
+ processDialback();
+ }
while (parser.next() != XmlPullParser.END_DOCUMENT) {
if (parser.getEventType() != XmlPullParser.START_TAG) {
@@ -115,7 +112,7 @@ public class ConnectionOut extends Connection implements Runnable {
XmlUtils.skip(parser);
} else if (tag.equals("features") && parser.getNamespace().equals(NS_STREAM)) {
StreamFeatures features = StreamFeatures.parse(parser);
- if (!isSecured() && features.STARTTLS >= 0) {
+ if (!isSecured() && features.STARTTLS >= 0 && !XMPPComponent.brokenSSLhosts.contains(to)) {
System.out.println("STREAM TO " + to + " " + streamID + " SECURING");
sendStanza("<starttls xmlns=\"" + NS_TLS + "\" />");
} else {
@@ -131,7 +128,7 @@ public class ConnectionOut extends Connection implements Runnable {
restartParser();
sendOpenStream();
} catch (SSLException sex) {
- System.err.println("STREAM " + streamID + " SSL ERROR");
+ LOGGER.log(Level.SEVERE, String.format("s2s ssl error: %s %s", to, streamID), sex);
sendStanza("<failed xmlns\"" + NS_TLS + "\" />");
XMPPComponent.removeConnectionOut(this);
closeConnection();
@@ -151,7 +148,7 @@ public class ConnectionOut extends Connection implements Runnable {
XMPPComponent.removeConnectionOut(ConnectionOut.this);
closeConnection();
} catch (Exception e) {
- LOGGER.log(Level.SEVERE, "s2s out exception", e);
+ LOGGER.log(Level.SEVERE, String.format("s2s out exception: %s %s", to, streamID), e);
XMPPComponent.removeConnectionOut(ConnectionOut.this);
closeConnection();
}