QcjHttpService Class Reference

Http protocol service. More...

Inheritance diagram for QcjHttpService:

DbPhotoService List of all members.

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

Detailed Description

Http protocol service.

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.


Member Enumeration Documentation

enum QcjHttpService::ErrorCodes

These names provide a symbolic method to reference the various status codes which are defined the the w3c.

Definition at line 98 of file QcjHttpService.h.


Constructor & Destructor Documentation

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.


Member Function Documentation

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.


The documentation for this class was generated from the following files:
Generated on Fri May 4 11:21:12 2007 for PhotoGrotto by  doxygen 1.5.0