mirror of
https://bitbucket.org/smil3y/kde-playground.git
synced 2025-02-23 18:32:51 +00:00
khttpd: adjust to kdnssd library changes
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
e0dd95c976
commit
9b30ea4993
1 changed files with 10 additions and 15 deletions
|
@ -16,7 +16,7 @@
|
||||||
Boston, MA 02110-1301, USA.
|
Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <kdnssd.h>
|
||||||
#include <KAboutData>
|
#include <KAboutData>
|
||||||
#include <KCmdLineArgs>
|
#include <KCmdLineArgs>
|
||||||
#include <KApplication>
|
#include <KApplication>
|
||||||
|
@ -29,7 +29,6 @@
|
||||||
#include <QTcpServer>
|
#include <QTcpServer>
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
#include <QHostInfo>
|
#include <QHostInfo>
|
||||||
#include <DNSSD/PublicService>
|
|
||||||
|
|
||||||
static QByteArray contentForDirectory(const QString &path, const QString &basedir)
|
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)) {
|
if (QDir::cleanPath(path) == QDir::cleanPath(basedir)) {
|
||||||
dirfilters = (QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot);
|
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);
|
QDir dir(path);
|
||||||
foreach (const QFileInfo &fileinfo, dir.entryInfoList(dirfilters, dirsortflags)) {
|
foreach (const QFileInfo &fileinfo, dir.entryInfoList(dirfilters, dirsortflags)) {
|
||||||
const QString fullpath = path.toLocal8Bit() + QLatin1Char('/') + fileinfo.fileName();
|
const QString fullpath = path.toLocal8Bit() + QLatin1Char('/') + fileinfo.fileName();
|
||||||
// chromium does weird stuff if the link starts with two slashes - removes, the host and
|
// 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()));
|
const QString cleanpath = QDir::cleanPath(fullpath.mid(basedir.size()));
|
||||||
|
|
||||||
data.append(" <tr>");
|
data.append(" <tr>");
|
||||||
|
@ -144,31 +144,26 @@ public Q_SLOTS:
|
||||||
private:
|
private:
|
||||||
QTcpServer m_tcpserver;
|
QTcpServer m_tcpserver;
|
||||||
QString m_directory;
|
QString m_directory;
|
||||||
DNSSD::PublicService *m_publicservice;
|
KDNSSD m_kdnssd;
|
||||||
};
|
};
|
||||||
|
|
||||||
KHTTPD::KHTTPD(QObject *parent)
|
KHTTPD::KHTTPD(QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent)
|
||||||
m_publicservice(nullptr)
|
|
||||||
{
|
{
|
||||||
connect(&m_tcpserver, SIGNAL(newConnection()), this, SLOT(handleRequest()));
|
connect(&m_tcpserver, SIGNAL(newConnection()), this, SLOT(handleRequest()));
|
||||||
}
|
}
|
||||||
|
|
||||||
KHTTPD::~KHTTPD()
|
KHTTPD::~KHTTPD()
|
||||||
{
|
{
|
||||||
if (m_publicservice) {
|
m_kdnssd.unpublishService();
|
||||||
m_publicservice->stop();
|
|
||||||
delete m_publicservice;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KHTTPD::start(const QString &host, int port, const QString &directory)
|
bool KHTTPD::start(const QString &host, int port, const QString &directory)
|
||||||
{
|
{
|
||||||
m_publicservice = new DNSSD::PublicService(
|
m_kdnssd.publishService(
|
||||||
i18n("KHTTPD@%1", QHostInfo::localHostName()),
|
"_http._tcp", port,
|
||||||
"_http._tcp", port
|
i18n("KHTTPD@%1", QHostInfo::localHostName())
|
||||||
);
|
);
|
||||||
m_publicservice->publishAsync();
|
|
||||||
m_directory = directory;
|
m_directory = directory;
|
||||||
QHostAddress address;
|
QHostAddress address;
|
||||||
address.setAddress(host);
|
address.setAddress(host);
|
||||||
|
|
Loading…
Add table
Reference in a new issue