From c4529f0f99de3ad695bc150cf06545c3c1d2751b Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Fri, 22 Jan 2016 12:58:44 +0200 Subject: [PATCH] expose urlDecode to the masses --- src/ESPAsyncWebServer.h | 2 +- src/WebHandlers.cpp | 2 -- src/WebServerClient.cpp | 23 +++++++++-------------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/ESPAsyncWebServer.h b/src/ESPAsyncWebServer.h index 036fb81..d1bfdc9 100644 --- a/src/ESPAsyncWebServer.h +++ b/src/ESPAsyncWebServer.h @@ -121,7 +121,6 @@ class AsyncWebServerRequest { void _onData(void *buf, size_t len); void _addParam(AsyncWebParameter*); - String _urlDecode(const String& text); bool _parseReqHead(); bool _parseReqHeader(); @@ -190,6 +189,7 @@ class AsyncWebServerRequest { String headerName(int i); // get request header name by number bool hasHeader(const char* name); // check if header exists + String urlDecode(const String& text); }; /* diff --git a/src/WebHandlers.cpp b/src/WebHandlers.cpp index 5c87499..de74b4a 100644 --- a/src/WebHandlers.cpp +++ b/src/WebHandlers.cpp @@ -38,5 +38,3 @@ void AsyncStaticWebHandler::handleRequest(AsyncWebServerRequest *request){ request->send(404); path = String(); } - - diff --git a/src/WebServerClient.cpp b/src/WebServerClient.cpp index 284028b..f2088d6 100644 --- a/src/WebServerClient.cpp +++ b/src/WebServerClient.cpp @@ -173,7 +173,7 @@ void AsyncWebServerRequest::_addParam(AsyncWebParameter *p){ } void AsyncWebServerRequest::_addGetParam(String param){ - param = _urlDecode(param); + param = urlDecode(param); String name = param; String value = ""; if(param.indexOf('=') > 0){ @@ -277,7 +277,7 @@ void AsyncWebServerRequest::_parsePlainPostChar(uint8_t data){ if(data && (char)data != '&') _temp += (char)data; if(!data || (char)data == '&' || _parsedLength == _contentLength){ - _temp = _urlDecode(_temp); + _temp = urlDecode(_temp); String name = "body"; String value = _temp; if(!_temp.startsWith("{") && !_temp.startsWith("[") && _temp.indexOf('=') > 0){ @@ -440,7 +440,7 @@ void AsyncWebServerRequest::_parseMultipartPostByte(uint8_t data, bool last){ } } else if(_multiParseState == DASH3_OR_RETURN2){ if(data == '-' && (_contentLength - _parsedLength - 4) != 0){ - os_printf("ERROR: The parser got to the end of the POST but is expecting % bytes more!\nDrop an issue so we can have more info on the matter!\n", _contentLength - _parsedLength - 4); + os_printf("ERROR: The parser got to the end of the POST but is expecting %u bytes more!\nDrop an issue so we can have more info on the matter!\n", _contentLength - _parsedLength - 4); _contentLength = _parsedLength + 4;//lets close the request gracefully } if(data == '\r'){ @@ -728,28 +728,23 @@ bool AsyncWebServerRequest::hasHeader(const char* name){ } -String AsyncWebServerRequest::_urlDecode(const String& text){ +String AsyncWebServerRequest::urlDecode(const String& text){ String decoded = ""; char temp[] = "0x00"; unsigned int len = text.length(); unsigned int i = 0; - while (i < len) - { + while (i < len){ char decodedChar; char encodedChar = text.charAt(i++); - if ((encodedChar == '%') && (i + 1 < len)) - { + if ((encodedChar == '%') && (i + 1 < len)){ temp[2] = text.charAt(i++); temp[3] = text.charAt(i++); decodedChar = strtol(temp, NULL, 16); - } - else { - if (encodedChar == '+') - { + } else { + if (encodedChar == '+'){ decodedChar = ' '; - } - else { + } else { decodedChar = encodedChar; // normal ascii char } }