Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Types | List of all members
cChunkedTEParser Class Reference
Inheritance diagram for cChunkedTEParser:
Inheritance graph
[legend]
Collaboration diagram for cChunkedTEParser:
Collaboration graph
[legend]

Public Member Functions

 cChunkedTEParser (Super::cCallbacks &a_Callbacks)
 
- Public Member Functions inherited from cTransferEncodingParser
virtual ~cTransferEncodingParser ()
 
- Public Member Functions inherited from cEnvelopeParser::cCallbacks
virtual ~cCallbacks ()
 

Protected Types

enum  eState {
  psChunkLength , psChunkLengthTrailer , psChunkLengthLF , psChunkData ,
  psChunkDataCR , psChunkDataLF , psTrailer , psFinished
}
 

Protected Member Functions

void Error (const AString &a_ErrorMsg)
 Calls the OnError callback and sets parser state to finished. More...
 
virtual void Finish () override
 To be called when the stream is terminated from the source (connection closed). More...
 
virtual void OnHeaderLine (const AString &a_Key, const AString &a_Value) override
 Called when a full header line is parsed. More...
 
virtual size_t Parse (const char *a_Data, size_t a_Size) override
 Parses the incoming data and calls the appropriate callbacks. More...
 
size_t ParseChunkData (const char *a_Data, size_t a_Size)
 Consumes as much chunk data from the input as possible. More...
 
size_t ParseChunkDataCR (const char *a_Data, size_t a_Size)
 Parses the incoming data, the current state is psChunkDataCR. More...
 
size_t ParseChunkDataLF (const char *a_Data, size_t a_Size)
 Parses the incoming data, the current state is psChunkDataCR. More...
 
size_t ParseChunkLength (const char *a_Data, size_t a_Size)
 Parses the incoming data, the current state is psChunkLength. More...
 
size_t ParseChunkLengthLF (const char *a_Data, size_t a_Size)
 Parses the incoming data, the current state is psChunkLengthLF. More...
 
size_t ParseChunkLengthTrailer (const char *a_Data, size_t a_Size)
 Parses the incoming data, the current state is psChunkLengthTrailer. More...
 
size_t ParseTrailer (const char *a_Data, size_t a_Size)
 Parses the incoming data, the current state is psChunkDataCR. More...
 
- Protected Member Functions inherited from cTransferEncodingParser
 cTransferEncodingParser (cCallbacks &a_Callbacks)
 

Protected Attributes

size_t m_ChunkDataLengthLeft
 Number of bytes that still belong to the chunk currently being parsed. More...
 
eState m_State
 The current state of the parser (parsing chunk length / chunk data). More...
 
cEnvelopeParser m_TrailerParser
 The parser used for the last (empty) chunk's trailer data. More...
 
- Protected Attributes inherited from cTransferEncodingParser
cCallbacksm_Callbacks
 The callbacks used to report progress. More...
 

Private Types

using Super = cTransferEncodingParser
 

Additional Inherited Members

- Static Public Member Functions inherited from cTransferEncodingParser
static cTransferEncodingParserPtr Create (cCallbacks &a_Callbacks, const AString &a_TransferEncoding, size_t a_ContentLength)
 Creates a new parser for the specified encoding. More...
 

Detailed Description

Definition at line 17 of file TransferEncodingParser.cpp.

Member Typedef Documentation

◆ Super

Definition at line 21 of file TransferEncodingParser.cpp.

Member Enumeration Documentation

◆ eState

enum cChunkedTEParser::eState
protected
Enumerator
psChunkLength 

Parsing the chunk length hex number.

psChunkLengthTrailer 

Any trailer (chunk extension) specified after the chunk length.

psChunkLengthLF 

The LF character after the CR character terminating the chunk length.

psChunkData 

Relaying chunk data.

psChunkDataCR 

Skipping the extra CR character after chunk data.

psChunkDataLF 

Skipping the extra LF character after chunk data.

psTrailer 

Received an empty chunk, parsing the trailer (through the envelope parser)

psFinished 

The parser has finished parsing, either successfully or with an error.

Definition at line 35 of file TransferEncodingParser.cpp.

Constructor & Destructor Documentation

◆ cChunkedTEParser()

cChunkedTEParser::cChunkedTEParser ( Super::cCallbacks a_Callbacks)
inline

Definition at line 25 of file TransferEncodingParser.cpp.

Member Function Documentation

◆ Error()

void cChunkedTEParser::Error ( const AString a_ErrorMsg)
inlineprotected

Calls the OnError callback and sets parser state to finished.

Definition at line 59 of file TransferEncodingParser.cpp.

◆ Finish()

virtual void cChunkedTEParser::Finish ( )
inlineoverrideprotectedvirtual

To be called when the stream is terminated from the source (connection closed).

Flushes any buffers and calls appropriate callbacks.

