wsd: move ClientRequestDispatcher to own file

This moves ClientRequestDispatcher and all
its direct exclusive dependencies to its
own file and adjusts formatting.

No functional changes were performed,
although namespaces were restored and
other minor changes were done for
consistency.

The resulting file is still rather large
at around 2000 lines, but that makes
COOLWSD.cpp smaller by about 30% now.

Change-Id: I59bcd997ad08702ce7029c6791095e75ad9b23b0
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
pull/8348/head
Ashod Nakashian 2024-02-11 11:42:22 -05:00 committed by Ashod Nakashian
parent 5208c93e9b
commit 5a82c36680
9 changed files with 2077 additions and 1915 deletions

View File

@ -136,6 +136,7 @@ coolwsd_sources = common/Crypto.cpp \
wsd/DocumentBroker.cpp \
wsd/ProxyProtocol.cpp \
wsd/COOLWSD.cpp \
wsd/ClientRequestDispatcher.cpp \
wsd/ClientSession.cpp \
wsd/FileServer.cpp \
wsd/ProxyRequestHandler.cpp \
@ -295,6 +296,7 @@ wsd_headers = wsd/Admin.hpp \
wsd/FileServer.hpp \
wsd/ProxyRequestHandler.hpp \
wsd/COOLWSD.hpp \
wsd/ClientRequestDispatcher.hpp \
wsd/ProofKey.hpp \
wsd/RequestDetails.hpp \
wsd/RequestVettingStation.hpp \

View File

@ -26,6 +26,7 @@ add_library(androidapp SHARED
../../../../../wsd/ClientSession.cpp
../../../../../wsd/DocumentBroker.cpp
../../../../../wsd/COOLWSD.cpp
../../../../../wsd/ClientRequestDispatcher.cpp
../../../../../wsd/RequestDetails.cpp
../../../../../wsd/Storage.cpp
../../../../../wsd/TileCache.cpp

View File

@ -42,6 +42,7 @@ net_sources = ../net/FakeSocket.cpp \
wsd_sources = ../wsd/ClientSession.cpp \
../wsd/DocumentBroker.cpp \
../wsd/COOLWSD.cpp \
../wsd/ClientRequestDispatcher.cpp \
../wsd/RequestDetails.cpp \
../wsd/Storage.cpp \
../wsd/TileCache.cpp \

View File

@ -33,6 +33,7 @@
BE5EB5CF213FE2D000E0826C /* ClientSession.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE5EB5CC213FE2D000E0826C /* ClientSession.cpp */; };
BE5EB5D0213FE2D000E0826C /* TileCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE5EB5CD213FE2D000E0826C /* TileCache.cpp */; };
BE5EB5D22140039100E0826C /* COOLWSD.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE5EB5D12140039100E0826C /* COOLWSD.cpp */; };
BE5EB5D22140039100E0826D /* ClientRequestDispatcher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE5EB5D12140039100E0826D /* ClientRequestDispatcher.cpp */; };
BE5EB5D421400DC100E0826C /* DocumentBroker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE5EB5D321400DC100E0826C /* DocumentBroker.cpp */; };
BE5EB5D621401E0F00E0826C /* Storage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE5EB5D521401E0F00E0826C /* Storage.cpp */; };
BE5EB5DA2140363100E0826C /* ios.mm in Sources */ = {isa = PBXBuildFile; fileRef = BE5EB5D92140363100E0826C /* ios.mm */; };
@ -577,6 +578,7 @@
BE5EB5CC213FE2D000E0826C /* ClientSession.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ClientSession.cpp; sourceTree = "<group>"; };
BE5EB5CD213FE2D000E0826C /* TileCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TileCache.cpp; sourceTree = "<group>"; };
BE5EB5D12140039100E0826C /* COOLWSD.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = COOLWSD.cpp; sourceTree = "<group>"; };
BE5EB5D12140039100E0826D /* ClientRequestDispatcher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ClientRequestDispatcher.cpp; sourceTree = "<group>"; };
BE5EB5D321400DC100E0826C /* DocumentBroker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DocumentBroker.cpp; sourceTree = "<group>"; };
BE5EB5D521401E0F00E0826C /* Storage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Storage.cpp; sourceTree = "<group>"; };
BE5EB5D92140363100E0826C /* ios.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ios.mm; path = ../../ios/ios.mm; sourceTree = "<group>"; };
@ -2212,6 +2214,7 @@
BE5EB5D321400DC100E0826C /* DocumentBroker.cpp */,
BE484B71228D8622001EE76C /* DocumentBroker.hpp */,
BE5EB5D12140039100E0826C /* COOLWSD.cpp */,
BE5EB5D12140039100E0826D /* ClientRequestDispatcher.cpp */,
BE5EB5D521401E0F00E0826C /* Storage.cpp */,
BE5EB5CD213FE2D000E0826C /* TileCache.cpp */,
);
@ -3635,6 +3638,7 @@
BE80E45E21B6CEF200859C97 /* TemplateSectionHeaderView.m in Sources */,
BE5EB5C3213FE29900E0826C /* Session.cpp in Sources */,
BE5EB5D22140039100E0826C /* COOLWSD.cpp in Sources */,
BE5EB5D22140039100E0826D /* ClientRequestDispatcher.cpp in Sources */,
BEFB1EE121C29CC70081D757 /* L10n.mm in Sources */,
BEDCC8992456FFAD00FB02BD /* SceneDelegate.mm in Sources */,
BE5EB5C6213FE29900E0826C /* SigUtil.cpp in Sources */,

