aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-05-13 16:22:13 +0300
committerGravatar Vitaly Takmazov2016-05-13 16:22:13 +0300
commit0ae572563427dcaba845b893bcef35fe7f172dd8 (patch)
tree44a1ac6e822557c77df3e537f61830c58ae0afeb /src/main/java/com/juick
parent8e4ab831c7342d3fc4a7829c10152d41c3e61f1e (diff)
parentc4d77b873c4deb15a968ac17998a024bd0c618d4 (diff)
Merge branch 'rebase_all' of ssh://den.jabber.ru:2205/var/lib/git/com.juick.http.www into rebase_all
Diffstat (limited to 'src/main/java/com/juick')
-rw-r--r--src/main/java/com/juick/PushComponent.java14
-rw-r--r--src/main/java/com/juick/http/www/PageTemplates.java45
-rw-r--r--src/main/java/com/juick/http/www/UserThread.java4
-rw-r--r--src/main/java/com/juick/xmpp/s2s/ConnectionIn.java20
-rw-r--r--src/main/java/com/juick/xmpp/s2s/ConnectionOut.java41
-rw-r--r--src/main/java/com/juick/xmpp/s2s/XMPPComponent.java3
6 files changed, 40 insertions, 87 deletions
diff --git a/src/main/java/com/juick/PushComponent.java b/src/main/java/com/juick/PushComponent.java
index 688f1cdd..386448f4 100644
--- a/src/main/java/com/juick/PushComponent.java
+++ b/src/main/java/com/juick/PushComponent.java
@@ -170,14 +170,8 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
boolean isPM = jmsg.getMID() == 0;
boolean isReply = jmsg.getRID() > 0;
int senderID = 0, recipientID = 0;
- // reply pushed to original sender
if (isReply) {
- com.juick.Message op = MessagesQueries.getMessage(sql, jmsg.getMID());
- senderID = op.getUser().getUID();
- // do not notify self
- if (jmsg.getUser().getUID() == op.getUser().getUID()) {
- return;
- }
+ senderID = jmsg.getUser().getUID();
}
if (isPM) {
// PM
@@ -198,7 +192,7 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
regids.add(targetId);
}
} else {
- regids = PushQueries.getAndroidSubscribers(sql, senderID);
+ regids = isReply ? PushQueries.getAndroidSubscribersToComments(sql, jmsg.getMID(), senderID) : PushQueries.getAndroidSubscribers(sql, senderID);
}
if (!regids.isEmpty()) {
@@ -230,7 +224,7 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
urls.add(targetURL);
}
} else {
- urls = PushQueries.getWinPhoneSubscribers(sql, senderID);
+ urls = isReply ? PushQueries.getWindowsSubscribersToComments(sql, jmsg.getMID(), senderID) :PushQueries.getWinPhoneSubscribers(sql, senderID);
}
@@ -276,7 +270,7 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
tokens.add(targetToken);
}
} else {
- tokens = PushQueries.getAPNSSubscribers(sql, senderID);
+ tokens = isReply ? PushQueries.getAppleSubscribersToComments(sql, jmsg.getMID(), senderID) : PushQueries.getAPNSSubscribers(sql, senderID);
}
if (!tokens.isEmpty()) {
ApnsService service = APNS.newService().withCert("/etc/juick/ios.p12", "juick")
diff --git a/src/main/java/com/juick/http/www/PageTemplates.java b/src/main/java/com/juick/http/www/PageTemplates.java
index 2f9c8976..fedb11bf 100644
--- a/src/main/java/com/juick/http/www/PageTemplates.java
+++ b/src/main/java/com/juick/http/www/PageTemplates.java
@@ -105,43 +105,6 @@ public class PageTemplates {
out.println("</header>");
}
- public static void pageYandexAd728(PrintWriter out, int YandexID) {
- /*
- out.println("<div id=\"yandex_ad_728\"></div>");
- out.println("<script type=\"text/javascript\">");
- out.println("if($(window).width()>1000) {");
- out.println("(function(w, d, n, s, t) {");
- out.println("w[n] = w[n] || [];");
- out.println("w[n].push(function() {");
- out.println("Ya.Direct.insertInto(84715, \"yandex_ad_728\", {");
- out.println("stat_id: " + YandexID + ",");
- out.println("site_charset: \"utf-8\",");
- out.println("ad_format: \"direct\",");
- out.println("type: \"728x90\",");
- out.println("site_bg_color: \"FFFFFF\",");
- out.println("title_color: \"006699\",");
- out.println("url_color: \"000000\",");
- out.println("text_color: \"000000\",");
- out.println("hover_color: \"006699\"");
- out.println("});");
- out.println("});");
- out.println("t = d.getElementsByTagName(\"script\")[0]");
- out.println("s = d.createElement(\"script\");");
- out.println("s.type = \"text/javascript\";");
- out.println("s.src = \"//an.yandex.ru/system/context.js\";");
- out.println("s.async = true");
- out.println("t.parentNode.insertBefore(s, t);");
- out.println("})(window, document, \"yandex_context_callbacks\");");
- out.println("} else { $('#yandex_ad_728').remove(); }");
- out.println("</script>");
- */
- out.println("<script async src='//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'></script>");
- out.println("<ins class='adsbygoogle adslot1' data-ad-client='ca-pub-1706616473363517' data-ad-slot='4828054583' data-ad-format='auto' style='display:block'></ins>");
- out.println("<script>");
- out.println("(adsbygoogle = window.adsbygoogle || []).push({})");
- out.println("</script>");
- }
-
public static void pageHomeColumn(PrintWriter out, Connection sql, com.juick.User visitor) {
pageHomeColumn(out, sql, visitor, false);
}
@@ -231,7 +194,7 @@ public class PageTemplates {
out.print("<a href=\"https://vk.com/juick\" rel=\"nofollow\" class=\"ico32-vk\">ВКонтакте</a>");
out.print("<a href=\"https://www.facebook.com/JuickCom\" rel=\"nofollow\" class=\"ico32-fb\">Facebook</a>");
out.println("</div>");
- out.print(" <div id=\"footer-left\">juick.com &copy; 2008-2015");
+ out.print(" <div id=\"footer-left\">juick.com &copy; 2008-2016");
String queryString = request.getQueryString();
String requestURI = request.getRequestURI();
@@ -514,10 +477,6 @@ public class PageTemplates {
for (int i = 0; i < msgs.size(); i++) {
- if (i == 0 && YandexID > 0 && ad_mid == 0) {
- pageYandexAd728(out, YandexID);
- }
-
com.juick.Message msg = msgs.get(i);
List<com.juick.Tag> tags = MessagesQueries.getMessageTags(sql, msg.getMID());
@@ -553,12 +512,12 @@ public class PageTemplates {
}
out.print(" <nav class=\"l\">");
msg.ReadOnly |= blUIDs.contains(msg.getUser().getUID());
+ out.print("<a href=\"#\" onclick=\"return likeMessage(this," + msg.getMID() + ")\">Мне нравится</a>");
if (visitor == null && !msg.ReadOnly) {
out.print("<a href=\"#\" onclick=\"return openDialogLogin()\">Комментировать</a> ");
} else if (visitor != null && (!msg.ReadOnly || visitor.getUID() == msg.getUser().getUID())) {
out.print("<a href=\"#\" onclick=\"return showCommentFooter(this)\">Комментировать</a> ");
}
- out.print("<a href=\"#\" onclick=\"return likeMessage(this," + msg.getMID() + ")\">Мне нравится</a>");
if (visitor != null && msg.Privacy < 0 && msg.getUser().getUID() == visitor.getUID()) {
out.print(" <a href=\"#\" onclick=\"return setPrivacy(this," + msg.getMID() + ")\">Открыть доступ</a>");
}
diff --git a/src/main/java/com/juick/http/www/UserThread.java b/src/main/java/com/juick/http/www/UserThread.java
index fe5ca32f..4ee290ab 100644
--- a/src/main/java/com/juick/http/www/UserThread.java
+++ b/src/main/java/com/juick/http/www/UserThread.java
@@ -261,10 +261,6 @@ public class UserThread {
}
out.println("</ul>");
- if (replies.size() > 0) {
- PageTemplates.pageYandexAd728(out, 1);
- }
-
for (Message reply : replies) {
reply.cleanupChilds();
}
diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java b/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java
index 8fa773b7..554d3b05 100644
--- a/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java
+++ b/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java
@@ -46,15 +46,14 @@ public class ConnectionIn extends Connection implements Runnable {
parser.next(); // stream:stream
updateTsRemoteData();
if (!parser.getName().equals("stream")
- || !parser.getNamespace("stream").equals(NS_STREAM)
- || !parser.getNamespace("db").equals(NS_DB)) {
+ || !parser.getNamespace("stream").equals(NS_STREAM)) {
// || !parser.getAttributeValue(null, "version").equals("1.0")
// || !parser.getAttributeValue(null, "to").equals(Main.HOSTNAME)) {
throw new Exception("STREAM FROM ? " + streamID + " INVALID FIRST PACKET");
}
boolean xmppversionnew = parser.getAttributeValue(null, "version") != null;
- sendOpenStream(xmppversionnew);
+ sendOpenStream(parser.getAttributeValue(null, "from"), xmppversionnew);
while (parser.next() != XmlPullParser.END_DOCUMENT) {
updateTsRemoteData();
@@ -85,7 +84,7 @@ public class ConnectionIn extends Connection implements Runnable {
XMPPComponent.executorService.submit(c);
}
} else {
- throw new Exception("STREAM FROM " + dfrom + " " + streamID + " DIALBACK RESULT FAIL");
+ throw new HostUnknownException("STREAM FROM " + dfrom + " " + streamID + " INVALID TO " + to);
}
} else if (tag.equals("verify") && parser.getNamespace().equals(NS_DB)) {
String vfrom = parser.getAttributeValue(null, "from");
@@ -145,7 +144,7 @@ public class ConnectionIn extends Connection implements Runnable {
closeConnection();
}
} else if (isSecured() && tag.equals("stream") && parser.getNamespace().equals(NS_STREAM)) {
- sendOpenStream(true);
+ sendOpenStream(null, true);
} else {
LOGGER.info("STREAM " + streamID + ": " + XmlUtils.parseToString(parser, true));
}
@@ -157,6 +156,8 @@ public class ConnectionIn extends Connection implements Runnable {
LOGGER.info(String.format("STREAM %s CLOSED (dirty)", streamID));
XMPPComponent.removeConnectionIn(this);
closeConnection();
+ } catch (HostUnknownException e) {
+ LOGGER.warning(e.getMessage());
} catch (Exception e) {
LOGGER.log(Level.WARNING, "STREAM " + streamID + " ERROR", e);
XMPPComponent.removeConnectionIn(this);
@@ -168,13 +169,13 @@ public class ConnectionIn extends Connection implements Runnable {
tsRemoteData = System.currentTimeMillis();
}
- void sendOpenStream(boolean xmppversionnew) throws IOException {
+ 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'>";
if (xmppversionnew) {
openStream += "<stream:features>";
- if (!isSecured()) {
+ if (!isSecured() && !XMPPComponent.brokenSSLhosts.contains(from)) {
openStream += "<starttls xmlns=\"" + NS_TLS + "\"><optional/></starttls>";
}
openStream += "</stream:features>";
@@ -211,4 +212,9 @@ public class ConnectionIn extends Connection implements Runnable {
}
return false;
}
+ class HostUnknownException extends Exception {
+ public HostUnknownException(String message) {
+ super(message);
+ }
+ }
}
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();
}
diff --git a/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java b/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java
index 03a12c26..2b293fd6 100644
--- a/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java
+++ b/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java
@@ -30,6 +30,7 @@ public class XMPPComponent implements ServletContextListener {
public static String STATSFILE = null;
public static String keystore;
public static String keystorePassword;
+ public static List<String> brokenSSLhosts;
public static ConnectionRouter connRouter;
static final List<ConnectionIn> inConnections = Collections.synchronizedList(new ArrayList<>());
static final List<ConnectionOut> outConnections = Collections.synchronizedList(new ArrayList<>());
@@ -163,7 +164,7 @@ public class XMPPComponent implements ServletContextListener {
STATSFILE = conf.getProperty("statsfile");
keystore = conf.getProperty("keystore");
keystorePassword = conf.getProperty("keystore_password");
-
+ brokenSSLhosts = Arrays.asList(conf.getProperty("broken_ssl_hosts", "").split(","));
Class.forName("com.mysql.jdbc.Driver");
sql = DriverManager.getConnection("jdbc:mysql://localhost/juick?autoReconnect=true&user=" +
conf.getProperty("mysql_username", "") + "&password=" + conf.getProperty("mysql_password", ""));