Commit 12b4559b authored by Dave Cridland's avatar Dave Cridland Committed by GitHub

Merge pull request #669 from surevine/muc-ext

OF-1213 Add extension points to MUC
parents b89a1357 f22c928f
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
package org.jivesoftware.openfire.muc; package org.jivesoftware.openfire.muc;
import org.jivesoftware.openfire.handler.IQHandler;
import org.xmpp.component.Component; import org.xmpp.component.Component;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
...@@ -398,4 +399,37 @@ public interface MultiUserChatService extends Component { ...@@ -398,4 +399,37 @@ public interface MultiUserChatService extends Component {
* @return true if the MUC service is hidden and externally managed. * @return true if the MUC service is hidden and externally managed.
*/ */
boolean isHidden(); boolean isHidden();
/**
* Add a IQHandler to MUC rooms and services. If the IQHandler only supports one or
* other, it should quietly ignore it.
*/
void addIQHandler(IQHandler handler);
void removeIQHandler(IQHandler handler);
/**
* Adds an extra Disco feature to the list of features returned for the conference service.
* @param feature Feature to add.
*/
void addExtraFeature(String feature);
/**
* Removes an extra Disco feature from the list of features returned for the conference service.
* @param feature Feature to remove.
*/
void removeExtraFeature(String feature);
/**
* Adds an extra Disco identity to the list of identities returned for the conference service.
* @param category Category for identity. e.g. conference
* @param name Descriptive name for identity. e.g. Public Chatrooms
* @param type Type for identity. e.g. text
*/
void addExtraIdentity(String category, String name, String type);
/**
* Removes an extra Disco identity from the list of identities returned for the conference service.
* @param name Name of identity to remove.
*/
void removeExtraIdentity(String name);
} }
\ No newline at end of file
...@@ -20,17 +20,7 @@ ...@@ -20,17 +20,7 @@
package org.jivesoftware.openfire.muc.spi; package org.jivesoftware.openfire.muc.spi;
import java.util.ArrayList; import java.util.*;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
...@@ -45,6 +35,7 @@ import org.jivesoftware.openfire.PacketRouter; ...@@ -45,6 +35,7 @@ import org.jivesoftware.openfire.PacketRouter;
import org.jivesoftware.openfire.RoutingTable; import org.jivesoftware.openfire.RoutingTable;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.XMPPServerListener; import org.jivesoftware.openfire.XMPPServerListener;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.cluster.ClusterManager; import org.jivesoftware.openfire.cluster.ClusterManager;
import org.jivesoftware.openfire.disco.DiscoInfoProvider; import org.jivesoftware.openfire.disco.DiscoInfoProvider;
import org.jivesoftware.openfire.disco.DiscoItem; import org.jivesoftware.openfire.disco.DiscoItem;
...@@ -55,6 +46,7 @@ import org.jivesoftware.openfire.event.GroupEventDispatcher; ...@@ -55,6 +46,7 @@ import org.jivesoftware.openfire.event.GroupEventDispatcher;
import org.jivesoftware.openfire.group.ConcurrentGroupList; import org.jivesoftware.openfire.group.ConcurrentGroupList;
import org.jivesoftware.openfire.group.GroupAwareList; import org.jivesoftware.openfire.group.GroupAwareList;
import org.jivesoftware.openfire.group.GroupJID; import org.jivesoftware.openfire.group.GroupJID;
import org.jivesoftware.openfire.handler.IQHandler;
import org.jivesoftware.openfire.muc.HistoryStrategy; import org.jivesoftware.openfire.muc.HistoryStrategy;
import org.jivesoftware.openfire.muc.MUCEventDelegate; import org.jivesoftware.openfire.muc.MUCEventDelegate;
import org.jivesoftware.openfire.muc.MUCEventDispatcher; import org.jivesoftware.openfire.muc.MUCEventDispatcher;
...@@ -168,6 +160,11 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService ...@@ -168,6 +160,11 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
*/ */
private IQMUCSearchHandler searchHandler = null; private IQMUCSearchHandler searchHandler = null;
/**
* Plugin (etc) provided IQ Handlers for MUC:
*/
private Map<String,IQHandler> iqHandlers = null;
/** /**
* The total time all agents took to chat * * The total time all agents took to chat *
*/ */
...@@ -293,6 +290,23 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService ...@@ -293,6 +290,23 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
historyStrategy = new HistoryStrategy(null); historyStrategy = new HistoryStrategy(null);
} }
@Override
public void addIQHandler(IQHandler iqHandler) {
if (this.iqHandlers == null) {
this.iqHandlers = new HashMap<>();
}
this.iqHandlers.put(iqHandler.getInfo().getNamespace(), iqHandler);
}
@Override
public void removeIQHandler(IQHandler iqHandler) {
if (this.iqHandlers != null) {
if (iqHandler == this.iqHandlers.get(iqHandler.getInfo().getNamespace())) {
this.iqHandlers.remove(iqHandler.getInfo().getNamespace());
}
}
}
@Override @Override
public String getDescription() { public String getDescription() {
return chatDescription; return chatDescription;
...@@ -402,6 +416,21 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService ...@@ -402,6 +416,21 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
router.route( IQ.createResultIQ(iq) ); router.route( IQ.createResultIQ(iq) );
} }
else { else {
IQHandler h = this.iqHandlers.get(namespace);
if (h != null) {
try {
IQ reply = h.handleIQ(iq);
if (reply != null) {
router.route(reply);
}
} catch (UnauthorizedException e) {
IQ reply = IQ.createResultIQ(iq);
reply.setType(IQ.Type.error);
reply.setError(PacketError.Condition.service_unavailable);
router.route(reply);
}
return true;
}
return false; return false;
} }
return true; return true;
...@@ -1528,6 +1557,9 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService ...@@ -1528,6 +1557,9 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
else { else {
features.add("muc_temporary"); features.add("muc_temporary");
} }
if (!extraDiscoFeatures.isEmpty()) {
features.addAll(extraDiscoFeatures);
}
} }
} }
return features.iterator(); return features.iterator();
......
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