Skip to content

Commit 71d3eb4

Browse files
committed
Fix compilation error
1 parent ff3bd25 commit 71d3eb4

File tree

8 files changed

+83
-68
lines changed

8 files changed

+83
-68
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
include 'vendor/autoload.php';
4+
5+
use Hhxsv5\SSE\Event;
6+
use Hhxsv5\SSE\SSE;
7+
use Hhxsv5\SSE\StopSSEException;
8+
9+
// PHP-FPM SSE Example: push messages to client
10+
11+
header('Content-Type: text/event-stream');
12+
header('Cache-Control: no-cache');
13+
header('Connection: keep-alive');
14+
header('X-Accel-Buffering: no'); // Nginx: unbuffered responses suitable for Comet and HTTP streaming applications
15+
16+
$callback = function () {
17+
$id = mt_rand(1, 1000);
18+
$news = [['id' => $id, 'title' => 'title ' . $id, 'content' => 'content ' . $id]]; // Get news from database or service.
19+
if (empty($news)) {
20+
return false; // Return false if no new messages
21+
}
22+
$shouldStop = false; // Stop if something happens or to clear connection, browser will retry
23+
if ($shouldStop) {
24+
throw new StopSSEException();
25+
}
26+
return json_encode(compact('news'));
27+
// return ['event' => 'ping', 'data' => 'ping data']; // Custom event temporarily: send ping event
28+
// return ['id' => uniqid(), 'data' => json_encode(compact('news'))]; // Custom event Id
29+
};
30+
(new SSE(new Event($callback, 'news')))->start();
31+
?>

examples/SSE/sse.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

library.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "ESP_SSLClient",
3-
"version": "3.0.3",
2+
"name": "SerialTCPClient",
3+
"version": "3.0.4",
44
"keywords": "TLS, SSL, SecureClient, communication, HTTPS, REST, MQTT, ESP32, ESP8266, RP2040, memory-efficient",
55
"description": "A versatile and memory-optimized library providing Secure Layer Networking (SSL/TLS) TCP Client functionality. It is designed to work across a wide range of Arduino architectures (ESP32, ESP8266, RP2040, Teensy, SAMD, etc.) by wrapping standard network interfaces like WiFiClient and EthernetClient. Features include protocol upgrade (plain TCP to TLS), session caching, and memory-saving build modes.",
66
"repository": {

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name=ESP_SSLClient
22

3-
version=3.0.3
3+
version=3.0.4
44

55
author=Mobizt
66

src/ESP_SSLClient.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
#define ESP_SSLCLIENT_VERSION_MAJOR 3
1111
#define ESP_SSLCLIENT_VERSION_MINOR 0
12-
#define ESP_SSLCLIENT_VERSION_PATCH 3
13-
#define ESP_SSLCLIENT_VERSION "3.0.3"
12+
#define ESP_SSLCLIENT_VERSION_PATCH 4
13+
#define ESP_SSLCLIENT_VERSION "3.0.4"
1414

1515
#pragma GCC diagnostic ignored "-Wunused-function"
1616
#pragma GCC diagnostic ignored "-Wunused-variable"

src/bssl/bssl_config.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
#ifndef BSSL_CONFIG_H
22
#define BSSL_CONFIG_H
33

4-
54
#include <Arduino.h>
5+
6+
#if defined(__has_include)
7+
#if __has_include("./BearSSL_Config.h")
8+
#include "./BearSSL_Config.h"
9+
#if defined(BEARSSL_CONFIG_BUILD_EXTERNAL_CORE)
10+
#define BSSL_BUILD_EXTERNAL_CORE
11+
#endif
12+
#endif
13+
#endif
14+
615
// Use BearSSL engine library internal or platform (ESP8266 and RP2040)
7-
// For non ESP8266 and RP2040 devices, define BSSL_BUILD_EXTERNAL_CORE when
16+
// For non ESP8266 and RP2040 devices, define BSSL_BUILD_EXTERNAL_CORE when
817
// external BearSSL libraries are used to prevent multiple functions definitions compile error.
918
#if !defined(BSSL_BUILD_EXTERNAL_CORE)
1019

@@ -14,7 +23,7 @@
1423
#define BSSL_BUILD_INTERNAL_CORE
1524
#endif
1625

17-
// workaround when these macros
26+
// workaround when these macros
1827
// are previousely defined.
1928
#if defined(MAX)
2029
#undef MAX
@@ -24,6 +33,5 @@
2433
#undef MIN
2534
#endif
2635

27-
2836
#endif
2937
#endif

src/client/Helper.h

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
22
* This work is STL free and based on Earle F. Philhower ESP8266 WiFiClientSecure helper functions.
3-
*
3+
*
44
* SPDX-FileCopyrightText: 2025 Suwatchai K. <suwatchai@outlook.com>
55
*
66
* SPDX-License-Identifier: MIT
7-
*
7+
*
88
* Copyright (c) 2018 Earle F. Philhower, III
99
*/
1010
#ifndef BSSL_HELPER_H
@@ -89,13 +89,13 @@ namespace key_bssl
8989
};
9090

