Commit eecda910 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

The from attribute of presence probes should be a full JID. JM-174


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1050 b35dd754-fafc-0310-a699-88a17e54d16e
parent 331fe660
...@@ -126,14 +126,6 @@ public interface PresenceManager { ...@@ -126,14 +126,6 @@ public interface PresenceManager {
*/ */
public void setOffline(JID jid); public void setOffline(JID jid);
/**
* Probes the presence of the given XMPPAddress and attempts to send it to the given user.
*
* @param prober The user requesting the probe
* @param probee The XMPPAddress whos presence we would like sent have have probed
*/
public void probePresence(String prober, JID probee);
/** /**
* Probes the presence of the given XMPPAddress and attempts to send it to the given user. * Probes the presence of the given XMPPAddress and attempts to send it to the given user.
* *
......
...@@ -183,7 +183,7 @@ public class PresenceUpdateHandler extends BasicModule implements ChannelHandler ...@@ -183,7 +183,7 @@ public class PresenceUpdateHandler extends BasicModule implements ChannelHandler
} }
if (item.getSubStatus() == RosterItem.SUB_TO if (item.getSubStatus() == RosterItem.SUB_TO
|| item.getSubStatus() == RosterItem.SUB_BOTH) { || item.getSubStatus() == RosterItem.SUB_BOTH) {
presenceManager.probePresence(username, item.getJid()); presenceManager.probePresence(session.getAddress(), item.getJid());
} }
} }
// deliver offline messages if any // deliver offline messages if any
......
...@@ -308,7 +308,7 @@ public class Roster implements Cacheable { ...@@ -308,7 +308,7 @@ public class Roster implements Cacheable {
broadcast(item); broadcast(item);
} }
if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_TO) { if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_TO) {
presenceManager.probePresence(username, item.getJid()); probePresence(item.getJid());
} }
} }
...@@ -496,6 +496,15 @@ public class Roster implements Cacheable { ...@@ -496,6 +496,15 @@ public class Roster implements Cacheable {
broadcast(roster); broadcast(roster);
} }
/**
* Sends a presence probe to the probee for each connected resource of this user.
*/
private void probePresence(JID probee) {
for (ClientSession session : sessionManager.getSessions(username)) {
presenceManager.probePresence(session.getAddress(), probee);
}
}
public int getCachedSize() { public int getCachedSize() {
// Approximate the size of the object in bytes by calculating the size // Approximate the size of the object in bytes by calculating the size
// of each field. // of each field.
...@@ -589,7 +598,7 @@ public class Roster implements Cacheable { ...@@ -589,7 +598,7 @@ public class Roster implements Cacheable {
broadcast(item); broadcast(item);
// Probe the presence of the new group user // Probe the presence of the new group user
if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_TO) { if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_TO) {
presenceManager.probePresence(username, item.getJid()); probePresence(item.getJid());
} }
} }
...@@ -680,7 +689,7 @@ public class Roster implements Cacheable { ...@@ -680,7 +689,7 @@ public class Roster implements Cacheable {
broadcast(item); broadcast(item);
// Probe the presence of the new group user // Probe the presence of the new group user
if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_TO) { if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_TO) {
presenceManager.probePresence(username, item.getJid()); probePresence(item.getJid());
} }
} }
......
...@@ -16,8 +16,6 @@ import org.jivesoftware.messenger.container.BasicModule; ...@@ -16,8 +16,6 @@ import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.messenger.user.User; import org.jivesoftware.messenger.user.User;
import org.jivesoftware.messenger.user.UserManager; import org.jivesoftware.messenger.user.UserManager;
import org.jivesoftware.messenger.user.UserNotFoundException; import org.jivesoftware.messenger.user.UserNotFoundException;
import org.jivesoftware.util.Cache;
import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
...@@ -37,11 +35,6 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -37,11 +35,6 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
private Map<String, Presence> onlineGuests; private Map<String, Presence> onlineGuests;
private Map<String, Presence> onlineUsers; private Map<String, Presence> onlineUsers;
/**
* table: key jid.getUserJid().toLowerCase() (String); value Presence
*/
private Cache foreignUserCache;
private UserManager userManager; private UserManager userManager;
private SessionManager sessionManager; private SessionManager sessionManager;
private XMPPServer server; private XMPPServer server;
...@@ -57,13 +50,9 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -57,13 +50,9 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
} }
private void initializeCaches() { private void initializeCaches() {
int foreignCacheSize = 128 * 1024 * 8; // 1 MB
// create caches - no size limit and never expire for presence caches // create caches - no size limit and never expire for presence caches
long HOUR = JiveConstants.HOUR;
onlineGuests = new ConcurrentHashMap<String, Presence>(); onlineGuests = new ConcurrentHashMap<String, Presence>();
onlineUsers = new ConcurrentHashMap<String, Presence>(); onlineUsers = new ConcurrentHashMap<String, Presence>();
foreignUserCache = new Cache("Foreign Users", foreignCacheSize, HOUR);
} }
public int getOnlineGuestCount() { public int getOnlineGuestCount() {
...@@ -283,18 +272,21 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -283,18 +272,21 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
return null; return null;
} }
public void probePresence(String prober, JID probee) { public void probePresence(JID prober, JID probee) {
try { try {
Component component = getPresenceComponent(probee); Component component = getPresenceComponent(probee);
if (server.isLocal(probee)) { if (server.isLocal(probee)) {
// If the probee is a local user then don't send a probe to the contact's server.
// But instead just send the contact's presence to the prober
if (probee.getNode() != null && !"".equals(probee.getNode())) { if (probee.getNode() != null && !"".equals(probee.getNode())) {
Collection<ClientSession> sessions = Collection<ClientSession> sessions =
sessionManager.getSessions(probee.getNode()); sessionManager.getSessions(probee.getNode());
for (ClientSession session : sessions) { for (ClientSession session : sessions) {
Presence presencePacket = session.getPresence().createCopy(); Presence presencePacket = session.getPresence().createCopy();
presencePacket.setFrom(session.getAddress()); presencePacket.setFrom(session.getAddress());
presencePacket.setTo(prober);
try { try {
sessionManager.userBroadcast(prober, presencePacket); deliverer.deliver(presencePacket);
} }
catch (Exception e) { catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e); Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
...@@ -303,63 +295,25 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -303,63 +295,25 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
} }
} }
else if (component != null) { else if (component != null) {
// If the probee belongs to a component then ask the component to process the
// probe presence
Presence presence = new Presence(); Presence presence = new Presence();
presence.setType(Presence.Type.probe); presence.setType(Presence.Type.probe);
presence.setFrom(server.createJID(prober, "")); presence.setFrom(prober);
presence.setTo(probee); presence.setTo(probee);
component.processPacket(presence); component.processPacket(presence);
} }
else { else {
Presence presence = (Presence) foreignUserCache.get(probee.toBareJID()); String serverDomain = server.getServerInfo().getName();
if (presence != null) { // Check if the probee may be hosted by this server
Presence presencePacket = presence.createCopy(); if (!probee.getDomain().contains(serverDomain)) {
presencePacket.setFrom(probee); // TODO Implete when s2s is implemented
try {
sessionManager.userBroadcast(prober, presencePacket);
}
catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
} }
else { else {
JID proberAddress = server.createJID(prober, ""); // The probee may be related to a component that has not yet been connected so
componentManager.addPresenceRequest(proberAddress, probee); // we will keep a registry of this presence probe. The component will answer
} // this presence probe when he becomes online
} componentManager.addPresenceRequest(prober, probee);
}
catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
public void probePresence(JID prober, JID probee) {
try {
if (server.isLocal(probee)) {
Collection<ClientSession> sessions =
sessionManager.getSessions(probee.getNode());
for (ClientSession session : sessions) {
Presence presencePacket = session.getPresence().createCopy();
presencePacket.setFrom(session.getAddress());
try {
deliverer.deliver(presencePacket);
}
catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
}
else {
Presence presence =
(Presence) foreignUserCache.get(probee.toBareJID());
if (presence != null) {
Presence presencePacket = presence.createCopy();
presencePacket.setFrom(probee);
try {
deliverer.deliver(presencePacket);
}
catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
} }
} }
} }
......
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