View File

@ -44,6 +44,7 @@ online_SOURCES = \
../wsd/ClientSession.cpp \
../wsd/DocumentBroker.cpp \
../wsd/COOLWSD.cpp \
../wsd/ClientRequestDispatcher.cpp \
../wsd/RequestDetails.cpp \
../wsd/Storage.cpp \
../wsd/TileCache.cpp \

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,119 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* Copyright the Collabora Online contributors.
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <RequestDetails.hpp>
#include <Socket.hpp>
#include <WopiProxy.hpp>
#include <string>
#include <memory>
class WopiProxy;
/// Handles incoming connections and dispatches to the appropriate handler.
class ClientRequestDispatcher final : public SimpleSocketHandler
{
public:
ClientRequestDispatcher() {}
static void InitStaticFileContentCache()
{
StaticFileContentCache["discovery.xml"] = getDiscoveryXML();
}
/// Does this address feature in the allowed hosts list.
static bool allowPostFrom(const std::string& address);
static bool allowConvertTo(const std::string& address, const Poco::Net::HTTPRequest& request);
private:
/// Set the socket associated with this ResponseClient.
void onConnect(const std::shared_ptr<StreamSocket>& socket) override;
/// Called after successful socket reads.
void handleIncomingMessage(SocketDisposition& disposition) override;
int getPollEvents(std::chrono::steady_clock::time_point /* now */,
int64_t& /* timeoutMaxMs */) override
{
return POLLIN;
}
void performWrites(std::size_t /*capacity*/) override {}
#if !MOBILEAPP
void handleRootRequest(const RequestDetails& requestDetails,
const std::shared_ptr<StreamSocket>& socket);
static void handleFaviconRequest(const RequestDetails& requestDetails,
const std::shared_ptr<StreamSocket>& socket);
void handleWopiDiscoveryRequest(const RequestDetails& requestDetails,
const std::shared_ptr<StreamSocket>& socket);
void handleCapabilitiesRequest(const Poco::Net::HTTPRequest& request,
const std::shared_ptr<StreamSocket>& socket);
static void handleClipboardRequest(const Poco::Net::HTTPRequest& request,
Poco::MemoryInputStream& message,
SocketDisposition& disposition,
const std::shared_ptr<StreamSocket>& socket);
static void handleRobotsTxtRequest(const Poco::Net::HTTPRequest& request,
const std::shared_ptr<StreamSocket>& socket);
static void handleMediaRequest(const Poco::Net::HTTPRequest& request,
SocketDisposition& /*disposition*/,
const std::shared_ptr<StreamSocket>& socket);
static std::string getContentType(const std::string& fileName);
static bool isSpreadsheet(const std::string& fileName);
void handlePostRequest(const RequestDetails& requestDetails,
const Poco::Net::HTTPRequest& request, Poco::MemoryInputStream& message,
SocketDisposition& disposition,
const std::shared_ptr<StreamSocket>& socket);
void handleClientProxyRequest(const Poco::Net::HTTPRequest& request,
const RequestDetails& requestDetails,
Poco::MemoryInputStream& message, SocketDisposition& disposition);
#endif // !MOBILEAPP
void handleClientWsUpgrade(const Poco::Net::HTTPRequest& request,
const RequestDetails& requestDetails, SocketDisposition& disposition,
const std::shared_ptr<StreamSocket>& socket,
unsigned mobileAppDocId = 0);
/// Lookup cached file content.
static const std::string& getFileContent(const std::string& filename);
/// Process the discovery.xml file and return as string.
static std::string getDiscoveryXML();
/// Create the /hosting/capabilities JSON and return as string.
std::string getCapabilitiesJson(const Poco::Net::HTTPRequest& request,
const std::shared_ptr<StreamSocket>& socket);
private:
// The socket that owns us (we can't own it).
std::weak_ptr<StreamSocket> _socket;
std::string _id;
/// WASM document request handler. Used only when WASM is enabled.
std::unique_ptr<WopiProxy> _wopiProxy;
/// Cache for static files, to avoid reading and processing from disk.
static std::map<std::string, std::string> StaticFileContentCache;
};

View File

@ -5,6 +5,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "RequestDetails.hpp"
#include <Storage.hpp>