mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-13 15:36:51 +01:00
Fix gateway crash when subscribing to short topics (two octets length)
Signed-off-by: Mariusz Suchora <mariusz.suchora@tieto.com>
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Tomoaki Yamaguchi - initial API and implementation and/or initial documentation
|
* Tomoaki Yamaguchi - initial API and implementation and/or initial documentation
|
||||||
|
* Tieto Poland Sp. z o.o. - Gateway improvements
|
||||||
**************************************************************************************/
|
**************************************************************************************/
|
||||||
|
|
||||||
#include "MQTTSNGWSubscribeHandler.h"
|
#include "MQTTSNGWSubscribeHandler.h"
|
||||||
@@ -89,6 +90,7 @@ void MQTTSNSubscribeHandler::handleSubscribe(Client* client, MQTTSNPacket* packe
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
uint16_t topicId = 0;
|
||||||
MQTTGWPacket* subscribe = new MQTTGWPacket();
|
MQTTGWPacket* subscribe = new MQTTGWPacket();
|
||||||
topic = client->getTopics()->getTopic(&topicFilter);
|
topic = client->getTopics()->getTopic(&topicFilter);
|
||||||
if (topic == 0)
|
if (topic == 0)
|
||||||
@@ -96,6 +98,7 @@ void MQTTSNSubscribeHandler::handleSubscribe(Client* client, MQTTSNPacket* packe
|
|||||||
if (topicFilter.type == MQTTSN_TOPIC_TYPE_NORMAL)
|
if (topicFilter.type == MQTTSN_TOPIC_TYPE_NORMAL)
|
||||||
{
|
{
|
||||||
topic = client->getTopics()->add(&topicFilter);
|
topic = client->getTopics()->add(&topicFilter);
|
||||||
|
topicId = topic->getTopicId();
|
||||||
subscribe->setSUBSCRIBE((char*)topic->getTopicName()->c_str(), (uint8_t)qos, (uint16_t)msgId);
|
subscribe->setSUBSCRIBE((char*)topic->getTopicName()->c_str(), (uint8_t)qos, (uint16_t)msgId);
|
||||||
}
|
}
|
||||||
else if (topicFilter.type == MQTTSN_TOPIC_TYPE_SHORT)
|
else if (topicFilter.type == MQTTSN_TOPIC_TYPE_SHORT)
|
||||||
@@ -104,17 +107,19 @@ void MQTTSNSubscribeHandler::handleSubscribe(Client* client, MQTTSNPacket* packe
|
|||||||
topic[0] = topicFilter.data.short_name[0];
|
topic[0] = topicFilter.data.short_name[0];
|
||||||
topic[1] = topicFilter.data.short_name[1];
|
topic[1] = topicFilter.data.short_name[1];
|
||||||
topic[2] = 0;
|
topic[2] = 0;
|
||||||
|
topicId = topicFilter.data.id;
|
||||||
subscribe->setSUBSCRIBE(topic, (uint8_t)qos, (uint16_t)msgId);
|
subscribe->setSUBSCRIBE(topic, (uint8_t)qos, (uint16_t)msgId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
topicId = topic->getTopicId();
|
||||||
subscribe->setSUBSCRIBE((char*)topic->getTopicName()->c_str(), (uint8_t)qos, (uint16_t)msgId);
|
subscribe->setSUBSCRIBE((char*)topic->getTopicName()->c_str(), (uint8_t)qos, (uint16_t)msgId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( msgId > 0 )
|
if ( msgId > 0 )
|
||||||
{
|
{
|
||||||
client->setWaitedSubTopicId(msgId, topic->getTopicId(), topicFilter.type);
|
client->setWaitedSubTopicId(msgId, topicId, topicFilter.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
Event* ev1 = new Event();
|
Event* ev1 = new Event();
|
||||||
|
|||||||
Reference in New Issue
Block a user