From 9b30ea499342d4af49aeb5083f80f784c72d65fe Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Thu, 5 May 2022 22:58:51 +0300 Subject: [PATCH] khttpd: adjust to kdnssd library changes Signed-off-by: Ivailo Monev --- khttpd/khttpd.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/khttpd/khttpd.cpp b/khttpd/khttpd.cpp index bdd4353b..854dcfe9 100644 --- a/khttpd/khttpd.cpp +++ b/khttpd/khttpd.cpp @@ -16,7 +16,7 @@ Boston, MA 02110-1301, USA. */ - +#include #include #include #include @@ -29,7 +29,6 @@ #include #include #include -#include static QByteArray contentForDirectory(const QString &path, const QString &basedir) { @@ -46,12 +45,13 @@ static QByteArray contentForDirectory(const QString &path, const QString &basedi if (QDir::cleanPath(path) == QDir::cleanPath(basedir)) { dirfilters = (QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot); } - QDir::SortFlags dirsortflags = (QDir::Name | QDir::DirsFirst); + const QDir::SortFlags dirsortflags = (QDir::Name | QDir::DirsFirst); QDir dir(path); foreach (const QFileInfo &fileinfo, dir.entryInfoList(dirfilters, dirsortflags)) { const QString fullpath = path.toLocal8Bit() + QLatin1Char('/') + fileinfo.fileName(); // chromium does weird stuff if the link starts with two slashes - removes, the host and - // port part of the link and converts the first directory to lower-case + // port part of the link (or rather does not prepend them) and converts the first directory + // to lower-case const QString cleanpath = QDir::cleanPath(fullpath.mid(basedir.size())); data.append(" "); @@ -144,31 +144,26 @@ public Q_SLOTS: private: QTcpServer m_tcpserver; QString m_directory; - DNSSD::PublicService *m_publicservice; + KDNSSD m_kdnssd; }; KHTTPD::KHTTPD(QObject *parent) - : QObject(parent), - m_publicservice(nullptr) + : QObject(parent) { connect(&m_tcpserver, SIGNAL(newConnection()), this, SLOT(handleRequest())); } KHTTPD::~KHTTPD() { - if (m_publicservice) { - m_publicservice->stop(); - delete m_publicservice; - } + m_kdnssd.unpublishService(); } bool KHTTPD::start(const QString &host, int port, const QString &directory) { - m_publicservice = new DNSSD::PublicService( - i18n("KHTTPD@%1", QHostInfo::localHostName()), - "_http._tcp", port + m_kdnssd.publishService( + "_http._tcp", port, + i18n("KHTTPD@%1", QHostInfo::localHostName()) ); - m_publicservice->publishAsync(); m_directory = directory; QHostAddress address; address.setAddress(host);