summaryrefslogtreecommitdiffstats
path: root/source/HTTPServer/HTTPFormParser.h
blob: 01446e865da6e9e2429ceb19d6b369207dd6f575 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

// HTTPFormParser.h

// Declares the cHTTPFormParser class representing a parser for forms sent over HTTP




#pragma once





// fwd:
class cHTTPRequest;





class cHTTPFormParser :
	public std::map<AString, AString>
{
public:
	cHTTPFormParser(cHTTPRequest & a_Request);
	
	/// Adds more data into the parser, as the request body is received
	void Parse(const char * a_Data, int a_Size);
	
	/** Notifies that there's no more data incoming and the parser should finish its parsing.
	Returns true if parsing successful
	*/
	bool Finish(void);
	
	/// Returns true if the headers suggest the request has form data parseable by this class
	static bool HasFormData(const cHTTPRequest & a_Request);
	
protected:
	enum eKind
	{
		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/*". Currently unsupported
	};

	/// The kind of the parser (decided in the constructor, used in Parse()
	eKind m_Kind;
	
	AString m_IncomingData;
	
	bool m_IsValid;
	
	/// Simple static objects to hold the various strings for comparison with request's content-type
	static AString m_FormURLEncoded;
	static AString m_MultipartFormData;
		
	
	/// Parses m_IncomingData as form-urlencoded data (fpkURL or fpkFormUrlEncoded kinds)
	void ParseFormUrlEncoded(void);
	
	/// Parses m_IncomingData as multipart data (fpkMultipart kind)
	void ParseMultipart(void);
} ;