73 for (
size_t i = 0; i < a_Size; i++)
123 Error(fmt::format(FMT_STRING(
"Invalid character in chunk length line: 0x{:02x}"), a_Data[i]));
124 return AString::npos;
139 for (
size_t i = 0; i < a_Size; i++)
153 Error(fmt::format(FMT_STRING(
"Invalid character in chunk length line: 0x{:02x}"), a_Data[i]));
154 return AString::npos;
174 if (a_Data[0] ==
'\n')
186 Error(fmt::format(FMT_STRING(
"Invalid character past chunk length's CR: 0x{:02x}"), a_Data[0]));
187 return AString::npos;
217 if (a_Data[0] ==
'\r')
222 Error(fmt::format(FMT_STRING(
"Invalid character past chunk data: 0x{:02x}"), a_Data[0]));
223 return AString::npos;
239 if (a_Data[0] ==
'\n')
244 Error(fmt::format(FMT_STRING(
"Invalid character past chunk data's CR: 0x{:02x}"), a_Data[0]));
245 return AString::npos;
255 if (res == AString::npos)
257 Error(
"Error while parsing the trailer");
269 virtual size_t Parse(
const char * a_Data,
size_t a_Size)
override
285 if (consumed == AString::npos)
287 return AString::npos;
299 Error(fmt::format(FMT_STRING(
"ChunkedTransferEncoding: Finish signal received before the data stream ended (state: {})"),
m_State));
338 virtual size_t Parse(
const char * a_Data,
size_t a_Size)
override
350 return a_Size - size;
375 const AString & a_TransferEncoding,
376 size_t a_ContentLength
379 if (a_TransferEncoding ==
"chunked")
381 return std::make_shared<cChunkedTEParser>(a_Callbacks);
383 if (a_TransferEncoding ==
"identity")
385 return std::make_shared<cIdentityTEParser>(a_Callbacks, a_ContentLength);
387 if (a_TransferEncoding.empty())
389 return std::make_shared<cIdentityTEParser>(a_Callbacks, a_ContentLength);
std::shared_ptr< cTransferEncodingParser > cTransferEncodingParserPtr
size_t Parse(const char *a_Data, size_t a_Size)
Parses the incoming data.
bool IsInHeaders(void) const
Returns true if more input is expected for the envelope header.
cEnvelopeParser m_TrailerParser
The parser used for the last (empty) chunk's trailer data.
void Error(const AString &a_ErrorMsg)
Calls the OnError callback and sets parser state to finished.
@ psChunkDataCR
Skipping the extra CR character after chunk data.
@ psChunkDataLF
Skipping the extra LF character after chunk data.
@ psChunkData
Relaying chunk data.
@ psChunkLengthLF
The LF character after the CR character terminating the chunk length.
@ psTrailer
Received an empty chunk, parsing the trailer (through the envelope parser)
@ psFinished
The parser has finished parsing, either successfully or with an error.
@ psChunkLengthTrailer
Any trailer (chunk extension) specified after the chunk length.
@ psChunkLength
Parsing the chunk length hex number.
size_t ParseTrailer(const char *a_Data, size_t a_Size)
Parses the incoming data, the current state is psChunkDataCR.
size_t ParseChunkLengthTrailer(const char *a_Data, size_t a_Size)
Parses the incoming data, the current state is psChunkLengthTrailer.
eState m_State
The current state of the parser (parsing chunk length / chunk data).
size_t ParseChunkDataLF(const char *a_Data, size_t a_Size)
Parses the incoming data, the current state is psChunkDataCR.
size_t ParseChunkLength(const char *a_Data, size_t a_Size)
Parses the incoming data, the current state is psChunkLength.
size_t m_ChunkDataLengthLeft
Number of bytes that still belong to the chunk currently being parsed.
size_t ParseChunkLengthLF(const char *a_Data, size_t a_Size)
Parses the incoming data, the current state is psChunkLengthLF.
cChunkedTEParser(Super::cCallbacks &a_Callbacks)
size_t ParseChunkDataCR(const char *a_Data, size_t a_Size)
Parses the incoming data, the current state is psChunkDataCR.
virtual void OnHeaderLine(const AString &a_Key, const AString &a_Value) override
Called when a full header line is parsed.
virtual void Finish() override
To be called when the stream is terminated from the source (connection closed).
virtual size_t Parse(const char *a_Data, size_t a_Size) override
Parses the incoming data and calls the appropriate callbacks.
size_t ParseChunkData(const char *a_Data, size_t a_Size)
Consumes as much chunk data from the input as possible.
virtual void Finish(void) override
To be called when the stream is terminated from the source (connection closed).
size_t m_BytesLeft
How many bytes of content are left before the message ends.
virtual size_t Parse(const char *a_Data, size_t a_Size) override
Parses the incoming data and calls the appropriate callbacks.
cIdentityTEParser(cCallbacks &a_Callbacks, size_t a_ContentLength)
Used as both the interface that all the parsers share and the (static) factory creating such parsers.
cCallbacks & m_Callbacks
The callbacks used to report progress.
cTransferEncodingParser(cCallbacks &a_Callbacks)
static cTransferEncodingParserPtr Create(cCallbacks &a_Callbacks, const AString &a_TransferEncoding, size_t a_ContentLength)
Creates a new parser for the specified encoding.
virtual void OnError(const AString &a_ErrorDescription)=0
Called when an error has occured while parsing.
virtual void OnBodyData(const void *a_Data, size_t a_Size)=0
Called for each chunk of the incoming body data.
virtual void OnBodyFinished(void)=0
Called when the entire body has been reported by OnBodyData().