configs can now hold multiple settings per transport type
This commit is contained in:
parent
807c2bc385
commit
a4658332ff
356
server/guhconfiguration.cpp
Normal file
356
server/guhconfiguration.cpp
Normal file
@ -0,0 +1,356 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2016 Simon Stürz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh. *
|
||||||
|
* *
|
||||||
|
* Guh is free software: you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation, version 2 of the License. *
|
||||||
|
* *
|
||||||
|
* Guh is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "loggingcategories.h"
|
||||||
|
#include "guhconfiguration.h"
|
||||||
|
#include "guhsettings.h"
|
||||||
|
|
||||||
|
#include <QTimeZone>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
|
namespace guhserver {
|
||||||
|
|
||||||
|
GuhConfiguration::GuhConfiguration(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
// Load guhd settings
|
||||||
|
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||||
|
settings.beginGroup("guhd");
|
||||||
|
m_serverName = settings.value("name", "guhIO").toString();
|
||||||
|
m_timeZone = settings.value("timeZone", QTimeZone::systemTimeZoneId()).toByteArray();
|
||||||
|
m_locale = QLocale(settings.value("language", "en_US").toString());
|
||||||
|
m_serverUuid = settings.value("uuid", QUuid()).toUuid();
|
||||||
|
if (m_serverUuid.isNull()) {
|
||||||
|
m_serverUuid = QUuid::createUuid();
|
||||||
|
settings.setValue("uuid", m_serverUuid);
|
||||||
|
}
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
#ifndef TESTING_ENABLED
|
||||||
|
// TcpServer
|
||||||
|
if (settings.childGroups().contains("TcpServer")) {
|
||||||
|
settings.beginGroup("TcpServer");
|
||||||
|
foreach (const QString &key, settings.childGroups()) {
|
||||||
|
qDebug() << "have key" << key;
|
||||||
|
ServerConfiguration config = readServerConfig("TcpServer", key);
|
||||||
|
m_tcpServerConfigs[config.id] = config;
|
||||||
|
}
|
||||||
|
settings.endGroup();
|
||||||
|
} else {
|
||||||
|
qCWarning(dcApplication) << "No TCP Server configuration found. Generating default of 0.0.0.0:2222";
|
||||||
|
ServerConfiguration config;
|
||||||
|
config.id = "default";
|
||||||
|
config.address = QHostAddress("0.0.0.0");
|
||||||
|
config.port = 2222;
|
||||||
|
// TODO enable encryption/authentication by default once the important clients are supporting it
|
||||||
|
config.sslEnabled = false;
|
||||||
|
config.authenticationEnabled = false;
|
||||||
|
m_tcpServerConfigs[config.id] = config;
|
||||||
|
storeServerConfig("TcpServer", config);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Webserver
|
||||||
|
if (settings.childGroups().contains("WebServer")) {
|
||||||
|
settings.beginGroup("WebServer");
|
||||||
|
foreach (const QString &key, settings.childGroups()) {
|
||||||
|
ServerConfiguration tmp = readServerConfig("WebServer", key);
|
||||||
|
WebServerConfiguration config;
|
||||||
|
config.id = tmp.id;
|
||||||
|
config.address = tmp.address;
|
||||||
|
config.port = tmp.port;
|
||||||
|
config.sslEnabled = tmp.sslEnabled;
|
||||||
|
config.authenticationEnabled = tmp.authenticationEnabled;
|
||||||
|
settings.beginGroup(key);
|
||||||
|
config.publicFolder = settings.value("publicFolder").toString();
|
||||||
|
settings.endGroup();
|
||||||
|
m_webServerConfigs[config.id] = config;
|
||||||
|
}
|
||||||
|
settings.endGroup();
|
||||||
|
} else {
|
||||||
|
qCWarning(dcApplication) << "No WebServer configuration found. Generating default of 0.0.0.0:3333";
|
||||||
|
WebServerConfiguration config;
|
||||||
|
config.id = "default";
|
||||||
|
config.address = QHostAddress("0.0.0.0");
|
||||||
|
config.port = 3333;
|
||||||
|
// TODO enable encryption/authentication by default once the important clients are supporting it
|
||||||
|
config.sslEnabled = false;
|
||||||
|
config.authenticationEnabled = false;
|
||||||
|
config.publicFolder = settings.value("publicFolder", "/usr/share/guh-webinterface/public/").toString();
|
||||||
|
#ifdef SNAPPY
|
||||||
|
// Override default public folder path for snappy
|
||||||
|
config.publicFolder = settings.value("publicFolder", QString(qgetenv("SNAP")) + "/guh-webinterface/").toString();
|
||||||
|
#endif
|
||||||
|
m_webServerConfigs[config.id] = config;
|
||||||
|
storeServerConfig("WebServer", config);
|
||||||
|
}
|
||||||
|
|
||||||
|
// WebSocket Server
|
||||||
|
if (settings.childGroups().contains("WebSocketServer")) {
|
||||||
|
settings.beginGroup("WebSocketServer");
|
||||||
|
foreach (const QString &key, settings.childGroups()) {
|
||||||
|
qWarning() << "have key" << key;
|
||||||
|
ServerConfiguration config = readServerConfig("WebSocketServer", key);
|
||||||
|
m_webSocketServerConfigs[config.id] = config;
|
||||||
|
qWarning() << "cound:" << m_webSocketServerConfigs.keys();
|
||||||
|
}
|
||||||
|
settings.endGroup();
|
||||||
|
} else {
|
||||||
|
qCWarning(dcApplication) << "No WebSocketServer configuration found. Generating default of 0.0.0.0:4444";
|
||||||
|
ServerConfiguration config;
|
||||||
|
config.id = "default";
|
||||||
|
config.address = QHostAddress("0.0.0.0");
|
||||||
|
config.port = 4444;
|
||||||
|
// TODO enable encryption/authentication by default once the important clients are supporting it
|
||||||
|
config.sslEnabled = false;
|
||||||
|
config.authenticationEnabled = false;
|
||||||
|
m_webSocketServerConfigs[config.id] = config;
|
||||||
|
storeServerConfig("WebSocketServer", config);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#else
|
||||||
|
ServerConfiguration tcpConfig;
|
||||||
|
tcpConfig.id = "default";
|
||||||
|
tcpConfig.address = QHostAddress("127.0.0.1");
|
||||||
|
tcpConfig.port = 2222;
|
||||||
|
tcpConfig.sslEnabled = true;
|
||||||
|
tcpConfig.authenticationEnabled = true;
|
||||||
|
m_tcpServerConfigs[tcpConfig.id] = tcpConfig;
|
||||||
|
|
||||||
|
WebServerConfiguration wsConfig;
|
||||||
|
wsConfig.id = "default";
|
||||||
|
wsConfig.address = QHostAddress("127.0.0.1");
|
||||||
|
wsConfig.port = 3333;
|
||||||
|
wsConfig.sslEnabled = true;
|
||||||
|
wsConfig.authenticationEnabled = true;
|
||||||
|
wsConfig.publicFolder = qApp->applicationDirPath();
|
||||||
|
m_webServerConfigs[wsConfig.id] = wsConfig;
|
||||||
|
|
||||||
|
ServerConfiguration wssConfig;
|
||||||
|
wssConfig.id = "default";
|
||||||
|
wssConfig.address = QHostAddress("127.0.0.1");
|
||||||
|
wssConfig.port = 4444;
|
||||||
|
wssConfig.sslEnabled = true;
|
||||||
|
wssConfig.authenticationEnabled = true;
|
||||||
|
m_webSocketServerConfigs[wssConfig.id] = wssConfig;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Bluetooth server
|
||||||
|
settings.beginGroup("BluetoothServer");
|
||||||
|
setBluetoothServerEnabled(settings.value("enabled", false).toBool());
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
// SSL configuration
|
||||||
|
settings.beginGroup("SSL");
|
||||||
|
setSslCertificate(settings.value("certificate", "/etc/ssl/certs/guhd-certificate.crt").toString(), settings.value("certificate-key", "/etc/ssl/certs/guhd-certificate.key").toString());
|
||||||
|
settings.endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
QUuid GuhConfiguration::serverUuid() const
|
||||||
|
{
|
||||||
|
return m_serverUuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString GuhConfiguration::serverName() const
|
||||||
|
{
|
||||||
|
return m_serverName;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuhConfiguration::setServerName(const QString &serverName)
|
||||||
|
{
|
||||||
|
qCDebug(dcApplication()) << "Configuration: Server name:" << serverName;
|
||||||
|
|
||||||
|
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||||
|
settings.beginGroup("guhd");
|
||||||
|
settings.setValue("name", serverName);
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
m_serverName = serverName;
|
||||||
|
emit serverNameChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray GuhConfiguration::timeZone() const
|
||||||
|
{
|
||||||
|
return m_timeZone;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuhConfiguration::setTimeZone(const QByteArray &timeZone)
|
||||||
|
{
|
||||||
|
qCDebug(dcApplication()) << "Configuration: Time zone:" << QString::fromUtf8(timeZone);
|
||||||
|
|
||||||
|
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||||
|
settings.beginGroup("guhd");
|
||||||
|
settings.setValue("timeZone", timeZone);
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
m_timeZone = timeZone;
|
||||||
|
emit timeZoneChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
QLocale GuhConfiguration::locale() const
|
||||||
|
{
|
||||||
|
return m_locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuhConfiguration::setLocale(const QLocale &locale)
|
||||||
|
{
|
||||||
|
qCDebug(dcApplication()) << "Configuration: set locale:" << locale.name() << locale.nativeCountryName() << locale.nativeLanguageName();
|
||||||
|
|
||||||
|
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||||
|
settings.beginGroup("guhd");
|
||||||
|
settings.setValue("language", locale.name());
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
m_locale = locale;
|
||||||
|
emit localeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<QString, ServerConfiguration> GuhConfiguration::tcpServerConfigurations() const
|
||||||
|
{
|
||||||
|
return m_tcpServerConfigs;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuhConfiguration::setTcpServerConfiguration(const ServerConfiguration &config)
|
||||||
|
{
|
||||||
|
m_tcpServerConfigs[config.id] = config;
|
||||||
|
storeServerConfig("TcpServer", config);
|
||||||
|
emit tcpServerConfigurationChanged(config.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<QString, WebServerConfiguration> GuhConfiguration::webServerConfigurations() const
|
||||||
|
{
|
||||||
|
return m_webServerConfigs;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuhConfiguration::setWebServerConfiguration(const WebServerConfiguration &config)
|
||||||
|
{
|
||||||
|
m_webServerConfigs[config.id] = config;
|
||||||
|
|
||||||
|
storeServerConfig("WebServer", config);
|
||||||
|
|
||||||
|
// This is a bit odd that we need to open the config once more just for the publicFolder...
|
||||||
|
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||||
|
settings.beginGroup("WebServer");
|
||||||
|
settings.beginGroup(config.id);
|
||||||
|
settings.setValue("publicFolder", config.publicFolder);
|
||||||
|
settings.endGroup();
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
emit webServerConfigurationChanged(config.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<QString, ServerConfiguration> GuhConfiguration::webSocketServerConfigurations() const
|
||||||
|
{
|
||||||
|
return m_webSocketServerConfigs;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuhConfiguration::setWebSocketServerConfiguration(const ServerConfiguration &config)
|
||||||
|
{
|
||||||
|
m_webSocketServerConfigs[config.id] = config;
|
||||||
|
storeServerConfig("WebSocketServer", config);
|
||||||
|
emit webSocketServerConfigurationChanged(config.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GuhConfiguration::bluetoothServerEnabled() const
|
||||||
|
{
|
||||||
|
return m_bluetoothServerEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuhConfiguration::setBluetoothServerEnabled(const bool &enabled)
|
||||||
|
{
|
||||||
|
qCDebug(dcApplication()) << "Configuration: Bluetooth server" << (enabled ? "enabled" : "disabled");
|
||||||
|
|
||||||
|
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||||
|
settings.beginGroup("BluetoothServer");
|
||||||
|
settings.setValue("enabled", enabled);
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
m_bluetoothServerEnabled = enabled;
|
||||||
|
emit bluetoothServerEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString GuhConfiguration::sslCertificate() const
|
||||||
|
{
|
||||||
|
return m_sslCertificate;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString GuhConfiguration::sslCertificateKey() const
|
||||||
|
{
|
||||||
|
return m_sslCertificateKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuhConfiguration::setSslCertificate(const QString &sslCertificate, const QString &sslCertificateKey)
|
||||||
|
{
|
||||||
|
qCDebug(dcApplication()) << "Configuration: SSL certificate:" << sslCertificate << "SSL certificate key:" << sslCertificateKey;
|
||||||
|
|
||||||
|
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||||
|
settings.beginGroup("SSL");
|
||||||
|
settings.setValue("certificate", sslCertificate);
|
||||||
|
settings.setValue("certificate-key", sslCertificateKey);
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
m_sslCertificate = sslCertificate;
|
||||||
|
m_sslCertificateKey = sslCertificateKey;
|
||||||
|
|
||||||
|
emit sslCertificateChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuhConfiguration::setServerUuid(const QUuid &uuid)
|
||||||
|
{
|
||||||
|
qCDebug(dcApplication()) << "Configuration: Server uuid:" << uuid.toString();
|
||||||
|
|
||||||
|
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||||
|
settings.beginGroup("guhd");
|
||||||
|
settings.setValue("uuid", uuid);
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
m_serverUuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuhConfiguration::storeServerConfig(const QString &group, const ServerConfiguration &config)
|
||||||
|
{
|
||||||
|
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||||
|
settings.beginGroup(group);
|
||||||
|
settings.beginGroup(config.id);
|
||||||
|
settings.setValue("address", config.address.toString());
|
||||||
|
settings.setValue("port", config.port);
|
||||||
|
settings.setValue("sslEnabled", config.sslEnabled);
|
||||||
|
settings.setValue("authenticationEnabled", config.authenticationEnabled);
|
||||||
|
settings.endGroup();
|
||||||
|
settings.endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerConfiguration GuhConfiguration::readServerConfig(const QString &group, const QString &id)
|
||||||
|
{
|
||||||
|
ServerConfiguration config;
|
||||||
|
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||||
|
settings.beginGroup(group);
|
||||||
|
settings.beginGroup(id);
|
||||||
|
config.id = id;
|
||||||
|
config.address = QHostAddress(settings.value("address").toString());
|
||||||
|
config.port = settings.value("port").toUInt();
|
||||||
|
config.sslEnabled = settings.value("sslEnabled", true).toBool();
|
||||||
|
config.authenticationEnabled = settings.value("authenticationEnabled", true).toBool();
|
||||||
|
settings.endGroup();
|
||||||
|
settings.endGroup();
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
134
server/guhconfiguration.h
Normal file
134
server/guhconfiguration.h
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2016 Simon Stürz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh. *
|
||||||
|
* *
|
||||||
|
* Guh is free software: you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation, version 2 of the License. *
|
||||||
|
* *
|
||||||
|
* Guh is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef GUHCONFIGURATION_H
|
||||||
|
#define GUHCONFIGURATION_H
|
||||||
|
|
||||||
|
#include <QHostAddress>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QLocale>
|
||||||
|
#include <QUuid>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
namespace guhserver {
|
||||||
|
|
||||||
|
class ServerConfiguration {
|
||||||
|
public:
|
||||||
|
QString id;
|
||||||
|
QHostAddress address;
|
||||||
|
uint port = 0;
|
||||||
|
bool sslEnabled = true;
|
||||||
|
bool authenticationEnabled = true;
|
||||||
|
};
|
||||||
|
class WebServerConfiguration: public ServerConfiguration
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QString publicFolder;
|
||||||
|
};
|
||||||
|
|
||||||
|
class GuhConfiguration : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_ENUMS(ConfigurationError)
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum ConfigurationError {
|
||||||
|
ConfigurationErrorNoError,
|
||||||
|
ConfigurationErrorInvalidTimeZone,
|
||||||
|
ConfigurationErrorInvalidStationName,
|
||||||
|
ConfigurationErrorInvalidPort,
|
||||||
|
ConfigurationErrorInvalidHostAddress,
|
||||||
|
ConfigurationErrorBluetoothHardwareNotAvailable,
|
||||||
|
ConfigurationErrorInvalidCertificate
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit GuhConfiguration(QObject *parent = 0);
|
||||||
|
|
||||||
|
// Global settings
|
||||||
|
QUuid serverUuid() const;
|
||||||
|
|
||||||
|
QString serverName() const;
|
||||||
|
void setServerName(const QString &serverName);
|
||||||
|
|
||||||
|
QByteArray timeZone() const;
|
||||||
|
void setTimeZone(const QByteArray &timeZone);
|
||||||
|
|
||||||
|
QLocale locale() const;
|
||||||
|
void setLocale(const QLocale &locale);
|
||||||
|
|
||||||
|
// TCP server
|
||||||
|
QHash<QString, ServerConfiguration> tcpServerConfigurations() const;
|
||||||
|
void setTcpServerConfiguration(const ServerConfiguration &config);
|
||||||
|
void removeTcpServerConfiguration(const QUuid &id);
|
||||||
|
|
||||||
|
// Web server
|
||||||
|
QHash<QString, WebServerConfiguration> webServerConfigurations() const;
|
||||||
|
void setWebServerConfiguration(const WebServerConfiguration &config);
|
||||||
|
|
||||||
|
// Websocket
|
||||||
|
QHash<QString, ServerConfiguration> webSocketServerConfigurations() const;
|
||||||
|
void setWebSocketServerConfiguration(const ServerConfiguration &config);
|
||||||
|
|
||||||
|
// Bluetooth
|
||||||
|
bool bluetoothServerEnabled() const;
|
||||||
|
void setBluetoothServerEnabled(const bool &enabled);
|
||||||
|
|
||||||
|
QString sslCertificate() const;
|
||||||
|
QString sslCertificateKey() const;
|
||||||
|
void setSslCertificate(const QString &sslCertificate, const QString &sslCertificateKey);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QUuid m_serverUuid;
|
||||||
|
QString m_serverName;
|
||||||
|
QByteArray m_timeZone;
|
||||||
|
QLocale m_locale;
|
||||||
|
|
||||||
|
QHash<QString, ServerConfiguration> m_tcpServerConfigs;
|
||||||
|
QHash<QString, WebServerConfiguration> m_webServerConfigs;
|
||||||
|
QHash<QString, ServerConfiguration> m_webSocketServerConfigs;
|
||||||
|
|
||||||
|
bool m_bluetoothServerEnabled;
|
||||||
|
|
||||||
|
QString m_sslCertificate;
|
||||||
|
QString m_sslCertificateKey;
|
||||||
|
|
||||||
|
void setServerUuid(const QUuid &uuid);
|
||||||
|
void setWebServerPublicFolder(const QString & path);
|
||||||
|
|
||||||
|
void storeServerConfig(const QString &group, const ServerConfiguration &config);
|
||||||
|
ServerConfiguration readServerConfig(const QString &group, const QString &id);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void serverNameChanged();
|
||||||
|
void timeZoneChanged();
|
||||||
|
void localeChanged();
|
||||||
|
|
||||||
|
void tcpServerConfigurationChanged(const QString &configId);
|
||||||
|
void webServerConfigurationChanged(const QString &configId);
|
||||||
|
void webSocketServerConfigurationChanged(const QString &configId);
|
||||||
|
|
||||||
|
void bluetoothServerEnabledChanged();
|
||||||
|
|
||||||
|
void sslCertificateChanged();
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // GUHCONFIGURATION_H
|
||||||
@ -367,18 +367,6 @@ TimeManager *GuhCore::timeManager() const
|
|||||||
return m_timeManager;
|
return m_timeManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Returns a pointer to the \l{WebServer} instance owned by GuhCore.*/
|
|
||||||
WebServer *GuhCore::webServer() const
|
|
||||||
{
|
|
||||||
return m_serverManager->webServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! Returns a pointer to the \l{WebSocketServer} instance owned by GuhCore.*/
|
|
||||||
WebSocketServer *GuhCore::webSocketServer() const
|
|
||||||
{
|
|
||||||
return m_serverManager->webSocketServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! Returns a pointer to the \l{ServerManager} instance owned by GuhCore. */
|
/*! Returns a pointer to the \l{ServerManager} instance owned by GuhCore. */
|
||||||
ServerManager *GuhCore::serverManager() const
|
ServerManager *GuhCore::serverManager() const
|
||||||
{
|
{
|
||||||
@ -409,17 +397,6 @@ UserManager *GuhCore::userManager() const
|
|||||||
return m_userManager;
|
return m_userManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TESTING_ENABLED
|
|
||||||
MockTcpServer
|
|
||||||
#else
|
|
||||||
/*! Returns a pointer to the \l{TcpServer} instance owned by GuhCore. */
|
|
||||||
TcpServer
|
|
||||||
#endif
|
|
||||||
*GuhCore::tcpServer() const
|
|
||||||
{
|
|
||||||
return m_serverManager->tcpServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! Constructs GuhCore with the given \a parent. This is private.
|
/*! Constructs GuhCore with the given \a parent. This is private.
|
||||||
Use \l{GuhCore::instance()} to access the single instance.*/
|
Use \l{GuhCore::instance()} to access the single instance.*/
|
||||||
GuhCore::GuhCore(QObject *parent) :
|
GuhCore::GuhCore(QObject *parent) :
|
||||||
|
|||||||
@ -43,8 +43,6 @@ class Device;
|
|||||||
namespace guhserver {
|
namespace guhserver {
|
||||||
|
|
||||||
class JsonRPCServer;
|
class JsonRPCServer;
|
||||||
class WebSocketServer;
|
|
||||||
class TcpServer;
|
|
||||||
class LogEngine;
|
class LogEngine;
|
||||||
class NetworkManager;
|
class NetworkManager;
|
||||||
|
|
||||||
@ -75,8 +73,6 @@ public:
|
|||||||
DeviceManager *deviceManager() const;
|
DeviceManager *deviceManager() const;
|
||||||
RuleEngine *ruleEngine() const;
|
RuleEngine *ruleEngine() const;
|
||||||
TimeManager *timeManager() const;
|
TimeManager *timeManager() const;
|
||||||
WebServer *webServer() const;
|
|
||||||
WebSocketServer *webSocketServer() const;
|
|
||||||
ServerManager *serverManager() const;
|
ServerManager *serverManager() const;
|
||||||
BluetoothServer *bluetoothServer() const;
|
BluetoothServer *bluetoothServer() const;
|
||||||
NetworkManager *networkManager() const;
|
NetworkManager *networkManager() const;
|
||||||
@ -84,12 +80,6 @@ public:
|
|||||||
|
|
||||||
static QStringList getAvailableLanguages();
|
static QStringList getAvailableLanguages();
|
||||||
|
|
||||||
#ifdef TESTING_ENABLED
|
|
||||||
MockTcpServer *tcpServer() const;
|
|
||||||
#else
|
|
||||||
TcpServer *tcpServer() const;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void pluginConfigChanged(const PluginId &id, const ParamList &config);
|
void pluginConfigChanged(const PluginId &id, const ParamList &config);
|
||||||
void eventTriggered(const Event &event);
|
void eventTriggered(const Event &event);
|
||||||
|
|||||||
@ -204,12 +204,25 @@ JsonReply *ConfigurationHandler::GetConfigurations(const QVariantMap ¶ms) co
|
|||||||
Q_UNUSED(params)
|
Q_UNUSED(params)
|
||||||
QVariantMap returns;
|
QVariantMap returns;
|
||||||
returns.insert("basicConfiguration", JsonTypes::packBasicConfiguration());
|
returns.insert("basicConfiguration", JsonTypes::packBasicConfiguration());
|
||||||
returns.insert("tcpServerConfiguration", JsonTypes::packTcpServerConfiguration());
|
QVariantList tcpServerConfigs;
|
||||||
returns.insert("webServerConfiguration", JsonTypes::packWebServerConfiguration());
|
foreach (const ServerConfiguration &config, GuhCore::instance()->configuration()->tcpServerConfigurations()) {
|
||||||
returns.insert("webSocketServerConfiguration", JsonTypes::packWebSocketServerConfiguration());
|
tcpServerConfigs.append(JsonTypes::packServerConfiguration(config));
|
||||||
QVariantMap sslConfiguration;
|
}
|
||||||
sslConfiguration.insert("enabled", GuhCore::instance()->configuration()->sslEnabled());
|
returns.insert("tcpServerConfigurations", tcpServerConfigs);
|
||||||
returns.insert("sslConfiguration", sslConfiguration);
|
|
||||||
|
QVariantList webServerConfigs;
|
||||||
|
foreach (const WebServerConfiguration &config, GuhCore::instance()->configuration()->webServerConfigurations()) {
|
||||||
|
webServerConfigs.append(JsonTypes::packWebServerConfiguration(config));
|
||||||
|
|
||||||
|
}
|
||||||
|
returns.insert("webServerConfigurations", tcpServerConfigs);
|
||||||
|
|
||||||
|
QVariantList webSocketServerConfigs;
|
||||||
|
foreach (const ServerConfiguration &config, GuhCore::instance()->configuration()->webSocketServerConfigurations()) {
|
||||||
|
tcpServerConfigs.append(JsonTypes::packServerConfiguration(config));
|
||||||
|
}
|
||||||
|
returns.insert("webServerConfigurations", tcpServerConfigs);
|
||||||
|
|
||||||
return createReply(returns);
|
return createReply(returns);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,65 +282,60 @@ JsonReply *ConfigurationHandler::SetLanguage(const QVariantMap ¶ms) const
|
|||||||
|
|
||||||
JsonReply *ConfigurationHandler::SetTcpServerConfiguration(const QVariantMap ¶ms) const
|
JsonReply *ConfigurationHandler::SetTcpServerConfiguration(const QVariantMap ¶ms) const
|
||||||
{
|
{
|
||||||
QHostAddress host = QHostAddress(params.value("host").toString());
|
ServerConfiguration config = JsonTypes::unpackServerConfiguration(params);
|
||||||
if (host.isNull())
|
if (config.address.isNull())
|
||||||
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorInvalidHostAddress));
|
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorInvalidHostAddress));
|
||||||
|
|
||||||
uint port = params.value("port").toUInt();
|
if (config.port <= 0 || config.port > 65535) {
|
||||||
if (port <= 0 || port > 65535) {
|
|
||||||
qCWarning(dcJsonRpc()) << "Port out of range";
|
qCWarning(dcJsonRpc()) << "Port out of range";
|
||||||
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorInvalidPort));
|
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorInvalidPort));
|
||||||
}
|
}
|
||||||
|
|
||||||
qCDebug(dcJsonRpc()) << QString("Configure TCP server %1:%2").arg(host.toString()).arg(port);
|
qCDebug(dcJsonRpc()) << QString("Configure TCP server %1:%2").arg(config.address.toString()).arg(config.port);
|
||||||
|
|
||||||
if (!GuhCore::instance()->tcpServer()->reconfigureServer(host, port))
|
GuhCore::instance()->configuration()->setTcpServerConfiguration(config);
|
||||||
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorInvalidPort));
|
|
||||||
|
|
||||||
GuhCore::instance()->configuration()->setTcpServerConfiguration(port, host);
|
// GuhCore::instance()->tcpServer()->reconfigureServer(config);
|
||||||
|
|
||||||
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorNoError));
|
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorNoError));
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonReply *ConfigurationHandler::SetWebServerConfiguration(const QVariantMap ¶ms) const
|
JsonReply *ConfigurationHandler::SetWebServerConfiguration(const QVariantMap ¶ms) const
|
||||||
{
|
{
|
||||||
QHostAddress host = QHostAddress(params.value("host").toString());
|
WebServerConfiguration config = JsonTypes::unpackWebServerConfiguration(params);
|
||||||
if (host.isNull())
|
|
||||||
|
if (config.address.isNull())
|
||||||
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorInvalidHostAddress));
|
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorInvalidHostAddress));
|
||||||
|
|
||||||
uint port = params.value("port").toUInt();
|
if (config.port <= 0 || config.port > 65535) {
|
||||||
if (port <= 0 || port > 65535) {
|
|
||||||
qCWarning(dcJsonRpc()) << "Port out of range";
|
qCWarning(dcJsonRpc()) << "Port out of range";
|
||||||
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorInvalidPort));
|
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorInvalidPort));
|
||||||
}
|
}
|
||||||
|
|
||||||
qCDebug(dcJsonRpc()) << QString("Configure web server %1:%2").arg(host.toString()).arg(port);
|
qCDebug(dcJsonRpc()) << QString("Configure web server %1:%2").arg(config.address.toString()).arg(config.port);
|
||||||
|
|
||||||
if (!GuhCore::instance()->webServer()->reconfigureServer(host, port))
|
GuhCore::instance()->configuration()->setWebServerConfiguration(config);
|
||||||
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorInvalidPort));
|
// GuhCore::instance()->webServer()->reconfigureServer(config);
|
||||||
|
|
||||||
GuhCore::instance()->configuration()->setWebServerConfiguration(port, host);
|
|
||||||
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorNoError));
|
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorNoError));
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonReply *ConfigurationHandler::SetWebSocketServerConfiguration(const QVariantMap ¶ms) const
|
JsonReply *ConfigurationHandler::SetWebSocketServerConfiguration(const QVariantMap ¶ms) const
|
||||||
{
|
{
|
||||||
QHostAddress host = QHostAddress(params.value("host").toString());
|
ServerConfiguration config = JsonTypes::unpackServerConfiguration(params);
|
||||||
if (host.isNull())
|
if (config.address.isNull())
|
||||||
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorInvalidHostAddress));
|
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorInvalidHostAddress));
|
||||||
|
|
||||||
uint port = params.value("port").toUInt();
|
if (config.port <= 0 || config.port > 65535) {
|
||||||
if (port <= 0 || port > 65535) {
|
|
||||||
qCWarning(dcJsonRpc()) << "Port out of range";
|
qCWarning(dcJsonRpc()) << "Port out of range";
|
||||||
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorInvalidPort));
|
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorInvalidPort));
|
||||||
}
|
}
|
||||||
|
|
||||||
qCDebug(dcJsonRpc()) << QString("Configure web socket server %1:%2").arg(host.toString()).arg(port);
|
qCDebug(dcJsonRpc()) << QString("Configure web socket server %1:%2").arg(config.address.toString()).arg(config.port);
|
||||||
|
|
||||||
if (!GuhCore::instance()->webSocketServer()->reconfigureServer(host, port))
|
GuhCore::instance()->configuration()->setWebSocketServerConfiguration(config);
|
||||||
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorInvalidPort));
|
// GuhCore::instance()->webSocketServer()->reconfigureServer(config);
|
||||||
|
|
||||||
GuhCore::instance()->configuration()->setWebServerConfiguration(port, host);
|
|
||||||
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorNoError));
|
return createReply(statusToReply(GuhConfiguration::ConfigurationErrorNoError));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,27 +347,27 @@ void ConfigurationHandler::onBasicConfigurationChanged()
|
|||||||
emit BasicConfigurationChanged(params);
|
emit BasicConfigurationChanged(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigurationHandler::onTcpServerConfigurationChanged()
|
void ConfigurationHandler::onTcpServerConfigurationChanged(const QString &id)
|
||||||
{
|
{
|
||||||
QVariantMap params;
|
QVariantMap params;
|
||||||
qCDebug(dcJsonRpc()) << "Notification: TCP server configuration changed";
|
qCDebug(dcJsonRpc()) << "Notification: TCP server configuration changed";
|
||||||
params.insert("tcpServerConfiguration", JsonTypes::packTcpServerConfiguration());
|
params.insert("tcpServerConfiguration", JsonTypes::packServerConfiguration(GuhCore::instance()->configuration()->tcpServerConfigurations().value(id)));
|
||||||
emit TcpServerConfigurationChanged(params);
|
emit TcpServerConfigurationChanged(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigurationHandler::onWebServerConfigurationChanged()
|
void ConfigurationHandler::onWebServerConfigurationChanged(const QString &id)
|
||||||
{
|
{
|
||||||
QVariantMap params;
|
QVariantMap params;
|
||||||
qCDebug(dcJsonRpc()) << "Notification: web server configuration changed";
|
qCDebug(dcJsonRpc()) << "Notification: web server configuration changed";
|
||||||
params.insert("webServerConfiguration", JsonTypes::packWebServerConfiguration());
|
params.insert("webServerConfiguration", JsonTypes::packWebServerConfiguration(GuhCore::instance()->configuration()->webServerConfigurations().value(id)));
|
||||||
emit WebServerConfigurationChanged(params);
|
emit WebServerConfigurationChanged(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigurationHandler::onWebSocketServerConfigurationChanged()
|
void ConfigurationHandler::onWebSocketServerConfigurationChanged(const QString &id)
|
||||||
{
|
{
|
||||||
QVariantMap params;
|
QVariantMap params;
|
||||||
qCDebug(dcJsonRpc()) << "Notification: web socket server configuration changed";
|
qCDebug(dcJsonRpc()) << "Notification: web socket server configuration changed";
|
||||||
params.insert("webSocketServerConfiguration", JsonTypes::packWebSocketServerConfiguration());
|
params.insert("webSocketServerConfiguration", JsonTypes::packServerConfiguration(GuhCore::instance()->configuration()->webSocketServerConfigurations().value(id)));
|
||||||
emit WebSocketServerConfigurationChanged(params);
|
emit WebSocketServerConfigurationChanged(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -54,9 +54,9 @@ signals:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onBasicConfigurationChanged();
|
void onBasicConfigurationChanged();
|
||||||
void onTcpServerConfigurationChanged();
|
void onTcpServerConfigurationChanged(const QString &id);
|
||||||
void onWebServerConfigurationChanged();
|
void onWebServerConfigurationChanged(const QString &id);
|
||||||
void onWebSocketServerConfigurationChanged();
|
void onWebSocketServerConfigurationChanged(const QString &id);
|
||||||
void onLanguageChanged();
|
void onLanguageChanged();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1088,32 +1088,23 @@ QVariantMap JsonTypes::packBasicConfiguration()
|
|||||||
return basicConfiguration;
|
return basicConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Returns a variant map with the current tcp configuration of the server. */
|
QVariantMap JsonTypes::packServerConfiguration(const ServerConfiguration &config)
|
||||||
QVariantMap JsonTypes::packTcpServerConfiguration()
|
|
||||||
{
|
{
|
||||||
QVariantMap tcpServerConfiguration;
|
QVariantMap serverConfiguration;
|
||||||
tcpServerConfiguration.insert("host", GuhCore::instance()->configuration()->tcpServerAddress().toString());
|
serverConfiguration.insert("host", config.address.toString());
|
||||||
tcpServerConfiguration.insert("port", GuhCore::instance()->configuration()->tcpServerPort());
|
serverConfiguration.insert("port", config.port);
|
||||||
return tcpServerConfiguration;
|
serverConfiguration.insert("sslEnabled", config.sslEnabled);
|
||||||
|
serverConfiguration.insert("authenticationEnabled", config.authenticationEnabled);
|
||||||
|
return serverConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Returns a variant map with the current web server configuration of the server. */
|
QVariantMap JsonTypes::packWebServerConfiguration(const WebServerConfiguration &config)
|
||||||
QVariantMap JsonTypes::packWebServerConfiguration()
|
|
||||||
{
|
{
|
||||||
QVariantMap webServerConfiguration;
|
QVariantMap webServerConfiguration = packServerConfiguration(config);
|
||||||
webServerConfiguration.insert("host", GuhCore::instance()->configuration()->webServerAddress().toString());
|
webServerConfiguration.insert("publicFolder", config.publicFolder);
|
||||||
webServerConfiguration.insert("port", GuhCore::instance()->configuration()->webServerPort());
|
|
||||||
return webServerConfiguration;
|
return webServerConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Returns a variant map with the current web socket server configuration of the server. */
|
|
||||||
QVariantMap JsonTypes::packWebSocketServerConfiguration()
|
|
||||||
{
|
|
||||||
QVariantMap webSocketServerConfiguration;
|
|
||||||
webSocketServerConfiguration.insert("host", GuhCore::instance()->configuration()->webSocketAddress().toString());
|
|
||||||
webSocketServerConfiguration.insert("port", GuhCore::instance()->configuration()->webSocketPort());
|
|
||||||
return webSocketServerConfiguration;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! Returns a variant list containing all rule descriptions. */
|
/*! Returns a variant list containing all rule descriptions. */
|
||||||
QVariantList JsonTypes::packRuleDescriptions()
|
QVariantList JsonTypes::packRuleDescriptions()
|
||||||
@ -1527,6 +1518,30 @@ TimeDescriptor JsonTypes::unpackTimeDescriptor(const QVariantMap &timeDescriptor
|
|||||||
return timeDescriptor;
|
return timeDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ServerConfiguration JsonTypes::unpackServerConfiguration(const QVariantMap &serverConfigurationMap)
|
||||||
|
{
|
||||||
|
ServerConfiguration serverConfiguration;
|
||||||
|
serverConfiguration.id = serverConfigurationMap.value("id").toString();
|
||||||
|
serverConfiguration.address = QHostAddress(serverConfigurationMap.value("address").toString());
|
||||||
|
serverConfiguration.port = serverConfigurationMap.value("port").toUInt();
|
||||||
|
serverConfiguration.sslEnabled = serverConfigurationMap.value("sslEnabled", true).toBool();
|
||||||
|
serverConfiguration.authenticationEnabled = serverConfigurationMap.value("authenticationEnabled", true).toBool();
|
||||||
|
return serverConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
WebServerConfiguration JsonTypes::unpackWebServerConfiguration(const QVariantMap &webServerConfigurationMap)
|
||||||
|
{
|
||||||
|
ServerConfiguration tmp = unpackServerConfiguration(webServerConfigurationMap);
|
||||||
|
WebServerConfiguration webServerConfiguration;
|
||||||
|
webServerConfiguration.id = tmp.id;
|
||||||
|
webServerConfiguration.address = tmp.address;
|
||||||
|
webServerConfiguration.port = tmp.port;
|
||||||
|
webServerConfiguration.sslEnabled = tmp.sslEnabled;
|
||||||
|
webServerConfiguration.authenticationEnabled = tmp.authenticationEnabled;
|
||||||
|
webServerConfiguration.publicFolder = webServerConfigurationMap.value("publicFolder").toString();
|
||||||
|
return webServerConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
/*! Compairs the given \a map with the given \a templateMap. Returns the error string and false if
|
/*! Compairs the given \a map with the given \a templateMap. Returns the error string and false if
|
||||||
the params are not valid. */
|
the params are not valid. */
|
||||||
QPair<bool, QString> JsonTypes::validateMap(const QVariantMap &templateMap, const QVariantMap &map)
|
QPair<bool, QString> JsonTypes::validateMap(const QVariantMap &templateMap, const QVariantMap &map)
|
||||||
|
|||||||
@ -207,9 +207,8 @@ public:
|
|||||||
static QVariantList packDeviceDescriptors(const QList<DeviceDescriptor> deviceDescriptors);
|
static QVariantList packDeviceDescriptors(const QList<DeviceDescriptor> deviceDescriptors);
|
||||||
|
|
||||||
static QVariantMap packBasicConfiguration();
|
static QVariantMap packBasicConfiguration();
|
||||||
static QVariantMap packTcpServerConfiguration();
|
static QVariantMap packServerConfiguration(const ServerConfiguration &config);
|
||||||
static QVariantMap packWebServerConfiguration();
|
static QVariantMap packWebServerConfiguration(const WebServerConfiguration &config);
|
||||||
static QVariantMap packWebSocketServerConfiguration();
|
|
||||||
|
|
||||||
static QVariantList packRuleDescriptions();
|
static QVariantList packRuleDescriptions();
|
||||||
static QVariantList packRuleDescriptions(const QList<Rule> &rules);
|
static QVariantList packRuleDescriptions(const QList<Rule> &rules);
|
||||||
@ -241,6 +240,9 @@ public:
|
|||||||
static TimeEventItem unpackTimeEventItem(const QVariantMap &timeEventItemMap);
|
static TimeEventItem unpackTimeEventItem(const QVariantMap &timeEventItemMap);
|
||||||
static TimeDescriptor unpackTimeDescriptor(const QVariantMap &timeDescriptorMap);
|
static TimeDescriptor unpackTimeDescriptor(const QVariantMap &timeDescriptorMap);
|
||||||
|
|
||||||
|
static ServerConfiguration unpackServerConfiguration(const QVariantMap &serverConfigurationMap);
|
||||||
|
static WebServerConfiguration unpackWebServerConfiguration(const QVariantMap &webServerConfigurationMap);
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
static QPair<bool, QString> validateMap(const QVariantMap &templateMap, const QVariantMap &map);
|
static QPair<bool, QString> validateMap(const QVariantMap &templateMap, const QVariantMap &map);
|
||||||
static QPair<bool, QString> validateProperty(const QVariant &templateValue, const QVariant &value);
|
static QPair<bool, QString> validateProperty(const QVariant &templateValue, const QVariant &value);
|
||||||
|
|||||||
@ -48,10 +48,10 @@ ServerManager::ServerManager(GuhConfiguration* configuration, QObject *parent) :
|
|||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_sslConfiguration(QSslConfiguration())
|
m_sslConfiguration(QSslConfiguration())
|
||||||
{
|
{
|
||||||
// check SSL
|
// TODO: check this
|
||||||
if (!configuration->sslEnabled()) {
|
|
||||||
qCDebug(dcConnection) << "SSL encryption disabled by config.";
|
|
||||||
} else if (!QSslSocket::supportsSsl()) {
|
if (!QSslSocket::supportsSsl()) {
|
||||||
qCWarning(dcConnection) << "SSL is not supported/installed on this platform.";
|
qCWarning(dcConnection) << "SSL is not supported/installed on this platform.";
|
||||||
} else {
|
} else {
|
||||||
qCDebug(dcConnection) << "SSL library version:" << QSslSocket::sslLibraryVersionString();
|
qCDebug(dcConnection) << "SSL library version:" << QSslSocket::sslLibraryVersionString();
|
||||||
@ -93,23 +93,28 @@ ServerManager::ServerManager(GuhConfiguration* configuration, QObject *parent) :
|
|||||||
|
|
||||||
// Transports
|
// Transports
|
||||||
#ifdef TESTING_ENABLED
|
#ifdef TESTING_ENABLED
|
||||||
m_tcpServer = new MockTcpServer(this);
|
MockTcpServer *tcpServer = new MockTcpServer(this);
|
||||||
|
m_jsonServer->registerTransportInterface(tcpServer);
|
||||||
#else
|
#else
|
||||||
m_tcpServer = new TcpServer(configuration->tcpServerAddress(), configuration->tcpServerPort(), configuration->sslEnabled(), m_sslConfiguration, this);
|
foreach (const ServerConfiguration &config, configuration->tcpServerConfigurations()) {
|
||||||
|
TcpServer *tcpServer = new TcpServer(config.address, config.port, config.sslEnabled, m_sslConfiguration, this);
|
||||||
|
m_jsonServer->registerTransportInterface(tcpServer);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_webSocketServer = new WebSocketServer(configuration->webSocketAddress(), configuration->webSocketPort(), configuration->sslEnabled(), m_sslConfiguration, this);
|
foreach (const ServerConfiguration &config, configuration->webSocketServerConfigurations()) {
|
||||||
|
qWarning() << "Have websockeserver config" << config.id;
|
||||||
|
WebSocketServer *webSocketServer = new WebSocketServer(config.address, config.port, config.sslEnabled, m_sslConfiguration, this);
|
||||||
|
m_jsonServer->registerTransportInterface(webSocketServer);
|
||||||
|
}
|
||||||
|
|
||||||
m_bluetoothServer = new BluetoothServer(this);
|
m_bluetoothServer = new BluetoothServer(this);
|
||||||
|
|
||||||
// Register transport interfaces for the JSON RPC server
|
|
||||||
m_jsonServer->registerTransportInterface(m_tcpServer);
|
|
||||||
m_jsonServer->registerTransportInterface(m_webSocketServer);
|
|
||||||
m_jsonServer->registerTransportInterface(m_bluetoothServer, configuration->bluetoothServerEnabled());
|
m_jsonServer->registerTransportInterface(m_bluetoothServer, configuration->bluetoothServerEnabled());
|
||||||
|
|
||||||
// Register transport itnerfaces for the Webserver
|
foreach (const WebServerConfiguration &config, configuration->webServerConfigurations()) {
|
||||||
m_webServer = new WebServer(configuration->webServerAddress(), configuration->webServerPort(), configuration->webServerPublicFolder(), configuration->sslEnabled(), m_sslConfiguration, this);
|
WebServer *webServer = new WebServer(config.address, config.port, config.publicFolder, config.sslEnabled, m_sslConfiguration, this);
|
||||||
m_restServer->registerWebserver(m_webServer);
|
m_restServer->registerWebserver(webServer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Returns the pointer to the created \l{JsonRPCServer} in this \l{ServerManager}. */
|
/*! Returns the pointer to the created \l{JsonRPCServer} in this \l{ServerManager}. */
|
||||||
@ -124,31 +129,11 @@ RestServer *ServerManager::restServer() const
|
|||||||
return m_restServer;
|
return m_restServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
WebServer *ServerManager::webServer() const
|
|
||||||
{
|
|
||||||
return m_webServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
WebSocketServer *ServerManager::webSocketServer() const
|
|
||||||
{
|
|
||||||
return m_webSocketServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
BluetoothServer *ServerManager::bluetoothServer() const
|
BluetoothServer *ServerManager::bluetoothServer() const
|
||||||
{
|
{
|
||||||
return m_bluetoothServer;
|
return m_bluetoothServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TESTING_ENABLED
|
|
||||||
MockTcpServer
|
|
||||||
#else
|
|
||||||
TcpServer
|
|
||||||
#endif
|
|
||||||
*ServerManager::tcpServer() const
|
|
||||||
{
|
|
||||||
return m_tcpServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ServerManager::loadCertificate(const QString &certificateKeyFileName, const QString &certificateFileName)
|
bool ServerManager::loadCertificate(const QString &certificateKeyFileName, const QString &certificateFileName)
|
||||||
{
|
{
|
||||||
QFile certificateKeyFile(certificateKeyFileName);
|
QFile certificateKeyFile(certificateKeyFileName);
|
||||||
|
|||||||
@ -67,14 +67,6 @@ private:
|
|||||||
JsonRPCServer *m_jsonServer;
|
JsonRPCServer *m_jsonServer;
|
||||||
RestServer *m_restServer;
|
RestServer *m_restServer;
|
||||||
|
|
||||||
// Transports
|
|
||||||
#ifdef TESTING_ENABLED
|
|
||||||
MockTcpServer *m_tcpServer;
|
|
||||||
#else
|
|
||||||
TcpServer *m_tcpServer;
|
|
||||||
#endif
|
|
||||||
WebSocketServer *m_webSocketServer;
|
|
||||||
WebServer *m_webServer;
|
|
||||||
BluetoothServer *m_bluetoothServer;
|
BluetoothServer *m_bluetoothServer;
|
||||||
|
|
||||||
// Encrytption and stuff
|
// Encrytption and stuff
|
||||||
|
|||||||
@ -564,7 +564,6 @@ bool WebServer::startServer()
|
|||||||
#ifndef TESTING_ENABLED
|
#ifndef TESTING_ENABLED
|
||||||
// Note: reversed order
|
// Note: reversed order
|
||||||
QHash<QString, QString> txt;
|
QHash<QString, QString> txt;
|
||||||
txt.insert("sslEnabled", GuhCore::instance()->configuration()->sslEnabled() ? "true" : "false");
|
|
||||||
txt.insert("jsonrpcVersion", JSON_PROTOCOL_VERSION);
|
txt.insert("jsonrpcVersion", JSON_PROTOCOL_VERSION);
|
||||||
txt.insert("serverVersion", GUH_VERSION_STRING);
|
txt.insert("serverVersion", GUH_VERSION_STRING);
|
||||||
txt.insert("manufacturer", "guh GmbH");
|
txt.insert("manufacturer", "guh GmbH");
|
||||||
@ -598,7 +597,11 @@ bool WebServer::stopServer()
|
|||||||
QByteArray WebServer::createServerXmlDocument(QHostAddress address)
|
QByteArray WebServer::createServerXmlDocument(QHostAddress address)
|
||||||
{
|
{
|
||||||
QByteArray uuid = GuhCore::instance()->configuration()->serverUuid().toByteArray();
|
QByteArray uuid = GuhCore::instance()->configuration()->serverUuid().toByteArray();
|
||||||
uint websocketPort = GuhCore::instance()->configuration()->webSocketPort();
|
|
||||||
|
// TODO: support multiple (or none) configured servers here, let's just use the first valid config for now
|
||||||
|
Q_ASSERT_X(GuhCore::instance()->configuration()->webSocketServerConfigurations().count() > 0, "WebServer", "No WebSocket Server config found. This is not supported");
|
||||||
|
|
||||||
|
uint websocketPort = GuhCore::instance()->configuration()->webSocketServerConfigurations().values().first().port;
|
||||||
|
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
QXmlStreamWriter writer(&data);
|
QXmlStreamWriter writer(&data);
|
||||||
|
|||||||
@ -246,7 +246,6 @@ bool WebSocketServer::startServer()
|
|||||||
#ifndef TESTING_ENABLED
|
#ifndef TESTING_ENABLED
|
||||||
// Note: reversed order
|
// Note: reversed order
|
||||||
QHash<QString, QString> txt;
|
QHash<QString, QString> txt;
|
||||||
txt.insert("sslEnabled", GuhCore::instance()->configuration()->sslEnabled() ? "true" : "false");
|
|
||||||
txt.insert("jsonrpcVersion", JSON_PROTOCOL_VERSION);
|
txt.insert("jsonrpcVersion", JSON_PROTOCOL_VERSION);
|
||||||
txt.insert("serverVersion", GUH_VERSION_STRING);
|
txt.insert("serverVersion", GUH_VERSION_STRING);
|
||||||
txt.insert("manufacturer", "guh GmbH");
|
txt.insert("manufacturer", "guh GmbH");
|
||||||
|
|||||||
Reference in New Issue
Block a user