Cuberite
A lightweight, fast and extensible game server for Minecraft
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cHTTPMessageParser Class Reference

#include <HTTPMessageParser.h>

Inheritance diagram for cHTTPMessageParser:
Inheritance graph
[legend]
Collaboration diagram for cHTTPMessageParser:
Collaboration graph
[legend]

Classes

class  cCallbacks
 

Public Member Functions

 cHTTPMessageParser (cCallbacks &a_Callbacks)
 Creates a new parser instance that will use the specified callbacks for reporting. More...
 
void Finish (void)
 Called when the server indicates no more data will be sent (HTTP 1.0 socket closed). More...
 
bool IsFinished (void) const
 Returns true if the entire response has been already parsed. More...
 
size_t Parse (const char *a_Data, size_t a_Size)
 Parses the incoming data and calls the appropriate callbacks. More...
 
void Reset (void)
 Resets the parser to the initial state, so that a new request can be parsed. More...
 

Protected Member Functions

void HeadersFinished (void)
 Called internally when the headers-parsing has just finished. More...
 
virtual void OnBodyData (const void *a_Data, size_t a_Size) override
 Called for each chunk of the incoming body data. More...
 
virtual void OnBodyFinished (void) override
 Called when the entire body has been reported by OnBodyData(). More...
 
virtual void OnError (const AString &a_ErrorDescription) override
 Called when an error has occured while parsing. More...
 
virtual void OnHeaderLine (const AString &a_Key, const AString &a_Value) override
 Called when a full header line is parsed. More...
 
size_t ParseBody (const char *a_Data, size_t a_Size)
 Parses the message body. More...
 
size_t ParseFirstLine (void)
 Parses the first line out of m_Buffer. More...
 
- Protected Member Functions inherited from cEnvelopeParser::cCallbacks
virtual ~cCallbacks ()
 
- Protected Member Functions inherited from cTransferEncodingParser::cCallbacks
virtual ~cCallbacks ()
 

Protected Attributes

AString m_Buffer
 Buffer for the incoming data until the status line is parsed. More...
 
cCallbacksm_Callbacks
 The callbacks used for reporting. More...
 
size_t m_ContentLength
 The content length, parsed from the headers, if available. More...
 
cEnvelopeParser m_EnvelopeParser
 Parser for the envelope data (headers) More...
 
AString m_FirstLine
 The complete first line of the response. More...
 
bool m_HasHadError
 Set to true if an error has been encountered by the parser. More...
 
bool m_IsFinished
 True if the response has been fully parsed. More...
 
AString m_TransferEncoding
 The transfer encoding to be used by the parser. More...
 
cTransferEncodingParserPtr m_TransferEncodingParser
 The specific parser for the transfer encoding used by this response. More...
 

Detailed Description

Definition at line 20 of file HTTPMessageParser.h.

Constructor & Destructor Documentation

◆ cHTTPMessageParser()

cHTTPMessageParser::cHTTPMessageParser ( cHTTPMessageParser::cCallbacks a_Callbacks)

Creates a new parser instance that will use the specified callbacks for reporting.

Definition at line 14 of file HTTPMessageParser.cpp.

Member Function Documentation

◆ Finish()

void cHTTPMessageParser::Finish ( void  )

Called when the server indicates no more data will be sent (HTTP 1.0 socket closed).

Finishes all parsing and calls apropriate callbacks (error if incomplete response).

◆ HeadersFinished()

void cHTTPMessageParser::HeadersFinished ( void  )
protected

Called internally when the headers-parsing has just finished.

Definition at line 159 of file HTTPMessageParser.cpp.

◆ IsFinished()

bool cHTTPMessageParser::IsFinished ( void  ) const
inline

Returns true if the entire response has been already parsed.

Definition at line 63 of file HTTPMessageParser.h.

◆ OnBodyData()

void cHTTPMessageParser::OnBodyData ( const void *  a_Data,
size_t  a_Size 
)
overrideprotectedvirtual

Called for each chunk of the incoming body data.

Implements cTransferEncodingParser::cCallbacks.

Definition at line 207 of file HTTPMessageParser.cpp.

