Skip to content

Commit 4a13ba4

Browse files
committed
Do not store authentication data in std::shared_ptr
1 parent 6b35745 commit 4a13ba4

File tree

7 files changed

+50
-35
lines changed

7 files changed

+50
-35
lines changed

examples/libuv_external.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ int main()
106106
MyHandler handler(loop);
107107

108108
// make a connection
109-
AMQP::TcpConnection connection(&handler, AMQP::Address("amqp://localhost/"), std::make_shared<AMQP::ExternalAuth>());
109+
AMQP::TcpConnection connection(&handler, AMQP::Address("amqp://localhost/"), AMQP::ExternalAuth());
110110

111111
// we need a channel too
112112
AMQP::TcpChannel channel(&connection);

include/amqpcpp/connection.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Connection
2828

2929
public:
3030
/**
31-
* Construct an AMQP object based on full login data
31+
* Construct an AMQP object based on authentication data
3232
*
3333
* The first parameter is a handler object. This handler class is
3434
* an interface that should be implemented by the caller.
@@ -37,35 +37,26 @@ class Connection
3737
* @param auth Authentication data
3838
* @param vhost Vhost to use
3939
*/
40-
Connection(ConnectionHandler *handler, std::shared_ptr<const Authentication> auth, const std::string &vhost) : _implementation(this, handler, std::move(auth), vhost) {}
41-
42-
/**
43-
* Construct an AMQP object based on plain login data
44-
*
45-
* @param handler Connection handler
46-
* @param login Login data
47-
* @param vhost Vhost to use
48-
*/
49-
Connection(ConnectionHandler *handler, const Login &login, const std::string &vhost) : _implementation(this, handler, std::make_shared<Login>(login), vhost) {}
40+
Connection(ConnectionHandler *handler, const Authentication &auth, const std::string &vhost) : _implementation(this, handler, auth, vhost) {}
5041

5142
/**
5243
* Construct with default vhost
5344
* @param handler Connection handler
54-
* @param login Login data
45+
* @param auth Authentication data
5546
*/
56-
Connection(ConnectionHandler *handler, const Login &login) : _implementation(this, handler, std::make_shared<Login>(login), "/") {}
47+
Connection(ConnectionHandler *handler, const Authentication &auth) : _implementation(this, handler, auth, "/") {}
5748

5849
/**
5950
* Construct an AMQP object with default login data and default vhost
6051
* @param handler Connection handler
6152
*/
62-
Connection(ConnectionHandler *handler, const std::string &vhost) : _implementation(this, handler, std::make_shared<Login>(), vhost) {}
53+
Connection(ConnectionHandler *handler, const std::string &vhost) : _implementation(this, handler, Login(), vhost) {}
6354

6455
/**
6556
* Construct an AMQP object with default login data and default vhost
6657
* @param handler Connection handler
6758
*/
68-
Connection(ConnectionHandler *handler) : _implementation(this, handler, std::make_shared<Login>(), "/") {}
59+
Connection(ConnectionHandler *handler) : _implementation(this, handler, Login(), "/") {}
6960

7061
/**
7162
* No copy'ing, we do not support having two identical connection objects
@@ -86,12 +77,21 @@ class Connection
8677
Connection &operator=(const Connection &connection) = delete;
8778

8879
/**
89-
* Retrieve the authentication data
90-
* @return Authentication
80+
* Retrieve the authentication mechanism
81+
* @return string
82+
*/
83+
const std::string &authenticationMechanism() const
84+
{
85+
return _implementation.authenticationMechanism();
86+
}
87+
88+
/**
89+
* Retrieve the authentication response data
90+
* @return string
9191
*/
92-
const Authentication &authentication() const
92+
const std::string &authenticationResponse() const
9393
{
94-
return _implementation.authentication();
94+
return _implementation.authenticationResponse();
9595
}
9696

9797
/**

include/amqpcpp/connectionimpl.h

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,16 @@ class ConnectionImpl : public Watchable
108108
uint32_t _expected = 7;
109109

110110
/**
111-
* The authentication for the server
112-
* @var Authentication
111+
* The authentication mechanism for the server
112+
* @var Authentication mechanism
113113
*/
114-
std::shared_ptr<const Authentication> _auth;
114+
std::string _auth_mechanism;
115+
116+
/**
117+
* The authentication response for the server
118+
* @var Authentication response
119+
*/
120+
std::string _auth_response;
115121

