1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

Update ESP8266HTTPUpdateServer library (#5297)

* Converted C type strings to String object

* Converted C type strings to String object
This commit is contained in:
dav1901 2018-11-13 05:43:21 +02:00 committed by Develo
parent 979e5cebd9
commit 41de43a263
2 changed files with 19 additions and 19 deletions

View File

@ -20,26 +20,26 @@ ESP8266HTTPUpdateServer::ESP8266HTTPUpdateServer(bool serial_debug)
{ {
_serial_output = serial_debug; _serial_output = serial_debug;
_server = NULL; _server = NULL;
_username = NULL; _username = emptyString;
_password = NULL; _password = emptyString;
_authenticated = false; _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; _server = server;
_username = (char *)username; _username = username;
_password = (char *)password; _password = password;
// handler for the /update form page // handler for the /update form page
_server->on(path, HTTP_GET, [&](){ _server->on(path.c_str(), HTTP_GET, [&](){
if(_username != NULL && _password != NULL && !_server->authenticate(_username, _password)) if(_username != emptyString && _password != emptyString && !_server->authenticate(_username.c_str(), _password.c_str()))
return _server->requestAuthentication(); return _server->requestAuthentication();
_server->send_P(200, PSTR("text/html"), serverIndex); _server->send_P(200, PSTR("text/html"), serverIndex);
}); });
// handler for the /update form POST (once file upload finishes) // handler for the /update form POST (once file upload finishes)
_server->on(path, HTTP_POST, [&](){ _server->on(path.c_str(), HTTP_POST, [&](){
if(!_authenticated) if(!_authenticated)
return _server->requestAuthentication(); return _server->requestAuthentication();
if (Update.hasError()) { if (Update.hasError()) {
@ -61,7 +61,7 @@ void ESP8266HTTPUpdateServer::setup(ESP8266WebServer *server, const char * path,
if (_serial_output) if (_serial_output)
Serial.setDebugOutput(true); 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(!_authenticated){
if (_serial_output) if (_serial_output)
Serial.printf("Unauthenticated Update\n"); Serial.printf("Unauthenticated Update\n");

View File

@ -10,25 +10,25 @@ class ESP8266HTTPUpdateServer
void setup(ESP8266WebServer *server) 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); 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; _username = username;
_password = (char *)password; _password = password;
} }
protected: protected:
@ -37,8 +37,8 @@ class ESP8266HTTPUpdateServer
private: private:
bool _serial_output; bool _serial_output;
ESP8266WebServer *_server; ESP8266WebServer *_server;
char * _username; String _username;
char * _password; String _password;
bool _authenticated; bool _authenticated;
String _updaterError; String _updaterError;
}; };