Commit 0178c18c authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

1. Fixed #storeOffline to filter correct messages. JM-265

2. Fixed #bounce to use the router. JM-265


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1286 b35dd754-fafc-0310-a699-88a17e54d16e
parent 69ecb34f
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
package org.jivesoftware.messenger; package org.jivesoftware.messenger;
import org.jivesoftware.messenger.container.BasicModule; import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
import org.xmpp.packet.PacketError; import org.xmpp.packet.PacketError;
...@@ -27,9 +27,10 @@ public class OfflineMessageStrategy extends BasicModule { ...@@ -27,9 +27,10 @@ public class OfflineMessageStrategy extends BasicModule {
private static int quota = 100*1024; // Default to 100 K. private static int quota = 100*1024; // Default to 100 K.
private static Type type = Type.store_and_bounce; private static Type type = Type.store_and_bounce;
private SessionManager sessionManager;
private OfflineMessageStore messageStore; private OfflineMessageStore messageStore;
private JID serverAddress;
private PacketRouter router;
public OfflineMessageStrategy() { public OfflineMessageStrategy() {
super("Offline Message Strategy"); super("Offline Message Strategy");
...@@ -58,35 +59,29 @@ public class OfflineMessageStrategy extends BasicModule { ...@@ -58,35 +59,29 @@ public class OfflineMessageStrategy extends BasicModule {
public void storeOffline(Message message) { public void storeOffline(Message message) {
if (message != null) { if (message != null) {
Session senderSession = sessionManager.getSession(message.getFrom()); // Do nothing if the message was sent to the server itself or to an anonymous user
if (senderSession == null) { if (message.getTo() == null || serverAddress.equals(message.getTo()) ||
message.getTo().getNode() == null) {
return; return;
} }
JID sender = senderSession.getAddress();
// server messages and anonymous messages can be silently dropped if (type == Type.bounce) {
if (sender == null || sender.getNode() == null) { bounce(message);
// silently drop the server message
} }
else { else if (type == Type.store) {
if (type == Type.bounce) { store(message);
bounce(message); }
} else if (type == Type.store_and_bounce) {
else if (type == Type.store) { if (underQuota(message)) {
store(message); store(message);
} }
else if (type == Type.store_and_bounce) { else {
if (underQuota(message)) { bounce(message);
store(message);
}
else {
bounce(message);
}
} }
else if (type == Type.store_and_drop) { }
if (underQuota(message)) { else if (type == Type.store_and_drop) {
store(message); if (underQuota(message)) {
} store(message);
} }
} }
} }
...@@ -101,14 +96,19 @@ public class OfflineMessageStrategy extends BasicModule { ...@@ -101,14 +96,19 @@ public class OfflineMessageStrategy extends BasicModule {
} }
private void bounce(Message message) { private void bounce(Message message) {
// Generate a rejection response to the sender // Do nothing if the sender was the server itself
if (message.getFrom() == null) {
return;
}
try { try {
Session session = sessionManager.getSession(message.getFrom()); // Generate a rejection response to the sender
Message errorResponse = message.createCopy(); Message errorResponse = message.createCopy();
errorResponse.setError(new PacketError(PacketError.Condition.item_not_found, errorResponse.setError(new PacketError(PacketError.Condition.item_not_found,
PacketError.Type.continue_processing)); PacketError.Type.continue_processing));
session.process(errorResponse); errorResponse.setFrom(message.getTo());
errorResponse.setTo(message.getFrom());
// Send the response
router.route(errorResponse);
} }
catch (Exception e) { catch (Exception e) {
Log.error(e); Log.error(e);
...@@ -118,7 +118,8 @@ public class OfflineMessageStrategy extends BasicModule { ...@@ -118,7 +118,8 @@ public class OfflineMessageStrategy extends BasicModule {
public void initialize(XMPPServer server) { public void initialize(XMPPServer server) {
super.initialize(server); super.initialize(server);
messageStore = server.getOfflineMessageStore(); messageStore = server.getOfflineMessageStore();
sessionManager = server.getSessionManager(); router = server.getPacketRouter();
serverAddress = new JID(server.getServerInfo().getName());
String quota = JiveGlobals.getProperty("xmpp.offline.quota"); String quota = JiveGlobals.getProperty("xmpp.offline.quota");
if (quota != null && quota.length() > 0) { if (quota != null && quota.length() > 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment