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 {
updateHandler.process(packet);
}
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
ChannelHandler route = routingTable.getRoute(recipientJID);
if (route != null) {
Session session = sessionManager.getSession(packet.getFrom());
if (session != null && session.getStatus() == Session.STATUS_CLOSED) {
Log.warn("Rejected available presence: " + packet + " - " + session);
return;
}
// Broadcast it to all connected resources
for (ChannelHandler route : routingTable.getRoutes(recipientJID)) {
// Register the sent directed presence
updateHandler.directedPresenceSent(packet, route, recipientJID.toString());
// Route the packet
......
......@@ -13,7 +13,7 @@ package org.jivesoftware.wildfire;
import org.xmpp.packet.JID;
import java.util.Iterator;
import java.util.List;
/**
* <p>Maintains server-wide knowledge of routes to any node.</p>
......@@ -102,7 +102,7 @@ public interface RoutingTable {
* @param node The address we want a route to
* @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>
......
......@@ -27,6 +27,7 @@ import org.xmpp.packet.PacketError;
import org.xmpp.packet.Presence;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
/**
......@@ -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
// 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.
ChannelHandler handler = routingTable.getRoute(recipientJID);
if (handler != null) {
Presence presenteToSend = presence.createCopy();
// Stamp the presence with the user's bare JID as the 'from' address
presenteToSend.setFrom(senderJID.toBareJID());
handler.process(presenteToSend);
List<ChannelHandler> handlers = routingTable.getRoutes(recipientJID);
if (!handlers.isEmpty()) {
for (ChannelHandler handler : handlers) {
Presence presenteToSend = presence.createCopy();
// Stamp the presence with the user's bare JID as the 'from' address
presenteToSend.setFrom(senderJID.toBareJID());
handler.process(presenteToSend);
}
}
else {
deliverer.deliver(presence.createCopy());
......
......@@ -538,15 +538,13 @@ public class Roster implements Cacheable {
for (RosterItem item : rosterItems.values()) {
if (item.getSubStatus() == RosterItem.SUB_BOTH
|| 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());
if (list != null && list.shouldBlockPacket(packet)) {
// Outgoing presence notifications are blocked for this contact
continue;
}
while (sessions.hasNext()) {
ChannelHandler session = (ChannelHandler)sessions.next();
JID searchNode = new JID(item.getJid().getNode(), item.getJid().getDomain(), null);
for (ChannelHandler session : routingTable.getRoutes(searchNode)) {
try {
session.process(packet);
}
......
......@@ -130,13 +130,15 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable {
return route;
}
public Iterator getRoutes(JID node) {
public List<ChannelHandler> getRoutes(JID node) {
// Check if the address belongs to a remote server
if (!serverName.equals(node.getDomain()) && routes.get(node.getDomain()) == null &&
componentManager.getComponent(node) == null) {
// Return a promise of a remote session. This object will queue packets pending
// 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;
......@@ -172,10 +174,10 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable {
}
}
if (list == null) {
return Collections.EMPTY_LIST.iterator();
return Collections.emptyList();
}
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