mirror of
https://github.com/YACReader/yacreader
synced 2025-08-03 12:55:32 -04:00
fixed LibraryServer in Qt5
moved server_log to standardPath
This commit is contained in:
@ -29,6 +29,12 @@
|
||||
@see HttpRequest for description of config settings maxRequestSize and maxMultiPartSize
|
||||
*/
|
||||
|
||||
#if QT_VERSION >= 0x050000
|
||||
typedef qintptr tSocketDescriptor;
|
||||
#else
|
||||
typedef int tSocketDescriptor;
|
||||
#endif
|
||||
|
||||
class HttpConnectionHandler : public QThread {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(HttpConnectionHandler)
|
||||
@ -79,7 +85,7 @@ public slots:
|
||||
Received from from the listener, when the handler shall start processing a new connection.
|
||||
@param socketDescriptor references the accepted connection.
|
||||
*/
|
||||
void handleConnection(int socketDescriptor);
|
||||
void handleConnection(tSocketDescriptor socketDescriptor);
|
||||
|
||||
private slots:
|
||||
|
||||
|
@ -12,6 +12,9 @@ HttpListener::HttpListener(QSettings* settings, HttpRequestHandler* requestHandl
|
||||
: QTcpServer(parent)
|
||||
{
|
||||
Q_ASSERT(settings!=0);
|
||||
// Reqister type of socketDescriptor for signal/slot handling
|
||||
qRegisterMetaType<tSocketDescriptor>("tSocketDescriptor");
|
||||
// Create connection handler pool
|
||||
this->settings=settings;
|
||||
pool=new HttpConnectionHandlerPool(settings,requestHandler);
|
||||
// Start listening
|
||||
@ -39,8 +42,7 @@ HttpListener::~HttpListener() {
|
||||
qDebug("HttpListener: destroyed");
|
||||
}
|
||||
|
||||
|
||||
void HttpListener::incomingConnection(int socketDescriptor) {
|
||||
void HttpListener::incomingConnection(tSocketDescriptor socketDescriptor) {
|
||||
#ifdef SUPERVERBOSE
|
||||
qDebug("HttpListener: New connection");
|
||||
#endif
|
||||
@ -50,9 +52,9 @@ void HttpListener::incomingConnection(int socketDescriptor) {
|
||||
if (freeHandler) {
|
||||
// The descriptor is passed via signal/slot because the handler lives in another
|
||||
// thread and cannot open the socket when called by another thread.
|
||||
connect(this,SIGNAL(handleConnection(int)),freeHandler,SLOT(handleConnection(int)));
|
||||
connect(this,SIGNAL(handleConnection(tSocketDescriptor)),freeHandler,SLOT(handleConnection(tSocketDescriptor)));
|
||||
emit handleConnection(socketDescriptor);
|
||||
disconnect(this,SIGNAL(handleConnection(int)),freeHandler,SLOT(handleConnection(int)));
|
||||
disconnect(this,SIGNAL(handleConnection(tSocketDescriptor)),freeHandler,SLOT(handleConnection(tSocketDescriptor)));
|
||||
}
|
||||
else {
|
||||
// Reject the connection
|
||||
|
@ -14,9 +14,8 @@
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
/**
|
||||
Listens for incoming TCP connections and passes control to
|
||||
one of the pooled connection handlers. This class is also
|
||||
responsible for managing the pool.
|
||||
Listens for incoming TCP connections and and passes all incoming HTTP requests to your implementation of HttpRequestHandler,
|
||||
which processes the request and generates the response (usually a HTML document).
|
||||
<p>
|
||||
Example for the required settings in the config file:
|
||||
<code><pre>
|
||||
@ -43,7 +42,7 @@ public:
|
||||
Constructor.
|
||||
@param settings Configuration settings for the HTTP server. Must not be 0.
|
||||
@param requestHandler Processes each received HTTP request, usually by dispatching to controller classes.
|
||||
@param parent Parent object
|
||||
@param parent Parent object.
|
||||
*/
|
||||
HttpListener(QSettings* settings, HttpRequestHandler* requestHandler, QObject* parent = 0);
|
||||
|
||||
@ -53,7 +52,7 @@ public:
|
||||
protected:
|
||||
|
||||
/** Serves new incoming connection requests */
|
||||
void incomingConnection(int socketDescriptor);
|
||||
void incomingConnection(tSocketDescriptor socketDescriptor);
|
||||
|
||||
private:
|
||||
|
||||
@ -69,7 +68,8 @@ signals:
|
||||
Emitted when the connection handler shall process a new incoming onnection.
|
||||
@param socketDescriptor references the accepted connection.
|
||||
*/
|
||||
void handleConnection(int socketDescriptor);
|
||||
|
||||
void handleConnection(tSocketDescriptor socketDescriptor);
|
||||
|
||||
};
|
||||
|
||||
|
@ -16,15 +16,15 @@
|
||||
<p>
|
||||
Example code for proper response generation:
|
||||
<code><pre>
|
||||
response.setStatus(200,"OK"); // optional, because this is the default
|
||||
response.writeBody("Hello");
|
||||
response.writeBody("World!",true);
|
||||
response.setStatus(200,"OK"); // optional, because this is the default
|
||||
response.writeBody("Hello");
|
||||
response.writeBody("World!",true);
|
||||
</pre></code>
|
||||
<p>
|
||||
Example how to return an error:
|
||||
<code><pre>
|
||||
response.setStatus(500,"server error");
|
||||
response.write("The request cannot be processed because the servers is broken",true);
|
||||
response.setStatus(500,"server error");
|
||||
response.write("The request cannot be processed because the servers is broken",true);
|
||||
</pre></code>
|
||||
<p>
|
||||
For performance reason, writing a single or few large packets is better than writing
|
||||
@ -34,7 +34,7 @@
|
||||
*/
|
||||
|
||||
class HttpResponse {
|
||||
Q_DISABLE_COPY(HttpResponse)
|
||||
Q_DISABLE_COPY(HttpResponse)
|
||||
public:
|
||||
|
||||
/**
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <QDateTime>
|
||||
#include "httpsession.h"
|
||||
#include "static.h"
|
||||
#include <QApplication>
|
||||
|
||||
StaticFileController::StaticFileController(QSettings* settings, QObject* parent)
|
||||
:HttpRequestHandler(parent)
|
||||
@ -23,8 +24,8 @@ StaticFileController::StaticFileController(QSettings* settings, QObject* parent)
|
||||
if (QDir::isRelativePath(docroot))
|
||||
#endif
|
||||
{
|
||||
QFileInfo configFile(settings->fileName());
|
||||
docroot=QFileInfo(configFile.absolutePath(),docroot).absoluteFilePath();
|
||||
QFileInfo configFile(QApplication::applicationDirPath());
|
||||
docroot=QFileInfo(QApplication::applicationDirPath(),docroot).absoluteFilePath();
|
||||
}
|
||||
qDebug("StaticFileController: docroot=%s, encoding=%s, maxAge=%i",qPrintable(docroot),qPrintable(encoding),maxAge);
|
||||
maxCachedFileSize=settings->value("maxCachedFileSize","65536").toInt();
|
||||
@ -202,4 +203,4 @@ QString StaticFileController::getDeviceAwareFileName(QString fileName, QString d
|
||||
return completeFileName; //existe un archivo espec<65>fico para este dispositivo y locales
|
||||
else
|
||||
return getLocalizedFileName(fileName,locales,path); //no hay archivo espec<65>fico para el dispositivo, pero puede haberlo para estas locales
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user