WebAdmin uses the new HTTP functionality.
This is a partial implementation of #183.
This commit is contained in:
@@ -32,7 +32,7 @@ cHTTPFormParser::cHTTPFormParser(cHTTPRequest & a_Request, cCallbacks & a_Callba
|
||||
}
|
||||
if ((a_Request.GetMethod() == "POST") || (a_Request.GetMethod() == "PUT"))
|
||||
{
|
||||
if (a_Request.GetContentType() == "application/x-www-form-urlencoded")
|
||||
if (strncmp(a_Request.GetContentType().c_str(), "application/x-www-form-urlencoded", 33) == 0)
|
||||
{
|
||||
m_Kind = fpkFormUrlEncoded;
|
||||
return;
|
||||
@@ -44,7 +44,8 @@ cHTTPFormParser::cHTTPFormParser(cHTTPRequest & a_Request, cCallbacks & a_Callba
|
||||
return;
|
||||
}
|
||||
}
|
||||
ASSERT(!"Unhandled request method");
|
||||
// Invalid method / content type combination, this is not a HTTP form
|
||||
m_IsValid = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -120,6 +120,23 @@ int cHTTPRequest::ParseHeaders(const char * a_Data, int a_Size)
|
||||
|
||||
|
||||
|
||||
AString cHTTPRequest::GetBareURL(void) const
|
||||
{
|
||||
size_t idxQM = m_URL.find('?');
|
||||
if (idxQM != AString::npos)
|
||||
{
|
||||
return m_URL.substr(0, idxQM);
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_URL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int cHTTPRequest::ParseRequestLine(const char * a_Data, int a_Size)
|
||||
{
|
||||
m_IncomingHeaderData.append(a_Data, a_Size);
|
||||
|
||||
@@ -82,6 +82,9 @@ public:
|
||||
/// Returns the URL used in the request
|
||||
const AString & GetURL(void) const { return m_URL; }
|
||||
|
||||
/// Returns the URL used in the request, without any parameters
|
||||
AString GetBareURL(void) const;
|
||||
|
||||
/// Sets the UserData pointer that is stored within this request. The request doesn't touch this data (doesn't delete it)!
|
||||
void SetUserData(void * a_UserData) { m_UserData = a_UserData; }
|
||||
|
||||
|
||||
@@ -127,25 +127,16 @@ cHTTPServer::cHTTPServer(void) :
|
||||
|
||||
|
||||
|
||||
bool cHTTPServer::Initialize(cIniFile & a_IniFile)
|
||||
bool cHTTPServer::Initialize(const AString & a_PortsIPv4, const AString & a_PortsIPv6)
|
||||
{
|
||||
if (!a_IniFile.GetValueSetB("WebAdmin", "Enabled", false))
|
||||
{
|
||||
// The WebAdmin is disabled
|
||||
return true;
|
||||
}
|
||||
bool HasAnyPort;
|
||||
HasAnyPort = m_ListenThreadIPv4.Initialize(a_IniFile.GetValueSet("WebAdmin", "Port", "8081"));
|
||||
HasAnyPort = m_ListenThreadIPv6.Initialize(a_IniFile.GetValueSet("WebAdmin", "PortsIPv6", "8082, 3300")) || HasAnyPort;
|
||||
HasAnyPort = m_ListenThreadIPv4.Initialize(a_PortsIPv4);
|
||||
HasAnyPort = m_ListenThreadIPv6.Initialize(a_PortsIPv6) || HasAnyPort;
|
||||
if (!HasAnyPort)
|
||||
{
|
||||
LOG("WebAdmin is disabled");
|
||||
return false;
|
||||
}
|
||||
|
||||
// DEBUG:
|
||||
return Start(g_DebugCallbacks);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,8 @@ public:
|
||||
|
||||
cHTTPServer(void);
|
||||
|
||||
bool Initialize(cIniFile & a_IniFile);
|
||||
/// Initializes the server on the specified ports
|
||||
bool Initialize(const AString & a_PortsIPv4, const AString & a_PortsIPv6);
|
||||
|
||||
/// Starts the server and assigns the callbacks to use for incoming requests
|
||||
bool Start(cCallbacks & a_Callbacks);
|
||||
|
||||
Reference in New Issue
Block a user