Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions libraries/WebServer/src/HTTPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static const char Content_Length[] = "Content-Length";

HTTPServer::HTTPServer()
: _corsEnabled(false)
, _currentClient(nullptr)
, _currentMethod(HTTP_ANY)
, _currentVersion(0)
, _currentStatus(HC_NONE)
Expand Down Expand Up @@ -109,18 +110,15 @@ bool HTTPServer::authenticate(const char * username, const char * password) {
char toencodeLen = strlen(username) + strlen(password) + 1;
char *toencode = new char[toencodeLen + 1];
if (toencode == NULL) {
authReq = "";
return false;
}
char *encoded = new char[base64_encode_expected_len(toencodeLen) + 1];
if (encoded == NULL) {
authReq = "";
delete[] toencode;
return false;
}
sprintf(toencode, "%s:%s", username, password);
if (base64_encode_chars(toencode, toencodeLen, encoded) > 0 && authReq == encoded) {
authReq = "";
delete[] toencode;
delete[] encoded;
return true;
Expand All @@ -132,7 +130,6 @@ bool HTTPServer::authenticate(const char * username, const char * password) {
log_v("%s", authReq.c_str());
String _username = _extractParam(authReq, F("username=\""), '\"');
if (!_username.length() || _username != String(username)) {
authReq = "";
return false;
}
// extracting required parameters for RFC 2069 simpler Digest
Expand All @@ -143,11 +140,9 @@ bool HTTPServer::authenticate(const char * username, const char * password) {
String _opaque = _extractParam(authReq, F("opaque=\""), '\"');

if ((!_realm.length()) || (!_nonce.length()) || (!_uri.length()) || (!_response.length()) || (!_opaque.length())) {
authReq = "";
return false;
}
if ((_opaque != _sopaque) || (_nonce != _snonce) || (_realm != _srealm)) {
authReq = "";
return false;
}
// parameters for the RFC 2617 newer Digest
Expand Down Expand Up @@ -179,11 +174,9 @@ bool HTTPServer::authenticate(const char * username, const char * password) {
}
log_v("The Proper response=%s", _responsecheck.c_str());
if (_response == _responsecheck) {
authReq = "";
return true;
}
}
authReq = "";
}
return false;
}
Expand Down Expand Up @@ -440,7 +433,7 @@ void HTTPServer::sendContent(const char* content, size_t contentLength) {
const char * footer = "\r\n";
if (_chunked) {
char chunkSize[11];
sprintf(chunkSize, "%x%s", contentLength, footer);
sprintf(chunkSize, "%x%s", (unsigned int)contentLength, footer);
_currentClientWrite(chunkSize, strlen(chunkSize));
}
_currentClientWrite(content, contentLength);
Expand All @@ -460,7 +453,7 @@ void HTTPServer::sendContent_P(PGM_P content, size_t size) {
const char * footer = "\r\n";
if (_chunked) {
char chunkSize[11];
sprintf(chunkSize, "%x%s", size, footer);
sprintf(chunkSize, "%x%s", (unsigned int)size, footer);
_currentClientWrite(chunkSize, strlen(chunkSize));
}
_currentClientWrite_P(content, size);
Expand Down
10 changes: 4 additions & 6 deletions libraries/WebServer/src/Parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,8 @@ bool HTTPServer::_parseForm(WiFiClient* client, String boundary, uint32_t len) {
_uploadWriteByte(0x0A);
_uploadWriteByte((uint8_t)('-'));
_uploadWriteByte((uint8_t)('-'));
uint32_t j = 0;
while (j < i) {
_uploadWriteByte(endBuf[j++]);
for (uint32_t j = 0; j < i; j++) {
_uploadWriteByte(endBuf[j]);
}
goto readfile;
}
Expand Down Expand Up @@ -545,9 +544,8 @@ bool HTTPServer::_parseForm(WiFiClient* client, String boundary, uint32_t len) {
_uploadWriteByte(0x0A);
_uploadWriteByte((uint8_t)('-'));
_uploadWriteByte((uint8_t)('-'));
uint32_t i = 0;
while (i < boundary.length()) {
_uploadWriteByte(endBuf[i++]);
for (uint32_t j = 0; j < boundary.length(); j++) {
_uploadWriteByte(endBuf[j]);
}
argByte = _uploadReadByte(client);
goto readfile;
Expand Down