From 6833aabe74aa050b49b4245e7fede110f7d3ed45 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 9 Jun 2024 18:29:43 +0700 Subject: [PATCH] Fix minor issue and update the Realtime database simple examples --- FAQ.md | 4 +- README.md | 4 +- .../SimpleDatabaseSecret.ino | 36 +++++++++++- .../Simple/SimpleNoAuth/SimpleNoAuth.ino | 37 ++++++++++-- .../StreamDatabaseSecret.ino | 56 +++++++++++++++--- .../Simple/StreamNoAuth/StreamNoAuth.ino | 58 ++++++++++++++++--- library.json | 2 +- library.properties | 2 +- src/FirebaseClient.h | 1 - src/client/SSLClient/ESP_SSLClient.h | 4 +- .../SSLClient/client/BSSL_SSL_Client.cpp | 14 ++--- src/client/SSLClient/client/BSSL_SSL_Client.h | 7 ++- .../SSLClient/client/BSSL_TCP_Client.cpp | 24 ++++---- src/client/SSLClient/client/BSSL_TCP_Client.h | 8 +-- src/core/AsyncClient/AsyncClient.h | 12 ++-- src/core/Core.h | 2 +- src/core/FileConfig.h | 11 +++- src/core/FirebaseApp.h | 17 +++--- src/core/JWT.cpp | 11 ++-- src/core/NetConfig.h | 4 +- 20 files changed, 231 insertions(+), 83 deletions(-) diff --git a/FAQ.md b/FAQ.md index f0270c23..67f76c8d 100644 --- a/FAQ.md +++ b/FAQ.md @@ -1,5 +1,5 @@ -Revision `2024-06-07T05:35:03Z` +Revision `2024-06-09T07:13:35Z` # Async Firebase Client library for Arduino Frequently Asked Questions. @@ -343,7 +343,7 @@ For running more tasks concurrency, see [Running Many Tasks Concurrency Using Di #### A29: Please see, [Possible GSM issues](#possible-gsm-issues). ### Q30: How to stop the authentication task? -#### A30: Normally the authentication task was unable to stop after initialize unless it can deinitialize. +#### A30: Normally the authentication task was unable to stop after initialized unless it can deinitialize. You can use `deinitializeApp()` to deinitalize the `FirebaseApp` that was initialized. diff --git a/README.md b/README.md index 7704b88b..9e01e215 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/mobizt/FirebaseClient/.github%2Fworkflows%2Fcompile_library.yml?logo=github&label=compile) [![Github Stars](https://img.shields.io/github/stars/mobizt/FirebaseClient?logo=github)](https://github.com/mobizt/FirebaseClient/stargazers) ![Github Issues](https://img.shields.io/github/issues/mobizt/FirebaseClient?logo=github) -![GitHub Release](https://img.shields.io/github/v/release/mobizt/FirebaseClient) ![Arduino](https://img.shields.io/badge/Arduino-v1.2.11-57C207?logo=arduino) ![PlatformIO](https://badges.registry.platformio.org/packages/mobizt/library/FirebaseClient.svg) ![GitHub Release Date](https://img.shields.io/github/release-date/mobizt/FirebaseClient) +![GitHub Release](https://img.shields.io/github/v/release/mobizt/FirebaseClient) ![Arduino](https://img.shields.io/badge/Arduino-v1.2.12-57C207?logo=arduino) ![PlatformIO](https://badges.registry.platformio.org/packages/mobizt/library/FirebaseClient.svg) ![GitHub Release Date](https://img.shields.io/github/release-date/mobizt/FirebaseClient) [![GitHub Sponsors](https://img.shields.io/github/sponsors/mobizt?logo=github)](https://github.com/sponsors/mobizt) -Revision `2024-06-07T06:05:58Z` +Revision `2024-06-09T07:13:35Z` ## Table of Contents diff --git a/examples/RealtimeDatabase/Simple/SimpleDatabaseSecret/SimpleDatabaseSecret.ino b/examples/RealtimeDatabase/Simple/SimpleDatabaseSecret/SimpleDatabaseSecret.ino index 439d81fe..1cc0b459 100644 --- a/examples/RealtimeDatabase/Simple/SimpleDatabaseSecret/SimpleDatabaseSecret.ino +++ b/examples/RealtimeDatabase/Simple/SimpleDatabaseSecret/SimpleDatabaseSecret.ino @@ -1,5 +1,23 @@ +/** + * This example is for new users which are familiar with other legacy Firebase libraries. + * + * The example shows how to set, push and get the values to/from Realtime database. + * + * This example will not use any authentication method included database secret. + * + * It needs to change the security rules to allow read and write. + * + * This example is for ESP32, ESP8266 and Raspberry Pi Pico W. + * + * You can adapt the WiFi and SSL client library that are available for your devices. + * + * For the ethernet and GSM network which are not covered by this example, + * you have to try another elaborate examples and read the library documentation thoroughly. + * + */ + #include -#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) || defined(ARDUINO_GIGA) +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) #include #elif defined(ESP8266) #include @@ -52,16 +70,23 @@ void setup() ssl.setBufferSizes(1024, 1024); #endif + // Initialize the authentication handler. initializeApp(client, app, getAuth(dbSecret)); - // Binding the FirebaseApp for authentication handler. - // To unbind, use Database.resetApp(); + // Binding the authentication handler with your Database class object. app.getApp(Database); + // Set your database URL Database.url(DATABASE_URL); + // Set the operating result for the the following blocking (sync) functions. + // The result will keep in the async result object we set to the client. client.setAsyncResult(result); + // The following are blocking operations which the result will store in the result object we set above. + + // In the another Stream examples, we will use the non-blocking (async) functions to allow the realtime incoming data. + // Set, push and get integer value Serial.print("Set int... "); @@ -217,4 +242,9 @@ void setup() void loop() { + // We don't need to poll the async task using Database.loop(); as in the Stream examples because + // only blocking (sync) functions were used in this example. + + // We don't have to poll authentication handler task using app.loop() as seen in other examples + // because the database secret is the priviledge access key that never expired. } \ No newline at end of file diff --git a/examples/RealtimeDatabase/Simple/SimpleNoAuth/SimpleNoAuth.ino b/examples/RealtimeDatabase/Simple/SimpleNoAuth/SimpleNoAuth.ino index 8b3cbebd..fe7940cd 100644 --- a/examples/RealtimeDatabase/Simple/SimpleNoAuth/SimpleNoAuth.ino +++ b/examples/RealtimeDatabase/Simple/SimpleNoAuth/SimpleNoAuth.ino @@ -1,4 +1,21 @@ -/** This example requires the Realtime database security rules setup as following. +/** + * This example is for new users which are familiar with other legacy Firebase libraries. + * + * The example shows how to set, push and get the values to/from Realtime database. + * + * This example will use the database secret for priviledge Realtime database access which does not need + * to change the security rules or it can access Realtime database no matter what the security rules are set. + * + * This example is for ESP32, ESP8266 and Raspberry Pi Pico W. + * + * You can adapt the WiFi and SSL client library that are available for your devices. + * + * For the ethernet and GSM network which are not covered by this example, + * you have to try another elaborate examples and read the library documentation thoroughly. + * + */ + +/** Change your Realtime database security rules as the following. { "rules": { ".read": true, @@ -8,7 +25,7 @@ */ #include -#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) || defined(ARDUINO_GIGA) +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) #include #elif defined(ESP8266) #include @@ -60,16 +77,23 @@ void setup() ssl.setBufferSizes(1024, 1024); #endif + // Initialize the authentication handler. initializeApp(client, app, getAuth(noAuth)); - // Binding the FirebaseApp for authentication handler. - // To unbind, use Database.resetApp(); + // Binding the authentication handler with your Database class object. app.getApp(Database); + // Set your database URL Database.url(DATABASE_URL); + // Set the operating result for the the following blocking (sync) functions. + // The result will keep in the async result object we set to the client. client.setAsyncResult(result); + // The following are blocking operations which the result will store in the result object we set above. + + // In the another Stream examples, we will use the non-blocking (async) functions to allow the realtime incoming data. + // Set, push and get integer value Serial.print("Set int... "); @@ -225,4 +249,9 @@ void setup() void loop() { + // We don't need to poll the async task using Database.loop(); as in the Stream examples because + // only blocking (sync) functions were used in this example. + + // We don't have to poll authentication handler task using app.loop() as seen in other examples + // because the database secret is the priviledge access key that never expired. } \ No newline at end of file diff --git a/examples/RealtimeDatabase/Simple/StreamDatabaseSecret/StreamDatabaseSecret.ino b/examples/RealtimeDatabase/Simple/StreamDatabaseSecret/StreamDatabaseSecret.ino index 337320e4..cacd65b0 100644 --- a/examples/RealtimeDatabase/Simple/StreamDatabaseSecret/StreamDatabaseSecret.ino +++ b/examples/RealtimeDatabase/Simple/StreamDatabaseSecret/StreamDatabaseSecret.ino @@ -1,5 +1,23 @@ +/** + * This example is for new users which are familiar with other legacy Firebase libraries. + * + * The example shows how to listen the data changes in your Firebase Realtime database + * while the database was set periodically. + * + * This example will use the database secret for priviledge Realtime database access which does not need + * to change the security rules or it can access Realtime database no matter what the security rules are set. + * + * This example is for ESP32, ESP8266 and Raspberry Pi Pico W. + * + * You can adapt the WiFi and SSL client library that are available for your devices. + * + * For the ethernet and GSM network which are not covered by this example, + * you have to try another elaborate examples and read the library documentation thoroughly. + * + */ + #include -#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) || defined(ARDUINO_GIGA) +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) #include #elif defined(ESP8266) #include @@ -14,13 +32,25 @@ #define DATABASE_SECRET "DATABASE_SECRET" #define DATABASE_URL "URL" +// The SSL client used for secure server connection. WiFiClientSecure ssl1, ssl2; + +// The default network config object that used in this library. DefaultNetwork network; + +// The client, aka async client, is the client that handles many tasks required for each operation. AsyncClientClass client1(ssl1, getNetwork(network)), client2(ssl2, getNetwork(network)); +// The authentication task handler, aka FirebaseApp. FirebaseApp app; + +// The Realtime database class object that provides the functions. RealtimeDatabase Database; + +// The class that stores the operating result, aka AsyncResult. AsyncResult result1, result2; + +// The legacy token provider class used for authentication initialization. LegacyToken dbSecret(DATABASE_SECRET); unsigned long ms = 0; @@ -91,30 +121,40 @@ void setup() ssl2.setBufferSizes(1024, 1024); #endif + // Initialize the authentication handler. initializeApp(client1, app, getAuth(dbSecret)); - // Binding the FirebaseApp for authentication handler. - // To unbind, use Database.resetApp(); + // Binding the authentication handler with your Database class object. app.getApp(Database); + // Set your database URL Database.url(DATABASE_URL); - client1.setAsyncResult(result1); - client2.setAsyncResult(result2); - - Database.get(client1, "/test/stream", result1, true); + // Initiate the Stream connection to listen the data changes. + // This function can be called once. + // The Stream was connected using async get function (non-blocking) which the result was assign to the function. + Database.get(client1, "/test/stream", result1, true /* this option is for Stream connection */); } void loop() { + // Polling for internal task operation + // This required for Stream in this case. Database.loop(); + // We don't have to poll authentication handler task using app.loop() as seen in other examples + // because the database secret is the priviledge access key that never expired. + + // Set the random int value to "/test/stream/int" every 20 seconds. if (millis() - ms > 20000 || ms == 0) { ms = millis(); - Database.set(client2, "/test/stream/ts", random(100, 999), result2); + + // We set the data with this non-blocking set function (async) which the result was assign to the function. + Database.set(client2, "/test/stream/int", random(100, 999), result2); } + // Polling print the result if it is available. printResult(result1); printResult(result2); } \ No newline at end of file diff --git a/examples/RealtimeDatabase/Simple/StreamNoAuth/StreamNoAuth.ino b/examples/RealtimeDatabase/Simple/StreamNoAuth/StreamNoAuth.ino index f503d8e0..1bcaa091 100644 --- a/examples/RealtimeDatabase/Simple/StreamNoAuth/StreamNoAuth.ino +++ b/examples/RealtimeDatabase/Simple/StreamNoAuth/StreamNoAuth.ino @@ -1,4 +1,23 @@ -/** This example requires the Realtime database security rules setup as following. +/** + * This example is for new users which are familiar with other legacy Firebase libraries. + * + * The example shows how to listen the data changes in your Firebase Realtime database + * while the database was set periodically. + * + * This example will not use any authentication method included database secret. + * + * It needs to change the security rules to allow read and write. + * + * This example is for ESP32, ESP8266 and Raspberry Pi Pico W. + * + * You can adapt the WiFi and SSL client library that are available for your devices. + * + * For the ethernet and GSM network which are not covered by this example, + * you have to try another elaborate examples and read the library documentation thoroughly. + * + */ + +/** Change your Realtime database security rules as the following. { "rules": { ".read": true, @@ -8,7 +27,7 @@ */ #include -#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) || defined(ARDUINO_GIGA) +#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) #include #elif defined(ESP8266) #include @@ -23,13 +42,25 @@ #define DATABASE_SECRET "DATABASE_SECRET" #define DATABASE_URL "URL" +// The SSL client used for secure server connection. WiFiClientSecure ssl1, ssl2; + +// The default network config object that used in this library. DefaultNetwork network; + +// The client, aka async client, is the client that handles many tasks required for each operation. AsyncClientClass client1(ssl1, getNetwork(network)), client2(ssl2, getNetwork(network)); +// The authentication task handler, aka FirebaseApp. FirebaseApp app; + +// The Realtime database class object that provides the functions. RealtimeDatabase Database; + +// The class that stores the operating result, aka AsyncResult. AsyncResult result1, result2; + +// The no-authentication provider class used for authentication initialization. NoAuth noAuth; unsigned long ms = 0; @@ -100,30 +131,39 @@ void setup() ssl2.setBufferSizes(1024, 1024); #endif + // Initialize the authentication handler. initializeApp(client1, app, getAuth(noAuth)); - // Binding the FirebaseApp for authentication handler. - // To unbind, use Database.resetApp(); + // Binding the authentication handler with your Database class object. app.getApp(Database); + // Set your database URL Database.url(DATABASE_URL); - client1.setAsyncResult(result1); - client2.setAsyncResult(result2); - - Database.get(client1, "/test/stream", result1, true); + // Initiate the Stream connection to listen the data changes. + // This function can be called once. + // The Stream was connected using async get function (non-blocking) which the result was assign to the function. + Database.get(client1, "/test/stream", result1, true /* this option is for Stream connection */); } void loop() { + // Polling for internal task operation + // This required for Stream in this case. Database.loop(); + // We don't have to poll authentication handler task using app.loop() as seen in other examples + // because the database secret is the priviledge access key that never expired. + + // Set the random int value to "/test/stream/int" every 20 seconds. if (millis() - ms > 20000 || ms == 0) { ms = millis(); - Database.set(client2, "/test/stream/ts", random(100, 999), result2); + // We set the data with this non-blocking set function (async) which the result was assign to the function. + Database.set(client2, "/test/stream/int", random(100, 999), result2); } + // Polling print the result if it is available. printResult(result1); printResult(result2); } \ No newline at end of file diff --git a/library.json b/library.json index 9dade154..f8a67d7b 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "FirebaseClient", - "version": "1.2.11", + "version": "1.2.12", "keywords": "communication, REST, esp32, esp8266, arduino", "description": "Async Firebase Client library for Arduino.", "repository": { diff --git a/library.properties b/library.properties index 6a788a79..a2261683 100644 --- a/library.properties +++ b/library.properties @@ -1,6 +1,6 @@ name=FirebaseClient -version=1.2.11 +version=1.2.12 author=Mobizt diff --git a/src/FirebaseClient.h b/src/FirebaseClient.h index 15479448..e8520222 100644 --- a/src/FirebaseClient.h +++ b/src/FirebaseClient.h @@ -147,7 +147,6 @@ namespace firebase #if defined(ENABLE_ID_TOKEN) app.auth_data.app_token.expire = app.expire; - app.auth_data.user_auth.user.val[user_ns::api_key] = app.auth_data.user_auth.user.val[user_ns::api_key]; app.auth_data.app_token.val[app_tk_ns::token] = app.auth_data.user_auth.id_token.val[id_tk_ns::token]; app.auth_data.app_token.val[app_tk_ns::refresh] = app.auth_data.user_auth.id_token.val[id_tk_ns::refresh]; app.auth_data.app_token.authenticated = app.auth_data.user_auth.id_token.val[id_tk_ns::token].length() ? app.auth_data.user_auth.initialized : false; diff --git a/src/client/SSLClient/ESP_SSLClient.h b/src/client/SSLClient/ESP_SSLClient.h index 58ae1d40..aad71b0c 100644 --- a/src/client/SSLClient/ESP_SSLClient.h +++ b/src/client/SSLClient/ESP_SSLClient.h @@ -1,8 +1,8 @@ /** * - * The ESP SSL Client Class, ESP_SSLClient.h v2.1.7 + * The ESP SSL Client Class, ESP_SSLClient.h v2.1.8 * - * Created September 2, 2023 + * Created June 9, 2024 * * The MIT License (MIT) * Copyright (c) 2023 K. Suwatchai (Mobizt) diff --git a/src/client/SSLClient/client/BSSL_SSL_Client.cpp b/src/client/SSLClient/client/BSSL_SSL_Client.cpp index 2d976292..32962ac4 100644 --- a/src/client/SSLClient/client/BSSL_SSL_Client.cpp +++ b/src/client/SSLClient/client/BSSL_SSL_Client.cpp @@ -1,7 +1,7 @@ /** - * BSSL_SSL_Client library v1.0.12 for Arduino devices. + * BSSL_SSL_Client library v1.0.13 for Arduino devices. * - * Created September 2, 2003 + * Created June 9, 2024 * * This work contains codes based on WiFiClientSecure from Earle F. Philhower and SSLClient from OSU OPEnS Lab. * @@ -493,7 +493,7 @@ void BSSL_SSL_Client::stop() mFreeSSL(); } -void BSSL_SSL_Client::setTimeout(unsigned int timeoutMs) { _timeout = timeoutMs; } +void BSSL_SSL_Client::setTimeout(unsigned int timeoutMs) { _timeout_ms = timeoutMs; } void BSSL_SSL_Client::setHandshakeTimeout(unsigned int timeoutMs) { _handshake_timeout = timeoutMs; } @@ -1089,7 +1089,7 @@ BSSL_SSL_Client &BSSL_SSL_Client::operator=(const BSSL_SSL_Client &other) stop(); setClient(other._basic_client); _use_insecure = other._use_insecure; - _timeout = other._timeout; + _timeout_ms = other._timeout_ms; _handshake_timeout = other._handshake_timeout; return *this; } @@ -1099,7 +1099,7 @@ bool BSSL_SSL_Client::operator==(const BSSL_SSL_Client &rhs) return _basic_client == rhs._basic_client; } -unsigned int BSSL_SSL_Client::getTimeout() const { return _timeout; } +unsigned int BSSL_SSL_Client::getTimeout() const { return _timeout_ms; } void BSSL_SSL_Client::setSecure(const char *rootCABuff, const char *cli_cert, const char *cli_key) { @@ -1982,7 +1982,7 @@ void BSSL_SSL_Client::mClearAuthenticationSettings() void BSSL_SSL_Client::mClear() { - _timeout = 15000; + _timeout_ms = 15000; _sc = nullptr; _eng = nullptr; _x509_minimal = nullptr; @@ -2116,7 +2116,7 @@ void BSSL_SSL_Client::mFreeSSL() _recvapp_len = 0; // This connection is toast _handshake_done = false; - _timeout = 15000; + _timeout_ms = 15000; _secure = false; _is_connected = false; } diff --git a/src/client/SSLClient/client/BSSL_SSL_Client.h b/src/client/SSLClient/client/BSSL_SSL_Client.h index 5196de1d..af49d5c0 100644 --- a/src/client/SSLClient/client/BSSL_SSL_Client.h +++ b/src/client/SSLClient/client/BSSL_SSL_Client.h @@ -1,7 +1,7 @@ /** - * BSSL_SSL_Client library v1.0.12 for Arduino devices. + * BSSL_SSL_Client library v1.0.13 for Arduino devices. * - * Created September 2, 2003 + * Created June 9, 2024 * * This work contains codes based on WiFiClientSecure from Earle F. Philhower and SSLClient from OSU OPEnS Lab. * @@ -336,7 +336,8 @@ class BSSL_SSL_Client : public Client bool _oom_err = false; unsigned char *_recvapp_buf = nullptr; size_t _recvapp_len; - unsigned long _timeout = 15000; + // Renameing from _timeout which also defined in parent's Stream class. + unsigned long _timeout_ms = 15000; unsigned long _handshake_timeout = 60000; bool _isSSLEnabled = false; String _host; diff --git a/src/client/SSLClient/client/BSSL_TCP_Client.cpp b/src/client/SSLClient/client/BSSL_TCP_Client.cpp index f9f90075..87def837 100644 --- a/src/client/SSLClient/client/BSSL_TCP_Client.cpp +++ b/src/client/SSLClient/client/BSSL_TCP_Client.cpp @@ -1,7 +1,7 @@ /** - * BSSL_TCP_Client v2.0.12 for Arduino devices. + * BSSL_TCP_Client v2.0.13 for Arduino devices. * - * Created August 27, 2023 + * Created June 9, 2024 * * The MIT License (MIT) * Copyright (c) 2023 K. Suwatchai (Mobizt) @@ -98,10 +98,10 @@ int BSSL_TCP_Client::connect(IPAddress ip, uint16_t port, int32_t timeout) if (timeout > 0) { - _timeout = timeout; + _timeout_ms = timeout; if (_basic_client) - _basic_client->setTimeout(_timeout); - _ssl_client.setTimeout(_timeout); + _basic_client->setTimeout(_timeout_ms); + _ssl_client.setTimeout(_timeout_ms); } return _ssl_client.connect(ip, port); @@ -120,10 +120,10 @@ int BSSL_TCP_Client::connect(const char *host, uint16_t port, int32_t timeout) if (timeout > 0) { - _timeout = timeout; + _timeout_ms = timeout; if (_basic_client) - _basic_client->setTimeout(_timeout); - _ssl_client.setTimeout(_timeout); + _basic_client->setTimeout(_timeout_ms); + _ssl_client.setTimeout(_timeout_ms); } return _ssl_client.connect(host, port); @@ -267,8 +267,8 @@ void BSSL_TCP_Client::stop() int BSSL_TCP_Client::setTimeout(uint32_t seconds) { - _timeout = seconds * 1000; - _ssl_client.setTimeout(_timeout); + _timeout_ms = seconds * 1000; + _ssl_client.setTimeout(_timeout_ms); return 1; } @@ -425,9 +425,9 @@ BSSL_TCP_Client &BSSL_TCP_Client::operator=(const BSSL_TCP_Client &other) stop(); setClient(other._basic_client); _use_insecure = other._use_insecure; - _timeout = other._timeout; + _timeout_ms = other._timeout_ms; _handshake_timeout = other._handshake_timeout; - _ssl_client.setTimeout(_timeout); + _ssl_client.setTimeout(_timeout_ms); _ssl_client.setHandshakeTimeout(_handshake_timeout); if (_use_insecure) _ssl_client.setInsecure(); diff --git a/src/client/SSLClient/client/BSSL_TCP_Client.h b/src/client/SSLClient/client/BSSL_TCP_Client.h index f70dbddf..72fedbc5 100644 --- a/src/client/SSLClient/client/BSSL_TCP_Client.h +++ b/src/client/SSLClient/client/BSSL_TCP_Client.h @@ -1,7 +1,7 @@ /** - * BSSL_TCP_Client v2.0.12 for Arduino devices. + * BSSL_TCP_Client v2.0.13 for Arduino devices. * - * Created August 27, 2023 + * Created June 9, 2024 * * The MIT License (MIT) * Copyright (c) 2023 K. Suwatchai (Mobizt) @@ -66,7 +66,6 @@ class BSSL_TCP_Client : public Client bool _use_insecure; public: - BSSL_TCP_Client *next; // The default class constructor BSSL_TCP_Client(); @@ -426,7 +425,8 @@ class BSSL_TCP_Client : public Client uint16_t _port; BSSL_SSL_Client _ssl_client; Client *_basic_client = nullptr; - unsigned long _timeout = 15000; + // Renameing from _timeout which also defined in parent's Stream class. + unsigned long _timeout_ms = 15000; unsigned long _handshake_timeout = 60000; char *mStreamLoad(Stream &stream, size_t size); diff --git a/src/core/AsyncClient/AsyncClient.h b/src/core/AsyncClient/AsyncClient.h index d312f05c..7d5840ef 100644 --- a/src/core/AsyncClient/AsyncClient.h +++ b/src/core/AsyncClient/AsyncClient.h @@ -256,7 +256,7 @@ class AsyncClientClass : public ResultBase, RTDBResultBase if (!sData || ret == function_return_type_failure) { // In case TCP (network) disconnected error. - setAsyncError(sData, sData->state, FIREBASE_ERROR_TCP_DISCONNECTED, !sData->sse, false); + setAsyncError(sData ? sData : nullptr, sData ? sData->state : async_state_undefined, FIREBASE_ERROR_TCP_DISCONNECTED, sData ? !sData->sse : true, false); return function_return_type_failure; } @@ -673,6 +673,9 @@ class AsyncClientClass : public ResultBase, RTDBResultBase void setAsyncError(async_data_item_t *sData, async_state state, int code, bool toRemove, bool toCloseFile) { + if (!sData) + return; + sData->error.state = state; sData->error.code = code; @@ -777,7 +780,7 @@ class AsyncClientClass : public ResultBase, RTDBResultBase void setLastError(async_data_item_t *sData) { - if (sData->error.code < 0) + if (sData && sData->error.code < 0) { sData->aResult.lastError.setClientError(sData->error.code); lastErr.setClientError(sData->error.code); @@ -787,7 +790,7 @@ class AsyncClientClass : public ResultBase, RTDBResultBase if (!sData->async) lastErr.isError(); } - else if (sData->response.httpCode > 0 && sData->response.httpCode >= FIREBASE_ERROR_HTTP_CODE_BAD_REQUEST) + else if (sData && sData->response.httpCode > 0 && sData->response.httpCode >= FIREBASE_ERROR_HTTP_CODE_BAD_REQUEST) { sData->aResult.lastError.setResponseError(sData->response.val[res_hndlr_ns::payload], sData->response.httpCode); lastErr.setResponseError(sData->response.val[res_hndlr_ns::payload], sData->response.httpCode); @@ -2044,9 +2047,8 @@ class AsyncClientClass : public ResultBase, RTDBResultBase sData->request.addNewLine(); } - // sData->request.val[req_hndlr_ns::header] += FPSTR("Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0"); - // sData->request.addNewLine(); sData->request.addConnectionHeader(true); + if (!options.sv && !options.no_etag && method != async_request_handler_t::http_patch && extras.indexOf("orderBy") == -1) { sData->request.val[req_hndlr_ns::header] += FPSTR("X-Firebase-ETag: true"); diff --git a/src/core/Core.h b/src/core/Core.h index b7c92678..06c17f3c 100644 --- a/src/core/Core.h +++ b/src/core/Core.h @@ -7,7 +7,7 @@ #undef FIREBASE_CLIENT_VERSION #endif -#define FIREBASE_CLIENT_VERSION "1.2.11" +#define FIREBASE_CLIENT_VERSION "1.2.12" static void sys_idle() { diff --git a/src/core/FileConfig.h b/src/core/FileConfig.h index 9ed1c0d0..1cf9f15d 100644 --- a/src/core/FileConfig.h +++ b/src/core/FileConfig.h @@ -1,5 +1,5 @@ /** - * Created May 29, 2024 + * Created June 9, 2024 * * The MIT License (MIT) * Copyright (c) 2024 K. Suwatchai (Mobizt) @@ -409,18 +409,23 @@ struct file_config_data } public: - file_config_data &operator=(file_config_data rhs) + file_config_data &operator=(file_config_data &rhs) { copy(rhs); return *this; } - void copy(file_config_data rhs) + void copy(file_config_data &rhs) { #if defined(ENABLE_FS) this->file = rhs.file; #endif this->filename = rhs.filename; + this->file_size = rhs.file_size; + this->file_status = rhs.file_status; + this->data_pos = rhs.data_pos; + this->data_size = rhs.data_size; + this->data = rhs.data; #if defined(ENABLE_FS) this->cb = rhs.cb; #endif diff --git a/src/core/FirebaseApp.h b/src/core/FirebaseApp.h index 2794e93f..3bbd0219 100644 --- a/src/core/FirebaseApp.h +++ b/src/core/FirebaseApp.h @@ -236,6 +236,7 @@ namespace firebase { // If aResult was not initiated, create and send temporary result to callback bool isRes = aResult != nullptr; + AsyncResult *ares = aResult; // Set uid from user defined async result. if (getRefResult()) @@ -243,15 +244,15 @@ namespace firebase if (!isRes) { - aResult = new AsyncResult(); - resultSetEvent(aResult, getAppEvent(aClient)); - resultSetDebug(aResult, getAppDebug(aClient)); + ares = new AsyncResult(); + resultSetEvent(ares, getAppEvent(aClient)); + resultSetDebug(ares, getAppDebug(aClient)); // Store the uid; if (uid.length() == 0) - uid = aResult->uid(); + uid = ares->uid(); else - setResultUID(aResult, uid); + setResultUID(ares, uid); } if (!getRefResult()) @@ -260,12 +261,12 @@ namespace firebase setEventBase(*getAppEvent(aClient), code, msg); if (resultCb) - resultCb(*aResult); + resultCb(*ares); if (!isRes) { - delete aResult; - aResult = nullptr; + delete ares; + ares = nullptr; } } diff --git a/src/core/JWT.cpp b/src/core/JWT.cpp index 8ac6612c..5a69361d 100644 --- a/src/core/JWT.cpp +++ b/src/core/JWT.cpp @@ -110,14 +110,15 @@ void JWTClass::sendErrCB(AsyncResultCallback cb, AsyncResult *aResult) { err_timer.feed(5); bool hasRes = aResult != nullptr; + AsyncResult *ares = aResult; if (!hasRes) - aResult = new AsyncResult(); - aResult->error().setLastError(jwt_data.err_code, jwt_data.msg); - cb(*aResult); + ares = new AsyncResult(); + ares->error().setLastError(jwt_data.err_code, jwt_data.msg); + cb(*ares); if (!hasRes) { - delete aResult; - aResult = nullptr; + delete ares; + ares = nullptr; } } } diff --git a/src/core/NetConfig.h b/src/core/NetConfig.h index 4557ed4d..e3a5b224 100644 --- a/src/core/NetConfig.h +++ b/src/core/NetConfig.h @@ -1,5 +1,5 @@ /** - * Created May 29, 2024 + * Created June 9, 2024 * * The MIT License (MIT) * Copyright (c) 2024 K. Suwatchai (Mobizt) @@ -159,7 +159,7 @@ struct network_config_data public: ~network_config_data() { clear(); } - network_config_data &operator=(network_config_data rhs) + network_config_data &operator=(network_config_data &rhs) { copy(rhs); return *this;