fixed spaces/tabs mix

This commit is contained in:
Luis Ángel San Martín
2013-08-24 10:30:54 +02:00
parent fa19b4b1ea
commit cd43bd791a
73 changed files with 1337 additions and 1343 deletions

View File

@ -6,15 +6,15 @@
#include "httprequesthandler.h"
class ErrorController : public HttpRequestHandler {
Q_OBJECT
Q_DISABLE_COPY(ErrorController);
Q_OBJECT
Q_DISABLE_COPY(ErrorController);
public:
/** Constructor */
ErrorController(int errorCode);
/** Constructor */
ErrorController(int errorCode);
/** Generates the response */
void service(HttpRequest& request, HttpResponse& response);
/** Generates the response */
void service(HttpRequest& request, HttpResponse& response);
private:
int error;
};

View File

@ -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,101 +34,101 @@
*/
class HttpResponse {
Q_DISABLE_COPY(HttpResponse)
Q_DISABLE_COPY(HttpResponse)
public:
/**
Constructor.
@param socket used to write the response
*/
HttpResponse(QTcpSocket* socket);
/**
Constructor.
@param socket used to write the response
*/
HttpResponse(QTcpSocket* socket);
/**
Set a HTTP response header
@param name name of the header
@param value value of the header
*/
void setHeader(QByteArray name, QByteArray value);
/**
Set a HTTP response header
@param name name of the header
@param value value of the header
*/
void setHeader(QByteArray name, QByteArray value);
/**
Set a HTTP response header
@param name name of the header
@param value value of the header
*/
void setHeader(QByteArray name, int value);
/**
Set a HTTP response header
@param name name of the header
@param value value of the header
*/
void setHeader(QByteArray name, int value);
/** Get the map of HTTP response headers */
QMap<QByteArray,QByteArray>& getHeaders();
/** Get the map of HTTP response headers */
QMap<QByteArray,QByteArray>& getHeaders();
/** Get the map of cookies */
QMap<QByteArray,HttpCookie>& getCookies();
/** Get the map of cookies */
QMap<QByteArray,HttpCookie>& getCookies();
/**
Set status code and description. The default is 200,OK.
*/
void setStatus(int statusCode, QByteArray description=QByteArray());
/**
Set status code and description. The default is 200,OK.
*/
void setStatus(int statusCode, QByteArray description=QByteArray());
/**
Write body data to the socket.
<p>
The HTTP status line and headers are sent automatically before the first
byte of the body gets sent.
<p>
If the response contains only a single chunk (indicated by lastPart=true),
the response is transferred in traditional mode with a Content-Length
header, which is automatically added if not already set before.
<p>
Otherwise, each part is transferred in chunked mode.
@param data Data bytes of the body
@param lastPart Indicator, if this is the last part of the response.
*/
void write(QByteArray data, bool lastPart=false);
/**
Write body data to the socket.
<p>
The HTTP status line and headers are sent automatically before the first
byte of the body gets sent.
<p>
If the response contains only a single chunk (indicated by lastPart=true),
the response is transferred in traditional mode with a Content-Length
header, which is automatically added if not already set before.
<p>
Otherwise, each part is transferred in chunked mode.
@param data Data bytes of the body
@param lastPart Indicator, if this is the last part of the response.
*/
void write(QByteArray data, bool lastPart=false);
void writeText(QString text, bool lastPart=false);
/**
Indicates wheter the body has been sent completely. Used by the connection
handler to terminate the body automatically when necessary.
*/
bool hasSentLastPart() const;
/**
Indicates wheter the body has been sent completely. Used by the connection
handler to terminate the body automatically when necessary.
*/
bool hasSentLastPart() const;
/**
Set a cookie. Cookies are sent together with the headers when the first
call to write() occurs.
*/
void setCookie(const HttpCookie& cookie);
/**
Set a cookie. Cookies are sent together with the headers when the first
call to write() occurs.
*/
void setCookie(const HttpCookie& cookie);
private:
/** Request headers */
QMap<QByteArray,QByteArray> headers;
/** Request headers */
QMap<QByteArray,QByteArray> headers;
/** Socket for writing output */
QTcpSocket* socket;
/** Socket for writing output */
QTcpSocket* socket;
/** HTTP status code*/
int statusCode;
/** HTTP status code*/
int statusCode;
/** HTTP status code description */
QByteArray statusText;
/** HTTP status code description */
QByteArray statusText;
/** Indicator whether headers have been sent */
bool sentHeaders;
/** Indicator whether headers have been sent */
bool sentHeaders;
/** Indicator whether the body has been sent completely */
bool sentLastPart;
/** Indicator whether the body has been sent completely */
bool sentLastPart;
/** Cookies */
QMap<QByteArray,HttpCookie> cookies;
/** Cookies */
QMap<QByteArray,HttpCookie> cookies;
/** Write raw data to the socket. This method blocks until all bytes have been passed to the TCP buffer */
bool writeToSocket(QByteArray data);
/** Write raw data to the socket. This method blocks until all bytes have been passed to the TCP buffer */
bool writeToSocket(QByteArray data);
/**
Write the response HTTP status and headers to the socket.
Calling this method is optional, because writeBody() calls
it automatically when required.
*/
void writeHeaders();
/**
Write the response HTTP status and headers to the socket.
Calling this method is optional, because writeBody() calls
it automatically when required.
*/
void writeHeaders();
};

View File

@ -25,72 +25,72 @@ class HttpSession {
public:
/**
Constructor.
@param canStore The session can store data, if this parameter is true.
Otherwise all calls to set() and remove() do not have any effect.
*/
HttpSession(bool canStore=false);
/**
Constructor.
@param canStore The session can store data, if this parameter is true.
Otherwise all calls to set() and remove() do not have any effect.
*/
HttpSession(bool canStore=false);
/**
Copy constructor. Creates another HttpSession object that shares the
data of the other object.
*/
HttpSession(const HttpSession& other);
/**
Copy constructor. Creates another HttpSession object that shares the
data of the other object.
*/
HttpSession(const HttpSession& other);
/**
Copy operator. Detaches from the current shared data and attaches to
the data of the other object.
*/
HttpSession& operator= (const HttpSession& other);
/**
Copy operator. Detaches from the current shared data and attaches to
the data of the other object.
*/
HttpSession& operator= (const HttpSession& other);
/**
Destructor. Detaches from the shared data.
*/
virtual ~HttpSession();
/**
Destructor. Detaches from the shared data.
*/
virtual ~HttpSession();
/** Get the unique ID of this session. This method is thread safe. */
QByteArray getId() const;
/** Get the unique ID of this session. This method is thread safe. */
QByteArray getId() const;
/**
Null sessions cannot store data. All calls to set() and remove()
do not have any effect.This method is thread safe.
*/
bool isNull() const;
/**
Null sessions cannot store data. All calls to set() and remove()
do not have any effect.This method is thread safe.
*/
bool isNull() const;
/** Set a value. This method is thread safe. */
void set(const QByteArray& key, const QVariant& value);
/** Set a value. This method is thread safe. */
void set(const QByteArray& key, const QVariant& value);
/** Remove a value. This method is thread safe. */
void remove(const QByteArray& key);
/** Remove a value. This method is thread safe. */
void remove(const QByteArray& key);
/** Get a value. This method is thread safe. */
QVariant get(const QByteArray& key) const;
/** Get a value. This method is thread safe. */
QVariant get(const QByteArray& key) const;
/** Check if a key exists. This method is thread safe. */
bool contains(const QByteArray& key) const;
/** Check if a key exists. This method is thread safe. */
bool contains(const QByteArray& key) const;
/**
Get a copy of all data stored in this session.
Changes to the session do not affect the copy and vice versa.
This method is thread safe.
*/
QMap<QByteArray,QVariant> getAll() const;
/**
Get a copy of all data stored in this session.
Changes to the session do not affect the copy and vice versa.
This method is thread safe.
*/
QMap<QByteArray,QVariant> getAll() const;
/**
Get the timestamp of last access. That is the time when the last
HttpSessionStore::getSession() has been called.
This method is thread safe.
*/
qint64 getLastAccess() const;
/**
Get the timestamp of last access. That is the time when the last
HttpSessionStore::getSession() has been called.
This method is thread safe.
*/
qint64 getLastAccess() const;
/**
Set the timestamp of last access, to renew the timeout period.
Called by HttpSessionStore::getSession().
This method is thread safe.
*/
void setLastAccess();
/**
Set the timestamp of last access, to renew the timeout period.
Called by HttpSessionStore::getSession().
This method is thread safe.
*/
void setLastAccess();
//A<>ADIDO
//sets
@ -157,8 +157,8 @@ private:
};
/** Pointer to the shared data. */
HttpSessionData* dataPtr;
/** Pointer to the shared data. */
HttpSessionData* dataPtr;
};

View File

