Unverified Commit 8c150e21 authored by Vlastimil Hajek's avatar Vlastimil Hajek Committed by GitHub

feat: adding possibility to manually set MD5 checksum for HTTP update (#7629)

parent 789ae4c9
...@@ -33,15 +33,18 @@ ...@@ -33,15 +33,18 @@
// To do extern "C" uint32_t _SPIFFS_end; // To do extern "C" uint32_t _SPIFFS_end;
HTTPUpdate::HTTPUpdate(void) HTTPUpdate::HTTPUpdate(void)
: _httpClientTimeout(8000), _ledPin(-1) : HTTPUpdate(8000)
{ {
_followRedirects = HTTPC_DISABLE_FOLLOW_REDIRECTS;
} }
HTTPUpdate::HTTPUpdate(int httpClientTimeout) HTTPUpdate::HTTPUpdate(int httpClientTimeout)
: _httpClientTimeout(httpClientTimeout), _ledPin(-1) : _httpClientTimeout(httpClientTimeout), _ledPin(-1)
{ {
_followRedirects = HTTPC_DISABLE_FOLLOW_REDIRECTS; _followRedirects = HTTPC_DISABLE_FOLLOW_REDIRECTS;
_md5Sum = String();
_user = String();
_password = String();
_auth = String();
} }
HTTPUpdate::~HTTPUpdate(void) HTTPUpdate::~HTTPUpdate(void)
...@@ -220,6 +223,14 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren ...@@ -220,6 +223,14 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
requestCB(&http); requestCB(&http);
} }
if (!_user.isEmpty() && !_password.isEmpty()) {
http.setAuthorization(_user.c_str(), _password.c_str());
}
if (!_auth.isEmpty()) {
http.setAuthorization(_auth.c_str());
}
const char * headerkeys[] = { "x-MD5" }; const char * headerkeys[] = { "x-MD5" };
size_t headerkeyssize = sizeof(headerkeys) / sizeof(char*); size_t headerkeyssize = sizeof(headerkeys) / sizeof(char*);
...@@ -243,8 +254,14 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren ...@@ -243,8 +254,14 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
log_d(" - code: %d\n", code); log_d(" - code: %d\n", code);
log_d(" - len: %d\n", len); log_d(" - len: %d\n", len);
if(http.hasHeader("x-MD5")) { String md5;
log_d(" - MD5: %s\n", http.header("x-MD5").c_str()); if (_md5Sum.length()) {
md5 = _md5Sum;
} else if(http.hasHeader("x-MD5")) {
md5 = http.header("x-MD5");
}
if(md5.length()) {
log_d(" - MD5: %s\n",md5.c_str());
} }
log_d("ESP32 info:\n"); log_d("ESP32 info:\n");
...@@ -341,7 +358,7 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren ...@@ -341,7 +358,7 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
} }
*/ */
} }
if(runUpdate(*tcp, len, http.header("x-MD5"), command)) { if(runUpdate(*tcp, len, md5, command)) {
ret = HTTP_UPDATE_OK; ret = HTTP_UPDATE_OK;
log_d("Update ok\n"); log_d("Update ok\n");
http.end(); http.end();
......
...@@ -85,6 +85,22 @@ public: ...@@ -85,6 +85,22 @@ public:
_ledOn = ledOn; _ledOn = ledOn;
} }
void setMD5sum(const String &md5Sum)
{
_md5Sum = md5Sum;
}
void setAuthorization(const String& user, const String& password)
{
_user = user;
_password = password;
}
void setAuthorization(const String& auth)
{
_auth = auth;
}
t_httpUpdate_return update(WiFiClient& client, const String& url, const String& currentVersion = "", HTTPUpdateRequestCB requestCB = NULL); t_httpUpdate_return update(WiFiClient& client, const String& url, const String& currentVersion = "", HTTPUpdateRequestCB requestCB = NULL);
t_httpUpdate_return update(WiFiClient& client, const String& host, uint16_t port, const String& uri = "/", t_httpUpdate_return update(WiFiClient& client, const String& host, uint16_t port, const String& uri = "/",
...@@ -123,6 +139,10 @@ protected: ...@@ -123,6 +139,10 @@ protected:
private: private:
int _httpClientTimeout; int _httpClientTimeout;
followRedirects_t _followRedirects; followRedirects_t _followRedirects;
String _user;
String _password;
String _auth;
String _md5Sum;
// Callbacks // Callbacks
HTTPUpdateStartCB _cbStart; HTTPUpdateStartCB _cbStart;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment