diff --git a/README.md b/README.md index 80ba67b33..376cf2d60 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Firebase Arduino Client Library for ESP8266 and ESP32 -Google's Firebase Arduino Client Library for ESP8266 and ESP32 v3.1.2 +Google's Firebase Arduino Client Library for ESP8266 and ESP32 v3.1.3 This library supports ESP8266 and ESP32 MCU from Espressif. The following are platforms in which the libraries are also available (RTDB only). diff --git a/library.json b/library.json index 6160eacdb..eeb3c0531 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Firebase Arduino Client Library for ESP8266 and ESP32", - "version": "3.1.2", + "version": "3.1.3", "keywords": "communication, REST, esp32, esp8266, arduino", "description": "The library supports Firebase products e.g. Realtime database, Cloud Firestore database, Firebase Storage and Google Cloud Storage, Cloud Functions for Firebase and Cloud Messaging. The library also supported other Arduino devices using Clients interfaces e.g. WiFiClient, EthernetClient, and GSMClient.", "repository": { diff --git a/library.properties b/library.properties index 89d61db56..febe2f448 100644 --- a/library.properties +++ b/library.properties @@ -1,6 +1,6 @@ name=Firebase Arduino Client Library for ESP8266 and ESP32 -version=3.1.2 +version=3.1.3 author=Mobizt diff --git a/src/Firebase_ESP_Client.h b/src/Firebase_ESP_Client.h index 6cf0402dc..6617594b8 100644 --- a/src/Firebase_ESP_Client.h +++ b/src/Firebase_ESP_Client.h @@ -1,16 +1,18 @@ #ifndef FIREBASE_CLIENT_VERSION -#define FIREBASE_CLIENT_VERSION "3.1.2" +#define FIREBASE_CLIENT_VERSION "3.1.3" #endif /** - * Google's Firebase ESP Client Main class, Firebase_ESP_Client.h v3.1.2 + * Google's Firebase ESP Client Main class, Firebase_ESP_Client.h v3.1.3 * * This library supports Espressif ESP8266 and ESP32 MCUs * * Created February 28, 2022 * * Updates: - * - Change files structure. + * - Fixed multiPathStream task execution issue #256. + * - Fixed Arduino IDE compiler waring. + * - Update printf functions. * * * This work is a part of Firebase ESP Client library diff --git a/src/README.md b/src/README.md index 0d9d7933c..a13725941 100644 --- a/src/README.md +++ b/src/README.md @@ -1,7 +1,7 @@ # Firebase Arduino Client Library for ESP8266 and ESP32 -Google's Firebase Arduino Client Library for ESP8266 and ESP32 v3.1.2 +Google's Firebase Arduino Client Library for ESP8266 and ESP32 v3.1.3 The default filessystem used in the library is flash and SD. diff --git a/src/json/FirebaseJson.cpp b/src/json/FirebaseJson.cpp index 390450097..761a430a0 100644 --- a/src/json/FirebaseJson.cpp +++ b/src/json/FirebaseJson.cpp @@ -1,5 +1,5 @@ /* - * FirebaseJson, version 2.6.12 + * FirebaseJson, version 2.6.13 * * The Easiest Arduino library to parse, create and edit JSON object using a relative path. * diff --git a/src/json/FirebaseJson.h b/src/json/FirebaseJson.h index 52271133e..7f604297e 100644 --- a/src/json/FirebaseJson.h +++ b/src/json/FirebaseJson.h @@ -1,5 +1,5 @@ /* - * FirebaseJson, version 2.6.12 + * FirebaseJson, version 2.6.13 * * The Easiest Arduino library to parse, create and edit JSON object using a relative path. * @@ -118,15 +118,15 @@ extern "C" #elif defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F4) || defined(__AVR__) -#include "extras/print/printf_alt.h" +#include "extras/print/fb_json_print.h" extern "C" __attribute__((weak)) void -_putchar_alt(char c) +fb_json_putchar(char c) { Serial.print(c); } -#define Serial_Printf printf_alt +#define Serial_Printf fb_json_printf #endif diff --git a/src/json/MB_String.h b/src/json/MB_String.h index 797129f8b..f462d4658 100644 --- a/src/json/MB_String.h +++ b/src/json/MB_String.h @@ -2,12 +2,12 @@ /** * Mobizt's SRAM/PSRAM supported String, version 1.2.4 * - * Created February 20, 2022 + * Created February 28, 2022 * * Changes Log - * + * * v1.2.4 - * - Check PSRAM availability before allocating the memory + * - Check PSRAM availability before allocating the memory * * v1.2.3 * - Fixed flash string F and PSTR handle @@ -71,7 +71,7 @@ #define MB_STRING_MAJOR 1 #define MB_STRING_MINOR 2 -#define MB_STRING_PATCH 3 +#define MB_STRING_PATCH 4 #if defined(ESP8266) && defined(MMU_EXTERNAL_HEAP) && defined(MB_STRING_USE_PSRAM) #include diff --git a/src/json/extras/print/printf_alt.c b/src/json/extras/print/fb_json_print.c similarity index 55% rename from src/json/extras/print/printf_alt.c rename to src/json/extras/print/fb_json_print.c index e6d7d1eea..fd4d38520 100644 --- a/src/json/extras/print/printf_alt.c +++ b/src/json/extras/print/fb_json_print.c @@ -30,105 +30,106 @@ // /////////////////////////////////////////////////////////////////////////////// -#ifndef _PRINTF_C_ -#define _PRINTF_C_ + +#ifndef FB_JSON_PRINT_C +#define FB_JSON_PRINT_C #include #include -#include "printf_alt.h" +#include "fb_json_print.h" -// define this globally (e.g. gcc -DPRINTF_INCLUDE_CONFIG_H ...) to include the +// define this globally (e.g. gcc -DFB_JSON_PRINT_INCLUDE_CONFIG_H ...) to include the // printf_config.h header file // default: undefined -#ifdef PRINTF_INCLUDE_CONFIG_H +#ifdef FB_JSON_PRINT_INCLUDE_CONFIG_H #include "printf_config.h" #endif // 'ntoa' conversion buffer size, this must be big enough to hold one converted // numeric number including padded zeros (dynamically created on stack) // default: 32 byte -#ifndef PRINTF_NTOA_BUFFER_SIZE -#define PRINTF_NTOA_BUFFER_SIZE 32U +#ifndef FB_JSON_PRINT_NTOA_BUFFER_SIZE +#define FB_JSON_PRINT_NTOA_BUFFER_SIZE 32U #endif // 'ftoa' conversion buffer size, this must be big enough to hold one converted // float number including padded zeros (dynamically created on stack) // default: 32 byte -#ifndef PRINTF_FTOA_BUFFER_SIZE -#define PRINTF_FTOA_BUFFER_SIZE 32U +#ifndef FB_JSON_PRINT_FTOA_BUFFER_SIZE +#define FB_JSON_PRINT_FTOA_BUFFER_SIZE 32U #endif // support for the floating point type (%f) // default: activated -#ifndef PRINTF_DISABLE_SUPPORT_FLOAT -#define PRINTF_SUPPORT_FLOAT +#ifndef FB_JSON_PRINT_DISABLE_SUPPORT_FLOAT +#define FB_JSON_PRINT_SUPPORT_FLOAT #endif // support for exponential floating point notation (%e/%g) // default: activated -#ifndef PRINTF_DISABLE_SUPPORT_EXPONENTIAL -#define PRINTF_SUPPORT_EXPONENTIAL +#ifndef FB_JSON_PRINT_DISABLE_SUPPORT_EXPONENTIAL +#define FB_JSON_PRINT_SUPPORT_EXPONENTIAL #endif // define the default floating point precision // default: 6 digits -#ifndef PRINTF_DEFAULT_FLOAT_PRECISION -#define PRINTF_DEFAULT_FLOAT_PRECISION 6U +#ifndef FB_JSON_PRINT_DEFAULT_FLOAT_PRECISION +#define FB_JSON_PRINT_DEFAULT_FLOAT_PRECISION 6U #endif // define the largest float suitable to print with %f // default: 1e9 -#ifndef PRINTF_MAX_FLOAT -#define PRINTF_MAX_FLOAT 1e9 +#ifndef FB_JSON_PRINT_MAX_FLOAT +#define FB_JSON_PRINT_MAX_FLOAT 1e9 #endif // support for the long long types (%llu or %p) // default: activated -#ifndef PRINTF_DISABLE_SUPPORT_LONG_LONG -#define PRINTF_SUPPORT_LONG_LONG +#ifndef FB_JSON_PRINT_DISABLE_SUPPORT_LONG_LONG +#define FB_JSON_PRINT_SUPPORT_LONG_LONG #endif // support for the ptrdiff_t type (%t) // ptrdiff_t is normally defined in as long or long long type // default: activated -#ifndef PRINTF_DISABLE_SUPPORT_PTRDIFF_T -#define PRINTF_SUPPORT_PTRDIFF_T +#ifndef FB_JSON_PRINT_DISABLE_SUPPORT_PTRDIFF_T +#define FB_JSON_PRINT_SUPPORT_PTRDIFF_T #endif /////////////////////////////////////////////////////////////////////////////// // internal flag definitions -#define _FLAGS_ZEROPAD (1U << 0U) -#define _FLAGS_LEFT (1U << 1U) -#define _FLAGS_PLUS (1U << 2U) -#define _FLAGS_SPACE (1U << 3U) -#define _FLAGS_HASH (1U << 4U) -#define _FLAGS_UPPERCASE (1U << 5U) -#define _FLAGS_CHAR (1U << 6U) -#define _FLAGS_SHORT (1U << 7U) -#define _FLAGS_LONG (1U << 8U) -#define _FLAGS_LONG_LONG (1U << 9U) -#define _FLAGS_PRECISION (1U << 10U) -#define _FLAGS_ADAPT_EXP (1U << 11U) +#define FB_JSON_PRINT_FLAGS_ZEROPAD (1U << 0U) +#define FB_JSON_PRINT_FLAGS_LEFT (1U << 1U) +#define FB_JSON_PRINT_FLAGS_PLUS (1U << 2U) +#define FB_JSON_PRINT_FLAGS_SPACE (1U << 3U) +#define FB_JSON_PRINT_FLAGS_HASH (1U << 4U) +#define FB_JSON_PRINT_FLAGS_UPPERCASE (1U << 5U) +#define FB_JSON_PRINT_FLAGS_CHAR (1U << 6U) +#define FB_JSON_PRINT_FLAGS_SHORT (1U << 7U) +#define FB_JSON_PRINT_FLAGS_LONG (1U << 8U) +#define FB_JSON_PRINT_FLAGS_LONG_LONG (1U << 9U) +#define FB_JSON_PRINT_FLAGS_PRECISION (1U << 10U) +#define FB_JSON_PRINT_FLAGS_ADAPT_EXP (1U << 11U) // import float.h for DBL_MAX -#if defined(PRINTF_SUPPORT_FLOAT) +#if defined(FB_JSON_PRINT_SUPPORT_FLOAT) #include #endif // output function type -typedef void (*out_fct_type)(char character, void *buffer, size_t idx, size_t maxlen); +typedef void (*fb_json_out_fn_type)(char character, void *buffer, size_t idx, size_t maxlen); // wrapper (used as buffer) for output function type typedef struct { void (*fct)(char character, void *arg); void *arg; -} out_fct_wrap_type_alt; +} fb_json_out_fn_wrap_type; // internal buffer output -static inline void _out_buffer_alt(char character, void *buffer, size_t idx, size_t maxlen) +static inline void fb_json_out_buffer(char character, void *buffer, size_t idx, size_t maxlen) { if (idx < maxlen) { @@ -137,7 +138,7 @@ static inline void _out_buffer_alt(char character, void *buffer, size_t idx, siz } // internal null output -static inline void _out_null_alt(char character, void *buffer, size_t idx, size_t maxlen) +static inline void fb_json_out_null(char character, void *buffer, size_t idx, size_t maxlen) { (void)character; (void)buffer; @@ -145,33 +146,33 @@ static inline void _out_null_alt(char character, void *buffer, size_t idx, size_ (void)maxlen; } -// internal _putchar_alt wrapper -static inline void _out_char_alt(char character, void *buffer, size_t idx, size_t maxlen) +// internal _putchar wrapper +static inline void fb_json_out_char(char character, void *buffer, size_t idx, size_t maxlen) { (void)buffer; (void)idx; (void)maxlen; if (character) { - _putchar_alt(character); + fb_json_putchar(character); } } // internal output function wrapper -static inline void _out_fct_alt(char character, void *buffer, size_t idx, size_t maxlen) +static inline void fb_json_out_fn(char character, void *buffer, size_t idx, size_t maxlen) { (void)idx; (void)maxlen; if (character) { // buffer is the output fct pointer - ((out_fct_wrap_type_alt *)buffer)->fct(character, ((out_fct_wrap_type_alt *)buffer)->arg); + ((fb_json_out_fn_wrap_type *)buffer)->fct(character, ((fb_json_out_fn_wrap_type *)buffer)->arg); } } // internal secure strlen // \return The length of the string (excluding the terminating 0) limited by 'maxsize' -static inline unsigned int _strnlen_s_alt(const char *str, size_t maxsize) +static inline unsigned int fb_json_strlen(const char *str, size_t maxsize) { const char *s; for (s = str; *s && maxsize--; ++s) @@ -181,16 +182,16 @@ static inline unsigned int _strnlen_s_alt(const char *str, size_t maxsize) // internal test if char is a digit (0-9) // \return true if char is a digit -static inline bool _is_digit_alt(char ch) +static inline bool fb_json_is_digit(char ch) { return (ch >= '0') && (ch <= '9'); } // internal ASCII string to unsigned int conversion -static unsigned int _atoi_alt(const char **str) +static unsigned int fb_json_atoi(const char **str) { unsigned int i = 0U; - while (_is_digit_alt(**str)) + while (fb_json_is_digit(**str)) { i = i * 10U + (unsigned int)(*((*str)++) - '0'); } @@ -198,12 +199,12 @@ static unsigned int _atoi_alt(const char **str) } // output the specified string in reverse, taking care of any zero-padding -static size_t _out_rev_alt(out_fct_type out, char *buffer, size_t idx, size_t maxlen, const char *buf, size_t len, unsigned int width, unsigned int flags) +static size_t fb_json_out_rev(fb_json_out_fn_type out, char *buffer, size_t idx, size_t maxlen, const char *buf, size_t len, unsigned int width, unsigned int flags) { const size_t start_idx = idx; // pad spaces up to given width - if (!(flags & _FLAGS_LEFT) && !(flags & _FLAGS_ZEROPAD)) + if (!(flags & FB_JSON_PRINT_FLAGS_LEFT) && !(flags & FB_JSON_PRINT_FLAGS_ZEROPAD)) { for (size_t i = len; i < width; i++) { @@ -218,7 +219,7 @@ static size_t _out_rev_alt(out_fct_type out, char *buffer, size_t idx, size_t ma } // append pad spaces up to given width - if (flags & _FLAGS_LEFT) + if (flags & FB_JSON_PRINT_FLAGS_LEFT) { while (idx - start_idx < width) { @@ -230,29 +231,29 @@ static size_t _out_rev_alt(out_fct_type out, char *buffer, size_t idx, size_t ma } // internal itoa format -static size_t _ntoa_format_alt(out_fct_type out, char *buffer, size_t idx, size_t maxlen, char *buf, size_t len, bool negative, unsigned int base, unsigned int prec, unsigned int width, unsigned int flags) +static size_t fb_json_itoa_format(fb_json_out_fn_type out, char *buffer, size_t idx, size_t maxlen, char *buf, size_t len, bool negative, unsigned int base, unsigned int prec, unsigned int width, unsigned int flags) { // pad leading zeros - if (!(flags & _FLAGS_LEFT)) + if (!(flags & FB_JSON_PRINT_FLAGS_LEFT)) { - if (width && (flags & _FLAGS_ZEROPAD) && (negative || (flags & (_FLAGS_PLUS | _FLAGS_SPACE)))) + if (width && (flags & FB_JSON_PRINT_FLAGS_ZEROPAD) && (negative || (flags & (FB_JSON_PRINT_FLAGS_PLUS | FB_JSON_PRINT_FLAGS_SPACE)))) { width--; } - while ((len < prec) && (len < PRINTF_NTOA_BUFFER_SIZE)) + while ((len < prec) && (len < FB_JSON_PRINT_NTOA_BUFFER_SIZE)) { buf[len++] = '0'; } - while ((flags & _FLAGS_ZEROPAD) && (len < width) && (len < PRINTF_NTOA_BUFFER_SIZE)) + while ((flags & FB_JSON_PRINT_FLAGS_ZEROPAD) && (len < width) && (len < FB_JSON_PRINT_NTOA_BUFFER_SIZE)) { buf[len++] = '0'; } } // handle hash - if (flags & _FLAGS_HASH) + if (flags & FB_JSON_PRINT_FLAGS_HASH) { - if (!(flags & _FLAGS_PRECISION) && len && ((len == prec) || (len == width))) + if (!(flags & FB_JSON_PRINT_FLAGS_PRECISION) && len && ((len == prec) || (len == width))) { len--; if (len && (base == 16U)) @@ -260,108 +261,108 @@ static size_t _ntoa_format_alt(out_fct_type out, char *buffer, size_t idx, size_ len--; } } - if ((base == 16U) && !(flags & _FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) + if ((base == 16U) && !(flags & FB_JSON_PRINT_FLAGS_UPPERCASE) && (len < FB_JSON_PRINT_NTOA_BUFFER_SIZE)) { buf[len++] = 'x'; } - else if ((base == 16U) && (flags & _FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) + else if ((base == 16U) && (flags & FB_JSON_PRINT_FLAGS_UPPERCASE) && (len < FB_JSON_PRINT_NTOA_BUFFER_SIZE)) { buf[len++] = 'X'; } - else if ((base == 2U) && (len < PRINTF_NTOA_BUFFER_SIZE)) + else if ((base == 2U) && (len < FB_JSON_PRINT_NTOA_BUFFER_SIZE)) { buf[len++] = 'b'; } - if (len < PRINTF_NTOA_BUFFER_SIZE) + if (len < FB_JSON_PRINT_NTOA_BUFFER_SIZE) { buf[len++] = '0'; } } - if (len < PRINTF_NTOA_BUFFER_SIZE) + if (len < FB_JSON_PRINT_NTOA_BUFFER_SIZE) { if (negative) { buf[len++] = '-'; } - else if (flags & _FLAGS_PLUS) + else if (flags & FB_JSON_PRINT_FLAGS_PLUS) { buf[len++] = '+'; // ignore the space if the '+' exists } - else if (flags & _FLAGS_SPACE) + else if (flags & FB_JSON_PRINT_FLAGS_SPACE) { buf[len++] = ' '; } } - return _out_rev_alt(out, buffer, idx, maxlen, buf, len, width, flags); + return fb_json_out_rev(out, buffer, idx, maxlen, buf, len, width, flags); } // internal itoa for 'long' type -static size_t _ntoa_long_alt(out_fct_type out, char *buffer, size_t idx, size_t maxlen, unsigned long value, bool negative, unsigned long base, unsigned int prec, unsigned int width, unsigned int flags) +static size_t fb_json_itoa_long(fb_json_out_fn_type out, char *buffer, size_t idx, size_t maxlen, unsigned long value, bool negative, unsigned long base, unsigned int prec, unsigned int width, unsigned int flags) { - char buf[PRINTF_NTOA_BUFFER_SIZE]; + char buf[FB_JSON_PRINT_NTOA_BUFFER_SIZE]; size_t len = 0U; // no hash for 0 values if (!value) { - flags &= ~_FLAGS_HASH; + flags &= ~FB_JSON_PRINT_FLAGS_HASH; } // write if precision != 0 and value is != 0 - if (!(flags & _FLAGS_PRECISION) || value) + if (!(flags & FB_JSON_PRINT_FLAGS_PRECISION) || value) { do { const char digit = (char)(value % base); - buf[len++] = digit < 10 ? '0' + digit : (flags & _FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10; + buf[len++] = digit < 10 ? '0' + digit : (flags & FB_JSON_PRINT_FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10; value /= base; - } while (value && (len < PRINTF_NTOA_BUFFER_SIZE)); + } while (value && (len < FB_JSON_PRINT_NTOA_BUFFER_SIZE)); } - return _ntoa_format_alt(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags); + return fb_json_itoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags); } // internal itoa for 'long long' type -#if defined(PRINTF_SUPPORT_LONG_LONG) -static size_t _ntoa_long_long_alt(out_fct_type out, char *buffer, size_t idx, size_t maxlen, unsigned long long value, bool negative, unsigned long long base, unsigned int prec, unsigned int width, unsigned int flags) +#if defined(FB_JSON_PRINT_SUPPORT_LONG_LONG) +static size_t fb_json_itoa_long_long(fb_json_out_fn_type out, char *buffer, size_t idx, size_t maxlen, unsigned long long value, bool negative, unsigned long long base, unsigned int prec, unsigned int width, unsigned int flags) { - char buf[PRINTF_NTOA_BUFFER_SIZE]; + char buf[FB_JSON_PRINT_NTOA_BUFFER_SIZE]; size_t len = 0U; // no hash for 0 values if (!value) { - flags &= ~_FLAGS_HASH; + flags &= ~FB_JSON_PRINT_FLAGS_HASH; } // write if precision != 0 and value is != 0 - if (!(flags & _FLAGS_PRECISION) || value) + if (!(flags & FB_JSON_PRINT_FLAGS_PRECISION) || value) { do { const char digit = (char)(value % base); - buf[len++] = digit < 10 ? '0' + digit : (flags & _FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10; + buf[len++] = digit < 10 ? '0' + digit : (flags & FB_JSON_PRINT_FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10; value /= base; - } while (value && (len < PRINTF_NTOA_BUFFER_SIZE)); + } while (value && (len < FB_JSON_PRINT_NTOA_BUFFER_SIZE)); } - return _ntoa_format_alt(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags); + return fb_json_itoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags); } -#endif // PRINTF_SUPPORT_LONG_LONG +#endif // FB_JSON_PRINT_SUPPORT_LONG_LONG -#if defined(PRINTF_SUPPORT_FLOAT) +#if defined(FB_JSON_PRINT_SUPPORT_FLOAT) -#if defined(PRINTF_SUPPORT_EXPONENTIAL) -// forward declaration so that _ftoa_alt can switch to exp notation for values > PRINTF_MAX_FLOAT -static size_t _etoa_alt(out_fct_type out, char *buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags); +#if defined(FB_JSON_PRINT_SUPPORT_EXPONENTIAL) +// forward declaration so that fb_json_ftoa can switch to exp notation for values > FB_JSON_PRINT_MAX_FLOAT +static size_t fb_json_ftoa_exp(fb_json_out_fn_type out, char *buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags); #endif // internal ftoa for fixed decimal floating point -static size_t _ftoa_alt(out_fct_type out, char *buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags) +static size_t fb_json_ftoa(fb_json_out_fn_type out, char *buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags) { - char buf[PRINTF_FTOA_BUFFER_SIZE]; + char buf[FB_JSON_PRINT_FTOA_BUFFER_SIZE]; size_t len = 0U; double diff = 0.0; @@ -370,18 +371,18 @@ static size_t _ftoa_alt(out_fct_type out, char *buffer, size_t idx, size_t maxle // test for special values if (value != value) - return _out_rev_alt(out, buffer, idx, maxlen, "nan", 3, width, flags); + return fb_json_out_rev(out, buffer, idx, maxlen, "nan", 3, width, flags); if (value < -DBL_MAX) - return _out_rev_alt(out, buffer, idx, maxlen, "fni-", 4, width, flags); + return fb_json_out_rev(out, buffer, idx, maxlen, "fni-", 4, width, flags); if (value > DBL_MAX) - return _out_rev_alt(out, buffer, idx, maxlen, (flags & _FLAGS_PLUS) ? "fni+" : "fni", (flags & _FLAGS_PLUS) ? 4U : 3U, width, flags); + return fb_json_out_rev(out, buffer, idx, maxlen, (flags & FB_JSON_PRINT_FLAGS_PLUS) ? "fni+" : "fni", (flags & FB_JSON_PRINT_FLAGS_PLUS) ? 4U : 3U, width, flags); // test for very large values // standard printf behavior is to print EVERY whole number digit -- which could be 100s of characters overflowing your buffers == bad - if ((value > PRINTF_MAX_FLOAT) || (value < -PRINTF_MAX_FLOAT)) + if ((value > FB_JSON_PRINT_MAX_FLOAT) || (value < -FB_JSON_PRINT_MAX_FLOAT)) { -#if defined(PRINTF_SUPPORT_EXPONENTIAL) - return _etoa_alt(out, buffer, idx, maxlen, value, prec, width, flags); +#if defined(FB_JSON_PRINT_SUPPORT_EXPONENTIAL) + return fb_json_ftoa_exp(out, buffer, idx, maxlen, value, prec, width, flags); #else return 0U; #endif @@ -396,12 +397,12 @@ static size_t _ftoa_alt(out_fct_type out, char *buffer, size_t idx, size_t maxle } // set default precision, if not set explicitly - if (!(flags & _FLAGS_PRECISION)) + if (!(flags & FB_JSON_PRINT_FLAGS_PRECISION)) { - prec = PRINTF_DEFAULT_FLOAT_PRECISION; + prec = FB_JSON_PRINT_DEFAULT_FLOAT_PRECISION; } // limit precision to 9, cause a prec >= 10 can lead to overflow errors - while ((len < PRINTF_FTOA_BUFFER_SIZE) && (prec > 9U)) + while ((len < FB_JSON_PRINT_FTOA_BUFFER_SIZE) && (prec > 9U)) { buf[len++] = '0'; prec--; @@ -445,7 +446,7 @@ static size_t _ftoa_alt(out_fct_type out, char *buffer, size_t idx, size_t maxle { unsigned int count = prec; // now do fractional part, as an unsigned number - while (len < PRINTF_FTOA_BUFFER_SIZE) + while (len < FB_JSON_PRINT_FTOA_BUFFER_SIZE) { --count; buf[len++] = (char)(48U + (frac % 10U)); @@ -455,11 +456,11 @@ static size_t _ftoa_alt(out_fct_type out, char *buffer, size_t idx, size_t maxle } } // add extra 0s - while ((len < PRINTF_FTOA_BUFFER_SIZE) && (count-- > 0U)) + while ((len < FB_JSON_PRINT_FTOA_BUFFER_SIZE) && (count-- > 0U)) { buf[len++] = '0'; } - if (len < PRINTF_FTOA_BUFFER_SIZE) + if (len < FB_JSON_PRINT_FTOA_BUFFER_SIZE) { // add decimal buf[len++] = '.'; @@ -467,7 +468,7 @@ static size_t _ftoa_alt(out_fct_type out, char *buffer, size_t idx, size_t maxle } // do whole part, number is reversed - while (len < PRINTF_FTOA_BUFFER_SIZE) + while (len < FB_JSON_PRINT_FTOA_BUFFER_SIZE) { buf[len++] = (char)(48 + (whole % 10)); if (!(whole /= 10)) @@ -477,45 +478,45 @@ static size_t _ftoa_alt(out_fct_type out, char *buffer, size_t idx, size_t maxle } // pad leading zeros - if (!(flags & _FLAGS_LEFT) && (flags & _FLAGS_ZEROPAD)) + if (!(flags & FB_JSON_PRINT_FLAGS_LEFT) && (flags & FB_JSON_PRINT_FLAGS_ZEROPAD)) { - if (width && (negative || (flags & (_FLAGS_PLUS | _FLAGS_SPACE)))) + if (width && (negative || (flags & (FB_JSON_PRINT_FLAGS_PLUS | FB_JSON_PRINT_FLAGS_SPACE)))) { width--; } - while ((len < width) && (len < PRINTF_FTOA_BUFFER_SIZE)) + while ((len < width) && (len < FB_JSON_PRINT_FTOA_BUFFER_SIZE)) { buf[len++] = '0'; } } - if (len < PRINTF_FTOA_BUFFER_SIZE) + if (len < FB_JSON_PRINT_FTOA_BUFFER_SIZE) { if (negative) { buf[len++] = '-'; } - else if (flags & _FLAGS_PLUS) + else if (flags & FB_JSON_PRINT_FLAGS_PLUS) { buf[len++] = '+'; // ignore the space if the '+' exists } - else if (flags & _FLAGS_SPACE) + else if (flags & FB_JSON_PRINT_FLAGS_SPACE) { buf[len++] = ' '; } } - return _out_rev_alt(out, buffer, idx, maxlen, buf, len, width, flags); + return fb_json_out_rev(out, buffer, idx, maxlen, buf, len, width, flags); } -#if defined(PRINTF_SUPPORT_EXPONENTIAL) +#if defined(FB_JSON_PRINT_SUPPORT_EXPONENTIAL) // internal ftoa variant for exponential floating-point type, contributed by Martijn Jasperse -static size_t _etoa_alt(out_fct_type out, char *buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags) +static size_t fb_json_ftoa_exp(fb_json_out_fn_type out, char *buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags) { // check for NaN and special values if ((value != value) || (value > DBL_MAX) || (value < -DBL_MAX)) { - return _ftoa_alt(out, buffer, idx, maxlen, value, prec, width, flags); + return fb_json_ftoa(out, buffer, idx, maxlen, value, prec, width, flags); } // determine the sign @@ -526,9 +527,9 @@ static size_t _etoa_alt(out_fct_type out, char *buffer, size_t idx, size_t maxle } // default precision - if (!(flags & _FLAGS_PRECISION)) + if (!(flags & FB_JSON_PRINT_FLAGS_PRECISION)) { - prec = PRINTF_DEFAULT_FLOAT_PRECISION; + prec = FB_JSON_PRINT_DEFAULT_FLOAT_PRECISION; } // determine the decimal exponent @@ -562,7 +563,7 @@ static size_t _etoa_alt(out_fct_type out, char *buffer, size_t idx, size_t maxle unsigned int minwidth = ((expval < 100) && (expval > -100)) ? 4U : 5U; // in "%g" mode, "prec" is the number of *significant figures* not decimals - if (flags & _FLAGS_ADAPT_EXP) + if (flags & FB_JSON_PRINT_FLAGS_ADAPT_EXP) { // do we want to fall-back to "%f" mode? if ((value >= 1e-4) && (value < 1e6)) @@ -575,7 +576,7 @@ static size_t _etoa_alt(out_fct_type out, char *buffer, size_t idx, size_t maxle { prec = 0; } - flags |= _FLAGS_PRECISION; // make sure _ftoa_alt respects precision + flags |= FB_JSON_PRINT_FLAGS_PRECISION; // make sure fb_json_ftoa respects precision // no characters in exponent minwidth = 0U; expval = 0; @@ -583,7 +584,7 @@ static size_t _etoa_alt(out_fct_type out, char *buffer, size_t idx, size_t maxle else { // we use one sigfig for the whole part - if ((prec > 0) && (flags & _FLAGS_PRECISION)) + if ((prec > 0) && (flags & FB_JSON_PRINT_FLAGS_PRECISION)) { --prec; } @@ -602,7 +603,7 @@ static size_t _etoa_alt(out_fct_type out, char *buffer, size_t idx, size_t maxle // not enough characters, so go back to default sizing fwidth = 0U; } - if ((flags & _FLAGS_LEFT) && minwidth) + if ((flags & FB_JSON_PRINT_FLAGS_LEFT) && minwidth) { // if we're padding on the right, DON'T pad the floating part fwidth = 0U; @@ -616,17 +617,17 @@ static size_t _etoa_alt(out_fct_type out, char *buffer, size_t idx, size_t maxle // output the floating part const size_t start_idx = idx; - idx = _ftoa_alt(out, buffer, idx, maxlen, negative ? -value : value, prec, fwidth, flags & ~_FLAGS_ADAPT_EXP); + idx = fb_json_ftoa(out, buffer, idx, maxlen, negative ? -value : value, prec, fwidth, flags & ~FB_JSON_PRINT_FLAGS_ADAPT_EXP); // output the exponent part if (minwidth) { // output the exponential symbol - out((flags & _FLAGS_UPPERCASE) ? 'E' : 'e', buffer, idx++, maxlen); + out((flags & FB_JSON_PRINT_FLAGS_UPPERCASE) ? 'E' : 'e', buffer, idx++, maxlen); // output the exponent value - idx = _ntoa_long_alt(out, buffer, idx, maxlen, (expval < 0) ? -expval : expval, expval < 0, 10, 0, minwidth - 1, _FLAGS_ZEROPAD | _FLAGS_PLUS); + idx = fb_json_itoa_long(out, buffer, idx, maxlen, (expval < 0) ? -expval : expval, expval < 0, 10, 0, minwidth - 1, FB_JSON_PRINT_FLAGS_ZEROPAD | FB_JSON_PRINT_FLAGS_PLUS); // might need to right-pad spaces - if (flags & _FLAGS_LEFT) + if (flags & FB_JSON_PRINT_FLAGS_LEFT) { while (idx - start_idx < width) out(' ', buffer, idx++, maxlen); @@ -634,11 +635,11 @@ static size_t _etoa_alt(out_fct_type out, char *buffer, size_t idx, size_t maxle } return idx; } -#endif // PRINTF_SUPPORT_EXPONENTIAL -#endif // PRINTF_SUPPORT_FLOAT +#endif // FB_JSON_PRINT_SUPPORT_EXPONENTIAL +#endif // FB_JSON_PRINT_SUPPORT_FLOAT // internal vsnprintf -static int _vsnprintf_alt(out_fct_type out, char *buffer, const size_t maxlen, const char *format, va_list va) +static int fb_json_vsnprintf_int(fb_json_out_fn_type out, char *buffer, const size_t maxlen, const char *format, va_list va) { unsigned int flags, width, precision, n; size_t idx = 0U; @@ -646,7 +647,7 @@ static int _vsnprintf_alt(out_fct_type out, char *buffer, const size_t maxlen, c if (!buffer) { // use null output function - out = _out_null_alt; + out = fb_json_out_null; } while (*format) @@ -672,27 +673,27 @@ static int _vsnprintf_alt(out_fct_type out, char *buffer, const size_t maxlen, c switch (*format) { case '0': - flags |= _FLAGS_ZEROPAD; + flags |= FB_JSON_PRINT_FLAGS_ZEROPAD; format++; n = 1U; break; case '-': - flags |= _FLAGS_LEFT; + flags |= FB_JSON_PRINT_FLAGS_LEFT; format++; n = 1U; break; case '+': - flags |= _FLAGS_PLUS; + flags |= FB_JSON_PRINT_FLAGS_PLUS; format++; n = 1U; break; case ' ': - flags |= _FLAGS_SPACE; + flags |= FB_JSON_PRINT_FLAGS_SPACE; format++; n = 1U; break; case '#': - flags |= _FLAGS_HASH; + flags |= FB_JSON_PRINT_FLAGS_HASH; format++; n = 1U; break; @@ -704,16 +705,16 @@ static int _vsnprintf_alt(out_fct_type out, char *buffer, const size_t maxlen, c // evaluate width field width = 0U; - if (_is_digit_alt(*format)) + if (fb_json_is_digit(*format)) { - width = _atoi_alt(&format); + width = fb_json_atoi(&format); } else if (*format == '*') { const int w = va_arg(va, int); if (w < 0) { - flags |= _FLAGS_LEFT; // reverse padding + flags |= FB_JSON_PRINT_FLAGS_LEFT; // reverse padding width = (unsigned int)-w; } else @@ -727,11 +728,11 @@ static int _vsnprintf_alt(out_fct_type out, char *buffer, const size_t maxlen, c precision = 0U; if (*format == '.') { - flags |= _FLAGS_PRECISION; + flags |= FB_JSON_PRINT_FLAGS_PRECISION; format++; - if (_is_digit_alt(*format)) + if (fb_json_is_digit(*format)) { - precision = _atoi_alt(&format); + precision = fb_json_atoi(&format); } else if (*format == '*') { @@ -745,35 +746,35 @@ static int _vsnprintf_alt(out_fct_type out, char *buffer, const size_t maxlen, c switch (*format) { case 'l': - flags |= _FLAGS_LONG; + flags |= FB_JSON_PRINT_FLAGS_LONG; format++; if (*format == 'l') { - flags |= _FLAGS_LONG_LONG; + flags |= FB_JSON_PRINT_FLAGS_LONG_LONG; format++; } break; case 'h': - flags |= _FLAGS_SHORT; + flags |= FB_JSON_PRINT_FLAGS_SHORT; format++; if (*format == 'h') { - flags |= _FLAGS_CHAR; + flags |= FB_JSON_PRINT_FLAGS_CHAR; format++; } break; -#if defined(PRINTF_SUPPORT_PTRDIFF_T) +#if defined(FB_JSON_PRINT_SUPPORT_PTRDIFF_T) case 't': - flags |= (sizeof(ptrdiff_t) == sizeof(long) ? _FLAGS_LONG : _FLAGS_LONG_LONG); + flags |= (sizeof(ptrdiff_t) == sizeof(long) ? FB_JSON_PRINT_FLAGS_LONG : FB_JSON_PRINT_FLAGS_LONG_LONG); format++; break; #endif case 'j': - flags |= (sizeof(intmax_t) == sizeof(long) ? _FLAGS_LONG : _FLAGS_LONG_LONG); + flags |= (sizeof(intmax_t) == sizeof(long) ? FB_JSON_PRINT_FLAGS_LONG : FB_JSON_PRINT_FLAGS_LONG_LONG); format++; break; case 'z': - flags |= (sizeof(size_t) == sizeof(long) ? _FLAGS_LONG : _FLAGS_LONG_LONG); + flags |= (sizeof(size_t) == sizeof(long) ? FB_JSON_PRINT_FLAGS_LONG : FB_JSON_PRINT_FLAGS_LONG_LONG); format++; break; default: @@ -808,99 +809,99 @@ static int _vsnprintf_alt(out_fct_type out, char *buffer, const size_t maxlen, c else { base = 10U; - flags &= ~_FLAGS_HASH; // no hash for dec format + flags &= ~FB_JSON_PRINT_FLAGS_HASH; // no hash for dec format } // uppercase if (*format == 'X') { - flags |= _FLAGS_UPPERCASE; + flags |= FB_JSON_PRINT_FLAGS_UPPERCASE; } // no plus or space flag for u, x, X, o, b if ((*format != 'i') && (*format != 'd')) { - flags &= ~(_FLAGS_PLUS | _FLAGS_SPACE); + flags &= ~(FB_JSON_PRINT_FLAGS_PLUS | FB_JSON_PRINT_FLAGS_SPACE); } // ignore '0' flag when precision is given - if (flags & _FLAGS_PRECISION) + if (flags & FB_JSON_PRINT_FLAGS_PRECISION) { - flags &= ~_FLAGS_ZEROPAD; + flags &= ~FB_JSON_PRINT_FLAGS_ZEROPAD; } // convert the integer if ((*format == 'i') || (*format == 'd')) { // signed - if (flags & _FLAGS_LONG_LONG) + if (flags & FB_JSON_PRINT_FLAGS_LONG_LONG) { -#if defined(PRINTF_SUPPORT_LONG_LONG) +#if defined(FB_JSON_PRINT_SUPPORT_LONG_LONG) const long long value = va_arg(va, long long); - idx = _ntoa_long_long_alt(out, buffer, idx, maxlen, (unsigned long long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); + idx = fb_json_itoa_long_long(out, buffer, idx, maxlen, (unsigned long long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); #endif } - else if (flags & _FLAGS_LONG) + else if (flags & FB_JSON_PRINT_FLAGS_LONG) { const long value = va_arg(va, long); - idx = _ntoa_long_alt(out, buffer, idx, maxlen, (unsigned long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); + idx = fb_json_itoa_long(out, buffer, idx, maxlen, (unsigned long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); } else { - const int value = (flags & _FLAGS_CHAR) ? (char)va_arg(va, int) : (flags & _FLAGS_SHORT) ? (short int)va_arg(va, int) - : va_arg(va, int); - idx = _ntoa_long_alt(out, buffer, idx, maxlen, (unsigned int)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); + const int value = (flags & FB_JSON_PRINT_FLAGS_CHAR) ? (char)va_arg(va, int) : (flags & FB_JSON_PRINT_FLAGS_SHORT) ? (short int)va_arg(va, int) + : va_arg(va, int); + idx = fb_json_itoa_long(out, buffer, idx, maxlen, (unsigned int)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); } } else { // unsigned - if (flags & _FLAGS_LONG_LONG) + if (flags & FB_JSON_PRINT_FLAGS_LONG_LONG) { -#if defined(PRINTF_SUPPORT_LONG_LONG) - idx = _ntoa_long_long_alt(out, buffer, idx, maxlen, va_arg(va, unsigned long long), false, base, precision, width, flags); +#if defined(FB_JSON_PRINT_SUPPORT_LONG_LONG) + idx = fb_json_itoa_long_long(out, buffer, idx, maxlen, va_arg(va, unsigned long long), false, base, precision, width, flags); #endif } - else if (flags & _FLAGS_LONG) + else if (flags & FB_JSON_PRINT_FLAGS_LONG) { - idx = _ntoa_long_alt(out, buffer, idx, maxlen, va_arg(va, unsigned long), false, base, precision, width, flags); + idx = fb_json_itoa_long(out, buffer, idx, maxlen, va_arg(va, unsigned long), false, base, precision, width, flags); } else { - const unsigned int value = (flags & _FLAGS_CHAR) ? (unsigned char)va_arg(va, unsigned int) : (flags & _FLAGS_SHORT) ? (unsigned short int)va_arg(va, unsigned int) - : va_arg(va, unsigned int); - idx = _ntoa_long_alt(out, buffer, idx, maxlen, value, false, base, precision, width, flags); + const unsigned int value = (flags & FB_JSON_PRINT_FLAGS_CHAR) ? (unsigned char)va_arg(va, unsigned int) : (flags & FB_JSON_PRINT_FLAGS_SHORT) ? (unsigned short int)va_arg(va, unsigned int) + : va_arg(va, unsigned int); + idx = fb_json_itoa_long(out, buffer, idx, maxlen, value, false, base, precision, width, flags); } } format++; break; } -#if defined(PRINTF_SUPPORT_FLOAT) +#if defined(FB_JSON_PRINT_SUPPORT_FLOAT) case 'f': case 'F': if (*format == 'F') - flags |= _FLAGS_UPPERCASE; - idx = _ftoa_alt(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags); + flags |= FB_JSON_PRINT_FLAGS_UPPERCASE; + idx = fb_json_ftoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags); format++; break; -#if defined(PRINTF_SUPPORT_EXPONENTIAL) +#if defined(FB_JSON_PRINT_SUPPORT_EXPONENTIAL) case 'e': case 'E': case 'g': case 'G': if ((*format == 'g') || (*format == 'G')) - flags |= _FLAGS_ADAPT_EXP; + flags |= FB_JSON_PRINT_FLAGS_ADAPT_EXP; if ((*format == 'E') || (*format == 'G')) - flags |= _FLAGS_UPPERCASE; - idx = _etoa_alt(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags); + flags |= FB_JSON_PRINT_FLAGS_UPPERCASE; + idx = fb_json_ftoa_exp(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags); format++; break; -#endif // PRINTF_SUPPORT_EXPONENTIAL -#endif // PRINTF_SUPPORT_FLOAT +#endif // FB_JSON_PRINT_SUPPORT_EXPONENTIAL +#endif // FB_JSON_PRINT_SUPPORT_FLOAT case 'c': { unsigned int l = 1U; // pre padding - if (!(flags & _FLAGS_LEFT)) + if (!(flags & FB_JSON_PRINT_FLAGS_LEFT)) { while (l++ < width) { @@ -910,7 +911,7 @@ static int _vsnprintf_alt(out_fct_type out, char *buffer, const size_t maxlen, c // char output out((char)va_arg(va, int), buffer, idx++, maxlen); // post padding - if (flags & _FLAGS_LEFT) + if (flags & FB_JSON_PRINT_FLAGS_LEFT) { while (l++ < width) { @@ -924,13 +925,13 @@ static int _vsnprintf_alt(out_fct_type out, char *buffer, const size_t maxlen, c case 's': { const char *p = va_arg(va, char *); - unsigned int l = _strnlen_s_alt(p, precision ? precision : (size_t)-1); + unsigned int l = fb_json_strlen(p, precision ? precision : (size_t)-1); // pre padding - if (flags & _FLAGS_PRECISION) + if (flags & FB_JSON_PRINT_FLAGS_PRECISION) { l = (l < precision ? l : precision); } - if (!(flags & _FLAGS_LEFT)) + if (!(flags & FB_JSON_PRINT_FLAGS_LEFT)) { while (l++ < width) { @@ -938,12 +939,12 @@ static int _vsnprintf_alt(out_fct_type out, char *buffer, const size_t maxlen, c } } // string output - while ((*p != 0) && (!(flags & _FLAGS_PRECISION) || precision--)) + while ((*p != 0) && (!(flags & FB_JSON_PRINT_FLAGS_PRECISION) || precision--)) { out(*(p++), buffer, idx++, maxlen); } // post padding - if (flags & _FLAGS_LEFT) + if (flags & FB_JSON_PRINT_FLAGS_LEFT) { while (l++ < width) { @@ -957,18 +958,18 @@ static int _vsnprintf_alt(out_fct_type out, char *buffer, const size_t maxlen, c case 'p': { width = sizeof(void *) * 2U; - flags |= _FLAGS_ZEROPAD | _FLAGS_UPPERCASE; -#if defined(PRINTF_SUPPORT_LONG_LONG) + flags |= FB_JSON_PRINT_FLAGS_ZEROPAD | FB_JSON_PRINT_FLAGS_UPPERCASE; +#if defined(FB_JSON_PRINT_SUPPORT_LONG_LONG) const bool is_ll = sizeof(uintptr_t) == sizeof(long long); if (is_ll) { - idx = _ntoa_long_long_alt(out, buffer, idx, maxlen, (uintptr_t)va_arg(va, void *), false, 16U, precision, width, flags); + idx = fb_json_itoa_long_long(out, buffer, idx, maxlen, (uintptr_t)va_arg(va, void *), false, 16U, precision, width, flags); } else { #endif - idx = _ntoa_long_alt(out, buffer, idx, maxlen, (unsigned long)((uintptr_t)va_arg(va, void *)), false, 16U, precision, width, flags); -#if defined(PRINTF_SUPPORT_LONG_LONG) + idx = fb_json_itoa_long(out, buffer, idx, maxlen, (unsigned long)((uintptr_t)va_arg(va, void *)), false, 16U, precision, width, flags); +#if defined(FB_JSON_PRINT_SUPPORT_LONG_LONG) } #endif format++; @@ -996,55 +997,53 @@ static int _vsnprintf_alt(out_fct_type out, char *buffer, const size_t maxlen, c /////////////////////////////////////////////////////////////////////////////// -static int printf_alt_(const char *format, ...) +int fb_json_printf(const char *format, ...) { va_list va; va_start(va, format); char buffer[1]; - const int ret = _vsnprintf_alt(_out_char_alt, buffer, (size_t)-1, format, va); + const int ret = fb_json_vsnprintf_int(fb_json_out_char, buffer, (size_t)-1, format, va); va_end(va); return ret; } -static int sprintf_alt_(char *buffer, const char *format, ...) +int fb_json_sprintf(char *buffer, const char *format, ...) { va_list va; va_start(va, format); - const int ret = _vsnprintf_alt(_out_buffer_alt, buffer, (size_t)-1, format, va); + const int ret = fb_json_vsnprintf_int(fb_json_out_buffer, buffer, (size_t)-1, format, va); va_end(va); return ret; } -static int snprintf_alt_(char *buffer, size_t count, const char *format, ...) +int fb_json_snprintf_(char *buffer, size_t count, const char *format, ...) { va_list va; va_start(va, format); - const int ret = _vsnprintf_alt(_out_buffer_alt, buffer, count, format, va); + const int ret = fb_json_vsnprintf_int(fb_json_out_buffer, buffer, count, format, va); va_end(va); return ret; } -static int vprintf_alt_(const char *format, va_list va) +int fb_json_vprintf(const char *format, va_list va) { char buffer[1]; - return _vsnprintf_alt(_out_char_alt, buffer, (size_t)-1, format, va); + return fb_json_vsnprintf_int(fb_json_out_char, buffer, (size_t)-1, format, va); } -static int vsnprintf_alt_(char *buffer, size_t count, const char *format, va_list va) +int fb_json_vsnprintf_(char *buffer, size_t count, const char *format, va_list va) { - return _vsnprintf_alt(_out_buffer_alt, buffer, count, format, va); + return fb_json_vsnprintf_int(fb_json_out_buffer, buffer, count, format, va); } -static int fctprintf_alt(void (*out)(char character, void *arg), void *arg, const char *format, ...) +int fb_json_fnprintf(void (*out)(char character, void *arg), void *arg, const char *format, ...) { va_list va; va_start(va, format); - const out_fct_wrap_type_alt out_fct_wrap = {out, arg}; - const int ret = _vsnprintf_alt(_out_fct_alt, (char *)(uintptr_t)&out_fct_wrap, (size_t)-1, format, va); + const fb_json_out_fn_wrap_type out_fct_wrap = {out, arg}; + const int ret = fb_json_vsnprintf_int(fb_json_out_fn, (char *)(uintptr_t)&out_fct_wrap, (size_t)-1, format, va); va_end(va); return ret; } - - #endif \ No newline at end of file diff --git a/src/json/extras/print/fb_json_print.h b/src/json/extras/print/fb_json_print.h new file mode 100644 index 000000000..db050bffa --- /dev/null +++ b/src/json/extras/print/fb_json_print.h @@ -0,0 +1,108 @@ +/////////////////////////////////////////////////////////////////////////////// +// \author (c) Marco Paland (info@paland.com) +// 2014-2019, PALANDesign Hannover, Germany +// +// \license The MIT License (MIT) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on +// embedded systems with a very limited resources. +// Use this instead of bloated standard/newlib printf. +// These routines are thread safe and reentrant. +// +/////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#ifndef FB_JSON_PRINT_H +#define FB_JSON_PRINT_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * Output a character to a custom device like UART, used by the printf() function + * This function is declared here only. You have to write your custom implementation somewhere + * \param character Character to output + */ + void fb_json_putchar(char character) __attribute__((used)); + + /** + * Tiny printf implementation + * You have to implement _putchar if you use printf() + * To avoid conflicts with the regular printf() API it is overridden by macro defines + * and internal underscore-appended functions like printf_() are used + * \param format A string that specifies the format of the output + * \return The number of characters that are written into the array, not counting the terminating null character + */ + int fb_json_printf(const char *format, ...) __attribute__((used)); + + /** + * Tiny sprintf implementation + * Due to security reasons (buffer overflow) YOU SHOULD CONSIDER USING (V)SNPRINTF INSTEAD! + * \param buffer A pointer to the buffer where to store the formatted string. MUST be big enough to store the output! + * \param format A string that specifies the format of the output + * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character + */ + int fb_json_sprintf(char *buffer, const char *format, ...) __attribute__((used)); + + /** + * Tiny snprintf/vsnprintf implementation + * \param buffer A pointer to the buffer where to store the formatted string + * \param count The maximum number of characters to store in the buffer, including a terminating null character + * \param format A string that specifies the format of the output + * \param va A value identifying a variable arguments list + * \return The number of characters that COULD have been written into the buffer, not counting the terminating + * null character. A value equal or larger than count indicates truncation. Only when the returned value + * is non-negative and less than count, the string has been completely written. + */ +#define fb_json_snprintf fb_json_snprintf_ +#define fb_json_vsnprintf fb_json_vsnprintf_ + int fb_json_snprintf_(char *buffer, size_t count, const char *format, ...) __attribute__((used)); + int fb_json_vsnprintf_(char *buffer, size_t count, const char *format, va_list va) __attribute__((used)); + + /** + * Tiny vprintf implementation + * \param format A string that specifies the format of the output + * \param va A value identifying a variable arguments list + * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character + */ + int fb_json_vprintf(const char *format, va_list va) __attribute__((used)); + + /** + * printf with output function + * You may use this as dynamic alternative to printf() with its fixed _putchar() output + * \param out An output function which takes one character and an argument pointer + * \param arg An argument pointer for user data passed to output function + * \param format A string that specifies the format of the output + * \return The number of characters that are sent to the output function, not counting the terminating null character + */ + int fb_json_fnprintf(void (*out)(char character, void *arg), void *arg, const char *format, ...) __attribute__((used)); + +#ifdef __cplusplus +} +#endif + +#endif // _PRINTF_H_ \ No newline at end of file diff --git a/src/json/extras/print/printf_alt.h b/src/json/extras/print/printf_alt.h deleted file mode 100644 index b79cb85d4..000000000 --- a/src/json/extras/print/printf_alt.h +++ /dev/null @@ -1,109 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// \author (c) Marco Paland (info@paland.com) -// 2014-2019, PALANDesign Hannover, Germany -// -// \license The MIT License (MIT) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// -// \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on -// embedded systems with a very limited resources. -// Use this instead of bloated standard/newlib printf. -// These routines are thread safe and reentrant. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef _PRINTF_H_ -#define _PRINTF_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * Output a character to a custom device like UART, used by the printf() function - * This function is declared here only. You have to write your custom implementation somewhere - * \param character Character to output - */ - void _putchar_alt(char character) __attribute__((used)); - -/** - * Tiny printf implementation - * You have to implement _putchar if you use printf() - * To avoid conflicts with the regular printf() API it is overridden by macro defines - * and internal underscore-appended functions like printf_() are used - * \param format A string that specifies the format of the output - * \return The number of characters that are written into the array, not counting the terminating null character - */ -#define printf_alt printf_alt_ - static int printf_alt_(const char *format, ...) __attribute__((used)); - -/** - * Tiny sprintf implementation - * Due to security reasons (buffer overflow) YOU SHOULD CONSIDER USING (V)SNPRINTF INSTEAD! - * \param buffer A pointer to the buffer where to store the formatted string. MUST be big enough to store the output! - * \param format A string that specifies the format of the output - * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character - */ -#define sprintf_alt sprintf_alt_ - static int sprintf_alt_(char *buffer, const char *format, ...) __attribute__((used)); - -/** - * Tiny snprintf/vsnprintf implementation - * \param buffer A pointer to the buffer where to store the formatted string - * \param count The maximum number of characters to store in the buffer, including a terminating null character - * \param format A string that specifies the format of the output - * \param va A value identifying a variable arguments list - * \return The number of characters that COULD have been written into the buffer, not counting the terminating - * null character. A value equal or larger than count indicates truncation. Only when the returned value - * is non-negative and less than count, the string has been completely written. - */ -#define snprintf_alt snprintf_alt_ -#define vsnprintf_alt vsnprintf_alt_ - static int snprintf_alt_(char *buffer, size_t count, const char *format, ...) __attribute__((used)); - static int vsnprintf_alt_(char *buffer, size_t count, const char *format, va_list va) __attribute__((used)); - -/** - * Tiny vprintf implementation - * \param format A string that specifies the format of the output - * \param va A value identifying a variable arguments list - * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character - */ -#define vprintf_alt vprintf_alt_ - static int vprintf_alt_(const char *format, va_list va) __attribute__((used)); - - /** - * printf with output function - * You may use this as dynamic alternative to printf() with its fixed _putchar() output - * \param out An output function which takes one character and an argument pointer - * \param arg An argument pointer for user data passed to output function - * \param format A string that specifies the format of the output - * \return The number of characters that are sent to the output function, not counting the terminating null character - */ - static int fctprintf_alt(void (*out)(char character, void *arg), void *arg, const char *format, ...) __attribute__((used)); - -#ifdef __cplusplus -} -#endif - -#endif // _PRINTF_H_ \ No newline at end of file diff --git a/src/rtdb/FB_RTDB.cpp b/src/rtdb/FB_RTDB.cpp index e3a00979c..38041c5e3 100644 --- a/src/rtdb/FB_RTDB.cpp +++ b/src/rtdb/FB_RTDB.cpp @@ -1,5 +1,5 @@ /** - * Google's Firebase Realtime Database class, FB_RTDB.cpp version 1.3.6 + * Google's Firebase Realtime Database class, FB_RTDB.cpp version 1.3.7 * * This library supports Espressif ESP8266 and ESP32 * @@ -809,6 +809,8 @@ void FB_RTDB::setMultiPathStreamCallback(FirebaseData *fbdo, FirebaseData::Multi fbdo->_multiPathDataCallback = multiPathDataCallback; fbdo->_timeoutCallback = timeoutCallback; + fbdo->addSO(); + #if defined(ESP32) MB_String taskName = fb_esp_pgm_str_72; taskName += fb_esp_pgm_str_113; @@ -880,6 +882,8 @@ void FB_RTDB::runStreamTask() { FirebaseData *_fbdo = addrTo(Signer.getCfg()->internal.so_addr_list[i]); + + if (_fbdo) { if (_fbdo->session.rtdb.stream_task_enable && (_fbdo->_dataAvailableCallback || _fbdo->_timeoutCallback)) @@ -3864,7 +3868,7 @@ bool FB_RTDB::sendHeader(FirebaseData *fbdo, struct fb_esp_rtdb_request_info_t * return true; } -#if defined(ESP32) || defined(ESP8266) + void FB_RTDB::removeStreamCallback(FirebaseData *fbdo) { FirebaseConfig *cfg = Signer.getCfg(); @@ -3890,7 +3894,6 @@ void FB_RTDB::removeStreamCallback(FirebaseData *fbdo) } } -#endif void FB_RTDB::clearDataStatus(FirebaseData *fbdo) { diff --git a/src/rtdb/FB_RTDB.h b/src/rtdb/FB_RTDB.h index 4ae8c4358..a851128a5 100644 --- a/src/rtdb/FB_RTDB.h +++ b/src/rtdb/FB_RTDB.h @@ -1,5 +1,5 @@ /** - * Google's Firebase Realtime Database class, FB_RTDB.h version 1.3.6 + * Google's Firebase Realtime Database class, FB_RTDB.h version 1.3.7 * * This library supports Espressif ESP8266 and ESP32 *