@ -40,47 +40,47 @@
*/
class StaticFileController : public HttpRequestHandler {
Q_OBJECT
Q_DISABLE_COPY(StaticFileController);
Q_OBJECT
Q_DISABLE_COPY(StaticFileController);
public:
/** Constructor */
StaticFileController(QSettings* settings, QObject* parent = 0);
/** Constructor */
StaticFileController(QSettings* settings, QObject* parent = 0);
/** Generates the response */
void service(HttpRequest& request, HttpResponse& response);
/** Generates the response */
void service(HttpRequest& request, HttpResponse& response);
private:
/** Encoding of text files */
QString encoding;
/** Encoding of text files */
QString encoding;
/** Root directory of documents */
QString docroot;
/** Root directory of documents */
QString docroot;
/** Maximum age of files in the browser cache */
int maxAge;
/** Maximum age of files in the browser cache */
int maxAge;
struct CacheEntry {
QByteArray document;
qint64 created;
};
struct CacheEntry {
QByteArray document;
qint64 created;
};
/** Timeout for each cached file */
int cacheTimeout;
/** Timeout for each cached file */
int cacheTimeout;
/** Maximum size of files in cache, larger files are not cached */
int maxCachedFileSize;
/** Maximum size of files in cache, larger files are not cached */
int maxCachedFileSize;
/** Cache storage */
QCache<QString,CacheEntry> cache;
/** Cache storage */
QCache<QString,CacheEntry> cache;
/** Used to synchronize cache access for threads */
QMutex mutex;
/** Used to synchronize cache access for threads */
QMutex mutex;
/** Set a content-type header in the response depending on the ending of the filename */
void setContentType(QString file, HttpResponse& response) const;
/** Set a content-type header in the response depending on the ending of the filename */
void setContentType(QString file, HttpResponse& response) const;
QString getLocalizedFileName(QString fileName, QString locales, QString path) const;
QString getDeviceAwareFileName(QString fileName, QString device, QString locales, QString path) const;

View File

@ -23,7 +23,7 @@
#include "db_helper.h"
RequestMapper::RequestMapper(QObject* parent)
:HttpRequestHandler(parent) {}
:HttpRequestHandler(parent) {}
void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
QByteArray path=request.getPath();

View File

@ -22,48 +22,48 @@
#define DESCRIPTION "Comic reader and organizer"
void Startup::start() {
// Initialize the core application
QCoreApplication* app = QApplication::instance();
app->setApplicationName(APPNAME);
app->setOrganizationName(ORGANISATION);
QString configFileName=Static::getConfigDir()+"/"+QCoreApplication::applicationName()+".ini";
// Initialize the core application
QCoreApplication* app = QApplication::instance();
app->setApplicationName(APPNAME);
app->setOrganizationName(ORGANISATION);
QString configFileName=Static::getConfigDir()+"/"+QCoreApplication::applicationName()+".ini";
// Configure logging into files
QSettings* mainLogSettings=new QSettings(configFileName,QSettings::IniFormat,app);
mainLogSettings->beginGroup("mainLogFile");
QSettings* debugLogSettings=new QSettings(configFileName,QSettings::IniFormat,app);
debugLogSettings->beginGroup("debugLogFile");
Logger* logger=new DualFileLogger(mainLogSettings,debugLogSettings,10000,app);
logger->installMsgHandler();
// Configure logging into files
QSettings* mainLogSettings=new QSettings(configFileName,QSettings::IniFormat,app);
mainLogSettings->beginGroup("mainLogFile");
QSettings* debugLogSettings=new QSettings(configFileName,QSettings::IniFormat,app);
debugLogSettings->beginGroup("debugLogFile");
Logger* logger=new DualFileLogger(mainLogSettings,debugLogSettings,10000,app);
logger->installMsgHandler();
// Configure template loader and cache
QSettings* templateSettings=new QSettings(configFileName,QSettings::IniFormat,app);
templateSettings->beginGroup("templates");
Static::templateLoader=new TemplateCache(templateSettings,app);
// Configure template loader and cache
QSettings* templateSettings=new QSettings(configFileName,QSettings::IniFormat,app);
templateSettings->beginGroup("templates");
Static::templateLoader=new TemplateCache(templateSettings,app);
// Configure session store
QSettings* sessionSettings=new QSettings(configFileName,QSettings::IniFormat,app);
sessionSettings->beginGroup("sessions");
Static::sessionStore=new HttpSessionStore(sessionSettings,app);
// Configure session store
QSettings* sessionSettings=new QSettings(configFileName,QSettings::IniFormat,app);
sessionSettings->beginGroup("sessions");
Static::sessionStore=new HttpSessionStore(sessionSettings,app);
// Configure static file controller
QSettings* fileSettings=new QSettings(configFileName,QSettings::IniFormat,app);
fileSettings->beginGroup("docroot");
Static::staticFileController=new StaticFileController(fileSettings,app);
// Configure static file controller
QSettings* fileSettings=new QSettings(configFileName,QSettings::IniFormat,app);
fileSettings->beginGroup("docroot");
Static::staticFileController=new StaticFileController(fileSettings,app);
// Configure and start the TCP listener
qDebug("ServiceHelper: Starting service");
QSettings* listenerSettings=new QSettings(configFileName,QSettings::IniFormat,app);
listenerSettings->beginGroup("listener");
listener = new HttpListener(listenerSettings,new RequestMapper(app),app);
// Configure and start the TCP listener
qDebug("ServiceHelper: Starting service");
QSettings* listenerSettings=new QSettings(configFileName,QSettings::IniFormat,app);
listenerSettings->beginGroup("listener");
listener = new HttpListener(listenerSettings,new RequestMapper(app),app);
qDebug("ServiceHelper: Service has started");
qDebug("ServiceHelper: Service has started");
}
void Startup::stop() {
qDebug("ServiceHelper: Service has been stopped");
// QCoreApplication destroys all objects that have been created in start().
qDebug("ServiceHelper: Service has been stopped");
// QCoreApplication destroys all objects that have been created in start().
delete listener;
}

View File

@ -18,12 +18,12 @@ private:
HttpListener * listener;
public:
/** Constructor */
Startup();
/** Constructor */
Startup();
/** Start the server */
void start();
void start();
/** Stop the server */
void stop();
void stop();
QString getPort();
protected: