Commit 2c6154d1 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Improved logic to detect JIDs of remote servers. JM-355


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1722 b35dd754-fafc-0310-a699-88a17e54d16e
parent a273c81a
......@@ -85,6 +85,7 @@ public class XMPPServer {
private ClassLoader loader;
private PluginManager pluginManager;
private InternalComponentManager componentManager;
/**
* True if in setup mode
......@@ -131,8 +132,10 @@ public class XMPPServer {
/**
* Returns true if the given address is local to the server (managed by this
* server domain).
* server domain). Return false even if the jid's domain matches a local component's
* service JID.
*
* @param jid the JID to check.
* @return true if the address is a local address to this server.
*/
public boolean isLocal(JID jid) {
......@@ -143,6 +146,24 @@ public class XMPPServer {
return local;
}
/**
* Returns true if the given address does not match the local server hostname and does not
* match a component service JID.
*
* @param jid the JID to check.
* @return true if the given address does not match the local server hostname and does not
* match a component service JID.
*/
public boolean isRemote(JID jid) {
if (jid != null) {
String domain = jid.getDomain();
if (!name.equals(domain) && componentManager.getComponent(domain) == null) {
return true;
}
}
return false;
}
/**
* Creates an XMPPAddress local to this server.
*
......@@ -175,6 +196,7 @@ public class XMPPServer {
}
loader = Thread.currentThread().getContextClassLoader();
componentManager = InternalComponentManager.getInstance();
initialized = true;
}
......
......@@ -11,13 +11,13 @@
package org.jivesoftware.messenger.net;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.messenger.*;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.xmpp.packet.Packet;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
import org.xmpp.packet.Presence;
/**
......@@ -28,9 +28,9 @@ import org.xmpp.packet.Presence;
*/
public class SocketPacketWriteHandler implements ChannelHandler {
private XMPPServer server;
private SessionManager sessionManager;
private OfflineMessageStrategy messageStrategy;
private String serverName = XMPPServer.getInstance().getServerInfo().getName();
private RoutingTable routingTable;
public SocketPacketWriteHandler(SessionManager sessionManager, RoutingTable routingTable,
......@@ -38,13 +38,14 @@ public class SocketPacketWriteHandler implements ChannelHandler {
this.sessionManager = sessionManager;
this.messageStrategy = messageStrategy;
this.routingTable = routingTable;
this.server = XMPPServer.getInstance();
}
public void process(Packet packet) throws UnauthorizedException, PacketException {
try {
JID recipient = packet.getTo();
// Check if the target domain belongs to a remote server
if (recipient != null && !recipient.getDomain().contains(serverName)) {
if (server.isRemote(recipient)) {
try {
// Locate the route to the remote server and ask it to process the packet
routingTable.getRoute(recipient).process(packet);
......
......@@ -305,9 +305,10 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
component.processPacket(presence);
}
else {
String serverDomain = server.getServerInfo().getName();
// Check if the probee may be hosted by this server
if (!probee.getDomain().contains(serverDomain)) {
/*String serverDomain = server.getServerInfo().getName();
if (!probee.getDomain().contains(serverDomain)) {*/
if (server.isRemote(probee)) {
// Send the probe presence to the remote server
Presence probePresence = new Presence();
probePresence.setType(Presence.Type.probe);
......
......@@ -94,7 +94,7 @@ public class PresencePlugin implements Plugin {
public Presence getPresence(String sender, String jid) throws UserNotFoundException {
JID targetJID = new JID(jid);
// Check that the sender is not requesting information of a remote server entity
if (targetJID.getDomain() == null || !targetJID.getDomain().contains(hostname)) {
if (targetJID.getDomain() == null || XMPPServer.getInstance().isRemote(targetJID)) {
throw new UserNotFoundException("Domain does not matches local server domain");
}
if (!hostname.equals(targetJID.getDomain())) {
......
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