From 41de43a26381d7c9d29ce879dd5d7c027528371b Mon Sep 17 00:00:00 2001 From: dav1901 <44604348+dav1901@users.noreply.github.com> Date: Tue, 13 Nov 2018 05:43:21 +0200 Subject: [PATCH] Update ESP8266HTTPUpdateServer library (#5297) * Converted C type strings to String object * Converted C type strings to String object --- .../src/ESP8266HTTPUpdateServer.cpp | 18 ++++++++--------- .../src/ESP8266HTTPUpdateServer.h | 20 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.cpp b/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.cpp index 25236294e..b53f0fa74 100644 --- a/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.cpp +++ b/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.cpp @@ -20,26 +20,26 @@ ESP8266HTTPUpdateServer::ESP8266HTTPUpdateServer(bool serial_debug) { _serial_output = serial_debug; _server = NULL; - _username = NULL; - _password = NULL; + _username = emptyString; + _password = emptyString; _authenticated = false; } -void ESP8266HTTPUpdateServer::setup(ESP8266WebServer *server, const char * path, const char * username, const char * password) +void ESP8266HTTPUpdateServer::setup(ESP8266WebServer *server, const String& path, const String& username, const String& password) { _server = server; - _username = (char *)username; - _password = (char *)password; + _username = username; + _password = password; // handler for the /update form page - _server->on(path, HTTP_GET, [&](){ - if(_username != NULL && _password != NULL && !_server->authenticate(_username, _password)) + _server->on(path.c_str(), HTTP_GET, [&](){ + if(_username != emptyString && _password != emptyString && !_server->authenticate(_username.c_str(), _password.c_str())) return _server->requestAuthentication(); _server->send_P(200, PSTR("text/html"), serverIndex); }); // handler for the /update form POST (once file upload finishes) - _server->on(path, HTTP_POST, [&](){ + _server->on(path.c_str(), HTTP_POST, [&](){ if(!_authenticated) return _server->requestAuthentication(); if (Update.hasError()) { @@ -61,7 +61,7 @@ void ESP8266HTTPUpdateServer::setup(ESP8266WebServer *server, const char * path, if (_serial_output) Serial.setDebugOutput(true); - _authenticated = (_username == NULL || _password == NULL || _server->authenticate(_username, _password)); + _authenticated = (_username == emptyString || _password == emptyString || _server->authenticate(_username.c_str(), _password.c_str())); if(!_authenticated){ if (_serial_output) Serial.printf("Unauthenticated Update\n"); diff --git a/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.h b/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.h index d537e5566..a0faa4675 100644 --- a/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.h +++ b/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.h @@ -10,25 +10,25 @@ class ESP8266HTTPUpdateServer void setup(ESP8266WebServer *server) { - setup(server, NULL, NULL); + setup(server, emptyString, emptyString); } - void setup(ESP8266WebServer *server, const char * path) + void setup(ESP8266WebServer *server, const String& path) { - setup(server, path, NULL, NULL); + setup(server, path, emptyString, emptyString); } - void setup(ESP8266WebServer *server, const char * username, const char * password) + void setup(ESP8266WebServer *server, const String& username, const String& password) { setup(server, "/update", username, password); } - void setup(ESP8266WebServer *server, const char * path, const char * username, const char * password); + void setup(ESP8266WebServer *server, const String& path, const String& username, const String& password); - void updateCredentials(const char * username, const char * password) + void updateCredentials(const String& username, const String& password) { - _username = (char *)username; - _password = (char *)password; + _username = username; + _password = password; } protected: @@ -37,8 +37,8 @@ class ESP8266HTTPUpdateServer private: bool _serial_output; ESP8266WebServer *_server; - char * _username; - char * _password; + String _username; + String _password; bool _authenticated; String _updaterError; };