summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles E. Rolke <chug@apache.org>2013-07-01 20:30:05 +0000
committerCharles E. Rolke <chug@apache.org>2013-07-01 20:30:05 +0000
commit5123aada670155155f2f4979e7e9699996b974d8 (patch)
tree38462248430a4330430eefaef8e08fae4234e75b
parentf4bbaac2bc787793dd7d1c7ab3a2673bbb2d38da (diff)
downloadqpid-python-5123aada670155155f2f4979e7e9699996b974d8.tar.gz
QPID-4969: C++ Broker headers exchange allows creation of bindings
with duplicate keys Patch from Gordon Sim to correct issues in initial fix. Now successive bind requests are accepted when the key, queue, and exchange are identical if and only if all of the binding args are also identical. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1498671 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/cpp/src/qpid/broker/HeadersExchange.cpp8
-rw-r--r--qpid/cpp/src/qpid/broker/HeadersExchange.h4
-rw-r--r--qpid/cpp/src/tests/ExchangeTest.cpp2
3 files changed, 8 insertions, 6 deletions
diff --git a/qpid/cpp/src/qpid/broker/HeadersExchange.cpp b/qpid/cpp/src/qpid/broker/HeadersExchange.cpp
index 204f5cf676..82284feaeb 100644
--- a/qpid/cpp/src/qpid/broker/HeadersExchange.cpp
+++ b/qpid/cpp/src/qpid/broker/HeadersExchange.cpp
@@ -200,8 +200,10 @@ bool HeadersExchange::bind(Queue::shared_ptr queue, const string& bindingKey, co
Bindings::ConstPtr p = bindings.snapshot();
if (p.get()) {
+ MatchArgs matchArgs(queue, &extra_args);
+ MatchKey matchKey(queue, bindingKey);
for (std::vector<BoundKey>::const_iterator i = p->begin(); i != p->end(); ++i) {
- if (queue == i->binding->queue && bindingKey == i->binding->key) {
+ if (matchKey(*i) && !matchArgs(*i)) {
throw InternalErrorException(QPID_MSG("Exchange: " << getName()
<< ", binding key: " << bindingKey
<< " Duplicate binding key not allowed." ));
@@ -372,7 +374,7 @@ bool HeadersExchange::equal(const FieldTable& a, const FieldTable& b) {
//---------
HeadersExchange::MatchArgs::MatchArgs(Queue::shared_ptr q, const qpid::framing::FieldTable* a) : queue(q), args(a) {}
-bool HeadersExchange::MatchArgs::operator()(BoundKey & bk)
+bool HeadersExchange::MatchArgs::operator()(const BoundKey & bk)
{
return bk.binding->queue == queue && bk.binding->args == *args;
}
@@ -380,7 +382,7 @@ bool HeadersExchange::MatchArgs::operator()(BoundKey & bk)
//---------
HeadersExchange::MatchKey::MatchKey(Queue::shared_ptr q, const std::string& k) : queue(q), key(k) {}
-bool HeadersExchange::MatchKey::operator()(BoundKey & bk)
+bool HeadersExchange::MatchKey::operator()(const BoundKey & bk)
{
return bk.binding->queue == queue && bk.binding->key == key;
}
diff --git a/qpid/cpp/src/qpid/broker/HeadersExchange.h b/qpid/cpp/src/qpid/broker/HeadersExchange.h
index c96c5bc790..b5b10350d2 100644
--- a/qpid/cpp/src/qpid/broker/HeadersExchange.h
+++ b/qpid/cpp/src/qpid/broker/HeadersExchange.h
@@ -48,7 +48,7 @@ class HeadersExchange : public virtual Exchange {
const Queue::shared_ptr queue;
const qpid::framing::FieldTable* args;
MatchArgs(Queue::shared_ptr q, const qpid::framing::FieldTable* a);
- bool operator()(BoundKey & bk);
+ bool operator()(const BoundKey & bk);
};
struct MatchKey
@@ -56,7 +56,7 @@ class HeadersExchange : public virtual Exchange {
const Queue::shared_ptr queue;
const std::string& key;
MatchKey(Queue::shared_ptr q, const std::string& k);
- bool operator()(BoundKey & bk);
+ bool operator()(const BoundKey & bk);
};
struct FedUnbindModifier
diff --git a/qpid/cpp/src/tests/ExchangeTest.cpp b/qpid/cpp/src/tests/ExchangeTest.cpp
index 4f18b91b5a..8c2dbb21c8 100644
--- a/qpid/cpp/src/tests/ExchangeTest.cpp
+++ b/qpid/cpp/src/tests/ExchangeTest.cpp
@@ -138,7 +138,7 @@ QPID_AUTO_TEST_CASE(testIsBound)
args3.setInt("b", 6);
headers.bind(a, "", &args1);
- headers.bind(a, "", &args3);
+ headers.bind(a, "other", &args3);//need to use different binding key to correctly identify second binding
headers.bind(b, "", &args2);
headers.bind(c, "", &args1);