Cuberite
A lightweight, fast and extensible game server for Minecraft
EnvelopeParser.h
Go to the documentation of this file.
1 
2 // EnvelopeParser.h
3 
4 // Declares the cEnvelopeParser class representing a parser for RFC-822 envelope headers, used both in HTTP and in MIME
5 
6 
7 
8 
9 
10 #pragma once
11 
12 
13 
14 
15 
17 {
18 public:
19  class cCallbacks
20  {
21  public:
22  // Force a virtual destructor in descendants:
23  virtual ~cCallbacks() {}
24 
26  virtual void OnHeaderLine(const AString & a_Key, const AString & a_Value) = 0;
27  } ;
28 
29 
30  cEnvelopeParser(cCallbacks & a_Callbacks);
31 
36  size_t Parse(const char * a_Data, size_t a_Size);
37 
39  void Reset(void);
40 
42  bool IsInHeaders(void) const { return m_IsInHeaders; }
43 
45  void SetIsInHeaders(bool a_IsInHeaders) { m_IsInHeaders = a_IsInHeaders; }
46 
47 public:
50 
53 
56 
59 
62 
63 
65  void NotifyLast(void);
66 
68  bool ParseLine(const char * a_Data, size_t a_Size);
69 } ;
70 
71 
72 
73 
std::string AString
Definition: StringUtils.h:11
void Reset(void)
Makes the parser forget everything parsed so far, so that it can be reused for parsing another datast...
cCallbacks & m_Callbacks
Callbacks to call for the various events.
size_t Parse(const char *a_Data, size_t a_Size)
Parses the incoming data.
AString m_LastValue
Holds the last parsed value; used for line-wrapped values.
bool ParseLine(const char *a_Data, size_t a_Size)
Parses one line of header data.
AString m_LastKey
Holds the last parsed key; used for line-wrapped values.
cEnvelopeParser(cCallbacks &a_Callbacks)
bool m_IsInHeaders
Set to true while the parser is still parsing the envelope headers.
void SetIsInHeaders(bool a_IsInHeaders)
Sets the IsInHeaders flag; used by cMultipartParser to simplify the parser initial conditions.
bool IsInHeaders(void) const
Returns true if more input is expected for the envelope header.
AString m_IncomingData
Buffer for the incoming data until it is parsed.
void NotifyLast(void)
Notifies the callback of the key / value stored in m_LastKey / m_LastValue, then erases them.
virtual void OnHeaderLine(const AString &a_Key, const AString &a_Value)=0
Called when a full header line is parsed.