You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ch...@apache.org on 2013/07/01 22:30:05 UTC

svn commit: r1498671 - in /qpid/trunk/qpid/cpp/src: qpid/broker/HeadersExchange.cpp qpid/broker/HeadersExchange.h tests/ExchangeTest.cpp

Author: chug
Date: Mon Jul  1 20:30:05 2013
New Revision: 1498671

URL: http://svn.apache.org/r1498671
Log:
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.


Modified:
    qpid/trunk/qpid/cpp/src/qpid/broker/HeadersExchange.cpp
    qpid/trunk/qpid/cpp/src/qpid/broker/HeadersExchange.h
    qpid/trunk/qpid/cpp/src/tests/ExchangeTest.cpp

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/HeadersExchange.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/HeadersExchange.cpp?rev=1498671&r1=1498670&r2=1498671&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/HeadersExchange.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/HeadersExchange.cpp Mon Jul  1 20:30:05 2013
@@ -200,8 +200,10 @@ bool HeadersExchange::bind(Queue::shared
 
         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 FieldT
 //---------
 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::operato
 //---------
 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;
 }

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/HeadersExchange.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/HeadersExchange.h?rev=1498671&r1=1498670&r2=1498671&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/HeadersExchange.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/HeadersExchange.h Mon Jul  1 20:30:05 2013
@@ -48,7 +48,7 @@ class HeadersExchange : public virtual E
         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 E
         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

Modified: qpid/trunk/qpid/cpp/src/tests/ExchangeTest.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/ExchangeTest.cpp?rev=1498671&r1=1498670&r2=1498671&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/ExchangeTest.cpp (original)
+++ qpid/trunk/qpid/cpp/src/tests/ExchangeTest.cpp Mon Jul  1 20:30:05 2013
@@ -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);
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org