2013-10-04 03:30:15 -04:00
|
|
|
|
|
|
|
// EnvelopeParser.h
|
|
|
|
|
|
|
|
// Declares the cEnvelopeParser class representing a parser for RFC-822 envelope headers, used both in HTTP and in MIME
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cEnvelopeParser
|
|
|
|
{
|
|
|
|
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() {}
|
|
|
|
|
|
|
|
/** Called when a full header line is parsed */
|
2013-10-04 03:30:15 -04:00
|
|
|
virtual void OnHeaderLine(const AString & a_Key, const AString & a_Value) = 0;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
cEnvelopeParser(cCallbacks & a_Callbacks);
|
|
|
|
|
|
|
|
/** Parses the incoming data.
|
2014-04-01 10:36:00 -04:00
|
|
|
Returns the number of bytes consumed from the input. The bytes not consumed are not part of the envelope header.
|
|
|
|
Returns AString::npos on error
|
2013-10-04 03:30:15 -04:00
|
|
|
*/
|
2014-04-01 10:36:00 -04:00
|
|
|
size_t Parse(const char * a_Data, size_t a_Size);
|
2013-10-04 03:30:15 -04:00
|
|
|
|
2014-04-01 10:36:00 -04:00
|
|
|
/** Makes the parser forget everything parsed so far, so that it can be reused for parsing another datastream */
|
2013-10-04 03:30:15 -04:00
|
|
|
void Reset(void);
|
|
|
|
|
2014-04-01 10:36:00 -04:00
|
|
|
/** Returns true if more input is expected for the envelope header */
|
2013-10-04 03:30:15 -04:00
|
|
|
bool IsInHeaders(void) const { return m_IsInHeaders; }
|
|
|
|
|
2014-04-01 10:36:00 -04:00
|
|
|
/** Sets the IsInHeaders flag; used by cMultipartParser to simplify the parser initial conditions */
|
2013-10-04 03:30:15 -04:00
|
|
|
void SetIsInHeaders(bool a_IsInHeaders) { m_IsInHeaders = a_IsInHeaders; }
|
|
|
|
|
|
|
|
public:
|
2014-04-01 10:36:00 -04:00
|
|
|
/** Callbacks to call for the various events */
|
2013-10-04 03:30:15 -04:00
|
|
|
cCallbacks & m_Callbacks;
|
|
|
|
|
2014-04-01 10:36:00 -04:00
|
|
|
/** Set to true while the parser is still parsing the envelope headers. Once set to true, the parser will not consume any more data. */
|
2013-10-04 03:30:15 -04:00
|
|
|
bool m_IsInHeaders;
|
|
|
|
|
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;
|
|
|
|
|
2014-04-01 10:36:00 -04:00
|
|
|
/** Holds the last parsed key; used for line-wrapped values */
|
2013-10-04 03:30:15 -04:00
|
|
|
AString m_LastKey;
|
|
|
|
|
2014-04-01 10:36:00 -04:00
|
|
|
/** Holds the last parsed value; used for line-wrapped values */
|
2013-10-04 03:30:15 -04:00
|
|
|
AString m_LastValue;
|
|
|
|
|
|
|
|
|
2014-04-01 10:36:00 -04:00
|
|
|
/** Notifies the callback of the key/value stored in m_LastKey/m_LastValue, then erases them */
|
2013-10-04 03:30:15 -04:00
|
|
|
void NotifyLast(void);
|
|
|
|
|
2014-04-01 10:36:00 -04:00
|
|
|
/** Parses one line of header data. Returns true if successful */
|
2013-10-04 03:30:15 -04:00
|
|
|
bool ParseLine(const char * a_Data, size_t a_Size);
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|