Cuberite
A lightweight, fast and extensible game server for Minecraft
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cHTTPFormParser Class Reference

#include <HTTPFormParser.h>

Inheritance diagram for cHTTPFormParser:
Inheritance graph
[legend]
Collaboration diagram for cHTTPFormParser:
Collaboration graph
[legend]

Classes

class  cCallbacks
 

Public Types

enum  eKind { fpkURL , fpkFormUrlEncoded , fpkMultipart }
 

Public Member Functions

 cHTTPFormParser (const cHTTPIncomingRequest &a_Request, cCallbacks &a_Callbacks)
 Creates a parser that is tied to a request and notifies of various events using a callback mechanism. More...
 
 cHTTPFormParser (eKind a_Kind, const char *a_Data, size_t a_Size, cCallbacks &a_Callbacks)
 Creates a parser with the specified content type that reads data from a string. More...
 
bool Finish (void)
 Notifies that there's no more data incoming and the parser should finish its parsing. More...
 
void Parse (const char *a_Data, size_t a_Size)
 Adds more data into the parser, as the request body is received. More...
 
- Public Member Functions inherited from cMultipartParser::cCallbacks
virtual ~cCallbacks ()
 

Static Public Member Functions

static bool HasFormData (const cHTTPIncomingRequest &a_Request)
 Returns true if the headers suggest the request has form data parseable by this class. More...
 

Protected Member Functions

void BeginMultipart (const cHTTPIncomingRequest &a_Request)
 Sets up the object for parsing a fpkMultipart request. More...
 
virtual void OnPartData (const char *a_Data, size_t a_Size) override
 Called when body for a part is received. More...
 
virtual void OnPartEnd (void) override
 Called when the current part ends. More...
 
virtual void OnPartHeader (const AString &a_Key, const AString &a_Value) override
 Called when a complete header line is received for a part. More...
 
virtual void OnPartStart (void) override
 Called when a new part starts. More...
 
void ParseFormUrlEncoded (void)
 Parses m_IncomingData as form-urlencoded data (fpkURL or fpkFormUrlEncoded kinds) More...
 

Protected Attributes

cCallbacksm_Callbacks
 The callbacks to call for incoming file data. More...
 
AString m_CurrentPartFileName
 Filename of the current parsed part in multipart data (for file uploads) More...
 
AString m_CurrentPartName
 Name of the currently parsed part in multipart data. More...
 
bool m_FileHasBeenAnnounced
 Set to true after m_Callbacks.OnFileStart() has been called, reset to false on PartEnd. More...
 
AString m_IncomingData
 Buffer for the incoming data until it's parsed. More...
 
bool m_IsCurrentPartFile
 True if the currently parsed part in multipart data is a file. More...
 
bool m_IsValid
 True if the information received so far is a valid form; set to false on first problem. More...
 
