Skip to content

Commit aa4dac9

Browse files
committed
remove recursion
1 parent 454a065 commit aa4dac9

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

libraries/ESP8266WebServer/src/ESP8266WebServer.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ class ESP8266WebServer
142142
void _handleRequest();
143143
void _finalizeResponse();
144144
bool _parseRequest(WiFiClient& client);
145-
int _parseArguments(const String& data, bool store = true);
145+
void _parseArguments(const String& data);
146+
int _parseArgumentsPrivate(const String& data, int counted);
146147
static String _responseCodeToString(int code);
147148
bool _parseForm(WiFiClient& client, String boundary, uint32_t len);
148149
bool _parseFormUploadAborted();

libraries/ESP8266WebServer/src/Parsing.cpp

+13-12
Original file line numberDiff line numberDiff line change
@@ -270,26 +270,27 @@ bool ESP8266WebServer::_collectHeader(const char* headerName, const char* header
270270
return false;
271271
}
272272

273-
int ESP8266WebServer::_parseArguments(const String& data, bool store) {
274-
// when store is true, a recursive call
275-
// with store=false is recursively called first
276-
// to evaluate the number of arguments
277-
// should we use a vector instead?
273+
void ESP8266WebServer::_parseArguments(const String& data) {
274+
int counted = _parseArgumentsPrivate(data, 0);
275+
(void)_parseArgumentsPrivate(data, counted);
276+
}
277+
278+
int ESP8266WebServer::_parseArgumentsPrivate(const String& data, int counted) {
279+
// counted==0: parsing only, return counted arguments
280+
// counted!=0: parsing and storing "counted" arguments
278281

279282
#ifdef DEBUG_ESP_HTTP_SERVER
280283
DEBUG_OUTPUT.print("args: ");
281284
DEBUG_OUTPUT.println(data);
282285
#endif
283286

284-
if (store) {
287+
if (counted > 0) {
285288
if (_currentArgs)
286289
delete[] _currentArgs;
287290
_currentArgs = 0;
288-
}
289291

290-
if (store) {
291-
_currentArgCount = _parseArguments(data, false);
292-
_currentArgs = new RequestArgument[_currentArgCount+1];
292+
// allocate one more, this is needed (search "plainBuf" in this file)
293+
_currentArgs = new RequestArgument[(_currentArgCount = counted) + 1];
293294
}
294295

295296
size_t pos = 0;
@@ -319,7 +320,7 @@ int ESP8266WebServer::_parseArguments(const String& data, bool store) {
319320
if (keyEndPos >= (int)pos) {
320321
// do not store or count empty ending key ("url?x=y;")
321322

322-
if (store) {
323+
if (counted > 0) {
323324
RequestArgument& arg = _currentArgs[arg_total];
324325
arg.key = urlDecode(data.substring(pos, keyEndPos));
325326
if ((equal_index != -1) && ((equal_index < next_index - 1) || (next_index == -1)))
@@ -347,7 +348,7 @@ int ESP8266WebServer::_parseArguments(const String& data, bool store) {
347348
DEBUG_OUTPUT.println(arg_total);
348349
#endif
349350

350-
if (store)
351+
if (counted > 0)
351352
_currentArgCount = arg_total;
352353

353354
return arg_total;

0 commit comments

Comments
 (0)