Skip to content

Commit 41de43a

Browse files
dav1901devyte
authored andcommitted
Update ESP8266HTTPUpdateServer library (#5297)
* Converted C type strings to String object * Converted C type strings to String object
1 parent 979e5ce commit 41de43a

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

Diff for: libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,26 @@ ESP8266HTTPUpdateServer::ESP8266HTTPUpdateServer(bool serial_debug)
2020
{
2121
_serial_output = serial_debug;
2222
_server = NULL;
23-
_username = NULL;
24-
_password = NULL;
23+
_username = emptyString;
24+
_password = emptyString;
2525
_authenticated = false;
2626
}
2727

28-
void ESP8266HTTPUpdateServer::setup(ESP8266WebServer *server, const char * path, const char * username, const char * password)
28+
void ESP8266HTTPUpdateServer::setup(ESP8266WebServer *server, const String& path, const String& username, const String& password)
2929
{
3030
_server = server;
31-
_username = (char *)username;
32-
_password = (char *)password;
31+
_username = username;
32+
_password = password;
3333

3434
// handler for the /update form page
35-
_server->on(path, HTTP_GET, [&](){
36-
if(_username != NULL && _password != NULL && !_server->authenticate(_username, _password))
35+
_server->on(path.c_str(), HTTP_GET, [&](){
36+
if(_username != emptyString && _password != emptyString && !_server->authenticate(_username.c_str(), _password.c_str()))
3737
return _server->requestAuthentication();
3838
_server->send_P(200, PSTR("text/html"), serverIndex);
3939
});
4040

4141
// handler for the /update form POST (once file upload finishes)
42-
_server->on(path, HTTP_POST, [&](){
42+
_server->on(path.c_str(), HTTP_POST, [&](){
4343
if(!_authenticated)
4444
return _server->requestAuthentication();
4545
if (Update.hasError()) {
@@ -61,7 +61,7 @@ void ESP8266HTTPUpdateServer::setup(ESP8266WebServer *server, const char * path,
6161
if (_serial_output)
6262
Serial.setDebugOutput(true);
6363

64-
_authenticated = (_username == NULL || _password == NULL || _server->authenticate(_username, _password));
64+
_authenticated = (_username == emptyString || _password == emptyString || _server->authenticate(_username.c_str(), _password.c_str()));
6565
if(!_authenticated){
6666
if (_serial_output)
6767
Serial.printf("Unauthenticated Update\n");

Diff for: libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ class ESP8266HTTPUpdateServer
1010

1111
void setup(ESP8266WebServer *server)
1212
{
13-
setup(server, NULL, NULL);
13+
setup(server, emptyString, emptyString);
1414
}
1515

16-
void setup(ESP8266WebServer *server, const char * path)
16+
void setup(ESP8266WebServer *server, const String& path)
1717
{
18-
setup(server, path, NULL, NULL);
18+
setup(server, path, emptyString, emptyString);
1919
}
2020

21-
void setup(ESP8266WebServer *server, const char * username, const char * password)
21+
void setup(ESP8266WebServer *server, const String& username, const String& password)
2222
{
2323
setup(server, "/update", username, password);
2424
}
2525

26-
void setup(ESP8266WebServer *server, const char * path, const char * username, const char * password);
26+
void setup(ESP8266WebServer *server, const String& path, const String& username, const String& password);
2727

28-
void updateCredentials(const char * username, const char * password)
28+
void updateCredentials(const String& username, const String& password)
2929
{
30-
_username = (char *)username;
31-
_password = (char *)password;
30+
_username = username;
31+
_password = password;
3232
}
3333

3434
protected:
@@ -37,8 +37,8 @@ class ESP8266HTTPUpdateServer
3737
private:
3838
bool _serial_output;
3939
ESP8266WebServer *_server;
40-
char * _username;
41-
char * _password;
40+
String _username;
41+
String _password;
4242
bool _authenticated;
4343
String _updaterError;
4444
};

0 commit comments

Comments
 (0)