|
32 | 32 | #define DEBUG_OUTPUT Serial
|
33 | 33 | #endif
|
34 | 34 |
|
| 35 | +#ifndef WEBSERVER_MAX_POST_ARGS |
| 36 | +#define WEBSERVER_MAX_POST_ARGS 32 |
| 37 | +#endif |
| 38 | + |
35 | 39 | static const char Content_Type[] PROGMEM = "Content-Type";
|
36 | 40 | static const char filename[] PROGMEM = "filename";
|
37 | 41 |
|
@@ -383,8 +387,9 @@ bool WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){
|
383 | 387 | client.readStringUntil('\n');
|
384 | 388 | //start reading the form
|
385 | 389 | if (line == ("--"+boundary)){
|
386 |
| - RequestArgument* postArgs = new RequestArgument[32]; |
387 |
| - int postArgsLen = 0; |
| 390 | + if(_postArgs) delete[] _postArgs; |
| 391 | + _postArgs = new RequestArgument[WEBSERVER_MAX_POST_ARGS]; |
| 392 | + _postArgsLen = 0; |
388 | 393 | while(1){
|
389 | 394 | String argName;
|
390 | 395 | String argValue;
|
@@ -445,7 +450,7 @@ bool WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){
|
445 | 450 | DEBUG_OUTPUT.println();
|
446 | 451 | #endif
|
447 | 452 |
|
448 |
| - RequestArgument& arg = postArgs[postArgsLen++]; |
| 453 | + RequestArgument& arg = _postArgs[_postArgsLen++]; |
449 | 454 | arg.key = argName;
|
450 | 455 | arg.value = argValue;
|
451 | 456 |
|
@@ -552,22 +557,25 @@ bool WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){
|
552 | 557 | }
|
553 | 558 |
|
554 | 559 | int iarg;
|
555 |
| - int totalArgs = ((32 - postArgsLen) < _currentArgCount)?(32 - postArgsLen):_currentArgCount; |
| 560 | + int totalArgs = ((WEBSERVER_MAX_POST_ARGS - _postArgsLen) < _currentArgCount)?(WEBSERVER_MAX_POST_ARGS - _postArgsLen):_currentArgCount; |
556 | 561 | for (iarg = 0; iarg < totalArgs; iarg++){
|
557 |
| - RequestArgument& arg = postArgs[postArgsLen++]; |
| 562 | + RequestArgument& arg = _postArgs[_postArgsLen++]; |
558 | 563 | arg.key = _currentArgs[iarg].key;
|
559 | 564 | arg.value = _currentArgs[iarg].value;
|
560 | 565 | }
|
561 | 566 | if (_currentArgs) delete[] _currentArgs;
|
562 |
| - _currentArgs = new RequestArgument[postArgsLen]; |
563 |
| - for (iarg = 0; iarg < postArgsLen; iarg++){ |
| 567 | + _currentArgs = new RequestArgument[_postArgsLen]; |
| 568 | + for (iarg = 0; iarg < _postArgsLen; iarg++){ |
564 | 569 | RequestArgument& arg = _currentArgs[iarg];
|
565 |
| - arg.key = postArgs[iarg].key; |
566 |
| - arg.value = postArgs[iarg].value; |
| 570 | + arg.key = _postArgs[iarg].key; |
| 571 | + arg.value = _postArgs[iarg].value; |
567 | 572 | }
|
568 | 573 | _currentArgCount = iarg;
|
569 |
| - if (postArgs) |
570 |
| - delete[] postArgs; |
| 574 | + if (_postArgs) { |
| 575 | + delete[] _postArgs; |
| 576 | + _postArgs=nullptr; |
| 577 | + _postArgsLen = 0; |
| 578 | + } |
571 | 579 | return true;
|
572 | 580 | }
|
573 | 581 | #ifdef DEBUG_ESP_HTTP_SERVER
|
|
0 commit comments