Implements cTransferEncodingParser.

Definition at line 295 of file TransferEncodingParser.cpp.

◆ OnHeaderLine()

virtual void cChunkedTEParser::OnHeaderLine ( const AString a_Key,
const AString a_Value 
)
inlineoverrideprotectedvirtual

Called when a full header line is parsed.

Implements cEnvelopeParser::cCallbacks.

Definition at line 306 of file TransferEncodingParser.cpp.

◆ Parse()

virtual size_t cChunkedTEParser::Parse ( const char *  a_Data,
size_t  a_Size 
)
inlineoverrideprotectedvirtual

Parses the incoming data and calls the appropriate callbacks.

Returns the number of bytes from the end of a_Data that is already not part of this message (if the parser can detect it). Returns AString::npos on an error.

Implements cTransferEncodingParser.

Definition at line 269 of file TransferEncodingParser.cpp.

◆ ParseChunkData()

size_t cChunkedTEParser::ParseChunkData ( const char *  a_Data,
size_t  a_Size 
)
inlineprotected

Consumes as much chunk data from the input as possible.

Returns the number of bytes consumed from the input, or AString::npos on error (calls the Error() handler).

Definition at line 193 of file TransferEncodingParser.cpp.

◆ ParseChunkDataCR()

size_t cChunkedTEParser::ParseChunkDataCR ( const char *  a_Data,
size_t  a_Size 
)
inlineprotected

Parses the incoming data, the current state is psChunkDataCR.

Only the CR character is expected, if found, moves to psChunkDataLF, otherwise issues an error. Returns the number of bytes consumed from the input, or AString::npos on error (calls the Error handler).

Definition at line 210 of file TransferEncodingParser.cpp.

◆ ParseChunkDataLF()

size_t cChunkedTEParser::ParseChunkDataLF ( const char *  a_Data,
size_t  a_Size 
)
inlineprotected

Parses the incoming data, the current state is psChunkDataCR.

Only the CR character is expected, if found, moves to psChunkDataLF, otherwise issues an error. Returns the number of bytes consumed from the input, or AString::npos on error (calls the Error handler).

Definition at line 232 of file TransferEncodingParser.cpp.

◆ ParseChunkLength()

size_t cChunkedTEParser::ParseChunkLength ( const char *  a_Data,
size_t  a_Size 
)
inlineprotected

Parses the incoming data, the current state is psChunkLength.

Stops parsing when either the chunk length has been read, or there is no more data in the input. Returns the number of bytes consumed from the input, or AString::npos on error (calls the Error handler).

Definition at line 69 of file TransferEncodingParser.cpp.

◆ ParseChunkLengthLF()

size_t cChunkedTEParser::ParseChunkLengthLF ( const char *  a_Data,
size_t  a_Size 
)
inlineprotected

Parses the incoming data, the current state is psChunkLengthLF.

Only the LF character is expected, if found, moves to psChunkData, otherwise issues an error. If the chunk length that just finished reading is equal to 0, signals the end of stream (via psTrailer). Returns the number of bytes consumed from the input, or AString::npos on error (calls the Error handler).

Definition at line 167 of file TransferEncodingParser.cpp.

◆ ParseChunkLengthTrailer()

size_t cChunkedTEParser::ParseChunkLengthTrailer ( const char *  a_Data,
size_t  a_Size 
)
inlineprotected

Parses the incoming data, the current state is psChunkLengthTrailer.

Stops parsing when either the chunk length trailer has been read, or there is no more data in the input. Returns the number of bytes consumed from the input, or AString::npos on error (calls the Error handler).

Definition at line 135 of file TransferEncodingParser.cpp.

◆ ParseTrailer()

size_t cChunkedTEParser::ParseTrailer ( const char *  a_Data,
size_t  a_Size 
)
inlineprotected

Parses the incoming data, the current state is psChunkDataCR.

The trailer is normally a set of "Header: Value" lines, terminated by an empty line. Use the m_TrailerParser for that. Returns the number of bytes consumed from the input, or AString::npos on error (calls the Error handler).

Definition at line 252 of file TransferEncodingParser.cpp.

Member Data Documentation

◆ m_ChunkDataLengthLeft

size_t cChunkedTEParser::m_ChunkDataLengthLeft
protected

Number of bytes that still belong to the chunk currently being parsed.

When in psChunkLength, the value is the currently parsed length digits.

Definition at line 52 of file TransferEncodingParser.cpp.

◆ m_State

eState cChunkedTEParser::m_State
protected

The current state of the parser (parsing chunk length / chunk data).

Definition at line 48 of file TransferEncodingParser.cpp.

◆ m_TrailerParser

cEnvelopeParser cChunkedTEParser::m_TrailerParser
protected

The parser used for the last (empty) chunk's trailer data.

Definition at line 55 of file TransferEncodingParser.cpp.


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