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 file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
2016-04-08 03:08:41 -05:00
|
|
|
#ifndef INCLUDED_FILESERVER_HPP
|
|
|
|
#define INCLUDED_FILESERVER_HPP
|
2016-03-21 03:40:10 -05:00
|
|
|
|
2016-04-20 05:50:14 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
2016-03-21 03:40:10 -05:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <Poco/Net/HTTPRequest.h>
|
|
|
|
#include <Poco/Net/HTTPRequestHandler.h>
|
|
|
|
#include <Poco/Net/HTTPServer.h>
|
|
|
|
#include <Poco/Net/HTTPServerRequest.h>
|
|
|
|
#include <Poco/Net/HTTPServerResponse.h>
|
|
|
|
#include <Poco/Net/SecureServerSocket.h>
|
|
|
|
|
2016-07-19 12:14:32 -05:00
|
|
|
#include "Log.hpp"
|
2016-03-21 03:40:10 -05:00
|
|
|
|
2016-08-13 23:01:13 -05:00
|
|
|
/// Handles file requests over HTTP(S).
|
2016-10-29 20:15:00 -05:00
|
|
|
class FileServerRequestHandler : public Poco::Net::HTTPRequestHandler
|
2016-03-21 03:40:10 -05:00
|
|
|
{
|
2016-07-19 12:14:32 -05:00
|
|
|
std::string getRequestPathname(const Poco::Net::HTTPServerRequest& request);
|
2016-04-06 13:14:03 -05:00
|
|
|
|
2016-07-19 12:14:32 -05:00
|
|
|
void preprocessFile(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response) throw(Poco::FileAccessDeniedException);
|
2016-04-06 13:14:03 -05:00
|
|
|
|
2016-07-19 12:14:32 -05:00
|
|
|
public:
|
|
|
|
/// Evaluate if the cookie exists, and if not, ask for the credentials.
|
|
|
|
static bool isAdminLoggedIn(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response);
|
2016-04-16 11:26:26 -05:00
|
|
|
|
2016-07-19 12:14:32 -05:00
|
|
|
void handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response) override;
|
2016-03-21 03:40:10 -05:00
|
|
|
};
|
|
|
|
|
2016-08-13 23:01:13 -05:00
|
|
|
/// Singleton class to serve files over HTTP(S).
|
2016-03-21 03:40:10 -05:00
|
|
|
class FileServer
|
|
|
|
{
|
|
|
|
public:
|
2016-07-28 03:24:25 -05:00
|
|
|
static FileServer& instance()
|
2016-03-21 03:40:10 -05:00
|
|
|
{
|
2016-07-28 03:24:25 -05:00
|
|
|
static FileServer fileServer;
|
|
|
|
return fileServer;
|
2016-03-21 03:40:10 -05:00
|
|
|
}
|
|
|
|
|
2016-07-28 03:24:25 -05:00
|
|
|
static FileServerRequestHandler* createRequestHandler()
|
2016-03-21 03:40:10 -05:00
|
|
|
{
|
|
|
|
return new FileServerRequestHandler();
|
|
|
|
}
|
2016-07-28 03:24:25 -05:00
|
|
|
|
|
|
|
FileServer(FileServer const&) = delete;
|
|
|
|
void operator=(FileServer const&) = delete;
|
|
|
|
|
|
|
|
private:
|
|
|
|
FileServer();
|
2016-03-21 03:40:10 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|