- The first part

- Added CodeDocs config file for customization
- Fixing LGTM alerts
- LGTM bug fixed again
- added token option to hyperion-remote
- fix DBManager::getDB()
- next bugfix
- correct broken signal from SettingManager to Hyperion
- Token list is created after the schema is fetched

Signed-off-by: Paulchen-Panther <Paulchen-Panter@protonmail.com>
This commit is contained in:
Paulchen-Panther
2019-07-12 16:54:26 +02:00
parent 4fc745e748
commit ea796160af
72 changed files with 2546 additions and 485 deletions

View File

@@ -6,20 +6,16 @@
#include <QTcpSocket>
#include <QHostAddress>
// websocket includes
#include "webserver/WebSocketClient.h"
JsonClientConnection::JsonClientConnection(QTcpSocket *socket)
JsonClientConnection::JsonClientConnection(QTcpSocket *socket, const bool& localConnection)
: QObject()
, _socket(socket)
, _websocketClient(nullptr)
, _receiveBuffer()
, _log(Logger::getInstance("JSONCLIENTCONNECTION"))
{
connect(_socket, &QTcpSocket::disconnected, this, &JsonClientConnection::disconnected);
connect(_socket, &QTcpSocket::readyRead, this, &JsonClientConnection::readRequest);
// create a new instance of JsonAPI
_jsonAPI = new JsonAPI(socket->peerAddress().toString(), _log, this);
_jsonAPI = new JsonAPI(socket->peerAddress().toString(), _log, localConnection, this);
// get the callback messages from JsonAPI and send it to the client
connect(_jsonAPI,SIGNAL(callbackMessage(QJsonObject)),this,SLOT(sendMessage(QJsonObject)));
}
@@ -27,37 +23,21 @@ JsonClientConnection::JsonClientConnection(QTcpSocket *socket)
void JsonClientConnection::readRequest()
{
_receiveBuffer += _socket->readAll();
// might be an old hyperion classic handshake request or raw socket data
if(_receiveBuffer.contains("Upgrade: websocket"))
// raw socket data, handling as usual
int bytes = _receiveBuffer.indexOf('\n') + 1;
while(bytes > 0)
{
if(_websocketClient == Q_NULLPTR)
{
// disconnect this slot from socket for further requests
disconnect(_socket, &QTcpSocket::readyRead, this, &JsonClientConnection::readRequest);
int start = _receiveBuffer.indexOf("Sec-WebSocket-Key") + 19;
QByteArray header(_receiveBuffer.mid(start, _receiveBuffer.indexOf("\r\n", start) - start).data());
_websocketClient = new WebSocketClient(header, _socket, this);
}
}
else
{
// raw socket data, handling as usual
int bytes = _receiveBuffer.indexOf('\n') + 1;
while(bytes > 0)
{
// create message string
QString message(QByteArray(_receiveBuffer.data(), bytes));
// create message string
QString message(QByteArray(_receiveBuffer.data(), bytes));
// remove message data from buffer
_receiveBuffer = _receiveBuffer.mid(bytes);
// remove message data from buffer
_receiveBuffer = _receiveBuffer.mid(bytes);
// handle message
_jsonAPI->handleMessage(message);
// handle message
_jsonAPI->handleMessage(message);
// try too look up '\n' again
bytes = _receiveBuffer.indexOf('\n') + 1;
}
// try too look up '\n' again
bytes = _receiveBuffer.indexOf('\n') + 1;
}
}

View File

@@ -10,7 +10,6 @@
class JsonAPI;
class QTcpSocket;
class WebSocketClient;
///
/// The Connection object created by \a JsonServer when a new connection is established
@@ -24,7 +23,7 @@ public:
/// Constructor
/// @param socket The Socket object for this connection
///
JsonClientConnection(QTcpSocket * socket);
JsonClientConnection(QTcpSocket * socket, const bool& localConnection);
signals:
void connectionClosed();
@@ -42,7 +41,6 @@ private slots:
private:
QTcpSocket* _socket;
WebSocketClient* _websocketClient;
/// new instance of JsonAPI
JsonAPI * _jsonAPI;

View File

@@ -7,6 +7,7 @@
// bonjour include
#include <bonjour/bonjourserviceregister.h>
#include <utils/NetOrigin.h>
// qt includes
#include <QTcpServer>
@@ -19,6 +20,7 @@ JsonServer::JsonServer(const QJsonDocument& config)
, _server(new QTcpServer(this))
, _openConnections()
, _log(Logger::getInstance("JSONSERVER"))
, _netOrigin(NetOrigin::getInstance())
{
Debug(_log, "Created instance");
@@ -95,12 +97,17 @@ void JsonServer::newConnection()
{
if (QTcpSocket * socket = _server->nextPendingConnection())
{
Debug(_log, "New connection from: %s ",socket->localAddress().toString().toStdString().c_str());
JsonClientConnection * connection = new JsonClientConnection(socket);
_openConnections.insert(connection);
if(_netOrigin->accessAllowed(socket->peerAddress(), socket->localAddress()))
{
Debug(_log, "New connection from: %s ",socket->localAddress().toString().toStdString().c_str());
JsonClientConnection * connection = new JsonClientConnection(socket, _netOrigin->isLocalAddress(socket->peerAddress(), socket->localAddress()));
_openConnections.insert(connection);
// register slot for cleaning up after the connection closed
connect(connection, &JsonClientConnection::connectionClosed, this, &JsonServer::closedConnection);
// register slot for cleaning up after the connection closed
connect(connection, &JsonClientConnection::connectionClosed, this, &JsonServer::closedConnection);
}
else
socket->close();
}
}
}