2121#include < Arduino_DebugUtils.h>
2222#include < WiFiC3.h>
2323#include < WiFiSSLClient.h>
24+ #include < Client.h>
2425
2526#define AIOT_CONFIG_PORTENTA_C33_OTA_HTTP_HEADER_RECEIVE_TIMEOUT_ms (5 *1000UL );
2627#define AIOT_CONFIG_PORTENTA_C33_OTA_HTTP_DATA_RECEIVE_TIMEOUT_ms (5 *60 *1000UL );
@@ -74,7 +75,7 @@ void URI::parse(const string& url_s)
7475 query_.assign (query_i, url_s.end ());
7576}
7677
77- int SFU::download (const char * ota_path, const char * ota_url) {
78+ int SFU::download (Client& client, const char * ota_path, const char * ota_url) {
7879 int err = -1 ;
7980
8081 FILE * file = fopen (ota_path, " wb" );
@@ -86,32 +87,29 @@ int SFU::download(const char* ota_path, const char* ota_url) {
8687 }
8788
8889 URI url (ota_url);
89- Client * client = nullptr ;
9090 int port = 0 ;
9191
9292 if (url.protocol_ == " http" ) {
93- client = new WiFiClient ();
9493 port = 80 ;
9594 } else if (url.protocol_ == " https" ) {
96- client = new WiFiSSLClient ();
9795 port = 443 ;
9896 } else {
9997 DEBUG_ERROR (" %s: Failed to parse OTA URL %s" , __FUNCTION__, url.host_ .c_str ());
10098 fclose (file);
10199 return static_cast <int >(OTAError::PORTENTA_C33_UrlParseError);
102100 }
103101
104- if (!client-> connect (url.host_ .c_str (), port))
102+ if (!client. connect (url.host_ .c_str (), port))
105103 {
106104 DEBUG_ERROR (" %s: Connection failure with OTA storage server %s" , __FUNCTION__, url.host_ .c_str ());
107105 fclose (file);
108106 return static_cast <int >(OTAError::PORTENTA_C33_ServerConnectError);
109107 }
110108
111- client-> println (String (" GET " ) + url.path_ .c_str () + " HTTP/1.1" );
112- client-> println (String (" Host: " ) + url.host_ .c_str ());
113- client-> println (" Connection: close" );
114- client-> println ();
109+ client. println (String (" GET " ) + url.path_ .c_str () + " HTTP/1.1" );
110+ client. println (String (" Host: " ) + url.host_ .c_str ());
111+ client. println (" Connection: close" );
112+ client. println ();
115113
116114 /* Receive HTTP header. */
117115 String http_header;
@@ -122,9 +120,9 @@ int SFU::download(const char* ota_path, const char* ota_url) {
122120 is_http_header_timeout = (millis () - start) > AIOT_CONFIG_PORTENTA_C33_OTA_HTTP_HEADER_RECEIVE_TIMEOUT_ms;
123121 if (is_http_header_timeout) break ;
124122
125- if (client-> available ())
123+ if (client. available ())
126124 {
127- char const c = client-> read ();
125+ char const c = client. read ();
128126
129127 http_header += c;
130128 if (http_header.endsWith (" \r\n\r\n " ))
@@ -166,9 +164,9 @@ int SFU::download(const char* ota_path, const char* ota_url) {
166164 is_http_data_timeout = (millis () - start) > AIOT_CONFIG_PORTENTA_C33_OTA_HTTP_DATA_RECEIVE_TIMEOUT_ms;
167165 if (is_http_data_timeout) break ;
168166
169- if (client-> available ())
167+ if (client. available ())
170168 {
171- char const c = client-> read ();
169+ char const c = client. read ();
172170
173171 if (fwrite (&c, 1 , sizeof (c), file) != sizeof (c))
174172 {
0 commit comments