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;
_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");

View File

@ -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;
};