Fix several warnings in code and libs

This commit is contained in:
Luc 2020-11-30 13:46:50 +01:00
parent 217b5062b4
commit fa863105fe
12 changed files with 176 additions and 154 deletions

View File

@ -1817,7 +1817,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
String cmd_part1 = currentline.substring (ESPpos + 4, ESPpos2); String cmd_part1 = currentline.substring (ESPpos + 4, ESPpos2);
String cmd_part2 = ""; String cmd_part2 = "";
//is there space for parameters? //is there space for parameters?
if (ESPpos2 < currentline.length() ) { if ((uint)ESPpos2 < currentline.length() ) {
cmd_part2 = currentline.substring (ESPpos2 + 1); cmd_part2 = currentline.substring (ESPpos2 + 1);
} }
//if command is a valid number then execute command //if command is a valid number then execute command
@ -2067,7 +2067,7 @@ bool COMMAND::check_command (String buffer, tpipe output, bool handlelockserial,
String cmd_part1 = buffer.substring (ESPpos + 4, ESPpos2); String cmd_part1 = buffer.substring (ESPpos + 4, ESPpos2);
String cmd_part2 = ""; String cmd_part2 = "";
//is there space for parameters? //is there space for parameters?
if (ESPpos2 < buffer.length() ) { if ((uint)ESPpos2 < buffer.length() ) {
cmd_part2 = buffer.substring (ESPpos2 + 1); cmd_part2 = buffer.substring (ESPpos2 + 1);
} }
//if command is a valid number then execute command //if command is a valid number then execute command
@ -2086,7 +2086,7 @@ bool COMMAND::check_command (String buffer, tpipe output, bool handlelockserial,
//read a buffer in an array //read a buffer in an array
void COMMAND::read_buffer_serial (uint8_t *b, size_t len) void COMMAND::read_buffer_serial (uint8_t *b, size_t len)
{ {
for (long i = 0; i < len; i++) { for (size_t i = 0; i < len; i++) {
read_buffer_serial (b[i]); read_buffer_serial (b[i]);
//*b++; //*b++;
} }

View File

@ -344,7 +344,7 @@ bool CONFIG::isHostnameValid (const char * hostname)
return false; return false;
} }
//only letter and digit //only letter and digit
for (int i = 0; i < strlen (hostname); i++) { for (uint i = 0; i < strlen (hostname); i++) {
c = hostname[i]; c = hostname[i];
if (! (isdigit (c) || isalpha (c) || c == '_') ) { if (! (isdigit (c) || isalpha (c) || c == '_') ) {
return false; return false;
@ -364,7 +364,7 @@ bool CONFIG::isSSIDValid (const char * ssid)
return false; return false;
} }
//only printable //only printable
for (int i = 0; i < strlen (ssid); i++) { for (uint i = 0; i < strlen (ssid); i++) {
if (!isPrintable (ssid[i]) ) { if (!isPrintable (ssid[i]) ) {
return false; return false;
} }
@ -384,7 +384,7 @@ bool CONFIG::isPasswordValid (const char * password)
} }
#endif #endif
//no space allowed //no space allowed
for (int i = 0; i < strlen (password); i++) for (uint i = 0; i < strlen (password); i++)
if (password[i] == ' ') { if (password[i] == ' ') {
return false; return false;
} }
@ -399,7 +399,7 @@ bool CONFIG::isLocalPasswordValid (const char * password)
return false; return false;
} }
//no space allowed //no space allowed
for (int i = 0; i < strlen (password); i++) { for (uint i = 0; i < strlen (password); i++) {
c = password[i]; c = password[i];
if (c == ' ') { if (c == ' ') {
return false; return false;
@ -424,7 +424,7 @@ bool CONFIG::isIPValid (const char * IP)
return false; return false;
} }
//only letter and digit //only letter and digit
for (int i = 0; i < strlen (IP); i++) { for (uint i = 0; i < strlen (IP); i++) {
c = IP[i]; c = IP[i];
if (isdigit (c) ) { if (isdigit (c) ) {
//only 3 digit at once //only 3 digit at once

View File

@ -53,11 +53,11 @@ typedef WiFiClientSecure TSecureClient;
#define PUSHOVERTIMEOUT 5000 #define PUSHOVERTIMEOUT 5000
#define PUSHOVERSERVER "api.pushover.net" #define PUSHOVERSERVER "api.pushover.net"
#define PUSHOVERPORT 443 #define PUSHOVERPORT 443
#define LINETIMEOUT 5000 #define LINETIMEOUT 5000
#define LINESERVER "notify-api.line.me" #define LINESERVER "notify-api.line.me"
#define LINEPORT 443 #define LINEPORT 443
#define EMAILTIMEOUT 5000 #define EMAILTIMEOUT 5000
@ -167,7 +167,10 @@ bool NotificationsService::sendPushoverMSG(const char * title, const char * mess
String data; String data;
String postcmd; String postcmd;
bool res; bool res;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
TSecureClient Notificationclient; TSecureClient Notificationclient;
#pragma GCC diagnostic pop
#if defined(ARDUINO_ARCH_ESP8266) && !defined(USING_AXTLS) #if defined(ARDUINO_ARCH_ESP8266) && !defined(USING_AXTLS)
Notificationclient.setInsecure(); Notificationclient.setInsecure();
#endif //ARDUINO_ARCH_ESP8266 && !USING_AXTLS #endif //ARDUINO_ARCH_ESP8266 && !USING_AXTLS
@ -200,7 +203,10 @@ bool NotificationsService::sendPushoverMSG(const char * title, const char * mess
} }
bool NotificationsService::sendEmailMSG(const char * title, const char * message) bool NotificationsService::sendEmailMSG(const char * title, const char * message)
{ {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
TSecureClient Notificationclient; TSecureClient Notificationclient;
#pragma GCC diagnostic pop
#if defined(ARDUINO_ARCH_ESP8266) && !defined(USING_AXTLS) #if defined(ARDUINO_ARCH_ESP8266) && !defined(USING_AXTLS)
Notificationclient.setInsecure(); Notificationclient.setInsecure();
#endif //ARDUINO_ARCH_ESP8266 && !USING_AXTLS #endif //ARDUINO_ARCH_ESP8266 && !USING_AXTLS
@ -293,7 +299,10 @@ bool NotificationsService::sendLineMSG(const char * title, const char * message)
String data; String data;
String postcmd; String postcmd;
bool res; bool res;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
TSecureClient Notificationclient; TSecureClient Notificationclient;
#pragma GCC diagnostic pop
#if defined(ARDUINO_ARCH_ESP8266) && !defined(USING_AXTLS) #if defined(ARDUINO_ARCH_ESP8266) && !defined(USING_AXTLS)
Notificationclient.setInsecure(); Notificationclient.setInsecure();
#endif //ARDUINO_ARCH_ESP8266 && !USING_AXTLS #endif //ARDUINO_ARCH_ESP8266 && !USING_AXTLS

View File

@ -122,7 +122,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length
//USE_SERIAL.printf("[%u] Disconnected!\n", num); //USE_SERIAL.printf("[%u] Disconnected!\n", num);
break; break;
case WStype_CONNECTED: { case WStype_CONNECTED: {
IPAddress ip = socket_server->remoteIP(num); //IPAddress ip = socket_server->remoteIP(num);
//USE_SERIAL.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload); //USE_SERIAL.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload);
String s = "CURRENT_ID:" + String(num); String s = "CURRENT_ID:" + String(num);
// send message to client // send message to client
@ -961,7 +961,7 @@ void handle_web_command()
return; return;
} }
//is there space for parameters? //is there space for parameters?
if (ESPpos2<cmd.length()) { if ((uint)ESPpos2<cmd.length()) {
cmd_part2=cmd.substring(ESPpos2+1); cmd_part2=cmd.substring(ESPpos2+1);
} }
//if command is a valid number then execute command //if command is a valid number then execute command
@ -1145,7 +1145,7 @@ void handle_web_command_silent()
String cmd_part1=cmd.substring(ESPpos+4,ESPpos2); String cmd_part1=cmd.substring(ESPpos+4,ESPpos2);
String cmd_part2=""; String cmd_part2="";
//is there space for parameters? //is there space for parameters?
if (ESPpos2<cmd.length()) { if ((uint)ESPpos2<cmd.length()) {
cmd_part2=cmd.substring(ESPpos2+1); cmd_part2=cmd.substring(ESPpos2+1);
} }
//if command is a valid number then execute command //if command is a valid number then execute command
@ -1296,7 +1296,7 @@ void SDFile_serial_upload()
//************** //**************
//upload is on going with data coming by 2K blocks //upload is on going with data coming by 2K blocks
} else if(upload.status == UPLOAD_FILE_WRITE) { //if com error no need to send more data to serial } else if(upload.status == UPLOAD_FILE_WRITE) { //if com error no need to send more data to serial
for (int pos = 0;( pos < upload.currentSize) && (web_interface->_upload_status == UPLOAD_STATUS_ONGOING); pos++) { //parse full post data for (uint pos = 0;( pos < upload.currentSize) && (web_interface->_upload_status == UPLOAD_STATUS_ONGOING); pos++) { //parse full post data
//feed watchdog //feed watchdog
CONFIG::wait(0); CONFIG::wait(0);
//it is a comment //it is a comment

View File

@ -221,7 +221,7 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
return sendLine2Serial (line, line_number, newlinenb); return sendLine2Serial (line, line_number, newlinenb);
} else { } else {
//the line requested is not the current one so we stop //the line requested is not the current one so we stop
if (line_number !=linenb) { if (line_number !=(uint32_t)linenb) {
log_esp3d ("Wrong line requested"); log_esp3d ("Wrong line requested");
count = 5; count = 5;
} }

View File

@ -239,7 +239,10 @@ bool WIFI_CONFIG::Setup (bool force_ap)
byte bflag = 0; byte bflag = 0;
byte bmode = 0; byte bmode = 0;
#ifdef ARDUINO_ARCH_ESP8266 #ifdef ARDUINO_ARCH_ESP8266
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
WiFi.onEvent(onWiFiEvent, WIFI_EVENT_ANY); WiFi.onEvent(onWiFiEvent, WIFI_EVENT_ANY);
#pragma GCC diagnostic pop
#else #else
WiFi.onEvent(onWiFiEvent); WiFi.onEvent(onWiFiEvent);
#endif #endif

View File

@ -444,7 +444,7 @@ void WebSockets::handleWebsocketPayloadCb(WSclient_t * client, bool ok, uint8_t
if(header->payloadLen >= 2) { if(header->payloadLen >= 2) {
reasonCode = payload[0] << 8 | payload[1]; reasonCode = payload[0] << 8 | payload[1];
} }
(void)reasonCode;
DEBUG_WEBSOCKETS("[WS][%d][handleWebsocket] get ask for close. Code: %d", client->num, reasonCode); DEBUG_WEBSOCKETS("[WS][%d][handleWebsocket] get ask for close. Code: %d", client->num, reasonCode);
if(header->payloadLen > 2) { if(header->payloadLen > 2) {
DEBUG_WEBSOCKETS(" (%s)\n", (payload + 2)); DEBUG_WEBSOCKETS(" (%s)\n", (payload + 2));
@ -453,7 +453,7 @@ void WebSockets::handleWebsocketPayloadCb(WSclient_t * client, bool ok, uint8_t
} }
clientDisconnect(client, 1000); clientDisconnect(client, 1000);
} }
break; break;
default: default:
clientDisconnect(client, 1002); clientDisconnect(client, 1002);
break; break;
@ -608,47 +608,47 @@ bool WebSockets::readCb(WSclient_t * client, uint8_t * out, size_t n, WSreadWait
* @return bytes send * @return bytes send
*/ */
size_t WebSockets::write(WSclient_t * client, uint8_t *out, size_t n) { size_t WebSockets::write(WSclient_t * client, uint8_t *out, size_t n) {
if(out == NULL) return 0; if(out == NULL) return 0;
if(client == NULL) return 0; if(client == NULL) return 0;
unsigned long t = millis(); unsigned long t = millis();
size_t len = 0; size_t len = 0;
size_t total = 0; size_t total = 0;
DEBUG_WEBSOCKETS("[write] n: %zu t: %lu\n", n, t); DEBUG_WEBSOCKETS("[write] n: %zu t: %lu\n", n, t);
while(n > 0) { while(n > 0) {
if(client->tcp == NULL) { if(client->tcp == NULL) {
DEBUG_WEBSOCKETS("[write] tcp is null!\n"); DEBUG_WEBSOCKETS("[write] tcp is null!\n");
break; break;
} }
if(!client->tcp->connected()) { if(!client->tcp->connected()) {
DEBUG_WEBSOCKETS("[write] not connected!\n"); DEBUG_WEBSOCKETS("[write] not connected!\n");
break; break;
} }
if((millis() - t) > WEBSOCKETS_TCP_TIMEOUT) { if((millis() - t) > WEBSOCKETS_TCP_TIMEOUT) {
DEBUG_WEBSOCKETS("[write] write TIMEOUT! %lu\n", (millis() - t)); DEBUG_WEBSOCKETS("[write] write TIMEOUT! %lu\n", (millis() - t));
break; break;
} }
len = client->tcp->write((const uint8_t*)out, n); len = client->tcp->write((const uint8_t*)out, n);
if(len) { if(len) {
t = millis(); t = millis();
out += len; out += len;
n -= len; n -= len;
total += len; total += len;
//DEBUG_WEBSOCKETS("write %d left %d!\n", len, n); //DEBUG_WEBSOCKETS("write %d left %d!\n", len, n);
} else { } else {
//DEBUG_WEBSOCKETS("write %d failed left %d!\n", len, n); //DEBUG_WEBSOCKETS("write %d failed left %d!\n", len, n);
} }
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
delay(0); delay(0);
#endif #endif
} }
return total; return total;
} }
size_t WebSockets::write(WSclient_t * client, const char *out) { size_t WebSockets::write(WSclient_t * client, const char *out) {
if(client == NULL) return 0; if(client == NULL) return 0;
if(out == NULL) return 0; if(out == NULL) return 0;
return write(client, (uint8_t*)out, strlen(out)); return write(client, (uint8_t*)out, strlen(out));
} }

View File

@ -698,7 +698,8 @@ void WebSocketsClient::connectedCb() {
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
_client.tcp->setNoDelay(true); _client.tcp->setNoDelay(true);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
if(_client.isSSL && _fingerprint.length()) { if(_client.isSSL && _fingerprint.length()) {
if(!_client.ssl->verify(_fingerprint.c_str(), _host.c_str())) { if(!_client.ssl->verify(_fingerprint.c_str(), _host.c_str())) {
DEBUG_WEBSOCKETS("[WS-Client] certificate mismatch\n"); DEBUG_WEBSOCKETS("[WS-Client] certificate mismatch\n");
@ -706,6 +707,7 @@ void WebSocketsClient::connectedCb() {
return; return;
} }
} }
#pragma GCC diagnostic pop
#endif #endif
// send Header to Server // send Header to Server

View File

@ -51,7 +51,7 @@ WebSocketsServer::WebSocketsServer(uint16_t port, String origin, String protocol
WebSocketsServer::~WebSocketsServer() { WebSocketsServer::~WebSocketsServer() {
// disconnect all clients // disconnect all clients
close(); close();
if (_mandatoryHttpHeaders) if (_mandatoryHttpHeaders)
delete[] _mandatoryHttpHeaders; delete[] _mandatoryHttpHeaders;
@ -110,8 +110,8 @@ void WebSocketsServer::begin(void) {
} }
void WebSocketsServer::close(void) { void WebSocketsServer::close(void) {
_runnning = false; _runnning = false;
disconnect(); disconnect();
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
_server->close(); _server->close();
@ -128,10 +128,10 @@ void WebSocketsServer::close(void) {
* called in arduino loop * called in arduino loop
*/ */
void WebSocketsServer::loop(void) { void WebSocketsServer::loop(void) {
if(_runnning) { if(_runnning) {
handleNewClients(); handleNewClients();
handleClientData(); handleClientData();
} }
} }
#endif #endif
@ -150,21 +150,21 @@ void WebSocketsServer::onEvent(WebSocketServerEvent cbEvent) {
* @param mandatoryHttpHeaderCount size_t ///< the number of items in the mandatoryHttpHeaders array * @param mandatoryHttpHeaderCount size_t ///< the number of items in the mandatoryHttpHeaders array
*/ */
void WebSocketsServer::onValidateHttpHeader( void WebSocketsServer::onValidateHttpHeader(
WebSocketServerHttpHeaderValFunc validationFunc, WebSocketServerHttpHeaderValFunc validationFunc,
const char* mandatoryHttpHeaders[], const char* mandatoryHttpHeaders[],
size_t mandatoryHttpHeaderCount) size_t mandatoryHttpHeaderCount)
{ {
_httpHeaderValidationFunc = validationFunc; _httpHeaderValidationFunc = validationFunc;
if (_mandatoryHttpHeaders) if (_mandatoryHttpHeaders)
delete[] _mandatoryHttpHeaders; delete[] _mandatoryHttpHeaders;
_mandatoryHttpHeaderCount = mandatoryHttpHeaderCount; _mandatoryHttpHeaderCount = mandatoryHttpHeaderCount;
_mandatoryHttpHeaders = new String[_mandatoryHttpHeaderCount]; _mandatoryHttpHeaders = new String[_mandatoryHttpHeaderCount];
for (size_t i = 0; i < _mandatoryHttpHeaderCount; i++) { for (size_t i = 0; i < _mandatoryHttpHeaderCount; i++) {
_mandatoryHttpHeaders[i] = mandatoryHttpHeaders[i]; _mandatoryHttpHeaders[i] = mandatoryHttpHeaders[i];
} }
} }
/* /*
@ -410,14 +410,14 @@ void WebSocketsServer::setAuthorization(const char * auth) {
int WebSocketsServer::connectedClients(bool ping) { int WebSocketsServer::connectedClients(bool ping) {
WSclient_t * client; WSclient_t * client;
int count = 0; int count = 0;
for(uint8_t i = 0; i < WEBSOCKETS_SERVER_CLIENT_MAX; i++) { for(uint8_t i = 0; i < WEBSOCKETS_SERVER_CLIENT_MAX; i++) {
client = &_clients[i]; client = &_clients[i];
if(client->status == WSC_CONNECTED) { if(client->status == WSC_CONNECTED) {
if(ping != true || sendPing(i)) { if(ping != true || sendPing(i)) {
count++; count++;
} }
} }
} }
return count; return count;
} }
@ -469,6 +469,7 @@ bool WebSocketsServer::newClient(WEBSOCKETS_NETWORK_CLASS * TCPclient) {
client->status = WSC_HEADER; client->status = WSC_HEADER;
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32)
IPAddress ip = client->tcp->remoteIP(); IPAddress ip = client->tcp->remoteIP();
(void)ip;
DEBUG_WEBSOCKETS("[WS-Server][%d] new client from %d.%d.%d.%d\n", client->num, ip[0], ip[1], ip[2], ip[3]); DEBUG_WEBSOCKETS("[WS-Server][%d] new client from %d.%d.%d.%d\n", client->num, ip[0], ip[1], ip[2], ip[3]);
#else #else
DEBUG_WEBSOCKETS("[WS-Server][%d] new client\n", client->num); DEBUG_WEBSOCKETS("[WS-Server][%d] new client\n", client->num);
@ -645,6 +646,7 @@ void WebSocketsServer::handleNewClients(void) {
// no free space to handle client // no free space to handle client
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32)
IPAddress ip = tcpClient->remoteIP(); IPAddress ip = tcpClient->remoteIP();
(void)ip;
DEBUG_WEBSOCKETS("[WS-Server] no free space new client from %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]); DEBUG_WEBSOCKETS("[WS-Server] no free space new client from %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
#else #else
DEBUG_WEBSOCKETS("[WS-Server] no free space new client\n"); DEBUG_WEBSOCKETS("[WS-Server] no free space new client\n");
@ -700,11 +702,11 @@ void WebSocketsServer::handleClientData(void) {
* @param headerName String ///< the name of the header being checked * @param headerName String ///< the name of the header being checked
*/ */
bool WebSocketsServer::hasMandatoryHeader(String headerName) { bool WebSocketsServer::hasMandatoryHeader(String headerName) {
for (size_t i = 0; i < _mandatoryHttpHeaderCount; i++) { for (size_t i = 0; i < _mandatoryHttpHeaderCount; i++) {
if (_mandatoryHttpHeaders[i].equalsIgnoreCase(headerName)) if (_mandatoryHttpHeaders[i].equalsIgnoreCase(headerName))
return true; return true;
} }
return false; return false;
} }
@ -715,62 +717,62 @@ bool WebSocketsServer::hasMandatoryHeader(String headerName) {
*/ */
void WebSocketsServer::handleHeader(WSclient_t * client, String * headerLine) { void WebSocketsServer::handleHeader(WSclient_t * client, String * headerLine) {
static const char * NEW_LINE = "\r\n"; static const char * NEW_LINE = "\r\n";
headerLine->trim(); // remove \r headerLine->trim(); // remove \r
if(headerLine->length() > 0) { if(headerLine->length() > 0) {
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] RX: %s\n", client->num, headerLine->c_str()); DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] RX: %s\n", client->num, headerLine->c_str());
// websocket requests always start with GET see rfc6455 // websocket requests always start with GET see rfc6455
if(headerLine->startsWith("GET ")) { if(headerLine->startsWith("GET ")) {
// cut URL out // cut URL out
client->cUrl = headerLine->substring(4, headerLine->indexOf(' ', 4)); client->cUrl = headerLine->substring(4, headerLine->indexOf(' ', 4));
//reset non-websocket http header validation state for this client //reset non-websocket http header validation state for this client
client->cHttpHeadersValid = true; client->cHttpHeadersValid = true;
client->cMandatoryHeadersCount = 0; client->cMandatoryHeadersCount = 0;
} else if(headerLine->indexOf(':')) { } else if(headerLine->indexOf(':')) {
String headerName = headerLine->substring(0, headerLine->indexOf(':')); String headerName = headerLine->substring(0, headerLine->indexOf(':'));
String headerValue = headerLine->substring(headerLine->indexOf(':') + 1); String headerValue = headerLine->substring(headerLine->indexOf(':') + 1);
// remove space in the beginning (RFC2616) // remove space in the beginning (RFC2616)
if(headerValue[0] == ' ') { if(headerValue[0] == ' ') {
headerValue.remove(0, 1); headerValue.remove(0, 1);
} }
if(headerName.equalsIgnoreCase(WEBSOCKETS_STRING("Connection"))) { if(headerName.equalsIgnoreCase(WEBSOCKETS_STRING("Connection"))) {
headerValue.toLowerCase(); headerValue.toLowerCase();
if(headerValue.indexOf(WEBSOCKETS_STRING("upgrade")) >= 0) { if(headerValue.indexOf(WEBSOCKETS_STRING("upgrade")) >= 0) {
client->cIsUpgrade = true; client->cIsUpgrade = true;
} }
} else if(headerName.equalsIgnoreCase(WEBSOCKETS_STRING("Upgrade"))) { } else if(headerName.equalsIgnoreCase(WEBSOCKETS_STRING("Upgrade"))) {
if(headerValue.equalsIgnoreCase(WEBSOCKETS_STRING("websocket"))) { if(headerValue.equalsIgnoreCase(WEBSOCKETS_STRING("websocket"))) {
client->cIsWebsocket = true; client->cIsWebsocket = true;
} }
} else if(headerName.equalsIgnoreCase(WEBSOCKETS_STRING("Sec-WebSocket-Version"))) { } else if(headerName.equalsIgnoreCase(WEBSOCKETS_STRING("Sec-WebSocket-Version"))) {
client->cVersion = headerValue.toInt(); client->cVersion = headerValue.toInt();
} else if(headerName.equalsIgnoreCase(WEBSOCKETS_STRING("Sec-WebSocket-Key"))) { } else if(headerName.equalsIgnoreCase(WEBSOCKETS_STRING("Sec-WebSocket-Key"))) {
client->cKey = headerValue; client->cKey = headerValue;
client->cKey.trim(); // see rfc6455 client->cKey.trim(); // see rfc6455
} else if(headerName.equalsIgnoreCase(WEBSOCKETS_STRING("Sec-WebSocket-Protocol"))) { } else if(headerName.equalsIgnoreCase(WEBSOCKETS_STRING("Sec-WebSocket-Protocol"))) {
client->cProtocol = headerValue; client->cProtocol = headerValue;
} else if(headerName.equalsIgnoreCase(WEBSOCKETS_STRING("Sec-WebSocket-Extensions"))) { } else if(headerName.equalsIgnoreCase(WEBSOCKETS_STRING("Sec-WebSocket-Extensions"))) {
client->cExtensions = headerValue; client->cExtensions = headerValue;
} else if(headerName.equalsIgnoreCase(WEBSOCKETS_STRING("Authorization"))) { } else if(headerName.equalsIgnoreCase(WEBSOCKETS_STRING("Authorization"))) {
client->base64Authorization = headerValue; client->base64Authorization = headerValue;
} else { } else {
client->cHttpHeadersValid &= execHttpHeaderValidation(headerName, headerValue); client->cHttpHeadersValid &= execHttpHeaderValidation(headerName, headerValue);
if(_mandatoryHttpHeaderCount > 0 && hasMandatoryHeader(headerName)) { if(_mandatoryHttpHeaderCount > 0 && hasMandatoryHeader(headerName)) {
client->cMandatoryHeadersCount++; client->cMandatoryHeadersCount++;
} }
} }
} else { } else {
DEBUG_WEBSOCKETS("[WS-Client][handleHeader] Header error (%s)\n", headerLine->c_str()); DEBUG_WEBSOCKETS("[WS-Client][handleHeader] Header error (%s)\n", headerLine->c_str());
} }
(*headerLine) = ""; (*headerLine) = "";
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
@ -792,32 +794,32 @@ void WebSocketsServer::handleHeader(WSclient_t * client, String * headerLine) {
bool ok = (client->cIsUpgrade && client->cIsWebsocket); bool ok = (client->cIsUpgrade && client->cIsWebsocket);
if(ok) { if(ok) {
if(client->cUrl.length() == 0) { if(client->cUrl.length() == 0) {
ok = false; ok = false;
} }
if(client->cKey.length() == 0) { if(client->cKey.length() == 0) {
ok = false; ok = false;
} }
if(client->cVersion != 13) { if(client->cVersion != 13) {
ok = false; ok = false;
} }
if(!client->cHttpHeadersValid) { if(!client->cHttpHeadersValid) {
ok = false; ok = false;
} }
if (client->cMandatoryHeadersCount != _mandatoryHttpHeaderCount) { if (client->cMandatoryHeadersCount != _mandatoryHttpHeaderCount) {
ok = false; ok = false;
} }
} }
if(_base64Authorization.length() > 0) { if(_base64Authorization.length() > 0) {
String auth = WEBSOCKETS_STRING("Basic "); String auth = WEBSOCKETS_STRING("Basic ");
auth += _base64Authorization; auth += _base64Authorization;
if(auth != client->base64Authorization) { if(auth != client->base64Authorization) {
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] HTTP Authorization failed!\n", client->num); DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] HTTP Authorization failed!\n", client->num);
handleAuthorizationFailed(client); handleAuthorizationFailed(client);
return; return;
} }
} }
if(ok) { if(ok) {
@ -837,7 +839,7 @@ void WebSocketsServer::handleHeader(WSclient_t * client, String * headerLine) {
"Connection: Upgrade\r\n" "Connection: Upgrade\r\n"
"Sec-WebSocket-Version: 13\r\n" "Sec-WebSocket-Version: 13\r\n"
"Sec-WebSocket-Accept: "); "Sec-WebSocket-Accept: ");
handshake += sKey + NEW_LINE; handshake += sKey + NEW_LINE;
if(_origin.length() > 0) { if(_origin.length() > 0) {
handshake += WEBSOCKETS_STRING("Access-Control-Allow-Origin: "); handshake += WEBSOCKETS_STRING("Access-Control-Allow-Origin: ");
@ -845,8 +847,8 @@ void WebSocketsServer::handleHeader(WSclient_t * client, String * headerLine) {
} }
if(client->cProtocol.length() > 0) { if(client->cProtocol.length() > 0) {
handshake += WEBSOCKETS_STRING("Sec-WebSocket-Protocol: "); handshake += WEBSOCKETS_STRING("Sec-WebSocket-Protocol: ");
handshake +=_protocol + NEW_LINE; handshake +=_protocol + NEW_LINE;
} }
// header end // header end

View File

@ -353,7 +353,7 @@ void OLEDDisplay::drawFastImage(int16_t xMove, int16_t yMove, int16_t width, int
void OLEDDisplay::drawXbm(int16_t xMove, int16_t yMove, int16_t width, int16_t height, const char *xbm) { void OLEDDisplay::drawXbm(int16_t xMove, int16_t yMove, int16_t width, int16_t height, const char *xbm) {
int16_t widthInXbm = (width + 7) / 8; int16_t widthInXbm = (width + 7) / 8;
uint8_t data; uint8_t data = 0;
for(int16_t y = 0; y < height; y++) { for(int16_t y = 0; y < height; y++) {
for(int16_t x = 0; x < width; x++ ) { for(int16_t x = 0; x < width; x++ ) {
@ -388,6 +388,8 @@ void OLEDDisplay::drawStringInternal(int16_t xMove, int16_t yMove, char* text, u
case TEXT_ALIGN_RIGHT: case TEXT_ALIGN_RIGHT:
xMove -= textWidth; xMove -= textWidth;
break; break;
default:
break;
} }
// Don't draw anything if it is not on the screen. // Don't draw anything if it is not on the screen.
@ -719,7 +721,7 @@ void inline OLEDDisplay::drawInternal(int16_t xMove, int16_t yMove, int16_t widt
int16_t xPos = xMove + (i / rasterHeight); int16_t xPos = xMove + (i / rasterHeight);
int16_t yPos = ((yMove >> 3) + (i % rasterHeight)) * DISPLAY_WIDTH; int16_t yPos = ((yMove >> 3) + (i % rasterHeight)) * DISPLAY_WIDTH;
int16_t yScreenPos = yMove + yOffset; //int16_t yScreenPos = yMove + yOffset;
int16_t dataPos = xPos + yPos; int16_t dataPos = xPos + yPos;
if (dataPos >= 0 && dataPos < DISPLAY_BUFFER_SIZE && if (dataPos >= 0 && dataPos < DISPLAY_BUFFER_SIZE &&

View File

@ -250,7 +250,7 @@ class OLEDDisplay : public Print {
virtual void sendCommand(uint8_t com) {}; virtual void sendCommand(uint8_t com) {};
// Connect to the display // Connect to the display
virtual bool connect() {}; virtual bool connect() {return false;};
// Send all the init commands // Send all the init commands
void sendInitCommands(); void sendInitCommands();

View File

@ -251,7 +251,10 @@ void OLEDDisplayUi::drawFrame(){
switch (this->state.frameState){ switch (this->state.frameState){
case IN_TRANSITION: { case IN_TRANSITION: {
float progress = (float) this->state.ticksSinceLastStateSwitch / (float) this->ticksPerTransition; float progress = (float) this->state.ticksSinceLastStateSwitch / (float) this->ticksPerTransition;
int16_t x, y, x1, y1; int16_t x = 0;
int16_t y = 0;
int16_t x1 = 0;
int16_t y1 = 0;
switch(this->frameAnimationDirection){ switch(this->frameAnimationDirection){
case SLIDE_LEFT: case SLIDE_LEFT:
x = -128 * progress; x = -128 * progress;
@ -331,7 +334,7 @@ void OLEDDisplayUi::drawIndicator() {
return; return;
} }
uint8_t posOfHighlightFrame; uint8_t posOfHighlightFrame = 0;
float indicatorFadeProgress = 0; float indicatorFadeProgress = 0;
// if the indicator needs to be slided in we want to // if the indicator needs to be slided in we want to
@ -362,7 +365,8 @@ void OLEDDisplayUi::drawIndicator() {
uint16_t frameStartPos = (12 * frameCount / 2); uint16_t frameStartPos = (12 * frameCount / 2);
const char *image; const char *image;
uint16_t x,y; uint16_t x = 0;
uint16_t y = 0;
for (byte i = 0; i < this->frameCount; i++) { for (byte i = 0; i < this->frameCount; i++) {
switch (this->indicatorPosition){ switch (this->indicatorPosition){