FARGOS/VISTA Object Management Environment Core  ..
FARGOS/VISTA Object Management Environment Core Table of Contents
HTTP_SessionRecord Class Reference

Per-session HTTP state record. More...

#include <HTTPembeddedServer.hpp>

+ Inheritance diagram for HTTP_SessionRecord:

Classes

struct  ltCharPtrStr
 

Public Types

typedef ssize_t(* HTTPcallbackFP) (HTTP_SessionRecord *session, const char *cmd, char *url, unsigned char *block, size_t blockLen)
 Signature for HTTP callback routine. More...
 
typedef std::map< const char *, const char *, ltCharPtrStrOptionsAttrValMap_t
 
- Public Types inherited from Parse_And_Process_HTTP_Stream
enum  ParseState { READ_RESPONSE =1, READ_REQUEST, READ_HEADER_LINE, READ_CONTENT_BODY }
 

Public Member Functions

 HTTP_SessionRecord (IO_Processor *io, CircularBufferManager *mgr, const GenericSocketAddress *from, void *extraData=nullptr, size_t maxDocSize=1024 *128)
 Create state record for current HTTP session. More...
 
 ~HTTP_SessionRecord ()
 
void addHTTPhandler (const char *cmd, HTTPcallbackFP routine)
 Add a handler routine for an HTTP request command. More...
 
void setCloseAfterRequestFlag (bool doClose)
 Set close-when-request-complete flag. More...
 
virtual void connectionEOF ()
 User-exit called when EOF reached on client connection. More...
 
virtual int_fast32_t processBlock (unsigned char *blockStart, size_t blockLen) VIRTUAL_OVERRIDE
 User-exit for receiving POSTed data. More...
 
virtual int processHTTPheader (unsigned char *line, size_t lineLen) VIRTUAL_OVERRIDE
 User exit to process incoming HTTP header. More...
 
virtual bool interestedInEvent (const class HTTPeventStateRecord *record)
 User-exit to filter out events when session has been converted into use with an HTTPstatusLog object. More...
 
- Public Member Functions inherited from Parse_And_Process_HTTP_Stream
 Parse_And_Process_HTTP_Stream (size_t maxDocSize=1024 *128, ParseState initialState=READ_RESPONSE)
 
virtual ~Parse_And_Process_HTTP_Stream ()
 
const char * findHeaderAttribute (const char *headerElement) const
 
virtual int processHTTPresponse (unsigned char *line, size_t lineLen)
 User-exit for HTTP response line. More...
 
virtual int processHTTPrequest (unsigned char *line, size_t lineLen)
 User-exit for HTTP request line. More...
 
int processDocument (unsigned char *docStart, size_t docLen) VIRTUAL_OVERRIDE
 User-exit to process extracted document. More...
 
- Public Member Functions inherited from Extract_And_Process_Document_Stream
 Extract_And_Process_Document_Stream (const char *docStart, const char *endTag, size_t maxDocSize=1024 *128)
 
virtual ~Extract_And_Process_Document_Stream ()
 
int scanAndProcessBuffer (const unsigned char *block, size_t blockLen)
 
int scanAndProcessBuffer (File_Buffer *bfrState)
 
int addIOblockThenProcess (SharedBufferAllocRecord *rec, IO_Processor *controller)
 Specialized interface to add incoming block from BufferRegion maintained by an IO_Processor. Block content is appended and then returned before any processing of the content is attempted. More...
 

Static Public Member Functions

static char * convertHTTPescapes (char *bfr, int_fast32_t bfrLen=-1, bool nullTerminate=false)
 
static int_fast32_t parseOptions (OptionsAttrValMap_t *tbl, char *optionText, int_fast32_t optionLength=-1)
 Parse an HTTP request option string. Elements are separated by "&" characters; each subelement is expected to be a "var=value" pair. More...
 
static int default_OPTIONS (HTTP_SessionRecord *session, const char *cmd, char *url, unsigned char *block, size_t blockLen)
 Default implementation to handle OPTIONS request. It emits Access-Control-Allow headers, assert GET, POST permitted. More...
 

Public Attributes

IO_Processorcontroller
 
CircularBufferManagerbfrMgr
 
void * userData
 
GenericSocketAddress fromAddress
 
bool closeWhenRequestComplete
 
- Public Attributes inherited from Parse_And_Process_HTTP_Stream
char httpVersion [16]
 
char statusCode [8]
 
