Commit 50b1036a authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Presence packets sent to bare JIDs were not being sent to all connected resources. JM-735

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4113 b35dd754-fafc-0310-a699-88a17e54d16e
parent 5dc51520
...@@ -92,14 +92,16 @@ public class PresenceRouter extends BasicModule { ...@@ -92,14 +92,16 @@ public class PresenceRouter extends BasicModule {
updateHandler.process(packet); updateHandler.process(packet);
} }
else { else {
// Check that sender session is still active
Session session = sessionManager.getSession(packet.getFrom());
if (session != null && session.getStatus() == Session.STATUS_CLOSED) {
Log.warn("Rejected available presence: " + packet + " - " + session);
return;
}
// The user sent a directed presence to an entity // The user sent a directed presence to an entity
ChannelHandler route = routingTable.getRoute(recipientJID); // Broadcast it to all connected resources
if (route != null) { for (ChannelHandler route : routingTable.getRoutes(recipientJID)) {
Session session = sessionManager.getSession(packet.getFrom());
if (session != null && session.getStatus() == Session.STATUS_CLOSED) {
Log.warn("Rejected available presence: " + packet + " - " + session);
return;
}
// Register the sent directed presence // Register the sent directed presence
updateHandler.directedPresenceSent(packet, route, recipientJID.toString()); updateHandler.directedPresenceSent(packet, route, recipientJID.toString());
// Route the packet // Route the packet
......
...@@ -13,7 +13,7 @@ package org.jivesoftware.wildfire; ...@@ -13,7 +13,7 @@ package org.jivesoftware.wildfire;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import java.util.Iterator; import java.util.List;
/** /**
* <p>Maintains server-wide knowledge of routes to any node.</p> * <p>Maintains server-wide knowledge of routes to any node.</p>
...@@ -102,7 +102,7 @@ public interface RoutingTable { ...@@ -102,7 +102,7 @@ public interface RoutingTable {
* @param node The address we want a route to * @param node The address we want a route to
* @return An iterator over all applicable routes * @return An iterator over all applicable routes
*/ */
Iterator getRoutes(JID node); List<ChannelHandler> getRoutes(JID node);
/** /**
* <p>Obtain a route to a handler at the given node falling back to a user branch if no resource leaf exists.</p> * <p>Obtain a route to a handler at the given node falling back to a user branch if no resource leaf exists.</p>
......
...@@ -27,6 +27,7 @@ import org.xmpp.packet.PacketError; ...@@ -27,6 +27,7 @@ import org.xmpp.packet.PacketError;
import org.xmpp.packet.Presence; import org.xmpp.packet.Presence;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -136,12 +137,14 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand ...@@ -136,12 +137,14 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand
// a module, the module will be able to handle the packet. If the handler is a // a module, the module will be able to handle the packet. If the handler is a
// Session the packet will be routed to the client. If a route cannot be found // Session the packet will be routed to the client. If a route cannot be found
// then the packet will be delivered based on its recipient and sender. // then the packet will be delivered based on its recipient and sender.
ChannelHandler handler = routingTable.getRoute(recipientJID); List<ChannelHandler> handlers = routingTable.getRoutes(recipientJID);
if (handler != null) { if (!handlers.isEmpty()) {
Presence presenteToSend = presence.createCopy(); for (ChannelHandler handler : handlers) {
// Stamp the presence with the user's bare JID as the 'from' address Presence presenteToSend = presence.createCopy();
presenteToSend.setFrom(senderJID.toBareJID()); // Stamp the presence with the user's bare JID as the 'from' address
handler.process(presenteToSend); presenteToSend.setFrom(senderJID.toBareJID());
handler.process(presenteToSend);
}
} }
else { else {
deliverer.deliver(presence.createCopy()); deliverer.deliver(presence.createCopy());
......
...@@ -538,15 +538,13 @@ public class Roster implements Cacheable { ...@@ -538,15 +538,13 @@ public class Roster implements Cacheable {
for (RosterItem item : rosterItems.values()) { for (RosterItem item : rosterItems.values()) {
if (item.getSubStatus() == RosterItem.SUB_BOTH if (item.getSubStatus() == RosterItem.SUB_BOTH
|| item.getSubStatus() == RosterItem.SUB_FROM) { || item.getSubStatus() == RosterItem.SUB_FROM) {
JID searchNode = new JID(item.getJid().getNode(), item.getJid().getDomain(), null);
Iterator sessions = routingTable.getRoutes(searchNode);
packet.setTo(item.getJid()); packet.setTo(item.getJid());
if (list != null && list.shouldBlockPacket(packet)) { if (list != null && list.shouldBlockPacket(packet)) {
// Outgoing presence notifications are blocked for this contact // Outgoing presence notifications are blocked for this contact
continue; continue;
} }
while (sessions.hasNext()) { JID searchNode = new JID(item.getJid().getNode(), item.getJid().getDomain(), null);
ChannelHandler session = (ChannelHandler)sessions.next(); for (ChannelHandler session : routingTable.getRoutes(searchNode)) {
try { try {
session.process(packet); session.process(packet);
} }
......
...@@ -130,13 +130,15 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable { ...@@ -130,13 +130,15 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable {
return route; return route;
} }
public Iterator getRoutes(JID node) { public List<ChannelHandler> getRoutes(JID node) {
// Check if the address belongs to a remote server // Check if the address belongs to a remote server
if (!serverName.equals(node.getDomain()) && routes.get(node.getDomain()) == null && if (!serverName.equals(node.getDomain()) && routes.get(node.getDomain()) == null &&
componentManager.getComponent(node) == null) { componentManager.getComponent(node) == null) {
// Return a promise of a remote session. This object will queue packets pending // Return a promise of a remote session. This object will queue packets pending
// to be sent to remote servers // to be sent to remote servers
return Arrays.asList(OutgoingSessionPromise.getInstance()).iterator(); List<ChannelHandler> list = new ArrayList<ChannelHandler>();
list.add(OutgoingSessionPromise.getInstance());
return list;
} }
LinkedList list = null; LinkedList list = null;
...@@ -172,10 +174,10 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable { ...@@ -172,10 +174,10 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable {
} }
} }
if (list == null) { if (list == null) {
return Collections.EMPTY_LIST.iterator(); return Collections.emptyList();
} }
else { else {
return list.iterator(); return list;
} }
} }
......
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