2016-03-21 03:40:10 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
2020-04-18 03:39:50 -05:00
|
|
|
#pragma once
|
2016-03-21 03:40:10 -05:00
|
|
|
|
|
|
|
#include <string>
|
2017-03-16 12:43:33 -05:00
|
|
|
#include "Socket.hpp"
|
2016-03-21 03:40:10 -05:00
|
|
|
|
2017-02-27 21:38:18 -06:00
|
|
|
#include <Poco/MemoryStream.h>
|
2017-02-27 07:28:04 -06:00
|
|
|
|
2020-05-12 10:19:41 -05:00
|
|
|
class RequestDetails;
|
2016-08-13 23:01:13 -05:00
|
|
|
/// Handles file requests over HTTP(S).
|
2017-02-27 07:28:04 -06:00
|
|
|
class FileServerRequestHandler
|
2016-03-21 03:40:10 -05:00
|
|
|
{
|
2020-06-03 11:46:42 -05:00
|
|
|
friend class WhiteBoxTests; // for unit testing
|
|
|
|
|
2017-02-27 07:28:04 -06:00
|
|
|
static std::string getRequestPathname(const Poco::Net::HTTPRequest& request);
|
2016-04-06 13:14:03 -05:00
|
|
|
|
2020-05-12 10:19:41 -05:00
|
|
|
static void preprocessFile(const Poco::Net::HTTPRequest& request,
|
|
|
|
const RequestDetails &requestDetails,
|
|
|
|
Poco::MemoryInputStream& message,
|
2020-01-15 06:34:50 -06:00
|
|
|
const std::shared_ptr<StreamSocket>& socket);
|
2020-05-12 10:19:41 -05:00
|
|
|
static void preprocessAdminFile(const Poco::Net::HTTPRequest& request,
|
|
|
|
const RequestDetails &requestDetails,
|
|
|
|
const std::shared_ptr<StreamSocket>& socket);
|
2020-06-03 11:46:42 -05:00
|
|
|
|
|
|
|
/// Construct a JSON to be accepted by the loleflet.html from a list like
|
|
|
|
/// UIMode=classic;TextRuler=true;PresentationStatusbar=false
|
|
|
|
/// that is passed as "ui_defaults" hidden input during the iframe setup.
|
|
|
|
static std::string uiDefaultsToJSON(const std::string& uiDefaults);
|
|
|
|
|
2016-07-19 12:14:32 -05:00
|
|
|
public:
|
2017-04-10 04:34:51 -05:00
|
|
|
/// Evaluate if the cookie exists, and if not, ask for the credentials.
|
|
|
|
static bool isAdminLoggedIn(const Poco::Net::HTTPRequest& request, Poco::Net::HTTPResponse& response);
|
2016-04-16 11:26:26 -05:00
|
|
|
|
2020-05-12 10:19:41 -05:00
|
|
|
static void handleRequest(const Poco::Net::HTTPRequest& request,
|
|
|
|
const RequestDetails &requestDetails,
|
|
|
|
Poco::MemoryInputStream& message,
|
|
|
|
const std::shared_ptr<StreamSocket>& socket);
|
2017-04-26 08:50:00 -05:00
|
|
|
|
2017-04-27 08:14:31 -05:00
|
|
|
/// Read all files that we can serve into memory and compress them.
|
|
|
|
static void initialize();
|
2017-04-26 08:50:00 -05:00
|
|
|
|
2017-07-02 21:10:23 -05:00
|
|
|
/// Clean cached files.
|
|
|
|
static void uninitialize() { FileHash.clear(); }
|
|
|
|
|
2020-04-14 12:50:04 -05:00
|
|
|
static void readDirToHash(const std::string &basePath, const std::string &path, const std::string &prefix = std::string());
|
2017-04-26 08:50:00 -05:00
|
|
|
|
2017-04-27 08:14:31 -05:00
|
|
|
static const std::string *getCompressedFile(const std::string &path);
|
2017-04-26 08:50:00 -05:00
|
|
|
|
2017-04-27 08:14:31 -05:00
|
|
|
static const std::string *getUncompressedFile(const std::string &path);
|
2017-04-26 08:50:00 -05:00
|
|
|
|
|
|
|
private:
|
2018-07-23 07:37:34 -05:00
|
|
|
static std::map<std::string, std::pair<std::string, std::string>> FileHash;
|
|
|
|
static void sendError(int errorCode, const Poco::Net::HTTPRequest& request,
|
2018-07-31 02:18:52 -05:00
|
|
|
const std::shared_ptr<StreamSocket>& socket, const std::string& shortMessage,
|
|
|
|
const std::string& longMessage, const std::string& extraHeader = "");
|
2016-03-21 03:40:10 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|