Commit 17fb2653 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Initial check-in of extended message stanza support (JM-501).

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3283 b35dd754-fafc-0310-a699-88a17e54d16e
parent 4e0314dd
......@@ -36,6 +36,7 @@ import java.util.concurrent.ConcurrentHashMap;
public class IQRouter extends BasicModule {
private RoutingTable routingTable;
private MulticastRouter multicastRouter;
private String serverName;
private List<IQHandler> iqHandlers = new ArrayList<IQHandler>();
private Map<String, IQHandler> namespace2Handlers = new ConcurrentHashMap<String, IQHandler>();
......@@ -144,6 +145,7 @@ public class IQRouter extends BasicModule {
super.initialize(server);
serverName = server.getServerInfo().getName();
routingTable = server.getRoutingTable();
multicastRouter = server.getMulticastRouter();
iqHandlers.addAll(server.getIQHandlers());
sessionManager = server.getSessionManager();
}
......@@ -165,11 +167,23 @@ public class IQRouter extends BasicModule {
// Check if the packet was sent to the server hostname
if (recipientJID != null && recipientJID.getNode() == null &&
recipientJID.getResource() == null && serverName.equals(recipientJID.getDomain())) {
if (IQ.Type.result == packet.getType() || IQ.Type.error == packet.getType()) {
Element childElement = packet.getChildElement();
if (childElement != null && childElement.element("addresses") != null) {
// Packet includes multicast processing instructions. Ask the multicastRouter
// to route this packet
multicastRouter.route(packet);
return;
}
else if (IQ.Type.result == packet.getType() || IQ.Type.error == packet.getType()) {
// The server got an answer to an IQ packet that was sent from the server
IQResultListener iqResultListener = resultListeners.remove(packet.getID());
if (iqResultListener != null) {
iqResultListener.receivedAnswer(packet);
try {
iqResultListener.receivedAnswer(packet);
}
catch (Exception e) {
Log.error("Error processing answer of remote entity", e);
}
return;
}
}
......@@ -323,4 +337,4 @@ public class IQRouter extends BasicModule {
}
return handler;
}
}
}
\ No newline at end of file
......@@ -35,6 +35,7 @@ public class MessageRouter extends BasicModule {
private OfflineMessageStrategy messageStrategy;
private RoutingTable routingTable;
private SessionManager sessionManager;
private MulticastRouter multicastRouter;
private String serverName;
......@@ -68,11 +69,20 @@ public class MessageRouter extends BasicModule {
{
JID recipientJID = packet.getTo();
// If the message was sent to the server hostname then forward the message to
// a configurable set of JID's (probably admin users)
if (recipientJID.getNode() == null && recipientJID.getResource() == null &&
// Check if the message was sent to the server hostname
if (recipientJID != null && recipientJID.getNode() == null &&
recipientJID.getResource() == null &&
serverName.equals(recipientJID.getDomain())) {
sendMessageToAdmins(packet);
if (packet.getElement().element("addresses") != null) {
// Message includes multicast processing instructions. Ask the multicastRouter
// to route this packet
multicastRouter.route(packet);
}
else {
// Message was sent to the server hostname so forward it to a configurable
// set of JID's (probably admin users)
sendMessageToAdmins(packet);
}
return;
}
......@@ -146,6 +156,7 @@ public class MessageRouter extends BasicModule {
messageStrategy = server.getOfflineMessageStrategy();
routingTable = server.getRoutingTable();
sessionManager = server.getSessionManager();
multicastRouter = server.getMulticastRouter();
serverName = server.getServerInfo().getName();
}
}
This diff is collapsed.
......@@ -11,15 +11,14 @@
package org.jivesoftware.wildfire;
import org.xmpp.packet.Presence;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.container.BasicModule;
import org.jivesoftware.wildfire.handler.PresenceSubscribeHandler;
import org.jivesoftware.wildfire.handler.PresenceUpdateHandler;
import org.xmpp.packet.JID;
import org.xmpp.packet.PacketError;
import org.jivesoftware.wildfire.handler.PresenceUpdateHandler;
import org.jivesoftware.wildfire.handler.PresenceSubscribeHandler;
import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.container.BasicModule;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.LocaleUtils;
import org.xmpp.packet.Presence;
/**
* <p>Route presence packets throughout the server.</p>
......@@ -37,6 +36,7 @@ public class PresenceRouter extends BasicModule {
private PresenceSubscribeHandler subscribeHandler;
private PresenceManager presenceManager;
private SessionManager sessionManager;
private MulticastRouter multicastRouter;
private String serverName;
/**
......@@ -56,7 +56,7 @@ public class PresenceRouter extends BasicModule {
if (packet == null) {
throw new NullPointerException();
}
Session session = sessionManager.getSession(packet.getFrom());
ClientSession session = sessionManager.getSession(packet.getFrom());
if (session == null || session.getStatus() == Session.STATUS_AUTHENTICATED) {
handle(packet);
}
......@@ -64,17 +64,22 @@ public class PresenceRouter extends BasicModule {
packet.setTo(session.getAddress());
packet.setFrom((JID)null);
packet.setError(PacketError.Condition.not_authorized);
try {
session.process(packet);
}
catch (UnauthorizedException ue) {
Log.error(ue);
}
session.process(packet);
}
}
private void handle(Presence packet) {
JID recipientJID = packet.getTo();
// Check if the packet was sent to the server hostname
if (recipientJID != null && recipientJID.getNode() == null &&
recipientJID.getResource() == null && serverName.equals(recipientJID.getDomain())) {
if (packet.getElement().element("addresses") != null) {
// Presence includes multicast processing instructions. Ask the multicastRouter
// to route this packet
multicastRouter.route(packet);
return;
}
}
try {
Presence.Type type = packet.getType();
// Presence updates (null is 'available')
......@@ -137,6 +142,7 @@ public class PresenceRouter extends BasicModule {
updateHandler = server.getPresenceUpdateHandler();
subscribeHandler = server.getPresenceSubscribeHandler();
presenceManager = server.getPresenceManager();
multicastRouter = server.getMulticastRouter();
sessionManager = server.getSessionManager();
}
}
......@@ -386,6 +386,7 @@ public class XMPPServer {
loadModule(IQRouter.class.getName());
loadModule(MessageRouter.class.getName());
loadModule(PresenceRouter.class.getName());
loadModule(MulticastRouter.class.getName());
loadModule(PacketTransporterImpl.class.getName());
loadModule(PacketDelivererImpl.class.getName());
loadModule(TransportHandler.class.getName());
......@@ -976,6 +977,17 @@ public class XMPPServer {
return (PresenceRouter) modules.get(PresenceRouter.class);
}
/**
* Returns the <code>MulticastRouter</code> registered with this server. The
* <code>MulticastRouter</code> was registered with the server as a module while starting up
* the server.
*
* @return the <code>MulticastRouter</code> registered with this server.
*/
public MulticastRouter getMulticastRouter() {
return (MulticastRouter) modules.get(MulticastRouter.class);
}
/**
* Returns the <code>UserManager</code> registered with this server. The
* <code>UserManager</code> was registered with the server as a module while starting up
......
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