killpoco: reduce scope and number of various includes.

Change-Id: Ic3eb409fbb11cc665f0f3a55bb7a4e59cbd28f8b
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
pull/8479/head
Michael Meeks 2024-03-06 16:53:06 +00:00 committed by Ashod Nakashian
parent 5ed9ade9da
commit 0b91bacdc8
6 changed files with 43 additions and 35 deletions

View File

@ -59,7 +59,6 @@
#include <Poco/Exception.h> #include <Poco/Exception.h>
#include <Poco/JSON/Object.h> #include <Poco/JSON/Object.h>
#include <Poco/JSON/Parser.h> #include <Poco/JSON/Parser.h>
#include <Poco/Net/Socket.h>
#include <Poco/URI.h> #include <Poco/URI.h>
#include "ChildSession.hpp" #include "ChildSession.hpp"

View File

@ -34,6 +34,7 @@
#include <Poco/MemoryStream.h> #include <Poco/MemoryStream.h>
#include <Poco/Net/HTTPRequest.h> #include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPResponse.h> #include <Poco/Net/HTTPResponse.h>
#include <Poco/Net/WebSocket.h> // computeAccept
#include <Poco/URI.h> #include <Poco/URI.h>
#if ENABLE_SSL #if ENABLE_SSL
#include <Poco/Net/X509Certificate.h> #include <Poco/Net/X509Certificate.h>
@ -1315,6 +1316,30 @@ bool StreamSocket::sniffSSL() const
#endif // !MOBILEAPP #endif // !MOBILEAPP
namespace {
/// To make the protected 'computeAccept' accessible.
class PublicComputeAccept final : public Poco::Net::WebSocket
{
public:
static std::string doComputeAccept(const std::string &key)
{
return computeAccept(key);
}
static std::string generateKey() { return createKey(); }
};
}
std::string WebSocketHandler::computeAccept(const std::string &key)
{
return PublicComputeAccept::doComputeAccept(key);
}
std::string WebSocketHandler::generateKey()
{
return PublicComputeAccept::generateKey();
}
// Required by Android and iOS apps. // Required by Android and iOS apps.
namespace http namespace http
{ {

View File

@ -19,10 +19,7 @@
#include "Socket.hpp" #include "Socket.hpp"
#include <net/HttpRequest.hpp> #include <net/HttpRequest.hpp>
#include <Poco/MemoryStream.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPResponse.h> #include <Poco/Net/HTTPResponse.h>
#include <Poco/Net/WebSocket.h>
#include <chrono> #include <chrono>
#include <memory> #include <memory>
@ -79,7 +76,7 @@ public:
, _pingTimeUs(0) , _pingTimeUs(0)
, _isMasking(isClient && isMasking) , _isMasking(isClient && isMasking)
, _inFragmentBlock(false) , _inFragmentBlock(false)
, _key(isClient ? PublicComputeAccept::generateKey() : std::string()) , _key(isClient ? generateKey() : std::string())
, _lastFlags(0) , _lastFlags(0)
, ,
#endif #endif
@ -931,17 +928,8 @@ protected:
/// Implementation of the ProtocolHandlerInterface. /// Implementation of the ProtocolHandlerInterface.
void dumpState(std::ostream& os) const override; void dumpState(std::ostream& os) const override;
/// To make the protected 'computeAccept' accessible. static std::string generateKey();
class PublicComputeAccept final : public Poco::Net::WebSocket static std::string computeAccept(const std::string &key);
{
public:
static std::string doComputeAccept(const std::string &key)
{
return computeAccept(key);
}
static std::string generateKey() { return createKey(); }
};
/// Upgrade the http(s) connection to a websocket. /// Upgrade the http(s) connection to a websocket.
template <typename T> template <typename T>
@ -969,7 +957,7 @@ protected:
http::Response httpResponse(http::StatusCode::SwitchingProtocols, socket->getFD()); http::Response httpResponse(http::StatusCode::SwitchingProtocols, socket->getFD());
httpResponse.set("Upgrade", "websocket"); httpResponse.set("Upgrade", "websocket");
httpResponse.set("Connection", "Upgrade"); httpResponse.set("Connection", "Upgrade");
httpResponse.set("Sec-WebSocket-Accept", PublicComputeAccept::doComputeAccept(wsKey)); httpResponse.set("Sec-WebSocket-Accept", computeAccept(wsKey));
LOG_TRC("Sending WS Upgrade response: " << httpResponse.header().toString()); LOG_TRC("Sending WS Upgrade response: " << httpResponse.header().toString());
socket->send(httpResponse); socket->send(httpResponse);
#else #else
@ -997,8 +985,7 @@ protected:
if (response.statusLine().statusCode() == http::StatusCode::SwitchingProtocols && if (response.statusLine().statusCode() == http::StatusCode::SwitchingProtocols &&
Util::iequal(response.get("Upgrade"), "websocket") && Util::iequal(response.get("Upgrade"), "websocket") &&
Util::iequal(response.get("Connection", ""), "Upgrade") && Util::iequal(response.get("Connection", ""), "Upgrade") &&
response.get("Sec-WebSocket-Accept", "") == response.get("Sec-WebSocket-Accept", "") == computeAccept(_key))
PublicComputeAccept::doComputeAccept(_key))
{ {
LOG_TRC("Accepted incoming websocket response"); LOG_TRC("Accepted incoming websocket response");
setWebSocket(socket); setWebSocket(socket);

View File

@ -14,6 +14,7 @@
#include <helpers.hpp> #include <helpers.hpp>
#include <Poco/Util/Application.h> #include <Poco/Util/Application.h>
#include <Poco/Net/StreamSocket.h> #include <Poco/Net/StreamSocket.h>
#include <Poco/Net/SecureStreamSocket.h>
#include <Poco/Net/StringPartSource.h> #include <Poco/Net/StringPartSource.h>
#include <Poco/Net/HTMLForm.h> #include <Poco/Net/HTMLForm.h>
#include <Poco/Net/HTTPRequest.h> #include <Poco/Net/HTTPRequest.h>
@ -115,11 +116,22 @@ public:
return true; return true;
} }
inline std::shared_ptr<Poco::Net::StreamSocket> createRawSocket()
{
return
#if ENABLE_SSL
std::make_shared<Poco::Net::SecureStreamSocket>
#else
std::make_shared<Poco::Net::StreamSocket>
#endif
(Poco::Net::SocketAddress("127.0.0.1", ClientPortNumber));
}
void testChunks() void testChunks()
{ {
LOG_TST("testChunks"); LOG_TST("testChunks");
std::shared_ptr<Poco::Net::StreamSocket> socket = helpers::createRawSocket(); std::shared_ptr<Poco::Net::StreamSocket> socket = createRawSocket();
writeString( writeString(
socket, socket,

View File

@ -17,7 +17,6 @@
#include <WopiTestServer.hpp> #include <WopiTestServer.hpp>
#include <wsd/DocumentBroker.hpp> #include <wsd/DocumentBroker.hpp>
#include <wsd/Admin.hpp>
#include <Poco/Net/HTTPRequest.h> #include <Poco/Net/HTTPRequest.h>

View File

@ -24,9 +24,6 @@
#include <Poco/Net/HTTPResponse.h> #include <Poco/Net/HTTPResponse.h>
#include <Poco/Net/HTTPSClientSession.h> #include <Poco/Net/HTTPSClientSession.h>
#include <Poco/Net/NetException.h> #include <Poco/Net/NetException.h>
#include <Poco/Net/StreamSocket.h>
#include <Poco/Net/SecureStreamSocket.h>
#include <Poco/Net/Socket.h>
#include <Poco/Path.h> #include <Poco/Path.h>
#include <Poco/URI.h> #include <Poco/URI.h>
@ -302,17 +299,6 @@ pocoGet(bool secure, const std::string& host, const int port, const std::string&
return pocoGet(uri); return pocoGet(uri);
} }
inline std::shared_ptr<Poco::Net::StreamSocket> createRawSocket()
{
return
#if ENABLE_SSL
std::make_shared<Poco::Net::SecureStreamSocket>
#else
std::make_shared<Poco::Net::StreamSocket>
#endif
(Poco::Net::SocketAddress("127.0.0.1", ClientPortNumber));
}
// Sets read / write timeout for the given file descriptor. // Sets read / write timeout for the given file descriptor.
inline void setSocketTimeOut(int socketFD, int timeMS) inline void setSocketTimeOut(int socketFD, int timeMS)
{ {