9191
// Forward definitions
92-
void free_ta_contents(br_x509_trust_anchor *ta);
93-
void free_public_key(public_key *pk);
94-
void free_private_key(private_key *sk);
95-
bool looks_like_DER(const unsigned char *buf, size_t len);
96-
pem_object *decode_pem(const void *src, size_t len, size_t *num);
97-
void free_pem_object_contents(pem_object *po);
98-
char *strdupImpl(const char *s);
92+
static void free_ta_contents(br_x509_trust_anchor *ta);
93+
static void free_public_key(public_key *pk);
94+
static void free_private_key(private_key *sk);
95+
static bool looks_like_DER(const unsigned char *buf, size_t len);
96+
static pem_object *decode_pem(const void *src, size_t len, size_t *num);
97+
static void free_pem_object_contents(pem_object *po);
98+
static char *strdupImpl(const char *s);
9999

100100
// Used as callback multiple places to append a string to a vector
101101
static void byte_vector_append(void *ctx, const void *buff, size_t len)
@@ -134,13 +134,13 @@ namespace key_bssl
134134
static bool certificate_to_trust_anchor_inner(br_x509_trust_anchor *ta, const br_x509_certificate *xc)
135135
{
136136

137-
br_x509_decoder_context *dc =reinterpret_cast<br_x509_decoder_context *>(esp_sslclient_malloc(sizeof(br_x509_decoder_context)));
137+
br_x509_decoder_context *dc = reinterpret_cast<br_x509_decoder_context *>(esp_sslclient_malloc(sizeof(br_x509_decoder_context)));
138138

139139
if (!dc)
140140
return false; // OOM check on context allocation
141141

142142
DynBuffer vdn_buffer; // Temporary buffer where the DN data is collected
143-
br_x509_pkey *pk = nullptr;
143+
br_x509_pkey *pk = nullptr;
144144
bool success = false; // Status flag
145145

146146
// Ensure Trust Anchor is clean before starting
@@ -161,7 +161,7 @@ namespace key_bssl
161161
if (pk == nullptr)
162162
{
163163
// No key present
164-
goto cleanup;
164+
goto cleanup;
165165
}
166166

167167
// Copy Parsed DN Data (Matching original STL code's logic)
@@ -172,13 +172,15 @@ namespace key_bssl
172172
if (!ta->dn.data)
173173
{
174174
// OOM on DN copy
175-
goto cleanup;
175+
goto cleanup;
176176
}
177177
memcpy(ta->dn.data, vdn_buffer.data, vdn_buffer.len);
178178
ta->dn.len = vdn_buffer.len;
179-
} else {
180-
ta->dn.data = nullptr; // Ensure null if DN is empty
181-
ta->dn.len = 0;
179+
}
180+
else
181+
{
182+
ta->dn.data = nullptr; // Ensure null if DN is empty
183+
ta->dn.len = 0;
182184
}
183185

184186
ta->flags = 0;
@@ -197,7 +199,7 @@ namespace key_bssl
197199
if ((ta->pkey.key.rsa.n == nullptr) || (ta->pkey.key.rsa.e == nullptr))
198200
{
199201
// OOM, so clean up DN data allocated above
200-
free_ta_contents(ta);
202+
free_ta_contents(ta);
201203
goto cleanup;
202204
}
203205
memcpy(ta->pkey.key.rsa.n, pk->key.rsa.n, pk->key.rsa.nlen);
@@ -215,7 +217,7 @@ namespace key_bssl
215217
if (ta->pkey.key.ec.q == nullptr)
216218
{
217219
// OOM, so clean up DN data allocated above
218-
free_ta_contents(ta);
220+
free_ta_contents(ta);
219221
goto cleanup;
220222
}
221223
memcpy(ta->pkey.key.ec.q, pk->key.ec.q, pk->key.ec.qlen);
@@ -231,12 +233,12 @@ namespace key_bssl
231233
cleanup:
232234
// Explicit cleanup of the decoder context and the temporary buffer
233235
esp_sslclient_free(&dc);
234-
free_dyn_buffer(&vdn_buffer);
235-
236+
free_dyn_buffer(&vdn_buffer);
237+
236238
return success;
237239
}
238240

