2222#include < regex>
2323#include < mutex>
2424
25- #define RSCP2MQTT_VERSION " 3.36 "
25+ #define RSCP2MQTT_VERSION " 3.37 "
2626
2727#define AES_KEY_SIZE 32
2828#define AES_BLOCK_SIZE 32
@@ -126,7 +126,13 @@ char *tagName(std::vector<RSCP_TAGS::tag_overview_t> & v, uint32_t tag) {
126126 return (it->name );
127127 }
128128 }
129- return (NULL );
129+ char name[128 ];
130+ sprintf (name, " 0x%02X" , tag);
131+ RSCP_TAGS::tag_overview_t tag_overview = { tag, " " , 0 };
132+ strcpy (tag_overview.name , name);
133+ RSCP_TAGS::RscpTagsOverview.push_back (tag_overview);
134+ logMessage (cfg.logfile , (char *)__FILE__, __LINE__, (char *)" tagName: new tag >%s<\n " , name);
135+ return (tagName (v, tag));
130136}
131137
132138uint32_t tagID (std::vector<RSCP_TAGS::tag_overview_t > & v, char *name) {
@@ -148,12 +154,14 @@ bool isTag(std::vector<RSCP_TAGS::tag_overview_t> & v, char *name, bool must_be_
148154}
149155
150156char *typeName (std::vector<RSCP_TAGS::rscp_types_t > & v, uint8_t code) {
157+ char *unknown = NULL ;
151158 for (std::vector<RSCP_TAGS::rscp_types_t >::iterator it = v.begin (); it != v.end (); ++it) {
159+ if (!it->code ) unknown = it->type ;
152160 if (it->code == code) {
153161 return (it->type );
154162 }
155163 }
156- return (NULL );
164+ return (unknown );
157165}
158166
159167uint8_t typeID (std::vector<RSCP_TAGS::rscp_types_t > & v, char *type) {
@@ -870,7 +878,7 @@ int mergeRawData(char *topic, char *payload, bool *changed) {
870878 if (!strcmp (it->topic , topic) && !it->handled && (i == it->nr )) {
871879 if (strcmp (it->payload , payload)) {
872880 if (strlen (it->payload ) != strlen (payload)) it->payload = (char *)realloc (it->payload , strlen (payload) + 1 );
873- strcpy (it->payload , payload);
881+ if (it-> payload ) strcpy (it->payload , payload);
874882 it->changed = true ;
875883 *changed = true ;
876884 }
@@ -2125,18 +2133,20 @@ void publishRaw(RscpProtocol *protocol, SRscpValue *response, char *topic_in) {
21252133 char topic[TOPIC_SIZE];
21262134 char *payload = (char *)malloc (PAYLOAD_SIZE * sizeof (char ) + 1 );
21272135 bool changed = false ;
2128- memset (payload, 0 , PAYLOAD_SIZE);
2129- preparePayload (protocol, response, &payload);
2136+ if (payload) {
2137+ memset (payload, 0 , PAYLOAD_SIZE);
2138+ preparePayload (protocol, response, &payload);
21302139
2131- int nr = mergeRawData (topic_in, payload, &changed);
2132- if (nr > 0 ) {
2133- if (snprintf (topic, TOPIC_SIZE, " %s/%d" , topic_in, nr) >= TOPIC_SIZE) {
2134- logMessage (cfg.logfile , (char *)__FILE__, __LINE__, (char *)" publishRaw: Buffer overflow\n " );
2135- return ;
2136- }
2137- if (changed) publishImmediately (topic, payload, false );
2138- } else if (changed) publishImmediately (topic_in, payload, false );
2139- if (payload) free (payload);
2140+ int nr = mergeRawData (topic_in, payload, &changed);
2141+ if (nr > 0 ) {
2142+ if (snprintf (topic, TOPIC_SIZE, " %s/%d" , topic_in, nr) >= TOPIC_SIZE) {
2143+ logMessage (cfg.logfile , (char *)__FILE__, __LINE__, (char *)" publishRaw: Buffer overflow\n " );
2144+ return ;
2145+ }
2146+ if (changed) publishImmediately (topic, payload, false );
2147+ } else if (changed) publishImmediately (topic_in, payload, false );
2148+ free (payload);
2149+ }
21402150 return ;
21412151}
21422152
@@ -2325,6 +2335,7 @@ int handleResponseValue(RscpProtocol *protocol, SRscpValue *response) {
23252335 if (storeResponseValue (RSCP_MQTT::RscpMqttCache, protocol, &(subcontainer[k]), containerData[i].tag , dcb_nr) < 0 ) break ;
23262336 }
23272337 }
2338+ protocol->destroyValueData (subcontainer); // Issue #107
23282339 }
23292340 }
23302341 }
@@ -3614,6 +3625,11 @@ int main(int argc, char *argv[]) {
36143625 logMessageCache (cfg.logfile , false );
36153626 }
36163627
3628+ for (std::vector<RSCP_MQTT::raw_data_t >::iterator it = RSCP_MQTT::rawData.begin (); it != RSCP_MQTT::rawData.end (); ++it) {
3629+ if (it->topic ) free (it->topic );
3630+ if (it->payload ) free (it->payload );
3631+ }
3632+
36173633 RSCP_MQTT::RscpMqttCache.clear ();
36183634 RSCP_MQTT::RscpMqttCacheTempl.clear ();
36193635 RSCP_MQTT::RscpMqttReceiveCache.clear ();
@@ -3623,6 +3639,7 @@ int main(int argc, char *argv[]) {
36233639 RSCP_MQTT::TopicStore.clear ();
36243640 RSCP_MQTT::IdlePeriodCache.clear ();
36253641 RSCP_MQTT::ErrorCache.clear ();
3642+ RSCP_MQTT::rawData.clear ();
36263643
36273644 // MQTT disconnect
36283645 mosquitto_disconnect (mosq);
@@ -3638,6 +3655,7 @@ int main(int argc, char *argv[]) {
36383655 if (cfg.curl_opt_cainfo ) free (cfg.curl_opt_cainfo );
36393656 if (cfg.curl_opt_sslcert ) free (cfg.curl_opt_sslcert );
36403657 if (cfg.curl_opt_sslkey ) free (cfg.curl_opt_sslkey );
3658+ if (cfg.curl_protocol ) free (cfg.curl_protocol );
36413659#endif
36423660
36433661 if (cfg.logfile ) free (cfg.logfile );
0 commit comments