◆ OnBodyFinished()

void cHTTPMessageParser::OnBodyFinished ( void  )
overrideprotectedvirtual

Called when the entire body has been reported by OnBodyData().

Implements cTransferEncodingParser::cCallbacks.

Definition at line 216 of file HTTPMessageParser.cpp.

◆ OnError()

void cHTTPMessageParser::OnError ( const AString a_ErrorDescription)
overrideprotectedvirtual

Called when an error has occured while parsing.

Implements cTransferEncodingParser::cCallbacks.

Definition at line 197 of file HTTPMessageParser.cpp.

◆ OnHeaderLine()

void cHTTPMessageParser::OnHeaderLine ( const AString a_Key,
const AString a_Value 
)
overrideprotectedvirtual

Called when a full header line is parsed.

Implements cEnvelopeParser::cCallbacks.

Definition at line 174 of file HTTPMessageParser.cpp.

◆ Parse()

size_t cHTTPMessageParser::Parse ( const char *  a_Data,
size_t  a_Size 
)

Parses the incoming data and calls the appropriate callbacks.

Returns the number of bytes consumed or AString::npos number for error.

Definition at line 25 of file HTTPMessageParser.cpp.

◆ ParseBody()

size_t cHTTPMessageParser::ParseBody ( const char *  a_Data,
size_t  a_Size 
)
protected

Parses the message body.

Processes transfer encoding and calls the callbacks for body data. Returns the number of bytes consumed or AString::npos number for error.

Definition at line 141 of file HTTPMessageParser.cpp.

◆ ParseFirstLine()

size_t cHTTPMessageParser::ParseFirstLine ( void  )
protected

Parses the first line out of m_Buffer.

Removes the first line from m_Buffer, if appropriate. Returns the number of bytes consumed out of m_Buffer, or AString::npos number for error.

Definition at line 123 of file HTTPMessageParser.cpp.

◆ Reset()

void cHTTPMessageParser::Reset ( void  )

Resets the parser to the initial state, so that a new request can be parsed.

Definition at line 107 of file HTTPMessageParser.cpp.

Member Data Documentation

◆ m_Buffer

AString cHTTPMessageParser::m_Buffer
protected

Buffer for the incoming data until the status line is parsed.

Definition at line 84 of file HTTPMessageParser.h.

◆ m_Callbacks

cCallbacks& cHTTPMessageParser::m_Callbacks
protected

The callbacks used for reporting.

Definition at line 72 of file HTTPMessageParser.h.

◆ m_ContentLength

size_t cHTTPMessageParser::m_ContentLength
protected

The content length, parsed from the headers, if available.

Unused for chunked encoding. Filled while parsing headers, used when headers are finished.

Definition at line 99 of file HTTPMessageParser.h.

◆ m_EnvelopeParser

cEnvelopeParser cHTTPMessageParser::m_EnvelopeParser
protected

Parser for the envelope data (headers)

Definition at line 87 of file HTTPMessageParser.h.

◆ m_FirstLine

AString cHTTPMessageParser::m_FirstLine
protected

The complete first line of the response.

Empty if not parsed yet.

Definition at line 81 of file HTTPMessageParser.h.

◆ m_HasHadError

bool cHTTPMessageParser::m_HasHadError
protected

Set to true if an error has been encountered by the parser.

Definition at line 75 of file HTTPMessageParser.h.

◆ m_IsFinished

bool cHTTPMessageParser::m_IsFinished
protected

True if the response has been fully parsed.

Definition at line 78 of file HTTPMessageParser.h.

◆ m_TransferEncoding

AString cHTTPMessageParser::m_TransferEncoding
protected

The transfer encoding to be used by the parser.

Filled while parsing headers, used when headers are finished.

Definition at line 94 of file HTTPMessageParser.h.

◆ m_TransferEncodingParser

cTransferEncodingParserPtr cHTTPMessageParser::m_TransferEncodingParser
protected

The specific parser for the transfer encoding used by this response.

Definition at line 90 of file HTTPMessageParser.h.


The documentation for this class was generated from the following files: