diff options
| author | Jonathan Robie <jonathan@apache.org> | 2010-10-28 15:21:06 +0000 |
|---|---|---|
| committer | Jonathan Robie <jonathan@apache.org> | 2010-10-28 15:21:06 +0000 |
| commit | 3197400e025c1198c831f4d75936cc351295ef48 (patch) | |
| tree | f7e0c1c280167418c1eb376c059c7e17e846f744 /cpp/src | |
| parent | 410031a2a1f90d4be1af1eba3f9aecf8cb3818c9 (diff) | |
| download | qpid-python-3197400e025c1198c831f4d75936cc351295ef48.tar.gz | |
Fixes broker issues when max_count or max_size are invalid.
Accepts non-negative integer values, or strings containing the lexical representation of such values.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1028346 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
| -rw-r--r-- | cpp/src/qpid/broker/QueuePolicy.cpp | 25 | ||||
| -rw-r--r-- | cpp/src/qpid/broker/QueuePolicy.h | 2 |
2 files changed, 20 insertions, 7 deletions
diff --git a/cpp/src/qpid/broker/QueuePolicy.cpp b/cpp/src/qpid/broker/QueuePolicy.cpp index 4b185ef025..c1d979ac33 100644 --- a/cpp/src/qpid/broker/QueuePolicy.cpp +++ b/cpp/src/qpid/broker/QueuePolicy.cpp @@ -24,6 +24,7 @@ #include "qpid/framing/FieldValue.h" #include "qpid/framing/reply_exceptions.h" #include "qpid/log/Statement.h" +#include <sstream> using namespace qpid::broker; using namespace qpid::framing; @@ -115,12 +116,24 @@ void QueuePolicy::update(FieldTable& settings) settings.setString(typeKey, type); } - -int QueuePolicy::getInt(const FieldTable& settings, const std::string& key, int defaultValue) +uint32_t QueuePolicy::getCapacity(const FieldTable& settings, const std::string& key, uint32_t defaultValue) { FieldTable::ValuePtr v = settings.get(key); - if (v && v->convertsTo<int>()) return v->get<int>(); - else return defaultValue; + + int32_t result = 0; + + if (!v) return defaultValue; + if (v->convertsTo<int>()) { + result = v->get<int>(); + if (result >= 0) return result; + } + else { + string s(v->get<string>()); // I assume anything can be converted to a string + std::istringstream convert(s); + if (convert >> result && result >= 0) return result; + } + + throw InvalidArgumentException(QPID_MSG("Cannot convert " << key << " to unsigned integer")); } std::string QueuePolicy::getType(const FieldTable& settings) @@ -297,8 +310,8 @@ std::auto_ptr<QueuePolicy> QueuePolicy::createQueuePolicy(const qpid::framing::F std::auto_ptr<QueuePolicy> QueuePolicy::createQueuePolicy(const std::string& name, const qpid::framing::FieldTable& settings) { - uint32_t maxCount = getInt(settings, maxCountKey, 0); - uint32_t maxSize = getInt(settings, maxSizeKey, defaultMaxSize); + uint32_t maxCount = getCapacity(settings, maxCountKey, 0); + uint32_t maxSize = getCapacity(settings, maxSizeKey, defaultMaxSize); if (maxCount || maxSize) { return createQueuePolicy(name, maxCount, maxSize, getType(settings)); } else { diff --git a/cpp/src/qpid/broker/QueuePolicy.h b/cpp/src/qpid/broker/QueuePolicy.h index 7006b617a1..3cdd63784d 100644 --- a/cpp/src/qpid/broker/QueuePolicy.h +++ b/cpp/src/qpid/broker/QueuePolicy.h @@ -44,7 +44,7 @@ class QueuePolicy uint64_t size; bool policyExceeded; - static int getInt(const qpid::framing::FieldTable& settings, const std::string& key, int defaultValue); + static uint32_t getCapacity(const qpid::framing::FieldTable& settings, const std::string& key, uint32_t defaultValue); protected: uint64_t getCurrentQueueSize() const { return size; } |
