Commit 15222622 authored by Dave Cridland's avatar Dave Cridland

Merge pull request #533 from Jongla/pubsub-item-handler

Allows dynamic setting of disco info handler and disco items handler …
parents a22d917b 98f27c92
...@@ -41,6 +41,8 @@ import org.jivesoftware.openfire.disco.DiscoInfoProvider; ...@@ -41,6 +41,8 @@ import org.jivesoftware.openfire.disco.DiscoInfoProvider;
import org.jivesoftware.openfire.disco.DiscoItem; import org.jivesoftware.openfire.disco.DiscoItem;
import org.jivesoftware.openfire.disco.DiscoItemsProvider; import org.jivesoftware.openfire.disco.DiscoItemsProvider;
import org.jivesoftware.openfire.disco.DiscoServerItem; import org.jivesoftware.openfire.disco.DiscoServerItem;
import org.jivesoftware.openfire.disco.IQDiscoInfoHandler;
import org.jivesoftware.openfire.disco.IQDiscoItemsHandler;
import org.jivesoftware.openfire.disco.ServerItemsProvider; import org.jivesoftware.openfire.disco.ServerItemsProvider;
import org.jivesoftware.openfire.pubsub.models.AccessModel; import org.jivesoftware.openfire.pubsub.models.AccessModel;
import org.jivesoftware.openfire.pubsub.models.PublisherModel; import org.jivesoftware.openfire.pubsub.models.PublisherModel;
...@@ -133,6 +135,15 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di ...@@ -133,6 +135,15 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di
private RoutingTable routingTable = null; private RoutingTable routingTable = null;
/**
* The disco info handler for this module
*/
private IQDiscoInfoHandler iqDiscoInfoHandler = null;
/**
* The disco items handler for this module
*/
private IQDiscoItemsHandler iqDiscoItemsHandler = null;
/** /**
* Default configuration to use for newly created leaf nodes. * Default configuration to use for newly created leaf nodes.
*/ */
...@@ -187,6 +198,10 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di ...@@ -187,6 +198,10 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di
} }
} }
private void sendServiceUnavailablePacket(IQ iq) {
engine.sendErrorPacket(iq, PacketError.Condition.service_unavailable, null);
}
private void process(IQ iq) { private void process(IQ iq) {
// Ignore IQs of type ERROR // Ignore IQs of type ERROR
if (IQ.Type.error == iq.getType()) { if (IQ.Type.error == iq.getType()) {
...@@ -199,20 +214,27 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di ...@@ -199,20 +214,27 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di
namespace = childElement.getNamespaceURI(); namespace = childElement.getNamespaceURI();
} }
if ("http://jabber.org/protocol/disco#info".equals(namespace)) { if ("http://jabber.org/protocol/disco#info".equals(namespace)) {
// TODO PubSub should have an IQDiscoInfoHandler of its own when PubSub becomes if (iqDiscoInfoHandler != null) {
// a component IQ reply = iqDiscoInfoHandler.handleIQ(iq);
IQ reply = XMPPServer.getInstance().getIQDiscoInfoHandler().handleIQ(iq); router.route(reply);
router.route(reply); } else {
sendServiceUnavailablePacket(iq);
return;
}
} }
else if ("http://jabber.org/protocol/disco#items".equals(namespace)) { else if ("http://jabber.org/protocol/disco#items".equals(namespace)) {
// TODO PubSub should have an IQDiscoItemsHandler of its own when PubSub becomes if (iqDiscoItemsHandler != null) {
// a component IQ reply = iqDiscoItemsHandler.handleIQ(iq);
IQ reply = XMPPServer.getInstance().getIQDiscoItemsHandler().handleIQ(iq); router.route(reply);
router.route(reply); } else {
sendServiceUnavailablePacket(iq);
return;
}
} }
else { else {
// Unknown namespace requested so return error to sender // Unknown namespace requested so return error to sender
engine.sendErrorPacket(iq, PacketError.Condition.service_unavailable, null); sendServiceUnavailablePacket(iq);
} }
} }
...@@ -358,6 +380,8 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di ...@@ -358,6 +380,8 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di
// Listen to property events so that the template is always up to date // Listen to property events so that the template is always up to date
PropertyEventDispatcher.addListener(this); PropertyEventDispatcher.addListener(this);
setIQDiscoItemsHandler(XMPPServer.getInstance().getIQDiscoItemsHandler());
setIQDiscoInfoHandler(XMPPServer.getInstance().getIQDiscoInfoHandler());
serviceEnabled = JiveGlobals.getBooleanProperty("xmpp.pubsub.enabled", true); serviceEnabled = JiveGlobals.getBooleanProperty("xmpp.pubsub.enabled", true);
serviceName = JiveGlobals.getProperty("xmpp.pubsub.service"); serviceName = JiveGlobals.getProperty("xmpp.pubsub.service");
if (serviceName == null) { if (serviceName == null) {
...@@ -480,15 +504,24 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di ...@@ -480,15 +504,24 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di
engine.shutdown(this); engine.shutdown(this);
} }
public void setIQDiscoItemsHandler(IQDiscoItemsHandler iqDiscoItemsHandler) {
this.iqDiscoItemsHandler = iqDiscoItemsHandler;
}
public void setIQDiscoInfoHandler(IQDiscoInfoHandler iqDiscoInfoHandler) {
this.iqDiscoInfoHandler = iqDiscoInfoHandler ;
}
private void enableService(boolean enabled) { private void enableService(boolean enabled) {
if (serviceEnabled == enabled) { if (serviceEnabled == enabled) {
// Do nothing if the service status has not changed // Do nothing if the service status has not changed
return; return;
} }
XMPPServer server = XMPPServer.getInstance();
if (!enabled) { if (!enabled) {
// Disable disco information // Disable disco information
server.getIQDiscoItemsHandler().removeServerItemsProvider(this); if (iqDiscoItemsHandler != null) {
iqDiscoItemsHandler.removeServerItemsProvider(this);
}
// Stop the service/module // Stop the service/module
stop(); stop();
} }
...@@ -497,7 +530,9 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di ...@@ -497,7 +530,9 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di
// Start the service/module // Start the service/module
start(); start();
// Enable disco information // Enable disco information
server.getIQDiscoItemsHandler().addServerItemsProvider(this); if (iqDiscoItemsHandler != null) {
iqDiscoItemsHandler.addServerItemsProvider(this);
}
} }
} }
......
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