116122
/**
117123
* Vhost to connect to
@@ -166,7 +172,7 @@ class ConnectionImpl : public Watchable
166172
* @param handler Connection handler
167173
* @param auth authentication data
168174
*/
169-
ConnectionImpl(Connection *parent, ConnectionHandler *handler, std::shared_ptr<const Authentication> auth, const std::string &vhost);
175+
ConnectionImpl(Connection *parent, ConnectionHandler *handler, const Authentication& auth, const std::string &vhost);
170176

171177
public:
172178
/**
@@ -274,12 +280,21 @@ class ConnectionImpl : public Watchable
274280
void setReady();
275281

276282
/**
277-
* Retrieve the authentication data
278-
* @return Authentication
283+
* Retrieve the authentication mechanism
284+
* @return string
285+
*/
286+
const std::string &authenticationMechanism() const
287+
{
288+
return _auth_mechanism;
289+
}
290+
291+
/**
292+
* Retrieve the authentication response data
293+
* @return string
279294
*/
280-
const Authentication &authentication() const
295+
const std::string &authenticationResponse() const
281296
{
282-
return *_auth;
297+
return _auth_response;
283298
}
284299

285300
/**

include/amqpcpp/linux_tcp/tcpconnection.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,15 @@ class TcpConnection :
206206
* @param hostname The address to connect to
207207
* @param auth The authentication to use
208208
*/
209-
TcpConnection(TcpHandler *handler, const Address &address, std::shared_ptr<const Authentication> auth);
209+
TcpConnection(TcpHandler *handler, const Address &address, const Authentication& auth);
210210

211211
/**
212212
* Constructor
213213
* @param handler User implemented handler object
214214
* @param hostname The address to connect to
215215
*/
216216
TcpConnection(TcpHandler *handler, const Address &address) :
217-
TcpConnection(handler, address, std::make_shared<Login>(address.login())) {}
217+
TcpConnection(handler, address, address.login()) {}
218218

219219
/**
220220
* No copying

src/connectionimpl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ namespace AMQP {
3131
* @param handler Connection handler
3232
* @param login Login data
3333
*/
34-
ConnectionImpl::ConnectionImpl(Connection *parent, ConnectionHandler *handler, std::shared_ptr<const Authentication> auth, const std::string &vhost) :
35-
_parent(parent), _handler(handler), _auth(std::move(auth)), _vhost(vhost)
34+
ConnectionImpl::ConnectionImpl(Connection *parent, ConnectionHandler *handler, const Authentication& auth, const std::string &vhost) :
35+
_parent(parent), _handler(handler), _auth_mechanism(auth.mechanism()), _auth_response(auth.response()), _vhost(vhost)
3636
{
3737
// we need to send a protocol header
3838
send(ProtocolHeaderFrame());

src/connectionstartframe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class ConnectionStartFrame : public ConnectionFrame
204204
if (!properties.contains("capabilities")) properties["capabilities"] = capabilities;
205205

206206
// send back a connection start ok frame
207-
connection->send(ConnectionStartOKFrame(properties, connection->authentication().mechanism(), connection->authentication().response(), "en_US"));
207+
connection->send(ConnectionStartOKFrame(properties, connection->authenticationMechanism(), connection->authenticationResponse(), "en_US"));
208208

209209
// done
210210
return true;

src/linux_tcp/tcpconnection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ namespace AMQP {
2424
* @param handler User implemented handler object
2525
* @param hostname The address to connect to
2626
*/
27-
TcpConnection::TcpConnection(TcpHandler *handler, const Address &address, std::shared_ptr<const Authentication> auth) :
27+
TcpConnection::TcpConnection(TcpHandler *handler, const Address &address, const Authentication& auth) :
2828
_handler(handler),
2929
_state(new TcpResolver(this, address.hostname(), address.port(), address.secure(), address.option("connectTimeout", 5), ConnectionOrder(address.option("connectionOrder")))),
30-
_connection(this, std::move(auth), address.vhost())
30+
_connection(this, auth, address.vhost())
3131
{
3232
// tell the handler
3333
_handler->onAttached(this);

0 commit comments

Comments
 (0)