eKind m_Kind
 The kind of the parser (decided in the constructor, used in Parse() More...
 
std::unique_ptr< cMultipartParserm_MultipartParser
 The parser for the multipart data, if used. More...
 

Detailed Description

Definition at line 24 of file HTTPFormParser.h.

Member Enumeration Documentation

◆ eKind

Enumerator
fpkURL 

The form has been transmitted as parameters to a GET request.

fpkFormUrlEncoded 

The form has been POSTed or PUT, with Content-Type of "application/x-www-form-urlencoded".

fpkMultipart 

The form has been POSTed or PUT, with Content-Type of "multipart/form-data".

Definition at line 29 of file HTTPFormParser.h.

Constructor & Destructor Documentation

◆ cHTTPFormParser() [1/2]

cHTTPFormParser::cHTTPFormParser ( const cHTTPIncomingRequest a_Request,
cCallbacks a_Callbacks 
)

Creates a parser that is tied to a request and notifies of various events using a callback mechanism.

Definition at line 15 of file HTTPFormParser.cpp.

◆ cHTTPFormParser() [2/2]

cHTTPFormParser::cHTTPFormParser ( eKind  a_Kind,
const char *  a_Data,
size_t  a_Size,
cCallbacks a_Callbacks 
)

Creates a parser with the specified content type that reads data from a string.

Definition at line 56 of file HTTPFormParser.cpp.

Member Function Documentation

◆ BeginMultipart()

void cHTTPFormParser::BeginMultipart ( const cHTTPIncomingRequest a_Request)
protected

Sets up the object for parsing a fpkMultipart request.

Definition at line 140 of file HTTPFormParser.cpp.

◆ Finish()

bool cHTTPFormParser::Finish ( void  )

Notifies that there's no more data incoming and the parser should finish its parsing.

Returns true if parsing successful.

Definition at line 99 of file HTTPFormParser.cpp.

◆ HasFormData()

bool cHTTPFormParser::HasFormData ( const cHTTPIncomingRequest a_Request)
static

Returns true if the headers suggest the request has form data parseable by this class.

Definition at line 123 of file HTTPFormParser.cpp.

◆ OnPartData()

void cHTTPFormParser::OnPartData ( const char *  a_Data,
size_t  a_Size 
)
overrideprotectedvirtual

Called when body for a part is received.

Implements cMultipartParser::cCallbacks.

Definition at line 253 of file HTTPFormParser.cpp.

◆ OnPartEnd()

void cHTTPFormParser::OnPartEnd ( void  )
overrideprotectedvirtual

Called when the current part ends.

Implements cMultipartParser::cCallbacks.

Definition at line 289 of file HTTPFormParser.cpp.

◆ OnPartHeader()

void cHTTPFormParser::OnPartHeader ( const AString a_Key,
const AString a_Value 
)
overrideprotectedvirtual

Called when a complete header line is received for a part.

Implements cMultipartParser::cCallbacks.

Definition at line 208 of file HTTPFormParser.cpp.

◆ OnPartStart()

void cHTTPFormParser::OnPartStart ( void  )
overrideprotectedvirtual

Called when a new part starts.

Implements cMultipartParser::cCallbacks.

Definition at line 196 of file HTTPFormParser.cpp.

◆ Parse()

void cHTTPFormParser::Parse ( const char *  a_Data,
size_t  a_Size 
)

Adds more data into the parser, as the request body is received.

Definition at line 70 of file HTTPFormParser.cpp.

◆ ParseFormUrlEncoded()

void cHTTPFormParser::ParseFormUrlEncoded ( void  )
protected

Parses m_IncomingData as form-urlencoded data (fpkURL or fpkFormUrlEncoded kinds)

Definition at line 150 of file HTTPFormParser.cpp.

Member Data Documentation

◆ m_Callbacks

cCallbacks& cHTTPFormParser::m_Callbacks
protected

The callbacks to call for incoming file data.

Definition at line 72 of file HTTPFormParser.h.

◆ m_CurrentPartFileName

AString cHTTPFormParser::m_CurrentPartFileName
protected

Filename of the current parsed part in multipart data (for file uploads)

Definition at line 93 of file HTTPFormParser.h.

◆ m_CurrentPartName

AString cHTTPFormParser::m_CurrentPartName
protected

Name of the currently parsed part in multipart data.

Definition at line 87 of file HTTPFormParser.h.

◆ m_FileHasBeenAnnounced

bool cHTTPFormParser::m_FileHasBeenAnnounced
protected

Set to true after m_Callbacks.OnFileStart() has been called, reset to false on PartEnd.

Definition at line 96 of file HTTPFormParser.h.

◆ m_IncomingData

AString cHTTPFormParser::m_IncomingData
protected

Buffer for the incoming data until it's parsed.

Definition at line 78 of file HTTPFormParser.h.

◆ m_IsCurrentPartFile

bool cHTTPFormParser::m_IsCurrentPartFile
protected

True if the currently parsed part in multipart data is a file.

Definition at line 90 of file HTTPFormParser.h.

◆ m_IsValid

bool cHTTPFormParser::m_IsValid
protected

True if the information received so far is a valid form; set to false on first problem.

Further parsing is skipped when false.

Definition at line 81 of file HTTPFormParser.h.

◆ m_Kind

eKind cHTTPFormParser::m_Kind
protected

The kind of the parser (decided in the constructor, used in Parse()

Definition at line 75 of file HTTPFormParser.h.

◆ m_MultipartParser

std::unique_ptr<cMultipartParser> cHTTPFormParser::m_MultipartParser
protected

The parser for the multipart data, if used.

Definition at line 84 of file HTTPFormParser.h.


The documentation for this class was generated from the following files: