Merge pull request #162 from eclipse/develop

BugFix of #149 and #151
This commit is contained in:
Tomoaki Yamaguchi
2019-07-27 12:32:20 +09:00
committed by GitHub
11 changed files with 105 additions and 56 deletions

View File

@@ -416,9 +416,9 @@ Client* ClientList::createClient(SensorNetAddress* addr, MQTTSNString* clientId,
Client* ClientList::createPredefinedTopic( MQTTSNString* clientId, string topicName, uint16_t topicId, bool aggregate)
{
if ( clientId->cstring == common_topic )
if ( strcmp(clientId->cstring, common_topic) == 0 )
{
_gateway->getTopics()->add((const char*)topicName.c_str(), topicId);
theGateway->getTopics()->add((const char*)topicName.c_str(), topicId);
return 0;
}
else

View File

@@ -18,6 +18,7 @@
#include "MQTTSNGateway.h"
#include "MQTTSNGWEncapsulatedPacket.h"
#include "MQTTSNGWQoSm1Proxy.h"
#include <errno.h>
using namespace MQTTSNGW;
using namespace std;
@@ -75,8 +76,8 @@ void ClientSendTask::run()
if ( rc < 0 )
{
WRITELOG("%s ClientSendTask can't send a packet to the client %s%s.\n",
ERRMSG_HEADER, (client ? (const char*)client->getClientId() : UNKNOWNCL ), ERRMSG_FOOTER);
WRITELOG("%s ClientSendTask can't send a packet to the client %s. Error=%d%s\n",
ERRMSG_HEADER, (client ? (const char*)client->getClientId() : UNKNOWNCL ), errno, ERRMSG_FOOTER);
}
delete ev;
}

View File

@@ -13,8 +13,6 @@
* Contributors:
* Tomoaki Yamaguchi - initial API and implementation and/or initial documentation
**************************************************************************************/
#define RINGBUFFER
#include "MQTTSNGWProcess.h"
#include "MQTTSNGWLogmonitor.h"
#include <stdio.h>

View File

@@ -60,25 +60,22 @@ MQTTGWPacket* MQTTSNSubscribeHandler::handleSubscribe(Client* client, MQTTSNPack
{
topic = client->getTopics()->getTopicById(&topicFilter);
if ( topic )
{
topicId = topic->getTopicId();
subscribe = new MQTTGWPacket();
subscribe->setSUBSCRIBE((char*)topic->getTopicName()->c_str(), (uint8_t)qos, (uint16_t)msgId);
}
else
if ( !topic )
{
topic = _gateway->getTopics()->getTopicById(&topicFilter);
if ( !topic )
{
if ( topic )
{
topic = client->getTopics()->add(topic->getTopicName()->c_str(), topic->getTopicId());
}
else
{
goto RespExit;
}
else
{
goto RespExit;
}
}
topicId = topic->getTopicId();
subscribe = new MQTTGWPacket();
subscribe->setSUBSCRIBE((char*)topic->getTopicName()->c_str(), (uint8_t)qos, (uint16_t)msgId);
}
else if (topicFilter.type == MQTTSN_TOPIC_TYPE_NORMAL)
{
@@ -148,7 +145,6 @@ MQTTGWPacket* MQTTSNSubscribeHandler::handleUnsubscribe(Client* client, MQTTSNPa
return nullptr;
}
Topic* topic = client->getTopics()->getTopicById(&topicFilter);
if (topicFilter.type == MQTTSN_TOPIC_TYPE_SHORT)
{
@@ -161,6 +157,17 @@ MQTTGWPacket* MQTTSNSubscribeHandler::handleUnsubscribe(Client* client, MQTTSNPa
}
else
{
Topic* topic = nullptr;
if (topicFilter.type == MQTTSN_TOPIC_TYPE_PREDEFINED)
{
topic = client->getTopics()->getTopicById(&topicFilter);
}
else
{
topic = client->getTopics()->getTopicByName(&topicFilter);
}
if ( topic == nullptr )
{
MQTTSNPacket* sUnsuback = new MQTTSNPacket();

View File

@@ -66,24 +66,52 @@ void SensorNetAddress::setAddress(struct sockaddr_in6 *IpAddr, uint16_t port)
/**
* convert Text data to SensorNetAddress
* @param buf is pointer of IP_Address:PortNo format text
* @param data is a IP_Address:PortNo format string
* @return success = 0, Invalid format = -1
*/
int SensorNetAddress::setAddress(string* data)
{
const char *cstr = data->c_str();
inet_pton(AF_INET6, cstr, &(_IpAddr.sin6_addr));
return 0;
size_t pos = data->find_last_of(":");
if ( pos != string::npos)
{
int portNo = 0;
string port = data->substr(pos + 1);
if ( ( portNo = atoi(port.c_str()) ) > 0 )
{
_portNo = htons(portNo);
string ip = data->substr(1,pos - 1);
const char *cstr = ip.c_str();
if (inet_pton(AF_INET6, cstr, &(_IpAddr.sin6_addr)) == 1 )
{
return 0;
}
}
}
_portNo = 0;
memset((void *)&_IpAddr,0,sizeof(_IpAddr));
return -1;
}
/**
* convert Text data to SensorNetAddress
* @param buf is pointer of IP_Address:PortNo format text
* @param data is pointer of IP_Address format text
* @return success = 0, Invalid format = -1
*/
int SensorNetAddress::setAddress(const char* data)
{
inet_pton(AF_INET6, data, &(_IpAddr.sin6_addr));
return 0;
if ( inet_pton(AF_INET6, data, &(_IpAddr.sin6_addr)) == 1 )
{
return 0;
}
else
{
return -1;
}
}
char* SensorNetAddress::getAddress(void)
@@ -319,7 +347,6 @@ int UDPPort6::open(const char* ipAddress, uint16_t uniPortNo, const char* broadc
return 0;
}
//TODO: test if unicast is working too....
int UDPPort6::unicast(const uint8_t* buf, uint32_t length, SensorNetAddress* addr)
{
char destStr[INET6_ADDRSTRLEN+10];
@@ -364,8 +391,6 @@ int UDPPort6::unicast(const uint8_t* buf, uint32_t length, SensorNetAddress* add
WRITELOG("errno in UDPPort::unicast(sendto): %d, %s\n",status,strerror(status));
}
WRITELOG("unicast sendto %s, port: %d length = %d\n", destStr,port,status);
return status;
}

View File

@@ -65,7 +65,7 @@ void TestProcess::run(void)
assert(1 == getArgc() || 3 == getArgc() );
assert(0 == strcmp(ARGV, *getArgv()));
getParam("BrokerName", value);
assert(0 == strcmp("iot.eclipse.org", value));
assert(0 == strcmp("mqtt.eclipse.org", value));
/* Test RingBuffer */
for ( i = 0; i < 1000; i++)