Commit ca435745 authored by Dave Cridland's avatar Dave Cridland Committed by Guus der Kinderen

OF-1427 Respond to PEP node disco#info

parent 38842fd5
...@@ -422,7 +422,7 @@ public class IQDiscoInfoHandler extends IQHandler implements ClusterEventListene ...@@ -422,7 +422,7 @@ public class IQDiscoInfoHandler extends IQHandler implements ClusterEventListene
// Redirect the request to the disco info provider of the specified node // Redirect the request to the disco info provider of the specified node
return serverNodeProviders.get(node).getIdentities(name, node, senderJID); return serverNodeProviders.get(node).getIdentities(name, node, senderJID);
} }
if (name != null && name.equals(XMPPServer.getInstance().getServerInfo().getXMPPDomain())) { if (name == null || name.equals(XMPPServer.getInstance().getServerInfo().getXMPPDomain())) {
// Answer identity of the server // Answer identity of the server
synchronized (identities) { synchronized (identities) {
if (identities.isEmpty()) { if (identities.isEmpty()) {
...@@ -442,6 +442,9 @@ public class IQDiscoInfoHandler extends IQHandler implements ClusterEventListene ...@@ -442,6 +442,9 @@ public class IQDiscoInfoHandler extends IQHandler implements ClusterEventListene
} }
return identities.iterator(); return identities.iterator();
} }
else if (node != null) {
return XMPPServer.getInstance().getIQPEPHandler().getIdentities(name, node, senderJID);
}
else { else {
if (SessionManager.getInstance().isAnonymousRoute(name)) { if (SessionManager.getInstance().isAnonymousRoute(name)) {
// Answer identity of an anonymous user. // Answer identity of an anonymous user.
...@@ -461,6 +464,9 @@ public class IQDiscoInfoHandler extends IQHandler implements ClusterEventListene ...@@ -461,6 +464,9 @@ public class IQDiscoInfoHandler extends IQHandler implements ClusterEventListene
// Redirect the request to the disco info provider of the specified node // Redirect the request to the disco info provider of the specified node
return serverNodeProviders.get(node).getFeatures(name, node, senderJID); return serverNodeProviders.get(node).getFeatures(name, node, senderJID);
} }
if (node != null && name != null) {
return XMPPServer.getInstance().getIQPEPHandler().getFeatures(name, node, senderJID);
}
// Answer features of the server // Answer features of the server
return new HashSet<>(serverFeatures.keySet()).iterator(); return new HashSet<>(serverFeatures.keySet()).iterator();
} }
...@@ -472,14 +478,24 @@ public class IQDiscoInfoHandler extends IQHandler implements ClusterEventListene ...@@ -472,14 +478,24 @@ public class IQDiscoInfoHandler extends IQHandler implements ClusterEventListene
// Redirect the request to the disco info provider of the specified node // Redirect the request to the disco info provider of the specified node
return serverNodeProviders.get(node).hasInfo(name, node, senderJID); return serverNodeProviders.get(node).hasInfo(name, node, senderJID);
} }
if (name != null) {
return XMPPServer.getInstance().getIQPEPHandler().hasInfo(name, node, senderJID);
}
// Unknown node // Unknown node
return false; return false;
} }
try { try {
// True if it is an info request of the server, a registered user or an // True if it is an info request of the server, a registered user or an
// anonymous user. We now support disco of user's bare JIDs // anonymous user. We now support disco of user's bare JIDs
return name == null || UserManager.getInstance().getUser(name) != null || if (name == null) return true;
SessionManager.getInstance().isAnonymousRoute(name); if (UserManager.getInstance().getUser(name) != null ||
SessionManager.getInstance().isAnonymousRoute(name)) {
if (node == null) {
return true;
}
return XMPPServer.getInstance().getIQPEPHandler().hasInfo(name, node, senderJID);
}
return false;
} }
catch (UserNotFoundException e) { catch (UserNotFoundException e) {
return false; return false;
...@@ -492,8 +508,11 @@ public class IQDiscoInfoHandler extends IQHandler implements ClusterEventListene ...@@ -492,8 +508,11 @@ public class IQDiscoInfoHandler extends IQHandler implements ClusterEventListene
// Redirect the request to the disco info provider of the specified node // Redirect the request to the disco info provider of the specified node
return serverNodeProviders.get(node).getExtendedInfo(name, node, senderJID); return serverNodeProviders.get(node).getExtendedInfo(name, node, senderJID);
} }
if (node != null && name != null) {
return XMPPServer.getInstance().getIQPEPHandler().getExtendedInfo(name, node, senderJID);
}
return null; return null;
} }
}; };
} }
} }
\ No newline at end of file
...@@ -16,10 +16,7 @@ ...@@ -16,10 +16,7 @@
package org.jivesoftware.openfire.pep; package org.jivesoftware.openfire.pep;
import java.util.ArrayList; import java.util.*;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -30,18 +27,11 @@ import org.dom4j.QName; ...@@ -30,18 +27,11 @@ import org.dom4j.QName;
import org.jivesoftware.openfire.IQHandlerInfo; import org.jivesoftware.openfire.IQHandlerInfo;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.disco.ServerFeaturesProvider; import org.jivesoftware.openfire.disco.*;
import org.jivesoftware.openfire.disco.ServerIdentitiesProvider;
import org.jivesoftware.openfire.disco.UserIdentitiesProvider;
import org.jivesoftware.openfire.disco.UserItemsProvider;
import org.jivesoftware.openfire.event.UserEventDispatcher; import org.jivesoftware.openfire.event.UserEventDispatcher;
import org.jivesoftware.openfire.event.UserEventListener; import org.jivesoftware.openfire.event.UserEventListener;
import org.jivesoftware.openfire.handler.IQHandler; import org.jivesoftware.openfire.handler.IQHandler;
import org.jivesoftware.openfire.pubsub.CollectionNode; import org.jivesoftware.openfire.pubsub.*;
import org.jivesoftware.openfire.pubsub.LeafNode;
import org.jivesoftware.openfire.pubsub.Node;
import org.jivesoftware.openfire.pubsub.NodeSubscription;
import org.jivesoftware.openfire.pubsub.PubSubEngine;
import org.jivesoftware.openfire.pubsub.models.AccessModel; import org.jivesoftware.openfire.pubsub.models.AccessModel;
import org.jivesoftware.openfire.roster.Roster; import org.jivesoftware.openfire.roster.Roster;
import org.jivesoftware.openfire.roster.RosterEventDispatcher; import org.jivesoftware.openfire.roster.RosterEventDispatcher;
...@@ -93,7 +83,7 @@ import org.xmpp.packet.Presence; ...@@ -93,7 +83,7 @@ import org.xmpp.packet.Presence;
*/ */
public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ServerFeaturesProvider, public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ServerFeaturesProvider,
UserIdentitiesProvider, UserItemsProvider, PresenceEventListener, UserIdentitiesProvider, UserItemsProvider, PresenceEventListener,
RosterEventListener, UserEventListener { RosterEventListener, UserEventListener, DiscoInfoProvider {
private static final Logger Log = LoggerFactory.getLogger(IQPEPHandler.class); private static final Logger Log = LoggerFactory.getLogger(IQPEPHandler.class);
...@@ -655,6 +645,76 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -655,6 +645,76 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
// Do nothing // Do nothing
} }
// DiscoInfoProvider
/*
* With all these, there are basically two axes of binary choice.
* Either the PEPService exists already - in which case we can defer to it,
* or else it doesn't, in which case we should use the generic engine.
*
* In either case, we might be being asked for a node, or the root. If we're
* asked for a node when the PEPService doesn't exist that's an error. Otherwise
* if we're asked for the root we can safely defer to the generic engine.
*/
@Override
public Iterator<Element> getIdentities(String name, String node, JID senderJID) {
String recipientJID = XMPPServer.getInstance().createJID(name, null, true).toBareJID();
PEPService pepService = pepServiceManager.getPEPService(recipientJID);
if (node != null && pepService != null) {
Node pubNode = pepService.getNode(node);
if (pubNode == null) return null;
// Answer the identity of a given node
Element identity = DocumentHelper.createElement("identity");
identity.addAttribute("category", "pubsub");
identity.addAttribute("type", pubNode.isCollectionNode() ? "collection" : "leaf");
List<Element> identities = new LinkedList<>();
identities.add(identity);
return identities.iterator();
} else if (node != null) {
return null;
} else {
PubSubModule pubsub = XMPPServer.getInstance().getPubSubModule();
return pubsub.getIdentities(null, null, senderJID);
}
}
@Override
public Iterator<String> getFeatures(String name, String node, JID senderJID) {
if (node == null) {
PubSubModule pubsub = XMPPServer.getInstance().getPubSubModule();
return pubsub.getFeatures(null, null, senderJID);
} else {
List<String> features = new LinkedList<>();
features.add("http://jabber.org/protocol/pubsub");
return features.iterator();
}
}
@Override
public DataForm getExtendedInfo(String name, String node, JID senderJID) {
String recipientJID = XMPPServer.getInstance().createJID(name, null, true).toBareJID();
PEPService pepService = pepServiceManager.getPEPService(recipientJID);
if (node != null) {
// Answer the extended info of a given node
Node pubNode = pepService.getNode(node);
// Get the metadata data form
return pubNode.getMetadataForm();
}
return null;
}
@Override
public boolean hasInfo(String name, String node, JID senderJID) {
if (node == null) return true;
String recipientJID = XMPPServer.getInstance().createJID(name, null, true).toBareJID();
PEPService pepService = pepServiceManager.getPEPService(recipientJID);
return pepService.getNode(node) != null;
}
private class GetNotificationsOnInitialPresence implements Runnable { private class GetNotificationsOnInitialPresence implements Runnable {
private final JID availableSessionJID; private final JID availableSessionJID;
......
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