Files
cantata/web/http/basichttpserver.cpp
Craig Drummond 605af484f7 Initial import of *VERY* incomplete, and not fully functional Cantata
webapp. Mainly used to test SQLite backend for storing MPD db.
2015-06-01 22:57:49 +01:00

50 lines
1.1 KiB
C++

/**
* @file
*
* @author Petr Bravenec petr.bravenec@hobrasoft.cz
* @author Craig Drummond
*/
#include "basichttpserver.h"
#include "httpconnection.h"
#include "httprequesthandler.h"
#include "staticfilecontroller.h"
#include <QSettings>
#include <QDebug>
bool BasicHttpServer::dbgEnabled=false;
#define DBUG if (BasicHttpServer::debugEnabled()) qWarning() << metaObject()->className() << (void *)this << __FUNCTION__
BasicHttpServer::BasicHttpServer(QObject *parent, const QSettings *s)
: QTcpServer(parent)
, serverSettings(s)
, staticFiles(0)
{
}
bool BasicHttpServer::start()
{
close();
connect(this, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
listen(QHostAddress::Any, serverSettings->value("http/port", 80).toInt());
return isListening();
}
void BasicHttpServer::slotNewConnection()
{
while (hasPendingConnections()) {
DBUG;
new HttpConnection(this, nextPendingConnection());
}
}
HttpRequestHandler * BasicHttpServer::getHandler(const QString &path)
{
Q_UNUSED(path)
if (!staticFiles) {
staticFiles=new StaticFileController(serverSettings);
}
return staticFiles;
}