Inheritance diagram for QcjHttpService:

Public Types | |
| enum | ErrorCodes { OK = 200, Created, Accepted, NonAuthorizedContent, NoContent, RevertContent, PartialContent, MultipleChoices = 300, MovedPermanently, Found, SeeOther, NotModified, UseProxy, Unused, TemporyRedirect, BadRequest = 400, Unauthorized, PaymentRequired, Forbidden, NotFound, MethodNotAllowed, NotAcceptable, ProxyAuthenticationRequired, RequestTimeout, Conflict, Gone, LengthRequired, PreconditionFailed, RequestEntityTooLong, RequestURITooLong, UnsupportedMediaType, RequestedRangeNotSatisfiable, ExpectationFailed, InternalServerError = 500, NotImplimented, BadGateway, ServiceUnavailable, GatewayTimeout, HTTPVersionNotSupported } |
Signals | |
| void | closeSocket (QTcpSocket *) |
| void | error (QAbstractSocket::SocketError) |
| void | send (QTcpSocket *, QByteArray) |
Public Member Functions | |
| void | addMethods (QStringList *extraMethods) |
| QcjHttpService (int socketDescripter, QObject *parent=0, int max_req=10, QStringList *extraMethods=0, long ttl=200) | |
| void | setMaxRequests (int max_req) |
| void | setTimeToLive (long ttl) |
Protected Slots | |
| void | errorResponse (enum ErrorCodes ec, QString msg) |
| void | haveData () |
| void | haveDisconnect () |
| void | haveError (QAbstractSocket::SocketError) |
| void | haveTimeOut () |
| void | haveTimeout () |
| void | processResponse (QMap< QString, QVariant > rsp) |
Protected Member Functions | |
| virtual void | clearLocks () |
| QMap< QString, QString > | parseArguments (QString args) |
| virtual void | processRequest (QMap< QString, QVariant > *, QMap< QString, QVariant > *) |
| void | run () |
| void | sendResponse (QMap< QString, QVariant > *rsp) |
Protected Attributes | |
| QMutex | bufLock |
| QTimer * | errTimer |
| bool | exitFlag |
| qlonglong | expectingBytes |
| QWaitCondition | haveInput |
| QByteArray | inArray |
| bool | inBody |
| QBuffer | inBuffer |
| QDataStream | inStream |
| QString | lineBuffer |
| int | maxRequests |
| QStringList | methods |
| Qt::HANDLE | myThreadId |
| QMap< QString, QVariant > * | request |
| QTcpSocket * | sock |
| int | socknum |
| long | timeToLive |
| QTimer * | ttlTimer |
This class is a base class for providing core functionalitity for an http service. It provides basic protocol packaging and unpackaging. It is expected to be subclassed to provide the actual functionality.
The actual processing of requests are performed on a seperate thread from the main application. While the new thread which is created for this object handles parsing the requests, processing then and formulating appropriate responses, the main application thread is still responsible for handling the basic IO for the object. The passing of data back and forth from the IO and this object is done through signals and slots and a couple of buffers. This is mandated by the fact that the Qt library cannot handle socket operations to be called by a thread from which the socket wasn't created under.
Definition at line 38 of file QcjHttpService.h.
These names provide a symbolic method to reference the various status codes which are defined the the w3c.
200 OK 201 Created 202 Accepted 203 NoAuthorizedContent 204 NoContent 205 RevertContent 206 PartialContent300 MultipleChoices 301 MovedPermanently 302 Found 303 SeeOther 304 NotModified 305 UseProxy 306 Unused 307 TemporaryRedirect400 BadRequest 401 Unauthorized 402 PaymentRequired 403 Forbidden 404 NotFound 405 MethodNotAllowed 406 NotAcceptable 407 ProxyAuthenticationRequired 408 RequestTimeout 409 Conflict 410 Gone 411 LengthRequired 412 PreconditionFailed 413 RequestEntityTooLong 414 RequestURITooLong 415 UnsupportedMediaType 416 RequestedRangeNotSatisfiable 417 ExpectationFailed500 InternalServerError 501 NotImplimented 502 BadGateway 503 ServiceUnavailable 504 GatewayTimeout 505 HTTPVersionNotSupported Definition at line 98 of file QcjHttpService.h.
| QcjHttpService::QcjHttpService | ( | int | socketDescripter, | |
| QObject * | parent = 0, |
|||
| int | max_req = 10, |
|||
| QStringList * | extraMethods = 0, |
|||
| long | ttl = 200 | |||
| ) |
This is the constructor. It creates it's QThread object, then sets up to handle requests from the socket whose number is passed in the parameter socketDescripter. The parameter max_req specifies how many requests the service should handle before quiting. The parameter ttl specified how long thie service should stay a live in milliseconds.
By default, the HTTP methods GET, POST, PUT, HEAD, TRACE, OPTIONS and DELETE are recognized. For flexibility and custimization, additional methods may be passed in using the parameter extraMethods.
Definition at line 66 of file QcjHttpService.cpp.
References error(), haveData(), haveDisconnect(), haveError(), inArray, inBody, inBuffer, inStream, maxRequests, methods, request, sock, socknum, and timeToLive.
| void QcjHttpService::addMethods | ( | QStringList * | extraMethods | ) | [inline] |
This function allows the caller to add additional HTTP methods which will be recognized by this object.
Definition at line 120 of file QcjHttpService.h.
References methods.
| void QcjHttpService::errorResponse | ( | enum ErrorCodes | ec, | |
| QString | msg | |||
| ) | [protected, slot] |
This function creates an error response and sends it out
Definition at line 546 of file QcjHttpService.cpp.
References closeSocket(), sendResponse(), and sock.
Referenced by haveTimeout(), DbPhotoService::processRequest(), and run().
| void QcjHttpService::haveData | ( | ) | [protected, slot] |
This function recieves incomming data from the socket. It is not actually executed as part of the thread, but by the thread the socket was created in.
Definition at line 370 of file QcjHttpService.cpp.
References bufLock, haveInput, inArray, and sock.
Referenced by QcjHttpService().
| void QcjHttpService::haveError | ( | QAbstractSocket::SocketError | err | ) | [protected, slot] |
This slot is called when an error is detected on the socket. It sets up to terminate the thread.
Definition at line 516 of file QcjHttpService.cpp.
References exitFlag, haveInput, and myThreadId.
Referenced by QcjHttpService().
| void QcjHttpService::haveTimeOut | ( | ) | [protected, slot] |
This is called when the ttl time expires. It emits the closeSocket() signal triggering the threads demise.
Definition at line 581 of file QcjHttpService.cpp.
References closeSocket(), and sock.
Referenced by run().
| void QcjHttpService::haveTimeout | ( | ) | [protected, slot] |
This slot is called when senders are too slow sending in their requests. It generates a error.
Definition at line 506 of file QcjHttpService.cpp.
References errorResponse().
| void QcjHttpService::processResponse | ( | QMap< QString, QVariant > | rsp | ) | [protected, slot] |
This function processes responses and sends them out. If the maximum number of requests have been fulfilled, it will emit the signal closeSocket triggering this threads ultimate demise.
Definition at line 408 of file QcjHttpService.cpp.
References closeSocket(), maxRequests, sendResponse(), and sock.
Referenced by run().
| void QcjHttpService::setMaxRequests | ( | int | max_req | ) | [inline] |
void setMaxRequests(int max_req)
This function sets the maximum number of requests to be processed by this object.
Definition at line 132 of file QcjHttpService.h.
References maxRequests.
| void QcjHttpService::setTimeToLive | ( | long | ttl | ) | [inline] |
This function sets the time, in milliseconds, for this object to process requests before dying.
Definition at line 143 of file QcjHttpService.h.
References timeToLive.
1.5.0