char responseReason [48]
 
char httpRequest [16]
 
char requestURL [1024]
 
int32_t contentLengthWanted
 
std::map< std::string, std::string > headerAttributes
 

Protected Member Functions

virtual ssize_t handleHTTPrequest (unsigned char *block, size_t blockLen)
 User-exit called when HTTP request read. Not normally overridden. More...
 
void closeConnection ()
 Close the connection associated with this HTTP session. More...
 
int_fast32_t prepareResponseHeader (void *outputBfr, size_t bfrLen, uint_fast32_t statusCodeValue=200, const char *statusText="OK", const char *extraHeaders="", ssize_t contentLength=0, const char *extraContent="")
 
ssize_t sendResponse (const void *bfr, size_t bfrLen)
 
- Protected Member Functions inherited from Extract_And_Process_Document_Stream
int scanForDocument ()
 

Protected Attributes

std::map< std::string, HTTPcallbackFPhttpRequestHandlerTable
 
- Protected Attributes inherited from Parse_And_Process_HTTP_Stream
ParseState parseState
 
ParseState restartParseState
 
- Protected Attributes inherited from Extract_And_Process_Document_Stream
enum Extract_And_Process_Document_Stream:: { ... }  scanState
 
enum Extract_And_Process_Document_Stream:: { ... }  restartScanState
 
unsigned char documentStartPrefix [64]
 
unsigned char documentEndTag [64]
 
File_BufferpendingContent
 
ssize_t neededBlockLen
 
size_t documentStartLen
 
size_t documentEndLen
 

Additional Inherited Members

- Protected Types inherited from Extract_And_Process_Document_Stream
enum  { FIND_NOTHING =0, FIND_DOC_START =1, FIND_END_TAG =2, FIND_BLOCK_LENGTH =3 }
 

Detailed Description

Per-session HTTP state record.

Custom applications are realized by implementing a subclass of HTTP_SessionRecord to handle the per-session behavior. The most trivial implementation will make an addHTTPhandler() call in the constructor and implement the corresponding method.

Member Typedef Documentation

◆ HTTPcallbackFP

typedef ssize_t(* HTTP_SessionRecord::HTTPcallbackFP) (HTTP_SessionRecord *session, const char *cmd, char *url, unsigned char *block, size_t blockLen)

Signature for HTTP callback routine.

◆ OptionsAttrValMap_t

typedef std::map<const char *, const char *, ltCharPtrStr> HTTP_SessionRecord::OptionsAttrValMap_t

Constructor & Destructor Documentation

◆ HTTP_SessionRecord()

HTTP_SessionRecord::HTTP_SessionRecord ( IO_Processor io,
CircularBufferManager mgr,
const GenericSocketAddress from,
void *  extraData = nullptr,
size_t  maxDocSize = 1024*128 
)
inline

Create state record for current HTTP session.

Parameters
iopoints to the IO_Processor object controlling the stream processing. It should be deleted by some parent object.
mgrspecifies the circular buffer manager used to buffer the input stream. Ownership is transferred to the HTTP_SessionRecord object.
fromspecifies the source of the incoming connection.
extraDataallows application-specific data to be passed.
maxDocSizespecifies the maximum size of an HTTP document to be pased to the Parse_And_Process_HTTP_Stream base class.

References bfrMgr, closeWhenRequestComplete, controller, io(), and userData.

◆ ~HTTP_SessionRecord()

HTTP_SessionRecord::~HTTP_SessionRecord ( )
inline

References bfrMgr.

Member Function Documentation

◆ addHTTPhandler()

void HTTP_SessionRecord::addHTTPhandler ( const char *  cmd,
HTTPcallbackFP  routine 
)
inline

Add a handler routine for an HTTP request command.

Parameters
cmdspecifies the request to be handled, such as "GET" or "POST".
routinespecifies the routine to be invoked.

References httpRequestHandlerTable.

◆ closeConnection()

void HTTP_SessionRecord::closeConnection ( )
protected

◆ connectionEOF()

virtual void HTTP_SessionRecord::connectionEOF ( )
inlinevirtual

User-exit called when EOF reached on client connection.

The default implementation calls closeConnection() to clean up.

References app(), closeConnection(), fromAddress, GenericSocketAddress::GenericSocketAddress_union::genericAddr, LOG_COMPONENT_CERR, LOG_ENDLINE, and GenericSocketAddress::socketAddress.

Referenced by HTTPembeddedServerBase::readHTTPstream().