239-
br_x509_trust_anchor *certificate_to_trust_anchor(const br_x509_certificate *xc)
241+
static br_x509_trust_anchor *certificate_to_trust_anchor(const br_x509_certificate *xc)
240242
{
241243
br_x509_trust_anchor *ta = reinterpret_cast<br_x509_trust_anchor *>(esp_sslclient_malloc(sizeof(br_x509_trust_anchor)));
242244
if (!ta)
@@ -250,7 +252,7 @@ namespace key_bssl
250252
return ta;
251253
}
252254

253-
void free_ta_contents(br_x509_trust_anchor *ta)
255+
static void free_ta_contents(br_x509_trust_anchor *ta)
254256
{
255257
if (ta)
256258
{
@@ -271,7 +273,7 @@ namespace key_bssl
271273
// Basically tries to verify the length of all included segments
272274
// matches the length of the input buffer. Does not actually
273275
// validate any contents.
274-
bool looks_like_DER(const unsigned char *buff, size_t len)
276+
static bool looks_like_DER(const unsigned char *buff, size_t len)
275277
{
276278
if (len < 2)
277279
return false;
@@ -303,7 +305,7 @@ namespace key_bssl
303305
}
304306
}
305307

306-
void free_pem_object_contents(pem_object *po)
308+
static void free_pem_object_contents(pem_object *po)
307309
{
308310
if (po)
309311
{
@@ -312,7 +314,7 @@ namespace key_bssl
312314
}
313315
}
314316

315-
char *strdupImpl(const char *s)
317+
static char *strdupImpl(const char *s)
316318
{
317319
size_t slen = strlen(s);
318320
char *result = reinterpret_cast<char *>(esp_sslclient_malloc(slen + 1));
@@ -351,7 +353,7 @@ namespace key_bssl
351353
// Converts a PEM (~=base64) source into a set of DER-encoded binary blobs.
352354
// Each blob is named by the ---- BEGIN xxx ---- field, and multiple
353355
// blobs may be returned.
354-
key_bssl::pem_object *decode_pem(const void *src, size_t len, size_t *num)
356+
static key_bssl::pem_object *decode_pem(const void *src, size_t len, size_t *num)
355357
{
356358
// Replace std::unique_ptr with manual pointer
357359
br_pem_decoder_context *pc = nullptr;
@@ -500,7 +502,7 @@ namespace key_bssl
500502
return nullptr;
501503
}
502504

503-
void free_certificates(br_x509_certificate *certs, size_t num)
505+
static void free_certificates(br_x509_certificate *certs, size_t num)
504506
{
505507
if (certs)
506508
{
@@ -512,7 +514,7 @@ namespace key_bssl
512514
}
513515
}
514516

515-
void free_pem_object(pem_object *pos)
517+
static void free_pem_object(pem_object *pos)
516518
{
517519
if (pos != nullptr)
518520
{
@@ -529,7 +531,7 @@ namespace key_bssl
529531
// Assuming pem_object, free_pem_object, key_bssl::free_certificates, and key_bssl::read_certificates
530532
// are defined (or used) elsewhere.
531533

532-
br_x509_certificate *read_certificates(const char *buff, size_t len, size_t *num)
534+
static br_x509_certificate *read_certificates(const char *buff, size_t len, size_t *num)
533535
{
534536
br_x509_certificate *cert_array = nullptr;
535537
size_t cert_count = 0;
@@ -740,7 +742,7 @@ namespace key_bssl
740742
return nullptr;
741743
}
742744

743-
void free_public_key(public_key *pk)
745+
static void free_public_key(public_key *pk)
744746
{
745747
if (pk)
746748
{
@@ -865,7 +867,7 @@ namespace key_bssl
865867
}
866868
return nullptr;
867869
}
868-
void free_private_key(private_key *sk)
870+
static void free_private_key(private_key *sk)
869871
{
870872
if (sk)
871873
{
@@ -889,7 +891,7 @@ namespace key_bssl
889891
}
890892
}
891893

892-
private_key *read_private_key(const char *buff, size_t len)
894+
static private_key *read_private_key(const char *buff, size_t len)
893895
{
894896
private_key *sk = nullptr;
895897
pem_object *pos = nullptr;
@@ -920,7 +922,7 @@ namespace key_bssl
920922
return nullptr;
921923
}
922924

923-
public_key *read_public_key(const char *buff, size_t len)
925+
static public_key *read_public_key(const char *buff, size_t len)
924926
{
925927
public_key *pk = nullptr;
926928
pem_object *pos = nullptr;

0 commit comments

Comments
 (0)