2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* The login information to access a server
|
|
|
|
|
*
|
|
|
|
|
* This class combines login, password and vhost
|
|
|
|
|
*
|
|
|
|
|
* @copyright 2014 Copernica BV
|
|
|
|
|
*/
|
|
|
|
|
|
2015-11-01 17:48:13 +08:00
|
|
|
/**
|
|
|
|
|
* Include guard
|
|
|
|
|
*/
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2016-06-23 20:42:50 +08:00
|
|
|
/**
|
|
|
|
|
* Dependencies
|
|
|
|
|
*/
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Set up namespace
|
|
|
|
|
*/
|
|
|
|
|
namespace AMQP {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class definition
|
|
|
|
|
*/
|
|
|
|
|
class Login
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
/**
|
|
|
|
|
* The username
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
std::string _user;
|
2014-01-04 21:11:06 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* The password
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
std::string _password;
|
2016-06-23 20:42:50 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/**
|
2015-11-01 01:23:24 +08:00
|
|
|
* Default constructor
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2015-11-01 01:23:24 +08:00
|
|
|
Login() : _user("guest"), _password("guest") {}
|
2014-01-27 04:02:23 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Constructor
|
2015-11-01 01:23:24 +08:00
|
|
|
* @param user
|
|
|
|
|
* @param password
|
2014-01-04 19:45:04 +08:00
|
|
|
*/
|
2015-11-01 01:23:24 +08:00
|
|
|
Login(std::string user, std::string password) :
|
|
|
|
|
_user(std::move(user)), _password(std::move(password)) {}
|
|
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* Destructor
|
|
|
|
|
*/
|
|
|
|
|
virtual ~Login() {}
|
2016-06-23 20:42:50 +08:00
|
|
|
|
2014-02-04 22:57:25 +08:00
|
|
|
/**
|
|
|
|
|
* Retrieve the user name
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
const std::string &user() const
|
|
|
|
|
{
|
|
|
|
|
return _user;
|
|
|
|
|
}
|
2016-06-23 20:42:50 +08:00
|
|
|
|
2014-02-04 22:57:25 +08:00
|
|
|
/**
|
|
|
|
|
* Retrieve the password
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
const std::string &password() const
|
|
|
|
|
{
|
|
|
|
|
return _password;
|
|
|
|
|
}
|
2016-06-23 20:42:50 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
/**
|
|
|
|
|
* String representation in SASL PLAIN mode
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2014-08-19 21:00:20 +08:00
|
|
|
std::string saslPlain() const
|
2014-01-04 19:45:04 +08:00
|
|
|
{
|
|
|
|
|
// we need an initial string
|
|
|
|
|
std::string result("\0", 1);
|
2016-06-23 20:42:50 +08:00
|
|
|
|
2014-01-04 19:45:04 +08:00
|
|
|
// append other elements
|
|
|
|
|
return result.append(_user).append("\0",1).append(_password);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* End of namespace
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|