http server send file mechanism reworked with constant buffer size
This commit is contained in:
parent
27835c9496
commit
be93495134
|
|
@ -586,8 +586,8 @@ static void HTTPPrint_ifc_mq2(char *VarData, void *arg)
|
||||||
|
|
||||||
static void HTTPPrint_testvariable(char *VarData, void *arg)
|
static void HTTPPrint_testvariable(char *VarData, void *arg)
|
||||||
{
|
{
|
||||||
static int counter = 0;
|
static int counter = 1;
|
||||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "[%d]", counter++);
|
snprintf(VarData, MAX_DYNVAR_LENGTH, "[Long extended dynamic variable number %d]", counter++);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Default string if not found handler
|
//Default string if not found handler
|
||||||
|
|
|
||||||
|
|
@ -354,7 +354,6 @@ static esp_err_t GETHandler(httpd_req_t *req)
|
||||||
//check if the file can contains dynamic variables
|
//check if the file can contains dynamic variables
|
||||||
if (IS_FILE_EXT(filename, ".html") || IS_FILE_EXT(filename, ".json"))
|
if (IS_FILE_EXT(filename, ".html") || IS_FILE_EXT(filename, ".json"))
|
||||||
isDynamicVars = true;
|
isDynamicVars = true;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
int pt = 0;
|
int pt = 0;
|
||||||
|
|
@ -366,12 +365,13 @@ static esp_err_t GETHandler(httpd_req_t *req)
|
||||||
int k = 0;
|
int k = 0;
|
||||||
char ch = 0x00;
|
char ch = 0x00;
|
||||||
char DynVarName[MAX_DYNVAR_NAME_LENGTH];
|
char DynVarName[MAX_DYNVAR_NAME_LENGTH];
|
||||||
|
pt++; //skip open tag
|
||||||
while (k < MAX_DYNVAR_NAME_LENGTH)
|
while (k < MAX_DYNVAR_NAME_LENGTH)
|
||||||
{
|
{
|
||||||
if (pt < bufSize)
|
if (pt < bufSize)
|
||||||
{
|
{
|
||||||
if (buf[++pt] != '~')
|
if (buf[pt] != '~')
|
||||||
DynVarName[k++] = buf[pt]; //continue extract variable name from buf
|
DynVarName[k++] = buf[pt++]; //continue extract variable name from buf
|
||||||
else
|
else
|
||||||
break; //found close tag
|
break; //found close tag
|
||||||
}
|
}
|
||||||
|
|
@ -388,25 +388,19 @@ static esp_err_t GETHandler(httpd_req_t *req)
|
||||||
else
|
else
|
||||||
//unexpected end of file
|
//unexpected end of file
|
||||||
goto file_send_error;
|
goto file_send_error;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[pt] == '~' || ch == '~') //close tag, got valid dynamic variable name
|
if (buf[pt] == '~' || ch == '~') //close tag, got valid dynamic variable name
|
||||||
{
|
{
|
||||||
DynVarName[k] = 0x00;
|
DynVarName[k] = 0x00;
|
||||||
preparedBytes += HTTPPrint(req, &chunk[preparedBytes], DynVarName);
|
preparedBytes += HTTPPrint(req, &chunk[preparedBytes], DynVarName);
|
||||||
|
//skip close '~' in buf but not directly in file!
|
||||||
//skip close '~' in buf or directly in file
|
if (ch != '~')
|
||||||
if (ch == '~')
|
|
||||||
espfs_fread(file, &ch, 1);
|
|
||||||
else
|
|
||||||
pt++;
|
pt++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
//not found close tag, exit by overflow max variable size or file end
|
//not found close tag, exit by overflow max variable size or file end
|
||||||
goto file_send_error;
|
goto file_send_error;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
chunk[preparedBytes++] = buf[pt++]; //write to chunk ordinary character
|
chunk[preparedBytes++] = buf[pt++]; //write to chunk ordinary character
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user