Commit 9c904ce5 authored by Christian Schudt's avatar Christian Schudt

OF-874 disco#items request SHOULD return connected or available resources

parent 9c69db39
...@@ -22,6 +22,7 @@ package org.jivesoftware.openfire; ...@@ -22,6 +22,7 @@ package org.jivesoftware.openfire;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
...@@ -32,6 +33,7 @@ import java.util.Set; ...@@ -32,6 +33,7 @@ import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import org.dom4j.Element;
import org.jivesoftware.openfire.audit.AuditStreamIDFactory; import org.jivesoftware.openfire.audit.AuditStreamIDFactory;
import org.jivesoftware.openfire.auth.AuthToken; import org.jivesoftware.openfire.auth.AuthToken;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.auth.UnauthorizedException;
...@@ -39,6 +41,11 @@ import org.jivesoftware.openfire.cluster.ClusterEventListener; ...@@ -39,6 +41,11 @@ import org.jivesoftware.openfire.cluster.ClusterEventListener;
import org.jivesoftware.openfire.cluster.ClusterManager; import org.jivesoftware.openfire.cluster.ClusterManager;
import org.jivesoftware.openfire.component.InternalComponentManager; import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.container.BasicModule; import org.jivesoftware.openfire.container.BasicModule;
import org.jivesoftware.openfire.disco.DiscoInfoProvider;
import org.jivesoftware.openfire.disco.DiscoItem;
import org.jivesoftware.openfire.disco.DiscoItemsProvider;
import org.jivesoftware.openfire.disco.DiscoServerItem;
import org.jivesoftware.openfire.disco.ServerItemsProvider;
import org.jivesoftware.openfire.event.SessionEventDispatcher; import org.jivesoftware.openfire.event.SessionEventDispatcher;
import org.jivesoftware.openfire.http.HttpConnection; import org.jivesoftware.openfire.http.HttpConnection;
import org.jivesoftware.openfire.http.HttpSession; import org.jivesoftware.openfire.http.HttpSession;
...@@ -60,12 +67,15 @@ import org.jivesoftware.openfire.session.RemoteSessionLocator; ...@@ -60,12 +67,15 @@ import org.jivesoftware.openfire.session.RemoteSessionLocator;
import org.jivesoftware.openfire.session.Session; import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.openfire.spi.BasicStreamIDFactory; import org.jivesoftware.openfire.spi.BasicStreamIDFactory;
import org.jivesoftware.openfire.user.UserManager; import org.jivesoftware.openfire.user.UserManager;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.cache.Cache; import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheFactory; import org.jivesoftware.util.cache.CacheFactory;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.xmpp.forms.DataForm;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
...@@ -78,7 +88,7 @@ import org.xmpp.packet.Presence; ...@@ -78,7 +88,7 @@ import org.xmpp.packet.Presence;
* *
* @author Derek DeMoro * @author Derek DeMoro
*/ */
public class SessionManager extends BasicModule implements ClusterEventListener { public class SessionManager extends BasicModule implements ClusterEventListener, ServerItemsProvider, DiscoInfoProvider, DiscoItemsProvider {
private static final Logger Log = LoggerFactory.getLogger(SessionManager.class); private static final Logger Log = LoggerFactory.getLogger(SessionManager.class);
...@@ -1162,6 +1172,48 @@ public class SessionManager extends BasicModule implements ClusterEventListener ...@@ -1162,6 +1172,48 @@ public class SessionManager extends BasicModule implements ClusterEventListener
JiveGlobals.setProperty("xmpp.session.conflict-limit", Integer.toString(conflictLimit)); JiveGlobals.setProperty("xmpp.session.conflict-limit", Integer.toString(conflictLimit));
} }
@Override
public Iterator<DiscoServerItem> getItems() {
return Arrays.asList(new DiscoServerItem(serverAddress, null, null, null, this, this)).iterator();
}
@Override
public Iterator<Element> getIdentities(String name, String node, JID senderJID) {
return Collections.emptyIterator();
}
@Override
public Iterator<String> getFeatures(String name, String node, JID senderJID) {
return Collections.emptyIterator();
}
@Override
public DataForm getExtendedInfo(String name, String node, JID senderJID) {
return null;
}
@Override
public boolean hasInfo(String name, String node, JID senderJID) {
return false;
}
@Override
public Iterator<DiscoItem> getItems(String name, String node, JID senderJID) {
try {
// If the requesting entity is the user itself or the sender or the requesting entity can probe the presence of the user.
if (server.getUserManager().isRegisteredUser(senderJID) && name.equals(senderJID.getNode()) || server.getPresenceManager().canProbePresence(senderJID, name)) {
Collection<DiscoItem> discoItems = new ArrayList<DiscoItem>();
for (ClientSession clientSession : getSessions(name)) {
discoItems.add(new DiscoItem(clientSession.getAddress(), null, null, null));
}
return discoItems.iterator();
}
return Collections.emptyIterator();
} catch (UserNotFoundException e) {
return Collections.emptyIterator();
}
}
private class ClientSessionListener implements ConnectionCloseListener { private class ClientSessionListener implements ConnectionCloseListener {
/** /**
* Handle a session that just closed. * Handle a session that just closed.
...@@ -1320,6 +1372,7 @@ public class SessionManager extends BasicModule implements ClusterEventListener ...@@ -1320,6 +1372,7 @@ public class SessionManager extends BasicModule implements ClusterEventListener
sessionInfoCache = CacheFactory.createCache(C2S_INFO_CACHE_NAME); sessionInfoCache = CacheFactory.createCache(C2S_INFO_CACHE_NAME);
// Listen to cluster events // Listen to cluster events
ClusterManager.addListener(this); ClusterManager.addListener(this);
server.getIQDiscoItemsHandler().addServerItemsProvider(this);
} }
......
...@@ -540,7 +540,6 @@ public class XMPPServer { ...@@ -540,7 +540,6 @@ public class XMPPServer {
loadModule(PrivateStorage.class.getName()); loadModule(PrivateStorage.class.getName());
// Load core modules // Load core modules
loadModule(PresenceManagerImpl.class.getName()); loadModule(PresenceManagerImpl.class.getName());
loadModule(SessionManager.class.getName());
loadModule(PacketRouterImpl.class.getName()); loadModule(PacketRouterImpl.class.getName());
loadModule(IQRouter.class.getName()); loadModule(IQRouter.class.getName());
loadModule(MessageRouter.class.getName()); loadModule(MessageRouter.class.getName());
...@@ -580,6 +579,8 @@ public class XMPPServer { ...@@ -580,6 +579,8 @@ public class XMPPServer {
loadModule(PubSubModule.class.getName()); loadModule(PubSubModule.class.getName());
loadModule(IQDiscoInfoHandler.class.getName()); loadModule(IQDiscoInfoHandler.class.getName());
loadModule(IQDiscoItemsHandler.class.getName()); loadModule(IQDiscoItemsHandler.class.getName());
// SessionManager registers to IQDiscoItemsHandler, therefore load it after it.
loadModule(SessionManager.class.getName());
loadModule(UpdateManager.class.getName()); loadModule(UpdateManager.class.getName());
loadModule(FlashCrossDomainHandler.class.getName()); loadModule(FlashCrossDomainHandler.class.getName());
loadModule(InternalComponentManager.class.getName()); loadModule(InternalComponentManager.class.getName());
......
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