1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 01:18:38 -05:00

Http server: fixed parameters passing

This commit is contained in:
f4exb 2017-11-18 10:15:29 +01:00
parent 7305f2fb00
commit 2b65fb2d62
8 changed files with 57 additions and 58 deletions

View File

@ -11,12 +11,13 @@ using namespace qtwebapp;
HttpConnectionHandler::HttpConnectionHandler(QSettings* settings, HttpRequestHandler* requestHandler, QSslConfiguration* sslConfiguration)
: QThread(), useQtSettings(true)
{
Q_ASSERT(settings!=0);
Q_ASSERT(requestHandler!=0);
this->settings=settings;
this->requestHandler=requestHandler;
this->sslConfiguration=sslConfiguration;
currentRequest=0;
Q_ASSERT(settings != 0);
Q_ASSERT(requestHandler != 0);
this->settings = settings;
this->listenerSettings = 0;
this->requestHandler = requestHandler;
this->sslConfiguration = sslConfiguration;
currentRequest = 0;
busy=false;
// Create TCP or SSL socket
@ -37,16 +38,17 @@ HttpConnectionHandler::HttpConnectionHandler(QSettings* settings, HttpRequestHan
this->start();
}
HttpConnectionHandler::HttpConnectionHandler(const HttpListenerSettings& settings, HttpRequestHandler* requestHandler, QSslConfiguration* sslConfiguration)
HttpConnectionHandler::HttpConnectionHandler(const HttpListenerSettings* settings, HttpRequestHandler* requestHandler, QSslConfiguration* sslConfiguration)
: QThread(), useQtSettings(false)
{
Q_ASSERT(requestHandler!=0);
this->settings=0;
listenerSettings=settings;
this->requestHandler=requestHandler;
this->sslConfiguration=sslConfiguration;
currentRequest=0;
busy=false;
Q_ASSERT(settings != 0);
Q_ASSERT(requestHandler != 0);
this->settings = 0;
this->listenerSettings = settings;
this->requestHandler = requestHandler;
this->sslConfiguration = sslConfiguration;
currentRequest = 0;
busy = false;
// Create TCP or SSL socket
createSocket();
@ -138,7 +140,7 @@ void HttpConnectionHandler::handleConnection(tSocketDescriptor socketDescriptor)
#endif
// Start timer for read timeout
int readTimeout = useQtSettings ? settings->value("readTimeout",10000).toInt() : listenerSettings.readTimeout;
int readTimeout = useQtSettings ? settings->value("readTimeout",10000).toInt() : listenerSettings->readTimeout;
readTimer.start(readTimeout);
// delete previous request
delete currentRequest;
@ -191,7 +193,11 @@ void HttpConnectionHandler::read()
// Create new HttpRequest object if necessary
if (!currentRequest)
{
currentRequest=new HttpRequest(settings);
if (useQtSettings) {
currentRequest = new HttpRequest(settings);
} else {
currentRequest = new HttpRequest(listenerSettings);
}
}
// Collect data for the request object
@ -202,7 +208,7 @@ void HttpConnectionHandler::read()
{
// Restart timer for read timeout, otherwise it would
// expire during large file uploads.
int readTimeout = useQtSettings ? settings->value("readTimeout",10000).toInt() : listenerSettings.readTimeout;
int readTimeout = useQtSettings ? settings->value("readTimeout",10000).toInt() : listenerSettings->readTimeout;
readTimer.start(readTimeout);
}
}
@ -296,7 +302,7 @@ void HttpConnectionHandler::read()
else
{
// Start timer for next request
int readTimeout = useQtSettings ? settings->value("readTimeout",10000).toInt() : listenerSettings.readTimeout;
int readTimeout = useQtSettings ? settings->value("readTimeout",10000).toInt() : listenerSettings->readTimeout;
readTimer.start(readTimeout);
}
delete currentRequest;

View File

@ -67,7 +67,7 @@ public:
@param requestHandler Handler that will process each incoming HTTP request
@param sslConfiguration SSL (HTTPS) will be used if not NULL
*/
HttpConnectionHandler(const HttpListenerSettings& settings, HttpRequestHandler* requestHandler, QSslConfiguration* sslConfiguration=NULL);
HttpConnectionHandler(const HttpListenerSettings* settings, HttpRequestHandler* requestHandler, QSslConfiguration* sslConfiguration=NULL);
/** Destructor */
virtual ~HttpConnectionHandler();
@ -79,16 +79,10 @@ public:
void setBusy();
/**
* Get a listener settings copy
* Get a listener settings constant reference. Can be changed on the HttpListener only.
* @return The current listener settings
*/
HttpListenerSettings getListenerSettings() const { return listenerSettings; }
/**
* Set new listener settings data
* @param Listener settings to replace current data
*/
void setListenerSettings(const HttpListenerSettings& settings) { listenerSettings = settings; }
const HttpListenerSettings *getListenerSettings() const { return listenerSettings; }
private:
@ -97,7 +91,7 @@ private:
QSettings* settings;
/** Configuration settings */
HttpListenerSettings listenerSettings;
const HttpListenerSettings* listenerSettings;
/** TCP socket of the current connection */
QTcpSocket* socket;

View File

@ -12,28 +12,29 @@ using namespace qtwebapp;
HttpConnectionHandlerPool::HttpConnectionHandlerPool(QSettings* settings, HttpRequestHandler* requestHandler)
: QObject(), useQtSettings(true)
{
Q_ASSERT(settings!=0);
this->settings=settings;
this->requestHandler=requestHandler;
this->sslConfiguration=NULL;
Q_ASSERT(settings != 0);
this->settings = settings;
this->listenerSettings = 0;
this->requestHandler = requestHandler;
this->sslConfiguration = 0;
loadSslConfig();
cleanupTimer.start(settings->value("cleanupInterval",1000).toInt());
connect(&cleanupTimer, SIGNAL(timeout()), SLOT(cleanup()));
}
HttpConnectionHandlerPool::HttpConnectionHandlerPool(const HttpListenerSettings& settings, HttpRequestHandler* requestHandler)
HttpConnectionHandlerPool::HttpConnectionHandlerPool(const HttpListenerSettings* settings, HttpRequestHandler* requestHandler)
: QObject(), useQtSettings(false)
{
this->settings=0;
listenerSettings=settings;
this->requestHandler=requestHandler;
this->sslConfiguration=NULL;
Q_ASSERT(listenerSettings != 0);
this->settings = 0;
this->listenerSettings = settings;
this->requestHandler = requestHandler;
this->sslConfiguration = 0;
loadSslConfig();
cleanupTimer.start(settings.cleanupInterval);
cleanupTimer.start(settings->cleanupInterval);
connect(&cleanupTimer, SIGNAL(timeout()), SLOT(cleanup()));
}
HttpConnectionHandlerPool::~HttpConnectionHandlerPool()
{
// delete all connection handlers and wait until their threads are closed
@ -63,7 +64,7 @@ HttpConnectionHandler* HttpConnectionHandlerPool::getConnectionHandler()
// create a new handler, if necessary
if (!freeHandler)
{
int maxConnectionHandlers = useQtSettings ? settings->value("maxThreads",100).toInt() : listenerSettings.maxThreads;
int maxConnectionHandlers = useQtSettings ? settings->value("maxThreads",100).toInt() : listenerSettings->maxThreads;
if (pool.count()<maxConnectionHandlers)
{
if (useQtSettings) {
@ -83,7 +84,7 @@ HttpConnectionHandler* HttpConnectionHandlerPool::getConnectionHandler()
void HttpConnectionHandlerPool::cleanup()
{
int maxIdleHandlers = useQtSettings ? settings->value("minThreads",1).toInt() : listenerSettings.minThreads;
int maxIdleHandlers = useQtSettings ? settings->value("minThreads",1).toInt() : listenerSettings->minThreads;
int idleCounter=0;
mutex.lock();
foreach(HttpConnectionHandler* handler, pool)
@ -106,8 +107,8 @@ void HttpConnectionHandlerPool::cleanup()
void HttpConnectionHandlerPool::loadSslConfig()
{
// If certificate and key files are configured, then load them
QString sslKeyFileName = useQtSettings ? settings->value("sslKeyFile","").toString() : listenerSettings.sslKeyFile;
QString sslCertFileName = useQtSettings ? settings->value("sslCertFile","").toString() : listenerSettings.sslCertFile;
QString sslKeyFileName = useQtSettings ? settings->value("sslKeyFile","").toString() : listenerSettings->sslKeyFile;
QString sslCertFileName = useQtSettings ? settings->value("sslCertFile","").toString() : listenerSettings->sslCertFile;
if (!sslKeyFileName.isEmpty() && !sslCertFileName.isEmpty())
{
#ifdef QT_NO_OPENSSL

View File

@ -65,7 +65,7 @@ public:
@param requestHandler The handler that will process each received HTTP request.
@warning The requestMapper gets deleted by the destructor of this pool
*/
HttpConnectionHandlerPool(const HttpListenerSettings& settings, HttpRequestHandler* requestHandler);
HttpConnectionHandlerPool(const HttpListenerSettings* settings, HttpRequestHandler* requestHandler);
/** Destructor */
virtual ~HttpConnectionHandlerPool();
@ -74,16 +74,10 @@ public:
HttpConnectionHandler* getConnectionHandler();
/**
* Get a listener settings copy
* Get a listener settings const reference. Can be changed on the HttpListener only.
* @return The current listener settings
*/
HttpListenerSettings getListenerSettings() const { return listenerSettings; }
/**
* Set new listener settings data
* @param Listener settings to replace current data
*/
void setListenerSettings(const HttpListenerSettings& settings) { listenerSettings = settings; }
const HttpListenerSettings* getListenerSettings() const { return listenerSettings; }
private:
@ -91,7 +85,7 @@ private:
QSettings* settings;
/** Settings for this pool as structure*/
HttpListenerSettings listenerSettings;
const HttpListenerSettings *listenerSettings;
/** Will be assigned to each Connectionhandler during their creation */
HttpRequestHandler* requestHandler;

View File

@ -54,7 +54,7 @@ void HttpListener::listen()
if (useQtSettings) {
pool = new HttpConnectionHandlerPool(settings, requestHandler);
} else {
pool = new HttpConnectionHandlerPool(listenerSettings, requestHandler);
pool = new HttpConnectionHandlerPool(&listenerSettings, requestHandler);
}
}
QString host = useQtSettings ? settings->value("host").toString() : listenerSettings.host;

View File

@ -15,6 +15,7 @@ using namespace qtwebapp;
HttpRequest::HttpRequest(QSettings* settings) :
useQtSettings(true)
{
Q_ASSERT(settings != 0);
status=waitForRequest;
currentSize=0;
expectedBodySize=0;
@ -23,14 +24,15 @@ HttpRequest::HttpRequest(QSettings* settings) :
tempFile=0;
}
HttpRequest::HttpRequest(const HttpListenerSettings& settings) :
HttpRequest::HttpRequest(const HttpListenerSettings* settings) :
useQtSettings(false)
{
Q_ASSERT(settings != 0);
status=waitForRequest;
currentSize=0;
expectedBodySize=0;
maxSize=settings.maxRequestSize;
maxMultiPartSize=settings.maxMultiPartSize;
maxSize=settings->maxRequestSize;
maxMultiPartSize=settings->maxMultiPartSize;
tempFile=0;
}

View File

@ -55,7 +55,7 @@ public:
Constructor.
@param settings Configuration settings as a structure
*/
HttpRequest(const HttpListenerSettings& settings);
HttpRequest(const HttpListenerSettings* settings);
/**
Destructor.

View File

@ -37,6 +37,8 @@ public:
void stop();
void setHostAndPort(const QString& host, uint16_t port);
const QString& getHost() const { return m_settings.host; }
int getPort() const { return m_settings.port; }
private:
WebAPIRequestMapper *m_requestMapper;