Cuberite
A lightweight, fast and extensible game server for Minecraft
MultipartParser.h
Go to the documentation of this file.
1 
2 // MultipartParser.h
3 
4 // Declares the cMultipartParser class that parses messages in "multipart/*" encoding into the separate parts
5 
6 
7 
8 
9 
10 #pragma once
11 
12 #include "EnvelopeParser.h"
13 
14 
15 
16 
17 
20 {
21 public:
22  class cCallbacks
23  {
24  public:
25  // Force a virtual destructor in descendants:
26  virtual ~cCallbacks() {}
27 
29  virtual void OnPartStart(void) = 0;
30 
32  virtual void OnPartHeader(const AString & a_Key, const AString & a_Value) = 0;
33 
35  virtual void OnPartData(const char * a_Data, size_t a_Size) = 0;
36 
38  virtual void OnPartEnd(void) = 0;
39  } ;
40 
42  cMultipartParser(const AString & a_ContentType, cCallbacks & a_Callbacks);
43 
45  void Parse(const char * a_Data, size_t a_Size);
46 
47 protected:
50 
52  bool m_IsValid;
53 
56 
59 
62 
65 
66 
68  void ParseLine(const char * a_Data, size_t a_Size);
69 
71  void ParseHeaderLine(const char * a_Data, size_t a_Size);
72 
73  // cEnvelopeParser overrides:
74  virtual void OnHeaderLine(const AString & a_Key, const AString & a_Value) override;
75 } ;
76 
77 
78 
79 
std::string AString
Definition: StringUtils.h:11
virtual void OnHeaderLine(const AString &a_Key, const AString &a_Value) override
Called when a full header line is parsed.
cCallbacks & m_Callbacks
The callbacks to call for various parsing events.
bool m_IsValid
True if the data parsed so far is valid; if false, further parsing is skipped.
void ParseLine(const char *a_Data, size_t a_Size)
Parse one line of incoming data.
cMultipartParser(const AString &a_ContentType, cCallbacks &a_Callbacks)
Creates the parser, expects to find the boundary in a_ContentType.
cEnvelopeParser m_EnvelopeParser
Parser for each part's envelope.
AString m_Boundary
The boundary, excluding both the initial "--" and the terminating CRLF.
void Parse(const char *a_Data, size_t a_Size)
Parses more incoming data.
void ParseHeaderLine(const char *a_Data, size_t a_Size)
Parse one line of incoming data in the headers section of a part.
bool m_HasHadData
Set to true if some data for the current part has already been signalized to m_Callbacks.
AString m_IncomingData
Buffer for the incoming data until it is parsed.
virtual void OnPartHeader(const AString &a_Key, const AString &a_Value)=0
Called when a complete header line is received for a part.
virtual void OnPartStart(void)=0
Called when a new part starts.
virtual void OnPartEnd(void)=0
Called when the current part ends.
virtual void OnPartData(const char *a_Data, size_t a_Size)=0
Called when body for a part is received.