1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-22 17:45:48 -05:00

HttpServer: use settings structures in place of QSettings (3)

This commit is contained in:
f4exb 2017-11-13 01:26:48 +01:00
parent 3fb9d56d85
commit ef2f591bcd
4 changed files with 52 additions and 9 deletions

View File

@ -6,18 +6,36 @@
#include "httplistener.h"
#include "httpconnectionhandler.h"
#include "httpconnectionhandlerpool.h"
#include "httplistenersettings.h"
#include <QCoreApplication>
using namespace qtwebapp;
HttpListener::HttpListener(QSettings* settings, HttpRequestHandler* requestHandler, QObject *parent)
: QTcpServer(parent)
: QTcpServer(parent), useQtSettings(true)
{
Q_ASSERT(settings!=0);
Q_ASSERT(requestHandler!=0);
pool=NULL;
this->settings=settings;
this->requestHandler=requestHandler;
Q_ASSERT(settings != 0);
Q_ASSERT(requestHandler != 0);
pool = 0;
this->settings = settings;
this->listenerSettings = 0;
this->requestHandler = requestHandler;
// Reqister type of socketDescriptor for signal/slot handling
qRegisterMetaType<tSocketDescriptor>("tSocketDescriptor");
// Start listening
listen();
}
HttpListener::HttpListener(HttpListenerSettings* settings, HttpRequestHandler* requestHandler, QObject *parent)
: QTcpServer(parent), useQtSettings(false)
{
Q_ASSERT(settings != 0);
Q_ASSERT(requestHandler != 0);
pool = 0;
this->settings = 0;
this->listenerSettings = settings;
this->requestHandler = requestHandler;
// Reqister type of socketDescriptor for signal/slot handling
qRegisterMetaType<tSocketDescriptor>("tSocketDescriptor");
// Start listening
@ -38,8 +56,8 @@ void HttpListener::listen()
{
pool=new HttpConnectionHandlerPool(settings,requestHandler);
}
QString host = settings->value("host").toString();
int port=settings->value("port").toInt();
QString host = useQtSettings ? settings->value("host").toString() : listenerSettings->host;
int port = useQtSettings ? settings->value("port").toInt() : listenerSettings->port;
QTcpServer::listen(host.isEmpty() ? QHostAddress::Any : QHostAddress(host), port);
if (!isListening())
{

View File

@ -41,6 +41,8 @@ namespace qtwebapp {
@see HttpRequest for description of config settings maxRequestSize and maxMultiPartSize
*/
class HttpListenerSettings;
class DECLSPEC HttpListener : public QTcpServer {
Q_OBJECT
Q_DISABLE_COPY(HttpListener)
@ -55,6 +57,7 @@ public:
@warning Ensure to close or delete the listener before deleting the request handler.
*/
HttpListener(QSettings* settings, HttpRequestHandler* requestHandler, QObject* parent = NULL);
HttpListener(HttpListenerSettings* settings, HttpRequestHandler* requestHandler, QObject* parent = NULL);
/** Destructor */
virtual ~HttpListener();
@ -79,6 +82,7 @@ private:
/** Configuration settings for the HTTP server */
QSettings* settings;
HttpListenerSettings* listenerSettings;
/** Point to the reuqest handler which processes all HTTP requests */
HttpRequestHandler* requestHandler;
@ -86,6 +90,9 @@ private:
/** Pool of connection handlers */
HttpConnectionHandlerPool* pool;
/** Settings flag */
bool useQtSettings;
signals:
/**

View File

@ -4,13 +4,15 @@
*/
#include "httprequest.h"
#include "httplistenersettings.h"
#include <QList>
#include <QDir>
#include "httpcookie.h"
using namespace qtwebapp;
HttpRequest::HttpRequest(QSettings* settings)
HttpRequest::HttpRequest(QSettings* settings) : useQtSettings(true)
{
status=waitForRequest;
currentSize=0;
@ -20,6 +22,16 @@ HttpRequest::HttpRequest(QSettings* settings)
tempFile=NULL;
}
HttpRequest::HttpRequest(HttpListenerSettings* settings) : useQtSettings(false)
{
status=waitForRequest;
currentSize=0;
expectedBodySize=0;
maxSize=settings->maxRequestSize;
maxMultiPartSize=settings->maxMultiPartSize;
tempFile=NULL;
}
void HttpRequest::readRequest(QTcpSocket* socket)
{

View File

@ -35,6 +35,8 @@ namespace qtwebapp {
The body is always a little larger than the file itself.
*/
class HttpListenerSettings;
class DECLSPEC HttpRequest {
Q_DISABLE_COPY(HttpRequest)
friend class HttpSessionStore;
@ -49,6 +51,7 @@ public:
@param settings Configuration settings
*/
HttpRequest(QSettings* settings);
HttpRequest(HttpListenerSettings* settings);
/**
Destructor.
@ -232,6 +235,9 @@ private:
/** Buffer for collecting characters of request and header lines */
QByteArray lineBuffer;
/** settings flag */
bool useQtSettings;
};
} // end of namespace