|
@@ -1,225 +1,225 @@
|
|
#include "pch.h"
|
|
#include "pch.h"
|
|
#include <proto/MqttPacket.h>
|
|
#include <proto/MqttPacket.h>
|
|
|
|
|
|
-int mqttReadInt(const char** pptr)
|
|
|
|
|
|
+int mqttReadInt(const char **pptr)
|
|
{
|
|
{
|
|
- const char* ptr = *pptr;
|
|
|
|
- int len = 256 * ((unsigned char)(*ptr)) + (unsigned char)(*(ptr + 1));
|
|
|
|
- *pptr += 2;
|
|
|
|
- return len;
|
|
|
|
|
|
+ const char *ptr = *pptr;
|
|
|
|
+ int len = 256 * ((unsigned char)(*ptr)) + (unsigned char)(*(ptr + 1));
|
|
|
|
+ *pptr += 2;
|
|
|
|
+ return len;
|
|
}
|
|
}
|
|
|
|
|
|
-char* mqttReadUTFlen(const char** pptr, const char* enddata, int* len)
|
|
|
|
|
|
+char *mqttReadUTFlen(const char **pptr, const char *enddata, int *len)
|
|
{
|
|
{
|
|
- char* string = NULL;
|
|
|
|
|
|
+ char *string = NULL;
|
|
|
|
|
|
- FUNC_ENTRY;
|
|
|
|
- if (enddata - (*pptr) > 1) /* enough length to read the integer? */
|
|
|
|
- {
|
|
|
|
- *len = mqttReadInt(pptr);
|
|
|
|
- if (&(*pptr)[*len] <= enddata)
|
|
|
|
- {
|
|
|
|
- if ((string = (char*)malloc(*len + 1)) == NULL)
|
|
|
|
- goto exit;
|
|
|
|
- memcpy(string, *pptr, *len);
|
|
|
|
- string[*len] = '\0';
|
|
|
|
- *pptr += *len;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ FUNC_ENTRY;
|
|
|
|
+ if (enddata - (*pptr) > 1) /* enough length to read the integer? */
|
|
|
|
+ {
|
|
|
|
+ *len = mqttReadInt(pptr);
|
|
|
|
+ if (&(*pptr)[*len] <= enddata)
|
|
|
|
+ {
|
|
|
|
+ if ((string = (char *)malloc(*len + 1)) == NULL)
|
|
|
|
+ goto exit;
|
|
|
|
+ memcpy(string, *pptr, *len);
|
|
|
|
+ string[*len] = '\0';
|
|
|
|
+ *pptr += *len;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
exit:
|
|
exit:
|
|
- FUNC_EXIT;
|
|
|
|
- return string;
|
|
|
|
|
|
+ FUNC_EXIT;
|
|
|
|
+ return string;
|
|
}
|
|
}
|
|
|
|
|
|
-char* mqttReadUTF(const char** pptr, const char* enddata)
|
|
|
|
|
|
+char *mqttReadUTF(const char **pptr, const char *enddata)
|
|
{
|
|
{
|
|
- int len;
|
|
|
|
- return mqttReadUTFlen(pptr, enddata, &len);
|
|
|
|
|
|
+ int len;
|
|
|
|
+ return mqttReadUTFlen(pptr, enddata, &len);
|
|
}
|
|
}
|
|
|
|
|
|
-unsigned char mqttReadChar(const char** pptr)
|
|
|
|
|
|
+unsigned char mqttReadChar(const char **pptr)
|
|
{
|
|
{
|
|
- unsigned char c = **pptr;
|
|
|
|
- (*pptr)++;
|
|
|
|
- return c;
|
|
|
|
|
|
+ unsigned char c = **pptr;
|
|
|
|
+ (*pptr)++;
|
|
|
|
+ return c;
|
|
}
|
|
}
|
|
|
|
|
|
-void mqttReadHeader(const char** pptr, MqttHeader& header, size_t* value)
|
|
|
|
|
|
+void mqttReadHeader(const char **pptr, MqttHeader &header, size_t *value)
|
|
{
|
|
{
|
|
- unsigned char h = **pptr;
|
|
|
|
- memcpy(&header, &h, 1);
|
|
|
|
- (*pptr)++;
|
|
|
|
|
|
+ unsigned char h = **pptr;
|
|
|
|
+ memcpy(&header, &h, 1);
|
|
|
|
+ (*pptr)++;
|
|
|
|
|
|
- char c;
|
|
|
|
- int multiplier = 1;
|
|
|
|
- int len = 0;
|
|
|
|
|
|
+ char c;
|
|
|
|
+ int multiplier = 1;
|
|
|
|
+ int len = 0;
|
|
#define MAX_NO_OF_REMAINING_LENGTH_BYTES 4
|
|
#define MAX_NO_OF_REMAINING_LENGTH_BYTES 4
|
|
|
|
|
|
- FUNC_ENTRY;
|
|
|
|
- *value = 0;
|
|
|
|
- do
|
|
|
|
- {
|
|
|
|
- if (++len > MAX_NO_OF_REMAINING_LENGTH_BYTES)
|
|
|
|
- {
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- c = **pptr;
|
|
|
|
- (*pptr)++;
|
|
|
|
- *value += (c & 127) * multiplier;
|
|
|
|
- multiplier *= 128;
|
|
|
|
- } while ((c & 128) != 0);
|
|
|
|
|
|
+ FUNC_ENTRY;
|
|
|
|
+ *value = 0;
|
|
|
|
+ do
|
|
|
|
+ {
|
|
|
|
+ if (++len > MAX_NO_OF_REMAINING_LENGTH_BYTES)
|
|
|
|
+ {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ c = **pptr;
|
|
|
|
+ (*pptr)++;
|
|
|
|
+ *value += (c & 127) * multiplier;
|
|
|
|
+ multiplier *= 128;
|
|
|
|
+ } while ((c & 128) != 0);
|
|
}
|
|
}
|
|
|
|
|
|
-void mqttWriteChar(std::string& buffer, char c)
|
|
|
|
|
|
+void mqttWriteChar(std::string &buffer, char c)
|
|
{
|
|
{
|
|
- buffer.append(&c, 1);
|
|
|
|
|
|
+ buffer.append(&c, 1);
|
|
}
|
|
}
|
|
|
|
|
|
-void mqttWriteChar(char** pptr, char c)
|
|
|
|
|
|
+void mqttWriteChar(char **pptr, char c)
|
|
{
|
|
{
|
|
- **pptr = c;
|
|
|
|
- (*pptr)++;
|
|
|
|
|
|
+ **pptr = c;
|
|
|
|
+ (*pptr)++;
|
|
}
|
|
}
|
|
|
|
|
|
-void mqttWriteInt(std::string& buffer, int anInt)
|
|
|
|
|
|
+void mqttWriteInt(std::string &buffer, int anInt)
|
|
{
|
|
{
|
|
- char ch[2];
|
|
|
|
- ch[0] = (char)(anInt / 256);
|
|
|
|
- ch[1] = (char)(anInt % 256);
|
|
|
|
- buffer.append(ch, 2);
|
|
|
|
|
|
+ char ch[2];
|
|
|
|
+ ch[0] = (char)(anInt / 256);
|
|
|
|
+ ch[1] = (char)(anInt % 256);
|
|
|
|
+ buffer.append(ch, 2);
|
|
}
|
|
}
|
|
|
|
|
|
-void mqttWriteInt(char** pptr, int anInt)
|
|
|
|
|
|
+void mqttWriteInt(char **pptr, int anInt)
|
|
{
|
|
{
|
|
- **pptr = (char)(anInt / 256);
|
|
|
|
- (*pptr)++;
|
|
|
|
- **pptr = (char)(anInt % 256);
|
|
|
|
- (*pptr)++;
|
|
|
|
|
|
+ **pptr = (char)(anInt / 256);
|
|
|
|
+ (*pptr)++;
|
|
|
|
+ **pptr = (char)(anInt % 256);
|
|
|
|
+ (*pptr)++;
|
|
}
|
|
}
|
|
|
|
|
|
-void mqttWriteUTF(char** pptr, const char* string)
|
|
|
|
|
|
+void mqttWriteUTF(char **pptr, const char *string)
|
|
{
|
|
{
|
|
- size_t len = strlen(string);
|
|
|
|
- mqttWriteInt(pptr, (int)len);
|
|
|
|
- memcpy(*pptr, string, len);
|
|
|
|
- *pptr += len;
|
|
|
|
|
|
+ size_t len = strlen(string);
|
|
|
|
+ mqttWriteInt(pptr, (int)len);
|
|
|
|
+ memcpy(*pptr, string, len);
|
|
|
|
+ *pptr += len;
|
|
}
|
|
}
|
|
|
|
|
|
-void mqttWriteUTF(std::string& buffer, const char* string)
|
|
|
|
|
|
+void mqttWriteUTF(std::string &buffer, const char *string)
|
|
{
|
|
{
|
|
- size_t len = strlen(string);
|
|
|
|
- mqttWriteInt(buffer, (int)len);
|
|
|
|
- buffer.append(string, len);
|
|
|
|
|
|
+ size_t len = strlen(string);
|
|
|
|
+ mqttWriteInt(buffer, (int)len);
|
|
|
|
+ buffer.append(string, len);
|
|
}
|
|
}
|
|
|
|
|
|
-void mqttWriteData(char** pptr, const void* data, int datalen)
|
|
|
|
|
|
+void mqttWriteData(char **pptr, const void *data, int datalen)
|
|
{
|
|
{
|
|
- mqttWriteInt(pptr, datalen);
|
|
|
|
- memcpy(*pptr, data, datalen);
|
|
|
|
- *pptr += datalen;
|
|
|
|
|
|
+ mqttWriteInt(pptr, datalen);
|
|
|
|
+ memcpy(*pptr, data, datalen);
|
|
|
|
+ *pptr += datalen;
|
|
}
|
|
}
|
|
|
|
|
|
-void mqttWriteDataNoLen(char** pptr, const void* data, int datalen)
|
|
|
|
|
|
+void mqttWriteDataNoLen(char **pptr, const void *data, int datalen)
|
|
{
|
|
{
|
|
- memcpy(*pptr, data, datalen);
|
|
|
|
- *pptr += datalen;
|
|
|
|
|
|
+ memcpy(*pptr, data, datalen);
|
|
|
|
+ *pptr += datalen;
|
|
}
|
|
}
|
|
|
|
|
|
-void mqttWriteData(std::string& buffer, const void* data, int datalen)
|
|
|
|
|
|
+void mqttWriteData(std::string &buffer, const void *data, int datalen)
|
|
{
|
|
{
|
|
- mqttWriteInt(buffer, datalen);
|
|
|
|
- buffer.append((const char*)data, datalen);
|
|
|
|
|
|
+ mqttWriteInt(buffer, datalen);
|
|
|
|
+ buffer.append((const char *)data, datalen);
|
|
}
|
|
}
|
|
-void mqttWriteDataNoLen(std::string& buffer, const void* data, int datalen)
|
|
|
|
|
|
+void mqttWriteDataNoLen(std::string &buffer, const void *data, int datalen)
|
|
{
|
|
{
|
|
- buffer.append((const char*)data, datalen);
|
|
|
|
|
|
+ buffer.append((const char *)data, datalen);
|
|
}
|
|
}
|
|
|
|
|
|
-void mqttWriteHeader(std::string& buffer, MqttHeader& header, size_t len)
|
|
|
|
|
|
+void mqttWriteHeader(std::string &buffer, MqttHeader &header, size_t len)
|
|
{
|
|
{
|
|
- mqttWriteChar(buffer, header.byte);
|
|
|
|
- do
|
|
|
|
- {
|
|
|
|
- char d = len % 128;
|
|
|
|
- len /= 128;
|
|
|
|
- /* if there are more digits to encode, set the top bit of this digit */
|
|
|
|
- if (len > 0)
|
|
|
|
- d |= 0x80;
|
|
|
|
- buffer.append(&d, 1);
|
|
|
|
- } while (len > 0);
|
|
|
|
|
|
+ mqttWriteChar(buffer, header.byte);
|
|
|
|
+ do
|
|
|
|
+ {
|
|
|
|
+ char d = len % 128;
|
|
|
|
+ len /= 128;
|
|
|
|
+ /* if there are more digits to encode, set the top bit of this digit */
|
|
|
|
+ if (len > 0)
|
|
|
|
+ d |= 0x80;
|
|
|
|
+ buffer.append(&d, 1);
|
|
|
|
+ } while (len > 0);
|
|
}
|
|
}
|
|
|
|
|
|
-int mqttToBuffer(MqttConnectPacket* packet, std::string& buffer)
|
|
|
|
|
|
+int mqttToBuffer(MqttConnectPacket *packet, std::string &buffer)
|
|
{
|
|
{
|
|
- int rc = 0;
|
|
|
|
- FUNC_ENTRY;
|
|
|
|
- size_t len = 10;
|
|
|
|
- if (packet->version >= MqttVersion_5)
|
|
|
|
- len++;
|
|
|
|
- len += packet->clientID.length() + 2;
|
|
|
|
- if (packet->flags.bits.username)
|
|
|
|
- len += packet->username.length() + 2;
|
|
|
|
- if (packet->flags.bits.password)
|
|
|
|
- len += packet->password.length() + 2;
|
|
|
|
- if (packet->payload.length() > 0)
|
|
|
|
- len += packet->payload.length() + 2;
|
|
|
|
|
|
+ int rc = 0;
|
|
|
|
+ FUNC_ENTRY;
|
|
|
|
+ size_t len = 10;
|
|
|
|
+ if (packet->version >= MqttVersion_5)
|
|
|
|
+ len++;
|
|
|
|
+ len += packet->clientID.length() + 2;
|
|
|
|
+ if (packet->flags.bits.username)
|
|
|
|
+ len += packet->username.length() + 2;
|
|
|
|
+ if (packet->flags.bits.password)
|
|
|
|
+ len += packet->password.length() + 2;
|
|
|
|
+ if (packet->payload.length() > 0)
|
|
|
|
+ len += packet->payload.length() + 2;
|
|
|
|
|
|
- mqttWriteHeader(buffer, packet->header, len);
|
|
|
|
|
|
+ mqttWriteHeader(buffer, packet->header, len);
|
|
|
|
|
|
- mqttWriteUTF(buffer, "MQTT");
|
|
|
|
- mqttWriteChar(buffer, packet->version);
|
|
|
|
- mqttWriteChar(buffer, packet->flags.all);
|
|
|
|
- mqttWriteInt(buffer, packet->keepAliveTimer);
|
|
|
|
- if (packet->version >= MqttVersion_5)
|
|
|
|
- mqttWriteChar(buffer, 0);
|
|
|
|
- mqttWriteUTF(buffer, packet->clientID.c_str());
|
|
|
|
- /*if (client->will)
|
|
|
|
|
|
+ mqttWriteUTF(buffer, "MQTT");
|
|
|
|
+ mqttWriteChar(buffer, packet->version);
|
|
|
|
+ mqttWriteChar(buffer, packet->flags.all);
|
|
|
|
+ mqttWriteInt(buffer, packet->keepAliveTimer);
|
|
|
|
+ if (packet->version >= MqttVersion_5)
|
|
|
|
+ mqttWriteChar(buffer, 0);
|
|
|
|
+ mqttWriteUTF(buffer, packet->clientID.c_str());
|
|
|
|
+ /*if (client->will)
|
|
{
|
|
{
|
|
if (packet->version >= MqttVersion_5)
|
|
if (packet->version >= MqttVersion_5)
|
|
MQTTProperties_write(&ptr, willProperties);
|
|
MQTTProperties_write(&ptr, willProperties);
|
|
writeUTF(&ptr, client->will->topic);
|
|
writeUTF(&ptr, client->will->topic);
|
|
writeData(&ptr, client->will->payload, client->will->payloadlen);
|
|
writeData(&ptr, client->will->payload, client->will->payloadlen);
|
|
}*/
|
|
}*/
|
|
- if (packet->flags.bits.username)
|
|
|
|
- mqttWriteUTF(buffer, packet->username.c_str());
|
|
|
|
- if (packet->flags.bits.password)
|
|
|
|
- mqttWriteData(buffer, packet->password.c_str(), packet->password.length());
|
|
|
|
- if (packet->payload.length() > 0)
|
|
|
|
- mqttWriteData(buffer, packet->payload.c_str(), packet->payload.length());
|
|
|
|
|
|
+ if (packet->flags.bits.username)
|
|
|
|
+ mqttWriteUTF(buffer, packet->username.c_str());
|
|
|
|
+ if (packet->flags.bits.password)
|
|
|
|
+ mqttWriteData(buffer, packet->password.c_str(), packet->password.length());
|
|
|
|
+ if (packet->payload.length() > 0)
|
|
|
|
+ mqttWriteData(buffer, packet->payload.c_str(), packet->payload.length());
|
|
clean:
|
|
clean:
|
|
- FUNC_EXIT_RC(rc);
|
|
|
|
- return rc;
|
|
|
|
|
|
+ FUNC_EXIT_RC(rc);
|
|
|
|
+ return rc;
|
|
}
|
|
}
|
|
|
|
|
|
-int mqttToBuffer(MqttPublishPacket* packet, std::string& buffer)
|
|
|
|
|
|
+int mqttToBuffer(MqttPublishPacket *packet, std::string &buffer)
|
|
{
|
|
{
|
|
- int rc = 0;
|
|
|
|
- FUNC_ENTRY;
|
|
|
|
|
|
+ int rc = 0;
|
|
|
|
+ FUNC_ENTRY;
|
|
|
|
|
|
- size_t len = 5;
|
|
|
|
- len += packet->payload.length() + packet->topic.length();
|
|
|
|
- mqttWriteHeader(buffer, packet->header, len);
|
|
|
|
- mqttWriteUTF(buffer, packet->topic.c_str());
|
|
|
|
- mqttWriteInt(buffer, packet->msgId);
|
|
|
|
- mqttWriteChar(buffer, 0);
|
|
|
|
- if (packet->payload.length() > 0)
|
|
|
|
- mqttWriteDataNoLen(buffer, packet->payload.c_str(), packet->payload.length());
|
|
|
|
|
|
+ size_t len = 5;
|
|
|
|
+ len += packet->payload.length() + packet->topic.length();
|
|
|
|
+ mqttWriteHeader(buffer, packet->header, len);
|
|
|
|
+ mqttWriteUTF(buffer, packet->topic.c_str());
|
|
|
|
+ mqttWriteInt(buffer, packet->msgId);
|
|
|
|
+ mqttWriteChar(buffer, 0);
|
|
|
|
+ if (packet->payload.length() > 0)
|
|
|
|
+ mqttWriteDataNoLen(buffer, packet->payload.c_str(), packet->payload.length());
|
|
clean:
|
|
clean:
|
|
- FUNC_EXIT_RC(rc);
|
|
|
|
- return rc;
|
|
|
|
|
|
+ FUNC_EXIT_RC(rc);
|
|
|
|
+ return rc;
|
|
}
|
|
}
|
|
|
|
|
|
-int mqttFromBuffer(MqttConnAckPacket* packet, std::vector<uint8_t>& buffer)
|
|
|
|
|
|
+int mqttFromBuffer(MqttConnAckPacket *packet, std::vector<uint8_t> &buffer)
|
|
{
|
|
{
|
|
- int rc = 0;
|
|
|
|
- FUNC_ENTRY;
|
|
|
|
- const char* curdata = (const char*)&buffer[0];
|
|
|
|
- const char* enddata = (const char*)&buffer[buffer.size() - 1];
|
|
|
|
- size_t len = 0;
|
|
|
|
- mqttReadHeader(&curdata, packet->header, &len);
|
|
|
|
- packet->flags.all = mqttReadChar(&curdata); /* connect flags */
|
|
|
|
- packet->rc = mqttReadChar(&curdata); /* reason code */
|
|
|
|
- /*if (MQTTVersion >= MQTTVERSION_5 && datalen > 2)
|
|
|
|
|
|
+ int rc = 0;
|
|
|
|
+ FUNC_ENTRY;
|
|
|
|
+ const char *curdata = (const char *)&buffer[0];
|
|
|
|
+ const char *enddata = (const char *)&buffer[buffer.size() - 1];
|
|
|
|
+ size_t len = 0;
|
|
|
|
+ mqttReadHeader(&curdata, packet->header, &len);
|
|
|
|
+ packet->flags.all = mqttReadChar(&curdata); /* connect flags */
|
|
|
|
+ packet->rc = mqttReadChar(&curdata); /* reason code */
|
|
|
|
+ /*if (MQTTVersion >= MQTTVERSION_5 && datalen > 2)
|
|
{
|
|
{
|
|
MQTTProperties props = MQTTProperties_initializer;
|
|
MQTTProperties props = MQTTProperties_initializer;
|
|
pack->properties = props;
|
|
pack->properties = props;
|
|
@@ -233,61 +233,61 @@ int mqttFromBuffer(MqttConnAckPacket* packet, std::vector<uint8_t>& buffer)
|
|
goto exit;
|
|
goto exit;
|
|
}
|
|
}
|
|
}*/
|
|
}*/
|
|
- len = mqttReadChar(&curdata);
|
|
|
|
- curdata = curdata + len;
|
|
|
|
- if (curdata != enddata)
|
|
|
|
- {
|
|
|
|
- packet->payload.append(curdata, enddata - curdata + 1);
|
|
|
|
- }
|
|
|
|
|
|
+ len = mqttReadChar(&curdata);
|
|
|
|
+ curdata = curdata + len;
|
|
|
|
+ if (curdata != enddata)
|
|
|
|
+ {
|
|
|
|
+ packet->payload.append(curdata, enddata - curdata + 1);
|
|
|
|
+ }
|
|
clean:
|
|
clean:
|
|
- FUNC_EXIT_RC(rc);
|
|
|
|
- return rc;
|
|
|
|
|
|
+ FUNC_EXIT_RC(rc);
|
|
|
|
+ return rc;
|
|
}
|
|
}
|
|
|
|
|
|
-int mqttFromBuffer(MqttPubAckPacket* packet, std::vector<uint8_t>& buffer)
|
|
|
|
|
|
+int mqttFromBuffer(MqttPubAckPacket *packet, std::vector<uint8_t> &buffer)
|
|
{
|
|
{
|
|
- int rc = 0;
|
|
|
|
- FUNC_ENTRY;
|
|
|
|
- const char* curdata = (const char*)&buffer[0];
|
|
|
|
- const char* enddata = (const char*)&buffer[buffer.size() - 1];
|
|
|
|
- size_t len = 0;
|
|
|
|
- mqttReadHeader(&curdata, packet->header, &len);
|
|
|
|
- packet->msgId = mqttReadInt(&curdata);
|
|
|
|
- packet->rc = mqttReadChar(&curdata);
|
|
|
|
- mqttReadChar(&curdata);
|
|
|
|
- if (curdata != enddata)
|
|
|
|
- {
|
|
|
|
- packet->payload.append(curdata, enddata - curdata + 1);
|
|
|
|
- }
|
|
|
|
|
|
+ int rc = 0;
|
|
|
|
+ FUNC_ENTRY;
|
|
|
|
+ const char *curdata = (const char *)&buffer[0];
|
|
|
|
+ const char *enddata = (const char *)&buffer[buffer.size() - 1];
|
|
|
|
+ size_t len = 0;
|
|
|
|
+ mqttReadHeader(&curdata, packet->header, &len);
|
|
|
|
+ packet->msgId = mqttReadInt(&curdata);
|
|
|
|
+ packet->rc = mqttReadChar(&curdata);
|
|
|
|
+ mqttReadChar(&curdata);
|
|
|
|
+ if (curdata != enddata)
|
|
|
|
+ {
|
|
|
|
+ packet->payload.append(curdata, enddata - curdata + 1);
|
|
|
|
+ }
|
|
clean:
|
|
clean:
|
|
- FUNC_EXIT_RC(rc);
|
|
|
|
- return rc;
|
|
|
|
|
|
+ FUNC_EXIT_RC(rc);
|
|
|
|
+ return rc;
|
|
}
|
|
}
|
|
|
|
|
|
-int mqttFromBuffer(MqttPublishPacket* packet, std::vector<uint8_t>& buffer)
|
|
|
|
|
|
+int mqttFromBuffer(MqttPublishPacket *packet, std::vector<uint8_t> &buffer)
|
|
{
|
|
{
|
|
- int rc = 0;
|
|
|
|
- FUNC_ENTRY;
|
|
|
|
- const char* curdata = (const char*)&buffer[0];
|
|
|
|
- const char* enddata = (const char*)&buffer[buffer.size() - 1];
|
|
|
|
- size_t len = 0;
|
|
|
|
- mqttReadHeader(&curdata, packet->header, &len);
|
|
|
|
|
|
+ int rc = 0;
|
|
|
|
+ FUNC_ENTRY;
|
|
|
|
+ const char *curdata = (const char *)&buffer[0];
|
|
|
|
+ const char *enddata = (const char *)&buffer[buffer.size() - 1];
|
|
|
|
+ size_t len = 0;
|
|
|
|
+ mqttReadHeader(&curdata, packet->header, &len);
|
|
|
|
|
|
- auto topic = mqttReadUTF(&curdata, enddata);
|
|
|
|
- if (topic != nullptr)
|
|
|
|
- {
|
|
|
|
- packet->topic = topic;
|
|
|
|
- free(topic);
|
|
|
|
- }
|
|
|
|
|
|
+ auto topic = mqttReadUTF(&curdata, enddata);
|
|
|
|
+ if (topic != nullptr)
|
|
|
|
+ {
|
|
|
|
+ packet->topic = topic;
|
|
|
|
+ free(topic);
|
|
|
|
+ }
|
|
|
|
|
|
- packet->msgId = mqttReadInt(&curdata);
|
|
|
|
- mqttReadChar(&curdata);
|
|
|
|
|
|
+ packet->msgId = 0; //mqttReadInt(&curdata);
|
|
|
|
+ mqttReadChar(&curdata);
|
|
|
|
|
|
- if (curdata != enddata)
|
|
|
|
- {
|
|
|
|
- packet->payload.append(curdata, enddata - curdata + 1);
|
|
|
|
- }
|
|
|
|
|
|
+ if (curdata != enddata)
|
|
|
|
+ {
|
|
|
|
+ packet->payload.append(curdata, enddata - curdata + 1);
|
|
|
|
+ }
|
|
clean:
|
|
clean:
|
|
- FUNC_EXIT_RC(rc);
|
|
|
|
- return rc;
|
|
|
|
|
|
+ FUNC_EXIT_RC(rc);
|
|
|
|
+ return rc;
|
|
}
|
|
}
|