diff options
author | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-07-02 09:55:38 (GMT) |
---|---|---|
committer | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-07-21 09:26:58 (GMT) |
commit | e98df2cfcd3bc553b16c139a7d2adfcbe672b540 (patch) | |
tree | 449b58d27884ae4fa7441cea3c3ee7c9f0410dd4 /src/com/isode/stroke/queries | |
parent | 43b51821ff8d03aa55209c66ea3e26080cf3cb8c (diff) | |
download | stroke-e98df2cfcd3bc553b16c139a7d2adfcbe672b540.zip stroke-e98df2cfcd3bc553b16c139a7d2adfcbe672b540.tar.bz2 |
Adds Disco Features.
Adds DiscoServiceWalker, FeatureOracle, JIDDiscoInfoResponder.
Updates CapsInfoGenerator, ClientDiscoManager,
EntityCapsManager, EntityCapsProvider, IQ Element, Request.
License:
This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Test-Information:
Tests added for:
CapsInfoGenerator, CapsManager, DiscoInfoResponder, EntityCapsManager, JIDDiscoInfoResponder.
All tests pass.
Change-Id: Ib7cd08ff6f72b7649e4819943b627459c69a1397
Diffstat (limited to 'src/com/isode/stroke/queries')
-rw-r--r-- | src/com/isode/stroke/queries/Request.java | 114 |
1 files changed, 77 insertions, 37 deletions
diff --git a/src/com/isode/stroke/queries/Request.java b/src/com/isode/stroke/queries/Request.java index 50645b4..52e3854 100644 --- a/src/com/isode/stroke/queries/Request.java +++ b/src/com/isode/stroke/queries/Request.java @@ -14,6 +14,7 @@ import com.isode.stroke.elements.IQ; import com.isode.stroke.elements.IQ.Type; import com.isode.stroke.elements.Payload; import com.isode.stroke.jid.JID; +import java.util.logging.Logger; /** * Base class for IQ requests. @@ -22,36 +23,63 @@ public abstract class Request implements IQHandler { protected final Type type_; protected final IQRouter router_; protected final JID receiver_; + protected final JID sender_; private boolean sent_; private Payload payload_; private String id_; + private Logger logger_ = Logger.getLogger(this.getClass().getName()); + /** + * Constructs a request of a certain type to a specific receiver. + */ public Request(IQ.Type type, JID receiver, IQRouter router) { - this(type, receiver, null, router); + this(type, null, receiver, null, router); } + /** + * Constructs a request of a certain type to a specific receiver, and attaches the given + * payload. + */ public Request(IQ.Type type, JID receiver, Payload payload, IQRouter router) { + this(type, null, receiver, payload, router); + } + + /** + * Constructs a request of a certain type to a specific receiver from a specific sender. + */ + public Request(IQ.Type type, JID sender, JID receiver, IQRouter router) { + this(type, sender, receiver, null, router); + } + + /** + * Constructs a request of a certain type to a specific receiver from a specific sender, and attaches the given + * payload. + */ + public Request(IQ.Type type, JID sender, JID receiver, Payload payload, IQRouter router) { type_ = type; router_ = router; receiver_ = receiver; payload_ = payload; + sender_ = sender; sent_ = false; } - public void send() { + public String send() { assert payload_ != null; - assert !sent_; - sent_ = true; + assert !sent_; + sent_ = true; - IQ iq = new IQ(type_); - iq.setTo(receiver_); - iq.addPayload(payload_); - id_ = router_.getNewIQID(); - iq.setID(id_); + IQ iq = new IQ(type_); + iq.setTo(receiver_); + iq.setFrom(sender_); + iq.addPayload(payload_); + id_ = router_.getNewIQID(); + iq.setID(id_); - router_.addHandler(this); + router_.addHandler(this); - router_.sendIQ(iq); + router_.sendIQ(iq); + return id_; } protected void setPayload(Payload payload) { @@ -66,42 +94,54 @@ public abstract class Request implements IQHandler { public boolean handleIQ(IQ iq) { boolean handled = false; - if (sent_ && iq.getID().equals(id_)) { - if (isCorrectSender(iq.getFrom())) { - - if (iq.getType().equals(IQ.Type.Result)) { - handleResponse(iq.getPayload(payload_), null); - } else { - ErrorPayload errorPayload = iq.getPayload(new ErrorPayload()); - if (errorPayload != null) { - handleResponse(null, errorPayload); - } else { - handleResponse(null, new ErrorPayload(ErrorPayload.Condition.UndefinedCondition)); - } + if (iq.getType() == IQ.Type.Result || iq.getType() == IQ.Type.Error) { + if (sent_ && iq.getID().equals(id_)) { + if (isCorrectSender(iq.getFrom())) { + + if (iq.getType().equals(IQ.Type.Result)) { + handleResponse(iq.getPayload(payload_), null); + } else { + ErrorPayload errorPayload = iq.getPayload(new ErrorPayload()); + if (errorPayload != null) { + handleResponse(null, errorPayload); + } else { + handleResponse(null, new ErrorPayload(ErrorPayload.Condition.UndefinedCondition)); + } + } + router_.removeHandler(this); + handled = true; + } + } } - router_.removeHandler(this); - handled = true; - } - } return handled; } private boolean isCorrectSender(final JID jid) { - if (isAccountJID(receiver_)) { - return isAccountJID(jid); - } - return (jid.compare(receiver_, JID.CompareType.WithResource) == 0); + if (isAccountJID(receiver_)) { + return isAccountJID(jid); + } + return (jid.compare(receiver_, JID.CompareType.WithResource) == 0); } private boolean isAccountJID(final JID jid) { - // If the router's JID is not set, we don't check anything - if (!router_.getJID().isValid()) { - return true; - } + // If the router's JID is not set, we don't check anything + if (!router_.getJID().isValid()) { + return true; + } - return jid.isValid() ? - router_.getJID().compare(jid, JID.CompareType.WithoutResource) == 0 : true; + return jid.isValid() ? + router_.getJID().compare(jid, JID.CompareType.WithoutResource) == 0 : true; } + public JID getReceiver() { + return receiver_; + } + /** + * Returns the ID of this request. + * This will only be set after send() is called. + */ + public String getID() { + return id_; + } }
\ No newline at end of file |