Commit 22ac8fea authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

The MUC service is now responsible for answering all packets whose domain...

The MUC service is now responsible for answering all packets whose domain matches the MUC service domain.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@965 b35dd754-fafc-0310-a699-88a17e54d16e
parent 3219a58b
......@@ -11,14 +11,9 @@
package org.jivesoftware.messenger.muc.spi;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.QName;
import org.jivesoftware.messenger.forms.DataForm;
import org.jivesoftware.messenger.forms.FormField;
import org.jivesoftware.messenger.forms.spi.XDataFormImpl;
......@@ -27,40 +22,30 @@ import org.jivesoftware.messenger.muc.ConflictException;
import org.jivesoftware.messenger.muc.ForbiddenException;
import org.jivesoftware.messenger.muc.MUCRoom;
import org.jivesoftware.messenger.muc.MultiUserChatServer;
import org.jivesoftware.util.ElementUtil;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.ElementUtil;
import org.jivesoftware.messenger.*;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.handler.IQHandler;
import org.xmpp.packet.IQ;
import org.xmpp.packet.Presence;
import org.xmpp.packet.PacketError;
import org.xmpp.packet.Presence;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* This class is not an actual IQHandler since all the packets with namespace
* jabber:iq:register will be handled by IQRegisterHandler. So currently IQRegisterHandler is
* delegating the responsibility for managing room registation to this class. In the future, when we
* implement the component JEP we will have to review this design since this is a temporary
* solution. Most probably this class will not inherit from IQHandler but for now this is
* a workaround that allows us to avoid the need to create a new interface. Note: The abstract class
* of this class is used in IQRegisterHandler to model any possible delegate.<p>
*
* However, the idea of having this class as a delegate will still persist in the future since
* MultiUserChatServer will be the main target for the room registration packets and that class
* will delegate the responsiblity to this class.
* This class is responsible for handling packets with namespace jabber:iq:register that were
* sent to the MUC service. MultiUserChatServer will receive all the IQ packets and if the
* namespace of the IQ is jabber:iq:register then this class will handle the packet.
*
* @author Gaston Dombiak
*/
public class IQMUCRegisterHandler extends IQHandler {
class IQMUCRegisterHandler {
private static Element probeResult;
private IQHandlerInfo info;
private MultiUserChatServer mucServer;
public IQMUCRegisterHandler(MultiUserChatServer mucServer) {
super("XMPP MUC Registration Handler");
info = new IQHandlerInfo("query", "jabber:iq:register");
this.mucServer = mucServer;
initialize();
}
......@@ -118,8 +103,7 @@ public class IQMUCRegisterHandler extends IQHandler {
}
}
public IQ handleIQ(IQ packet) throws UnauthorizedException {
Session session = SessionManager.getInstance().getSession(packet.getFrom());
public IQ handleIQ(IQ packet) {
IQ reply = null;
// Get the target room
MUCRoom room = mucServer.getChatRoom(packet.getTo().getNode());
......@@ -209,15 +193,6 @@ public class IQMUCRegisterHandler extends IQHandler {
Log.error(e);
}
}
if (reply != null) {
// why is this done here instead of letting the iq handler do it?
session.getConnection().deliver(reply);
}
return null;
}
public IQHandlerInfo getInfo() {
return info;
return reply;
}
}
......@@ -31,7 +31,6 @@ import org.jivesoftware.messenger.forms.DataForm;
import org.jivesoftware.messenger.forms.FormField;
import org.jivesoftware.messenger.forms.spi.XDataFormImpl;
import org.jivesoftware.messenger.forms.spi.XFormFieldImpl;
import org.jivesoftware.messenger.handler.IQRegisterHandler;
import org.jivesoftware.messenger.muc.HistoryStrategy;
import org.jivesoftware.messenger.muc.MUCRole;
import org.jivesoftware.messenger.muc.MUCRoom;
......@@ -41,10 +40,7 @@ import org.jivesoftware.messenger.muc.NotAllowedException;
import org.jivesoftware.messenger.user.UserNotFoundException;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
import org.xmpp.packet.Presence;
import org.xmpp.packet.*;
import org.xmpp.component.ComponentManager;
/**
......@@ -118,7 +114,7 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
/**
* The handler of packets with namespace jabber:iq:register for the server.
*/
private IQRegisterHandler registerHandler = null;
private IQMUCRegisterHandler registerHandler = null;
/**
* The total time all agents took to chat *
*/
......@@ -196,7 +192,17 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
}
public void processPacket(Packet packet) {
// The MUC service will receive all the packets whose domain matches the domain of the MUC
// service. This means that, for instance, a disco request should be responded by the
// service itself instead of relying on the server to handle the request.
try {
// Check if the packet is a disco request or a packet with namespace iq:register
if (packet instanceof IQ) {
if (process((IQ)packet)) {
return;
}
}
// The packet is a normal packet that should possibly be sent to the room
MUCUser user = getChatUser(packet.getFrom());
user.process(packet);
}
......@@ -205,6 +211,51 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
}
}
/**
* Returns true if the IQ packet was processed. This method should only process disco packets
* as well as jabber:iq:register packets sent to the MUC service.
*
* @param iq the IQ packet to process.
* @return true if the IQ packet was processed.
*/
private boolean process(IQ iq) {
Element childElement = iq.getChildElement();
String namespace = null;
if (childElement != null) {
namespace = childElement.getNamespaceURI();
}
if ("jabber:iq:register".equals(namespace)) {
IQ reply = registerHandler.handleIQ(iq);
router.route(reply);
}
else if ("http://jabber.org/protocol/disco#info".equals(namespace)) {
try {
// TODO MUC should have an IQDiscoInfoHandler of its own when MUC becomes
// a component
IQ reply = XMPPServer.getInstance().getIQDiscoInfoHandler().handleIQ(iq);
router.route(reply);
}
catch (UnauthorizedException e) {
// Do nothing. This error should never happen
}
}
else if ("http://jabber.org/protocol/disco#items".equals(namespace)) {
try {
// TODO MUC should have an IQDiscoItemsHandler of its own when MUC becomes
// a component
IQ reply = XMPPServer.getInstance().getIQDiscoItemsHandler().handleIQ(iq);
router.route(reply);
}
catch (UnauthorizedException e) {
// Do nothing. This error should never happen
}
}
else {
return false;
}
return true;
}
public void initialize(JID jid, ComponentManager componentManager) {
}
......@@ -690,9 +741,8 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
routingTable = server.getRoutingTable();
router = server.getPacketRouter();
// TODO Remove the tracking for IQRegisterHandler when the component JEP gets implemented.
registerHandler = server.getIQRegisterHandler();
registerHandler.addDelegate(getServiceDomain(), new IQMUCRegisterHandler(this));
// Configure the handler of iq:register packets
registerHandler = new IQMUCRegisterHandler(this);
}
public void start() {
......@@ -716,9 +766,6 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
routingTable.removeRoute(getAddress());
timer.cancel();
logAllConversation();
if (registerHandler != null) {
registerHandler.removeDelegate(getServiceDomain());
}
}
public long getTotalChatTime() {
......
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