The WEB Server root directory is now copied so that the parameter doesn't have to live during the whole life of the program
This commit is contained in:
parent
2449ab6013
commit
966177a209
@ -42,6 +42,11 @@ class WEBServer : public TCPServer<T>, public HttpConstants
|
||||
|
||||
WEBServer(uint16_t port = 80, SDClass *sdClass = NULL, uint8_t maxClient = MAX_CLIENT, uint16_t clientDataBufferSize = 256) : TCPServer<T>(port, maxClient, clientDataBufferSize), _sdClass(sdClass) {}
|
||||
|
||||
virtual ~WEBServer()
|
||||
{
|
||||
free(_WWWDir);
|
||||
}
|
||||
|
||||
boolean addApiRoutine(const char *uri, boolean (*apiRoutine)(HttpRequestData&, WiFiClient*, void*), void *pData, HttpRequestMethod HRM = UNDEFINED)
|
||||
{
|
||||
return _apiDictionary.add(uri, new ApiRoutine({apiRoutine, pData, HRM}));
|
||||
@ -72,7 +77,12 @@ class WEBServer : public TCPServer<T>, public HttpConstants
|
||||
|
||||
void setWWWDir(const char *WWWDir)
|
||||
{
|
||||
_WWWDir = WWWDir;
|
||||
if(WWWDir != nullptr)
|
||||
{
|
||||
free(_WWWDir);
|
||||
_WWWDir = (char *)malloc((strlen(WWWDir) * sizeof(char)) + 1);
|
||||
strcpy(_WWWDir, WWWDir);
|
||||
}
|
||||
}
|
||||
protected:
|
||||
private:
|
||||
@ -165,11 +175,14 @@ class WEBServer : public TCPServer<T>, public HttpConstants
|
||||
case HttpParserStatus::PARSE_HTTP_RESOURCE:
|
||||
{
|
||||
char *pRsrc(strchr((char *)client->_data, ' ')), *pRsrcQuery(strchr((char *)client->_data, '?'));
|
||||
//!\ the ? should be present before ' ' if ' ' is found !!!!
|
||||
if(pRsrc && pRsrcQuery)
|
||||
if(pRsrcQuery > pRsrc)pRsrcQuery = nullptr;
|
||||
//The case where we have the resource complete or not complete with query parameters like : GET /some/path/resource.rsrc?param1=one¶m2 HTTP/1.1
|
||||
if(pRsrc || pRsrcQuery)
|
||||
{
|
||||
uint16_t rawLengthOfResource(0);
|
||||
if(pRsrcQuery)
|
||||
if(pRsrcQuery )
|
||||
{
|
||||
*pRsrcQuery = '\0'; // The ? is the end of the resource string
|
||||
rawLengthOfResource = pRsrcQuery - (char *)client->_data;
|
||||
@ -182,7 +195,7 @@ class WEBServer : public TCPServer<T>, public HttpConstants
|
||||
*pRsrc = '\0';
|
||||
rawLengthOfResource = pRsrc - (char *)client->_data;
|
||||
#ifdef DEBUG_WEBS
|
||||
Serial.printf("Resource w/o query\n");
|
||||
Serial.printf("Resource w/o query\nRaw length : %u\n",rawLengthOfResource);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -937,7 +950,7 @@ class WEBServer : public TCPServer<T>, public HttpConstants
|
||||
|
||||
Dictionary<ApiRoutine> _apiDictionary;
|
||||
SDClass *_sdClass;
|
||||
const char *_WWWDir = NULL; //Website root folder
|
||||
char *_WWWDir = nullptr; //Website root folder
|
||||
};
|
||||
|
||||
#endif //WEBSERVER_H
|
||||
|
Loading…
Reference in New Issue
Block a user