2024-02-11 10:42:22 -06:00
|
|
|
/* -*- 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
|
|
|
|
|
2023-02-28 05:34:50 -06:00
|
|
|
#include <RequestVettingStation.hpp>
|
2024-02-11 10:42:22 -06:00
|
|
|
#include <RequestDetails.hpp>
|
|
|
|
#include <Socket.hpp>
|
2024-03-06 07:50:24 -06:00
|
|
|
#if !MOBILEAPP
|
2024-03-05 17:40:47 -06:00
|
|
|
#include <wopi/WopiProxy.hpp>
|
2024-03-06 07:50:24 -06:00
|
|
|
#endif // !MOBILEAPP
|
2024-02-11 10:42:22 -06:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
/// Handles incoming connections and dispatches to the appropriate handler.
|
|
|
|
class ClientRequestDispatcher final : public SimpleSocketHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ClientRequestDispatcher() {}
|
|
|
|
|
|
|
|
static void InitStaticFileContentCache()
|
|
|
|
{
|
|
|
|
StaticFileContentCache["discovery.xml"] = getDiscoveryXML();
|
|
|
|
}
|
|
|
|
|
2024-05-16 03:47:17 -05:00
|
|
|
typedef std::function<void(bool)> AsyncFn;
|
|
|
|
|
2024-02-11 10:42:22 -06:00
|
|
|
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
|
2024-02-20 05:16:39 -06:00
|
|
|
/// Does this address feature in the allowed hosts list.
|
|
|
|
static bool allowPostFrom(const std::string& address);
|
|
|
|
|
2024-05-16 03:47:17 -05:00
|
|
|
static bool allowConvertTo(const std::string& address, const Poco::Net::HTTPRequest& request, AsyncFn asyncCb);
|
2024-02-20 05:16:39 -06:00
|
|
|
|
2024-02-11 10:42:22 -06:00
|
|
|
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();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// The socket that owns us (we can't own it).
|
|
|
|
std::weak_ptr<StreamSocket> _socket;
|
|
|
|
std::string _id;
|
|
|
|
|
2024-03-06 07:50:24 -06:00
|
|
|
#if !MOBILEAPP
|
2024-02-11 10:42:22 -06:00
|
|
|
/// WASM document request handler. Used only when WASM is enabled.
|
|
|
|
std::unique_ptr<WopiProxy> _wopiProxy;
|
2024-03-06 07:50:24 -06:00
|
|
|
#endif // !MOBILEAPP
|
2024-02-11 10:42:22 -06:00
|
|
|
|
2024-01-13 14:33:15 -06:00
|
|
|
/// The private RequestVettingStation. Held privately after the
|
|
|
|
/// WS is created and as long as it is connected.
|
|
|
|
std::shared_ptr<RequestVettingStation> _rvs;
|
|
|
|
|
2023-02-28 05:34:50 -06:00
|
|
|
/// External requests are first vetted before allocating DocBroker and Kit process.
|
|
|
|
/// This is a map of the request URI to the RequestVettingStation for vetting.
|
2024-01-16 05:26:21 -06:00
|
|
|
static std::unordered_map<std::string, std::shared_ptr<RequestVettingStation>>
|
|
|
|
RequestVettingStations;
|
2023-02-28 05:34:50 -06:00
|
|
|
|
2024-02-11 10:42:22 -06:00
|
|
|
/// Cache for static files, to avoid reading and processing from disk.
|
|
|
|
static std::map<std::string, std::string> StaticFileContentCache;
|
2024-01-16 05:26:21 -06:00
|
|
|
};
|