From d81565fe6ab22a241fb672aa1a32754698dbc4e2 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Sat, 10 Mar 2018 10:31:40 +0100 Subject: [PATCH] fixed that stream operator of address wrote the port number when the default amqps port was used --- include/amqpcpp/address.h | 24 +++++++++++++++++------- src/linux_tcp/sslhandshake.h | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/amqpcpp/address.h b/include/amqpcpp/address.h index 32e00fb..8851954 100644 --- a/include/amqpcpp/address.h +++ b/include/amqpcpp/address.h @@ -27,7 +27,7 @@ private: * The auth method * @var bool */ - bool _secure; + bool _secure = false; /** * Login data (username + password) @@ -52,6 +52,16 @@ private: * @var std::string */ std::string _vhost; + + + /** + * The default port + * @return uint16_t + */ + uint16_t defaultport() const + { + return _secure ? 5671 : 5672; + } public: /** @@ -67,13 +77,13 @@ public: const char *last = data + size; // must start with ampqs:// to have a secure connection (and we also assign a different default port) - _secure = strncmp(data, "amqps://", 8) == 0; - - // default port changes for secure connections - if (_secure) _port = 5671; + if (strncmp(data, "amqps://", 8) == 0) _secure = true; // otherwise protocol must be amqp:// - else if (strncmp(data, "amqp://", 7) != 0) throw std::runtime_error("AMQP address should start with \"amqp://\" or \"amqps://\""); + else if (!strncmp(data, "amqp://", 7) != 0) throw std::runtime_error("AMQP address should start with \"amqp://\" or \"amqps://\""); + + // assign default port (we may overwrite it later) + _port = defaultport(); // begin of the string was parsed data += _secure ? 8 : 7; @@ -307,7 +317,7 @@ public: stream << address._hostname; // do we need a special portnumber? - if (address._port != 5672) stream << ":" << address._port; + if (address._port != address.defaultport()) stream << ":" << address._port; // append default vhost stream << "/"; diff --git a/src/linux_tcp/sslhandshake.h b/src/linux_tcp/sslhandshake.h index 34d379e..caa1b4f 100644 --- a/src/linux_tcp/sslhandshake.h +++ b/src/linux_tcp/sslhandshake.h @@ -74,7 +74,7 @@ private: if (allowed) return new SslConnected(_connection, socket, std::move(_ssl), std::move(_out), _handler); // report that the connection is broken - _handler->onError(_connection, "TLS connection has been blocked by application level checks"); + _handler->onError(_connection, "TLS connection has been rejected"); // the onError method could have destructed this object if (!monitor.valid()) return nullptr;