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