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;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.TimeZone;
import org.dom4j.*;
import org.jivesoftware.openfire.auth.UnauthorizedException;
......@@ -31,17 +28,17 @@ import com.reucon.openfire.plugin.archive.xep0059.XmppResultSet;
/**
* XEP-0313 IQ Query Handler
*/
public class IQQueryHandler extends AbstractIQHandler implements
abstract class IQQueryHandler extends AbstractIQHandler implements
ServerFeaturesProvider {
private static final Logger Log = LoggerFactory.getLogger(IQHandler.class);
private static final String NAMESPACE = "urn:xmpp:mam:0";
private static final String MODULE_NAME = "Message Archive Management Query Handler";
protected final String NAMESPACE;
XMPPDateTimeFormat xmppDateTimeFormat = new XMPPDateTimeFormat();
private final XMPPDateTimeFormat xmppDateTimeFormat = new XMPPDateTimeFormat();
protected IQQueryHandler() {
super(MODULE_NAME, "query", NAMESPACE);
IQQueryHandler(final String moduleName, final String namespace) {
super(moduleName, "query", namespace);
NAMESPACE = namespace;
}
public IQ handleIQ(IQ packet) throws UnauthorizedException {
......@@ -73,6 +70,8 @@ public class IQQueryHandler extends AbstractIQHandler implements
}
}
sendMidQuery(packet, session);
final QueryRequest queryRequest = new QueryRequest(packet.getChildElement(), archiveJid);
Collection<ArchivedMessage> archivedMessages = retrieveMessages(queryRequest);
......@@ -80,17 +79,21 @@ public class IQQueryHandler extends AbstractIQHandler implements
sendMessageResult(session, queryRequest, archivedMessage);
}
sendFinalMessage(session, queryRequest);
sendAcknowledgementResult(packet, session);
sendEndQuery(packet, session, queryRequest);
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
* @param packet
* @return
* @param packet IQ stanza received
* @return IQ stanza to be sent.
*/
private IQ buildErrorResponse(IQ packet) {
IQ reply = IQ.createResultIQ(packet);
......@@ -268,4 +271,18 @@ public class IQQueryHandler extends AbstractIQHandler implements
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 {
public Xep0313Support(XMPPServer server) {
super(server, NAMESPACE,NAMESPACE, "XEP-0313 IQ Dispatcher");
this.iqHandlers = new ArrayList<IQHandler>();
iqHandlers.add(new IQQueryHandler());
this.iqHandlers = new ArrayList<>();
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;
import java.io.File;
import java.io.FileFilter;
import com.reucon.openfire.plugin.archive.xep0313.Xep0313Support1;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.archive.ArchiveIndexer;
import org.jivesoftware.openfire.archive.ArchiveInterceptor;
......@@ -73,6 +74,7 @@ public class MonitoringPlugin implements Plugin {
private IndexManager indexManager;
private Xep0136Support xep0136Support;
private Xep0313Support xep0313Support;
private Xep0313Support1 xep0313Support1;
public MonitoringPlugin() {
instance = this;
......@@ -162,6 +164,9 @@ public class MonitoringPlugin implements Plugin {
xep0313Support = new Xep0313Support(XMPPServer.getInstance());
xep0313Support.start();
xep0313Support1 = new Xep0313Support1(XMPPServer.getInstance());
xep0313Support1.start();
// Check if we Enterprise is installed and stop loading this plugin if
// found
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