aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/xmpp/s2s/ConnectionIn.java')
-rw-r--r--src/main/java/com/juick/xmpp/s2s/ConnectionIn.java42
1 files changed, 22 insertions, 20 deletions
diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java b/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java
index 93e761a0..345caea9 100644
--- a/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java
+++ b/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java
@@ -31,9 +31,11 @@ public class ConnectionIn extends Connection implements Runnable {
final public List<String> from = new ArrayList<>();
public long tsRemoteData = 0;
public long packetsRemote = 0;
+ JuickBot bot;
- public ConnectionIn(Socket socket) throws Exception {
- super();
+ public ConnectionIn(XMPPComponent xmpp, JuickBot bot, Socket socket) throws Exception {
+ super(xmpp);
+ this.bot = bot;
this.socket = socket;
streamID = UUID.randomUUID().toString();
restartParser();
@@ -69,19 +71,19 @@ public class ConnectionIn extends Connection implements Runnable {
String dfrom = parser.getAttributeValue(null, "from");
String to = parser.getAttributeValue(null, "to");
LOGGER.info("STREAM FROM " + dfrom + " TO " + to + " " + streamID + " ASKING FOR DIALBACK");
- if (dfrom.endsWith(XMPPComponent.HOSTNAME) && (dfrom.equals(XMPPComponent.HOSTNAME) || dfrom.endsWith("." + XMPPComponent.HOSTNAME))) {
+ if (dfrom.endsWith(xmpp.HOSTNAME) && (dfrom.equals(xmpp.HOSTNAME) || dfrom.endsWith("." + xmpp.HOSTNAME))) {
break;
}
- if (to != null && to.equals(XMPPComponent.HOSTNAME)) {
+ if (to != null && to.equals(xmpp.HOSTNAME)) {
String dbKey = XmlUtils.getTagText(parser);
updateTsRemoteData();
- ConnectionOut c = XMPPComponent.getConnectionOut(dfrom, false);
+ ConnectionOut c = xmpp.getConnectionOut(dfrom, false);
if (c != null) {
c.sendDialbackVerify(streamID, dbKey);
} else {
- c = new ConnectionOut(dfrom, streamID, dbKey);
- XMPPComponent.executorService.submit(c);
+ c = new ConnectionOut(xmpp, dfrom, streamID, dbKey);
+ xmpp.executorService.submit(c);
}
} else {
throw new HostUnknownException("STREAM FROM " + dfrom + " " + streamID + " INVALID TO " + to);
@@ -107,15 +109,15 @@ public class ConnectionIn extends Connection implements Runnable {
} 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))) {
- JuickBot.incomingPresence(p);
+ bot.incomingPresence(p);
}
} else if (tag.equals("message") && checkFromTo(parser)) {
updateTsRemoteData();
- Message msg = Message.parse(parser, XMPPComponent.childParsers);
+ Message msg = Message.parse(parser, xmpp.childParsers);
if (msg != null && (msg.type == null || !msg.type.equals(Message.Type.error))) {
LOGGER.info("STREAM " + streamID + ": " + msg.toString());
- if (!JuickBot.incomingMessage(msg)) {
- XMPPComponent.connRouter.router.send(msg.toString());
+ if (!bot.incomingMessage(msg)) {
+ xmpp.router.send(msg.toString());
}
}
} else if (tag.equals("iq") && checkFromTo(parser)) {
@@ -124,7 +126,7 @@ public class ConnectionIn extends Connection implements Runnable {
String xml = XmlUtils.parseToString(parser, true);
if (type == null || !type.equals(Iq.Type.error)) {
LOGGER.info("STREAM " + streamID + ": " + xml);
- XMPPComponent.connRouter.router.send(xml);
+ xmpp.router.send(xml);
}
} else if (!isSecured() && tag.equals("starttls")) {
LOGGER.info("STREAM " + streamID + " SECURING");
@@ -140,7 +142,7 @@ public class ConnectionIn extends Connection implements Runnable {
} catch (SSLException sex) {
LOGGER.warning("STREAM " + streamID + " SSL ERROR");
sendStanza("<failed xmlns\"" + NS_TLS + "\" />");
- XMPPComponent.removeConnectionIn(this);
+ xmpp.removeConnectionIn(this);
closeConnection();
}
} else if (isSecured() && tag.equals("stream") && parser.getNamespace().equals(NS_STREAM)) {
@@ -150,17 +152,17 @@ public class ConnectionIn extends Connection implements Runnable {
}
}
LOGGER.warning("STREAM " + streamID + " FINISHED");
- XMPPComponent.removeConnectionIn(this);
+ xmpp.removeConnectionIn(this);
closeConnection();
} catch (EOFException ex) {
LOGGER.info(String.format("STREAM %s CLOSED (dirty)", streamID));
- XMPPComponent.removeConnectionIn(this);
+ xmpp.removeConnectionIn(this);
closeConnection();
} catch (HostUnknownException e) {
LOGGER.warning(e.getMessage());
} catch (Exception e) {
LOGGER.log(Level.WARNING, "STREAM " + streamID + " ERROR", e);
- XMPPComponent.removeConnectionIn(this);
+ xmpp.removeConnectionIn(this);
closeConnection();
}
}
@@ -172,10 +174,10 @@ public class ConnectionIn extends Connection implements Runnable {
void sendOpenStream(String from, boolean xmppversionnew) throws IOException {
String openStream = "<?xml version='1.0'?><stream:stream xmlns='jabber:server' " +
"xmlns:stream='http://etherx.jabber.org/streams' xmlns:db='jabber:server:dialback' from='" +
- XMPPComponent.HOSTNAME + "' id='" + streamID + "' version='1.0'>";
+ xmpp.HOSTNAME + "' id='" + streamID + "' version='1.0'>";
if (xmppversionnew) {
openStream += "<stream:features>";
- if (!isSecured() && !XMPPComponent.brokenSSLhosts.contains(from)) {
+ if (!isSecured() && !xmpp.brokenSSLhosts.contains(from)) {
openStream += "<starttls xmlns=\"" + NS_TLS + "\"><optional/></starttls>";
}
openStream += "</stream:features>";
@@ -185,7 +187,7 @@ public class ConnectionIn extends Connection implements Runnable {
public void sendDialbackResult(String sfrom, String type) {
try {
- sendStanza("<db:result from='" + XMPPComponent.HOSTNAME + "' to='" + sfrom + "' type='" + type + "'/>");
+ sendStanza("<db:result from='" + xmpp.HOSTNAME + "' to='" + sfrom + "' type='" + type + "'/>");
if (type.equals("valid")) {
from.add(sfrom);
LOGGER.info("STREAM FROM " + sfrom + " " + streamID + " READY");
@@ -200,7 +202,7 @@ public class ConnectionIn extends Connection implements Runnable {
String cto = parser.getAttributeValue(null, "to");
if (cfrom != null && cto != null && !cfrom.isEmpty() && !cto.isEmpty()) {
JID jidto = new JID(cto);
- if (jidto.Host != null && jidto.Username != null && jidto.Host.equals(XMPPComponent.HOSTNAME) && jidto.Username.matches("^[a-zA-Z0-9\\-]{2,16}$")) {
+ if (jidto.Host != null && jidto.Username != null && jidto.Host.equals(xmpp.HOSTNAME) && jidto.Username.matches("^[a-zA-Z0-9\\-]{2,16}$")) {
JID jidfrom = new JID(cfrom);
int size = from.size();
for (int i = 0; i < size; i++) {