2015-04-13 04:09:02 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
2015-03-17 18:56:15 -05:00
|
|
|
/*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCLUDED_LOOLWSD_HPP
|
|
|
|
#define INCLUDED_LOOLWSD_HPP
|
|
|
|
|
2015-12-27 21:47:39 -06:00
|
|
|
#include <atomic>
|
2016-12-21 14:37:22 -06:00
|
|
|
#include <map>
|
2016-03-08 01:31:29 -06:00
|
|
|
#include <string>
|
2015-03-17 18:56:15 -05:00
|
|
|
|
2015-07-13 09:13:06 -05:00
|
|
|
#include <Poco/Path.h>
|
2016-01-25 19:07:10 -06:00
|
|
|
#include <Poco/Process.h>
|
2016-03-08 01:31:29 -06:00
|
|
|
#include <Poco/Util/OptionSet.h>
|
|
|
|
#include <Poco/Util/ServerApplication.h>
|
2015-03-17 18:56:15 -05:00
|
|
|
|
2015-12-27 21:47:39 -06:00
|
|
|
#include "Util.hpp"
|
|
|
|
|
2016-08-17 18:57:38 -05:00
|
|
|
class TraceFileWriter;
|
|
|
|
|
2016-08-13 23:01:13 -05:00
|
|
|
/// The Server class which is responsible for all
|
|
|
|
/// external interactions.
|
2016-10-29 20:15:00 -05:00
|
|
|
class LOOLWSD : public Poco::Util::ServerApplication
|
2015-03-17 18:56:15 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
LOOLWSD();
|
|
|
|
~LOOLWSD();
|
|
|
|
|
2016-03-10 21:33:03 -06:00
|
|
|
// An Application is a singleton anyway,
|
|
|
|
// so just keep these as statics.
|
2015-12-27 21:47:39 -06:00
|
|
|
static std::atomic<unsigned> NextSessionId;
|
2016-04-06 22:51:58 -05:00
|
|
|
static unsigned int NumPreSpawnedChildren;
|
2016-08-01 03:05:37 -05:00
|
|
|
static bool NoCapsForKit;
|
2017-01-15 11:57:22 -06:00
|
|
|
static std::atomic<int> ForKitWritePipe;
|
2017-01-15 16:54:55 -06:00
|
|
|
static std::atomic<int> ForKitProcId;
|
2017-02-08 05:34:16 -06:00
|
|
|
static bool DummyLOK;
|
2017-02-07 14:00:23 -06:00
|
|
|
static std::string FuzzFileName;
|
2016-01-15 02:40:54 -06:00
|
|
|
static std::string Cache;
|
2017-01-26 02:19:50 -06:00
|
|
|
static std::string ConfigFile;
|
2016-01-15 02:40:54 -06:00
|
|
|
static std::string SysTemplate;
|
|
|
|
static std::string LoTemplate;
|
|
|
|
static std::string ChildRoot;
|
2016-04-14 04:13:30 -05:00
|
|
|
static std::string ServerName;
|
2016-03-20 09:07:24 -05:00
|
|
|
static std::string FileServerRoot;
|
2016-06-20 13:58:00 -05:00
|
|
|
static std::string LOKitVersion;
|
2016-07-13 21:01:23 -05:00
|
|
|
static std::atomic<unsigned> NumConnections;
|
2016-07-31 12:56:57 -05:00
|
|
|
static std::unique_ptr<TraceFileWriter> TraceDumper;
|
2015-04-08 09:22:42 -05:00
|
|
|
|
2017-03-04 11:33:46 -06:00
|
|
|
/// Flag to shutdown the server.
|
|
|
|
std::atomic<bool> ShutdownFlag;
|
|
|
|
|
|
|
|
bool isShuttingDown()
|
|
|
|
{
|
|
|
|
return ShutdownFlag;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool handleShutdownRequest();
|
|
|
|
|
2016-10-29 20:15:00 -05:00
|
|
|
static std::string GenSessionId()
|
2015-12-27 21:47:39 -06:00
|
|
|
{
|
|
|
|
return Util::encodeId(++NextSessionId, 4);
|
|
|
|
}
|
|
|
|
|
2016-10-29 20:15:00 -05:00
|
|
|
static bool isSSLEnabled()
|
2016-07-18 06:45:36 -05:00
|
|
|
{
|
|
|
|
return LOOLWSD::SSLEnabled.get();
|
|
|
|
}
|
|
|
|
|
2016-10-29 20:15:00 -05:00
|
|
|
static bool isSSLTermination()
|
2016-08-28 14:41:28 -05:00
|
|
|
{
|
|
|
|
return LOOLWSD::SSLTermination.get();
|
|
|
|
}
|
|
|
|
|
2017-02-05 18:35:54 -06:00
|
|
|
/// Trace a new session and take a snapshot of the file.
|
|
|
|
static void dumpNewSessionTrace(const std::string& id, const std::string& sessionId, const std::string& uri, const std::string& path);
|
|
|
|
|
|
|
|
/// Trace the end of a session.
|
|
|
|
static void dumpEndSessionTrace(const std::string& id, const std::string& sessionId, const std::string& uri);
|
|
|
|
|
2017-01-13 06:52:08 -06:00
|
|
|
static void dumpEventTrace(const std::string& id, const std::string& sessionId, const std::string& data);
|
2016-08-02 20:09:01 -05:00
|
|
|
|
2017-01-13 06:52:08 -06:00
|
|
|
static void dumpIncomingTrace(const std::string& id, const std::string& sessionId, const std::string& data);
|
2016-07-30 21:22:28 -05:00
|
|
|
|
2017-01-13 06:52:08 -06:00
|
|
|
static void dumpOutgoingTrace(const std::string& id, const std::string& sessionId, const std::string& data);
|
2016-07-31 06:54:47 -05:00
|
|
|
|
2017-01-15 19:12:10 -06:00
|
|
|
/// Waits on Forkit and reaps if it dies, then restores.
|
|
|
|
/// Return true if wait succeeds.
|
|
|
|
static bool checkAndRestoreForKit();
|
|
|
|
|
2017-01-15 16:54:55 -06:00
|
|
|
/// Creates a new instance of Forkit.
|
|
|
|
/// Return true when successfull.
|
|
|
|
static bool createForKit();
|
|
|
|
|
2015-03-17 18:56:15 -05:00
|
|
|
protected:
|
|
|
|
void initialize(Poco::Util::Application& self) override;
|
|
|
|
void defineOptions(Poco::Util::OptionSet& options) override;
|
|
|
|
void handleOption(const std::string& name, const std::string& value) override;
|
|
|
|
int main(const std::vector<std::string>& args) override;
|
|
|
|
|
|
|
|
private:
|
2016-07-19 04:07:07 -05:00
|
|
|
static Util::RuntimeConstant<bool> SSLEnabled;
|
2016-08-28 14:41:28 -05:00
|
|
|
static Util::RuntimeConstant<bool> SSLTermination;
|
2016-07-18 06:45:36 -05:00
|
|
|
|
2016-03-23 06:08:01 -05:00
|
|
|
void initializeSSL();
|
2015-03-17 18:56:15 -05:00
|
|
|
void displayHelp();
|
2016-04-06 17:17:59 -05:00
|
|
|
|
2016-07-18 06:45:36 -05:00
|
|
|
class ConfigValueGetter
|
|
|
|
{
|
2016-07-28 01:39:03 -05:00
|
|
|
Poco::Util::LayeredConfiguration& _config;
|
|
|
|
const std::string& _name;
|
2016-07-18 06:45:36 -05:00
|
|
|
|
|
|
|
public:
|
|
|
|
ConfigValueGetter(Poco::Util::LayeredConfiguration& config,
|
|
|
|
const std::string& name)
|
2016-07-28 01:39:03 -05:00
|
|
|
: _config(config)
|
|
|
|
, _name(name)
|
2016-10-29 20:15:00 -05:00
|
|
|
{
|
|
|
|
}
|
2016-07-18 06:45:36 -05:00
|
|
|
|
2017-01-28 16:25:14 -06:00
|
|
|
void operator()(int& value) { value = _config.getInt(_name); }
|
2016-07-28 01:39:03 -05:00
|
|
|
void operator()(unsigned int& value) { value = _config.getUInt(_name); }
|
|
|
|
void operator()(bool& value) { value = _config.getBool(_name); }
|
2016-07-30 21:19:31 -05:00
|
|
|
void operator()(std::string& value) { value = _config.getString(_name); }
|
2016-07-18 06:45:36 -05:00
|
|
|
};
|
|
|
|
|
2016-10-29 20:15:00 -05:00
|
|
|
template <typename T>
|
|
|
|
static bool getSafeConfig(Poco::Util::LayeredConfiguration& config,
|
|
|
|
const std::string& name, T& value)
|
2016-06-25 11:31:22 -05:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2016-07-18 06:45:36 -05:00
|
|
|
ConfigValueGetter(config, name)(value);
|
2016-06-25 11:31:22 -05:00
|
|
|
return true;
|
|
|
|
}
|
2016-08-01 02:18:00 -05:00
|
|
|
catch (const Poco::SyntaxException&)
|
2016-06-25 11:31:22 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-18 06:45:36 -05:00
|
|
|
template<typename T>
|
2016-06-25 11:31:22 -05:00
|
|
|
static
|
2016-07-18 06:45:36 -05:00
|
|
|
T getConfigValue(Poco::Util::LayeredConfiguration& config,
|
|
|
|
const std::string& name, const T def)
|
2016-06-25 11:31:22 -05:00
|
|
|
{
|
2016-07-18 06:45:36 -05:00
|
|
|
T value = def;
|
|
|
|
if (getSafeConfig(config, name, value) ||
|
|
|
|
getSafeConfig(config, name + "[@default]", value))
|
2016-06-25 11:31:22 -05:00
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
2016-04-06 17:17:59 -05:00
|
|
|
/// Reads and processes path entries with the given property
|
|
|
|
/// from the configuration.
|
|
|
|
/// Converts relative paths to absolute.
|
|
|
|
std::string getPathFromConfig(const std::string& property) const
|
|
|
|
{
|
|
|
|
auto path = config().getString(property);
|
2016-04-06 22:51:58 -05:00
|
|
|
if (path.empty() && config().hasProperty(property + "[@default]"))
|
|
|
|
{
|
|
|
|
// Use the default value if empty and a default provided.
|
|
|
|
path = config().getString(property + "[@default]");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reconstruct absolute path if relative.
|
2016-06-25 17:03:41 -05:00
|
|
|
if (!Poco::Path(path).isAbsolute() &&
|
|
|
|
config().hasProperty(property + "[@relative]") &&
|
2016-04-06 17:17:59 -05:00
|
|
|
config().getBool(property + "[@relative]"))
|
|
|
|
{
|
|
|
|
path = Poco::Path(Application::instance().commandPath()).parent().append(path).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
2016-06-25 11:31:22 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// Settings passed from the command-line to override those in the config file.
|
|
|
|
std::map<std::string, std::string> _overrideSettings;
|
2015-03-17 18:56:15 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|