1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-14 06:51:08 +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:
Florian Schmaus 2015-01-08 11:01:35 +01:00
parent fcb4844d10
commit bb8dcc9874
28 changed files with 533 additions and 317 deletions

View file

@ -37,6 +37,8 @@ import org.jivesoftware.smack.filter.IQResultReplyFilter;
import org.jivesoftware.smack.filter.IQTypeFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler;
import org.jivesoftware.smack.iqrequest.IQRequestHandler.Mode;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
@ -65,8 +67,6 @@ public class PrivacyListManager extends Manager {
public static final PacketFilter PRIVACY_FILTER = new PacketTypeFilter(Privacy.class);
private static final PacketFilter PRIVACY_SET = new AndFilter(IQTypeFilter.SET, PRIVACY_FILTER);
private static final PacketFilter PRIVACY_RESULT = new AndFilter(IQTypeFilter.RESULT, PRIVACY_FILTER);
// Keep the list of instances of this class.
@ -97,10 +97,11 @@ public class PrivacyListManager extends Manager {
private PrivacyListManager(XMPPConnection connection) {
super(connection);
connection.addSyncPacketListener(new PacketListener() {
connection.registerIQRequestHandler(new AbstractIqRequestHandler(Privacy.ELEMENT, Privacy.NAMESPACE,
IQ.Type.set, Mode.sync) {
@Override
public void processPacket(Packet packet) throws NotConnectedException {
Privacy privacy = (Privacy) packet;
public IQ handleIQRequest(IQ iqRequest) {
Privacy privacy = (Privacy) iqRequest;
// Notifies the event to the listeners.
for (PrivacyListListener listener : listeners) {
@ -117,11 +118,9 @@ public class PrivacyListManager extends Manager {
}
}
// Send a result package acknowledging the reception of a privacy package.
IQ iq = IQ.createResultIQ(privacy);
connection().sendPacket(iq);
return IQ.createResultIQ(privacy);
}
}, PRIVACY_SET);
});
// cached(Active|Default)ListName handling
connection.addPacketSendingListener(new PacketListener() {