246e87fea2
Signed-off-by: Aron Budea <aron.budea@collabora.com> Change-Id: Iec477c223f2dc75e0be8b472c8439ca9311d6aae
83 lines
1.8 KiB
C++
83 lines
1.8 KiB
C++
/* -*- 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/.
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#include <ConfigUtil.hpp>
|
|
#include <Util.hpp>
|
|
|
|
#include <cassert>
|
|
#include <string>
|
|
#include <sstream>
|
|
|
|
#include <Poco/Util/AbstractConfiguration.h>
|
|
#include <Poco/Util/XMLConfiguration.h>
|
|
|
|
namespace config
|
|
{
|
|
static Poco::AutoPtr<Poco::Util::XMLConfiguration> XmlConfig;
|
|
static const Poco::Util::AbstractConfiguration* Config{ 0 };
|
|
|
|
void initialize(const Poco::Util::AbstractConfiguration* config)
|
|
{
|
|
assert(!Config && "Config is already initialized.");
|
|
Config = config;
|
|
}
|
|
|
|
void initialize(const std::string& xml)
|
|
{
|
|
std::istringstream iss(xml);
|
|
XmlConfig.reset(new Poco::Util::XMLConfiguration(iss));
|
|
initialize(XmlConfig);
|
|
}
|
|
|
|
bool isInitialized()
|
|
{
|
|
return Config;
|
|
}
|
|
|
|
std::string getString(const std::string& key, const std::string& def)
|
|
{
|
|
assert(Config && "Config is not initialized.");
|
|
return Config ? Config->getString(key, def) : def;
|
|
}
|
|
|
|
bool getBool(const std::string& key, const bool def)
|
|
{
|
|
assert(Config && "Config is not initialized.");
|
|
return Config ? Config->getBool(key, def) : def;
|
|
}
|
|
|
|
bool has(const std::string& key)
|
|
{
|
|
assert(Config && "Config is not initialized.");
|
|
return Config ? Config->has(key) : false;
|
|
}
|
|
|
|
bool isSslEnabled()
|
|
{
|
|
#if ENABLE_SSL
|
|
return !Util::isFuzzing() && getBool("ssl.enable", true);
|
|
#else
|
|
return false;
|
|
#endif
|
|
}
|
|
|
|
bool isSupportKeyEnabled()
|
|
{
|
|
#if ENABLE_SUPPORT_KEY
|
|
return true;
|
|
#else
|
|
return false;
|
|
#endif
|
|
}
|
|
|
|
} // namespace config
|