Skip to content

Commit 8c6a232

Browse files
authored
Merge branch 'master' into master
2 parents 78ab38b + 211606f commit 8c6a232

File tree

9 files changed

+159
-60
lines changed

9 files changed

+159
-60
lines changed

cores/esp8266/WString.cpp

+61
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,13 @@ String &String::operator =(const __FlashStringHelper *pstr) {
273273
return *this;
274274
}
275275

276+
String &String::operator =(char c) {
277+
char buffer[2] { c, '\0' };
278+
*this = buffer;
279+
return *this;
280+
}
281+
282+
276283
/*********************************************/
277284
/* concat */
278285
/*********************************************/
@@ -500,6 +507,10 @@ bool String::equals(const char *cstr) const {
500507
return strcmp(buffer(), cstr) == 0;
501508
}
502509

510+
bool String::equals(const __FlashStringHelper *s) const {
511+
return equals(String(s));
512+
}
513+
503514
bool String::operator<(const String &rhs) const {
504515
return compareTo(rhs) < 0;
505516
}
@@ -532,6 +543,10 @@ bool String::equalsIgnoreCase(const String &s2) const {
532543
return true;
533544
}
534545

546+
bool String::equalsIgnoreCase(const __FlashStringHelper *s) const {
547+
return equalsIgnoreCase(String(s));
548+
}
549+
535550
unsigned char String::equalsConstantTime(const String &s2) const {
536551
// To avoid possible time-based attacks present function
537552
// compares given strings in a constant time.
@@ -565,18 +580,37 @@ bool String::startsWith(const String &s2) const {
565580
return startsWith(s2, 0);
566581
}
567582

583+
bool String::startsWith(const char *prefix) const {
584+
return this->startsWith(String(prefix));
585+
}
586+
bool String::startsWith(const __FlashStringHelper *prefix) const {
587+
return this->startsWith(String(prefix));
588+
}
589+
568590
bool String::startsWith(const String &s2, unsigned int offset) const {
569591
if (offset > (unsigned)(len() - s2.len()) || !buffer() || !s2.buffer())
570592
return false;
571593
return strncmp(&buffer()[offset], s2.buffer(), s2.len()) == 0;
572594
}
573595

596+
bool String::startsWith(const __FlashStringHelper *prefix, unsigned int offset) const {
597+
return startsWith(String(prefix), offset);
598+
}
599+
574600
bool String::endsWith(const String &s2) const {
575601
if (len() < s2.len() || !buffer() || !s2.buffer())
576602
return false;
577603
return strcmp(&buffer()[len() - s2.len()], s2.buffer()) == 0;
578604
}
579605

606+
bool String::endsWith(const char *suffix) const {
607+
return this->endsWith(String(suffix));
608+
}
609+
bool String::endsWith(const __FlashStringHelper *suffix) const {
610+
return this->endsWith(String(suffix));
611+
}
612+
613+
580614
/*********************************************/
581615
/* Character Access */
582616
/*********************************************/
@@ -678,6 +712,15 @@ int String::lastIndexOf(const String &s2, unsigned int fromIndex) const {
678712
return found;
679713
}
680714

715+
int String::lastIndexOf(const __FlashStringHelper *str) const {
716+
return lastIndexOf(String(str));
717+
}
718+
719+
int String::lastIndexOf(const __FlashStringHelper *str, unsigned int fromIndex) const {
720+
return lastIndexOf(String(str), fromIndex);
721+
}
722+
723+
681724
String String::substring(unsigned int left, unsigned int right) const {
682725
if (left > right) {
683726
unsigned int temp = right;
@@ -756,6 +799,24 @@ void String::replace(const String &find, const String &replace) {
756799
}
757800
}
758801

802+
803+
void String::replace(const char *find, const String &replace) {
804+
this->replace(String(find), replace);
805+
}
806+
void String::replace(const __FlashStringHelper *find, const String &replace) {
807+
this->replace(String(find), replace);
808+
}
809+
void String::replace(const char *find, const char *replace) {
810+
this->replace(String(find), String(replace));
811+
}
812+
void String::replace(const __FlashStringHelper *find, const char *replace) {
813+
this->replace(String(find), String(replace));
814+
}
815+
void String::replace(const __FlashStringHelper *find, const __FlashStringHelper *replace) {
816+
this->replace(String(find), String(replace));
817+
}
818+
819+
759820
void String::remove(unsigned int index, unsigned int count) {
760821
if (index >= len()) {
761822
return;

cores/esp8266/WString.h

+22-32
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,7 @@ class String {
101101
String &operator =(const char *cstr);
102102
String &operator =(const __FlashStringHelper *str);
103103
String &operator =(String &&rval) noexcept;
104-
String &operator =(char c) {
105-
char buffer[2] { c, '\0' };
106-
*this = buffer;
107-
return *this;
108-
}
104+
String &operator =(char c);
109105

110106
// concatenate (works w/ built-in types)
111107

@@ -142,39 +138,40 @@ class String {
142138
int compareTo(const String &s) const;
143139
bool equals(const String &s) const;
144140
bool equals(const char *cstr) const;
141+
bool equals(const __FlashStringHelper *s) const;
145142
bool operator ==(const String &rhs) const {
146143
return equals(rhs);
147144
}
148145
bool operator ==(const char *cstr) const {
149146
return equals(cstr);
150147
}
148+
bool operator ==(const __FlashStringHelper *rhs) const {
149+
return equals(rhs);
150+
}
151151
bool operator !=(const String &rhs) const {
152152
return !equals(rhs);
153153
}
154154
bool operator !=(const char *cstr) const {
155155
return !equals(cstr);
156156
}
157+
bool operator !=(const __FlashStringHelper *rhs) const {
158+
return !equals(rhs);
159+
}
157160
bool operator <(const String &rhs) const;
158161
bool operator >(const String &rhs) const;
159162
bool operator <=(const String &rhs) const;
160163
bool operator >=(const String &rhs) const;
161164
bool equalsIgnoreCase(const String &s) const;
165+
bool equalsIgnoreCase(const __FlashStringHelper *s) const;
162166
unsigned char equalsConstantTime(const String &s) const;
163167
bool startsWith(const String &prefix) const;
164-
bool startsWith(const char *prefix) const {
165-
return this->startsWith(String(prefix));
166-
}
167-
bool startsWith(const __FlashStringHelper *prefix) const {
168-
return this->startsWith(String(prefix));
169-
}
168+
bool startsWith(const char *prefix) const;
169+
bool startsWith(const __FlashStringHelper *prefix) const;
170170
bool startsWith(const String &prefix, unsigned int offset) const;
171+
bool startsWith(const __FlashStringHelper *prefix, unsigned int offset) const;
171172
bool endsWith(const String &suffix) const;
172-
bool endsWith(const char *suffix) const {
173-
return this->endsWith(String(suffix));
174-
}
175-
bool endsWith(const __FlashStringHelper *suffix) const {
176-
return this->endsWith(String(suffix));
177-
}
173+
bool endsWith(const char *suffix) const;
174+
bool endsWith(const __FlashStringHelper *suffix) const;
178175

179176
// character access
180177
char charAt(unsigned int index) const {
@@ -204,6 +201,8 @@ class String {
204201
int lastIndexOf(char ch, unsigned int fromIndex) const;
205202
int lastIndexOf(const String &str) const;
206203
int lastIndexOf(const String &str, unsigned int fromIndex) const;
204+
int lastIndexOf(const __FlashStringHelper *str) const;
205+
int lastIndexOf(const __FlashStringHelper *str, unsigned int fromIndex) const;
207206
String substring(unsigned int beginIndex) const {
208207
return substring(beginIndex, len());
209208
}
@@ -212,21 +211,12 @@ class String {
212211
// modification
213212
void replace(char find, char replace);
214213
void replace(const String &find, const String &replace);
215-
void replace(const char *find, const String &replace) {
216-
this->replace(String(find), replace);
217-
}
218-
void replace(const __FlashStringHelper *find, const String &replace) {
219-
this->replace(String(find), replace);
220-
}
221-
void replace(const char *find, const char *replace) {
222-
this->replace(String(find), String(replace));
223-
}
224-
void replace(const __FlashStringHelper *find, const char *replace) {
225-
this->replace(String(find), String(replace));
226-
}
227-
void replace(const __FlashStringHelper *find, const __FlashStringHelper *replace) {
228-
this->replace(String(find), String(replace));
229-
}
214+
void replace(const char *find, const String &replace);
215+
void replace(const __FlashStringHelper *find, const String &replace);
216+
void replace(const char *find, const char *replace);
217+
void replace(const __FlashStringHelper *find, const char *replace);
218+
void replace(const __FlashStringHelper *find, const __FlashStringHelper *replace);
219+
230220
// Pass the biggest integer if the count is not specified.
231221
// The remove method below will take care of truncating it at the end of the string.
232222
void remove(unsigned int index, unsigned int count = (unsigned int)-1);

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

+34-7
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,26 @@ void HTTPClient::setAuthorization(const char * user, const char * password)
276276
}
277277

278278
/**
279-
* set the Authorizatio for the http request
279+
* set the Authorization for the http request
280280
* @param auth const char * base64
281281
*/
282282
void HTTPClient::setAuthorization(const char * auth)
283283
{
284-
if(auth) {
285-
_base64Authorization = auth;
286-
_base64Authorization.replace(String('\n'), emptyString);
284+
if (auth) {
285+
setAuthorization(String(auth));
287286
}
288287
}
289288

289+
/**
290+
* set the Authorization for the http request
291+
* @param auth String base64
292+
*/
293+
void HTTPClient::setAuthorization(String auth)
294+
{
295+
_base64Authorization = std::move(auth);
296+
_base64Authorization.replace(String('\n'), emptyString);
297+
}
298+
290299
/**
291300
* set the timeout for the TCP connection
292301
* @param timeout unsigned int
@@ -354,6 +363,14 @@ int HTTPClient::GET()
354363
{
355364
return sendRequest("GET");
356365
}
366+
/**
367+
* send a DELETE request
368+
* @return http code
369+
*/
370+
int HTTPClient::DELETE()
371+
{
372+
return sendRequest("DELETE");
373+
}
357374

358375
/**
359376
* sends a post request to the server
@@ -610,8 +627,18 @@ WiFiClient* HTTPClient::getStreamPtr(void)
610627
*/
611628
int HTTPClient::writeToStream(Stream * stream)
612629
{
630+
return writeToPrint(stream);
631+
}
613632

614-
if(!stream) {
633+
/**
634+
* write all message body / payload to Print
635+
* @param print Print *
636+
* @return bytes written ( negative values are error codes )
637+
*/
638+
int HTTPClient::writeToPrint(Print * print)
639+
{
640+
641+
if(!print) {
615642
return returnError(HTTPC_ERROR_NO_STREAM);
616643
}
617644

@@ -628,7 +655,7 @@ int HTTPClient::writeToStream(Stream * stream)
628655
if(_transferEncoding == HTTPC_TE_IDENTITY) {
629656
// len < 0: transfer all of it, with timeout
630657
// len >= 0: max:len, with timeout
631-
ret = _client->sendSize(stream, len);
658+
ret = _client->sendSize(print, len);
632659

633660
// do we have an error?
634661
if(_client->getLastSendReport() != Stream::Report::Success) {
@@ -656,7 +683,7 @@ int HTTPClient::writeToStream(Stream * stream)
656683
// data left?
657684
if(len > 0) {
658685
// read len bytes with timeout
659-
int r = _client->sendSize(stream, len);
686+
int r = _client->sendSize(print, len);
660687
if (_client->getLastSendReport() != Stream::Report::Success)
661688
// not all data transferred
662689
return returnError(StreamReportToHttpClientReport(_client->getLastSendReport()));

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h

+3
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class HTTPClient
176176
void setUserAgent(const String& userAgent);
177177
void setAuthorization(const char * user, const char * password);
178178
void setAuthorization(const char * auth);
179+
void setAuthorization(String auth);
179180
void setTimeout(uint16_t timeout);
180181

181182
// Redirections
@@ -187,6 +188,7 @@ class HTTPClient
187188

188189
/// request handling
189190
int GET();
191+
int DELETE();
190192
int POST(const uint8_t* payload, size_t size);
191193
int POST(const String& payload);
192194
int PUT(const uint8_t* payload, size_t size);
@@ -213,6 +215,7 @@ class HTTPClient
213215

214216
WiFiClient& getStream(void);
215217
WiFiClient* getStreamPtr(void);
218+
int writeToPrint(Print* print);
216219
int writeToStream(Stream* stream);
217220
const String& getString(void);
218221
static String errorToString(int error);

libraries/ESP8266WiFi/src/WiFiClient.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class WiFiClient : public Client, public SList<WiFiClient> {
5959
virtual size_t write(uint8_t) override;
6060
virtual size_t write(const uint8_t *buf, size_t size) override;
6161
virtual size_t write_P(PGM_P buf, size_t size);
62-
size_t write(Stream& stream) [[ deprecated("use stream.sendHow(client...)") ]];
62+
[[ deprecated("use stream.sendHow(client...)") ]]
63+
size_t write(Stream& stream);
6364

6465
virtual int available() override;
6566
virtual int read() override;

libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,14 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
211211
DEBUG_HTTP_UPDATE("[httpUpdate] - code: %d\n", code);
212212
DEBUG_HTTP_UPDATE("[httpUpdate] - len: %d\n", len);
213213

214-
if(http.hasHeader("x-MD5")) {
215-
DEBUG_HTTP_UPDATE("[httpUpdate] - MD5: %s\n", http.header("x-MD5").c_str());
214+
String md5;
215+
if (_md5Sum.length()) {
216+
md5 = _md5Sum;
217+
} else if(http.hasHeader("x-MD5")) {
218+
md5 = http.header("x-MD5");
219+
}
220+
if(md5.length()) {
221+
DEBUG_HTTP_UPDATE("[httpUpdate] - MD5: %s\n", md5.c_str());
216222
}
217223

218224
DEBUG_HTTP_UPDATE("[httpUpdate] ESP8266 info:\n");
@@ -298,7 +304,7 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
298304
}
299305
}
300306
}
301-
if(runUpdate(*tcp, len, http.header("x-MD5"), command)) {
307+
if(runUpdate(*tcp, len, md5, command)) {
302308
ret = HTTP_UPDATE_OK;
303309
DEBUG_HTTP_UPDATE("[httpUpdate] Update ok\n");
304310
http.end();

libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ class ESP8266HTTPUpdate
108108
_ledOn = ledOn;
109109
}
110110

111+
void setMD5sum(const String &md5Sum)
112+
{
113+
_md5Sum = md5Sum;
114+
}
115+
111116
void setAuthorization(const String& user, const String& password);
112117
void setAuthorization(const String& auth);
113118

@@ -142,7 +147,7 @@ class ESP8266HTTPUpdate
142147
String _user;
143148
String _password;
144149
String _auth;
145-
150+
String _md5Sum;
146151
private:
147152
int _httpClientTimeout;
148153
followRedirects_t _followRedirects = HTTPC_DISABLE_FOLLOW_REDIRECTS;

0 commit comments

Comments
 (0)