From 84a3f43af98294f62e2ec3e40c87d95120c310d7 Mon Sep 17 00:00:00 2001 From: suwatchai Date: Sun, 4 Jul 2021 18:27:54 +0700 Subject: [PATCH] Fix RTDB data type mismatch, FireSense addon issue. Reduce memory usage. Remove RTDB's priority parameter in set and push of File and Blob functions. --- src/rtdb/FB_RTDB.cpp | 9 ++++++--- src/{ => rtdb}/stream/FB_MP_Stream.cpp | 0 src/{ => rtdb}/stream/FB_MP_Stream.h | 0 src/{ => rtdb}/stream/FB_Stream.cpp | 0 src/{ => rtdb}/stream/FB_Stream.h | 0 src/session/FB_Session.cpp | 28 ++++++++++++++++++-------- src/session/FB_Session.h | 6 +++--- 7 files changed, 29 insertions(+), 14 deletions(-) rename src/{ => rtdb}/stream/FB_MP_Stream.cpp (100%) rename src/{ => rtdb}/stream/FB_MP_Stream.h (100%) rename src/{ => rtdb}/stream/FB_Stream.cpp (100%) rename src/{ => rtdb}/stream/FB_Stream.h (100%) diff --git a/src/rtdb/FB_RTDB.cpp b/src/rtdb/FB_RTDB.cpp index 86c6d4fbc..00f286e8d 100644 --- a/src/rtdb/FB_RTDB.cpp +++ b/src/rtdb/FB_RTDB.cpp @@ -633,11 +633,14 @@ bool FB_RTDB::int_pushInt(FirebaseData *fbdo, const char *path, int intValue, bo void FB_RTDB::addJsonPriority(FirebaseData *fbdo, struct fb_esp_rtdb_request_info_t *req) { - if (req->data.jsonPtr) + if (req->data.jsonPtr && strlen(req->priority) > 0) { char *tmp = nullptr; tmp = ut->strP(fb_esp_pgm_str_157); - req->data.jsonPtr->add((const char *)tmp, req->priority); + if (ut->strposP(req->priority, fb_esp_pgm_str_4, 0) != -1) + req->data.jsonPtr->add((const char *)tmp, atof(req->priority)); + else + req->data.jsonPtr->add((const char *)tmp, atoi(req->priority)); ut->delS(tmp); } } @@ -4653,7 +4656,7 @@ bool FB_RTDB::handleResponse(FirebaseData *fbdo) } } - if (fbdo->_ss.rtdb.resp_data_type != d_null && fbdo->_ss.rtdb.req_data_type != d_timestamp && !response.noContent && fbdo->_ss.rtdb.req_method != m_post && fbdo->_ss.rtdb.req_method != m_get_shallow && response.httpCode < 400) + if (fbdo->_ss.rtdb.req_method != m_get_nocontent && fbdo->_ss.rtdb.req_data_type != d_timestamp && !response.noContent && fbdo->_ss.rtdb.req_method != m_post && fbdo->_ss.rtdb.req_method != m_get_shallow && response.httpCode < 400) { bool _reqType = fbdo->_ss.rtdb.req_data_type == d_integer || fbdo->_ss.rtdb.req_data_type == d_float || fbdo->_ss.rtdb.req_data_type == d_double; bool _respType = fbdo->_ss.rtdb.resp_data_type == d_integer || fbdo->_ss.rtdb.resp_data_type == d_float || fbdo->_ss.rtdb.resp_data_type == d_double; diff --git a/src/stream/FB_MP_Stream.cpp b/src/rtdb/stream/FB_MP_Stream.cpp similarity index 100% rename from src/stream/FB_MP_Stream.cpp rename to src/rtdb/stream/FB_MP_Stream.cpp diff --git a/src/stream/FB_MP_Stream.h b/src/rtdb/stream/FB_MP_Stream.h similarity index 100% rename from src/stream/FB_MP_Stream.h rename to src/rtdb/stream/FB_MP_Stream.h diff --git a/src/stream/FB_Stream.cpp b/src/rtdb/stream/FB_Stream.cpp similarity index 100% rename from src/stream/FB_Stream.cpp rename to src/rtdb/stream/FB_Stream.cpp diff --git a/src/stream/FB_Stream.h b/src/rtdb/stream/FB_Stream.h similarity index 100% rename from src/stream/FB_Stream.h rename to src/rtdb/stream/FB_Stream.h diff --git a/src/session/FB_Session.cpp b/src/session/FB_Session.cpp index fd54c6f42..0c5f3de98 100644 --- a/src/session/FB_Session.cpp +++ b/src/session/FB_Session.cpp @@ -1149,8 +1149,10 @@ void FCMObject::fcm_begin(FirebaseData &fbdo) fbdo.tcpClient.begin(host.c_str(), _port); } -void FCMObject::fcm_prepareHeader(std::string &header, size_t payloadSize) +int FCMObject::fcm_sendHeader(FirebaseData &fbdo, size_t payloadSize) { + int ret = -1; + std::string header; if (!ut) ut = new UtilsClass(nullptr); FirebaseJsonData server_key; @@ -1172,7 +1174,16 @@ void FCMObject::fcm_prepareHeader(std::string &header, size_t payloadSize) ut->appendP(header, fb_esp_pgm_str_21); ut->appendP(header, fb_esp_pgm_str_131); - header += server_key.stringValue.c_str(); + + ret = fbdo.tcpSend(header.c_str()); + ut->clearS(header); + if (ret < 0) + return ret; + + ret = fbdo.tcpSend(server_key.stringValue.c_str()); + if (ret < 0) + return ret; + ut->appendP(header, fb_esp_pgm_str_21); ut->appendP(header, fb_esp_pgm_str_32); @@ -1188,6 +1199,10 @@ void FCMObject::fcm_prepareHeader(std::string &header, size_t payloadSize) ut->appendP(header, fb_esp_pgm_str_21); ut->appendP(header, fb_esp_pgm_str_36); ut->appendP(header, fb_esp_pgm_str_21); + + ret = fbdo.tcpSend(header.c_str()); + ut->clearS(header); + return ret; } void FCMObject::fcm_preparePayload(fb_esp_fcm_msg_type messageType) @@ -1534,8 +1549,6 @@ bool FCMObject::fcm_send(FirebaseData &fbdo, fb_esp_fcm_msg_type messageType) if (!ut) ut = new UtilsClass(nullptr); - std::string header; - FirebaseJsonData msg; fcm_preparePayload(messageType); @@ -1545,10 +1558,9 @@ bool FCMObject::fcm_send(FirebaseData &fbdo, fb_esp_fcm_msg_type messageType) ut->appendP(s, fb_esp_pgm_str_575); json.get(msg, s.c_str()); - fcm_prepareHeader(header, msg.stringValue.length()); - - int ret = fbdo.tcpClient.send(header.c_str(), msg.stringValue.c_str()); - ut->clearS(header); + int ret = fcm_sendHeader(fbdo, msg.stringValue.length()); + if (ret == 0) + ret = fbdo.tcpSend(msg.stringValue.c_str()); json.remove(s.c_str()); ut->clearS(s); ut->clearS(raw); diff --git a/src/session/FB_Session.h b/src/session/FB_Session.h index ff918333f..976c90500 100644 --- a/src/session/FB_Session.h +++ b/src/session/FB_Session.h @@ -36,8 +36,8 @@ #define FIREBASE_SESSION_H #include #include "Utils.h" -#include "stream/FB_Stream.h" -#include "stream/FB_MP_Stream.h" +#include "rtdb/stream/FB_Stream.h" +#include "rtdb/stream/FB_MP_Stream.h" #include "rtdb/QueueInfo.h" #include "rtdb/QueueManager.h" @@ -180,7 +180,7 @@ class FCMObject bool fcm_send(FirebaseData &fbdo, fb_esp_fcm_msg_type messageType); - void fcm_prepareHeader(std::string &header, size_t payloadSize); + int fcm_sendHeader(FirebaseData &fbdo, size_t payloadSize); void fcm_preparePayload(fb_esp_fcm_msg_type messageType);