1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-29 15:32:06 +01:00

Add AbstractXMPPConnection.setReplyToUnkownIq(boolean)

and some javadoc related to IQ request handlers.
This commit is contained in:
Florian Schmaus 2015-01-23 20:12:21 +01:00
parent e3f1865821
commit cbb477ebeb
3 changed files with 41 additions and 5 deletions

View file

@ -881,6 +881,32 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
packetReplyTimeout = timeout; packetReplyTimeout = timeout;
} }
private static boolean replyToUnknownIqDefault = true;
/**
* Set the default value used to determine if new connection will reply to unknown IQ requests. The pre-configured
* default is 'true'.
*
* @param replyToUnkownIqDefault
* @see #setReplyToUnknownIq(boolean)
*/
public static void setReplyToUnknownIqDefault(boolean replyToUnkownIqDefault) {
AbstractXMPPConnection.replyToUnknownIqDefault = replyToUnkownIqDefault;
}
private boolean replyToUnkownIq = replyToUnknownIqDefault;
/**
* Set if Smack will automatically send
* {@link org.jivesoftware.smack.packet.XMPPError.Condition#feature_not_implemented} when a request IQ without a
* registered {@link IQRequestHandler} is received.
*
* @param replyToUnknownIq
*/
public void setReplyToUnknownIq(boolean replyToUnknownIq) {
this.replyToUnkownIq = replyToUnknownIq;
}
protected void parseAndProcessStanza(XmlPullParser parser) throws Exception { protected void parseAndProcessStanza(XmlPullParser parser) throws Exception {
ParserUtils.assertAtStartTag(parser); ParserUtils.assertAtStartTag(parser);
int parserDepth = parser.getDepth(); int parserDepth = parser.getDepth();
@ -933,7 +959,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
} }
} }
/** /**
* Invoke {@link PacketCollector#processPacket(Packet)} for every * Invoke {@link PacketCollector#processPacket(Packet)} for every
* PacketCollector with the given packet. Also notify the receive listeners with a matching packet filter about the packet. * PacketCollector with the given packet. Also notify the receive listeners with a matching packet filter about the packet.
@ -964,6 +989,9 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
throw new IllegalStateException("Should only encounter IQ type 'get' or 'set'"); throw new IllegalStateException("Should only encounter IQ type 'get' or 'set'");
} }
if (iqRequestHandler == null) { if (iqRequestHandler == null) {
if (!replyToUnkownIq) {
return;
}
// If the IQ stanza is of type "get" or "set" with no registered IQ request handler, then answer an // If the IQ stanza is of type "get" or "set" with no registered IQ request handler, then answer an
// IQ of type "error" with code 501 ("feature-not-implemented") // IQ of type "error" with code 501 ("feature-not-implemented")
ErrorIQ errorIQ = IQ.createErrorResponse(iq, new XMPPError( ErrorIQ errorIQ = IQ.createErrorResponse(iq, new XMPPError(
@ -992,10 +1020,9 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
if (response == null) { if (response == null) {
// It is not ideal if the IQ request handler does not return an IQ response, because RFC // It is not ideal if the IQ request handler does not return an IQ response, because RFC
// 6120 § 8.1.2 does specify that a response is mandatory. But some APIs, mostly the // 6120 § 8.1.2 does specify that a response is mandatory. But some APIs, mostly the
// file transfer one, does not always return a result, so we need to handle this case // file transfer one, does not always return a result, so we need to handle this case.
// gracefully for now // Also sometimes a request handler may decide that it's better to not send a response,
// TODO Add a warning if response is null once all APIs using handleIQRequest return an // e.g. to avoid presence leaks.
// IQ response. Later consider throwing an IllegalStateException
return; return;
} }
try { try {

View file

@ -19,6 +19,9 @@ package org.jivesoftware.smack.iqrequest;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type; import org.jivesoftware.smack.packet.IQ.Type;
/**
* Convenience class to create IQ requests handlers.
*/
public abstract class AbstractIqRequestHandler implements IQRequestHandler { public abstract class AbstractIqRequestHandler implements IQRequestHandler {
private final String element; private final String element;

View file

@ -18,6 +18,12 @@ package org.jivesoftware.smack.iqrequest;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
/**
* IQ request handler are responsible for handling incoming IQ requests. They can be registered with
* {@link org.jivesoftware.smack.XMPPConnection#registerIQRequestHandler(IQRequestHandler)}.
*
* @see AbstractIqRequestHandler
*/
public interface IQRequestHandler { public interface IQRequestHandler {
public enum Mode { public enum Mode {