From 02fd70cf59c30e3a9702eaf60d9e51f460efd8ca Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 6 Jul 2016 19:04:41 +0300 Subject: static components are evil --- .../java/com/juick/xmpp/s2s/ConnectionOut.java | 34 ++++++++++++---------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'src/main/java/com/juick/xmpp/s2s/ConnectionOut.java') diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java b/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java index d3a10406..b79cb49a 100644 --- a/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java +++ b/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java @@ -26,16 +26,18 @@ public class ConnectionOut extends Connection implements Runnable { public boolean streamReady = false; public String to; + XMPPComponent xmpp; String checkSID = null; String dbKey = null; - public ConnectionOut(String hostname) throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, XmlPullParserException, KeyManagementException, KeyStoreException, IOException { - super(); + public ConnectionOut(XMPPComponent xmpp, String hostname) throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, XmlPullParserException, KeyManagementException, KeyStoreException, IOException { + super(xmpp); + this.xmpp = xmpp; to = hostname; } - public ConnectionOut(String hostname, String checkSID, String dbKey) throws Exception { - super(); + public ConnectionOut(XMPPComponent xmpp, String hostname, String checkSID, String dbKey) throws Exception { + super(xmpp); to = hostname; this.checkSID = checkSID; this.dbKey = dbKey; @@ -44,15 +46,15 @@ public class ConnectionOut extends Connection implements Runnable { void sendOpenStream() throws IOException { sendStanza(""); + xmpp.HOSTNAME + "' to='" + to + "' version='1.0'>"); } void processDialback() throws Exception { if (checkSID != null) { sendDialbackVerify(checkSID, dbKey); } - sendStanza("" + - generateDialbackKey(to, XMPPComponent.HOSTNAME, streamID) + ""); + sendStanza("" + + generateDialbackKey(to, xmpp.HOSTNAME, streamID) + ""); } @Override @@ -76,7 +78,7 @@ public class ConnectionOut extends Connection implements Runnable { } LOGGER.info("STREAM TO " + to + " " + streamID + " OPEN"); - XMPPComponent.addConnectionOut(ConnectionOut.this); + xmpp.addConnectionOut(ConnectionOut.this); boolean xmppversionnew = parser.getAttributeValue(null, "version") != null; if (!xmppversionnew) { processDialback(); @@ -95,7 +97,7 @@ public class ConnectionOut extends Connection implements Runnable { streamReady = true; LOGGER.info("STREAM TO " + to + " " + streamID + " READY"); - String cache = XMPPComponent.getFromCache(to); + String cache = xmpp.getFromCache(to); if (cache != null) { LOGGER.info("STREAM TO " + to + " " + streamID + " SENDING CACHE"); sendStanza(cache); @@ -110,7 +112,7 @@ public class ConnectionOut extends Connection implements Runnable { String type = parser.getAttributeValue(null, "type"); String sid = parser.getAttributeValue(null, "id"); if (from != null && from.equals(to) && sid != null && !sid.isEmpty() && type != null) { - ConnectionIn c = XMPPComponent.getConnectionIn(sid); + ConnectionIn c = xmpp.getConnectionIn(sid); if (c != null) { c.sendDialbackResult(from, type); } @@ -118,7 +120,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 && !XMPPComponent.brokenSSLhosts.contains(to)) { + if (!isSecured() && features.STARTTLS >= 0 && !xmpp.brokenSSLhosts.contains(to)) { System.out.println("STREAM TO " + to + " " + streamID + " SECURING"); sendStanza(""); } else { @@ -136,7 +138,7 @@ public class ConnectionOut extends Connection implements Runnable { } catch (SSLException sex) { LOGGER.log(Level.SEVERE, String.format("s2s ssl error: %s %s", to, streamID), sex); sendStanza(""); - XMPPComponent.removeConnectionOut(this); + xmpp.removeConnectionOut(this); closeConnection(); } } else if (isSecured() && tag.equals("stream") && parser.getNamespace().equals(NS_STREAM)) { @@ -147,22 +149,22 @@ public class ConnectionOut extends Connection implements Runnable { } LOGGER.warning("STREAM TO " + to + " " + streamID + " FINISHED"); - XMPPComponent.removeConnectionOut(ConnectionOut.this); + xmpp.removeConnectionOut(ConnectionOut.this); closeConnection(); } catch (EOFException eofex) { LOGGER.info(String.format("STREAM %s %s CLOSED (dirty)", to, streamID)); - XMPPComponent.removeConnectionOut(ConnectionOut.this); + xmpp.removeConnectionOut(ConnectionOut.this); closeConnection(); } catch (Exception e) { LOGGER.log(Level.SEVERE, String.format("s2s out exception: %s %s", to, streamID), e); - XMPPComponent.removeConnectionOut(ConnectionOut.this); + xmpp.removeConnectionOut(ConnectionOut.this); closeConnection(); } } public void sendDialbackVerify(String sid, String key) { try { - sendStanza("" + key + ""); + sendStanza("" + key + ""); } catch (IOException e) { LOGGER.log(Level.WARNING, "STREAM TO " + to + " " + streamID + " ERROR", e); } -- cgit v1.2.3