forked from Links2004/arduinoWebSockets
clang-format
This commit is contained in:
63
.clang-format
Normal file
63
.clang-format
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
---
|
||||||
|
BasedOnStyle: Google
|
||||||
|
AccessModifierOffset: '-2'
|
||||||
|
AlignAfterOpenBracket: DontAlign
|
||||||
|
AlignConsecutiveAssignments: 'true'
|
||||||
|
AlignConsecutiveDeclarations: 'false'
|
||||||
|
AlignEscapedNewlines: Left
|
||||||
|
AlignTrailingComments: 'true'
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: 'false'
|
||||||
|
AllowShortBlocksOnASingleLine: 'false'
|
||||||
|
AllowShortCaseLabelsOnASingleLine: 'false'
|
||||||
|
AllowShortFunctionsOnASingleLine: InlineOnly
|
||||||
|
AllowShortIfStatementsOnASingleLine: 'true'
|
||||||
|
AllowShortLoopsOnASingleLine: 'true'
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: 'true'
|
||||||
|
AlwaysBreakTemplateDeclarations: 'false'
|
||||||
|
BinPackParameters: 'true'
|
||||||
|
BreakAfterJavaFieldAnnotations: 'false'
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
BreakBeforeInheritanceComma: 'false'
|
||||||
|
BreakBeforeTernaryOperators: 'false'
|
||||||
|
BreakConstructorInitializers: BeforeColon
|
||||||
|
BreakStringLiterals: 'false'
|
||||||
|
ColumnLimit: '0'
|
||||||
|
CompactNamespaces: 'true'
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
|
||||||
|
ConstructorInitializerIndentWidth: '4'
|
||||||
|
ContinuationIndentWidth: '4'
|
||||||
|
Cpp11BracedListStyle: 'false'
|
||||||
|
DerivePointerAlignment: 'false'
|
||||||
|
FixNamespaceComments: 'true'
|
||||||
|
IndentCaseLabels: 'true'
|
||||||
|
IndentWidth: '4'
|
||||||
|
IndentWrappedFunctionNames: 'false'
|
||||||
|
JavaScriptQuotes: Single
|
||||||
|
JavaScriptWrapImports: 'false'
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: 'false'
|
||||||
|
MaxEmptyLinesToKeep: '1'
|
||||||
|
NamespaceIndentation: All
|
||||||
|
ObjCBlockIndentWidth: '4'
|
||||||
|
ObjCSpaceAfterProperty: 'false'
|
||||||
|
ObjCSpaceBeforeProtocolList: 'false'
|
||||||
|
PointerAlignment: Middle
|
||||||
|
SortIncludes: 'false'
|
||||||
|
SortUsingDeclarations: 'true'
|
||||||
|
SpaceAfterCStyleCast: 'false'
|
||||||
|
SpaceAfterTemplateKeyword: 'false'
|
||||||
|
SpaceBeforeAssignmentOperators: 'true'
|
||||||
|
SpaceBeforeParens: Never
|
||||||
|
SpaceInEmptyParentheses: 'false'
|
||||||
|
SpacesBeforeTrailingComments: '4'
|
||||||
|
SpacesInAngles: 'false'
|
||||||
|
SpacesInCStyleCastParentheses: 'false'
|
||||||
|
SpacesInContainerLiterals: 'false'
|
||||||
|
SpacesInParentheses: 'false'
|
||||||
|
SpacesInSquareBrackets: 'false'
|
||||||
|
TabWidth: '4'
|
||||||
|
UseTab: Never
|
||||||
|
|
||||||
|
...
|
@ -48,7 +48,6 @@ extern "C" {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param client WSclient_t * ptr to the client struct
|
* @param client WSclient_t * ptr to the client struct
|
||||||
@ -82,7 +81,6 @@ void WebSockets::clientDisconnect(WSclient_t * client, uint16_t code, char * rea
|
|||||||
* @return true if ok
|
* @return true if ok
|
||||||
*/
|
*/
|
||||||
bool WebSockets::sendFrame(WSclient_t * client, WSopcode_t opcode, uint8_t * payload, size_t length, bool fin, bool headerToPayload) {
|
bool WebSockets::sendFrame(WSclient_t * client, WSopcode_t opcode, uint8_t * payload, size_t length, bool fin, bool headerToPayload) {
|
||||||
|
|
||||||
if(client->tcp && !client->tcp->connected()) {
|
if(client->tcp && !client->tcp->connected()) {
|
||||||
DEBUG_WEBSOCKETS("[WS][%d][sendFrame] not Connected!?\n", client->num);
|
DEBUG_WEBSOCKETS("[WS][%d][sendFrame] not Connected!?\n", client->num);
|
||||||
return false;
|
return false;
|
||||||
@ -318,12 +316,12 @@ bool WebSockets::handleWebsocketWaitFor(WSclient_t * client, size_t size) {
|
|||||||
// timeout or error
|
// timeout or error
|
||||||
server->clientDisconnect(client, 1002);
|
server->clientDisconnect(client, 1002);
|
||||||
}
|
}
|
||||||
}, this, size, std::placeholders::_1, std::placeholders::_2));
|
},
|
||||||
|
this, size, std::placeholders::_1, std::placeholders::_2));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebSockets::handleWebsocketCb(WSclient_t * client) {
|
void WebSockets::handleWebsocketCb(WSclient_t * client) {
|
||||||
|
|
||||||
if(!client->tcp || !client->tcp->connected()) {
|
if(!client->tcp || !client->tcp->connected()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -409,7 +407,6 @@ void WebSockets::handleWebsocketCb(WSclient_t * client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WebSockets::handleWebsocketPayloadCb(WSclient_t * client, bool ok, uint8_t * payload) {
|
void WebSockets::handleWebsocketPayloadCb(WSclient_t * client, bool ok, uint8_t * payload) {
|
||||||
|
|
||||||
WSMessageHeader_t * header = &client->cWsHeaderDecode;
|
WSMessageHeader_t * header = &client->cWsHeaderDecode;
|
||||||
if(ok) {
|
if(ok) {
|
||||||
if(header->payloadLen > 0) {
|
if(header->payloadLen > 0) {
|
||||||
@ -456,8 +453,7 @@ void WebSockets::handleWebsocketPayloadCb(WSclient_t * client, bool ok, uint8_t
|
|||||||
DEBUG_WEBSOCKETS("\n");
|
DEBUG_WEBSOCKETS("\n");
|
||||||
}
|
}
|
||||||
clientDisconnect(client, 1000);
|
clientDisconnect(client, 1000);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
clientDisconnect(client, 1002);
|
clientDisconnect(client, 1002);
|
||||||
break;
|
break;
|
||||||
@ -546,7 +542,8 @@ bool WebSockets::readCb(WSclient_t * client, uint8_t * out, size_t n, WSreadWait
|
|||||||
if(cb) {
|
if(cb) {
|
||||||
cb(client, ok);
|
cb(client, ok);
|
||||||
}
|
}
|
||||||
}, client, std::placeholders::_1, cb));
|
},
|
||||||
|
client, std::placeholders::_1, cb));
|
||||||
|
|
||||||
#else
|
#else
|
||||||
unsigned long t = millis();
|
unsigned long t = millis();
|
||||||
@ -612,8 +609,10 @@ 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)
|
||||||
if(client == NULL) return 0;
|
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;
|
||||||
@ -652,8 +651,10 @@ size_t WebSockets::write(WSclient_t * client, uint8_t *out, size_t n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
if(out == NULL) return 0;
|
return 0;
|
||||||
|
if(out == NULL)
|
||||||
|
return 0;
|
||||||
return write(client, (uint8_t *)out, strlen(out));
|
return write(client, (uint8_t *)out, strlen(out));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -665,7 +666,8 @@ size_t WebSockets::write(WSclient_t * client, const char *out) {
|
|||||||
* @param disconnectTimeoutCount uint8_t how many timeouts before disconnect, 0=> do not disconnect
|
* @param disconnectTimeoutCount uint8_t how many timeouts before disconnect, 0=> do not disconnect
|
||||||
*/
|
*/
|
||||||
void WebSockets::enableHeartbeat(WSclient_t * client, uint32_t pingInterval, uint32_t pongTimeout, uint8_t disconnectTimeoutCount) {
|
void WebSockets::enableHeartbeat(WSclient_t * client, uint32_t pingInterval, uint32_t pongTimeout, uint8_t disconnectTimeoutCount) {
|
||||||
if(client == NULL) return;
|
if(client == NULL)
|
||||||
|
return;
|
||||||
client->pingInterval = pingInterval;
|
client->pingInterval = pingInterval;
|
||||||
client->pongTimeout = pongTimeout;
|
client->pongTimeout = pongTimeout;
|
||||||
client->disconnectTimeoutCount = disconnectTimeoutCount;
|
client->disconnectTimeoutCount = disconnectTimeoutCount;
|
||||||
|
@ -40,7 +40,6 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef NODEBUG_WEBSOCKETS
|
#ifndef NODEBUG_WEBSOCKETS
|
||||||
#ifdef DEBUG_ESP_PORT
|
#ifdef DEBUG_ESP_PORT
|
||||||
#define DEBUG_WEBSOCKETS(...) DEBUG_ESP_PORT.printf(__VA_ARGS__)
|
#define DEBUG_WEBSOCKETS(...) DEBUG_ESP_PORT.printf(__VA_ARGS__)
|
||||||
@ -49,7 +48,6 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef DEBUG_WEBSOCKETS
|
#ifndef DEBUG_WEBSOCKETS
|
||||||
#define DEBUG_WEBSOCKETS(...)
|
#define DEBUG_WEBSOCKETS(...)
|
||||||
#define NODEBUG_WEBSOCKETS
|
#define NODEBUG_WEBSOCKETS
|
||||||
@ -78,7 +76,6 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define WEBSOCKETS_TCP_TIMEOUT (2000)
|
#define WEBSOCKETS_TCP_TIMEOUT (2000)
|
||||||
|
|
||||||
#define NETWORK_ESP8266_ASYNC (0)
|
#define NETWORK_ESP8266_ASYNC (0)
|
||||||
@ -114,7 +111,6 @@
|
|||||||
// No SSL/WSS support for client in Async mode
|
// No SSL/WSS support for client in Async mode
|
||||||
// TLS lib need a sync interface!
|
// TLS lib need a sync interface!
|
||||||
|
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#elif defined(ESP32)
|
#elif defined(ESP32)
|
||||||
@ -182,7 +178,6 @@
|
|||||||
#error "no network type selected!"
|
#error "no network type selected!"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef WEBSOCKETS_NETWORK_SSL_CLASS
|
#ifdef WEBSOCKETS_NETWORK_SSL_CLASS
|
||||||
#define HAS_SSL
|
#define HAS_SSL
|
||||||
#endif
|
#endif
|
||||||
@ -226,7 +221,6 @@ typedef enum {
|
|||||||
} WSopcode_t;
|
} WSopcode_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
||||||
bool fin;
|
bool fin;
|
||||||
bool rsv1;
|
bool rsv1;
|
||||||
bool rsv2;
|
bool rsv2;
|
||||||
@ -293,8 +287,6 @@ typedef struct {
|
|||||||
|
|
||||||
} WSclient_t;
|
} WSclient_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class WebSockets {
|
class WebSockets {
|
||||||
protected:
|
protected:
|
||||||
#ifdef __AVR__
|
#ifdef __AVR__
|
||||||
@ -328,8 +320,6 @@ class WebSockets {
|
|||||||
|
|
||||||
void enableHeartbeat(WSclient_t * client, uint32_t pingInterval, uint32_t pongTimeout, uint8_t disconnectTimeoutCount);
|
void enableHeartbeat(WSclient_t * client, uint32_t pingInterval, uint32_t pongTimeout, uint8_t disconnectTimeoutCount);
|
||||||
void handleHBTimeout(WSclient_t * client);
|
void handleHBTimeout(WSclient_t * client);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef UNUSED
|
#ifndef UNUSED
|
||||||
|
@ -197,7 +197,6 @@ void WebSocketsClient::loop(void) {
|
|||||||
} else {
|
} else {
|
||||||
connectFailedCb();
|
connectFailedCb();
|
||||||
_lastConnectionFail = millis();
|
_lastConnectionFail = millis();
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
handleClientData();
|
handleClientData();
|
||||||
@ -206,7 +205,6 @@ void WebSocketsClient::loop(void) {
|
|||||||
handleHBPing();
|
handleHBPing();
|
||||||
handleHBTimeout(&_client);
|
handleHBTimeout(&_client);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -383,7 +381,6 @@ void WebSocketsClient::messageReceived(WSclient_t * client, WSopcode_t opcode, u
|
|||||||
}
|
}
|
||||||
|
|
||||||
runCbEvent(type, payload, length);
|
runCbEvent(type, payload, length);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -391,7 +388,6 @@ void WebSocketsClient::messageReceived(WSclient_t * client, WSopcode_t opcode, u
|
|||||||
* @param client WSclient_t * ptr to the client struct
|
* @param client WSclient_t * ptr to the client struct
|
||||||
*/
|
*/
|
||||||
void WebSocketsClient::clientDisconnect(WSclient_t * client) {
|
void WebSocketsClient::clientDisconnect(WSclient_t * client) {
|
||||||
|
|
||||||
bool event = false;
|
bool event = false;
|
||||||
|
|
||||||
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32)
|
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32)
|
||||||
@ -445,7 +441,6 @@ void WebSocketsClient::clientDisconnect(WSclient_t * client) {
|
|||||||
* @return true = conneted
|
* @return true = conneted
|
||||||
*/
|
*/
|
||||||
bool WebSocketsClient::clientIsConnected(WSclient_t * client) {
|
bool WebSocketsClient::clientIsConnected(WSclient_t * client) {
|
||||||
|
|
||||||
if(!client->tcp) {
|
if(!client->tcp) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -481,8 +476,7 @@ void WebSocketsClient::handleClientData(void) {
|
|||||||
case WSC_HEADER: {
|
case WSC_HEADER: {
|
||||||
String headerLine = _client.tcp->readStringUntil('\n');
|
String headerLine = _client.tcp->readStringUntil('\n');
|
||||||
handleHeader(&_client, &headerLine);
|
handleHeader(&_client, &headerLine);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
case WSC_CONNECTED:
|
case WSC_CONNECTED:
|
||||||
WebSockets::handleWebsocket(&_client);
|
WebSockets::handleWebsocket(&_client);
|
||||||
break;
|
break;
|
||||||
@ -502,7 +496,6 @@ void WebSocketsClient::handleClientData(void) {
|
|||||||
* @param client WSclient_t * ptr to the client struct
|
* @param client WSclient_t * ptr to the client struct
|
||||||
*/
|
*/
|
||||||
void WebSocketsClient::sendHeader(WSclient_t * client) {
|
void WebSocketsClient::sendHeader(WSclient_t * client) {
|
||||||
|
|
||||||
static const char * NEW_LINE = "\r\n";
|
static const char * NEW_LINE = "\r\n";
|
||||||
|
|
||||||
DEBUG_WEBSOCKETS("[WS-Client][sendHeader] sending header...\n");
|
DEBUG_WEBSOCKETS("[WS-Client][sendHeader] sending header...\n");
|
||||||
@ -534,12 +527,14 @@ void WebSocketsClient::sendHeader(WSclient_t * client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handshake = WEBSOCKETS_STRING("GET ");
|
handshake = WEBSOCKETS_STRING("GET ");
|
||||||
handshake += url + WEBSOCKETS_STRING(" HTTP/1.1\r\n"
|
handshake += url + WEBSOCKETS_STRING(
|
||||||
|
" HTTP/1.1\r\n"
|
||||||
"Host: ");
|
"Host: ");
|
||||||
handshake += _host + ":" + _port + NEW_LINE;
|
handshake += _host + ":" + _port + NEW_LINE;
|
||||||
|
|
||||||
if(ws_header) {
|
if(ws_header) {
|
||||||
handshake += WEBSOCKETS_STRING("Connection: Upgrade\r\n"
|
handshake += WEBSOCKETS_STRING(
|
||||||
|
"Connection: Upgrade\r\n"
|
||||||
"Upgrade: websocket\r\n"
|
"Upgrade: websocket\r\n"
|
||||||
"Sec-WebSocket-Version: 13\r\n"
|
"Sec-WebSocket-Version: 13\r\n"
|
||||||
"Sec-WebSocket-Key: ");
|
"Sec-WebSocket-Key: ");
|
||||||
@ -585,7 +580,6 @@ void WebSocketsClient::sendHeader(WSclient_t * client) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
DEBUG_WEBSOCKETS("[WS-Client][sendHeader] sending header... Done (%luus).\n", (micros() - start));
|
DEBUG_WEBSOCKETS("[WS-Client][sendHeader] sending header... Done (%luus).\n", (micros() - start));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -593,7 +587,6 @@ void WebSocketsClient::sendHeader(WSclient_t * client) {
|
|||||||
* @param client WSclient_t * ptr to the client struct
|
* @param client WSclient_t * ptr to the client struct
|
||||||
*/
|
*/
|
||||||
void WebSocketsClient::handleHeader(WSclient_t * client, String * headerLine) {
|
void WebSocketsClient::handleHeader(WSclient_t * client, String * headerLine) {
|
||||||
|
|
||||||
headerLine->trim(); // remove \r
|
headerLine->trim(); // remove \r
|
||||||
|
|
||||||
if(headerLine->length() > 0) {
|
if(headerLine->length() > 0) {
|
||||||
@ -643,7 +636,6 @@ void WebSocketsClient::handleHeader(WSclient_t * client, String * headerLine) {
|
|||||||
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
|
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
|
||||||
client->tcp->readStringUntil('\n', &(client->cHttpLine), std::bind(&WebSocketsClient::handleHeader, this, client, &(client->cHttpLine)));
|
client->tcp->readStringUntil('\n', &(client->cHttpLine), std::bind(&WebSocketsClient::handleHeader, this, client, &(client->cHttpLine)));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
DEBUG_WEBSOCKETS("[WS-Client][handleHeader] Header read fin.\n");
|
DEBUG_WEBSOCKETS("[WS-Client][handleHeader] Header read fin.\n");
|
||||||
DEBUG_WEBSOCKETS("[WS-Client][handleHeader] Client settings:\n");
|
DEBUG_WEBSOCKETS("[WS-Client][handleHeader] Client settings:\n");
|
||||||
@ -684,7 +676,6 @@ void WebSocketsClient::handleHeader(WSclient_t * client, String * headerLine) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(ok) {
|
if(ok) {
|
||||||
|
|
||||||
if(client->cAccept.length() == 0) {
|
if(client->cAccept.length() == 0) {
|
||||||
ok = false;
|
ok = false;
|
||||||
} else {
|
} else {
|
||||||
@ -698,12 +689,10 @@ void WebSocketsClient::handleHeader(WSclient_t * client, String * headerLine) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(ok) {
|
if(ok) {
|
||||||
|
|
||||||
DEBUG_WEBSOCKETS("[WS-Client][handleHeader] Websocket connection init done.\n");
|
DEBUG_WEBSOCKETS("[WS-Client][handleHeader] Websocket connection init done.\n");
|
||||||
headerDone(client);
|
headerDone(client);
|
||||||
|
|
||||||
runCbEvent(WStype_CONNECTED, (uint8_t *)client->cUrl.c_str(), client->cUrl.length());
|
runCbEvent(WStype_CONNECTED, (uint8_t *)client->cUrl.c_str(), client->cUrl.length());
|
||||||
|
|
||||||
} else if(clientIsConnected(client) && client->isSocketIO && client->cSessionId.length() > 0) {
|
} else if(clientIsConnected(client) && client->isSocketIO && client->cSessionId.length() > 0) {
|
||||||
sendHeader(client);
|
sendHeader(client);
|
||||||
} else {
|
} else {
|
||||||
@ -718,7 +707,6 @@ void WebSocketsClient::handleHeader(WSclient_t * client, String * headerLine) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WebSocketsClient::connectedCb() {
|
void WebSocketsClient::connectedCb() {
|
||||||
|
|
||||||
DEBUG_WEBSOCKETS("[WS-Client] connected to %s:%u.\n", _host.c_str(), _port);
|
DEBUG_WEBSOCKETS("[WS-Client] connected to %s:%u.\n", _host.c_str(), _port);
|
||||||
|
|
||||||
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
|
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
|
||||||
@ -731,7 +719,8 @@ void WebSocketsClient::connectedCb() {
|
|||||||
c->asyncConnect();
|
c->asyncConnect();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}, this, std::placeholders::_1, &_client));
|
},
|
||||||
|
this, std::placeholders::_1, &_client));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_client.status = WSC_HEADER;
|
_client.status = WSC_HEADER;
|
||||||
@ -741,7 +730,7 @@ void WebSocketsClient::connectedCb() {
|
|||||||
_client.tcp->setTimeout(WEBSOCKETS_TCP_TIMEOUT);
|
_client.tcp->setTimeout(WEBSOCKETS_TCP_TIMEOUT);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32
|
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32)
|
||||||
_client.tcp->setNoDelay(true);
|
_client.tcp->setNoDelay(true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -761,7 +750,6 @@ void WebSocketsClient::connectedCb() {
|
|||||||
|
|
||||||
// send Header to Server
|
// send Header to Server
|
||||||
sendHeader(&_client);
|
sendHeader(&_client);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebSocketsClient::connectFailedCb() {
|
void WebSocketsClient::connectFailedCb() {
|
||||||
@ -771,7 +759,6 @@ void WebSocketsClient::connectFailedCb() {
|
|||||||
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
|
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
|
||||||
|
|
||||||
void WebSocketsClient::asyncConnect() {
|
void WebSocketsClient::asyncConnect() {
|
||||||
|
|
||||||
DEBUG_WEBSOCKETS("[WS-Client] asyncConnect...\n");
|
DEBUG_WEBSOCKETS("[WS-Client] asyncConnect...\n");
|
||||||
|
|
||||||
AsyncClient * tcpclient = new AsyncClient();
|
AsyncClient * tcpclient = new AsyncClient();
|
||||||
@ -794,20 +781,21 @@ void WebSocketsClient::asyncConnect() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ws->connectedCb();
|
ws->connectedCb();
|
||||||
}, this, std::placeholders::_2));
|
},
|
||||||
|
this, std::placeholders::_2));
|
||||||
|
|
||||||
tcpclient->onError(std::bind([](WebSocketsClient * ws, AsyncClient * tcp) {
|
tcpclient->onError(std::bind([](WebSocketsClient * ws, AsyncClient * tcp) {
|
||||||
ws->connectFailedCb();
|
ws->connectFailedCb();
|
||||||
|
|
||||||
// reconnect
|
// reconnect
|
||||||
ws->asyncConnect();
|
ws->asyncConnect();
|
||||||
}, this, std::placeholders::_2));
|
},
|
||||||
|
this, std::placeholders::_2));
|
||||||
|
|
||||||
if(!tcpclient->connect(_host.c_str(), _port)) {
|
if(!tcpclient->connect(_host.c_str(), _port)) {
|
||||||
connectFailedCb();
|
connectFailedCb();
|
||||||
delete tcpclient;
|
delete tcpclient;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -816,7 +804,8 @@ void WebSocketsClient::asyncConnect() {
|
|||||||
* send heartbeat ping to server in set intervals
|
* send heartbeat ping to server in set intervals
|
||||||
*/
|
*/
|
||||||
void WebSocketsClient::handleHBPing() {
|
void WebSocketsClient::handleHBPing() {
|
||||||
if (_client.pingInterval == 0) return;
|
if(_client.pingInterval == 0)
|
||||||
|
return;
|
||||||
uint32_t pi = millis() - _client.lastPing;
|
uint32_t pi = millis() - _client.lastPing;
|
||||||
if(pi > _client.pingInterval) {
|
if(pi > _client.pingInterval) {
|
||||||
DEBUG_WEBSOCKETS("[WS-Client] sending HB ping\n");
|
DEBUG_WEBSOCKETS("[WS-Client] sending HB ping\n");
|
||||||
@ -825,7 +814,6 @@ void WebSocketsClient::handleHBPing(){
|
|||||||
_client.pongReceived = false;
|
_client.pongReceived = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,7 +35,6 @@ class WebSocketsClient: private WebSockets {
|
|||||||
typedef std::function<void(WStype_t type, uint8_t * payload, size_t length)> WebSocketClientEvent;
|
typedef std::function<void(WStype_t type, uint8_t * payload, size_t length)> WebSocketClientEvent;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
WebSocketsClient(void);
|
WebSocketsClient(void);
|
||||||
virtual ~WebSocketsClient(void);
|
virtual ~WebSocketsClient(void);
|
||||||
|
|
||||||
@ -138,7 +137,6 @@ class WebSocketsClient: private WebSockets {
|
|||||||
_cbEvent(type, payload, length);
|
_cbEvent(type, payload, length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* WEBSOCKETSCLIENT_H_ */
|
#endif /* WEBSOCKETSCLIENT_H_ */
|
||||||
|
@ -36,7 +36,8 @@ WebSocketsServer::WebSocketsServer(uint16_t port, String origin, String protocol
|
|||||||
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
|
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
|
||||||
_server->onClient([](void * s, AsyncClient * c) {
|
_server->onClient([](void * s, AsyncClient * c) {
|
||||||
((WebSocketsServer *)s)->newClient(new AsyncTCPbuffer(c));
|
((WebSocketsServer *)s)->newClient(new AsyncTCPbuffer(c));
|
||||||
}, this);
|
},
|
||||||
|
this);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_cbEvent = NULL;
|
_cbEvent = NULL;
|
||||||
@ -48,7 +49,6 @@ WebSocketsServer::WebSocketsServer(uint16_t port, String origin, String protocol
|
|||||||
memset(&_clients[0], 0x00, (sizeof(WSclient_t) * WEBSOCKETS_SERVER_CLIENT_MAX));
|
memset(&_clients[0], 0x00, (sizeof(WSclient_t) * WEBSOCKETS_SERVER_CLIENT_MAX));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
WebSocketsServer::~WebSocketsServer() {
|
WebSocketsServer::~WebSocketsServer() {
|
||||||
// disconnect all clients
|
// disconnect all clients
|
||||||
close();
|
close();
|
||||||
@ -120,7 +120,6 @@ void WebSocketsServer::close(void) {
|
|||||||
#else
|
#else
|
||||||
// TODO how to close server?
|
// TODO how to close server?
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if(WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC)
|
#if(WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC)
|
||||||
@ -152,8 +151,7 @@ void WebSocketsServer::onEvent(WebSocketServerEvent cbEvent) {
|
|||||||
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)
|
||||||
@ -300,7 +298,6 @@ bool WebSocketsServer::broadcastBIN(const uint8_t * payload, size_t length) {
|
|||||||
return broadcastBIN((uint8_t *)payload, length);
|
return broadcastBIN((uint8_t *)payload, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sends a WS ping to Client
|
* sends a WS ping to Client
|
||||||
* @param num uint8_t client id
|
* @param num uint8_t client id
|
||||||
@ -350,7 +347,6 @@ bool WebSocketsServer::broadcastPing(String & payload) {
|
|||||||
return broadcastPing((uint8_t *)payload.c_str(), payload.length());
|
return broadcastPing((uint8_t *)payload.c_str(), payload.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* disconnect all clients
|
* disconnect all clients
|
||||||
*/
|
*/
|
||||||
@ -378,7 +374,6 @@ void WebSocketsServer::disconnect(uint8_t num) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* set the Authorization for the http request
|
* set the Authorization for the http request
|
||||||
* @param user const char *
|
* @param user const char *
|
||||||
@ -455,7 +450,6 @@ bool WebSocketsServer::newClient(WEBSOCKETS_NETWORK_CLASS * TCPclient) {
|
|||||||
|
|
||||||
// state is not connected or tcp connection is lost
|
// state is not connected or tcp connection is lost
|
||||||
if(!clientIsConnected(client)) {
|
if(!clientIsConnected(client)) {
|
||||||
|
|
||||||
client->tcp = TCPclient;
|
client->tcp = TCPclient;
|
||||||
|
|
||||||
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32)
|
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32)
|
||||||
@ -474,7 +468,6 @@ bool WebSocketsServer::newClient(WEBSOCKETS_NETWORK_CLASS * TCPclient) {
|
|||||||
DEBUG_WEBSOCKETS("[WS-Server][%d] new client\n", client->num);
|
DEBUG_WEBSOCKETS("[WS-Server][%d] new client\n", client->num);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
|
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
|
||||||
client->tcp->onDisconnect(std::bind([](WebSocketsServer * server, AsyncTCPbuffer * obj, WSclient_t * client) -> bool {
|
client->tcp->onDisconnect(std::bind([](WebSocketsServer * server, AsyncTCPbuffer * obj, WSclient_t * client) -> bool {
|
||||||
DEBUG_WEBSOCKETS("[WS-Server][%d] Disconnect client\n", client->num);
|
DEBUG_WEBSOCKETS("[WS-Server][%d] Disconnect client\n", client->num);
|
||||||
@ -485,8 +478,8 @@ bool WebSocketsServer::newClient(WEBSOCKETS_NETWORK_CLASS * TCPclient) {
|
|||||||
*sl = NULL;
|
*sl = NULL;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}, this, std::placeholders::_1, client));
|
},
|
||||||
|
this, std::placeholders::_1, client));
|
||||||
|
|
||||||
client->tcp->readStringUntil('\n', &(client->cHttpLine), std::bind(&WebSocketsServer::handleHeader, this, client, &(client->cHttpLine)));
|
client->tcp->readStringUntil('\n', &(client->cHttpLine), std::bind(&WebSocketsServer::handleHeader, this, client, &(client->cHttpLine)));
|
||||||
#endif
|
#endif
|
||||||
@ -530,7 +523,6 @@ void WebSocketsServer::messageReceived(WSclient_t * client, WSopcode_t opcode, u
|
|||||||
}
|
}
|
||||||
|
|
||||||
runCbEvent(client->num, type, payload, length);
|
runCbEvent(client->num, type, payload, length);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -538,8 +530,6 @@ void WebSocketsServer::messageReceived(WSclient_t * client, WSopcode_t opcode, u
|
|||||||
* @param client WSclient_t * ptr to the client struct
|
* @param client WSclient_t * ptr to the client struct
|
||||||
*/
|
*/
|
||||||
void WebSocketsServer::clientDisconnect(WSclient_t * client) {
|
void WebSocketsServer::clientDisconnect(WSclient_t * client) {
|
||||||
|
|
||||||
|
|
||||||
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32)
|
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32)
|
||||||
if(client->isSSL && client->ssl) {
|
if(client->isSSL && client->ssl) {
|
||||||
if(client->ssl->connected()) {
|
if(client->ssl->connected()) {
|
||||||
@ -585,7 +575,6 @@ void WebSocketsServer::clientDisconnect(WSclient_t * client) {
|
|||||||
DEBUG_WEBSOCKETS("[WS-Server][%d] client disconnected.\n", client->num);
|
DEBUG_WEBSOCKETS("[WS-Server][%d] client disconnected.\n", client->num);
|
||||||
|
|
||||||
runCbEvent(client->num, WStype_DISCONNECTED, NULL, 0);
|
runCbEvent(client->num, WStype_DISCONNECTED, NULL, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -594,7 +583,6 @@ void WebSocketsServer::clientDisconnect(WSclient_t * client) {
|
|||||||
* @return true = connected
|
* @return true = connected
|
||||||
*/
|
*/
|
||||||
bool WebSocketsServer::clientIsConnected(WSclient_t * client) {
|
bool WebSocketsServer::clientIsConnected(WSclient_t * client) {
|
||||||
|
|
||||||
if(!client->tcp) {
|
if(!client->tcp) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -625,7 +613,6 @@ bool WebSocketsServer::clientIsConnected(WSclient_t * client) {
|
|||||||
* Handle incoming Connection Request
|
* Handle incoming Connection Request
|
||||||
*/
|
*/
|
||||||
void WebSocketsServer::handleNewClients(void) {
|
void WebSocketsServer::handleNewClients(void) {
|
||||||
|
|
||||||
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32)
|
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32)
|
||||||
while(_server->hasClient()) {
|
while(_server->hasClient()) {
|
||||||
#endif
|
#endif
|
||||||
@ -660,15 +647,12 @@ void WebSocketsServer::handleNewClients(void) {
|
|||||||
delay(0);
|
delay(0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handel incomming data from Client
|
* Handel incomming data from Client
|
||||||
*/
|
*/
|
||||||
void WebSocketsServer::handleClientData(void) {
|
void WebSocketsServer::handleClientData(void) {
|
||||||
|
|
||||||
WSclient_t * client;
|
WSclient_t * client;
|
||||||
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];
|
||||||
@ -677,12 +661,10 @@ void WebSocketsServer::handleClientData(void) {
|
|||||||
if(len > 0) {
|
if(len > 0) {
|
||||||
//DEBUG_WEBSOCKETS("[WS-Server][%d][handleClientData] len: %d\n", client->num, len);
|
//DEBUG_WEBSOCKETS("[WS-Server][%d][handleClientData] len: %d\n", client->num, len);
|
||||||
switch(client->status) {
|
switch(client->status) {
|
||||||
case WSC_HEADER:
|
case WSC_HEADER: {
|
||||||
{
|
|
||||||
String headerLine = client->tcp->readStringUntil('\n');
|
String headerLine = client->tcp->readStringUntil('\n');
|
||||||
handleHeader(client, &headerLine);
|
handleHeader(client, &headerLine);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
case WSC_CONNECTED:
|
case WSC_CONNECTED:
|
||||||
WebSockets::handleWebsocket(client);
|
WebSockets::handleWebsocket(client);
|
||||||
break;
|
break;
|
||||||
@ -711,14 +693,12 @@ bool WebSocketsServer::hasMandatoryHeader(String headerName) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* handles http header reading for WebSocket upgrade
|
* handles http header reading for WebSocket upgrade
|
||||||
* @param client WSclient_t * ///< pointer to the client struct
|
* @param client WSclient_t * ///< pointer to the client struct
|
||||||
* @param headerLine String ///< the header being read / processed
|
* @param headerLine String ///< the header being read / processed
|
||||||
*/
|
*/
|
||||||
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
|
||||||
@ -728,7 +708,6 @@ void WebSocketsServer::handleHeader(WSclient_t * client, String * headerLine) {
|
|||||||
|
|
||||||
// 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));
|
||||||
|
|
||||||
@ -781,7 +760,6 @@ void WebSocketsServer::handleHeader(WSclient_t * client, String * headerLine) {
|
|||||||
client->tcp->readStringUntil('\n', &(client->cHttpLine), std::bind(&WebSocketsServer::handleHeader, this, client, &(client->cHttpLine)));
|
client->tcp->readStringUntil('\n', &(client->cHttpLine), std::bind(&WebSocketsServer::handleHeader, this, client, &(client->cHttpLine)));
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] Header read fin.\n", client->num);
|
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] Header read fin.\n", client->num);
|
||||||
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] - cURL: %s\n", client->num, client->cUrl.c_str());
|
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] - cURL: %s\n", client->num, client->cUrl.c_str());
|
||||||
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] - cIsUpgrade: %d\n", client->num, client->cIsUpgrade);
|
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] - cIsUpgrade: %d\n", client->num, client->cIsUpgrade);
|
||||||
@ -825,7 +803,6 @@ void WebSocketsServer::handleHeader(WSclient_t * client, String * headerLine) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(ok) {
|
if(ok) {
|
||||||
|
|
||||||
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] Websocket connection incoming.\n", client->num);
|
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] Websocket connection incoming.\n", client->num);
|
||||||
|
|
||||||
// generate Sec-WebSocket-Accept key
|
// generate Sec-WebSocket-Accept key
|
||||||
@ -835,7 +812,8 @@ void WebSocketsServer::handleHeader(WSclient_t * client, String * headerLine) {
|
|||||||
|
|
||||||
client->status = WSC_CONNECTED;
|
client->status = WSC_CONNECTED;
|
||||||
|
|
||||||
String handshake = WEBSOCKETS_STRING("HTTP/1.1 101 Switching Protocols\r\n"
|
String handshake = WEBSOCKETS_STRING(
|
||||||
|
"HTTP/1.1 101 Switching Protocols\r\n"
|
||||||
"Server: arduino-WebSocketsServer\r\n"
|
"Server: arduino-WebSocketsServer\r\n"
|
||||||
"Upgrade: websocket\r\n"
|
"Upgrade: websocket\r\n"
|
||||||
"Connection: Upgrade\r\n"
|
"Connection: Upgrade\r\n"
|
||||||
@ -872,6 +850,3 @@ void WebSocketsServer::handleHeader(WSclient_t * client, String * headerLine) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,12 +31,8 @@
|
|||||||
#define WEBSOCKETS_SERVER_CLIENT_MAX (5)
|
#define WEBSOCKETS_SERVER_CLIENT_MAX (5)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class WebSocketsServer : protected WebSockets {
|
class WebSocketsServer : protected WebSockets {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
#ifdef __AVR__
|
#ifdef __AVR__
|
||||||
typedef void (*WebSocketServerEvent)(uint8_t num, WStype_t type, uint8_t * payload, size_t length);
|
typedef void (*WebSocketServerEvent)(uint8_t num, WStype_t type, uint8_t * payload, size_t length);
|
||||||
typedef bool (*WebSocketServerHttpHeaderValFunc)(String headerName, String headerValue);
|
typedef bool (*WebSocketServerHttpHeaderValFunc)(String headerName, String headerValue);
|
||||||
@ -64,7 +60,6 @@ public:
|
|||||||
const char * mandatoryHttpHeaders[],
|
const char * mandatoryHttpHeaders[],
|
||||||
size_t mandatoryHttpHeaderCount);
|
size_t mandatoryHttpHeaderCount);
|
||||||
|
|
||||||
|
|
||||||
bool sendTXT(uint8_t num, uint8_t * payload, size_t length = 0, bool headerToPayload = false);
|
bool sendTXT(uint8_t num, uint8_t * payload, size_t length = 0, bool headerToPayload = false);
|
||||||
bool sendTXT(uint8_t num, const uint8_t * payload, size_t length = 0);
|
bool sendTXT(uint8_t num, const uint8_t * payload, size_t length = 0);
|
||||||
bool sendTXT(uint8_t num, char * payload, size_t length = 0, bool headerToPayload = false);
|
bool sendTXT(uint8_t num, char * payload, size_t length = 0, bool headerToPayload = false);
|
||||||
@ -139,7 +134,8 @@ protected:
|
|||||||
*/
|
*/
|
||||||
virtual void handleNonWebsocketConnection(WSclient_t * client) {
|
virtual void handleNonWebsocketConnection(WSclient_t * client) {
|
||||||
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] no Websocket connection close.\n", client->num);
|
DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] no Websocket connection close.\n", client->num);
|
||||||
client->tcp->write("HTTP/1.1 400 Bad Request\r\n"
|
client->tcp->write(
|
||||||
|
"HTTP/1.1 400 Bad Request\r\n"
|
||||||
"Server: arduino-WebSocket-Server\r\n"
|
"Server: arduino-WebSocket-Server\r\n"
|
||||||
"Content-Type: text/plain\r\n"
|
"Content-Type: text/plain\r\n"
|
||||||
"Content-Length: 32\r\n"
|
"Content-Length: 32\r\n"
|
||||||
@ -156,7 +152,8 @@ protected:
|
|||||||
* @param client WSclient_t * ptr to the client struct
|
* @param client WSclient_t * ptr to the client struct
|
||||||
*/
|
*/
|
||||||
virtual void handleAuthorizationFailed(WSclient_t * client) {
|
virtual void handleAuthorizationFailed(WSclient_t * client) {
|
||||||
client->tcp->write("HTTP/1.1 401 Unauthorized\r\n"
|
client->tcp->write(
|
||||||
|
"HTTP/1.1 401 Unauthorized\r\n"
|
||||||
"Server: arduino-WebSocket-Server\r\n"
|
"Server: arduino-WebSocket-Server\r\n"
|
||||||
"Content-Type: text/plain\r\n"
|
"Content-Type: text/plain\r\n"
|
||||||
"Content-Length: 45\r\n"
|
"Content-Length: 45\r\n"
|
||||||
@ -204,9 +201,6 @@ private:
|
|||||||
* @param headerName String ///< the name of the header being checked
|
* @param headerName String ///< the name of the header being checked
|
||||||
*/
|
*/
|
||||||
bool hasMandatoryHeader(String headerName);
|
bool hasMandatoryHeader(String headerName);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* WEBSOCKETSSERVER_H_ */
|
#endif /* WEBSOCKETSSERVER_H_ */
|
||||||
|
Reference in New Issue
Block a user