From 9bde3bc63408bfe79c61721cae1435abf99c4a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Obiltschnig?= Date: Sun, 3 Jul 2022 16:09:29 +0200 Subject: [PATCH] merge changes from 1.11.3 --- Redis/include/Poco/Redis/Client.h | 23 +++++++--------- Redis/src/Client.cpp | 45 +++++++++++++++---------------- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/Redis/include/Poco/Redis/Client.h b/Redis/include/Poco/Redis/Client.h index 22e3fe3ce..009cd1899 100644 --- a/Redis/include/Poco/Redis/Client.h +++ b/Redis/include/Poco/Redis/Client.h @@ -87,6 +87,11 @@ public: Client(const Net::SocketAddress& addrs); /// Constructor which connects to the given Redis host/port. + Client(const Net::StreamSocket& socket); + /// Constructor which connects using an existing TCP + /// connection. This can be used to connect via TLS, if the + /// given socket is a Poco::Net::SecureStreamSocket. + virtual ~Client(); /// Destroys the Client. @@ -113,18 +118,17 @@ public: void connect(const Net::SocketAddress& addrs, const Timespan& timeout); /// Connects to the given Redis server. + void connect(const Net::StreamSocket& socket); + /// Connects to the given Redis server using an existing TCP + /// connection. This can be used to connect via TLS, if the + /// given socket is a Poco::Net::SecureStreamSocket. + void disconnect(); /// Disconnects from the Redis server. bool isConnected() const; /// Returns true iff the Client is connected to a Redis server. - bool sendAuth(const std::string& password); - /// Sends password to Redis server - - bool isAuthenticated(); - /// Returns true when the client is authenticated - template T execute(const Array& command) /// Sends the Redis Command to the server. It gets the reply @@ -205,7 +209,6 @@ private: Net::StreamSocket _socket; RedisInputStream* _input; RedisOutputStream* _output; - bool _authenticated = false; }; @@ -240,12 +243,6 @@ inline void Client::setReceiveTimeout(const Timespan& timeout) } -inline bool Client::isAuthenticated() -{ - return _authenticated; -} - - } } // namespace Poco::Redis diff --git a/Redis/src/Client.cpp b/Redis/src/Client.cpp index 9f9fff288..60b97f4e5 100644 --- a/Redis/src/Client.cpp +++ b/Redis/src/Client.cpp @@ -61,6 +61,16 @@ Client::Client(const Net::SocketAddress& addrs): } +Client::Client(const Net::StreamSocket& socket): + _address(), + _socket(), + _input(0), + _output(0) +{ + connect(socket); +} + + Client::~Client() { delete _input; @@ -133,6 +143,18 @@ void Client::connect(const Net::SocketAddress& addrs, const Timespan& timeout) } +void Client::connect(const Poco::Net::StreamSocket& socket) +{ + poco_assert(! _input); + poco_assert(! _output); + + _address = socket.peerAddress(); + _socket = socket; + _input = new RedisInputStream(_socket); + _output = new RedisOutputStream(_socket); +} + + void Client::disconnect() { delete _input; @@ -151,29 +173,6 @@ bool Client::isConnected() const } -bool Client::sendAuth(const std::string& password) -{ - Array cmd; - cmd << "AUTH" << password; - - bool ret = true; - std::string response; - - try - { - response = execute(cmd); - } - catch (...) - { - ret = false; - } - - _authenticated = (ret && (response == "OK")); - - return _authenticated; -} - - void Client::writeCommand(const Array& command, bool doFlush) { poco_assert(_output);