mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
even more changes
Signed-off-by: Paulchen-Panther <Paulchen--Panter@gmx.net>
This commit is contained in:
@@ -13,11 +13,9 @@
|
||||
#include <utils/Process.h>
|
||||
#include <utils/jsonschema/QJsonFactory.h>
|
||||
|
||||
CgiHandler::CgiHandler (Hyperion * hyperion, QObject * parent)
|
||||
CgiHandler::CgiHandler (QObject * parent)
|
||||
: QObject(parent)
|
||||
, _hyperion(hyperion)
|
||||
, _args(QStringList())
|
||||
, _hyperionConfig(_hyperion->getQJsonConfig())
|
||||
, _baseUrl()
|
||||
, _log(Logger::getInstance("WEBSERVER"))
|
||||
{
|
||||
@@ -57,11 +55,6 @@ void CgiHandler::cmd_cfg_jsonserver()
|
||||
if ( _args.at(0) == "cfg_jsonserver" )
|
||||
{
|
||||
quint16 jsonPort = 19444;
|
||||
if (_hyperionConfig.contains("jsonServer"))
|
||||
{
|
||||
const QJsonObject jsonConfig = _hyperionConfig["jsonServer"].toObject();
|
||||
jsonPort = jsonConfig["port"].toInt(jsonPort);
|
||||
}
|
||||
|
||||
// send result as reply
|
||||
_reply->addHeader ("Content-Type", "text/plain" );
|
||||
|
@@ -5,7 +5,6 @@
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
#include <hyperion/Hyperion.h>
|
||||
#include <utils/Logger.h>
|
||||
|
||||
#include "QtHttpReply.h"
|
||||
@@ -15,7 +14,7 @@ class CgiHandler : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CgiHandler (Hyperion * hyperion, QObject * parent = NULL);
|
||||
CgiHandler (QObject * parent = NULL);
|
||||
virtual ~CgiHandler (void);
|
||||
|
||||
void setBaseUrl(const QString& url);
|
||||
@@ -26,11 +25,9 @@ public:
|
||||
void cmd_runscript ();
|
||||
|
||||
private:
|
||||
Hyperion* _hyperion;
|
||||
QtHttpReply * _reply;
|
||||
QtHttpRequest * _request;
|
||||
QStringList _args;
|
||||
const QJsonObject & _hyperionConfig;
|
||||
QString _baseUrl;
|
||||
Logger * _log;
|
||||
};
|
||||
|
@@ -19,67 +19,69 @@ class QtHttpReply;
|
||||
class QtHttpClientWrapper;
|
||||
|
||||
class QtHttpServerWrapper : public QTcpServer {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit QtHttpServerWrapper (QObject * parent = Q_NULLPTR);
|
||||
virtual ~QtHttpServerWrapper (void);
|
||||
explicit QtHttpServerWrapper (QObject * parent = Q_NULLPTR);
|
||||
virtual ~QtHttpServerWrapper (void);
|
||||
|
||||
void setUseSecure (const bool ssl = true);
|
||||
void setUseSecure (const bool ssl = true);
|
||||
|
||||
protected:
|
||||
void incomingConnection (qintptr handle) Q_DECL_OVERRIDE;
|
||||
void incomingConnection (qintptr handle) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
bool m_useSsl;
|
||||
bool m_useSsl;
|
||||
};
|
||||
|
||||
class QtHttpServer : public QObject {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit QtHttpServer (QObject * parent = Q_NULLPTR);
|
||||
explicit QtHttpServer (QObject * parent = Q_NULLPTR);
|
||||
|
||||
static const QString & HTTP_VERSION;
|
||||
static const QString & HTTP_VERSION;
|
||||
|
||||
typedef void (QSslSocket::* SslErrorSignal) (const QList<QSslError> &);
|
||||
typedef void (QSslSocket::* SslErrorSignal) (const QList<QSslError> &);
|
||||
|
||||
const QString & getServerName (void) const;
|
||||
const QString & getServerName (void) const;
|
||||
|
||||
quint16 getServerPort (void) const;
|
||||
QString getErrorString (void) const;
|
||||
quint16 getServerPort (void) const;
|
||||
QString getErrorString (void) const;
|
||||
|
||||
// const bool isListening(void) { return m_sockServer->isListening(); };
|
||||
|
||||
public slots:
|
||||
void start (quint16 port = 0);
|
||||
void stop (void);
|
||||
void setServerName (const QString & serverName);
|
||||
void setUseSecure (const bool ssl = true);
|
||||
void setPrivateKey (const QSslKey & key);
|
||||
void setCertificates (const QList<QSslCertificate> & certs);
|
||||
void start (quint16 port = 0);
|
||||
void stop (void);
|
||||
void setServerName (const QString & serverName);
|
||||
void setUseSecure (const bool ssl = true);
|
||||
void setPrivateKey (const QSslKey & key);
|
||||
void setCertificates (const QList<QSslCertificate> & certs);
|
||||
|
||||
signals:
|
||||
void started (quint16 port);
|
||||
void stopped (void);
|
||||
void error (const QString & msg);
|
||||
void clientConnected (const QString & guid);
|
||||
void clientDisconnected (const QString & guid);
|
||||
void requestNeedsReply (QtHttpRequest * request, QtHttpReply * reply);
|
||||
void started (quint16 port);
|
||||
void stopped (void);
|
||||
void error (const QString & msg);
|
||||
void clientConnected (const QString & guid);
|
||||
void clientDisconnected (const QString & guid);
|
||||
void requestNeedsReply (QtHttpRequest * request, QtHttpReply * reply);
|
||||
|
||||
private slots:
|
||||
void onClientConnected (void);
|
||||
void onClientDisconnected (void);
|
||||
void onClientSslEncrypted (void);
|
||||
void onClientSslPeerVerifyError (const QSslError & err);
|
||||
void onClientSslErrors (const QList<QSslError> & errors);
|
||||
void onClientSslModeChanged (QSslSocket::SslMode mode);
|
||||
void onClientConnected (void);
|
||||
void onClientDisconnected (void);
|
||||
void onClientSslEncrypted (void);
|
||||
void onClientSslPeerVerifyError (const QSslError & err);
|
||||
void onClientSslErrors (const QList<QSslError> & errors);
|
||||
void onClientSslModeChanged (QSslSocket::SslMode mode);
|
||||
|
||||
private:
|
||||
bool m_useSsl;
|
||||
QSslKey m_sslKey;
|
||||
QList<QSslCertificate> m_sslCerts;
|
||||
QString m_serverName;
|
||||
QtHttpServerWrapper * m_sockServer;
|
||||
QHash<QTcpSocket *, QtHttpClientWrapper *> m_socksClientsHash;
|
||||
bool m_useSsl;
|
||||
QSslKey m_sslKey;
|
||||
QList<QSslCertificate> m_sslCerts;
|
||||
QString m_serverName;
|
||||
QtHttpServerWrapper * m_sockServer;
|
||||
QHash<QTcpSocket *, QtHttpClientWrapper *> m_socksClientsHash;
|
||||
};
|
||||
|
||||
#endif // QTHTTPSERVER_H
|
||||
|
@@ -10,11 +10,10 @@
|
||||
#include <QResource>
|
||||
#include <exception>
|
||||
|
||||
StaticFileServing::StaticFileServing (Hyperion *hyperion, QObject * parent)
|
||||
StaticFileServing::StaticFileServing (QObject * parent)
|
||||
: QObject (parent)
|
||||
, _hyperion(hyperion)
|
||||
, _baseUrl ()
|
||||
, _cgi(hyperion, this)
|
||||
, _cgi(this)
|
||||
, _log(Logger::getInstance("WEBSERVER"))
|
||||
{
|
||||
Q_INIT_RESOURCE(WebConfig);
|
||||
|
@@ -1,22 +1,23 @@
|
||||
#ifndef STATICFILESERVING_H
|
||||
#define STATICFILESERVING_H
|
||||
|
||||
#include <QMimeDatabase>
|
||||
// locales includes
|
||||
#include "CgiHandler.h"
|
||||
|
||||
//#include "QtHttpServer.h"
|
||||
// qt includes
|
||||
#include <QMimeDatabase>
|
||||
#include "QtHttpRequest.h"
|
||||
#include "QtHttpReply.h"
|
||||
#include "QtHttpHeader.h"
|
||||
#include "CgiHandler.h"
|
||||
|
||||
#include <hyperion/Hyperion.h>
|
||||
//utils includes
|
||||
#include <utils/Logger.h>
|
||||
|
||||
class StaticFileServing : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit StaticFileServing (Hyperion *hyperion, QObject * parent = nullptr);
|
||||
explicit StaticFileServing (QObject * parent = nullptr);
|
||||
virtual ~StaticFileServing (void);
|
||||
|
||||
void setBaseUrl(const QString& url);
|
||||
@@ -25,7 +26,6 @@ public slots:
|
||||
void onRequestNeedsReply (QtHttpRequest * request, QtHttpReply * reply);
|
||||
|
||||
private:
|
||||
Hyperion * _hyperion;
|
||||
QString _baseUrl;
|
||||
QMimeDatabase * _mimeDb;
|
||||
CgiHandler _cgi;
|
||||
|
@@ -1,7 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
// utils includes
|
||||
#include <utils/Logger.h>
|
||||
|
||||
// qt includes
|
||||
#include <QJsonObject>
|
||||
|
||||
class QtHttpServer;
|
||||
class QtHttpRequest;
|
||||
class QtHttpClientWrapper;
|
||||
|
@@ -1,17 +1,21 @@
|
||||
#include "webserver/WebServer.h"
|
||||
#include "StaticFileServing.h"
|
||||
#include "QtHttpServer.h"
|
||||
|
||||
// bonjour
|
||||
// qt includes
|
||||
#include "QtHttpServer.h"
|
||||
#include <QFileInfo>
|
||||
#include <QJsonObject>
|
||||
|
||||
// bonjour includes
|
||||
#include <bonjour/bonjourserviceregister.h>
|
||||
#include <bonjour/bonjourrecord.h>
|
||||
|
||||
#include <QFileInfo>
|
||||
// utils includes
|
||||
#include <utils/NetUtils.h>
|
||||
|
||||
WebServer::WebServer(const QJsonDocument& config, QObject * parent)
|
||||
: QObject(parent)
|
||||
, _log(Logger::getInstance("WEBSERVER"))
|
||||
, _hyperion(Hyperion::getInstance())
|
||||
, _server(new QtHttpServer (this))
|
||||
{
|
||||
_server->setServerName (QStringLiteral ("Hyperion Webserver"));
|
||||
@@ -21,7 +25,7 @@ WebServer::WebServer(const QJsonDocument& config, QObject * parent)
|
||||
connect (_server, &QtHttpServer::error, this, &WebServer::onServerError);
|
||||
|
||||
// create StaticFileServing
|
||||
_staticFileServing = new StaticFileServing (_hyperion, this);
|
||||
_staticFileServing = new StaticFileServing (this);
|
||||
connect(_server, &QtHttpServer::requestNeedsReply, _staticFileServing, &StaticFileServing::onRequestNeedsReply);
|
||||
|
||||
Debug(_log, "Instance created");
|
||||
@@ -38,8 +42,17 @@ void WebServer::onServerStarted (quint16 port)
|
||||
{
|
||||
Info(_log, "Started on port %d name '%s'", port ,_server->getServerName().toStdString().c_str());
|
||||
|
||||
BonjourServiceRegister *bonjourRegister_http = new BonjourServiceRegister();
|
||||
bonjourRegister_http->registerService("_hyperiond-http._tcp", port);
|
||||
if(_serviceRegister == nullptr)
|
||||
{
|
||||
_serviceRegister = new BonjourServiceRegister(this);
|
||||
_serviceRegister->registerService("_hyperiond-http._tcp", port);
|
||||
}
|
||||
else if( _serviceRegister->getPort() != port)
|
||||
{
|
||||
delete _serviceRegister;
|
||||
_serviceRegister = new BonjourServiceRegister(this);
|
||||
_serviceRegister->registerService("_hyperiond-http._tcp", port);
|
||||
}
|
||||
}
|
||||
|
||||
void WebServer::onServerStopped () {
|
||||
@@ -57,10 +70,8 @@ void WebServer::handleSettingsUpdate(const settings::type& type, const QJsonDocu
|
||||
{
|
||||
const QJsonObject& obj = config.object();
|
||||
|
||||
bool webconfigEnable = obj["enable"].toBool(true);
|
||||
_baseUrl = obj["document_root"].toString(WEBSERVER_DEFAULT_PATH);
|
||||
|
||||
|
||||
if ( (_baseUrl != ":/webconfig") && !_baseUrl.trimmed().isEmpty())
|
||||
{
|
||||
QFileInfo info(_baseUrl);
|
||||
@@ -81,10 +92,10 @@ void WebServer::handleSettingsUpdate(const settings::type& type, const QJsonDocu
|
||||
_port = obj["port"].toInt(WEBSERVER_DEFAULT_PORT);
|
||||
stop();
|
||||
}
|
||||
if ( webconfigEnable )
|
||||
{
|
||||
start();
|
||||
}
|
||||
|
||||
// eval if the port is available, will be incremented if not
|
||||
NetUtils::portAvailable(_port, _log);
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,13 +1,18 @@
|
||||
#include "WebSocketClient.h"
|
||||
#include "QtHttpRequest.h"
|
||||
#include "QtHttpHeader.h"
|
||||
|
||||
// hyperion includes
|
||||
#include <hyperion/Hyperion.h>
|
||||
|
||||
// JsonAPI includes
|
||||
#include <api/JsonAPI.h>
|
||||
|
||||
// qt includes
|
||||
#include "QtHttpRequest.h"
|
||||
#include "QtHttpHeader.h"
|
||||
#include <QTcpSocket>
|
||||
#include <QtEndian>
|
||||
#include <QCryptographicHash>
|
||||
#include <QJsonObject>
|
||||
|
||||
WebSocketClient::WebSocketClient(QtHttpRequest* request, QTcpSocket* sock, QObject* parent)
|
||||
: QObject(parent)
|
||||
|
Reference in New Issue
Block a user