mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-12-14 00:51:19 +01:00
Add IQ request handler API
This also moves the logic to send error IQ replies from "when there is no IQ provider registerd" to "when there is no IQ request handler registered". Which has for example the advantage that IQ parsing no longer asks for a connection instance.
This commit is contained in:
parent
fcb4844d10
commit
bb8dcc9874
28 changed files with 533 additions and 317 deletions
|
|
@ -24,14 +24,14 @@ import org.jivesoftware.smack.SmackException.NotConnectedException;
|
|||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.ConnectionCreationListener;
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import org.jivesoftware.smack.XMPPConnectionRegistry;
|
||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smack.filter.AndFilter;
|
||||
import org.jivesoftware.smack.filter.IQTypeFilter;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler;
|
||||
import org.jivesoftware.smack.iqrequest.IQRequestHandler.Mode;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.IQ.Type;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.packet.XMPPError.Condition;
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.time.packet.Time;
|
||||
|
||||
|
|
@ -39,9 +39,6 @@ public class EntityTimeManager extends Manager {
|
|||
|
||||
private static final Map<XMPPConnection, EntityTimeManager> INSTANCES = new WeakHashMap<XMPPConnection, EntityTimeManager>();
|
||||
|
||||
private static final PacketFilter TIME_PACKET_FILTER = new AndFilter(new PacketTypeFilter(
|
||||
Time.class), IQTypeFilter.GET);
|
||||
|
||||
private static boolean autoEnable = true;
|
||||
|
||||
static {
|
||||
|
|
@ -72,14 +69,18 @@ public class EntityTimeManager extends Manager {
|
|||
if (autoEnable)
|
||||
enable();
|
||||
|
||||
connection.addAsyncPacketListener(new PacketListener() {
|
||||
connection.registerIQRequestHandler(new AbstractIqRequestHandler(Time.ELEMENT, Time.NAMESPACE, Type.get,
|
||||
Mode.async) {
|
||||
@Override
|
||||
public void processPacket(Packet packet) throws NotConnectedException {
|
||||
if (!enabled)
|
||||
return;
|
||||
connection().sendPacket(Time.createResponse(packet));
|
||||
public IQ handleIQRequest(IQ iqRequest) {
|
||||
if (enabled) {
|
||||
return Time.createResponse(iqRequest);
|
||||
}
|
||||
else {
|
||||
return IQ.createErrorResponse(iqRequest, new XMPPError(Condition.not_acceptable));
|
||||
}
|
||||
}
|
||||
}, TIME_PACKET_FILTER);
|
||||
});
|
||||
}
|
||||
|
||||
public synchronized void enable() {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
package org.jivesoftware.smackx.time.packet;
|
||||
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jxmpp.util.XmppDateTime;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
|
@ -123,7 +122,7 @@ public class Time extends IQ {
|
|||
this.tzo = tzo;
|
||||
}
|
||||
|
||||
public static Time createResponse(Packet request) {
|
||||
public static Time createResponse(IQ request) {
|
||||
Time time = new Time(Calendar.getInstance());
|
||||
time.setType(Type.result);
|
||||
time.setTo(request.getFrom());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue