Hyperiond refactoring + preparation for ip restriction settings (#12)

* make hyperion to singelton.
remove arguments for config and hyperion - both are gettable via Hyperion::getInstance

* refactor hyperiond

* remove qt4 comapt
make zeroconf mandatory
refactor hyperiond

* xbmcchecker is now a singleton

* cleanup in hyperiond
zeroconf switchable between static and shared linking

* fix xbmcchecker

* extensive refactoring of hyperiond
webserver: make client ip information availabel in request object - preparation for ip filters
proto/json server, use hyperion::getInstance instead of hyperion argument

* move creation of hyperion core into hyperionDeamon class
cleanup
This commit is contained in:
redPanther
2016-06-19 00:56:47 +02:00
committed by brindosch
parent 0e5607db65
commit 4533b34606
14 changed files with 261 additions and 226 deletions

View File

@@ -5,9 +5,9 @@
#include <jsonserver/JsonServer.h>
#include "JsonClientConnection.h"
JsonServer::JsonServer(Hyperion *hyperion, uint16_t port) :
JsonServer::JsonServer(uint16_t port) :
QObject(),
_hyperion(hyperion),
_hyperion(Hyperion::getInstance()),
_server(),
_openConnections()
{

View File

@@ -7,14 +7,14 @@
#include "protoserver/ProtoConnection.h"
#include "ProtoClientConnection.h"
ProtoServer::ProtoServer(Hyperion *hyperion, uint16_t port) :
ProtoServer::ProtoServer(uint16_t port) :
QObject(),
_hyperion(hyperion),
_hyperion(Hyperion::getInstance()),
_server(),
_openConnections()
{
MessageForwarder * forwarder = hyperion->getForwarder();
MessageForwarder * forwarder = _hyperion->getForwarder();
QStringList slaves = forwarder->getProtoSlaves();
for (int i = 0; i < slaves.size(); ++i) {

View File

@@ -4,6 +4,7 @@
#include <QByteArray>
#include "CgiHandler.h"
#include "QtHttpHeader.h"
CgiHandler::CgiHandler (Hyperion * hyperion, QObject * parent)
: QObject(parent)
@@ -16,10 +17,15 @@ CgiHandler::~CgiHandler()
{
}
void CgiHandler::exec(const QStringList & args, QtHttpReply * reply)
void CgiHandler::exec(const QStringList & args, QtHttpRequest * request, QtHttpReply * reply)
{
try
{
// QByteArray header = reply->getHeader(QtHttpHeader::Host);
// QtHttpRequest::ClientInfo info = request->getClientInfo();
// qDebug() << info.clientAddress.toString();
// qDebug() << info.serverAddress.toString();
cmd_cfg_jsonserver(args,reply);
cmd_cfg_hyperion(args,reply);
throw 1;

View File

@@ -9,6 +9,7 @@
#include <hyperion/Hyperion.h>
#include "QtHttpReply.h"
#include "QtHttpRequest.h"
class CgiHandler : public QObject {
Q_OBJECT
@@ -17,7 +18,7 @@ public:
CgiHandler (Hyperion * hyperion, QObject * parent = NULL);
virtual ~CgiHandler (void);
void exec(const QStringList & args, QtHttpReply * reply);
void exec(const QStringList & args,QtHttpRequest * request, QtHttpReply * reply);
// cgi commands
void cmd_cfg_jsonserver(const QStringList & args, QtHttpReply * reply);

View File

@@ -10,6 +10,7 @@
#include <QStringBuilder>
#include <QStringList>
#include <QDateTime>
#include <QHostAddress>
const QByteArray & QtHttpClientWrapper::CRLF = QByteArrayLiteral ("\r\n");
@@ -54,6 +55,7 @@ void QtHttpClientWrapper::onClientDataReceived (void) {
// << "url :" << url
// << "version :" << version;
m_currentRequest = new QtHttpRequest (m_serverHandle);
m_currentRequest->setClientInfo(m_sockClient->localAddress(), m_sockClient->peerAddress());
m_currentRequest->setUrl (QUrl (url));
m_currentRequest->setCommand (command);
m_parsingStatus = AwaitingHeaders;

View File

@@ -23,6 +23,10 @@ QString QtHttpRequest::getCommand (void) const {
return m_command;
}
QtHttpRequest::ClientInfo QtHttpRequest::getClientInfo (void) const {
return m_clientInfo;
}
int QtHttpRequest::getRawDataSize (void) const {
return m_data.size ();
}
@@ -48,6 +52,11 @@ void QtHttpRequest::setCommand (const QString & command) {
m_command = command;
}
void QtHttpRequest::setClientInfo (const QHostAddress & server, const QHostAddress & client) {
m_clientInfo.serverAddress = server;
m_clientInfo.clientAddress = client;
}
void QtHttpRequest::addHeader (const QByteArray & header, const QByteArray & value) {
QByteArray key = header.trimmed ();
if (!key.isEmpty ()) {

View File

@@ -6,6 +6,7 @@
#include <QByteArray>
#include <QHash>
#include <QUrl>
#include <QHostAddress>
class QtHttpServer;
@@ -15,17 +16,24 @@ class QtHttpRequest : public QObject {
public:
explicit QtHttpRequest (QtHttpServer * parent);
int getRawDataSize (void) const;
struct ClientInfo {
QHostAddress serverAddress;
QHostAddress clientAddress;
};
int getRawDataSize (void) const;
QUrl getUrl (void) const;
QString getCommand (void) const;
QByteArray getRawData (void) const;
QList<QByteArray> getHeadersList (void) const;
ClientInfo getClientInfo (void) const;
QByteArray getHeader (const QByteArray & header) const;
public slots:
void setUrl (const QUrl & url);
void setCommand (const QString & command);
void setClientInfo (const QHostAddress & server, const QHostAddress & client);
void addHeader (const QByteArray & header, const QByteArray & value);
void appendRawData (const QByteArray & data);
@@ -35,6 +43,7 @@ private:
QByteArray m_data;
QtHttpServer * m_serverHandle;
QHash<QByteArray, QByteArray> m_headersHash;
ClientInfo m_clientInfo;
};
#endif // QTHTTPREQUEST_H

View File

@@ -66,7 +66,7 @@ void StaticFileServing::onRequestNeedsReply (QtHttpRequest * request, QtHttpRepl
uri_parts.removeAt(0);
try
{
_cgi.exec(uri_parts, reply);
_cgi.exec(uri_parts, request, reply);
}
catch(...)
{

View File

@@ -16,7 +16,7 @@ class StaticFileServing : public QObject {
Q_OBJECT
public:
explicit StaticFileServing (Hyperion *hyperion, QString baseUrl, quint16 port, QObject * parent = NULL);
explicit StaticFileServing (Hyperion *hyperion, QString baseUrl, quint16 port, QObject * parent = nullptr);
virtual ~StaticFileServing (void);
public slots: