From 6e93a73628ee87cf4bba12098c7a27a5fd03bc64 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 31 Jan 2017 06:57:45 +0300 Subject: update dependencies --- juick-xmpp/build.gradle | 6 +-- .../main/java/com/juick/components/XMPPServer.java | 10 ++-- .../com/juick/components/s2s/ConnectionIn.java | 11 +++-- .../com/juick/components/s2s/ConnectionRouter.java | 21 ++++---- .../java/com/juick/components/s2s/JuickBot.java | 57 +++++++++++----------- 5 files changed, 53 insertions(+), 52 deletions(-) (limited to 'juick-xmpp') diff --git a/juick-xmpp/build.gradle b/juick-xmpp/build.gradle index 268c5e7b..5bd71e64 100644 --- a/juick-xmpp/build.gradle +++ b/juick-xmpp/build.gradle @@ -5,16 +5,16 @@ apply plugin: 'com.github.ben-manes.versions' dependencies { compile project(':juick-server') - compile 'com.github.juick:com.juick.xmpp:dbf603cfff' + compile 'com.github.juick:com.juick.xmpp:43212cf5ac' compile "org.slf4j:slf4j-api:${rootProject.slf4jVersion}" compile "org.springframework:spring-webmvc:${rootProject.springFrameworkVersion}" compile "com.fasterxml.jackson.core:jackson-core:${rootProject.jacksonVersion}" compile "com.fasterxml.jackson.core:jackson-databind:${rootProject.jacksonVersion}" compile "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:${rootProject.jacksonVersion}" compile 'javax.inject:javax.inject:1' - compile 'org.apache.httpcomponents:httpclient:4.5.2' + compile 'org.apache.httpcomponents:httpclient:4.5.3' compile 'org.apache.commons:commons-dbcp2:2.1.1' - compile 'net.jodah:failsafe:1.0.1' + compile 'net.jodah:failsafe:1.0.3' providedRuntime 'mysql:mysql-connector-java:5.1.40' } diff --git a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java index 3bfa49e1..4a182cc9 100644 --- a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java +++ b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java @@ -2,7 +2,6 @@ package com.juick.components; import com.juick.components.s2s.*; import com.juick.service.*; -import com.juick.xmpp.JID; import com.juick.xmpp.Stanza; import com.juick.xmpp.StanzaChild; import com.juick.xmpp.extensions.JuickMessage; @@ -13,6 +12,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.env.Environment; import org.xmlpull.v1.XmlPullParserException; +import rocks.xmpp.addr.Jid; import javax.inject.Inject; import java.io.IOException; @@ -59,7 +59,7 @@ public class XMPPServer implements AutoCloseable { @Inject public SubscriptionService subscriptionService; - private JID jid; + private Jid jid; private ServerSocket listener; @@ -76,7 +76,7 @@ public class XMPPServer implements AutoCloseable { keystorePassword = env.getProperty("keystore_password"); brokenSSLhosts = Arrays.asList(env.getProperty("broken_ssl_hosts", StringUtils.EMPTY).split(",")); bannedHosts = Arrays.asList(env.getProperty("banned_hosts", StringUtils.EMPTY).split(",")); - jid = new JID(env.getProperty("xmppbot_jid")); + jid = Jid.of(env.getProperty("xmppbot_jid")); boolean disabled = BooleanUtils.toBoolean(env.getProperty("xmpp_disabled", "false")); childParsers.put(JuickMessage.XMLNS, new JuickMessage()); @@ -196,7 +196,7 @@ public class XMPPServer implements AutoCloseable { } public void sendOut(Stanza s) { - sendOut(s.to.Host, s.toString()); + sendOut(s.to.getDomain(), s.toString()); } public void sendOut(String hostname, String xml) { @@ -286,7 +286,7 @@ public class XMPPServer implements AutoCloseable { stanzaListeners.forEach(l -> l.stanzaReceived(type, xmlValue)); } - public JID getJid() { + public Jid getJid() { return jid; } } diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java index 882cc2f7..8713aa03 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java @@ -2,11 +2,11 @@ package com.juick.components.s2s; import com.juick.components.XMPPServer; import com.juick.xmpp.Iq; -import com.juick.xmpp.JID; import com.juick.xmpp.Message; import com.juick.xmpp.Presence; import com.juick.xmpp.utils.XmlUtils; import org.xmlpull.v1.XmlPullParser; +import rocks.xmpp.addr.Jid; import javax.net.ssl.SSLException; import javax.net.ssl.SSLSocket; @@ -188,12 +188,13 @@ public class ConnectionIn extends Connection implements Runnable { String cfrom = parser.getAttributeValue(null, "from"); 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(xmpp.HOSTNAME) && jidto.Username.matches("^[a-zA-Z0-9\\-]{2,16}$")) { - JID jidfrom = new JID(cfrom); + Jid jidto = Jid.of(cto); + if (jidto.getDomain() != null && jidto.getLocal() != null && jidto.getDomain().equals(xmpp.HOSTNAME) + && jidto.getLocal().matches("^[a-zA-Z0-9\\-]{2,16}$")) { + Jid jidfrom = Jid.of(cfrom); int size = from.size(); for (int i = 0; i < size; i++) { - if (from.get(i).equals(jidfrom.Host)) { + if (from.get(i).equals(jidfrom.getDomain())) { return true; } } diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java index 37d3c59f..f0fc3c60 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java @@ -2,7 +2,6 @@ package com.juick.components.s2s; import com.juick.User; import com.juick.components.XMPPServer; -import com.juick.xmpp.JID; import com.juick.xmpp.Message; import com.juick.xmpp.extensions.JuickMessage; import com.juick.xmpp.extensions.Nickname; @@ -15,6 +14,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; +import rocks.xmpp.addr.Jid; import java.io.IOException; import java.io.InputStreamReader; @@ -92,15 +92,15 @@ public class ConnectionRouter extends Connection implements Runnable, AutoClosea String tag = parser.getName(); String to = parser.getAttributeValue(null, "to"); if (to != null && (tag.equals("message") || tag.equals("presence") || tag.equals("iq"))) { - JID jid = new JID(to); - if (jid.Host != null) { - if (jid.Host.equals(componentName)) { + Jid jid = Jid.of(to); + if (jid.getDomain() != null) { + if (jid.getDomain().equals(componentName)) { if (tag.equals("message")) { Message xmsg = Message.parse(parser, xmpp.childParsers); logger.info("stream router (process): {}", xmsg); JuickMessage jmsg = (JuickMessage) xmsg.getChild(JuickMessage.XMLNS); if (jmsg != null) { - if (jid.Username != null && jid.Username.equals("recomm")) { + if (jid.getLocal() != null && jid.getLocal().equals("recomm")) { sendJuickRecommendation(jmsg); } else { if (jmsg.getRid() > 0) { @@ -114,13 +114,14 @@ public class ConnectionRouter extends Connection implements Runnable, AutoClosea String xml = XmlUtils.parseToString(parser, true); logger.info("stream router (stanza): {}", xml); } - } else if (jid.Host.endsWith(xmpp.HOSTNAME) && (jid.Host.equals(xmpp.HOSTNAME) || jid.Host.endsWith("." + xmpp.HOSTNAME))) { + } else if (jid.getDomain().endsWith(xmpp.HOSTNAME) && (jid.getDomain().equals(xmpp.HOSTNAME) + || jid.getDomain().endsWith("." + xmpp.HOSTNAME))) { String xml = XmlUtils.parseToString(parser, true); logger.info("stream router: {}", xml); } else { String xml = XmlUtils.parseToString(parser, true); logger.info("stream router (out): {}", xml); - xmpp.sendOut(jid.Host, xml); + xmpp.sendOut(jid.getDomain(), xml); } } else { String invalidStanza = XmlUtils.parseToString(parser, true); @@ -183,7 +184,7 @@ public class ConnectionRouter extends Connection implements Runnable, AutoClosea } for (String jid : jids) { - msg.to = new JID(jid); + msg.to = Jid.of(jid); xmpp.sendOut(msg); } } @@ -214,7 +215,7 @@ public class ConnectionRouter extends Connection implements Runnable, AutoClosea msg.addChild(jmsg); for (User user : users) { for (String jid : xmpp.userService.getJIDsbyUID(user.getUid())) { - msg.to = new JID(jid); + msg.to = Jid.of(jid); xmpp.sendOut(msg); } } @@ -262,7 +263,7 @@ public class ConnectionRouter extends Connection implements Runnable, AutoClosea for (User user : users) { for (String jid : xmpp.userService.getJIDsbyUID(user.getUid())) { - msg.to = new JID(jid); + msg.to = Jid.of(jid); xmpp.sendOut(msg); } } diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java b/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java index eec9b8e2..f309bd21 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java @@ -2,13 +2,13 @@ package com.juick.components.s2s; import com.juick.User; import com.juick.components.XMPPServer; -import com.juick.xmpp.JID; import com.juick.xmpp.Message; import com.juick.xmpp.Presence; import com.juick.xmpp.Stanza; -import com.juick.xmpp.extensions.Error; +import com.juick.xmpp.extensions.XMPPError; import com.juick.xmpp.extensions.JuickMessage; import org.apache.commons.lang3.StringUtils; +import rocks.xmpp.addr.Jid; import javax.inject.Inject; import java.util.List; @@ -64,13 +64,13 @@ public class JuickBot implements StanzaListener { + "Read more: http://juick.com/help/"; public boolean incomingPresence(Presence p) { - final String username = p.to.Username.toLowerCase(); + final String username = p.to.getLocal(); final boolean toJuick = username.equals("juick"); if (p.type == null) { Presence reply = new Presence(); - reply.from = new JID(p.to.Username, p.to.Host, null); - reply.to = new JID(p.from.Username, p.from.Host, null); + reply.from = p.to.asBareJid(); + reply.to = p.from.asBareJid(); reply.type = Presence.Type.unsubscribe; xmpp.sendOut(reply); return true; @@ -82,15 +82,14 @@ public class JuickBot implements StanzaListener { if (toJuick || uid_to > 0) { Presence reply = new Presence(); - reply.from = p.to; - reply.from.Resource = "Juick"; + reply.from = p.to.withResource("Juick"); reply.to = p.from; reply.priority = 10; xmpp.sendOut(reply); } else { Presence reply = new Presence(p.to, p.from, Presence.Type.error); reply.id = p.id; - reply.addChild(new Error(Error.Type.cancel, "item-not-found")); + reply.addChild(new XMPPError(XMPPError.Type.cancel, "item-not-found")); xmpp.sendOut(reply); return true; } @@ -102,7 +101,7 @@ public class JuickBot implements StanzaListener { } else { int uid_to = xmpp.userService.getUIDbyName(username); if (uid_to > 0) { - xmpp.pmQueriesService.addPMinRoster(uid_to, p.from.Bare()); + xmpp.pmQueriesService.addPMinRoster(uid_to, p.from.asBareJid().toEscapedString()); canSubscribe = true; } } @@ -111,7 +110,7 @@ public class JuickBot implements StanzaListener { Presence reply = new Presence(p.to, p.from, Presence.Type.subscribed); xmpp.sendOut(reply); - reply.from.Resource = "Juick"; + reply.from = reply.from.withResource("Juick"); reply.priority = 10; reply.type = null; xmpp.sendOut(reply); @@ -120,7 +119,7 @@ public class JuickBot implements StanzaListener { } else { Presence reply = new Presence(p.to, p.from, Presence.Type.error); reply.id = p.id; - reply.addChild(new Error(Error.Type.cancel, "item-not-found")); + reply.addChild(new XMPPError(XMPPError.Type.cancel, "item-not-found")); xmpp.sendOut(reply); return true; } @@ -128,7 +127,7 @@ public class JuickBot implements StanzaListener { if (!toJuick) { int uid_to = xmpp.userService.getUIDbyName(username); if (uid_to > 0) { - xmpp.pmQueriesService.removePMinRoster(uid_to, p.from.Bare()); + xmpp.pmQueriesService.removePMinRoster(uid_to, p.from.asBareJid().toEscapedString()); } } @@ -144,13 +143,13 @@ public class JuickBot implements StanzaListener { return false; } - String username = msg.to.Username.toLowerCase(); + String username = msg.to.getLocal(); User user_from; String signuphash = StringUtils.EMPTY; - user_from = xmpp.userService.getUserByJID(msg.from.Bare()); + user_from = xmpp.userService.getUserByJID(msg.from.asBareJid().toEscapedString()); if (user_from == null) { - signuphash = xmpp.userService.getSignUpHashByJID(msg.from.Bare()); + signuphash = xmpp.userService.getSignUpHashByJID(msg.from.asBareJid().toEscapedString()); } if (user_from == null) { @@ -173,7 +172,7 @@ public class JuickBot implements StanzaListener { if (uid_to == 0) { Message reply = new Message(msg.to, msg.from, Message.Type.error); reply.id = msg.id; - reply.addChild(new Error(Error.Type.cancel, "item-not-found")); + reply.addChild(new XMPPError(XMPPError.Type.cancel, "item-not-found")); xmpp.sendOut(reply); return true; } @@ -185,15 +184,15 @@ public class JuickBot implements StanzaListener { if (success) { Message m = new Message(); - m.from = new JID("juick", "juick.com", null); - m.to = new JID(Integer.toString(uid_to), "push.juick.com", null); + m.from = Jid.of("juick@juick.com"); + m.to = Jid.of(Integer.toString(uid_to), "push.juick.com", null); JuickMessage jmsg = new JuickMessage(); jmsg.setUser(user_from); jmsg.setText(msg.body); m.childs.add(jmsg); xmpp.getRouter().sendStanza(m.toString()); - m.to.Host = "ws.juick.com"; + m.to = Jid.of(Integer.toString(uid_to), "ws.juick.com", null); xmpp.getRouter().sendStanza(m.toString()); List jids; @@ -201,14 +200,14 @@ public class JuickBot implements StanzaListener { jids = xmpp.userService.getJIDsbyUID(uid_to); for (String jid : jids) { Message mm = new Message(); - mm.to = new JID(jid); + mm.to = Jid.of(jid); mm.type = Message.Type.chat; inroster = xmpp.pmQueriesService.havePMinRoster(user_from.getUid(), jid); if (inroster) { - mm.from = new JID(jmsg.getUser().getName(), "juick.com", "Juick"); + mm.from = Jid.of(jmsg.getUser().getName(), "juick.com", "Juick"); mm.body = msg.body; } else { - mm.from = new JID("juick", "juick.com", "Juick"); + mm.from = Jid.of("juick", "juick.com", "Juick"); mm.body = "Private message from @" + jmsg.getUser().getName() + ":\n" + msg.body; } xmpp.sendOut(mm); @@ -216,7 +215,7 @@ public class JuickBot implements StanzaListener { } else { Message reply = new Message(msg.to, msg.from, Message.Type.error); reply.id = msg.id; - reply.addChild(new Error(Error.Type.cancel, "not-allowed")); + reply.addChild(new XMPPError(XMPPError.Type.cancel, "not-allowed")); xmpp.sendOut(reply); } @@ -313,27 +312,27 @@ public class JuickBot implements StanzaListener { if (ret == 200) { Message msg = new Message(); - msg.from = new JID("juick", "juick.com", null); - msg.to = new JID(Integer.toString(uid_to), "push.juick.com", null); + msg.from = Jid.of("juick", "juick.com", null); + msg.to = Jid.of(Integer.toString(uid_to), "push.juick.com", null); JuickMessage jmsg = new JuickMessage(); jmsg.setUser(user_from); jmsg.setText(body); msg.childs.add(jmsg); xmpp.getRouter().sendStanza(msg.toString()); - msg.to.Host = "ws.juick.com"; + msg.to = Jid.of(Integer.toString(uid_to), "ws.juick.com", null); xmpp.getRouter().sendStanza(msg.toString()); for (String jid : jids_to) { Message mm = new Message(); - mm.to = new JID(jid); + mm.to = Jid.of(jid); mm.type = Message.Type.chat; haveInRoster = xmpp.pmQueriesService.havePMinRoster(user_from.getUid(), jid); if (haveInRoster) { - mm.from = new JID(user_from.getName(), "juick.com", "Juick"); + mm.from = Jid.of(user_from.getName(), "juick.com", "Juick"); mm.body = body; } else { - mm.from = new JID("juick", "juick.com", "Juick"); + mm.from = Jid.of("juick", "juick.com", "Juick"); mm.body = "Private message from @" + user_from.getName() + ":\n" + body; } xmpp.sendOut(mm); -- cgit v1.2.3