Add Qt6 support
This commit is contained in:
parent
9f60a76d14
commit
fad0bc1e62
@ -68,7 +68,11 @@ QByteArray SlipDataProcessor::deserializeData(const QByteArray &data)
|
||||
QByteArray SlipDataProcessor::serializeData(const QByteArray &data)
|
||||
{
|
||||
QByteArray serializedData;
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
QDataStream stream(&serializedData, QDataStream::WriteOnly);
|
||||
#else
|
||||
QDataStream stream(&serializedData, QIODevice::WriteOnly);
|
||||
#endif
|
||||
// stream << static_cast<quint8>(ProtocolByteEnd);
|
||||
|
||||
for (int i = 0; i < data.length(); i++) {
|
||||
@ -110,7 +114,11 @@ SlipDataProcessor::Frame SlipDataProcessor::parseFrame(const QByteArray &data)
|
||||
QByteArray SlipDataProcessor::buildFrame(const Frame &frame)
|
||||
{
|
||||
QByteArray data;
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
QDataStream stream(&data, QDataStream::WriteOnly);
|
||||
#else
|
||||
QDataStream stream(&data, QIODevice::WriteOnly);
|
||||
#endif
|
||||
stream << frame.socketAddress;
|
||||
for (int i = 0; i < frame.data.size(); i++) {
|
||||
stream << static_cast<quint8>(frame.data.at(i));
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
#include "jsonhandler.h"
|
||||
#include <QMetaMethod>
|
||||
#include <QDebug>
|
||||
#include <QRegExp>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "jsonreply.h"
|
||||
#include "jsontypes.h"
|
||||
@ -67,7 +67,7 @@ QVariantMap JsonHandler::introspect(const QMetaMethod::MethodType &type)
|
||||
if (!m_descriptions.contains(method.name()) || !m_params.contains(method.name())) {
|
||||
continue;
|
||||
}
|
||||
if (QString(method.name()).contains(QRegExp("^[A-Z]"))) {
|
||||
if (QString(method.name()).contains(QRegularExpression("^[A-Z]"))) {
|
||||
QVariantMap methodData;
|
||||
methodData.insert("description", m_descriptions.value(method.name()));
|
||||
methodData.insert("params", m_params.value(method.name()));
|
||||
|
||||
@ -39,6 +39,7 @@ namespace remoteproxy {
|
||||
class JsonReply: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Type {
|
||||
TypeSync,
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
#include <QStringList>
|
||||
#include <QJsonDocument>
|
||||
#include <QDebug>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "loggingcategories.h"
|
||||
|
||||
@ -72,7 +73,7 @@ QPair<bool, QString> JsonTypes::validateMap(const QVariantMap &templateMap, cons
|
||||
// Make sure all values defined in the template are around
|
||||
foreach (const QString &key, templateMap.keys()) {
|
||||
QString strippedKey = key;
|
||||
strippedKey.remove(QRegExp("^o:"));
|
||||
strippedKey.remove(QRegularExpression("^o:"));
|
||||
if (!key.startsWith("o:") && !map.contains(strippedKey)) {
|
||||
qCWarning(dcJsonRpc()) << "*** missing key" << key;
|
||||
qCWarning(dcJsonRpc()) << "Expected: " << templateMap;
|
||||
@ -274,7 +275,7 @@ QString JsonTypes::basicTypeToString(const QVariant::Type &type)
|
||||
|
||||
QPair<bool, QString> JsonTypes::report(bool status, const QString &message)
|
||||
{
|
||||
return qMakePair<bool, QString>(status, message);
|
||||
return QPair<bool, QString>(status, message);
|
||||
}
|
||||
|
||||
QVariantList JsonTypes::enumToStrings(const QMetaObject &metaObject, const QString &enumName)
|
||||
|
||||
@ -70,7 +70,6 @@ namespace remoteproxy {
|
||||
class JsonTypes
|
||||
{
|
||||
Q_GADGET
|
||||
Q_ENUMS(BasicType)
|
||||
|
||||
public:
|
||||
enum BasicType {
|
||||
|
||||
@ -45,6 +45,15 @@ public:
|
||||
|
||||
QString name() const override;
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
// Server
|
||||
Q_INVOKABLE remoteproxy::JsonReply *RegisterServer(const QVariantMap ¶ms, TransportClient *transportClient);
|
||||
Q_INVOKABLE remoteproxy::JsonReply *DisconnectClient(const QVariantMap ¶ms, TransportClient *transportClient);
|
||||
Q_INVOKABLE remoteproxy::JsonReply *Ping(const QVariantMap ¶ms, TransportClient *transportClient);
|
||||
|
||||
// Client
|
||||
Q_INVOKABLE remoteproxy::JsonReply *RegisterClient(const QVariantMap ¶ms, TransportClient *transportClient);
|
||||
#else
|
||||
// Server
|
||||
Q_INVOKABLE JsonReply *RegisterServer(const QVariantMap ¶ms, TransportClient *transportClient);
|
||||
Q_INVOKABLE JsonReply *DisconnectClient(const QVariantMap ¶ms, TransportClient *transportClient);
|
||||
@ -52,7 +61,7 @@ public:
|
||||
|
||||
// Client
|
||||
Q_INVOKABLE JsonReply *RegisterClient(const QVariantMap ¶ms, TransportClient *transportClient);
|
||||
|
||||
#endif
|
||||
signals:
|
||||
void ClientConnected(const QVariantMap ¶ms, TransportClient *transportClient);
|
||||
void ClientDisconnected(const QVariantMap ¶ms, TransportClient *transportClient);
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
#include "loggingcategories.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QtGlobal>
|
||||
|
||||
namespace remoteproxy {
|
||||
|
||||
@ -101,7 +102,7 @@ void LogEngine::rotateLogs()
|
||||
|
||||
QString LogEngine::createTimestamp()
|
||||
{
|
||||
return QString::number(QDateTime::currentDateTimeUtc().toTime_t());
|
||||
return QString::number(QDateTime::currentDateTimeUtc().toSecsSinceEpoch());
|
||||
}
|
||||
|
||||
void LogEngine::enable()
|
||||
|
||||
@ -331,7 +331,7 @@ QDebug operator<<(QDebug debug, ProxyConfiguration *configuration)
|
||||
debug.nospace() << " Locality name:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::LocalityName) << "\n";
|
||||
debug.nospace() << " State/Province:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::StateOrProvinceName) << "\n";
|
||||
debug.nospace() << " Email address:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::EmailAddress) << "\n";
|
||||
debug.nospace() << "UnixSocketServer Proxy" << endl;
|
||||
debug.nospace() << "UnixSocketServer Proxy" << "\n";
|
||||
debug.nospace() << " - Filename:" << configuration->unixSocketFileName() << "\n";
|
||||
debug.nospace() << "WebSocketServer TunnelProxy" << "\n";
|
||||
debug.nospace() << " - Host:" << configuration->webSocketServerTunnelProxyHost().toString() << "\n";
|
||||
|
||||
@ -42,6 +42,9 @@ namespace remoteproxy {
|
||||
JsonRpcServer::JsonRpcServer(QObject *parent) :
|
||||
JsonHandler(parent)
|
||||
{
|
||||
|
||||
//qRegisterMetaType<JsonReply*>();
|
||||
|
||||
// Methods
|
||||
QVariantMap params; QVariantMap returns;
|
||||
|
||||
@ -66,9 +69,9 @@ JsonRpcServer::JsonRpcServer(QObject *parent) :
|
||||
// Notifications
|
||||
params.clear(); returns.clear();
|
||||
setDescription("TunnelEstablished", "Emitted whenever the tunnel has been established successfully. "
|
||||
"This is the last message from the remote proxy server! Any following data will be from "
|
||||
"the other tunnel client until the connection will be closed. The parameter contain some information "
|
||||
"about the other tunnel client.");
|
||||
"This is the last message from the remote proxy server! Any following data will be from "
|
||||
"the other tunnel client until the connection will be closed. The parameter contain some information "
|
||||
"about the other tunnel client.");
|
||||
params.insert("uuid", JsonTypes::basicTypeToString(JsonTypes::String));
|
||||
params.insert("name", JsonTypes::basicTypeToString(JsonTypes::String));
|
||||
setParams("TunnelEstablished", params);
|
||||
@ -114,14 +117,20 @@ JsonReply *JsonRpcServer::Introspect(const QVariantMap ¶ms, TransportClient
|
||||
|
||||
QVariantMap methods;
|
||||
foreach (JsonHandler *handler, m_handlers) {
|
||||
methods.unite(handler->introspect(QMetaMethod::Method));
|
||||
QVariantMap handlerMethods = handler->introspect(QMetaMethod::Method);
|
||||
foreach (const QString &method, handlerMethods.keys()) {
|
||||
methods.insert(method, handlerMethods.value(method));
|
||||
}
|
||||
}
|
||||
|
||||
data.insert("methods", methods);
|
||||
|
||||
QVariantMap signalsMap;
|
||||
foreach (JsonHandler *handler, m_handlers) {
|
||||
signalsMap.unite(handler->introspect(QMetaMethod::Signal));
|
||||
QVariantMap handlerSignals = handler->introspect(QMetaMethod::Signal);
|
||||
foreach (const QString &signalName, handlerSignals.keys()) {
|
||||
signalsMap.insert(signalName, handlerSignals.value(signalName));
|
||||
}
|
||||
}
|
||||
|
||||
data.insert("notifications", signalsMap);
|
||||
@ -141,10 +150,10 @@ void JsonRpcServer::sendResponse(TransportClient *client, int commandId, const Q
|
||||
if (client->slipEnabled()) {
|
||||
SlipDataProcessor::Frame frame;
|
||||
frame.socketAddress = 0x0000;
|
||||
frame.data = data + '\n';
|
||||
frame.data = data + "\n";
|
||||
client->sendData(SlipDataProcessor::serializeData(SlipDataProcessor::buildFrame(frame)));
|
||||
} else {
|
||||
client->sendData(data + '\n');
|
||||
client->sendData(data + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -160,10 +169,10 @@ void JsonRpcServer::sendErrorResponse(TransportClient *client, int commandId, co
|
||||
if (client->slipEnabled()) {
|
||||
SlipDataProcessor::Frame frame;
|
||||
frame.socketAddress = 0x0000;
|
||||
frame.data = data + '\n';
|
||||
frame.data = data + "\n";
|
||||
client->sendData(SlipDataProcessor::serializeData(SlipDataProcessor::buildFrame(frame)));
|
||||
} else {
|
||||
client->sendData(data + '\n');
|
||||
client->sendData(data + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,9 +181,9 @@ QString JsonRpcServer::formatAssertion(const QString &targetNamespace, const QSt
|
||||
QJsonDocument doc = QJsonDocument::fromVariant(handler->introspect(QMetaMethod::Method).value(targetNamespace + "." + method));
|
||||
QJsonDocument doc2 = QJsonDocument::fromVariant(data);
|
||||
return QString("\nMethod: %1\nTemplate: %2\nValue: %3")
|
||||
.arg(targetNamespace + "." + method)
|
||||
.arg(QString(doc.toJson(QJsonDocument::Indented)))
|
||||
.arg(QString(doc2.toJson(QJsonDocument::Indented)));
|
||||
.arg(targetNamespace + "." + method)
|
||||
.arg(QString(doc.toJson(QJsonDocument::Indented)))
|
||||
.arg(QString(doc2.toJson(QJsonDocument::Indented)));
|
||||
}
|
||||
|
||||
void JsonRpcServer::registerHandler(JsonHandler *handler)
|
||||
@ -248,14 +257,38 @@ void JsonRpcServer::processDataPacket(TransportClient *transportClient, const QB
|
||||
return;
|
||||
}
|
||||
|
||||
JsonReply *reply;
|
||||
QMetaObject::invokeMethod(handler, method.toLatin1().data(), Q_RETURN_ARG(JsonReply*, reply), Q_ARG(QVariantMap, params), Q_ARG(TransportClient*, transportClient));
|
||||
|
||||
JsonReply *reply = nullptr;
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
bool invokedSuccessfully = QMetaObject::invokeMethod(handler, method.toLatin1().constData(),
|
||||
Qt::DirectConnection,
|
||||
qReturnArg(reply),
|
||||
params, transportClient);
|
||||
|
||||
if (!invokedSuccessfully) {
|
||||
qCWarning(dcJsonRpc()) << "Failed to invoke method" << handler << method;
|
||||
}
|
||||
#else
|
||||
QMetaObject::invokeMethod(handler, method.toLatin1().constData(),
|
||||
Qt::DirectConnection,
|
||||
Q_RETURN_ARG(JsonReply *, reply),
|
||||
Q_ARG(QVariantMap, params),
|
||||
Q_ARG(TransportClient *, transportClient));
|
||||
#endif
|
||||
|
||||
|
||||
if (!reply) {
|
||||
qCWarning(dcJsonRpc()) << "Internal error. No reply, could not invoke method.";
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (reply->type() == JsonReply::TypeAsync) {
|
||||
m_asyncReplies.insert(reply, transportClient);
|
||||
reply->setClientId(transportClient->clientId());
|
||||
reply->setCommandId(commandId);
|
||||
|
||||
connect(reply, &JsonReply::finished, this, &JsonRpcServer::asyncReplyFinished);
|
||||
connect(reply, &remoteproxy::JsonReply::finished, this, &JsonRpcServer::asyncReplyFinished);
|
||||
reply->startWait();
|
||||
} else {
|
||||
Q_ASSERT_X((targetNamespace == "RemoteProxy" && method == "Introspect") || handler->validateReturns(method, reply->data()).first
|
||||
@ -295,7 +328,7 @@ void JsonRpcServer::asyncReplyFinished()
|
||||
if (!reply->timedOut()) {
|
||||
Q_ASSERT_X(reply->handler()->validateReturns(reply->method(), reply->data()).first
|
||||
,"validating return value", formatAssertion(reply->handler()->name(),
|
||||
reply->method(), reply->handler(), reply->data()).toLatin1().data());
|
||||
reply->method(), reply->handler(), reply->data()).toLatin1().data());
|
||||
|
||||
QPair<bool, QString> returnValidation = reply->handler()->validateReturns(reply->method(), reply->data());
|
||||
if (!returnValidation.first) {
|
||||
@ -385,12 +418,12 @@ void JsonRpcServer::sendNotification(const QString &nameSpace, const QString &me
|
||||
if (transportClient->slipEnabled()) {
|
||||
SlipDataProcessor::Frame frame;
|
||||
frame.socketAddress = 0x0000;
|
||||
frame.data = data + '\n';
|
||||
frame.data = data + "\n";
|
||||
qCDebug(dcJsonRpcTraffic()) << "Sending notification frame:" <<frame.socketAddress << qUtf8Printable(frame.data);
|
||||
transportClient->sendData(SlipDataProcessor::serializeData(SlipDataProcessor::buildFrame(frame)));
|
||||
} else {
|
||||
qCDebug(dcJsonRpcTraffic()) << "Sending notification:" << data;
|
||||
transportClient->sendData(data + '\n');
|
||||
transportClient->sendData(data + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -56,7 +56,7 @@ bool MonitorServer::running() const
|
||||
|
||||
void MonitorServer::sendMonitorData(QLocalSocket *clientConnection, const QVariantMap &dataMap)
|
||||
{
|
||||
QByteArray data = QJsonDocument::fromVariant(dataMap).toJson(QJsonDocument::Compact) + '\n';
|
||||
QByteArray data = QJsonDocument::fromVariant(dataMap).toJson(QJsonDocument::Compact) + "\n";
|
||||
qCDebug(dcMonitorServer()) << "Sending monitor data" << qUtf8Printable(data);
|
||||
clientConnection->write(data);
|
||||
clientConnection->flush();
|
||||
|
||||
@ -45,7 +45,7 @@ TcpSocketServer::~TcpSocketServer()
|
||||
|
||||
void TcpSocketServer::sendData(const QUuid &clientId, const QByteArray &data)
|
||||
{
|
||||
QTcpSocket *client = m_clientList.value(clientId);
|
||||
QSslSocket *client = m_clientList.value(clientId);
|
||||
if (!client) {
|
||||
qCWarning(dcTcpSocketServer()) << "Client" << clientId << "unknown to this transport";
|
||||
return;
|
||||
@ -59,7 +59,7 @@ void TcpSocketServer::sendData(const QUuid &clientId, const QByteArray &data)
|
||||
|
||||
void TcpSocketServer::killClientConnection(const QUuid &clientId, const QString &killReason)
|
||||
{
|
||||
QTcpSocket *client = m_clientList.value(clientId);
|
||||
QSslSocket *client = m_clientList.value(clientId);
|
||||
if (!client) {
|
||||
qCWarning(dcTcpSocketServer()) << "Could not kill connection with id" << clientId.toString() << "with reason" << killReason << "because there is no socket with this id.";
|
||||
return;
|
||||
@ -193,10 +193,17 @@ void SslServer::incomingConnection(qintptr socketDescriptor)
|
||||
qCDebug(dcTcpSocketServer()) << "Client socket disconnected:" << sslSocket << sslSocket->peerAddress().toString();;
|
||||
|
||||
if (m_sslEnabled) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
// FIXME: the SSL socket behavior seems to have changed in Qt6,
|
||||
// we need to emit this signal in any case, otherwise the upper layer assumes the
|
||||
// socket object still exists, even if we only hand over to upper layers on encypted.
|
||||
emit socketDisconnected(sslSocket);
|
||||
#else
|
||||
// Only tell the upper layer the client has disconnecred if it was encrypted
|
||||
if (sslSocket->isEncrypted()) {
|
||||
emit socketDisconnected(sslSocket);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
emit socketDisconnected(sslSocket);
|
||||
}
|
||||
@ -221,6 +228,19 @@ void SslServer::incomingConnection(qintptr socketDescriptor)
|
||||
emit socketConnected(sslSocket);
|
||||
});
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
connect(sslSocket, &QSslSocket::errorOccurred, this, [sslSocket](QAbstractSocket::SocketError error){
|
||||
qCWarning(dcTcpSocketServer()) << "Socket error occurred on" << sslSocket << error << sslSocket->errorString() << "Explicitly closing the client connection.";
|
||||
sslSocket->close();
|
||||
});
|
||||
|
||||
connect(sslSocket, &QSslSocket::sslErrors, this, [sslSocket](const QList<QSslError> &errors) {
|
||||
qCWarning(dcTcpSocketServer()) << "SSL error occurred in the client connection" << sslSocket;
|
||||
foreach (const QSslError &error, errors) {
|
||||
qCWarning(dcTcpSocketServer()) << "--> SSL error:" << error.error() << error.errorString();
|
||||
}
|
||||
});
|
||||
#else
|
||||
typedef void (QAbstractSocket:: *errorSignal)(QAbstractSocket::SocketError);
|
||||
connect(sslSocket, static_cast<errorSignal>(&QAbstractSocket::error), this, [sslSocket](QAbstractSocket::SocketError error){
|
||||
qCWarning(dcTcpSocketServer()) << "Socket error occurred on" << sslSocket << error << sslSocket->errorString() << "Explicitly closing the client connection.";
|
||||
@ -235,6 +255,8 @@ void SslServer::incomingConnection(qintptr socketDescriptor)
|
||||
}
|
||||
});
|
||||
|
||||
#endif
|
||||
|
||||
if (m_sslEnabled) {
|
||||
qCDebug(dcTcpSocketServer()) << "Starting SSL encryption for" << sslSocket;
|
||||
sslSocket->setSslConfiguration(m_config);
|
||||
|
||||
@ -38,7 +38,7 @@ TransportClient::TransportClient(TransportInterface *interface, const QUuid &cli
|
||||
m_clientId(clientId),
|
||||
m_peerAddress(address)
|
||||
{
|
||||
m_creationTimeStamp = QDateTime::currentDateTime().toMSecsSinceEpoch() / 1000;
|
||||
m_creationTimeStamp = QDateTime::currentDateTime().toSecsSinceEpoch();
|
||||
}
|
||||
|
||||
QUuid TransportClient::clientId() const
|
||||
|
||||
@ -134,14 +134,14 @@ void UnixSocketServer::onClientConnected()
|
||||
qCDebug(dcUnixSocketServer()) << "New client connected" << clientId.toString();
|
||||
m_clientList.insert(clientId, client);
|
||||
|
||||
connect(client, &QLocalSocket::disconnected, this, [=](){
|
||||
connect(client, &QLocalSocket::disconnected, this, [this, client](){
|
||||
QUuid clientId = m_clientList.key(client);
|
||||
qCDebug(dcUnixSocketServer()) << "Client disconnected:" << clientId.toString();
|
||||
if (m_clientList.take(clientId)) {
|
||||
emit clientDisconnected(clientId);
|
||||
}
|
||||
});
|
||||
connect(client, &QLocalSocket::readyRead, this, [=](){
|
||||
connect(client, &QLocalSocket::readyRead, this, [this, client, clientId](){
|
||||
QByteArray data = client->readAll();
|
||||
qCDebug(dcUnixSocketServerTraffic()) << "Incomming data from" << clientId.toString() << data;
|
||||
emit dataAvailable(clientId, data);
|
||||
|
||||
@ -105,7 +105,7 @@ JsonReply *JsonRpcClient::callPing(uint timestamp)
|
||||
|
||||
void JsonRpcClient::sendRequest(const QVariantMap &request, bool slipEnabled)
|
||||
{
|
||||
QByteArray data = QJsonDocument::fromVariant(request).toJson(QJsonDocument::Compact) + '\n';
|
||||
QByteArray data = QJsonDocument::fromVariant(request).toJson(QJsonDocument::Compact) + "\n";
|
||||
|
||||
if (slipEnabled) {
|
||||
SlipDataProcessor::Frame frame;
|
||||
|
||||
@ -41,11 +41,17 @@ TcpSocketConnection::TcpSocketConnection(QObject *parent) :
|
||||
QObject::connect(m_tcpSocket, &QSslSocket::readyRead, this, &TcpSocketConnection::onReadyRead);
|
||||
QObject::connect(m_tcpSocket, &QSslSocket::stateChanged, this, &TcpSocketConnection::onStateChanged);
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
connect(m_tcpSocket, &QSslSocket::errorOccurred, this, &TcpSocketConnection::onError);
|
||||
connect(m_tcpSocket, &QSslSocket::sslErrors, this, &TcpSocketConnection::sslErrors);
|
||||
#else
|
||||
typedef void (QSslSocket:: *errorSignal)(QAbstractSocket::SocketError);
|
||||
QObject::connect(m_tcpSocket, static_cast<errorSignal>(&QSslSocket::error), this, &TcpSocketConnection::onError);
|
||||
|
||||
typedef void (QSslSocket:: *sslErrorsSignal)(const QList<QSslError> &);
|
||||
QObject::connect(m_tcpSocket, static_cast<sslErrorsSignal>(&QSslSocket::sslErrors), this, &TcpSocketConnection::sslErrors);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
TcpSocketConnection::~TcpSocketConnection()
|
||||
|
||||
@ -87,7 +87,7 @@ void MonitorClient::onDisconnected()
|
||||
|
||||
void MonitorClient::onReadyRead()
|
||||
{
|
||||
// Note: the server sends the data compact with '\n' at the end
|
||||
// Note: the server sends the data compact with "\n" at the end
|
||||
QByteArray data = m_socket->readAll();
|
||||
|
||||
int index = data.indexOf("}\n");
|
||||
|
||||
@ -69,7 +69,7 @@ void NonInteractiveMonitor::onConnected()
|
||||
QVariantList clientList = serverMap.value("clientConnections").toList();
|
||||
|
||||
// Server line
|
||||
QString serverConnectionTime = QDateTime::fromTime_t(serverMap.value("timestamp").toUInt()).toString("dd.MM.yyyy hh:mm:ss");
|
||||
QString serverConnectionTime = QDateTime::fromMSecsSinceEpoch(serverMap.value("timestamp").toLongLong() * 1000).toString("dd.MM.yyyy hh:mm:ss");
|
||||
QString serverLinePrint;
|
||||
if (clientList.isEmpty()) {
|
||||
serverLinePrint.prepend("├──");
|
||||
@ -97,7 +97,7 @@ void NonInteractiveMonitor::onConnected()
|
||||
}
|
||||
|
||||
clientLinePrint += QString("%1 | %2 | %3 RX: %4 TX: %5 | %6")
|
||||
.arg(QDateTime::fromTime_t(clientMap.value("timestamp").toUInt()).toString("dd.MM.yyyy hh:mm:ss"))
|
||||
.arg(QDateTime::fromMSecsSinceEpoch(clientMap.value("timestamp").toLongLong() * 1000).toString("dd.MM.yyyy hh:mm:ss"))
|
||||
.arg(clientMap.value("clientUuid").toString())
|
||||
.arg(clientMap.value("address").toString(), - 15)
|
||||
.arg(Utils::humanReadableTraffic(serverMap.value("rxDataCount").toInt()), - 9)
|
||||
|
||||
@ -195,7 +195,7 @@ void TerminalWindow::paintContentClients()
|
||||
QVariantMap clientMap = clientVariant.toMap();
|
||||
|
||||
uint timeStamp = clientMap.value("timestamp").toUInt();
|
||||
QString clientConnectionTime = QDateTime::fromTime_t(timeStamp).toString("dd.MM.yyyy hh:mm:ss");
|
||||
QString clientConnectionTime = QDateTime::fromMSecsSinceEpoch(timeStamp * 1000).toString("dd.MM.yyyy hh:mm:ss");
|
||||
|
||||
int rxDataCountBytes = clientMap.value("rxDataCount").toInt();
|
||||
int txDataCountBytes = clientMap.value("txDataCount").toInt();
|
||||
@ -226,7 +226,7 @@ void TerminalWindow::paintContentTunnels()
|
||||
|
||||
// Tunnel time
|
||||
uint timeStamp = tunnelMap.value("timestamp").toUInt();
|
||||
QString tunnelConnectionTime = QDateTime::fromTime_t(timeStamp).toString("dd.MM.yyyy hh:mm:ss");
|
||||
QString tunnelConnectionTime = QDateTime::fromMSecsSinceEpoch(timeStamp * 1000).toString("dd.MM.yyyy hh:mm:ss");
|
||||
|
||||
QString tunnelPrint = QString("%1 | %2 | %3 | %4 | %5 (%6) <---> %7 (%8)")
|
||||
.arg(tunnelConnectionTime)
|
||||
@ -252,7 +252,7 @@ void TerminalWindow::paintContentTunnelProxy()
|
||||
foreach (const QVariant &serverVariant, tunnelProxyMap.value("tunnelConnections").toList()) {
|
||||
QVariantMap serverMap = serverVariant.toMap();
|
||||
uint timeStamp = serverMap.value("timestamp").toUInt();
|
||||
QString serverConnectionTime = QDateTime::fromTime_t(timeStamp).toString("dd.MM.yyyy hh:mm:ss");
|
||||
QString serverConnectionTime = QDateTime::fromMSecsSinceEpoch(timeStamp * 1000).toString("dd.MM.yyyy hh:mm:ss");
|
||||
int rxDataCountBytes = serverMap.value("rxDataCount").toInt();
|
||||
int txDataCountBytes = serverMap.value("txDataCount").toInt();
|
||||
QString serverLinePrint = QString("%1 | %2 | RX: %3 | TX: %4 | %5")
|
||||
@ -287,7 +287,7 @@ void TerminalWindow::paintContentTunnelProxy()
|
||||
mvwaddch(m_contentWindow, i, 5, ACS_HLINE);
|
||||
|
||||
QString clientLinePrint = QString("%1 | %2 | RX: %3 | TX: %4 | %5")
|
||||
.arg(QDateTime::fromTime_t(clientMap.value("timestamp").toUInt()).toString("dd.MM.yyyy hh:mm:ss"))
|
||||
.arg(QDateTime::fromMSecsSinceEpoch(clientMap.value("timestamp").toULongLong() * 1000).toString("dd.MM.yyyy hh:mm:ss"))
|
||||
.arg(clientMap.value("address").toString(), - 16)
|
||||
.arg(Utils::humanReadableTraffic(clientMap.value("rxDataCount").toInt()), - 10)
|
||||
.arg(Utils::humanReadableTraffic(clientMap.value("txDataCount").toInt()), - 10)
|
||||
|
||||
@ -43,7 +43,7 @@ public:
|
||||
Utils() = default;
|
||||
|
||||
inline static QString getDurationString(uint timestamp) {
|
||||
uint duration = QDateTime::currentDateTimeUtc().toTime_t() - timestamp;
|
||||
uint duration = QDateTime::currentDateTimeUtc().toSecsSinceEpoch() - timestamp;
|
||||
int seconds = static_cast<int>(duration % 60);
|
||||
duration /= 60;
|
||||
int minutes = static_cast<int>(duration % 60);
|
||||
|
||||
@ -1,10 +1,22 @@
|
||||
QT *= network websockets
|
||||
QT -= gui
|
||||
|
||||
CONFIG += c++11 console
|
||||
CONFIG += console
|
||||
|
||||
QMAKE_CXXFLAGS *= -Werror -std=c++11 -g -Wno-deprecated-declarations
|
||||
QMAKE_LFLAGS *= -std=c++11
|
||||
greaterThan(QT_MAJOR_VERSION, 5) {
|
||||
message("Building using Qt6 support")
|
||||
CONFIG *= c++17
|
||||
QMAKE_LFLAGS *= -std=c++17
|
||||
QMAKE_CXXFLAGS *= -std=c++17
|
||||
} else {
|
||||
message("Building using Qt5 support")
|
||||
CONFIG *= c++11
|
||||
QMAKE_LFLAGS *= -std=c++11
|
||||
QMAKE_CXXFLAGS *= -std=c++11
|
||||
DEFINES += QT_DISABLE_DEPRECATED_UP_TO=0x050F00
|
||||
}
|
||||
|
||||
QMAKE_CXXFLAGS *= -Werror -g -Wno-deprecated-declarations
|
||||
|
||||
top_srcdir=$$PWD
|
||||
top_builddir=$$shadowed($$PWD)
|
||||
@ -19,6 +31,7 @@ coverage {
|
||||
MOC_DIR =
|
||||
|
||||
LIBS += -lgcov
|
||||
|
||||
QMAKE_CXXFLAGS += --coverage
|
||||
QMAKE_LDFLAGS += --coverage
|
||||
|
||||
|
||||
@ -171,11 +171,9 @@ void RemoteProxyTestsTunnelProxy::getHello()
|
||||
|
||||
void RemoteProxyTestsTunnelProxy::monitorServer()
|
||||
{
|
||||
|
||||
// Start the server
|
||||
startServer();
|
||||
|
||||
|
||||
// ** Create the server **
|
||||
QString serverName = "nymea server";
|
||||
QUuid serverUuid = QUuid::createUuid();
|
||||
@ -188,7 +186,9 @@ void RemoteProxyTestsTunnelProxy::monitorServer()
|
||||
tunnelProxyServer->startServer(m_serverUrlTunnelProxyTcp);
|
||||
|
||||
QSignalSpy serverRunningSpy(tunnelProxyServer, &TunnelProxySocketServer::runningChanged);
|
||||
serverRunningSpy.wait();
|
||||
if (serverRunningSpy.isEmpty())
|
||||
serverRunningSpy.wait();
|
||||
|
||||
QVERIFY(serverRunningSpy.count() == 1);
|
||||
QList<QVariant> arguments = serverRunningSpy.takeFirst();
|
||||
QVERIFY(arguments.at(0).toBool() == true);
|
||||
|
||||
@ -241,7 +241,7 @@ QVariant BaseTest::invokeTcpSocketTunnelProxyApiCall(const QString &method, cons
|
||||
}
|
||||
|
||||
QSignalSpy dataSpy(socket, &QSslSocket::readyRead);
|
||||
socket->write(jsonDoc.toJson(QJsonDocument::Compact) + '\n');
|
||||
socket->write(jsonDoc.toJson(QJsonDocument::Compact) + "\n");
|
||||
dataSpy.wait();
|
||||
if (dataSpy.count() != 1) {
|
||||
qWarning() << "No data received";
|
||||
@ -292,7 +292,7 @@ QVariant BaseTest::injectTcpSocketTunnelProxyData(const QByteArray &data)
|
||||
}
|
||||
|
||||
QSignalSpy dataSpy(socket, &QSslSocket::readyRead);
|
||||
socket->write(data + '\n');
|
||||
socket->write(data + "\n");
|
||||
dataSpy.wait();
|
||||
if (dataSpy.count() != 1) {
|
||||
qWarning() << "No data received";
|
||||
@ -345,7 +345,7 @@ QPair<QVariant, QSslSocket *> BaseTest::invokeTcpSocketTunnelProxyApiCallPersist
|
||||
request.insert("method", method);
|
||||
request.insert("params", params);
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromVariant(request);
|
||||
QByteArray payload = jsonDoc.toJson(QJsonDocument::Compact) + '\n';
|
||||
QByteArray payload = jsonDoc.toJson(QJsonDocument::Compact) + "\n";
|
||||
|
||||
QSignalSpy dataSpy(socket, &QSslSocket::readyRead);
|
||||
|
||||
@ -439,7 +439,7 @@ QPair<QVariant, QWebSocket *> BaseTest::invokeWebSocketTunnelProxyApiCallPersist
|
||||
request.insert("method", method);
|
||||
request.insert("params", params);
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromVariant(request);
|
||||
QByteArray payload = jsonDoc.toJson(QJsonDocument::Compact) + '\n';
|
||||
QByteArray payload = jsonDoc.toJson(QJsonDocument::Compact) + "\n";
|
||||
|
||||
|
||||
if (socket->state() != QAbstractSocket::ConnectedState) {
|
||||
|
||||
@ -11,7 +11,7 @@ ClientConnection::ClientConnection(const QUrl &serverUrl, const QString &name, c
|
||||
{
|
||||
m_remoteConnection = new TunnelProxyRemoteConnection(m_uuid, m_name);
|
||||
m_timer.setSingleShot(true);
|
||||
connect(&m_timer, &QTimer::timeout, this, [=](){
|
||||
connect(&m_timer, &QTimer::timeout, this, [this](){
|
||||
if (m_remoteConnection->remoteConnected()) {
|
||||
m_remoteConnection->sendData(generateRandomString(100).toUtf8());
|
||||
m_timer.start(1000);
|
||||
@ -45,7 +45,7 @@ ClientConnection::ClientConnection(const QUrl &serverUrl, const QString &name, c
|
||||
qWarning() << "Socket error occurred" << error;
|
||||
});
|
||||
|
||||
connect(m_remoteConnection, &TunnelProxyRemoteConnection::sslErrors, this, [=](const QList<QSslError> &errors){
|
||||
connect(m_remoteConnection, &TunnelProxyRemoteConnection::sslErrors, this, [this](const QList<QSslError> &errors){
|
||||
if (m_insecure) {
|
||||
m_remoteConnection->ignoreSslErrors(errors);
|
||||
} else {
|
||||
@ -67,7 +67,7 @@ QString ClientConnection::generateRandomString(uint length) const
|
||||
const QString possibleCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
|
||||
QString randomString;
|
||||
for(uint i = 0; i < length; i++) {
|
||||
randomString.append(possibleCharacters.at(qrand() % possibleCharacters.length()));
|
||||
randomString.append(possibleCharacters.at(std::rand() % possibleCharacters.length()));
|
||||
}
|
||||
return randomString;
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ ServerConnection::ServerConnection(const QUrl &serverUrl, const QString &name, c
|
||||
|
||||
m_socketServer = new TunnelProxySocketServer(m_uuid, m_name, this);
|
||||
|
||||
connect(m_socketServer, &TunnelProxySocketServer::clientConnected, this, [=](TunnelProxySocket *tunnelProxySocket){
|
||||
connect(m_socketServer, &TunnelProxySocketServer::clientConnected, this, [this](TunnelProxySocket *tunnelProxySocket){
|
||||
qDebug() << "[+] Client connected" << tunnelProxySocket;
|
||||
if (m_echo) {
|
||||
connect(tunnelProxySocket, &TunnelProxySocket::dataReceived, m_socketServer, [tunnelProxySocket](const QByteArray &data){
|
||||
@ -20,18 +20,18 @@ ServerConnection::ServerConnection(const QUrl &serverUrl, const QString &name, c
|
||||
}
|
||||
});
|
||||
|
||||
connect(m_socketServer, &TunnelProxySocketServer::clientDisconnected, this, [=](TunnelProxySocket *tunnelProxySocket){
|
||||
connect(m_socketServer, &TunnelProxySocketServer::clientDisconnected, this, [](TunnelProxySocket *tunnelProxySocket){
|
||||
qDebug() << "[-] Client disconnected" << tunnelProxySocket;
|
||||
});
|
||||
|
||||
connect(m_socketServer, &TunnelProxySocketServer::runningChanged, this, [=](bool running){
|
||||
connect(m_socketServer, &TunnelProxySocketServer::runningChanged, this, [this](bool running){
|
||||
if (running) {
|
||||
qDebug() << "Connected with" << m_socketServer->remoteProxyServer() << m_socketServer->remoteProxyServerName() << m_socketServer->remoteProxyServerVersion() << m_socketServer->remoteProxyApiVersion();
|
||||
}
|
||||
qDebug() << "--> The tunnel proxy server is" << (running ? "running and listening for incoming connections" : "not running any more");
|
||||
});
|
||||
|
||||
connect(m_socketServer, &TunnelProxySocketServer::sslErrors, this, [=](const QList<QSslError> &errors){
|
||||
connect(m_socketServer, &TunnelProxySocketServer::sslErrors, this, [this](const QList<QSslError> &errors){
|
||||
if (m_insecure) {
|
||||
m_socketServer->ignoreSslErrors(errors);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user