fixed that stream operator of address wrote the port number when the default amqps port was used

This commit is contained in:
Emiel Bruijntjes 2018-03-10 10:31:40 +01:00
parent 1ee18911ce
commit d81565fe6a
2 changed files with 18 additions and 8 deletions

View File

@ -27,7 +27,7 @@ private:
* The auth method * The auth method
* @var bool * @var bool
*/ */
bool _secure; bool _secure = false;
/** /**
* Login data (username + password) * Login data (username + password)
@ -52,6 +52,16 @@ private:
* @var std::string * @var std::string
*/ */
std::string _vhost; std::string _vhost;
/**
* The default port
* @return uint16_t
*/
uint16_t defaultport() const
{
return _secure ? 5671 : 5672;
}
public: public:
/** /**
@ -67,13 +77,13 @@ public:
const char *last = data + size; const char *last = data + size;
// must start with ampqs:// to have a secure connection (and we also assign a different default port) // must start with ampqs:// to have a secure connection (and we also assign a different default port)
_secure = strncmp(data, "amqps://", 8) == 0; if (strncmp(data, "amqps://", 8) == 0) _secure = true;
// default port changes for secure connections
if (_secure) _port = 5671;
// otherwise protocol must be amqp:// // 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 // begin of the string was parsed
data += _secure ? 8 : 7; data += _secure ? 8 : 7;
@ -307,7 +317,7 @@ public:
stream << address._hostname; stream << address._hostname;
// do we need a special portnumber? // do we need a special portnumber?
if (address._port != 5672) stream << ":" << address._port; if (address._port != address.defaultport()) stream << ":" << address._port;
// append default vhost // append default vhost
stream << "/"; stream << "/";

View File

@ -74,7 +74,7 @@ private:
if (allowed) return new SslConnected(_connection, socket, std::move(_ssl), std::move(_out), _handler); if (allowed) return new SslConnected(_connection, socket, std::move(_ssl), std::move(_out), _handler);
// report that the connection is broken // 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 // the onError method could have destructed this object
if (!monitor.valid()) return nullptr; if (!monitor.valid()) return nullptr;