From 6091d24574fbca95921f0f4cfea7d6d6546246ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Fri, 8 Aug 2025 13:53:44 +0200 Subject: [PATCH] httpcommander: Add Qt6 support --- httpcommander/httpcommander.pro | 4 +-- httpcommander/httpsimpleserver.cpp | 30 +++++++++---------- httpcommander/httpsimpleserver.h | 8 ++--- .../integrationpluginhttpcommander.cpp | 16 ++++++---- .../integrationpluginhttpcommander.h | 9 ++---- 5 files changed, 30 insertions(+), 37 deletions(-) diff --git a/httpcommander/httpcommander.pro b/httpcommander/httpcommander.pro index e7f52426..f7d0af7a 100644 --- a/httpcommander/httpcommander.pro +++ b/httpcommander/httpcommander.pro @@ -1,8 +1,6 @@ include(../plugins.pri) -QT += network - -TARGET = $$qtLibraryTarget(nymea_integrationpluginhttpcommander) +QT *= network SOURCES += \ integrationpluginhttpcommander.cpp \ diff --git a/httpcommander/httpsimpleserver.cpp b/httpcommander/httpsimpleserver.cpp index 576f8b6e..f9b075b9 100644 --- a/httpcommander/httpsimpleserver.cpp +++ b/httpcommander/httpsimpleserver.cpp @@ -1,6 +1,6 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* Copyright 2013 - 2020, nymea GmbH +* Copyright 2013 - 2025, nymea GmbH * Contact: contact@nymea.io * * This file is part of nymea. @@ -30,14 +30,13 @@ #include "httpsimpleserver.h" -#include "types/statetype.h" #include "extern-plugininfo.h" #include #include #include #include -#include +#include #include HttpSimpleServer::HttpSimpleServer(quint16 port, QObject *parent): @@ -58,8 +57,8 @@ void HttpSimpleServer::incomingConnection(qintptr socket) // works asynchronously, this means that all the communication is done // in the two slots readClient() and discardClient(). QTcpSocket* tcpSocket = new QTcpSocket(this); - connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readClient())); - connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(discardClient())); + connect(tcpSocket, &QTcpSocket::readyRead, this, &HttpSimpleServer::readClient); + connect(tcpSocket, &QTcpSocket::disconnected, this, &HttpSimpleServer::discardClient); tcpSocket->setSocketDescriptor(socket); } @@ -69,17 +68,16 @@ void HttpSimpleServer::readClient() // This slot is called when the client sent data to the server. The // server looks if it was a get request and sends a very simple HTML // document back. - QTcpSocket* tcpSocket = static_cast(sender()); + QTcpSocket *tcpSocket = static_cast(sender()); if (tcpSocket->canReadLine()) { - QByteArray data = tcpSocket->readAll(); - QStringList tokens = QString(data).split(QRegExp("[ \r\n][ \r\n]*")); + QStringList tokens = QString(data).split(QRegularExpression("[ \r\n][ \r\n]*")); qCDebug(dcHttpCommander()) << "Http Request, type" << tokens[0] << "path" << tokens[1] << "body" << tokens.last(); if ((tokens[0] == "GET") || - (tokens[0] == "PUT") || - (tokens[0] == "POST") || - (tokens[0] == "DELETE")) { + (tokens[0] == "PUT") || + (tokens[0] == "POST") || + (tokens[0] == "DELETE")) { QTextStream os(tcpSocket); os.setAutoDetectUnicode(true); @@ -96,16 +94,16 @@ void HttpSimpleServer::readClient() void HttpSimpleServer::discardClient() { - QTcpSocket* socket = static_cast(sender()); + QTcpSocket *socket = static_cast(sender()); socket->deleteLater(); } QString HttpSimpleServer::generateHeader() { QString contentHeader( - "HTTP/1.0 200 Ok\r\n" - "Content-Type: text/html; charset=\"utf-8\"\r\n" - "\r\n" - ); + "HTTP/1.0 200 Ok\r\n" + "Content-Type: text/html; charset=\"utf-8\"\r\n" + "\r\n" + ); return contentHeader; } diff --git a/httpcommander/httpsimpleserver.h b/httpcommander/httpsimpleserver.h index 075a9822..23160921 100644 --- a/httpcommander/httpsimpleserver.h +++ b/httpcommander/httpsimpleserver.h @@ -1,6 +1,6 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* Copyright 2013 - 2020, nymea GmbH +* Copyright 2013 - 2025, nymea GmbH * Contact: contact@nymea.io * * This file is part of nymea. @@ -31,15 +31,12 @@ #ifndef HTTPSIMPLESERVER1_H #define HTTPSIMPLESERVER1_H -#include "typeutils.h" - #include #include #include #include -class Device; -class DevicePlugin; +#include class HttpSimpleServer : public QTcpServer { @@ -48,6 +45,7 @@ public: HttpSimpleServer(quint16 port, QObject* parent = nullptr); ~HttpSimpleServer() override; + void incomingConnection(qintptr socket) override; signals: diff --git a/httpcommander/integrationpluginhttpcommander.cpp b/httpcommander/integrationpluginhttpcommander.cpp index de29fce0..6f3086f2 100644 --- a/httpcommander/integrationpluginhttpcommander.cpp +++ b/httpcommander/integrationpluginhttpcommander.cpp @@ -1,6 +1,6 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* Copyright 2013 - 2020, nymea GmbH +* Copyright 2013 - 2025, nymea GmbH * Contact: contact@nymea.io * * This file is part of nymea. @@ -29,8 +29,12 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include "integrationpluginhttpcommander.h" -#include "network/networkaccessmanager.h" #include "plugininfo.h" + +#include + +#include +#include #include IntegrationPluginHttpCommander::IntegrationPluginHttpCommander() @@ -40,14 +44,14 @@ IntegrationPluginHttpCommander::IntegrationPluginHttpCommander() void IntegrationPluginHttpCommander::setupThing(ThingSetupInfo *info) { Thing *thing = info->thing(); - qDebug(dcHttpCommander()) << "Setup thing" << thing->name() << thing->params(); + qCDebug(dcHttpCommander()) << "Setup thing" << thing->name() << thing->params(); if (thing->thingClassId() == httpRequestThingClassId) { QUrl url = thing->paramValue(httpRequestThingUrlParamTypeId).toUrl(); if (!url.isValid()) { - qDebug(dcHttpCommander()) << "Given URL is not valid"; + qCDebug(dcHttpCommander()) << "Given URL is not valid"; //: Error setting up thing return info->finish(Thing::ThingErrorInvalidParameter, QT_TR_NOOP("The given url is not valid.")); } @@ -92,9 +96,9 @@ void IntegrationPluginHttpCommander::executeAction(ThingActionInfo *info) info->finish(Thing::ThingErrorInvalidParameter); return; } - connect(reply, &QNetworkReply::finished, this, [thing, reply, this](){ - qDebug(dcHttpCommander()) << "POST reply finished"; + connect(reply, &QNetworkReply::finished, this, [thing, reply](){ + qCDebug(dcHttpCommander()) << "POST reply finished"; QByteArray data = reply->readAll(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); diff --git a/httpcommander/integrationpluginhttpcommander.h b/httpcommander/integrationpluginhttpcommander.h index 6e83f43e..faccc281 100644 --- a/httpcommander/integrationpluginhttpcommander.h +++ b/httpcommander/integrationpluginhttpcommander.h @@ -1,6 +1,6 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* Copyright 2013 - 2020, nymea GmbH +* Copyright 2013 - 2025, nymea GmbH * Contact: contact@nymea.io * * This file is part of nymea. @@ -31,13 +31,9 @@ #ifndef INTEGRATIONPLUGINHTTPCOMMANDER_H #define INTEGRATIONPLUGINHTTPCOMMANDER_H -#include "integrations/integrationplugin.h" -#include "plugintimer.h" +#include #include "httpsimpleserver.h" -#include -#include - class IntegrationPluginHttpCommander : public IntegrationPlugin { Q_OBJECT @@ -46,7 +42,6 @@ class IntegrationPluginHttpCommander : public IntegrationPlugin Q_INTERFACES(IntegrationPlugin) public: - explicit IntegrationPluginHttpCommander(); void setupThing(ThingSetupInfo *info) override;