mirror of
https://github.com/Links2004/arduinoWebSockets.git
synced 2025-12-22 06:52:33 +01:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d0744eb5e | ||
|
|
da006ccf91 | ||
|
|
fa150b41c9 | ||
|
|
c97b15e575 | ||
|
|
84f379474d | ||
|
|
6801736f98 | ||
|
|
3af6593a00 |
@@ -62,7 +62,7 @@ jobs:
|
||||
sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }}
|
||||
|
||||
- name: Save sketches report as workflow artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v6
|
||||
with:
|
||||
if-no-files-found: error
|
||||
path: ${{ env.SKETCHES_REPORTS_PATH }}
|
||||
|
||||
@@ -74,7 +74,7 @@ jobs:
|
||||
sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }}
|
||||
|
||||
- name: Save sketches report as workflow artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v6
|
||||
with:
|
||||
if-no-files-found: error
|
||||
path: ${{ env.SKETCHES_REPORTS_PATH }}
|
||||
|
||||
@@ -53,7 +53,7 @@ jobs:
|
||||
sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }}
|
||||
|
||||
- name: Save sketches report as workflow artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v6
|
||||
with:
|
||||
if-no-files-found: error
|
||||
path: ${{ env.SKETCHES_REPORTS_PATH }}
|
||||
|
||||
4
.github/workflows/main.yml
vendored
4
.github/workflows/main.yml
vendored
@@ -69,7 +69,7 @@ jobs:
|
||||
echo "hash=$(/bin/date -u "+%Y%m%d")-$(md5sum ".github/workflows/main.yml" | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT
|
||||
shell: bash
|
||||
|
||||
- uses: actions/cache@v4
|
||||
- uses: actions/cache@v5
|
||||
id: cache_all
|
||||
with:
|
||||
path: |
|
||||
@@ -128,7 +128,7 @@ jobs:
|
||||
echo "hash=$(/bin/date -u "+%Y%m%d")-$(md5sum ".github/workflows/main.yml" | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT
|
||||
shell: bash
|
||||
|
||||
- uses: actions/cache@v4
|
||||
- uses: actions/cache@v5
|
||||
id: cache_all
|
||||
with:
|
||||
path: |
|
||||
|
||||
@@ -158,11 +158,20 @@ void WebSocketsNetworkClientSecure::setCACert(const char *rootCA) {
|
||||
Serial.println(_impl->no_interface_error_);
|
||||
}
|
||||
|
||||
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4)
|
||||
void WebSocketsNetworkClientSecure::setCACertBundle(const uint8_t *bundle,
|
||||
size_t bundle_size) {
|
||||
#else
|
||||
void WebSocketsNetworkClientSecure::setCACertBundle(const uint8_t *bundle) {
|
||||
#endif
|
||||
if (_impl->gsm_client_secure_) {
|
||||
return _impl->gsm_client_secure_->setCACertBundle(bundle);
|
||||
} else if (_impl->wifi_client_secure_) {
|
||||
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4)
|
||||
return _impl->wifi_client_secure_->setCACertBundle(bundle, bundle_size);
|
||||
#else
|
||||
return _impl->wifi_client_secure_->setCACertBundle(bundle);
|
||||
#endif
|
||||
}
|
||||
Serial.println(_impl->no_interface_error_);
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/Links2004/arduinoWebSockets.git"
|
||||
},
|
||||
"version": "2.7.0"
|
||||
"version": "2.7.2"
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
name=WebSockets
|
||||
version=2.7.0
|
||||
version=2.7.2
|
||||
author=Markus Sattler
|
||||
maintainer=Markus Sattler
|
||||
sentence=WebSockets for Arduino (Server + Client)
|
||||
|
||||
@@ -128,6 +128,12 @@ void WebSocketsClient::beginSslWithCA(const char * host, uint16_t port, const ch
|
||||
_CA_bundle = NULL;
|
||||
}
|
||||
|
||||
void WebSocketsClient::beginSslWithClientKey(const char * host, uint16_t port, const char * url, const char * CA_cert, const char * clientCert, const char * clientPrivateKey, const char * protocol) {
|
||||
_client_cert = clientCert;
|
||||
_client_key = clientPrivateKey;
|
||||
beginSslWithCA(host, port, url, CA_cert, protocol);
|
||||
}
|
||||
|
||||
#if defined(ESP32) && ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4)
|
||||
void WebSocketsClient::beginSslWithBundle(const char * host, uint16_t port, const char * url, const uint8_t * CA_bundle, size_t CA_bundle_size, const char * protocol) {
|
||||
begin(host, port, url, protocol);
|
||||
@@ -256,8 +262,15 @@ void WebSocketsClient::loop(void) {
|
||||
_client.ssl = new WEBSOCKETS_NETWORK_SSL_CLASS();
|
||||
_client.tcp = _client.ssl;
|
||||
if(_CA_cert) {
|
||||
DEBUG_WEBSOCKETS("[WS-Client] setting CA certificate");
|
||||
DEBUG_WEBSOCKETS("[WS-Client] setting CA certificate\n");
|
||||
#if defined(ESP32)
|
||||
if(_client_cert && _client_key) {
|
||||
DEBUG_WEBSOCKETS("[WS-Client] setting client certificate and private key\n");
|
||||
_client.ssl->setCertificate(_client_cert);
|
||||
_client.ssl->setPrivateKey(_client_key);
|
||||
} else {
|
||||
DEBUG_WEBSOCKETS("[WS-Client] no client certificate and/or private key set\n");
|
||||
}
|
||||
_client.ssl->setCACert(_CA_cert);
|
||||
#elif defined(ESP8266) && defined(SSL_AXTLS)
|
||||
_client.ssl->setCACert((const uint8_t *)_CA_cert, strlen(_CA_cert) + 1);
|
||||
@@ -272,7 +285,7 @@ void WebSocketsClient::loop(void) {
|
||||
#endif
|
||||
#if defined(ESP32)
|
||||
} else if(_CA_bundle) {
|
||||
DEBUG_WEBSOCKETS("[WS-Client] setting CA bundle");
|
||||
DEBUG_WEBSOCKETS("[WS-Client] setting CA bundle\n");
|
||||
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4)
|
||||
_client.ssl->setCACertBundle(_CA_bundle, _CA_bundle_size);
|
||||
#else
|
||||
@@ -287,8 +300,10 @@ void WebSocketsClient::loop(void) {
|
||||
_client.ssl->setInsecure();
|
||||
}
|
||||
if(_client_cert && _client_key) {
|
||||
DEBUG_WEBSOCKETS("[WS-Client] setting client certificate and private key\n");
|
||||
_client.ssl->setClientRSACert(_client_cert, _client_key);
|
||||
DEBUG_WEBSOCKETS("[WS-Client] setting client certificate and key");
|
||||
} else {
|
||||
DEBUG_WEBSOCKETS("[WS-Client] no client certificate and/or private key set\n");
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
@@ -478,6 +493,19 @@ bool WebSocketsClient::isConnected(void) {
|
||||
return (_client.status == WSC_CONNECTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* RFC 6455
|
||||
* get the full URL/URI of the connection
|
||||
*/
|
||||
String WebSocketsClient::getUrl(void) {
|
||||
#if defined(HAS_SSL)
|
||||
String protocol = (_client.isSSL) ? WEBSOCKETS_STRING("wss://") : WEBSOCKETS_STRING("ws://");
|
||||
#else
|
||||
String protocol = WEBSOCKETS_STRING("ws://");
|
||||
#endif
|
||||
return protocol + _host + ":" + String(_port) + _client.cUrl;
|
||||
}
|
||||
|
||||
// #################################################################################
|
||||
// #################################################################################
|
||||
// #################################################################################
|
||||
@@ -519,10 +547,11 @@ void WebSocketsClient::messageReceived(WSclient_t * client, WSopcode_t opcode, u
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect an client
|
||||
* Disconnect a client
|
||||
* @param client WSclient_t * ptr to the client struct
|
||||
* @param reason const char * disconnect reason (optional, defaults to NULL)
|
||||
*/
|
||||
void WebSocketsClient::clientDisconnect(WSclient_t * client) {
|
||||
void WebSocketsClient::clientDisconnect(WSclient_t * client, const char * reason) {
|
||||
bool event = false;
|
||||
|
||||
#ifdef HAS_SSL
|
||||
@@ -571,7 +600,11 @@ void WebSocketsClient::clientDisconnect(WSclient_t * client) {
|
||||
|
||||
DEBUG_WEBSOCKETS("[WS-Client] client disconnected.\n");
|
||||
if(event) {
|
||||
runCbEvent(WStype_DISCONNECTED, NULL, 0);
|
||||
if(reason && strlen(reason) > 0) {
|
||||
runCbEvent(WStype_DISCONNECTED, (uint8_t *)reason, strlen(reason));
|
||||
} else {
|
||||
runCbEvent(WStype_DISCONNECTED, NULL, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -594,13 +627,13 @@ bool WebSocketsClient::clientIsConnected(WSclient_t * client) {
|
||||
if(client->status != WSC_NOT_CONNECTED) {
|
||||
DEBUG_WEBSOCKETS("[WS-Client] connection lost.\n");
|
||||
// do cleanup
|
||||
clientDisconnect(client);
|
||||
clientDisconnect(client, "Connection lost");
|
||||
}
|
||||
}
|
||||
|
||||
if(client->tcp) {
|
||||
// do cleanup
|
||||
clientDisconnect(client);
|
||||
clientDisconnect(client, "TCP connection cleanup");
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -612,7 +645,7 @@ bool WebSocketsClient::clientIsConnected(WSclient_t * client) {
|
||||
void WebSocketsClient::handleClientData(void) {
|
||||
if((_client.status == WSC_HEADER || _client.status == WSC_BODY) && _lastHeaderSent + WEBSOCKETS_TCP_TIMEOUT < millis()) {
|
||||
DEBUG_WEBSOCKETS("[WS-Client][handleClientData] header response timeout.. disconnecting!\n");
|
||||
clientDisconnect(&_client);
|
||||
clientDisconnect(&_client, "Header response timeout");
|
||||
WEBSOCKETS_YIELD();
|
||||
return;
|
||||
}
|
||||
@@ -847,7 +880,9 @@ void WebSocketsClient::handleHeader(WSclient_t * client, String * headerLine) {
|
||||
default: ///< Server dont unterstand requrst
|
||||
ok = false;
|
||||
DEBUG_WEBSOCKETS("[WS-Client][handleHeader] serverCode is not 101 (%d)\n", client->cCode);
|
||||
clientDisconnect(client);
|
||||
// Create disconnect reason with HTTP status code
|
||||
String reason = "HTTP " + String(client->cCode);
|
||||
clientDisconnect(client, reason.c_str());
|
||||
_lastConnectionFail = millis();
|
||||
break;
|
||||
}
|
||||
@@ -891,7 +926,11 @@ void WebSocketsClient::handleHeader(WSclient_t * client, String * headerLine) {
|
||||
if(clientIsConnected(client)) {
|
||||
write(client, "This is a webSocket client!");
|
||||
}
|
||||
clientDisconnect(client);
|
||||
String reason = "WebSocket handshake failed";
|
||||
if(client->cCode > 0) {
|
||||
reason += " - HTTP " + String(client->cCode);
|
||||
}
|
||||
clientDisconnect(client, reason.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ class WebSocketsClient : protected WebSockets {
|
||||
void setSSLClientCertKey(const char * clientCert = NULL, const char * clientPrivateKey = NULL);
|
||||
#endif
|
||||
void beginSslWithCA(const char * host, uint16_t port, const char * url = "/", const char * CA_cert = NULL, const char * protocol = "arduino");
|
||||
void beginSslWithClientKey(const char * host, uint16_t port, const char * url, const char * CA_cert, const char * clientCert, const char * clientPrivateKey, const char * protocol = "arduino");
|
||||
#ifdef ESP32
|
||||
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4)
|
||||
void beginSslWithBundle(const char * host, uint16_t port, const char * url = "/", const uint8_t * CA_bundle = NULL, size_t CA_bundle_size = 0, const char * protocol = "arduino");
|
||||
@@ -112,6 +113,7 @@ class WebSocketsClient : protected WebSockets {
|
||||
void disableHeartbeat();
|
||||
|
||||
bool isConnected(void);
|
||||
String getUrl(void);
|
||||
|
||||
protected:
|
||||
String _host;
|
||||
@@ -122,6 +124,8 @@ class WebSocketsClient : protected WebSockets {
|
||||
String _fingerprint;
|
||||
const char * _CA_cert;
|
||||
const uint8_t * _CA_bundle;
|
||||
const char * _client_cert;
|
||||
const char * _client_key;
|
||||
#if defined(ESP32)
|
||||
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4)
|
||||
size_t _CA_bundle_size;
|
||||
@@ -156,7 +160,10 @@ class WebSocketsClient : protected WebSockets {
|
||||
|
||||
void messageReceived(WSclient_t * client, WSopcode_t opcode, uint8_t * payload, size_t length, bool fin);
|
||||
|
||||
void clientDisconnect(WSclient_t * client);
|
||||
void clientDisconnect(WSclient_t * client) {
|
||||
clientDisconnect(client, NULL);
|
||||
}
|
||||
void clientDisconnect(WSclient_t * client, const char * reason = NULL);
|
||||
bool clientIsConnected(WSclient_t * client);
|
||||
|
||||
#if (WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC)
|
||||
|
||||
@@ -24,7 +24,11 @@ class WebSocketsNetworkClientSecure : public WebSocketsNetworkClient {
|
||||
operator bool() override;
|
||||
|
||||
void setCACert(const char * rootCA);
|
||||
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4)
|
||||
void setCACertBundle(const uint8_t * bundle, size_t bundle_size);
|
||||
#else
|
||||
void setCACertBundle(const uint8_t * bundle);
|
||||
#endif
|
||||
void setInsecure();
|
||||
bool verify(const char * fingerprint, const char * domain_name);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file WebSocketsVersion.h
|
||||
* @date 13.08.2025
|
||||
* @date 20.12.2025
|
||||
* @author Markus Sattler
|
||||
*
|
||||
* Copyright (c) 2015 Markus Sattler. All rights reserved.
|
||||
@@ -25,12 +25,12 @@
|
||||
#ifndef WEBSOCKETSVERSION_H_
|
||||
#define WEBSOCKETSVERSION_H_
|
||||
|
||||
#define WEBSOCKETS_VERSION "2.7.0"
|
||||
#define WEBSOCKETS_VERSION "2.7.2"
|
||||
|
||||
#define WEBSOCKETS_VERSION_MAJOR 2
|
||||
#define WEBSOCKETS_VERSION_MINOR 7
|
||||
#define WEBSOCKETS_VERSION_PATCH 0
|
||||
#define WEBSOCKETS_VERSION_PATCH 2
|
||||
|
||||
#define WEBSOCKETS_VERSION_INT 2007000
|
||||
#define WEBSOCKETS_VERSION_INT 2007002
|
||||
|
||||
#endif /* WEBSOCKETSVERSION_H_ */
|
||||
|
||||
Reference in New Issue
Block a user