Commit e586132d authored by Dave Cridland's avatar Dave Cridland

Update MAM support to cover :0 and :1

parent 57e24df5
package com.reucon.openfire.plugin.archive.xep0313; package com.reucon.openfire.plugin.archive.xep0313;
import java.text.DateFormat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.TimeZone;
import org.dom4j.*; import org.dom4j.*;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.auth.UnauthorizedException;
...@@ -31,17 +28,17 @@ import com.reucon.openfire.plugin.archive.xep0059.XmppResultSet; ...@@ -31,17 +28,17 @@ import com.reucon.openfire.plugin.archive.xep0059.XmppResultSet;
/** /**
* XEP-0313 IQ Query Handler * XEP-0313 IQ Query Handler
*/ */
public class IQQueryHandler extends AbstractIQHandler implements abstract class IQQueryHandler extends AbstractIQHandler implements
ServerFeaturesProvider { ServerFeaturesProvider {
private static final Logger Log = LoggerFactory.getLogger(IQHandler.class); private static final Logger Log = LoggerFactory.getLogger(IQHandler.class);
private static final String NAMESPACE = "urn:xmpp:mam:0"; protected final String NAMESPACE;
private static final String MODULE_NAME = "Message Archive Management Query Handler";
XMPPDateTimeFormat xmppDateTimeFormat = new XMPPDateTimeFormat(); private final XMPPDateTimeFormat xmppDateTimeFormat = new XMPPDateTimeFormat();
protected IQQueryHandler() { IQQueryHandler(final String moduleName, final String namespace) {
super(MODULE_NAME, "query", NAMESPACE); super(moduleName, "query", namespace);
NAMESPACE = namespace;
} }
public IQ handleIQ(IQ packet) throws UnauthorizedException { public IQ handleIQ(IQ packet) throws UnauthorizedException {
...@@ -73,6 +70,8 @@ public class IQQueryHandler extends AbstractIQHandler implements ...@@ -73,6 +70,8 @@ public class IQQueryHandler extends AbstractIQHandler implements
} }
} }
sendMidQuery(packet, session);
final QueryRequest queryRequest = new QueryRequest(packet.getChildElement(), archiveJid); final QueryRequest queryRequest = new QueryRequest(packet.getChildElement(), archiveJid);
Collection<ArchivedMessage> archivedMessages = retrieveMessages(queryRequest); Collection<ArchivedMessage> archivedMessages = retrieveMessages(queryRequest);
...@@ -80,17 +79,21 @@ public class IQQueryHandler extends AbstractIQHandler implements ...@@ -80,17 +79,21 @@ public class IQQueryHandler extends AbstractIQHandler implements
sendMessageResult(session, queryRequest, archivedMessage); sendMessageResult(session, queryRequest, archivedMessage);
} }
sendFinalMessage(session, queryRequest); sendEndQuery(packet, session, queryRequest);
sendAcknowledgementResult(packet, session);
return null; return null;
} }
protected void sendMidQuery(IQ packet, LocalClientSession session) {
// Default: Do nothing.
}
protected abstract void sendEndQuery(IQ packet, LocalClientSession session, QueryRequest queryRequest);
/** /**
* Create error response to send to client * Create error response to send to client
* @param packet * @param packet IQ stanza received
* @return * @return IQ stanza to be sent.
*/ */
private IQ buildErrorResponse(IQ packet) { private IQ buildErrorResponse(IQ packet) {
IQ reply = IQ.createResultIQ(packet); IQ reply = IQ.createResultIQ(packet);
...@@ -268,4 +271,18 @@ public class IQQueryHandler extends AbstractIQHandler implements ...@@ -268,4 +271,18 @@ public class IQQueryHandler extends AbstractIQHandler implements
return Collections.singleton(NAMESPACE).iterator(); return Collections.singleton(NAMESPACE).iterator();
} }
void completeFinElement(QueryRequest queryRequest, Element fin) {
if(queryRequest.getQueryid() != null) {
fin.addAttribute("queryid", queryRequest.getQueryid());
}
XmppResultSet resultSet = queryRequest.getResultSet();
if (resultSet != null) {
fin.add(resultSet.createResultElement());
if(resultSet.isComplete()) {
fin.addAttribute("complete", "true");
}
}
}
} }
package com.reucon.openfire.plugin.archive.xep0313;
import org.dom4j.*;
import org.jivesoftware.openfire.handler.IQHandler;
import org.jivesoftware.openfire.session.LocalClientSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.IQ;
import org.xmpp.packet.Message;
/**
* XEP-0313 IQ Query Handler
*/
class IQQueryHandler0 extends IQQueryHandler {
private static final Logger Log = LoggerFactory.getLogger(IQHandler.class);
private static final String MODULE_NAME = "Message Archive Management Query Handler v0";
IQQueryHandler0() {
super(MODULE_NAME, "urn:xmpp:mam:0");
}
@Override
protected void sendMidQuery(IQ packet, LocalClientSession session) {
sendAcknowledgementResult(packet, session);
}
@Override
protected void sendEndQuery(IQ packet, LocalClientSession session, QueryRequest queryRequest) {
sendFinalMessage(session, queryRequest);
}
/**
* Send result packet to client acknowledging query.
* @param packet Received query packet
* @param session Client session to respond to
*/
private void sendAcknowledgementResult(IQ packet, LocalClientSession session) {
IQ result = IQ.createResultIQ(packet);
session.process(result);
}
/**
* Send final message back to client following query.
* @param session Client session to respond to
* @param queryRequest Received query request
*/
private void sendFinalMessage(LocalClientSession session,
final QueryRequest queryRequest) {
Message finalMessage = new Message();
finalMessage.setTo(session.getAddress());
Element fin = finalMessage.addChildElement("fin", NAMESPACE);
completeFinElement(queryRequest, fin);
session.process(finalMessage);
}
}
package com.reucon.openfire.plugin.archive.xep0313;
import org.dom4j.*;
import org.jivesoftware.openfire.session.LocalClientSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.IQ;
/**
* XEP-0313 IQ Query Handler
*/
class IQQueryHandler1 extends IQQueryHandler {
private static final Logger Log = LoggerFactory.getLogger(IQQueryHandler1.class);
private static final String MODULE_NAME = "Message Archive Management Query Handler v1";
IQQueryHandler1() {
super(MODULE_NAME, "urn:xmpp:mam:1");
}
@Override
protected void sendEndQuery(IQ packet, LocalClientSession session, QueryRequest queryRequest) {
sendAcknowledgementResult(packet, session, queryRequest);
}
/**
* Send result packet to client acknowledging query.
* @param packet Received query packet
* @param session Client session to respond to
*/
private void sendAcknowledgementResult(IQ packet, LocalClientSession session, QueryRequest queryRequest) {
IQ result = IQ.createResultIQ(packet);
Element fin = result.setChildElement("fin", NAMESPACE);
completeFinElement(queryRequest, fin);
session.process(result);
}
}
...@@ -18,8 +18,8 @@ public class Xep0313Support extends AbstractXepSupport { ...@@ -18,8 +18,8 @@ public class Xep0313Support extends AbstractXepSupport {
public Xep0313Support(XMPPServer server) { public Xep0313Support(XMPPServer server) {
super(server, NAMESPACE,NAMESPACE, "XEP-0313 IQ Dispatcher"); super(server, NAMESPACE,NAMESPACE, "XEP-0313 IQ Dispatcher");
this.iqHandlers = new ArrayList<IQHandler>(); this.iqHandlers = new ArrayList<>();
iqHandlers.add(new IQQueryHandler()); iqHandlers.add(new IQQueryHandler0());
} }
} }
package com.reucon.openfire.plugin.archive.xep0313;
import com.reucon.openfire.plugin.archive.xep.AbstractXepSupport;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.handler.IQHandler;
import java.util.ArrayList;
/**
* Encapsulates support for <a
* href="http://www.xmpp.org/extensions/xep-0313.html">XEP-0313</a>.
*/
public class Xep0313Support1 extends AbstractXepSupport {
private static final String NAMESPACE = "urn:xmpp:mam:1";
public Xep0313Support1(XMPPServer server) {
super(server, NAMESPACE,NAMESPACE, "XEP-0313 IQ Dispatcher");
this.iqHandlers = new ArrayList<>();
iqHandlers.add(new IQQueryHandler1());
}
}
...@@ -22,6 +22,7 @@ package org.jivesoftware.openfire.plugin; ...@@ -22,6 +22,7 @@ package org.jivesoftware.openfire.plugin;
import java.io.File; import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
import com.reucon.openfire.plugin.archive.xep0313.Xep0313Support1;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.archive.ArchiveIndexer; import org.jivesoftware.openfire.archive.ArchiveIndexer;
import org.jivesoftware.openfire.archive.ArchiveInterceptor; import org.jivesoftware.openfire.archive.ArchiveInterceptor;
...@@ -73,6 +74,7 @@ public class MonitoringPlugin implements Plugin { ...@@ -73,6 +74,7 @@ public class MonitoringPlugin implements Plugin {
private IndexManager indexManager; private IndexManager indexManager;
private Xep0136Support xep0136Support; private Xep0136Support xep0136Support;
private Xep0313Support xep0313Support; private Xep0313Support xep0313Support;
private Xep0313Support1 xep0313Support1;
public MonitoringPlugin() { public MonitoringPlugin() {
instance = this; instance = this;
...@@ -162,6 +164,9 @@ public class MonitoringPlugin implements Plugin { ...@@ -162,6 +164,9 @@ public class MonitoringPlugin implements Plugin {
xep0313Support = new Xep0313Support(XMPPServer.getInstance()); xep0313Support = new Xep0313Support(XMPPServer.getInstance());
xep0313Support.start(); xep0313Support.start();
xep0313Support1 = new Xep0313Support1(XMPPServer.getInstance());
xep0313Support1.start();
// Check if we Enterprise is installed and stop loading this plugin if // Check if we Enterprise is installed and stop loading this plugin if
// found // found
File pluginDir = new File(JiveGlobals.getHomeDirectory(), "plugins"); File pluginDir = new File(JiveGlobals.getHomeDirectory(), "plugins");
......
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