added ampqs:// parsing to address
This commit is contained in:
parent
2fde0eb03d
commit
b9047f5ea7
|
|
@ -6,7 +6,7 @@
|
||||||
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
|
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
|
||||||
* @copyright 2015 Copernica BV
|
* @copyright 2015 Copernica BV
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Include guard
|
* Include guard
|
||||||
*/
|
*/
|
||||||
|
|
@ -23,6 +23,13 @@ namespace AMQP {
|
||||||
class Address
|
class Address
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The auth method
|
||||||
|
* @var std::string
|
||||||
|
*/
|
||||||
|
std::string _authmethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Login data (username + password)
|
* Login data (username + password)
|
||||||
* @var Login
|
* @var Login
|
||||||
|
|
@ -60,8 +67,10 @@ public:
|
||||||
// position of the last byte
|
// position of the last byte
|
||||||
const char *last = data + size;
|
const char *last = data + size;
|
||||||
|
|
||||||
// must start with amqp://
|
// must start with amqp:// or ampqs://
|
||||||
if (size < 7 || strncmp(data, "amqp://", 7) != 0) throw std::runtime_error("AMQP address should start with \"amqp://\"");
|
if (strncmp(data, "amqps://", 8) == 0) _authmethod = std::string("amqps://");
|
||||||
|
else if (strncmp(data, "amqp://", 7) == 0) _authmethod = std::string("amqp://");
|
||||||
|
else throw std::runtime_error("AMQP address should start with \"amqp://\" or \"amqps://\"");
|
||||||
|
|
||||||
// begin of the string was parsed
|
// begin of the string was parsed
|
||||||
data += 7;
|
data += 7;
|
||||||
|
|
@ -115,7 +124,7 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor to parse an address string
|
* Constructor to parse an address string
|
||||||
* The address should start with "amqp://
|
* The address should start with amqp:// or amqps://
|
||||||
* @param data
|
* @param data
|
||||||
* @throws std::runtime_error
|
* @throws std::runtime_error
|
||||||
*/
|
*/
|
||||||
|
|
@ -129,12 +138,14 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor based on already known properties
|
* Constructor based on already known properties
|
||||||
|
* @param authmethod
|
||||||
* @param host
|
* @param host
|
||||||
* @param port
|
* @param port
|
||||||
* @param login
|
* @param login
|
||||||
* @param vhost
|
* @param vhost
|
||||||
*/
|
*/
|
||||||
Address(std::string host, uint16_t port, Login login, std::string vhost) :
|
Address(std::string authmethod, std::string host, uint16_t port, Login login, std::string vhost) :
|
||||||
|
_authmethod(std::move(authmethod)),
|
||||||
_login(std::move(login)),
|
_login(std::move(login)),
|
||||||
_hostname(std::move(host)),
|
_hostname(std::move(host)),
|
||||||
_port(port),
|
_port(port),
|
||||||
|
|
@ -145,6 +156,15 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual ~Address() = default;
|
virtual ~Address() = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expose the login data
|
||||||
|
* @return Login
|
||||||
|
*/
|
||||||
|
const std::string &authmethod() const
|
||||||
|
{
|
||||||
|
return _authmethod;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expose the login data
|
* Expose the login data
|
||||||
* @return Login
|
* @return Login
|
||||||
|
|
@ -183,12 +203,12 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cast to a string
|
* Cast to a string
|
||||||
* @return std:string
|
* @return std::string
|
||||||
*/
|
*/
|
||||||
operator std::string () const
|
operator std::string () const
|
||||||
{
|
{
|
||||||
// result object
|
// result object
|
||||||
std::string str("amqp://");
|
std::string str(_authmethod);
|
||||||
|
|
||||||
// append login
|
// append login
|
||||||
str.append(_login.user()).append(":").append(_login.password()).append("@").append(_hostname);
|
str.append(_login.user()).append(":").append(_login.password()).append("@").append(_hostname);
|
||||||
|
|
@ -213,6 +233,9 @@ public:
|
||||||
*/
|
*/
|
||||||
bool operator==(const Address &that) const
|
bool operator==(const Address &that) const
|
||||||
{
|
{
|
||||||
|
// auth method should match
|
||||||
|
if (_authmethod != that._authmethod) return false;
|
||||||
|
|
||||||
// logins must match
|
// logins must match
|
||||||
if (_login != that._login) return false;
|
if (_login != that._login) return false;
|
||||||
|
|
||||||
|
|
@ -244,6 +267,9 @@ public:
|
||||||
*/
|
*/
|
||||||
bool operator<(const Address &that) const
|
bool operator<(const Address &that) const
|
||||||
{
|
{
|
||||||
|
// compare auth methods
|
||||||
|
if (_authmethod != that._authmethod) return _authmethod < that._authmethod;
|
||||||
|
|
||||||
// compare logins
|
// compare logins
|
||||||
if (_login != that._login) return _login < that._login;
|
if (_login != that._login) return _login < that._login;
|
||||||
|
|
||||||
|
|
@ -269,7 +295,7 @@ public:
|
||||||
friend std::ostream &operator<<(std::ostream &stream, const Address &address)
|
friend std::ostream &operator<<(std::ostream &stream, const Address &address)
|
||||||
{
|
{
|
||||||
// start with the protocol and login
|
// start with the protocol and login
|
||||||
stream << "amqp://" << address._login;
|
stream << address._authmethod << address._login;
|
||||||
|
|
||||||
// do we need a special portnumber?
|
// do we need a special portnumber?
|
||||||
if (address._port != 5672) stream << ":" << address._port;
|
if (address._port != 5672) stream << ":" << address._port;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue