2013-10-04 03:30:15 -04:00
|
|
|
|
|
|
|
// MultipartParser.h
|
|
|
|
|
|
|
|
// Declares the cMultipartParser class that parses messages in "multipart/*" encoding into the separate parts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "EnvelopeParser.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cMultipartParser :
|
|
|
|
protected cEnvelopeParser::cCallbacks
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class cCallbacks
|
|
|
|
{
|
|
|
|
public:
|
2014-04-02 10:39:42 -04:00
|
|
|
// Force a virtual destructor in descendants:
|
2014-04-01 10:36:00 -04:00
|
|
|
virtual ~cCallbacks() {}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-01 10:36:00 -04:00
|
|
|
/** Called when a new part starts */
|
2013-10-04 03:30:15 -04:00
|
|
|
virtual void OnPartStart(void) = 0;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-01 10:36:00 -04:00
|
|
|
/** Called when a complete header line is received for a part */
|
2013-10-04 03:30:15 -04:00
|
|
|
virtual void OnPartHeader(const AString & a_Key, const AString & a_Value) = 0;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-01 10:36:00 -04:00
|
|
|
/** Called when body for a part is received */
|
|
|
|
virtual void OnPartData(const char * a_Data, size_t a_Size) = 0;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-01 10:36:00 -04:00
|
|
|
/** Called when the current part ends */
|
2013-10-04 03:30:15 -04:00
|
|
|
virtual void OnPartEnd(void) = 0;
|
|
|
|
} ;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-01 10:36:00 -04:00
|
|
|
/** Creates the parser, expects to find the boundary in a_ContentType */
|
2013-10-04 03:30:15 -04:00
|
|
|
cMultipartParser(const AString & a_ContentType, cCallbacks & a_Callbacks);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-01 10:36:00 -04:00
|
|
|
/** Parses more incoming data */
|
|
|
|
void Parse(const char * a_Data, size_t a_Size);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-10-04 03:30:15 -04:00
|
|
|
protected:
|
2014-04-01 10:36:00 -04:00
|
|
|
/** The callbacks to call for various parsing events */
|
2013-10-04 03:30:15 -04:00
|
|
|
cCallbacks & m_Callbacks;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-01 10:36:00 -04:00
|
|
|
/** True if the data parsed so far is valid; if false, further parsing is skipped */
|
2013-10-04 03:30:15 -04:00
|
|
|
bool m_IsValid;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-01 10:36:00 -04:00
|
|
|
/** Parser for each part's envelope */
|
2013-10-04 03:30:15 -04:00
|
|
|
cEnvelopeParser m_EnvelopeParser;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-01 10:36:00 -04:00
|
|
|
/** Buffer for the incoming data until it is parsed */
|
2013-10-04 03:30:15 -04:00
|
|
|
AString m_IncomingData;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-01 10:36:00 -04:00
|
|
|
/** The boundary, excluding both the initial "--" and the terminating CRLF */
|
2013-10-04 03:30:15 -04:00
|
|
|
AString m_Boundary;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-01 10:36:00 -04:00
|
|
|
/** Set to true if some data for the current part has already been signalized to m_Callbacks. Used for proper CRLF inserting. */
|
2013-10-04 03:30:15 -04:00
|
|
|
bool m_HasHadData;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
|
|
|
|
2014-04-01 10:36:00 -04:00
|
|
|
/** Parse one line of incoming data. The CRLF has already been stripped from a_Data / a_Size */
|
|
|
|
void ParseLine(const char * a_Data, size_t a_Size);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-01 10:36:00 -04:00
|
|
|
/** Parse one line of incoming data in the headers section of a part. The CRLF has already been stripped from a_Data / a_Size */
|
|
|
|
void ParseHeaderLine(const char * a_Data, size_t a_Size);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-10-04 03:30:15 -04:00
|
|
|
// cEnvelopeParser overrides:
|
|
|
|
virtual void OnHeaderLine(const AString & a_Key, const AString & a_Value) override;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|