◆ convertHTTPescapes()

char * HTTP_SessionRecord::convertHTTPescapes ( char *  bfr,
int_fast32_t  bfrLen = -1,
bool  nullTerminate = false 
)
static

References fromHex.

Referenced by parseOptions().

◆ default_OPTIONS()

int HTTP_SessionRecord::default_OPTIONS ( HTTP_SessionRecord session,
const char *  cmd,
char *  url,
unsigned char *  block,
size_t  blockLen 
)
static

Default implementation to handle OPTIONS request. It emits Access-Control-Allow headers, assert GET, POST permitted.

References controller, IO_Processor::descriptor, and SOCKET_CAST.

◆ handleHTTPrequest()

ssize_t HTTP_SessionRecord::handleHTTPrequest ( unsigned char *  block,
size_t  blockLen 
)
protectedvirtual

◆ interestedInEvent()

virtual bool HTTP_SessionRecord::interestedInEvent ( const class HTTPeventStateRecord record)
inlinevirtual

User-exit to filter out events when session has been converted into use with an HTTPstatusLog object.

Referenced by HTTPstatusLog::dumpEventsFromTime(), and HTTPstatusLog::publishEventState().

◆ parseOptions()

int_fast32_t HTTP_SessionRecord::parseOptions ( OptionsAttrValMap_t tbl,
char *  optionText,
int_fast32_t  optionLength = -1 
)
static

Parse an HTTP request option string. Elements are separated by "&" characters; each subelement is expected to be a "var=value" pair.

Parameters
tblis an attribute/value map into which the parsed attribute value pairs will be stored. Its key and value pointers will refer to addresses within optionText, so the storage associated with optionText must not be deleted while * the tbl map is accessed.
optionTextis a string of HTML option text; if the length is specified, then the string content does not have to be terminated by a null character.
optionLengthis an optional argument that specifies the length of optionText. If set to -1, the length will be determined at runtime using strlen().

NOTE: optionText will be modified.

Returns
The number of elements parsed is returned.

References convertHTTPescapes().

◆ prepareResponseHeader()

int_fast32_t HTTP_SessionRecord::prepareResponseHeader ( void *  outputBfr,
size_t  bfrLen,
uint_fast32_t  statusCodeValue = 200,
const char *  statusText = "OK",
const char *  extraHeaders = "",
ssize_t  contentLength = 0,
const char *  extraContent = "" 
)
protected

◆ processBlock()

virtual int_fast32_t HTTP_SessionRecord::processBlock ( unsigned char *  blockStart,
size_t  blockLen 
)
inlinevirtual

User-exit for receiving POSTed data.

Parameters
blockStartpoints to start of data
blockLenindicates length of provided data

This overrides

Reimplemented from Parse_And_Process_HTTP_Stream.

References app(), AS_TEXT_BUFFER, fromAddress, GenericSocketAddress::GenericSocketAddress_union::genericAddr, handleHTTPrequest(), LOG_COMPONENT_CERR, LOG_ENDLINE, and GenericSocketAddress::socketAddress.

◆ processHTTPheader()

virtual int HTTP_SessionRecord::processHTTPheader ( unsigned char *  line,
size_t  lineLen 
)
inlinevirtual

◆ sendResponse()

ssize_t HTTP_SessionRecord::sendResponse ( const void *  bfr,
size_t  bfrLen 
)
protected

◆ setCloseAfterRequestFlag()

void HTTP_SessionRecord::setCloseAfterRequestFlag ( bool  doClose)
inline

Set close-when-request-complete flag.

Parameters
doClosespecifies the desired state.

By default, if a requesting client provides a "Connection: keep-alive" header, the connection will remain open after a request is processed. The connection can be forced to be closed by passing a value of true.

References closeWhenRequestComplete.

Member Data Documentation

◆ bfrMgr

CircularBufferManager* HTTP_SessionRecord::bfrMgr

◆ closeWhenRequestComplete

bool HTTP_SessionRecord::closeWhenRequestComplete

◆ controller

◆ fromAddress

◆ httpRequestHandlerTable

std::map<std::string,HTTPcallbackFP> HTTP_SessionRecord::httpRequestHandlerTable
protected

◆ userData

void* HTTP_SessionRecord::userData

Referenced by HTTP_SessionRecord().


The documentation for this class was generated from the following files:
Generated: Tue Jul 28 2020 16:03:27
Support Information