summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/com')
-rw-r--r--src/com/isode/stroke/client/CoreClient.java3
-rw-r--r--src/com/isode/stroke/queries/IQRouter.java20
-rw-r--r--src/com/isode/stroke/queries/Request.java49
3 files changed, 56 insertions, 16 deletions
diff --git a/src/com/isode/stroke/client/CoreClient.java b/src/com/isode/stroke/client/CoreClient.java
index 236ed89..524a05a 100644
--- a/src/com/isode/stroke/client/CoreClient.java
+++ b/src/com/isode/stroke/client/CoreClient.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2013, Isode Limited, London, England.
+ * Copyright (c) 2010-2014, Isode Limited, London, England.
* All rights reserved.
*/
/*
@@ -154,6 +154,7 @@ public class CoreClient {
});
iqRouter_ = new IQRouter(stanzaChannel_);
+ iqRouter_.setJID(jid);
}
/*CoreClient::~CoreClient() {
diff --git a/src/com/isode/stroke/queries/IQRouter.java b/src/com/isode/stroke/queries/IQRouter.java
index bb4dafa..f35cab4 100644
--- a/src/com/isode/stroke/queries/IQRouter.java
+++ b/src/com/isode/stroke/queries/IQRouter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, Isode Limited, London, England.
+ * Copyright (c) 2010-2014, Isode Limited, London, England.
* All rights reserved.
*/
/*
@@ -13,6 +13,7 @@ import java.util.Vector;
import com.isode.stroke.elements.ErrorPayload;
import com.isode.stroke.elements.IQ;
import com.isode.stroke.signals.Slot1;
+import com.isode.stroke.jid.JID;
/**
* This class is responsible for routing all IQ stanzas to the handlers. It's
@@ -26,6 +27,7 @@ public class IQRouter {
private final Vector<IQHandler> handlers_ = new Vector<IQHandler>();
private final IQChannel channel_;
+ private JID jid_;
public IQRouter(IQChannel channel) {
channel_ = channel;
@@ -75,4 +77,20 @@ public class IQRouter {
sendIQ(IQ.createError(iq.getFrom(), iq.getID(), ErrorPayload.Condition.FeatureNotImplemented, ErrorPayload.Type.Cancel));
}
}
+
+ /**
+ * Sets the JID of this IQ router.
+ *
+ * This JID is used by requests to check whether incoming results
+ * are addressed correctly
+ * @param jid the JID
+ */
+ public void setJID(final JID jid) {
+ jid_ = jid;
+ }
+
+ public JID getJID() {
+ return jid_;
+ }
+
}
diff --git a/src/com/isode/stroke/queries/Request.java b/src/com/isode/stroke/queries/Request.java
index 6a843a1..50645b4 100644
--- a/src/com/isode/stroke/queries/Request.java
+++ b/src/com/isode/stroke/queries/Request.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, Isode Limited, London, England.
+ * Copyright (c) 2010-2014, Isode Limited, London, England.
* All rights reserved.
*/
/*
@@ -67,20 +67,41 @@ public abstract class Request implements IQHandler {
public boolean handleIQ(IQ iq) {
boolean handled = false;
if (sent_ && iq.getID().equals(id_)) {
- 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;
- }
+ 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;
+ }
+ }
return handled;
}
+ private boolean isCorrectSender(final JID jid) {
+ 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;
+ }
+
+ return jid.isValid() ?
+ router_.getJID().compare(jid, JID.CompareType.WithoutResource) == 0 : true;
+ }
+
+
} \ No newline at end of file