Move request buff to stack

Save 384 heap bytes by handling the web request buffering in the loop()
stack context.
This commit is contained in:
Earle F. Philhower, III committed 2017-12-14 09:47:00 -08:00
1 parent ec4979e6f5
commit 143c4e65ae
3 files changed
+7 -8

No files matched your search

+3 -2
View File
@@ -319,7 +319,7 @@ void loop()
if (decoder && decoder->isRunning()) {
strcpy_P(status, PSTR("Playing")); // By default we're OK unless the decoder says otherwise
if (!decoder->loop()) {
Serial.printf_P(PSTR("Stopping decoder"));
Serial.printf_P(PSTR("Stopping decoder\n"));
decoder->stop();
strcpy_P(title, PSTR("Stopped"));
}
@@ -330,7 +330,8 @@ void loop()
char *reqUrl;
char *params;
WiFiClient client = server.available();
if (client && WebReadRequest(&client, &reqUrl, &params)) {
char *reqBuff = (char *)alloca(384);
if (client && WebReadRequest(&client, reqBuff, 384, &reqUrl, &params)) {
Serial.printf_P(PSTR("URL: '%s'\n"), reqUrl);
if (IsIndexHTML(reqUrl)) {
HandleIndex(&client);
+3 -5
View File
@@ -24,8 +24,6 @@
#define LogPrintf(fmt, ...) { Serial.printf_P(PSTR(fmt), ## __VA_ARGS__); }
// Web request line (URL, PARAMs parsed in-line)
static char reqBuff[384];
void WebPrintError(WiFiClient *client, int code)
{
@@ -155,7 +153,7 @@ void URLDecode(char *ptr)
// Parse HTTP request
bool WebReadRequest(WiFiClient *client, char **urlStr, char **paramStr)
bool WebReadRequest(WiFiClient *client, char *reqBuff, int reqBuffLen, char **urlStr, char **paramStr)
{
static char NUL = 0; // Get around writable strings...
@@ -169,7 +167,7 @@ bool WebReadRequest(WiFiClient *client, char **urlStr, char **paramStr)
LogPrintf("-WebReadRequest: Timeout @ %d\n", millis());
return false;
}
int wlen = client->readBytesUntil('\r', reqBuff, sizeof(reqBuff)-1);
int wlen = client->readBytesUntil('\r', reqBuff, reqBuffLen-1);
reqBuff[wlen] = 0;
@@ -206,7 +204,7 @@ bool WebReadRequest(WiFiClient *client, char **urlStr, char **paramStr)
qp = strchr(url, '?');
if (qp) *qp = 0; // End URL @ ?
// In a POST the params are in the body
int sizeleft = sizeof(reqBuff) - strlen(reqBuff) - 1;
int sizeleft = reqBuffLen - strlen(reqBuff) - 1;
qp = reqBuff + strlen(reqBuff) + 1;
int wlen = client->readBytesUntil('\r', qp, sizeleft-1);
qp[wlen] = 0;
+1 -1
View File
@@ -41,7 +41,7 @@ void Base64Decode(char *str); // In-place B64 decode
void URLDecode(char *ptr); // In-place URL decode
// GET/POST parsing
bool WebReadRequest(WiFiClient *client, char **urlStr, char **paramStr);
bool WebReadRequest(WiFiClient *client, char *reqBuff, int reqBuffLen, char **urlStr, char **paramStr);
bool ParseParam(char **paramStr, char **name, char **value); // Get next name/parameter from a param string
bool IsIndexHTML(const char *url); // Is this meant to be index.html (/, index.htm, etc.)