Fixed WebAdmin's request parameters.
Also added doxycomments on what they really contain.
This commit is contained in:
parent
e62cac07c0
commit
efb7d4fd3e
@ -52,6 +52,18 @@ cHTTPFormParser::cHTTPFormParser(cHTTPRequest & a_Request, cCallbacks & a_Callba
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
cHTTPFormParser::cHTTPFormParser(eKind a_Kind, const char * a_Data, int a_Size, cCallbacks & a_Callbacks) :
|
||||||
|
m_Callbacks(a_Callbacks),
|
||||||
|
m_Kind(a_Kind),
|
||||||
|
m_IsValid(true)
|
||||||
|
{
|
||||||
|
Parse(a_Data, a_Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cHTTPFormParser::Parse(const char * a_Data, int a_Size)
|
void cHTTPFormParser::Parse(const char * a_Data, int a_Size)
|
||||||
{
|
{
|
||||||
if (!m_IsValid)
|
if (!m_IsValid)
|
||||||
|
@ -26,6 +26,13 @@ class cHTTPFormParser :
|
|||||||
public cMultipartParser::cCallbacks
|
public cMultipartParser::cCallbacks
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
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/form-data"
|
||||||
|
} ;
|
||||||
|
|
||||||
class cCallbacks
|
class cCallbacks
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -40,8 +47,12 @@ public:
|
|||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
/// Creates a parser that is tied to a request and notifies of various events using a callback mechanism
|
||||||
cHTTPFormParser(cHTTPRequest & a_Request, cCallbacks & a_Callbacks);
|
cHTTPFormParser(cHTTPRequest & a_Request, cCallbacks & a_Callbacks);
|
||||||
|
|
||||||
|
/// Creates a parser with the specified content type that reads data from a string
|
||||||
|
cHTTPFormParser(eKind a_Kind, const char * a_Data, int a_Size, cCallbacks & a_Callbacks);
|
||||||
|
|
||||||
/// Adds more data into the parser, as the request body is received
|
/// Adds more data into the parser, as the request body is received
|
||||||
void Parse(const char * a_Data, int a_Size);
|
void Parse(const char * a_Data, int a_Size);
|
||||||
|
|
||||||
@ -54,12 +65,6 @@ public:
|
|||||||
static bool HasFormData(const cHTTPRequest & a_Request);
|
static bool HasFormData(const cHTTPRequest & a_Request);
|
||||||
|
|
||||||
protected:
|
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/form-data"
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The callbacks to call for incoming file data
|
/// The callbacks to call for incoming file data
|
||||||
cCallbacks & m_Callbacks;
|
cCallbacks & m_Callbacks;
|
||||||
|
@ -185,8 +185,19 @@ void cWebAdmin::HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPReque
|
|||||||
HTTPfd.Name = itr->first;
|
HTTPfd.Name = itr->first;
|
||||||
TemplateRequest.Request.FormData[itr->first] = HTTPfd;
|
TemplateRequest.Request.FormData[itr->first] = HTTPfd;
|
||||||
TemplateRequest.Request.PostParams[itr->first] = itr->second;
|
TemplateRequest.Request.PostParams[itr->first] = itr->second;
|
||||||
TemplateRequest.Request.Params[itr->first] = itr->second;
|
|
||||||
} // for itr - Data->m_Form[]
|
} // for itr - Data->m_Form[]
|
||||||
|
|
||||||
|
// Parse the URL into individual params:
|
||||||
|
size_t idxQM = a_Request.GetURL().find('?');
|
||||||
|
if (idxQM != AString::npos)
|
||||||
|
{
|
||||||
|
cHTTPFormParser URLParams(cHTTPFormParser::fpkURL, a_Request.GetURL().c_str() + idxQM + 1, a_Request.GetURL().length() - idxQM - 1, *Data);
|
||||||
|
URLParams.Finish();
|
||||||
|
for (cHTTPFormParser::const_iterator itr = URLParams.begin(), end = URLParams.end(); itr != end; ++itr)
|
||||||
|
{
|
||||||
|
TemplateRequest.Request.Params[itr->first] = itr->second;
|
||||||
|
} // for itr - URLParams[]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to get the template from the Lua template script
|
// Try to get the template from the Lua template script
|
||||||
|
@ -56,8 +56,14 @@ struct HTTPRequest
|
|||||||
AString Path;
|
AString Path;
|
||||||
AString Username;
|
AString Username;
|
||||||
// tolua_end
|
// tolua_end
|
||||||
|
|
||||||
|
/// Parameters given in the URL, after the questionmark
|
||||||
StringStringMap Params; // >> EXPORTED IN MANUALBINDINGS <<
|
StringStringMap Params; // >> EXPORTED IN MANUALBINDINGS <<
|
||||||
|
|
||||||
|
/// Parameters posted as a part of a form - either in the URL (GET method) or in the body (POST method)
|
||||||
StringStringMap PostParams; // >> EXPORTED IN MANUALBINDINGS <<
|
StringStringMap PostParams; // >> EXPORTED IN MANUALBINDINGS <<
|
||||||
|
|
||||||
|
/// Same as PostParams
|
||||||
FormDataMap FormData; // >> EXPORTED IN MANUALBINDINGS <<
|
FormDataMap FormData; // >> EXPORTED IN MANUALBINDINGS <<
|
||||||
} ; // tolua_export
|
} ; // tolua_export
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user