Commit 0a94812d authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Return service_unavailable when IQ packet is blocked.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3428 b35dd754-fafc-0310-a699-88a17e54d16e
parent 316114f2
...@@ -717,22 +717,33 @@ public class ClientSession extends Session { ...@@ -717,22 +717,33 @@ public class ClientSession extends Session {
conflictCount++; conflictCount++;
} }
public void process(Packet packet) { /**
* Returns true if the specified packet must be blocked based on the active or default
* privacy list rules. The active list will be tried first. If none was found then the
* default list is going to be used. If no default list was defined for this user then
* allow the packet to flow.
*
* @param packet the packet to analyze if it must be blocked.
* @return true if the specified packet must be blocked.
*/
public boolean shouldBlockPacket(Packet packet) {
if (activeList != null) { if (activeList != null) {
// If a privacy list is active then make sure that the packet is not blocked // If a privacy list is active then make sure that the packet is not blocked
if (activeList.shouldBlockPacket(packet)) { return activeList.shouldBlockPacket(packet);
// Communication is blocked. Drop packet.
return;
}
} }
else if (defaultList != null) { else if (defaultList != null) {
// There is no active list so check if there exists a default list and make // There is no active list so check if there exists a default list and make
// sure that the packet is not blocked // sure that the packet is not blocked
if (defaultList.shouldBlockPacket(packet)) { return defaultList.shouldBlockPacket(packet);
}
return false;
}
public void process(Packet packet) {
if (shouldBlockPacket(packet)) {
// Communication is blocked. Drop packet. // Communication is blocked. Drop packet.
return; return;
} }
}
// Deliver packet to the client // Deliver packet to the client
deliver(packet); deliver(packet);
} }
......
...@@ -12,13 +12,13 @@ ...@@ -12,13 +12,13 @@
package org.jivesoftware.wildfire; package org.jivesoftware.wildfire;
import org.dom4j.Element; import org.dom4j.Element;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.container.BasicModule; import org.jivesoftware.wildfire.container.BasicModule;
import org.jivesoftware.wildfire.handler.IQHandler; import org.jivesoftware.wildfire.handler.IQHandler;
import org.jivesoftware.wildfire.privacy.PrivacyList; import org.jivesoftware.wildfire.privacy.PrivacyList;
import org.jivesoftware.wildfire.privacy.PrivacyListManager; import org.jivesoftware.wildfire.privacy.PrivacyListManager;
import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.xmpp.packet.IQ; import org.xmpp.packet.IQ;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.PacketError; import org.xmpp.packet.PacketError;
...@@ -270,11 +270,13 @@ public class IQRouter extends BasicModule { ...@@ -270,11 +270,13 @@ public class IQRouter extends BasicModule {
// So if the target address belongs to this server then use the sessionManager // So if the target address belongs to this server then use the sessionManager
// instead of the routingTable since unavailable clients won't have a route to them // instead of the routingTable since unavailable clients won't have a route to them
if (XMPPServer.getInstance().isLocal(recipientJID)) { if (XMPPServer.getInstance().isLocal(recipientJID)) {
Session session = sessionManager.getBestRoute(recipientJID); ClientSession session = sessionManager.getBestRoute(recipientJID);
if (session != null) { if (session != null) {
if (!session.shouldBlockPacket(packet)) {
session.process(packet); session.process(packet);
handlerFound = true; handlerFound = true;
} }
}
else { else {
Log.info("Packet sent to unreachable address " + packet); Log.info("Packet sent to unreachable address " + packet);
} }
......
...@@ -11,9 +11,15 @@ ...@@ -11,9 +11,15 @@
package org.jivesoftware.wildfire; package org.jivesoftware.wildfire;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.audit.AuditStreamIDFactory; import org.jivesoftware.wildfire.audit.AuditStreamIDFactory;
import org.jivesoftware.wildfire.auth.UnauthorizedException; import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.component.ComponentSession;
import org.jivesoftware.wildfire.component.InternalComponentManager;
import org.jivesoftware.wildfire.container.BasicModule; import org.jivesoftware.wildfire.container.BasicModule;
import org.jivesoftware.wildfire.event.SessionEventDispatcher;
import org.jivesoftware.wildfire.handler.PresenceUpdateHandler; import org.jivesoftware.wildfire.handler.PresenceUpdateHandler;
import org.jivesoftware.wildfire.server.IncomingServerSession; import org.jivesoftware.wildfire.server.IncomingServerSession;
import org.jivesoftware.wildfire.server.OutgoingServerSession; import org.jivesoftware.wildfire.server.OutgoingServerSession;
...@@ -21,12 +27,6 @@ import org.jivesoftware.wildfire.server.OutgoingSessionPromise; ...@@ -21,12 +27,6 @@ import org.jivesoftware.wildfire.server.OutgoingSessionPromise;
import org.jivesoftware.wildfire.spi.BasicStreamIDFactory; import org.jivesoftware.wildfire.spi.BasicStreamIDFactory;
import org.jivesoftware.wildfire.user.UserManager; import org.jivesoftware.wildfire.user.UserManager;
import org.jivesoftware.wildfire.user.UserNotFoundException; import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.jivesoftware.wildfire.component.ComponentSession;
import org.jivesoftware.wildfire.component.InternalComponentManager;
import org.jivesoftware.wildfire.event.SessionEventDispatcher;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.LocaleUtils;
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.Packet; import org.xmpp.packet.Packet;
...@@ -711,7 +711,7 @@ public class SessionManager extends BasicModule { ...@@ -711,7 +711,7 @@ public class SessionManager extends BasicModule {
* @param recipient The recipient ID to deliver packets to * @param recipient The recipient ID to deliver packets to
* @return The XMPPAddress best suited to use for delivery to the recipient * @return The XMPPAddress best suited to use for delivery to the recipient
*/ */
public Session getBestRoute(JID recipient) { public ClientSession getBestRoute(JID recipient) {
// Return null if the JID belongs to a foreign server // Return null if the JID belongs to a foreign server
if (serverName == null || !serverName.equals(recipient.getDomain())) { if (serverName == null || !serverName.equals(recipient.getDomain())) {
return null; return null;
......
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