summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2011-03-07 15:59:26 +0000
committerGordon Sim <gsim@apache.org>2011-03-07 15:59:26 +0000
commit8ce4a81a01f849b2642e48a1f59ea0e9463bd5ee (patch)
tree77c722b5244eb7007618d8f538508986bd629f67
parent05442b09a6589e75ba1d992bc31895f7bae76e15 (diff)
downloadqpid-python-8ce4a81a01f849b2642e48a1f59ea0e9463bd5ee.tar.gz
QPID-3015: Merge changes from trunk into release branch for 0.10
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/0.10@1078823 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/cpp/src/qpid/client/ConnectionHandler.cpp48
-rw-r--r--qpid/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp124
-rw-r--r--qpid/doc/book/src/Programming-In-Apache-Qpid.xml41
3 files changed, 101 insertions, 112 deletions
diff --git a/qpid/cpp/src/qpid/client/ConnectionHandler.cpp b/qpid/cpp/src/qpid/client/ConnectionHandler.cpp
index 8dc1e8338a..4fbf55aa60 100644
--- a/qpid/cpp/src/qpid/client/ConnectionHandler.cpp
+++ b/qpid/cpp/src/qpid/client/ConnectionHandler.cpp
@@ -22,6 +22,7 @@
#include "qpid/client/ConnectionHandler.h"
#include "qpid/SaslFactory.h"
+#include "qpid/StringUtils.h"
#include "qpid/client/Bounds.h"
#include "qpid/framing/amqp_framing.h"
#include "qpid/framing/all_method_bodies.h"
@@ -202,6 +203,24 @@ void ConnectionHandler::fail(const std::string& message)
namespace {
std::string SPACE(" ");
+
+std::string join(const std::vector<std::string>& in)
+{
+ std::string result;
+ for (std::vector<std::string>::const_iterator i = in.begin(); i != in.end(); ++i) {
+ if (result.size()) result += SPACE;
+ result += *i;
+ }
+ return result;
+}
+
+void intersection(const std::vector<std::string>& a, const std::vector<std::string>& b, std::vector<std::string>& results)
+{
+ for (std::vector<std::string>::const_iterator i = a.begin(); i != a.end(); ++i) {
+ if (std::find(b.begin(), b.end(), *i) != b.end()) results.push_back(*i);
+ }
+}
+
}
void ConnectionHandler::start(const FieldTable& /*serverProps*/, const Array& mechanisms, const Array& /*locales*/)
@@ -216,25 +235,24 @@ void ConnectionHandler::start(const FieldTable& /*serverProps*/, const Array& me
maxSsf
);
- std::string mechlist;
- bool chosenMechanismSupported = mechanism.empty();
- for (Array::const_iterator i = mechanisms.begin(); i != mechanisms.end(); ++i) {
- if (!mechanism.empty() && mechanism == (*i)->get<std::string>()) {
- chosenMechanismSupported = true;
- mechlist = (*i)->get<std::string>() + SPACE + mechlist;
- } else {
- if (i != mechanisms.begin()) mechlist += SPACE;
- mechlist += (*i)->get<std::string>();
+ std::vector<std::string> mechlist;
+ if (mechanism.empty()) {
+ //mechlist is simply what the server offers
+ mechanisms.collect(mechlist);
+ } else {
+ //mechlist is the intersection of those indicated by user and
+ //those supported by server, in the order listed by user
+ std::vector<std::string> allowed = split(mechanism, " ");
+ std::vector<std::string> supported;
+ mechanisms.collect(supported);
+ intersection(allowed, supported, mechlist);
+ if (mechlist.empty()) {
+ throw Exception(QPID_MSG("Desired mechanism(s) not valid: " << mechanism << " (supported: " << join(supported) << ")"));
}
}
- if (!chosenMechanismSupported) {
- fail("Selected mechanism not supported: " + mechanism);
- }
-
if (sasl.get()) {
- string response = sasl->start(mechanism.empty() ? mechlist : mechanism,
- getSecuritySettings ? getSecuritySettings() : 0);
+ string response = sasl->start(join(mechlist), getSecuritySettings ? getSecuritySettings() : 0);
proxy.startOk(properties, sasl->getMechanism(), response, locale);
} else {
//TODO: verify that desired mechanism and locale are supported
diff --git a/qpid/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp b/qpid/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp
index 5a545c1f6a..a87a8dea67 100644
--- a/qpid/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp
+++ b/qpid/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp
@@ -39,6 +39,7 @@ using qpid::types::Variant;
using qpid::types::VAR_LIST;
using qpid::framing::Uuid;
+namespace {
void convert(const Variant::List& from, std::vector<std::string>& to)
{
for (Variant::List::const_iterator i = from.begin(); i != from.end(); ++i) {
@@ -46,19 +47,6 @@ void convert(const Variant::List& from, std::vector<std::string>& to)
}
}
-template <class T> bool setIfFound(const Variant::Map& map, const std::string& key, T& value)
-{
- Variant::Map::const_iterator i = map.find(key);
- if (i != map.end()) {
- value = (T) i->second;
- QPID_LOG(debug, "option " << key << " specified as " << i->second);
- return true;
- } else {
- return false;
- }
-}
-
-namespace {
std::string asString(const std::vector<std::string>& v) {
std::stringstream os;
os << "[";
@@ -71,47 +59,6 @@ std::string asString(const std::vector<std::string>& v) {
}
}
-template <> bool setIfFound< std::vector<std::string> >(const Variant::Map& map,
- const std::string& key,
- std::vector<std::string>& value)
-{
- Variant::Map::const_iterator i = map.find(key);
- if (i != map.end()) {
- value.clear();
- if (i->second.getType() == VAR_LIST) {
- convert(i->second.asList(), value);
- } else {
- value.push_back(i->second.asString());
- }
- QPID_LOG(debug, "option " << key << " specified as " << asString(value));
- return true;
- } else {
- return false;
- }
-}
-
-void convert(const Variant::Map& from, ConnectionSettings& to)
-{
- setIfFound(from, "username", to.username);
- setIfFound(from, "password", to.password);
- setIfFound(from, "sasl-mechanism", to.mechanism);
- setIfFound(from, "sasl-service", to.service);
- setIfFound(from, "sasl-min-ssf", to.minSsf);
- setIfFound(from, "sasl-max-ssf", to.maxSsf);
-
- setIfFound(from, "heartbeat", to.heartbeat);
- setIfFound(from, "tcp-nodelay", to.tcpNoDelay);
-
- setIfFound(from, "locale", to.locale);
- setIfFound(from, "max-channels", to.maxChannels);
- setIfFound(from, "max-frame-size", to.maxFrameSize);
- setIfFound(from, "bounds", to.bounds);
-
- setIfFound(from, "transport", to.protocol);
-
- setIfFound(from, "ssl-cert-name", to.sslCertName);
-}
-
ConnectionImpl::ConnectionImpl(const std::string& url, const Variant::Map& options) :
reconnect(false), timeout(-1), limit(-1),
minReconnectInterval(3), maxReconnectInterval(60),
@@ -124,27 +71,64 @@ ConnectionImpl::ConnectionImpl(const std::string& url, const Variant::Map& optio
void ConnectionImpl::setOptions(const Variant::Map& options)
{
- sys::Mutex::ScopedLock l(lock);
- convert(options, settings);
- setIfFound(options, "reconnect", reconnect);
- setIfFound(options, "reconnect-timeout", timeout);
- setIfFound(options, "reconnect-limit", limit);
- int64_t reconnectInterval;
- if (setIfFound(options, "reconnect-interval", reconnectInterval)) {
- minReconnectInterval = maxReconnectInterval = reconnectInterval;
- } else {
- setIfFound(options, "reconnect-interval-min", minReconnectInterval);
- setIfFound(options, "reconnect-interval-max", maxReconnectInterval);
+ for (Variant::Map::const_iterator i = options.begin(); i != options.end(); ++i) {
+ setOption(i->first, i->second);
}
- setIfFound(options, "reconnect-urls", urls);
- setIfFound(options, "x-reconnect-on-limit-exceeded", reconnectOnLimitExceeded);
}
void ConnectionImpl::setOption(const std::string& name, const Variant& value)
{
- Variant::Map options;
- options[name] = value;
- setOptions(options);
+ sys::Mutex::ScopedLock l(lock);
+ if (name == "reconnect") {
+ reconnect = value;
+ } else if (name == "reconnect-timeout" || name == "reconnect_timeout") {
+ timeout = value;
+ } else if (name == "reconnect-limit" || name == "reconnect_limit") {
+ limit = value;
+ } else if (name == "reconnect-interval" || name == "reconnect_interval") {
+ maxReconnectInterval = minReconnectInterval = value;
+ } else if (name == "reconnect-interval-min" || name == "reconnect_interval_min") {
+ minReconnectInterval = value;
+ } else if (name == "reconnect-interval-max" || name == "reconnect_interval_max") {
+ maxReconnectInterval = value;
+ } else if (name == "reconnect-urls" || name == "reconnect_urls") {
+ if (value.getType() == VAR_LIST) {
+ convert(value.asList(), urls);
+ } else {
+ urls.push_back(value.asString());
+ }
+ } else if (name == "username") {
+ settings.username = value.asString();
+ } else if (name == "password") {
+ settings.password = value.asString();
+ } else if (name == "sasl-mechanism" || name == "sasl_mechanism" ||
+ name == "sasl-mechanisms" || name == "sasl_mechanisms") {
+ settings.mechanism = value.asString();
+ } else if (name == "sasl-service" || name == "sasl_service") {
+ settings.service = value.asString();
+ } else if (name == "sasl-min-ssf" || name == "sasl_min_ssf") {
+ settings.minSsf = value;
+ } else if (name == "sasl-max-ssf" || name == "sasl_max_ssf") {
+ settings.maxSsf = value;
+ } else if (name == "heartbeat") {
+ settings.heartbeat = value;
+ } else if (name == "tcp-nodelay" || name == "tcp_nodelay") {
+ settings.tcpNoDelay = value;
+ } else if (name == "locale") {
+ settings.locale = value.asString();
+ } else if (name == "max-channels" || name == "max_channels") {
+ settings.maxChannels = value;
+ } else if (name == "max-frame-size" || name == "max_frame_size") {
+ settings.maxFrameSize = value;
+ } else if (name == "bounds") {
+ settings.bounds = value;
+ } else if (name == "transport") {
+ settings.protocol = value.asString();
+ } else if (name == "ssl-cert-name" || name == "ssl_cert_name") {
+ settings.sslCertName = value.asString();
+ } else {
+ throw qpid::messaging::MessagingException(QPID_MSG("Invalid option: " << name << " not recognised"));
+ }
}
diff --git a/qpid/doc/book/src/Programming-In-Apache-Qpid.xml b/qpid/doc/book/src/Programming-In-Apache-Qpid.xml
index 3950b375da..6fae2f0bc7 100644
--- a/qpid/doc/book/src/Programming-In-Apache-Qpid.xml
+++ b/qpid/doc/book/src/Programming-In-Apache-Qpid.xml
@@ -1722,7 +1722,7 @@ try {
<row>
<entry>
- username
+ <literal>username</literal>
</entry>
<entry>
string
@@ -1733,7 +1733,7 @@ try {
</row>
<row>
<entry>
- password
+ <literal>password</literal>
</entry>
<entry>
string
@@ -1744,35 +1744,22 @@ try {
</row>
<row>
<entry>
- sasl-mechanism
+ <literal>sasl_mechanisms</literal>
</entry>
<entry>
string
</entry>
<entry>
- The specific SASL mechanism to use with the c++
- client when authenticating to the broker. Only a
- single value can be specified at present. [C++ only].
- </entry>
- </row>
- <row>
- <entry>
- sasl_mechanisms
- </entry>
- <entry>
- string
- </entry>
- <entry>
- The specific SASL mechanism to use with the python
+ The specific SASL mechanisms to use with the python
client when authenticating to the broker. The value
- is a space separated list in order of preference. [Python only].
+ is a space separated list.
</entry>
</row>
<row>
<entry>
- reconnect
+ <literal>reconnect</literal>
</entry>
<entry>
boolean
@@ -1783,7 +1770,7 @@ try {
</row>
<row>
<entry>
- <literal>reconnect_timeout&nbsp;[Python]</literal> <literal>reconnect-timeout&nbsp;[C++]</literal>
+ <literal>reconnect_timeout</literal>
</entry>
<entry>
integer
@@ -1794,7 +1781,7 @@ try {
</row>
<row>
<entry>
- <literal>reconnect_limit&nbsp;[Python]</literal> <literal>reconnect-limit&nbsp;[C++]</literal>
+ <literal>reconnect_limit</literal>
</entry>
<entry>
integer
@@ -1805,7 +1792,7 @@ try {
</row>
<row>
<entry>
- <literal>reconnect_interval_min&nbsp;[Python]</literal> <literal>reconnect-interval-min&nbsp;[C++]</literal>
+ <literal>reconnect_interval_min</literal>
</entry>
<entry>
integer representing time in seconds
@@ -1816,7 +1803,7 @@ try {
</row>
<row>
<entry>
- <literal>reconnect_interval_max&nbsp;[Python]</literal> <literal>reconnect-interval-max&nbsp;[C++]</literal>
+ <literal>reconnect_interval_max</literal>
</entry>
<entry>
integer representing time in seconds
@@ -1827,7 +1814,7 @@ try {
</row>
<row>
<entry>
- <literal>reconnect_interval&nbsp;[Python]</literal> <literal>reconnect-interval&nbsp;[C++]</literal>
+ <literal>reconnect_interval</literal>
</entry>
<entry>
integer representing time in seconds
@@ -1839,7 +1826,7 @@ try {
<row>
<entry>
- heartbeat
+ <literal>heartbeat</literal>
</entry>
<entry>
integer representing time in seconds
@@ -1852,7 +1839,7 @@ try {
</row>
<row>
<entry>
- protocol
+ <literal>protocol</literal>
</entry>
<entry>
string
@@ -1863,7 +1850,7 @@ try {
</row>
<row>
<entry>
- tcp-nodelay
+ <literal>tcp-nodelay</literal>
</entry>
<entry>
boolean